RecommendedSuppliers.php
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?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\DeployBuild;
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 DeployBuild();
$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['project_id'] . PHP_EOL;
ProjectServer::useProject($v['project_id']);
$info = Keyword::inRandomOrder()->first();
if(empty($info)){
echo date('Y-m-d H:i:s') . $info . PHP_EOL;
continue;
}
$keywordInfo = $this->getPurchaser($info['title']);
if($keywordInfo !== false){
echo date('Y-m-d H:i:s') . '222222' . PHP_EOL;
continue;
}
echo date('Y-m-d H:i:s') . '开始:'.$v['project_id'] . PHP_EOL;
$this->savePurchaser($v['id'],$info['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,
];
ksort($data);
$token = 'company_list+'.date('Y-m-d').'+'.http_build_query($data);
echo date('Y-m-d H:i:s') . '加密token:'.md5($token) . PHP_EOL;
$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;
}
}