作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into master-server

@@ -62,7 +62,7 @@ class InquiryDelay extends Command @@ -62,7 +62,7 @@ class InquiryDelay extends Command
62 * @time :2023/7/13 14:39 62 * @time :2023/7/13 14:39
63 */ 63 */
64 public function inquiryForward($post_data){ 64 public function inquiryForward($post_data){
65 - $url = 'https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f'; 65 + $url = 'https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f';
66 $post_data_new = []; 66 $post_data_new = [];
67 $post_data_new['refer'] = $post_data['url']; 67 $post_data_new['refer'] = $post_data['url'];
68 $post_data_new['name'] = $post_data['name']; 68 $post_data_new['name'] = $post_data['name'];
@@ -57,8 +57,11 @@ class SyncInquiryProject extends Command @@ -57,8 +57,11 @@ class SyncInquiryProject extends Command
57 */ 57 */
58 public function handle() 58 public function handle()
59 { 59 {
  60 + echo '开始同步v5' . PHP_EOL;
60 $this->syncGloV5(); 61 $this->syncGloV5();
  62 + echo '开始同步v6' . PHP_EOL;
61 $this->syncGloV6(); 63 $this->syncGloV6();
  64 + echo '删除过期数据' . PHP_EOL;
62 $this->deleteExpire(); 65 $this->deleteExpire();
63 return true; 66 return true;
64 } 67 }
@@ -73,12 +76,14 @@ class SyncInquiryProject extends Command @@ -73,12 +76,14 @@ class SyncInquiryProject extends Command
73 $channel = Channel::pluck('contact_mobile', 'id')->toArray(); 76 $channel = Channel::pluck('contact_mobile', 'id')->toArray();
74 foreach ($result as $key=>$val) 77 foreach ($result as $key=>$val)
75 { 78 {
  79 + echo '同步项目:' . $val['postid'] . ' - ' . $val['company'] . PHP_EOL;
76 // 记录渠道商, 如果渠道有问题, 记录日志, 跳过当前项目, 处理数据后, 第二天再重新同步 80 // 记录渠道商, 如果渠道有问题, 记录日志, 跳过当前项目, 处理数据后, 第二天再重新同步
77 $channel_flag = false; 81 $channel_flag = false;
78 $channel_tmp = []; 82 $channel_tmp = [];
79 foreach ($val['agent'] as $v) { 83 foreach ($val['agent'] as $v) {
80 $channel_id = array_search($v, $channel); 84 $channel_id = array_search($v, $channel);
81 if (empty($channel_id)) { 85 if (empty($channel_id)) {
  86 + $this->log('ERROR 代理商找不到不记录当前项目, 代理商手机号码:' . $v);
82 $channel_flag = true; 87 $channel_flag = true;
83 break; 88 break;
84 } 89 }
@@ -106,16 +111,32 @@ class SyncInquiryProject extends Command @@ -106,16 +111,32 @@ class SyncInquiryProject extends Command
106 */ 111 */
107 public function syncGloV5Route($project_id, $route_domain) 112 public function syncGloV5Route($project_id, $route_domain)
108 { 113 {
109 - $result = http_get($route_domain . 'k_u_api.php'); 114 + try{
  115 + $result = http_get($route_domain . 'k_u_api.php');
  116 + if (empty($result)) {
  117 + $this->log('syncGloV5Route 未获取到路由信息:' . $project_id . ', 路由获取地址:' . $route_domain . 'k_u_api.php');
  118 + return false;
  119 + }
  120 + } catch (\Exception $e) {
  121 + $this->log('syncGloV5Route 未获取到路由信息:' . $project_id . ', 路由获取地址:' . $route_domain . 'k_u_api.php' . ', 错误信息:' . $e->getMessage());
  122 + echo 'syncGloV5Route 未获取到路由信息:' . $project_id . ', 路由获取地址:' . $route_domain . 'k_u_api.php' . ', 错误信息:' . $e->getMessage() . PHP_EOL;
  123 + return false;
  124 + }
  125 +
110 foreach ($result as $key=>$val) { 126 foreach ($result as $key=>$val) {
111 try { 127 try {
112 $tmp = explode('|', $val); 128 $tmp = explode('|', $val);
113 $url_tmp = parse_url($tmp[0]); 129 $url_tmp = parse_url($tmp[0]);
114 $route = trim($url_tmp['path'], '/'); 130 $route = trim($url_tmp['path'], '/');
115 $title = str_replace('+', ' ', $tmp[1]); 131 $title = str_replace('+', ' ', $tmp[1]);
  132 + if (strlen($title) > 200 || strlen($route) > 200) {
  133 + $this->log('syncGloV5Route 路由或标题过长,无效记录');
  134 + continue;
  135 + }
116 InquiryProjectRoute::saveProjectRoute($project_id, $title, $route); 136 InquiryProjectRoute::saveProjectRoute($project_id, $title, $route);
117 } catch (\Exception $e) { 137 } catch (\Exception $e) {
118 $this->log('syncGloV5Route 解析路径:' . $val . ', 错误信息:' . $e->getMessage()); 138 $this->log('syncGloV5Route 解析路径:' . $val . ', 错误信息:' . $e->getMessage());
  139 + echo 'syncGloV5Route 解析路径:' . $val . ', 错误信息:' . $e->getMessage() . PHP_EOL;
119 } 140 }
120 } 141 }
121 return true; 142 return true;
@@ -140,6 +161,7 @@ class SyncInquiryProject extends Command @@ -140,6 +161,7 @@ class SyncInquiryProject extends Command
140 // 获取所有项目域名 161 // 获取所有项目域名
141 $domains = DomainInfo::whereIn('project_id', $project->pluck('id')->toArray())->pluck('domain', 'project_id')->toArray(); 162 $domains = DomainInfo::whereIn('project_id', $project->pluck('id')->toArray())->pluck('domain', 'project_id')->toArray();
142 foreach ($project as $key=>$val) { 163 foreach ($project as $key=>$val) {
  164 + echo '同步项目:' . $val->id . ' - ' . $val->title . PHP_EOL;
143 // 过滤暂停优化项目, 映射类型2, model没有定义常量 165 // 过滤暂停优化项目, 映射类型2, model没有定义常量
144 if (in_array(2, $val->level)) 166 if (in_array(2, $val->level))
145 continue; 167 continue;
@@ -167,6 +189,7 @@ class SyncInquiryProject extends Command @@ -167,6 +189,7 @@ class SyncInquiryProject extends Command
167 // 产品数量会比较多, 所以使用分页 同步数据 189 // 产品数量会比较多, 所以使用分页 同步数据
168 $id = 0; 190 $id = 0;
169 while (true) { 191 while (true) {
  192 + echo '同步项目路由:' . $id . PHP_EOL;
170 $product = Product::where('status', Product::STATUS_ON)->where('id', '>', $id)->orderBy('id', 'asc')->limit(1000)->get(['id', 'title', 'route']); 193 $product = Product::where('status', Product::STATUS_ON)->where('id', '>', $id)->orderBy('id', 'asc')->limit(1000)->get(['id', 'title', 'route']);
171 if ($product->isEmpty()) 194 if ($product->isEmpty())
172 break; 195 break;
@@ -243,7 +243,7 @@ class postInquiry extends Command @@ -243,7 +243,7 @@ class postInquiry extends Command
243 'source' => 5, 243 'source' => 5,
244 ]; 244 ];
245 245
246 - $result = Http::withoutVerifying()->timeout(30)->post('https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data); 246 + $result = Http::withoutVerifying()->timeout(30)->post('https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f', $data);
247 $res = $result->json(); 247 $res = $result->json();
248 //兼容接口返回格式 248 //兼容接口返回格式
249 if (!empty($res['data'][0]['status'])) { 249 if (!empty($res['data'][0]['status'])) {
@@ -255,7 +255,7 @@ class postInquiry extends Command @@ -255,7 +255,7 @@ class postInquiry extends Command
255 $log->remark = mb_substr($res['message'] ?? '', 0, 200); 255 $log->remark = mb_substr($res['message'] ?? '', 0, 200);
256 $log->save(); 256 $log->save();
257 257
258 - Log::channel('inquiry_relay')->error('inquiry_relay v4|v5 inquiry error', [$result->body(), 'https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data]); 258 + Log::channel('inquiry_relay')->error('inquiry_relay v4|v5 inquiry error', [$result->body(), 'https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f', $data]);
259 return false; 259 return false;
260 } 260 }
261 return true; 261 return true;
@@ -17,7 +17,7 @@ use GuzzleHttp\Exception\GuzzleException; @@ -17,7 +17,7 @@ use GuzzleHttp\Exception\GuzzleException;
17 class FormGlobalsoApi 17 class FormGlobalsoApi
18 { 18 {
19 //接口地址 19 //接口地址
20 - protected $url = 'https://form.globalso.com'; 20 + protected $url = 'https://www.globalso.site';
21 21
22 /** 22 /**
23 * 设置询盘通知 23 * 设置询盘通知
@@ -179,7 +179,7 @@ class FormGlobalsoApi @@ -179,7 +179,7 @@ class FormGlobalsoApi
179 'num'=>15, 179 'num'=>15,
180 ]; 180 ];
181 $queryString = http_build_query($data); 181 $queryString = http_build_query($data);
182 - $url = "https://form.globalso.com/api/external-interface/domain_con/15243d63ed5a5738?".$queryString; 182 + $url = "https://www.globalso.site/api/external-interface/domain_con/15243d63ed5a5738?".$queryString;
183 try { 183 try {
184 $res = http_get($url,['charset=utf-8']); 184 $res = http_get($url,['charset=utf-8']);
185 } catch (\Exception | GuzzleException $e) { 185 } catch (\Exception | GuzzleException $e) {
@@ -207,7 +207,7 @@ class FormGlobalsoApi @@ -207,7 +207,7 @@ class FormGlobalsoApi
207 'sta_date'=>$month, 207 'sta_date'=>$month,
208 ]; 208 ];
209 $queryString = http_build_query($data); 209 $queryString = http_build_query($data);
210 - $url = 'https://form.globalso.com/api/external-interface/country_con/15243d63ed5a5738?'.$queryString; 210 + $url = 'https://www.globalso.site/api/external-interface/country_con/15243d63ed5a5738?'.$queryString;
211 $res = http_get($url,['charset=utf-8']); 211 $res = http_get($url,['charset=utf-8']);
212 echo date('Y-m-d H:i:s') . '数据:'.json_encode($res) . PHP_EOL; 212 echo date('Y-m-d H:i:s') . '数据:'.json_encode($res) . PHP_EOL;
213 return $res; 213 return $res;
@@ -501,7 +501,7 @@ if (!function_exists('getInquiryInformation')) { @@ -501,7 +501,7 @@ if (!function_exists('getInquiryInformation')) {
501 { 501 {
502 $token = md5($domain . date("Y-m-d")); 502 $token = md5($domain . date("Y-m-d"));
503 $source = '1,3'; 503 $source = '1,3';
504 - $url = "https://form.globalso.com/api/external-interface/country_con/15243d63ed5a5738?domain={$domain}&token={$token}&source={$source}&sta_date={$sta_date}"; 504 + $url = "https://www.globalso.site/api/external-interface/country_con/15243d63ed5a5738?domain={$domain}&token={$token}&source={$source}&sta_date={$sta_date}";
505 $client = new Client(['verify' => false]); 505 $client = new Client(['verify' => false]);
506 $http = $client->get($url); 506 $http = $client->get($url);
507 $data = []; 507 $data = [];
@@ -172,7 +172,7 @@ class InquiryInfoLogic extends BaseLogic @@ -172,7 +172,7 @@ class InquiryInfoLogic extends BaseLogic
172 * @time :2023/7/13 14:39 172 * @time :2023/7/13 14:39
173 */ 173 */
174 public function inquiryForward($post_data){ 174 public function inquiryForward($post_data){
175 - $url = 'https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f'; 175 + $url = 'https://www.globalso.site/api/external-interface/add/fa043f9cbec6b38f';
176 $post_data_new = []; 176 $post_data_new = [];
177 $post_data_new['refer'] = $post_data['url']; 177 $post_data_new['refer'] = $post_data['url'];
178 $post_data_new['name'] = $post_data['name']; 178 $post_data_new['name'] = $post_data['name'];
@@ -153,4 +153,16 @@ class DomainInfo extends Base @@ -153,4 +153,16 @@ class DomainInfo extends Base
153 $value = Arr::s2a($value); 153 $value = Arr::s2a($value);
154 return $value; 154 return $value;
155 } 155 }
  156 +
  157 + public static function getCacheInfoByProjectId($project_id){
  158 + $cache_key = 'DOMAIN_INFO_BY_PROJECT_ID_' . $project_id;
  159 + $data = Cache::get($cache_key);
  160 + if(!$data){
  161 + $data = DomainInfo::where('project_id', $project_id)->first();
  162 + if($data){
  163 + Cache::put($cache_key, $data, 3600);
  164 + }
  165 + }
  166 + return $data;
  167 + }
156 } 168 }
@@ -23,7 +23,7 @@ class InquiryRelayService @@ -23,7 +23,7 @@ class InquiryRelayService
23 { 23 {
24 $date = date('Y-m-d'); 24 $date = date('Y-m-d');
25 $token = md5($date . 'qqs'); 25 $token = md5($date . 'qqs');
26 - $url = 'https://form.globalso.com/api/external-interface/echo_inquriy/d1483a8e57cb485a?date=' . $date . '&token=' . $token . '&type=2'; 26 + $url = 'https://www.globalso.site/api/external-interface/echo_inquriy/d1483a8e57cb485a?date=' . $date . '&token=' . $token . '&type=2';
27 $result = http_get($url); 27 $result = http_get($url);
28 return $result; 28 return $result;
29 } 29 }
@@ -105,4 +105,8 @@ class InquiryRelayService @@ -105,4 +105,8 @@ class InquiryRelayService
105 curl_close($ch); 105 curl_close($ch);
106 return $result; 106 return $result;
107 } 107 }
  108 +
  109 +########################################################################################################################
  110 +# 询盘结束, 同步项目及路由 #
  111 +########################################################################################################################
108 } 112 }
@@ -29,7 +29,7 @@ class SyncService @@ -29,7 +29,7 @@ class SyncService
29 public function projectAcceptAddress($project_id = 0) 29 public function projectAcceptAddress($project_id = 0)
30 { 30 {
31 try { 31 try {
32 - $url = 'https://form.globalso.com/api/globalsov6'; 32 + $url = 'https://www.globalso.site/api/globalsov6';
33 // 项目信息 33 // 项目信息
34 $project = Project::with('deploy_build')->with('deploy_optimize')->where(['id'=>$project_id])->first(); 34 $project = Project::with('deploy_build')->with('deploy_optimize')->where(['id'=>$project_id])->first();
35 // 不满足条件 不同步到表单系统 35 // 不满足条件 不同步到表单系统
@@ -75,7 +75,7 @@ class SyncSubmitTaskService @@ -75,7 +75,7 @@ class SyncSubmitTaskService
75 } 75 }
76 76
77 //域名 过滤国家或ip 77 //域名 过滤国家或ip
78 - $domain_info = DomainInfo::where('project_id', $project['id'])->first(); 78 + $domain_info = DomainInfo::getCacheInfoByProjectId($project['id']);
79 if(!empty($domain_info['not_allow_country'])){ 79 if(!empty($domain_info['not_allow_country'])){
80 $not_allow_countries = CountryCode::whereIn('id', $domain_info['not_allow_country'])->pluck('c_name')->toArray(); 80 $not_allow_countries = CountryCode::whereIn('id', $domain_info['not_allow_country'])->pluck('c_name')->toArray();
81 if(in_array($data['country'], $not_allow_countries)){ 81 if(in_array($data['country'], $not_allow_countries)){
@@ -88,9 +88,11 @@ class SyncSubmitTaskService @@ -88,9 +88,11 @@ class SyncSubmitTaskService
88 } 88 }
89 } 89 }
90 90
  91 + $time = time();
91 if(!ProjectServer::useProject($project['id'])){ 92 if(!ProjectServer::useProject($project['id'])){
92 return false; 93 return false;
93 } 94 }
  95 + echo date('Y-m-d H:i:s') . ' | useProject time:' . (time() - $time) . PHP_EOL;
94 96
95 $action = $task['type']; 97 $action = $task['type'];
96 98
@@ -106,7 +108,7 @@ class SyncSubmitTaskService @@ -106,7 +108,7 @@ class SyncSubmitTaskService
106 } 108 }
107 $filed == 'email' && $action = 'subscribe'; 109 $filed == 'email' && $action = 'subscribe';
108 } 110 }
109 - 111 +
110 $handler = new self(); 112 $handler = new self();
111 return $handler->$action($data, $date, $task['id'], $task['traffic']); 113 return $handler->$action($data, $date, $task['id'], $task['traffic']);
112 } 114 }
@@ -297,6 +299,17 @@ class SyncSubmitTaskService @@ -297,6 +299,17 @@ class SyncSubmitTaskService
297 if(!$ip){ 299 if(!$ip){
298 return ''; 300 return '';
299 } 301 }
  302 +
  303 +// $client = new \GuzzleHttp\Client();
  304 +// $res = $client->request('GET', "http://ip.globalso.com?ip=".$ip, [
  305 +// 'proxy' => env('CURL_PROXY'), // 代理服务器地址和端口号
  306 +// ]);
  307 +// if($res->getStatusCode() == 200){
  308 +// return $res->getBody()->getContents();
  309 +// }else{
  310 +// return '';
  311 +// }
  312 +
300 $res = Http::withoutVerifying()->get('http://ip.globalso.com', ['ip' => $ip]); 313 $res = Http::withoutVerifying()->get('http://ip.globalso.com', ['ip' => $ip]);
301 if($res->status() == 200){ 314 if($res->status() == 200){
302 return $res->body(); 315 return $res->body();
@@ -334,7 +347,9 @@ class SyncSubmitTaskService @@ -334,7 +347,9 @@ class SyncSubmitTaskService
334 if($ip == "127.0.0.1"){ 347 if($ip == "127.0.0.1"){
335 throw new InquiryFilterException('127.0.0.1过滤'); 348 throw new InquiryFilterException('127.0.0.1过滤');
336 } 349 }
  350 + $time = time();
337 $country = self::getCountryByIp($ip); 351 $country = self::getCountryByIp($ip);
  352 + echo date('Y-m-d H:i:s') . ' | getCountryByIp time:' . (time() - $time) . PHP_EOL;
338 //访问记录过滤国内 353 //访问记录过滤国内
339 if ($type == SyncSubmitTask::TYPE_VISIT && $country == "中国" && !$project->is_record_china_visit){ 354 if ($type == SyncSubmitTask::TYPE_VISIT && $country == "中国" && !$project->is_record_china_visit){
340 throw new InquiryFilterException('中国内地过滤'); 355 throw new InquiryFilterException('中国内地过滤');