正在显示
1 个修改的文件
包含
8 行增加
和
11 行删除
| @@ -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 | - $this->savePurchaserInfo($project_id,$keyword,$res['data']); | ||
| 175 | - }else{ | ||
| 176 | - if(!isset($res['code']) || $res['code'] != 200){ | ||
| 177 | - echo '请求错误,跳过当前项目。避免进入死循环'.PHP_EOL; | ||
| 178 | - return true; | 174 | + if(!empty($res['data'])){ |
| 175 | + $this->savePurchaserInfo($project_id,$keyword,$res['data']); | ||
| 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 | /** |
-
请 注册 或 登录 后发表评论