作者 周海龙

合并分支 'zhl' 到 'master'

修改部分流程



查看合并请求 !1120
@@ -71,76 +71,95 @@ class SyncInquiryRelay extends Command @@ -71,76 +71,95 @@ class SyncInquiryRelay extends Command
71 */ 71 */
72 public function getInquirySzcm() 72 public function getInquirySzcm()
73 { 73 {
74 - $max_origin_key = InquiryInfo::where('type', 4)->orderBy('origin_key', 'desc')->value('origin_key'); 74 + $max_origin_key = InquiryInfo::where('type', InquiryInfo::TYPE_SPIDER)->orderBy('origin_key', 'desc')->value('origin_key');
75 if ($max_origin_key) { 75 if ($max_origin_key) {
76 $start_id = $max_origin_key + 1; 76 $start_id = $max_origin_key + 1;
77 } else { 77 } else {
78 $start_id = 65029; 78 $start_id = 65029;
79 } 79 }
80 80
  81 + // TODO 由于该渠道数据不规则, 可能某个ID获取不到数据, 无法判断是因为已经没有数据了, 还是因为解析问题导致, 所以当未获取到数据时, 多向后取几次数据, 连续几次没有数据, 就认为已经获取到最大数据。
81 $service = new InquiryRelayService(); 82 $service = new InquiryRelayService();
  83 + $pre = 0;
82 while ($start_id > 0) { 84 while ($start_id > 0) {
83 $result = $service->getInquirySzcm($start_id); 85 $result = $service->getInquirySzcm($start_id);
  86 + if (empty($result) && $pre <= 3) {
  87 + $start_id++;
  88 + $pre++;
  89 + continue;
  90 + }
  91 +
84 if ($result) { 92 if ($result) {
85 - $this->saveDate($result, 4);  
86 - $start_id += 1;  
87 - } else {  
88 - $start_id = 0; 93 + $this->saveDate($result, InquiryInfo::TYPE_SPIDER);
  94 + $start_id++;
  95 + $pre = 0;
89 } 96 }
  97 +
  98 + if ($pre > 3)
  99 + break;
90 } 100 }
  101 + return true;
91 } 102 }
92 103
  104 + /**
  105 + * 询盘数据入库
  106 + * @param $data
  107 + * @param $type
  108 + * @return bool
  109 + */
93 public function saveDate($data, $type) 110 public function saveDate($data, $type)
94 { 111 {
95 $model = new InquiryInfo(); 112 $model = new InquiryInfo();
96 $message_sign = md5($data['name'] . $data['email'] . $data['phone'] . $data['ip'] . $data['time']); 113 $message_sign = md5($data['name'] . $data['email'] . $data['phone'] . $data['ip'] . $data['time']);
97 $inquiry_info = $model->where('message_sign', $message_sign)->first(); 114 $inquiry_info = $model->where('message_sign', $message_sign)->first();
98 - if (!$inquiry_info) {  
99 - //没有IP,根据submit_country获取  
100 - if (empty($data['ip']) && isset($data['submit_country']) && $data['submit_country']) {  
101 - $chinese_name = DB::table('gl_world_country_city')->where('pid', 0)->where('iso2', $data['submit_country'])->value('chinese_name');  
102 - $data['ip'] = $this->getIpData($chinese_name);  
103 - } 115 + if ($inquiry_info)
  116 + return true;
104 117
105 - //获取country  
106 - $country = '';  
107 - if ($data['ip']) {  
108 - $country = file_get_contents("http://ip.globalso.com?ip=" . $data['ip']);  
109 - } 118 + //没有IP,根据submit_country获取
  119 + if (empty($data['ip']) && isset($data['submit_country']) && $data['submit_country']) {
  120 + $chinese_name = DB::table('gl_world_country_city')->where('pid', 0)->where('iso2', $data['submit_country'])->value('chinese_name');
  121 + $data['ip'] = $this->getIpData($chinese_name);
  122 + }
110 123
111 - //翻译message  
112 - $message_cn = '';  
113 - $re_message_trans = Translate::translate($data['message'], 'zh');  
114 - if (isset($re_message_trans[0]['code']) && $re_message_trans[0]['code'] == 200) {  
115 - $message_cn = $re_message_trans[0]['texts'];  
116 - } 124 + //获取country
  125 + $country = '';
  126 + if ($data['ip']) {
  127 + $country = file_get_contents("http://ip.globalso.com?ip=" . $data['ip']);
  128 + }
117 129
118 - //获取页面上title和keywords  
119 - $html = curl_c($data['refer'], false); 130 + //翻译message
  131 + $message_cn = '';
  132 + $re_message_trans = Translate::translate($data['message'], 'zh');
  133 + if (isset($re_message_trans[0]['code']) && $re_message_trans[0]['code'] == 200) {
  134 + $message_cn = $re_message_trans[0]['texts'];
  135 + }
120 136
121 - if (empty($data['title'])) {  
122 - preg_match_all('/<title>([\w\W]*?)<\/title>/', $html, $matches);  
123 - if (!empty($matches[1])) {  
124 - $data['title'] = substr($matches[1][0], 0, 255);  
125 - }  
126 - } 137 + //获取页面上title和keywords
  138 + $html = curl_c($data['refer'], false);
127 139
128 - $keywords = '';  
129 - preg_match_all('/<meta\s+[^>]*?name=[\'|\"]keywords[\'|\"]\s+[^>]*?content=[\'|\"]([\w\W]*?)[\'|\"]/', $html, $matches); 140 + if (empty($data['title'])) {
  141 + preg_match_all('/<title>([\w\W]*?)<\/title>/', $html, $matches);
130 if (!empty($matches[1])) { 142 if (!empty($matches[1])) {
131 - $keywords = substr($matches[1][0], 0, 255); 143 + $data['title'] = substr($matches[1][0], 0, 255);
132 } 144 }
  145 + }
133 146
134 - if (empty($data['origin_key'])) {  
135 - $data['origin_key'] = 0;  
136 - } 147 + $keywords = '';
  148 + preg_match_all('/<meta\s+[^>]*?name=[\'|\"]keywords[\'|\"]\s+[^>]*?content=[\'|\"]([\w\W]*?)[\'|\"]/', $html, $matches);
  149 + if (!empty($matches[1])) {
  150 + $keywords = substr($matches[1][0], 0, 255);
  151 + }
137 152
138 - if (empty($data['image'])) {  
139 - $data['image'] = '';  
140 - } 153 + if (empty($data['origin_key'])) {
  154 + $data['origin_key'] = 0;
  155 + }
141 156
142 - $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']); 157 + if (empty($data['image'])) {
  158 + $data['image'] = '';
143 } 159 }
  160 +
  161 + $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']);
  162 + return true;
144 } 163 }
145 164
146 /** 165 /**