作者 周海龙

合并分支 'zhl' 到 'master'

修改部分流程



查看合并请求 !1120
... ... @@ -71,76 +71,95 @@ class SyncInquiryRelay extends Command
*/
public function getInquirySzcm()
{
$max_origin_key = InquiryInfo::where('type', 4)->orderBy('origin_key', 'desc')->value('origin_key');
$max_origin_key = InquiryInfo::where('type', InquiryInfo::TYPE_SPIDER)->orderBy('origin_key', 'desc')->value('origin_key');
if ($max_origin_key) {
$start_id = $max_origin_key + 1;
} else {
$start_id = 65029;
}
// TODO 由于该渠道数据不规则, 可能某个ID获取不到数据, 无法判断是因为已经没有数据了, 还是因为解析问题导致, 所以当未获取到数据时, 多向后取几次数据, 连续几次没有数据, 就认为已经获取到最大数据。
$service = new InquiryRelayService();
$pre = 0;
while ($start_id > 0) {
$result = $service->getInquirySzcm($start_id);
if (empty($result) && $pre <= 3) {
$start_id++;
$pre++;
continue;
}
if ($result) {
$this->saveDate($result, 4);
$start_id += 1;
} else {
$start_id = 0;
$this->saveDate($result, InquiryInfo::TYPE_SPIDER);
$start_id++;
$pre = 0;
}
if ($pre > 3)
break;
}
return true;
}
/**
* 询盘数据入库
* @param $data
* @param $type
* @return bool
*/
public function saveDate($data, $type)
{
$model = new InquiryInfo();
$message_sign = md5($data['name'] . $data['email'] . $data['phone'] . $data['ip'] . $data['time']);
$inquiry_info = $model->where('message_sign', $message_sign)->first();
if (!$inquiry_info) {
//没有IP,根据submit_country获取
if (empty($data['ip']) && isset($data['submit_country']) && $data['submit_country']) {
$chinese_name = DB::table('gl_world_country_city')->where('pid', 0)->where('iso2', $data['submit_country'])->value('chinese_name');
$data['ip'] = $this->getIpData($chinese_name);
}
if ($inquiry_info)
return true;
//获取country
$country = '';
if ($data['ip']) {
$country = file_get_contents("http://ip.globalso.com?ip=" . $data['ip']);
}
//没有IP,根据submit_country获取
if (empty($data['ip']) && isset($data['submit_country']) && $data['submit_country']) {
$chinese_name = DB::table('gl_world_country_city')->where('pid', 0)->where('iso2', $data['submit_country'])->value('chinese_name');
$data['ip'] = $this->getIpData($chinese_name);
}
//翻译message
$message_cn = '';
$re_message_trans = Translate::translate($data['message'], 'zh');
if (isset($re_message_trans[0]['code']) && $re_message_trans[0]['code'] == 200) {
$message_cn = $re_message_trans[0]['texts'];
}
//获取country
$country = '';
if ($data['ip']) {
$country = file_get_contents("http://ip.globalso.com?ip=" . $data['ip']);
}
//获取页面上title和keywords
$html = curl_c($data['refer'], false);
//翻译message
$message_cn = '';
$re_message_trans = Translate::translate($data['message'], 'zh');
if (isset($re_message_trans[0]['code']) && $re_message_trans[0]['code'] == 200) {
$message_cn = $re_message_trans[0]['texts'];
}
if (empty($data['title'])) {
preg_match_all('/<title>([\w\W]*?)<\/title>/', $html, $matches);
if (!empty($matches[1])) {
$data['title'] = substr($matches[1][0], 0, 255);
}
}
//获取页面上title和keywords
$html = curl_c($data['refer'], false);
$keywords = '';
preg_match_all('/<meta\s+[^>]*?name=[\'|\"]keywords[\'|\"]\s+[^>]*?content=[\'|\"]([\w\W]*?)[\'|\"]/', $html, $matches);
if (empty($data['title'])) {
preg_match_all('/<title>([\w\W]*?)<\/title>/', $html, $matches);
if (!empty($matches[1])) {
$keywords = substr($matches[1][0], 0, 255);
$data['title'] = substr($matches[1][0], 0, 255);
}
}
if (empty($data['origin_key'])) {
$data['origin_key'] = 0;
}
$keywords = '';
preg_match_all('/<meta\s+[^>]*?name=[\'|\"]keywords[\'|\"]\s+[^>]*?content=[\'|\"]([\w\W]*?)[\'|\"]/', $html, $matches);
if (!empty($matches[1])) {
$keywords = substr($matches[1][0], 0, 255);
}
if (empty($data['image'])) {
$data['image'] = '';
}
if (empty($data['origin_key'])) {
$data['origin_key'] = 0;
}
$model->createInquiry($data['name'], $data['phone'], $data['email'], $data['ip'], $country, $data['message'], $message_cn, $type, $data['time'], $data['refer'], $data['title'], $keywords, $message_sign, $data['origin_key'], $data['image']);
if (empty($data['image'])) {
$data['image'] = '';
}
$model->createInquiry($data['name'], $data['phone'], $data['email'], $data['ip'], $country, $data['message'], $message_cn, $type, $data['time'], $data['refer'], $data['title'], $keywords, $message_sign, $data['origin_key'], $data['image']);
return true;
}
/**
... ...