PurchaserJob.php
1.8 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
<?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;
}
}