作者 lyh

gx批量操作关键词

... ... @@ -62,7 +62,11 @@ class RecommendedSuppliers extends Command
if($result !== false){
ProjectServer::useProject($v['project_id']);
$title = $this->getKeywords($v['project_id']);
$this->savePurchaser($v['project_id'],$title);
if(!empty($title)){
$this->savePurchaser($v['project_id'],$title);
}else{
echo '关键词已取完'.PHP_EOL;
}
DB::disconnect('custom_mysql');
}
}
... ... @@ -95,12 +99,31 @@ class RecommendedSuppliers extends Command
return true;
}
/**
* @remark :获取关键词数据
* @name :getPurchaser
* @author :lyh
* @method :post
* @time :2025/4/15 17:55
*/
public function getPurchaser($keyword,$project_id){
$purchaserModel = new Purchaser();
return $purchaserModel->read(['keyword'=>$keyword,'project_id'=>$project_id]);
}
/**
* @remark :获取已经处理过的关键词
* @name :getPurchaserList
* @author :lyh
* @method :post
* @time :2025/4/15 17:55
*/
public function getPurchaserList($project_id){
$purchaserModel = new Purchaser();
return $purchaserModel->selectField(['project_id'=>$project_id],'keyword');
}
/**
* @remark :保存供应商
* @name :getPurchaser
* @author :lyh
... ... @@ -110,6 +133,7 @@ class RecommendedSuppliers extends Command
public function savePurchaser($project_id,$keyword,$row = 10){
//项目还没有关键词
if(!$keyword){
echo '项目还没有关键词';
return true;
}
$url = 'https://fob.ai.cc/api/company_list';
... ... @@ -126,8 +150,10 @@ class RecommendedSuppliers extends Command
'total'=>$this->param['row'] ?? 10,
];
$res = http_post($url,json_encode($param));
echo '请求返回状态'.$res['code']?? ''.PHP_EOL;
// echo date('Y-m-d H:i:s') . json_encode($res) . PHP_EOL;
if(!empty($res) && isset($res['code']) && $res['code'] == 200 && !empty($res['data'])){
//保存多条数据
$saveData = [
'project_id'=>$project_id,
... ... @@ -152,15 +178,13 @@ class RecommendedSuppliers extends Command
* @time :2024/7/1 18:07
*/
public function getKeywords($project_id){
$info = Keyword::inRandomOrder()->first();
if(!$info){
$keywordModel = new Keyword();
$keyword_array = $this->getPurchaserList($project_id);
$info = $keywordModel->read(['title'=>'not in',$keyword_array],'title');
if($info === false){
return '';
}
$keywordInfo = $this->getPurchaser($info->title,$project_id);
if($keywordInfo !== false){
$this->getKeywords($project_id);
}
return $info->title;
return $info['title'] ?? '';
}
/**
... ...