|
@@ -47,7 +47,6 @@ class postInquiry extends Command |
|
@@ -47,7 +47,6 @@ class postInquiry extends Command |
|
47
|
while (true) {
|
47
|
while (true) {
|
|
48
|
$list = ReInquiryDetailLog::where('status', ReInquiryDetailLog::STATUS_INIT)->where('start_at', '<=', date('Y-m-d H:i:s'))->limit(100)->get();
|
48
|
$list = ReInquiryDetailLog::where('status', ReInquiryDetailLog::STATUS_INIT)->where('start_at', '<=', date('Y-m-d H:i:s'))->limit(100)->get();
|
|
49
|
if (!$list->count()){
|
49
|
if (!$list->count()){
|
|
50
|
- //5分钟同步一次
|
|
|
|
51
|
sleep(1);
|
50
|
sleep(1);
|
|
52
|
}
|
51
|
}
|
|
53
|
// 询盘数据入库
|
52
|
// 询盘数据入库
|
|
@@ -67,6 +66,25 @@ class postInquiry extends Command |
|
@@ -67,6 +66,25 @@ class postInquiry extends Command |
|
67
|
$this->output('开始执行' . $val->id);
|
66
|
$this->output('开始执行' . $val->id);
|
|
68
|
try {
|
67
|
try {
|
|
69
|
$detail = ReInquiryDetail::find($val['detail_id']);
|
68
|
$detail = ReInquiryDetail::find($val['detail_id']);
|
|
|
|
69
|
+
|
|
|
|
70
|
+ //防止 程序中断 启动时 同一时间一下就发了
|
|
|
|
71
|
+ $last_log = ReInquiryDetailLog::where('detail_id', $val['detail_id'])->where('id', '<', $val['id'])->first();
|
|
|
|
72
|
+ //不是第一个 或者 上一个处理失败了 直接处理
|
|
|
|
73
|
+ if(!empty($last_log)){
|
|
|
|
74
|
+ //上一个还没有处理 直接跳过
|
|
|
|
75
|
+ if($last_log->status == ReInquiryDetailLog::STATUS_INIT){
|
|
|
|
76
|
+ continue;
|
|
|
|
77
|
+ }
|
|
|
|
78
|
+ //上一个处理完成 直接跳过
|
|
|
|
79
|
+ if($last_log->status == ReInquiryDetailLog::STATUS_SUCCESS){
|
|
|
|
80
|
+ //上次处理时间间隔达到没
|
|
|
|
81
|
+ $interval = strtotime($val->start_at) - strtotime($last_log->start_at);
|
|
|
|
82
|
+ if(time() - strtotime($last_log->updated_at) < $interval){
|
|
|
|
83
|
+ continue;
|
|
|
|
84
|
+ }
|
|
|
|
85
|
+ }
|
|
|
|
86
|
+ }
|
|
|
|
87
|
+
|
|
70
|
if($val['type'] == 1){
|
88
|
if($val['type'] == 1){
|
|
71
|
$this->visit($detail, $val);
|
89
|
$this->visit($detail, $val);
|
|
72
|
}else{
|
90
|
}else{
|
|
@@ -105,7 +123,7 @@ class postInquiry extends Command |
|
@@ -105,7 +123,7 @@ class postInquiry extends Command |
|
105
|
'referrer_url' => $detail['referrer'],
|
123
|
'referrer_url' => $detail['referrer'],
|
|
106
|
'user_agent' => $detail['user_agent'],
|
124
|
'user_agent' => $detail['user_agent'],
|
|
107
|
];
|
125
|
];
|
|
108
|
- $res = Http::withoutVerifying()->post($website . 'api/traffic_visit/', $data)->json();
|
126
|
+ $res = Http::withoutVerifying()->timeout(10)->post($website . 'api/traffic_visit/', $data)->json();
|
|
109
|
if (empty($res['status']) || $res['status'] != 200) {
|
127
|
if (empty($res['status']) || $res['status'] != 200) {
|
|
110
|
$log->status = ReInquiryDetailLog::STATUS_FAIL;
|
128
|
$log->status = ReInquiryDetailLog::STATUS_FAIL;
|
|
111
|
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
|
129
|
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
|
|
@@ -201,7 +219,7 @@ class postInquiry extends Command |
|
@@ -201,7 +219,7 @@ class postInquiry extends Command |
|
201
|
} else {
|
219
|
} else {
|
|
202
|
$data['__amp_source_origin'] = trim($website, '/');
|
220
|
$data['__amp_source_origin'] = trim($website, '/');
|
|
203
|
}
|
221
|
}
|
|
204
|
- $res = Http::withoutVerifying()->withHeaders(['User-Agent' => $detail['user_agent']])->post($website . 'api/inquiryQd/', $data)->json();
|
222
|
+ $res = Http::withoutVerifying()->timeout(10)->withHeaders(['User-Agent' => $detail['user_agent']])->post($website . 'api/inquiryQd/', $data)->json();
|
|
205
|
if (empty($res['code']) || $res['code'] != 200) {
|
223
|
if (empty($res['code']) || $res['code'] != 200) {
|
|
206
|
$log->status = ReInquiryDetailLog::STATUS_FAIL;
|
224
|
$log->status = ReInquiryDetailLog::STATUS_FAIL;
|
|
207
|
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
|
225
|
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
|
|
@@ -225,7 +243,7 @@ class postInquiry extends Command |
|
@@ -225,7 +243,7 @@ class postInquiry extends Command |
|
225
|
'source' => 5,
|
243
|
'source' => 5,
|
|
226
|
];
|
244
|
];
|
|
227
|
|
245
|
|
|
228
|
- $result = Http::withoutVerifying()->post('https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data);
|
246
|
+ $result = Http::withoutVerifying()->timeout(10)->post('https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data);
|
|
229
|
$res = $result->json();
|
247
|
$res = $result->json();
|
|
230
|
//兼容接口返回格式
|
248
|
//兼容接口返回格式
|
|
231
|
if (!empty($res['data'][0]['status'])) {
|
249
|
if (!empty($res['data'][0]['status'])) {
|
|
@@ -255,7 +273,7 @@ class postInquiry extends Command |
|
@@ -255,7 +273,7 @@ class postInquiry extends Command |
|
255
|
ksort($data);
|
273
|
ksort($data);
|
|
256
|
$data['token'] = md5( json_encode($data, JSON_UNESCAPED_UNICODE ) . date("Y-m-d"));
|
274
|
$data['token'] = md5( json_encode($data, JSON_UNESCAPED_UNICODE ) . date("Y-m-d"));
|
|
257
|
$url = 'https://' . $detail['re_website'] . '/index.php?route=api/ai_inquiry/add';
|
275
|
$url = 'https://' . $detail['re_website'] . '/index.php?route=api/ai_inquiry/add';
|
|
258
|
- $res = Http::withoutVerifying()->post($url, $data)->json();
|
276
|
+ $res = Http::withoutVerifying()->timeout(10)->post($url, $data)->json();
|
|
259
|
if (empty($res['code']) || $res['code'] != 200) {
|
277
|
if (empty($res['code']) || $res['code'] != 200) {
|
|
260
|
$log->status = ReInquiryDetailLog::STATUS_FAIL;
|
278
|
$log->status = ReInquiryDetailLog::STATUS_FAIL;
|
|
261
|
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
|
279
|
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
|
|
@@ -274,7 +292,7 @@ class postInquiry extends Command |
|
@@ -274,7 +292,7 @@ class postInquiry extends Command |
|
274
|
'post_id' => $log['url'],
|
292
|
'post_id' => $log['url'],
|
|
275
|
'message' => $detail['message'],
|
293
|
'message' => $detail['message'],
|
|
276
|
];
|
294
|
];
|
|
277
|
- $res = Http::withoutVerifying()->post('https://fob.ai.cc/api/ad_to_scrm', $data)->json();
|
295
|
+ $res = Http::withoutVerifying()->timeout(10)->post('https://fob.ai.cc/api/ad_to_scrm', $data)->json();
|
|
278
|
if (empty($res['status']) || $res['status'] != 200) {
|
296
|
if (empty($res['status']) || $res['status'] != 200) {
|
|
279
|
$log->status = ReInquiryDetailLog::STATUS_FAIL;
|
297
|
$log->status = ReInquiryDetailLog::STATUS_FAIL;
|
|
280
|
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
|
298
|
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
|