作者 赵彬吉
@@ -67,7 +67,30 @@ class UpdateRoute extends Command @@ -67,7 +67,30 @@ class UpdateRoute extends Command
67 */ 67 */
68 public function handle() 68 public function handle()
69 { 69 {
70 - return $this->settingSeo(); 70 + return $this->getNullRoute();
  71 + }
  72 +
  73 + /**
  74 + * @remark :查询 路由为空的关键词项目id
  75 + * @name :getNullRoute
  76 + * @author :lyh
  77 + * @method :post
  78 + * @time :2025/4/21 11:52
  79 + */
  80 + public function getNullRoute(){
  81 + $projectModel = new Project();
  82 + $lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'type'=>['in',[1,2,3,4]]], 'id', ['id']);
  83 + foreach ($lists as $val) {
  84 + echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
  85 + ProjectServer::useProject($val['id']);
  86 + $keywordModel = new Keyword();
  87 + $info = $keywordModel->read(['route'=>'']);
  88 + if($info !== false){
  89 + echo '存在路由为空--项目id:'.$val['id'].PHP_EOL;
  90 + }
  91 + DB::disconnect('custom_mysql');
  92 + }
  93 + return true;
71 } 94 }
72 95
73 public function keyword_actions(){ 96 public function keyword_actions(){
@@ -162,7 +162,7 @@ class RecommendedSuppliers extends Command @@ -162,7 +162,7 @@ class RecommendedSuppliers extends Command
162 $res = http_post($url,json_encode($param)); 162 $res = http_post($url,json_encode($param));
163 echo '请求返回状态'. ($res['code']?? '').PHP_EOL; 163 echo '请求返回状态'. ($res['code']?? '').PHP_EOL;
164 // echo date('Y-m-d H:i:s') . json_encode($res) . PHP_EOL; 164 // echo date('Y-m-d H:i:s') . json_encode($res) . PHP_EOL;
165 - if(!empty($res) && isset($res['code']) && $res['code'] == 200 && !empty($res['data'])){ 165 + if(isset($res['code']) && $res['code'] == 200){
166 //保存多条数据 166 //保存多条数据
167 $saveData = [ 167 $saveData = [
168 'project_id'=>$project_id, 168 'project_id'=>$project_id,
@@ -171,14 +171,11 @@ class RecommendedSuppliers extends Command @@ -171,14 +171,11 @@ class RecommendedSuppliers extends Command
171 ]; 171 ];
172 $purchaserModel = new Purchaser(); 172 $purchaserModel = new Purchaser();
173 $purchaserModel->add($saveData); 173 $purchaserModel->add($saveData);
  174 + if(!empty($res['data'])){
174 $this->savePurchaserInfo($project_id,$keyword,$res['data']); 175 $this->savePurchaserInfo($project_id,$keyword,$res['data']);
175 - }else{  
176 - if(!isset($res['code']) || $res['code'] != 200){  
177 - echo '请求错误,跳过当前项目。避免进入死循环'.PHP_EOL;  
178 - return true;  
179 } 176 }
180 - $title = $this->getKeywords($project_id);  
181 - $this->savePurchaser($project_id,$title); 177 + }else{
  178 + echo '未正常返回数据,跳过项目'.PHP_EOL;
182 } 179 }
183 return true; 180 return true;
184 } 181 }
@@ -193,11 +190,11 @@ class RecommendedSuppliers extends Command @@ -193,11 +190,11 @@ class RecommendedSuppliers extends Command
193 public function getKeywords($project_id){ 190 public function getKeywords($project_id){
194 $keywordModel = new Keyword(); 191 $keywordModel = new Keyword();
195 $keyword_array = $this->getPurchaserList($project_id); 192 $keyword_array = $this->getPurchaserList($project_id);
196 - $info = $keywordModel->read(['title'=>['not in',$keyword_array]],'title');  
197 - if($info === false){ 193 + $title = $keywordModel->where('title', 'not in', $keyword_array)->orderRaw('RAND()')->limit(1)->value('title'); // 只返回 title 字段
  194 + if(empty($title)){
198 return ''; 195 return '';
199 } 196 }
200 - return $info['title'] ?? ''; 197 + return $title;
201 } 198 }
202 199
203 /** 200 /**