作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

@@ -41,51 +41,75 @@ class AiBlogTask extends Command @@ -41,51 +41,75 @@ 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'); 49 + $updateProject = [];
  50 + foreach ($list as $item){
  51 + echo '开始->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
51 //获取配置 52 //获取配置
52 - $aiSettingInfo = $this->getSetting($info['project_id']); 53 + $aiSettingInfo = $this->getSetting($item['project_id']);
53 $aiBlogService = new AiBlogService(); 54 $aiBlogService = new AiBlogService();
54 $aiBlogService->mch_id = $aiSettingInfo['mch_id']; 55 $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
55 $aiBlogService->key = $aiSettingInfo['key']; 56 $aiBlogService->key = $aiSettingInfo['key'];
56 - $aiBlogService->task_id = $info['task_id']; 57 + $aiBlogService->task_id = $item['task_id'];
57 $result = $aiBlogService->getDetail(); 58 $result = $aiBlogService->getDetail();
58 - if(!isset($result['status'])){  
59 - continue;  
60 - }  
61 if($result['status'] != 200){ 59 if($result['status'] != 200){
62 sleep(10); 60 sleep(10);
63 continue; 61 continue;
64 } 62 }
65 //保存当前项目ai_blog数据 63 //保存当前项目ai_blog数据
66 - ProjectServer::useProject($info['project_id']); 64 + ProjectServer::useProject($item['project_id']);
67 $aiBlogModel = new AiBlog(); 65 $aiBlogModel = new AiBlog();
68 - $aiBlogInfo = $aiBlogModel->read(['task_id'=>$info['task_id']],['id']); 66 + $aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id']);
69 if($aiBlogInfo === false){ 67 if($aiBlogInfo === false){
70 - $aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]); 68 + $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
71 continue; 69 continue;
72 } 70 }
  71 + if (!in_array($result['data']['author_id'], $updateProject[$item['project_id']] ?? [])) {
  72 + $updateProject[$item['project_id']][] = $result['data']['author_id'];
  73 + }
73 //拿到返回的路由查看是否重复 74 //拿到返回的路由查看是否重复
74 - $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $info['project_id']); 75 + $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $item['project_id']);
75 if($route != $result['data']['url']){ 76 if($route != $result['data']['url']){
76 $aiBlogService->updateDetail(['route'=>$this->param['route']]); 77 $aiBlogService->updateDetail(['route'=>$this->param['route']]);
77 } 78 }
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']);  
80 - $this->updateBlogList($aiSettingInfo); 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']]);
81 DB::disconnect('custom_mysql'); 80 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'); 81 + $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
  82 + }
  83 + //TODO::更新列表页及作者
  84 + $this->updateProject($updateProject);
  85 + echo '结束->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
85 } 86 }
86 return true; 87 return true;
87 } 88 }
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);
  104 + $this->updateBlogList($aiSettingInfo);
  105 + //更新作者
  106 + foreach ($author as $val){
  107 + $this->updateAiBlogAuthor($aiSettingInfo,$val);
  108 + }
  109 + DB::disconnect('custom_mysql');
  110 + }
  111 + return true;
  112 + }
