作者 lyh

gx脚本导出产品

@@ -9,8 +9,18 @@ @@ -9,8 +9,18 @@
9 9
10 namespace App\Console\Commands\Project; 10 namespace App\Console\Commands\Project;
11 11
  12 +use App\Enums\Common\Code;
  13 +use App\Helper\Common;
12 use App\Models\Domain\DomainInfo; 14 use App\Models\Domain\DomainInfo;
  15 +use App\Models\Product\Category;
  16 +use App\Models\Product\CategoryRelated;
  17 +use App\Models\Product\Detail;
  18 +use App\Models\Product\Product;
13 use App\Models\Project\Project; 19 use App\Models\Project\Project;
  20 +use App\Models\RouteMap\RouteMap;
  21 +use App\Models\Template\BTemplate;
  22 +use App\Models\Template\Setting;
  23 +use App\Models\User\User;
14 use App\Models\WebSetting\WebSettingSeo; 24 use App\Models\WebSetting\WebSettingSeo;
15 use App\Services\ProjectServer; 25 use App\Services\ProjectServer;
16 use Illuminate\Console\Command; 26 use Illuminate\Console\Command;
@@ -25,7 +35,7 @@ class DownloadProject extends Command @@ -25,7 +35,7 @@ class DownloadProject extends Command
25 * 35 *
26 * @var string 36 * @var string
27 */ 37 */
28 - protected $signature = 'downloads_project'; 38 + protected $signature = 'downloads_products';
29 39
30 /** 40 /**
31 * The console command description. 41 * The console command description.
@@ -34,47 +44,94 @@ class DownloadProject extends Command @@ -34,47 +44,94 @@ class DownloadProject extends Command
34 */ 44 */
35 protected $description = '导出项目数据'; 45 protected $description = '导出项目数据';
36 46
37 -// public function handle(){  
38 -// $projectModel = new Project();  
39 -// $data = $projectModel->formatQuery(['channel'=>['like','%"channel_id": "57"%'],'delete_status'=>0])->with(['deploy_optimize'])->get()->toArray();  
40 -// if(!empty($data)){  
41 -// $result = $this->exportData($data);  
42 -// }  
43 -// echo date('Y-m-d H:i:s') . ' ' . json_encode($result) . PHP_EOL;  
44 -// return $result;  
45 -//  
46 -// }  
47 -  
48 public function handle(){ 47 public function handle(){
49 - $data = [];  
50 - $projectModel = new Project();  
51 - $projectList = $projectModel->formatQuery(['delete_status'=>0,'type'=>['in',[2,3]]])->with(['deploy_optimize'])->select(['id','status','type','title','remain_day'])->get()->toArray();;  
52 - foreach ($projectList as $v){  
53 - ProjectServer::useProject($v['id']);  
54 - $seoModel = new WebSettingSeo();  
55 - $seoInfo = $seoModel->read(['project_id'=>$v['id']]);  
56 - if($seoInfo === false){  
57 - $data[] = $v; 48 + ProjectServer::useProject(1225);
  49 + $data = $this->downloadProduct();
  50 + DB::disconnect('custom_mysql');
  51 + echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
  52 + return true;
  53 +// return $this->exportData($data);
  54 + }
  55 +
  56 + public function downloadProduct()
  57 + {
  58 + $product = new Product();
  59 + $filed = ['id', 'project_id', 'title' ,'thumb' , 'route' ,'intro','content',
  60 + 'category_id', 'status'];
  61 + $this->order = 'sort';
  62 + $lists = $product->list(['status'=>1],'id',$filed);
  63 + if(!empty($lists)){
  64 + $cate_data = $this->getCategoryList();//分类
  65 + $detailModel = new Detail();
  66 + foreach ($lists as $k => $v){
  67 + $detailInfo = $detailModel->read(['product_id'=>$v['id'],'column_id'=>1,'text_type'=>1],['content']);
  68 + if($detailInfo === false || ($detailInfo['content']['content'] == null)){
  69 + $v['content'] = '';
58 }else{ 70 }else{
59 - if(empty($seoInfo['single_page_suffix'])){  
60 - $data[] = $v; 71 + $v['content'] = $detailInfo['content']['content'];
61 } 72 }
  73 + $v['url'] = 'https://www.autsikinta.com/' . getRouteMap(RouteMap::SOURCE_PRODUCT,$v['id']);
  74 + $v['category_id_text'] = $this->categoryName($v['id'],$cate_data);
  75 + //ToDo::处理图片及文件
  76 + if(!empty($v['thumb']) && !empty($v['thumb']['url'])){
  77 + $v['images'] = getImageUrl($v['thumb']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location']);
  78 + }else{
  79 + $v['images'] = '';
62 } 80 }
63 - DB::disconnect('custom_mysql'); 81 + echo date('Y-m-d H:i:s') . '数据详情$v:'. $v . PHP_EOL;
  82 + $lists[$k] = $v;
64 } 83 }
65 - return $this->exportData($data);  
66 } 84 }
67 - 85 + return $lists;
  86 + }
  87 + public function categoryName($product_id,$data){
  88 + $cateRelatedModel = new CategoryRelated();
  89 + $category_id = $cateRelatedModel->where('product_id',$product_id)->pluck('cate_id')->toArray();
  90 + $category_name = '';
  91 + if(!empty($category_id) && !empty($data)){
  92 + foreach ($category_id as $v){
  93 + if(isset($data[$v])){
  94 + $category_name .= $data[$v].',';
  95 + }
  96 + }
  97 + $category_name = trim($category_name,',');
  98 + }
  99 + return $category_name;
  100 + }
  101 + /**
  102 + * @remark :获取所有分类
  103 + * @name :getCategoryList
  104 + * @author :lyh
  105 + * @method :post
  106 + * @time :2023/9/14 13:56
  107 + */
  108 + public function getCategoryList(){
  109 + $data = Common::get_user_cache('product_category',$this->user['project_id']);
  110 + if(empty($data)){
  111 + $categoryModel = new Category();
  112 + $data = [];
  113 + $cateList = $categoryModel->list(['project_id'=>$this->user['project_id']],['id','title']);
  114 + if(!empty($cateList)){
  115 + foreach ($cateList as $value){
  116 + $data[$value['id']] = $value['title'];
  117 + }
  118 + }
  119 + Common::set_user_cache($data,'product_category',$this->user['project_id']);
  120 + }
  121 + return $data;
  122 + }
68 public function exportData($data){ 123 public function exportData($data){
69 // 创建一个新的 Excel 电子表格实例 124 // 创建一个新的 Excel 电子表格实例
70 $spreadsheet = new Spreadsheet(); 125 $spreadsheet = new Spreadsheet();
71 $sheet = $spreadsheet->getActiveSheet(); 126 $sheet = $spreadsheet->getActiveSheet();
72 // 添加表头 127 // 添加表头
73 - $sheet->setCellValue('A1', '项目ID');  
74 - $sheet->setCellValue('B1', '项目名称');  
75 - $sheet->setCellValue('C1', '域名');  
76 - $sheet->setCellValue('D1', '状态');  
77 - $sheet->setCellValue('E1', '剩余服务时间'); 128 + $sheet->setCellValue('A1', '产品名称');
  129 + $sheet->setCellValue('B1', '产品描述');
  130 + $sheet->setCellValue('C1', '产品内容');
  131 + $sheet->setCellValue('D1', '产品路由');
  132 + $sheet->setCellValue('E1', '产品分类');
  133 + $sheet->setCellValue('F1', '产品状态');
  134 + $sheet->setCellValue('G1', '产品主图');
78 $rowCount = 2; 135 $rowCount = 2;
79 // $allData = $this->countAll(); 136 // $allData = $this->countAll();
80 foreach ($data as $v) { 137 foreach ($data as $v) {