作者 赵彬吉
@@ -9,7 +9,6 @@ use App\Models\RouteMap\RouteMap; @@ -9,7 +9,6 @@ use App\Models\RouteMap\RouteMap;
9 use App\Services\CosService; 9 use App\Services\CosService;
10 use App\Services\ProjectServer; 10 use App\Services\ProjectServer;
11 use Illuminate\Console\Command; 11 use Illuminate\Console\Command;
12 -use Illuminate\Support\Facades\Cache;  
13 use Illuminate\Support\Facades\DB; 12 use Illuminate\Support\Facades\DB;
14 use Illuminate\Support\Facades\Redis; 13 use Illuminate\Support\Facades\Redis;
15 14
@@ -77,8 +76,8 @@ class HtmlCollect extends Command @@ -77,8 +76,8 @@ class HtmlCollect extends Command
77 $collect_info->status = CollectTask::STATUS_ING; 76 $collect_info->status = CollectTask::STATUS_ING;
78 $collect_info->save(); 77 $collect_info->save();
79 78
80 - //获取站点正式和测试域名  
81 - $old_info = $this->getOldDomain($project_id, $collect_info->domain); 79 + //获取站点原始域名信息
  80 + $old_info = getOldDomain($project_id, $collect_info->domain);
82 81
83 //采集html页面,下载资源到本地并替换 82 //采集html页面,下载资源到本地并替换
84 try { 83 try {
@@ -183,42 +182,6 @@ class HtmlCollect extends Command @@ -183,42 +182,6 @@ class HtmlCollect extends Command
183 return $task_id; 182 return $task_id;
184 } 183 }
185 184
186 - //获取站点老域名  
187 - protected function getOldDomain($project_id, $domain)  
188 - {  
189 - $key = 'project_collect_domain_' . $project_id;  
190 -  
191 - $data = Cache::get($key);  
192 -  
193 - if (!$data) {  
194 - $web_url_domain = $domain;  
195 - $home_url = $domain;  
196 -  
197 - $url_web_config = 'https://' . $domain . '/wp-content/cache/user_config.text';  
198 - $data_config = curl_c($url_web_config);  
199 - if ($data_config) {  
200 - $web_url_arr = parse_url($data_config['web_url_domain'] ?? '');  
201 - if (isset($web_url_arr['host'])) {  
202 - $web_url_domain = $web_url_arr['host'];  
203 - }  
204 -  
205 - $home_url_arr = parse_url($data_config['home_url'] ?? '');  
206 - if (isset($home_url_arr['host'])) {  
207 - $home_url = $home_url_arr['host'];  
208 - }  
209 - }  
210 -  
211 - $data = [  
212 - 'web_url_domain' => $web_url_domain,  
213 - 'home_url' => $home_url,  
214 - ];  
215 -  
216 - Cache::add($key, $data, 3600);//缓存1小时  
217 - }  
218 -  
219 - return $data;  
220 - }  
221 -  
222 //正则匹配html资源 185 //正则匹配html资源
223 protected function html_preg($html, $project_id, $domain, $web_url_domain, $home_url) 186 protected function html_preg($html, $project_id, $domain, $web_url_domain, $home_url)
224 { 187 {
@@ -9,7 +9,6 @@ use App\Models\RouteMap\RouteMap; @@ -9,7 +9,6 @@ use App\Models\RouteMap\RouteMap;
9 use App\Services\CosService; 9 use App\Services\CosService;
10 use App\Services\ProjectServer; 10 use App\Services\ProjectServer;
11 use Illuminate\Console\Command; 11 use Illuminate\Console\Command;
12 -use Illuminate\Support\Facades\Cache;  
13 use Illuminate\Support\Facades\DB; 12 use Illuminate\Support\Facades\DB;
14 use Illuminate\Support\Facades\Redis; 13 use Illuminate\Support\Facades\Redis;
15 14
@@ -78,7 +77,7 @@ class HtmlLanguageCollect extends Command @@ -78,7 +77,7 @@ class HtmlLanguageCollect extends Command
78 $collect_info->save(); 77 $collect_info->save();
79 78
80 //获取站点正式和测试域名 79 //获取站点正式和测试域名
81 - $old_info = $this->getOldDomain($project_id, $collect_info->domain); 80 + $old_info = getOldDomain($project_id, $collect_info->domain);
82 81
83 //采集html页面,下载资源到本地并替换 82 //采集html页面,下载资源到本地并替换
84 try { 83 try {
@@ -183,42 +182,6 @@ class HtmlLanguageCollect extends Command @@ -183,42 +182,6 @@ class HtmlLanguageCollect extends Command
183 return $task_id; 182 return $task_id;
184 } 183 }
185 184
186 - //获取站点老域名  
187 - protected function getOldDomain($project_id, $domain)  
188 - {  
189 - $key = 'project_collect_lan_domain_' . $project_id;  
190 -  
191 - $data = Cache::get($key);  
192 -  
193 - if (!$data) {  
194 - $web_url_domain = $domain;  
195 - $home_url = $domain;  
196 -  
197 - $url_web_config = 'https://' . $domain . '/wp-content/cache/user_config.text';  
198 - $data_config = curl_c($url_web_config);  
199 - if ($data_config) {  
200 - $web_url_arr = parse_url($data_config['web_url_domain'] ?? '');  
201 - if (isset($web_url_arr['host'])) {  
202 - $web_url_domain = $web_url_arr['host'];  
203 - }  
204 -  
205 - $home_url_arr = parse_url($data_config['home_url'] ?? '');  
206 - if (isset($home_url_arr['host'])) {  
207 - $home_url = $home_url_arr['host'];  
208 - }  
209 - }  
210 -  
211 - $data = [  
212 - 'web_url_domain' => $web_url_domain,  
213 - 'home_url' => $home_url,  
214 - ];  
215 -  
216 - Cache::add($key, $data, 3600);//缓存1小时  
217 - }  
218 -  
219 - return $data;  
220 - }  
221 -  
222 //正则匹配html资源 185 //正则匹配html资源
223 protected function html_preg($html, $project_id, $domain, $web_url_domain, $home_url) 186 protected function html_preg($html, $project_id, $domain, $web_url_domain, $home_url)
224 { 187 {
@@ -73,6 +73,7 @@ class ProjectUpdate extends Command @@ -73,6 +73,7 @@ class ProjectUpdate extends Command
73 $api_type = $task->api_type; 73 $api_type = $task->api_type;
74 $api_url_arr = explode('?', $task->api_url); 74 $api_url_arr = explode('?', $task->api_url);
75 $api_url = $api_url_arr[0]; 75 $api_url = $api_url_arr[0];
  76 + $domain_arr = parse_url($api_url);
76 77
77 $page_size = 20; 78 $page_size = 20;
78 79
@@ -81,26 +82,12 @@ class ProjectUpdate extends Command @@ -81,26 +82,12 @@ class ProjectUpdate extends Command
81 $task->status = UpdateLog::STATUS_ING;//同步中 82 $task->status = UpdateLog::STATUS_ING;//同步中
82 $task->save(); 83 $task->save();
83 84
84 - $domain_arr = parse_url($api_url);  
85 - //获取网站配置  
86 - $link_type = 0;  
87 - $web_url_domain = $domain_arr['host'];  
88 - $home_url = $domain_arr['host'];  
89 - $url_web_config = 'https://' . $domain_arr['host'] . '/wp-content/cache/user_config.text';  
90 - $data_config = curl_c($url_web_config);  
91 - if ($data_config) {  
92 - $link_type = $data_config['link_type'] ?? 0;  
93 -  
94 - $web_url_arr = parse_url($data_config['web_url_domain'] ?? '');  
95 - if (isset($web_url_arr['host'])) {  
96 - $web_url_domain = $web_url_arr['host'];  
97 - } 85 + //获取站点原始域名信息
  86 + $old_info = getOldDomain($project_id, $domain_arr['host']);
  87 + $link_type = $old_info['link_type'];
  88 + $web_url_domain = $old_info['web_url_domain'];
  89 + $home_url = $old_info['home_url'];
98 90
99 - $home_url_arr = parse_url($data_config['home_url'] ?? '');  
100 - if (isset($home_url_arr['host'])) {  
101 - $home_url = $home_url_arr['host'];  
102 - }  
103 - }  
104 //获取所有语种 91 //获取所有语种
105 $language_list = []; 92 $language_list = [];
106 $url_language = 'https://' . $domain_arr['host'] . '/wp-content/plugins/proofreading/json/user_language.json'; 93 $url_language = 'https://' . $domain_arr['host'] . '/wp-content/plugins/proofreading/json/user_language.json';
@@ -108,6 +95,7 @@ class ProjectUpdate extends Command @@ -108,6 +95,7 @@ class ProjectUpdate extends Command
108 if ($data_language) { 95 if ($data_language) {
109 $language_list = array_column($data_language, 'short'); 96 $language_list = array_column($data_language, 'short');
110 } 97 }
  98 +
111 //获取所有页面 99 //获取所有页面
112 $page_list = []; 100 $page_list = [];
113 $url_page = 'https://' . $domain_arr['host'] . '/wp-content/cache/pages_list.json'; 101 $url_page = 'https://' . $domain_arr['host'] . '/wp-content/cache/pages_list.json';
@@ -623,8 +611,11 @@ class ProjectUpdate extends Command @@ -623,8 +611,11 @@ class ProjectUpdate extends Command
623 611
624 $url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path; 612 $url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path;
625 613
626 - if ((empty($host) || $host == $web_url_domain || $host == $home_url) && $path) {  
627 - 614 + if (
  615 + (empty($scheme) || $scheme == 'https' || $scheme == 'http')
  616 + && (empty($host) || (strpos($web_url_domain, $host) !== false) || (strpos($home_url, $host) !== false))
  617 + && $path
  618 + ) {
628 $source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first(); 619 $source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first();
629 if (!$source) { 620 if (!$source) {
630 $new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete); 621 $new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete);
@@ -53,14 +53,10 @@ class UpdateRoute extends Command @@ -53,14 +53,10 @@ class UpdateRoute extends Command
53 * @time :2023/11/20 15:13 53 * @time :2023/11/20 15:13
54 */ 54 */
55 public function handle(){ 55 public function handle(){
56 - $projectModel = new Project();  
57 - $lists = $projectModel->list(['is_upgrade'=>0,'type'=>['!=',0]]);  
58 - foreach ($lists as $k => $v){  
59 - ProjectServer::useProject($v['id']);  
60 - $this->getProductKeyword($v['id']);  
61 - DB::disconnect('custom_mysql');  
62 - }  
63 - echo date('Y-m-d H:i:s') . ' end: 项目id为' . $v['id'] . PHP_EOL; 56 + ProjectServer::useProject(75);
  57 + $this->getProductKeyword();
  58 + DB::disconnect('custom_mysql');
  59 + echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
64 } 60 }
65 61
66 /** 62 /**
@@ -70,12 +66,32 @@ class UpdateRoute extends Command @@ -70,12 +66,32 @@ class UpdateRoute extends Command
70 * @method :post 66 * @method :post
71 * @time :2023/12/8 11:13 67 * @time :2023/12/8 11:13
72 */ 68 */
73 - public function getProductKeyword($id){ 69 + public function getProductKeyword(){
74 $keywordModel = new Keyword(); 70 $keywordModel = new Keyword();
75 - $lists = $keywordModel->list(['route'=>['like','%-1-2-%']]); 71 + $lists = $keywordModel->list(['route'=>null]);
76 if(!empty($lists)){ 72 if(!empty($lists)){
77 - echo date('Y-m-d H:i:s') . ' 错误id:' . $id . PHP_EOL; 73 + foreach ($lists as $v){
  74 + echo date('Y-m-d H:i:s') . 'id :'.$v['id'] . PHP_EOL;
  75 + $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], 75);
  76 + $this->curlDelRoute(['new_route'=>$route]);
  77 + $keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
  78 + echo date('Y-m-d H:i:s') . 'end :'.$route . PHP_EOL;
  79 + }
78 } 80 }
79 } 81 }
80 82
  83 + /**
  84 + * @remark :删除路由通知C端
  85 + * @name :curlDelRoute
  86 + * @author :lyh
  87 + * @method :post
  88 + * @time :2023/11/30 14:43
  89 + */
  90 + public function curlDelRoute($data){
  91 + $data['project_id'] = 75;
  92 + $str = http_build_query($data);
  93 + $url = 'https://www.zrutong.com/api/delHtml/?'.$str;
  94 + curlGet($url);
  95 + return true;
  96 + }
81 } 97 }
@@ -9,6 +9,7 @@ use GuzzleHttp\Client; @@ -9,6 +9,7 @@ use GuzzleHttp\Client;
9 use GuzzleHttp\Exception\GuzzleException; 9 use GuzzleHttp\Exception\GuzzleException;
10 use Illuminate\Support\Carbon; 10 use Illuminate\Support\Carbon;
11 use App\Models\File\File; 11 use App\Models\File\File;
  12 +use Illuminate\Support\Facades\Cache;
12 use Illuminate\Support\Facades\Redis; 13 use Illuminate\Support\Facades\Redis;
13 14
14 define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/'); 15 define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/');
@@ -654,6 +655,7 @@ function redis_add($key,$val,$ttl=3600){ @@ -654,6 +655,7 @@ function redis_add($key,$val,$ttl=3600){
654 * 判断远程地址是否需要下载 655 * 判断远程地址是否需要下载
655 * @param $url 656 * @param $url
656 * @author Akun 657 * @author Akun
  658 + * @return bool
657 * @date 2023/12/08 14:17 659 * @date 2023/12/08 14:17
658 */ 660 */
659 function check_remote_url_down($url){ 661 function check_remote_url_down($url){
@@ -689,3 +691,50 @@ function check_remote_url_down($url){ @@ -689,3 +691,50 @@ function check_remote_url_down($url){
689 691
690 return true; 692 return true;
691 } 693 }
  694 +
  695 +/**
  696 + * 获取升级项目原始域名
  697 + * @param $project_id
  698 + * @param $domain
  699 + * @return array
  700 + * @author Akun
  701 + * @date 2023/12/12 10:52
  702 + */
  703 +function getOldDomain($project_id, $domain)
  704 +{
  705 + $key = 'project_collect_domain_' . $project_id;
  706 +
  707 + $data = Cache::get($key);
  708 +
  709 + if (!$data) {
  710 + $link_type = 0;
  711 + $web_url_domain = $domain;
  712 + $home_url = $domain;
  713 +
  714 + $url_web_config = 'https://' . $domain . '/wp-content/cache/user_config.text';
  715 + $data_config = curl_c($url_web_config);
  716 + if ($data_config) {
  717 + $link_type = $data_config['link_type'] ?? 0;
  718 +
  719 + $web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
  720 + if (isset($web_url_arr['host'])) {
  721 + $web_url_domain = $web_url_arr['host'];
  722 + }
  723 +
  724 + $home_url_arr = parse_url($data_config['home_url'] ?? '');
  725 + if (isset($home_url_arr['host'])) {
  726 + $home_url = $home_url_arr['host'];
  727 + }
  728 + }
  729 +
  730 + $data = [
  731 + 'link_type' => $link_type,
  732 + 'web_url_domain' => $web_url_domain,
  733 + 'home_url' => $home_url,
  734 + ];
  735 +
  736 + Cache::add($key, $data, 3600);//缓存1小时
  737 + }
  738 +
  739 + return $data;
  740 +}
@@ -126,7 +126,6 @@ class KeywordLogic extends BaseLogic @@ -126,7 +126,6 @@ class KeywordLogic extends BaseLogic
126 */ 126 */
127 public function batchAdd(){ 127 public function batchAdd(){
128 try { 128 try {
129 - $idArr = [];  
130 foreach ($this->param['title'] as $v){ 129 foreach ($this->param['title'] as $v){
131 $this->model = new Keyword(); 130 $this->model = new Keyword();
132 $info = $this->model->read(['title'=>$v]); 131 $info = $this->model->read(['title'=>$v]);
@@ -136,16 +135,11 @@ class KeywordLogic extends BaseLogic @@ -136,16 +135,11 @@ class KeywordLogic extends BaseLogic
136 $param['updated_at'] = $param['created_at']; 135 $param['updated_at'] = $param['created_at'];
137 $param['title'] = $v; 136 $param['title'] = $v;
138 $id = $this->model->insertGetId($param); 137 $id = $this->model->insertGetId($param);
139 - $idArr[] = ['id'=>$id,'title'=>$v]; 138 + $route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
  139 + $this->curlDelRoute(['new_route'=>$route]);
  140 + $this->model->edit(['route'=>$route],['id'=>$id]);
140 } 141 }
141 } 142 }
142 - //批量生成路由  
143 - foreach ($idArr as $v){  
144 - $this->model = new Keyword();  
145 - $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $this->user['project_id']);  
146 - $this->curlDelRoute(['new_route'=>$route]);  
147 - $this->model->edit(['route'=>$route],['id'=>$v['id']]);  
148 - }  
149 }catch (\Exception $e){ 143 }catch (\Exception $e){
150 $this->fail('error'); 144 $this->fail('error');
151 } 145 }