89 113
90 /** 114 /**
91 * @remark :获取项目配置 115 * @remark :获取项目配置
@@ -14,6 +14,10 @@ use App\Models\CustomModule\CustomModuleContent; @@ -14,6 +14,10 @@ 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\CategoryRelated;
  18 +use App\Models\Product\Column;
  19 +use App\Models\Product\Detail;
  20 +use App\Models\Product\Product;
17 use App\Models\RouteMap\RouteMap; 21 use App\Models\RouteMap\RouteMap;
18 use App\Models\Template\BTemplate; 22 use App\Models\Template\BTemplate;
19 use App\Models\Template\Template; 23 use App\Models\Template\Template;
@@ -37,7 +41,7 @@ class LyhImportTest extends Command @@ -37,7 +41,7 @@ class LyhImportTest extends Command
37 */ 41 */
38 protected $description = '导入数据'; 42 protected $description = '导入数据';
39 43
40 - public $data = ''; 44 +
41 45
42 /** 46 /**
43 * @remark :统一更新路由 47 * @remark :统一更新路由
@@ -49,9 +53,7 @@ class LyhImportTest extends Command @@ -49,9 +53,7 @@ class LyhImportTest extends Command
49 public function handle(){ 53 public function handle(){
50 ProjectServer::useProject(3283); 54 ProjectServer::useProject(3283);
51 echo date('Y-m-d H:i:s') . 'start' . PHP_EOL; 55 echo date('Y-m-d H:i:s') . 'start' . PHP_EOL;
52 -// $this->importCustomModule($this->data);  
53 -// $this->importProductCategory($this->data,3283);  
54 - $this->handleCatePid(); 56 + $this->importProduct('https://ecdn6.globalso.com/upload/p/1/file/2025-03/zy_boss_price_copy1.csv',3283);
55 DB::disconnect('custom_mysql'); 57 DB::disconnect('custom_mysql');
56 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; 58 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
57 } 59 }
@@ -63,23 +65,92 @@ class LyhImportTest extends Command @@ -63,23 +65,92 @@ class LyhImportTest extends Command
63 * @method :post 65 * @method :post
64 * @time :2025/3/3 15:59 66 * @time :2025/3/3 15:59
65 */ 67 */
66 - public function importProductCategory($text,$project_id){  
67 - //设置对应管理数组  
68 - $key_val = [];  
69 - $arr = explode("\n", $text);  
70 - foreach ($arr as $val){  
71 - $cate_arr = explode(",", $val);  
72 - $key_val[$cate_arr[1]] = $cate_arr[1];  
73 - $saveData = [  
74 - 'project_id'=>$project_id,  
75 - 'title'=>$cate_arr[1],  
76 - 'seo_title'=>$cate_arr[0],  
77 - 'seo_des'=>$cate_arr[2] 68 + public function importProduct($url,$project_id){
  69 + $line_of_text = [];
  70 + $opts = [
  71 + 'http' => [
  72 + 'method' => 'GET',
  73 + 'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'
  74 + ],
  75 + 'ssl' => [
  76 + 'verify_peer' => false,
  77 + 'verify_peer_name' => false
  78 + ]
78 ]; 79 ];
  80 + $file_handle = fopen($url, 'r', null, stream_context_create($opts));
  81 + while (!feof($file_handle)) {
  82 + $line_of_text[] = fgetcsv($file_handle, 0, ',');
  83 + }
  84 + fclose($file_handle);
79 $cateModel = new Category(); 85 $cateModel = new Category();
80 - $id = $cateModel->addReturnId($saveData);  
81 - $route = RouteMap::setRoute($cate_arr[1],RouteMap::SOURCE_PRODUCT_CATE,$id,$project_id);  
82 - $cateModel->edit(['route'=>$route],['id'=>$id]); 86 + $productModel = new Product();
  87 + $detailModel = new Detail();
  88 + $columnModel = new Column();
  89 + foreach ($line_of_text as $k => $val){
  90 + if($k < 2){
  91 + continue;
  92 + }
  93 + $saveData = [];
  94 + if($val[1] ?? ''){
  95 + $saveData['title'] = $val[1];
  96 + }else{
  97 + continue;
  98 + }
  99 + if($val[0] ?? ''){
  100 + $cateInfo = $cateModel->read(['seo_title'=>trim($val[0])]);
  101 + if($cateInfo !== false){
  102 + $saveData['category_id'] = ','.$cateInfo['id'].',';
  103 + }
  104 + }
  105 + $saveData['intro'] = $val[2];
  106 + $saveData['content'] = $val[3];
  107 + $seo = ['seo_title'=>$val[5]];
  108 + $saveData['seo_mate'] = json_encode($seo,true);
  109 + $thumb = ['alt'=>'主图','url'=>str_replace('/public','',$val[6])];
  110 + $gallery = [['alt'=>'主图','url'=>str_replace('/public','',$val[6])]];
  111 + $saveData['thumb'] = json_encode($thumb,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 + if($cateInfo !== false){
  117 + CategoryRelated::saveRelated($id,[$cateInfo['id']]);
  118 + }
  119 + //设置路由
  120 + $route = RouteMap::setRoute($val[1],RouteMap::SOURCE_PRODUCT,$id,$project_id);
  121 + $productModel->edit(['route'=>$route],['id'=>$id]);
  122 + //设置产品描述
  123 + $detail = [
  124 + 'product_id'=>$id,
  125 + 'column_id'=>1,
  126 + 'text_type'=>1,
  127 + 'content'=>json_encode(['content'=>$val[3]])
  128 + ];
  129 + $detailModel->addReturnId($detail);
  130 + //扩展描述设置
  131 + $detailFaq = [
  132 + 'column_name'=>'FAQs',
  133 + 'product_id'=>$id
  134 + ];
  135 + $faqId = $columnModel->addReturnId($detailFaq);
  136 +
  137 + $faqsDetail = json_decode($val[4],true);
  138 + $faqContent = '';
  139 + if(!empty($faqsDetail) && is_array($faqsDetail)){
  140 + foreach ($faqsDetail as $faq_Val){
  141 + $faqContent .= "question:".$faq_Val['question'] . "<br />" . "answer:".$faq_Val['answer']. "<br />";
  142 + }
  143 + $detailFaqInfo = [
  144 + 'product_id'=>$id,
  145 + 'column_id'=>$faqId,
  146 + 'text_type'=>1,
  147 + 'content'=>json_encode(['content'=>$faqContent])
  148 + ];
  149 + $detailModel->addReturnId($detailFaqInfo);
  150 + }else{
  151 + @file_put_contents(storage_path('logs/lyh_error.log'), var_export('产品标题:'. $val[1] . PHP_EOL .'faqs数据有问题:' . $val[4], true) . PHP_EOL, FILE_APPEND);
  152 + echo date('Y-m-d H:i:s') . '产品标题:'. $val[1] . PHP_EOL .'faqs数据有问题:' . $val[4];
  153 + }
83 } 154 }
84 return true; 155 return true;
85 } 156 }
@@ -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
@@ -26,7 +26,7 @@ class UserLogic extends BaseLogic @@ -26,7 +26,7 @@ class UserLogic extends BaseLogic
26 */ 26 */
27 public function user_info() 27 public function user_info()
28 { 28 {
29 - $info = $this->model->read($this->param, ['id', 'project_id', 'name', 'status', 'role_id' ,'mobile', 'operator_id']); 29 + $info = $this->model->read($this->param, ['id', 'project_id', 'name', 'status', 'role_id' ,'mobile', 'is_password' ,'operator_id']);
30 if ($info === false) { 30 if ($info === false) {
31 $this->fail('当前数据不存在'); 31 $this->fail('当前数据不存在');
32 } 32 }
@@ -488,7 +488,7 @@ class RankDataLogic extends BaseLogic @@ -488,7 +488,7 @@ class RankDataLogic extends BaseLogic
488 $without_project_ids = []; //不用处理排名的项目 488 $without_project_ids = []; //不用处理排名的项目
489 $without_extension_project_ids = [658]; //是否达标只统计主词的 489 $without_extension_project_ids = [658]; //是否达标只统计主词的
490 $extension_project_ids = [354]; //扩展词也到达标的 490 $extension_project_ids = [354]; //扩展词也到达标的
491 - $compliance_project_ids = [2163]; //直接达标处理的 491 + $compliance_project_ids = [2163,257]; //直接达标处理的
492 $ceaseProjectId = [ 492 $ceaseProjectId = [
493 47, 493 47,
494 354, 494 354,