PushAiccData.php
2.9 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
<?php
namespace App\Console\Commands\GeneratePDF;
use App\Models\File\PdfFile;
use App\Models\ProjectAssociation\ProjectAssociation;
use Illuminate\Console\Command;
class PushAiccData extends Command
{
// use CmdSignal;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'push_data_to_aicc';
/**
* The console command description.
*
* @var string
*/
protected $description = '向AICC推送数据';
// 最大支持5个进程
public $maxRunNumber = 50;
protected $time;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
$this->time = date('Y-m');
parent::__construct();
}
public function handle()
{
return $this->main();
}
public function start(): int
{
return $this->main();
}
protected function main()
{
$list = PdfFile::query()->whereIsPdf(PdfFile::GENERATE_PUSH)->whereIsPush(PdfFile::GENERATE_NOT_PUSH)->first();
if (is_null($list)) {
$this->error('向AICC推送 - 没有任务,等待中');
sleep(60);
return 0;
}
$pid = $list->pid;
if (empty($pid)) {
$this->error('向AICC推送数据错误');
return 0;
}
$isExists = ProjectAssociation::query()->whereId($pid)->whereStatus(ProjectAssociation::STATUS_NORMAL)->first();
if (is_null($isExists)) {
$this->error('向AICC推送数据已被禁用 —— ' . $pid);
return 0;
}
$key = 'push_data_to_aicc_' . $list->id;
$count = (int)redis_get($key) ?: 0;
$data = $list->toArray();
$data['project_id'] = $isExists->project_id;
$data['friend_id'] = $isExists->friend_id;
$data['user_id'] = $isExists->user_id;
$url = env('AICC_URL') . env('AICC_PUSH_API_URL');
$msg = http_post($url, json_encode(compact('data')));
$status_code = 0;
if ($msg) {
$status_code = (int)$msg['status'];
}
if ($count == 2) {
$list->is_push = PdfFile::GENERATE_OTHER_PUSH;
$list->save();
$this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key);
return 0;
}
if ($status_code != 200) {
redis_set($key, $count + 1);
$this->debug_echo('项目文件数据保存失败! - ' . $key);
return 0;
}
$list->is_push = PdfFile::GENERATE_PUSH;
$list->save();
$this->info('项目文件数据保存成功!');
return 0;
}
public function post_data($data)
{
$url = env('AICC_URL') . env('AICC_PUSH_API_URL');
$msg = http_post($url, json_encode(compact('data')));
print_r($msg);
}
}