作者 张关杰

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into bate

<?php
/**
* @remark :
* @name :RecommendedSuppliers.php
* @author :lyh
* @method :post
* @time :2024/3/5 11:27
*/
namespace App\Console\Commands\Suppliers;
use App\Models\Com\Purchaser;
use App\Models\Product\Keyword;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class RecommendedSuppliers extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'recommended_suppliers';
/**
* The console command description.
*
* @var string
*/
protected $description = '推荐供应商';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
$projectModel = new Project();
$project_list = $projectModel->list(['is_supplier'=>1]);//TODO::已开启推荐供应商
foreach ($project_list as $k => $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$keywordInfo = Keyword::inRandomOrder()->first();
if(empty($keywordInfo)){
continue;
}
$keywordInfo = $this->getPurchaser($keywordInfo['title']);
if($keywordInfo !== false){
continue;
}
$this->savePurchaser($v['id'],$keywordInfo['title']);
DB::disconnect('custom_mysql');
}
return true;
}
public function getPurchaser($keyword){
$purchaserModel = new Purchaser();
return $purchaserModel->read(['keyword'=>$keyword]);
}
/**
* @remark :保存供应商
* @name :getPurchaser
* @author :lyh
* @method :post
* @time :2024/3/5 11:38
*/
public function savePurchaser($project_id,$keyword,$row = 10){
$url = 'https://admin.hagro.cn/api/company_list';
$data = [
'prod_desc'=>$keyword,
'total'=>$row ?? 10,
];
arsort($data);
$token = 'company_list+'.date('Y-m-d').'+'.http_build_query($data);
$param = [
'prod_desc'=>$keyword,
'token'=>md5($token),
'total'=>$this->param['row'] ?? 10,
];
$res = http_post($url,json_encode($param));
if(!empty($res) && $res['code'] == 200){
$saveData = [
'project_id'=>$project_id,
'keyword'=>$keyword,
'data'=>json_encode($res['data'])
];
$purchaserModel = new Purchaser();
$purchaserModel->add($saveData);
}
return true;
}
}
... ...
... ... @@ -336,14 +336,14 @@ class ComController extends BaseController
* @time :2024/3/4 10:10
*/
public function recommendedPurchaser(){
$data = [];
$purchaserModel = new Purchaser();
$info = $purchaserModel->read(['project_id'=>$this->user['project_id']]);
if($info === false){
PurchaserJob::dispatch(['keyword'=>$this->param['keyword'] ?? 'led','row'=>$this->param['row'] ?? 10,'project_id'=>$this->user['project_id']]);
}else{
$data = json_decode($info['data']);
$lists = $purchaserModel->lists(['project_id'=>$this->user['project_id']],$this->page,$this->row);
if(!empty($lists) && !empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$v['data'] = json_decode($v['data']);
$lists['list'][$k] = $v;
}
}
$this->response('数据生成中',Code::SUCCESS,$data);
$this->response('success',Code::SUCCESS,$lists);
}
}
... ...
... ... @@ -173,12 +173,11 @@ class BaseLogic extends Logic
$data['project_id'] = $this->user['project_id'];
$str = http_build_query($data);
$url = $this->user['domain'].'api/delHtml/?'.$str;
$rs = shell_exec('curl -k "'.$url.'"');
// if($this->user['project_id'] == 177){
// @file_put_contents(storage_path('logs/lyh_error.log'), var_export($url, true) . PHP_EOL, FILE_APPEND);
// @file_put_contents(storage_path('logs/lyh_error.log'), var_export($rs, true) . PHP_EOL, FILE_APPEND);
// }
// curlGet($url);
if($this->user['project_id'] == 672){//TODO::当前项目通知不过 ,跳过自动更新
exec('curl -k "'.$url.'" > /dev/null 2>&1 &');
}else{
shell_exec('curl -k "'.$url.'"');
}
return $this->success();
}
}
... ...
<?php
/**
* @remark :
* @name :PurchaserJob.php
* @author :lyh
* @method :post
* @time :2024/3/4 11:06
*/
namespace App\Jobs;
use App\Models\Com\Purchaser;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class PurchaserJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 3; // 可配置任务重试次数
protected $param;
/**
* Create a new job instance.
*
* @param CopyImageFile $event
* @return void
*/
public function __construct($data)
{
$this->param = $data;
}
/**
* Handle the event.
*
* @param UpdateHtml $event
* @return void
*/
public function handle()
{
$this->param['keyword'] = 'led';
$url = 'https://admin.hagro.cn/api/company_list';
$data = [
'prod_desc'=>$this->param['keyword'],
'total'=>$this->param['row'] ?? 10,
];
arsort($data);
$token = 'company_list+'.date('Y-m-d').'+'.http_build_query($data);
$param = [
'prod_desc'=>$this->param['keyword'],
'token'=>md5($token),
'total'=>$this->param['row'] ?? 10,
];
$res = http_post($url,json_encode($param));
if(!empty($res) && $res['code'] == 200){
$saveData = [
'project_id'=>$this->param['project_id'],
'keyword'=>$this->param['keyword'],
'data'=>json_encode($res['data'])
];
$purchaserModel = new Purchaser();
$purchaserModel->add($saveData);
}
return true;
}
}