作者 lyh
... ... @@ -372,11 +372,11 @@ class RelayInquiry extends Command
$user_agent, $referrer, $urls, $is_v6, date('Y-m-d H:i:s', $start_time + $seconds));
foreach ($urls as $k=>$v){
$pre++;
$seconds += rand(3,10);
$seconds += rand(5,60);
ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_VISIT, $pre, $v, date('Y-m-d H:i:s', $start_time + $seconds));
// 最后一次访问询盘 加上询盘
if($k+1 >= count($urls)){
$seconds += rand(10,30);
$seconds += rand(30,120);
$pre++;
ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_INQUIRY, $pre, $v, date('Y-m-d H:i:s', $start_time + $seconds));
}
... ...
... ... @@ -47,7 +47,6 @@ class postInquiry extends Command
while (true) {
$list = ReInquiryDetailLog::where('status', ReInquiryDetailLog::STATUS_INIT)->where('start_at', '<=', date('Y-m-d H:i:s'))->limit(100)->get();
if (!$list->count()){
//5分钟同步一次
sleep(1);
}
// 询盘数据入库
... ... @@ -67,6 +66,25 @@ class postInquiry extends Command
$this->output('开始执行' . $val->id);
try {
$detail = ReInquiryDetail::find($val['detail_id']);
//防止 程序中断 启动时 同一时间一下就发了
$last_log = ReInquiryDetailLog::where('detail_id', $val['detail_id'])->where('id', '<', $val['id'])->orderBy('id', 'desc')->first();
//不是第一个 或者 上一个处理失败了 直接处理
if(!empty($last_log)){
//上一个还没有处理 直接跳过
if($last_log->status == ReInquiryDetailLog::STATUS_INIT){
continue;
}
//上一个处理完成 直接跳过
if($last_log->status == ReInquiryDetailLog::STATUS_SUCCESS){
//上次处理时间间隔达到没
$interval = strtotime($val->start_at) - strtotime($last_log->start_at);
if(time() - strtotime($last_log->updated_at) < $interval){
continue;
}
}
}
if($val['type'] == 1){
$this->visit($detail, $val);
}else{
... ... @@ -105,7 +123,7 @@ class postInquiry extends Command
'referrer_url' => $detail['referrer'],
'user_agent' => $detail['user_agent'],
];
$res = Http::withoutVerifying()->post($website . 'api/traffic_visit/', $data)->json();
$res = Http::withoutVerifying()->timeout(10)->post($website . 'api/traffic_visit/', $data)->json();
if (empty($res['status']) || $res['status'] != 200) {
$log->status = ReInquiryDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
... ... @@ -201,7 +219,7 @@ class postInquiry extends Command
} else {
$data['__amp_source_origin'] = trim($website, '/');
}
$res = Http::withoutVerifying()->withHeaders(['User-Agent' => $detail['user_agent']])->post($website . 'api/inquiryQd/', $data)->json();
$res = Http::withoutVerifying()->timeout(10)->withHeaders(['User-Agent' => $detail['user_agent']])->post($website . 'api/inquiryQd/', $data)->json();
if (empty($res['code']) || $res['code'] != 200) {
$log->status = ReInquiryDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
... ... @@ -225,7 +243,7 @@ class postInquiry extends Command
'source' => 5,
];
$result = Http::withoutVerifying()->post('https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data);
$result = Http::withoutVerifying()->timeout(10)->post('https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data);
$res = $result->json();
//兼容接口返回格式
if (!empty($res['data'][0]['status'])) {
... ... @@ -255,7 +273,7 @@ class postInquiry extends Command
ksort($data);
$data['token'] = md5( json_encode($data, JSON_UNESCAPED_UNICODE ) . date("Y-m-d"));
$url = 'https://' . $detail['re_website'] . '/index.php?route=api/ai_inquiry/add';
$res = Http::withoutVerifying()->post($url, $data)->json();
$res = Http::withoutVerifying()->timeout(10)->post($url, $data)->json();
if (empty($res['code']) || $res['code'] != 200) {
$log->status = ReInquiryDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
... ... @@ -274,7 +292,7 @@ class postInquiry extends Command
'post_id' => $log['url'],
'message' => $detail['message'],
];
$res = Http::withoutVerifying()->post('https://fob.ai.cc/api/ad_to_scrm', $data)->json();
$res = Http::withoutVerifying()->timeout(10)->post('https://fob.ai.cc/api/ad_to_scrm', $data)->json();
if (empty($res['status']) || $res['status'] != 200) {
$log->status = ReInquiryDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
... ...