作者 李宇航

合并分支 'master-server' 到 'master'

gx导入产品脚本



查看合并请求 !1315
@@ -41,52 +41,76 @@ class AiBlogTask extends Command @@ -41,52 +41,76 @@ class AiBlogTask extends Command
41 public function handle(){ 41 public function handle(){
42 $aiBlogTaskModel = new AiBlogTaskModel(); 42 $aiBlogTaskModel = new AiBlogTaskModel();
43 while (true){ 43 while (true){
44 - $info = $aiBlogTaskModel->where('status',1)->where('type',2)->inRandomOrder()->first();  
45 - if(empty($info)){ 44 + $list = $aiBlogTaskModel->list(['status'=>1,'type'=>2],'id',['*'],'asc',1000);
  45 + if(empty($list)){
46 sleep(300); 46 sleep(300);
47 continue; 47 continue;
48 } 48 }
49 - $info = $info->toArray();  
50 - echo '开始->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');  
51 - //获取配置  
52 - $aiSettingInfo = $this->getSetting($info['project_id']);  
53 - $aiBlogService = new AiBlogService();  
54 - $aiBlogService->mch_id = $aiSettingInfo['mch_id'];  
55 - $aiBlogService->key = $aiSettingInfo['key'];  
56 - $aiBlogService->task_id = $info['task_id'];  
57 - $result = $aiBlogService->getDetail();  
58 - if(!isset($result['status'])){  
59 - continue;  
60 - }  
61 - if($result['status'] != 200){  
62 - sleep(10);  
63 - continue;  
64 - }  
65 - //保存当前项目ai_blog数据  
66 - ProjectServer::useProject($info['project_id']);  
67 - $aiBlogModel = new AiBlog();  
68 - $aiBlogInfo = $aiBlogModel->read(['task_id'=>$info['task_id']],['id']);  
69 - if($aiBlogInfo === false){  
70 - $aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]);  
71 - continue; 49 + $updateProject = [];
  50 + foreach ($list as $item){
  51 + echo '开始->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
  52 + //获取配置
  53 + $aiSettingInfo = $this->getSetting($item['project_id']);
  54 + $aiBlogService = new AiBlogService();
  55 + $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
  56 + $aiBlogService->key = $aiSettingInfo['key'];
  57 + $aiBlogService->task_id = $item['task_id'];
  58 + $result = $aiBlogService->getDetail();
  59 + if($result['status'] != 200){
  60 + sleep(10);
  61 + continue;
  62 + }
  63 + //保存当前项目ai_blog数据
  64 + ProjectServer::useProject($item['project_id']);
  65 + $aiBlogModel = new AiBlog();
  66 + $aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id']);
  67 + if($aiBlogInfo === false){
  68 + $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
  69 + continue;
  70 + }
  71 + if (!in_array($result['data']['author_id'], $updateProject[$item['project_id']] ?? [])) {
  72 + $updateProject[$item['project_id']][] = $result['data']['author_id'];
  73 + }
  74 + //拿到返回的路由查看是否重复
  75 + $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $item['project_id']);
  76 + if($route != $result['data']['url']){
  77 + $aiBlogService->updateDetail(['route'=>$this->param['route']]);
  78 + }
  79 + $aiBlogModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'], 'route'=>$route ,'status'=>2], ['task_id'=>$item['task_id']]);
  80 + DB::disconnect('custom_mysql');
  81 + $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
72 } 82 }
73 - //拿到返回的路由查看是否重复  
74 - $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $info['project_id']);  
75 - if($route != $result['data']['url']){  
76 - $aiBlogService->updateDetail(['route'=>$this->param['route']]);  
77 - }  
78 - $aiBlogModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'], 'route'=>$route ,'status'=>2], ['task_id'=>$info['task_id']]);  
79 - $this->updateAiBlogAuthor($aiSettingInfo,$result['data']['author_id']); 83 + //TODO::更新列表页及作者
  84 + $this->updateProject($updateProject);
  85 + echo '结束->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
  86 + }
  87 + return true;
  88 + }
  89 +
  90 + /**
  91 + * @remark :更新项目作者页面及列表页
  92 + * @name :updateProject
  93 + * @author :lyh
  94 + * @method :post
  95 + * @time :2025/3/4 10:25
  96 + */
  97 + public function updateProject($updateProject){
  98 + if(empty($updateProject)){
  99 + return true;
  100 + }
  101 + foreach ($updateProject as $project_id => $author){
  102 + ProjectServer::useProject($project_id);
  103 + $aiSettingInfo = $this->getSetting($project_id);
80 $this->updateBlogList($aiSettingInfo); 104 $this->updateBlogList($aiSettingInfo);
  105 + //更新作者
  106 + foreach ($author as $val){
  107 + $this->updateAiBlogAuthor($aiSettingInfo,$val);
  108 + }
81 DB::disconnect('custom_mysql'); 109 DB::disconnect('custom_mysql');
82 - //修改任务状态  
83 - $aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]);  
84 - echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');  
85 } 110 }
86 return true; 111 return true;
87 } 112 }
88 113
89 -  
90 /** 114 /**
91 * @remark :获取项目配置 115 * @remark :获取项目配置
92 * @name :getSetting 116 * @name :getSetting
@@ -14,6 +14,8 @@ use App\Models\CustomModule\CustomModuleContent; @@ -14,6 +14,8 @@ use App\Models\CustomModule\CustomModuleContent;
14 use App\Models\CustomModule\CustomModuleExtentContent; 14 use App\Models\CustomModule\CustomModuleExtentContent;
15 use App\Models\News\News; 15 use App\Models\News\News;
16 use App\Models\Product\Category; 16 use App\Models\Product\Category;
  17 +use App\Models\Product\Column;
  18 +use App\Models\Product\Detail;
17 use App\Models\Product\Product; 19 use App\Models\Product\Product;
18 use App\Models\RouteMap\RouteMap; 20 use App\Models\RouteMap\RouteMap;
19 use App\Models\Template\BTemplate; 21 use App\Models\Template\BTemplate;
@@ -81,10 +83,13 @@ class LyhImportTest extends Command @@ -81,10 +83,13 @@ class LyhImportTest extends Command
81 fclose($file_handle); 83 fclose($file_handle);
82 $cateModel = new Category(); 84 $cateModel = new Category();
83 $productModel = new Product(); 85 $productModel = new Product();
  86 + $detailModel = new Detail();
  87 + $columnModel = new Column();
84 foreach ($line_of_text as $k => $val){ 88 foreach ($line_of_text as $k => $val){
85 if($k < 2){ 89 if($k < 2){
86 continue; 90 continue;
87 } 91 }
  92 + dd($val);
88 $saveData = []; 93 $saveData = [];
89 if($val[1] ?? ''){ 94 if($val[1] ?? ''){
90 $saveData['title'] = $val[1]; 95 $saveData['title'] = $val[1];
@@ -105,7 +110,39 @@ class LyhImportTest extends Command @@ -105,7 +110,39 @@ class LyhImportTest extends Command
105 $gallery = [['alt'=>'主图','url'=>str_replace('/public','',$val[6])]]; 110 $gallery = [['alt'=>'主图','url'=>str_replace('/public','',$val[6])]];
106 $saveData['thumb'] = json_encode($thumb,true); 111 $saveData['thumb'] = json_encode($thumb,true);
107 $saveData['gallery'] = json_encode($gallery,true); 112 $saveData['gallery'] = json_encode($gallery,true);
  113 + $id = $productModel->addReturnId($saveData);
  114 + echo date('Y-m-d H:i:s') . '新增产品id:'.$id . PHP_EOL;
  115 + //设置路由
  116 + $route = RouteMap::setRoute($val[1],RouteMap::SOURCE_PRODUCT,$id,$project_id);
  117 + $productModel->edit(['route'=>$route],['id'=>$id]);
  118 + //设置产品描述
  119 + $detail = [
  120 + 'product_id'=>$id,
  121 + 'column_id'=>1,
  122 + 'text_type'=>1,
  123 + 'content'=>json_encode(['content'=>$val[3]])
  124 + ];
  125 + $detailModel->addReturnId($detail);
  126 + //扩展描述设置
  127 + $detailFaq = [
  128 + 'column_name'=>'FAQs',
  129 + 'product_id'=>$id
  130 + ];
  131 + $faqId = $columnModel->addReturnId($detailFaq);
  132 + $faqsDetail = json_decode($val[4],true);
  133 + $faqContent = '';
  134 + foreach ($faqsDetail as $faq_Val){
  135 + $faqContent = "question:".$faq_Val['question'] . "<br />" . "answer:".$faq_Val['answer']. "<br />";
  136 + }
  137 + $detailFaqInfo = [
  138 + 'product_id'=>$id,
  139 + 'column_id'=>$faqId,
  140 + 'text_type'=>1,
  141 + 'content'=>json_encode(['content'=>$faqContent])
  142 + ];
  143 + $detailModel->addReturnId($detailFaqInfo);
108 } 144 }
  145 + return true;
109 } 146 }
110 147
111 public function handleCatePid(){ 148 public function handleCatePid(){
@@ -739,7 +739,7 @@ if (!function_exists('getAutoLoginCode')) { @@ -739,7 +739,7 @@ if (!function_exists('getAutoLoginCode')) {
739 function getAutoLoginCode($project_id) 739 function getAutoLoginCode($project_id)
740 { 740 {
741 $encrypt = new EncryptUtils(); 741 $encrypt = new EncryptUtils();
742 - return $encrypt->authcode(json_encode(['project_id' => $project_id]), 'ENCODE', 'autologin', 3600); 742 + return $encrypt->authcode(json_encode(['project_id' => $project_id]), 'ENCODE', 'autologin', 300);
743 } 743 }
744 } 744 }
745 745