作者 lyh
@@ -383,20 +383,12 @@ class ProjectUpdate extends Command @@ -383,20 +383,12 @@ class ProjectUpdate extends Command
383 'sort' => $item['sort'] ?? 0, 383 'sort' => $item['sort'] ?? 0,
384 'files' => $files, 384 'files' => $files,
385 ], ['id' => $id]); 385 ], ['id' => $id]);
386 - } else {  
387 - //按6.0展示只更新分类  
388 - $model->edit([  
389 - 'category_id' => $category_id  
390 - ], ['id' => $id]);  
391 } 386 }
392 } 387 }
393 388
394 - //关联分类  
395 - if ($category_arr) {  
396 - CategoryRelated::saveRelated($id, array_column($category_arr, 'id'));  
397 - }  
398 -  
399 if ($six_read) { 389 if ($six_read) {
  390 + //关联分类
  391 + CategoryRelated::saveRelated($id, array_column($category_arr, 'id'));
400 //扩展字段 392 //扩展字段
401 if ($item['extend'] ?? []) { 393 if ($item['extend'] ?? []) {
402 foreach (array_reverse($item['extend']) as $ke => $ve) { 394 foreach (array_reverse($item['extend']) as $ke => $ve) {
@@ -508,9 +500,7 @@ class ProjectUpdate extends Command @@ -508,9 +500,7 @@ class ProjectUpdate extends Command
508 500
509 CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $domain_arr['host'], $link_type, $language_list, $page_list); 501 CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $domain_arr['host'], $link_type, $language_list, $page_list);
510 } else { 502 } else {
511 - $id = $news['id'];  
512 - $six_read = $news['six_read'];  
513 - if ($six_read) { 503 + if ($news['six_read']) {
514 //按5.0展示才需要更新数据 504 //按5.0展示才需要更新数据
515 $model->edit([ 505 $model->edit([
516 'name' => $item['ttile'], 506 'name' => $item['ttile'],
@@ -522,7 +512,7 @@ class ProjectUpdate extends Command @@ -522,7 +512,7 @@ class ProjectUpdate extends Command
522 'image' => $new_img, 512 'image' => $new_img,
523 'release_at' => $item['post_date'] ?? date('Y-m-d H:i:s'), 513 'release_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
524 'sort' => $item['sort'] ?? 0, 514 'sort' => $item['sort'] ?? 0,
525 - ], ['id' => $id]); 515 + ], ['id' => $news['id']]);
526 } 516 }
527 } 517 }
528 } catch (\Exception $e) { 518 } catch (\Exception $e) {
@@ -855,51 +845,61 @@ class ProjectUpdate extends Command @@ -855,51 +845,61 @@ class ProjectUpdate extends Command
855 foreach ($items as $item) { 845 foreach ($items as $item) {
856 $route = $this->get_url_route($item['url'] ?? ''); 846 $route = $this->get_url_route($item['url'] ?? '');
857 if ($route) { 847 if ($route) {
858 - $parent = $model->read(['pid' => $pid, 'route' => $route], 'id');  
859 - if (!$parent) {  
860 - try {  
861 - $item['name'] = $this->special2str($item['name'] ?? '');  
862 - //图片  
863 - if (is_array($item['images'] ?? '')) {  
864 - $image = $item['images'][0] ?? '';  
865 - } else {  
866 - $image = $item['images'] ?? '';  
867 - }  
868 - $new_img = $this->source_download($image, $project_id, $domain, $web_url_domain, $home_url);  
869 - //描述  
870 - if (isset($item['description']) && $item['description']) {  
871 - //匹配描述资源  
872 - $source_list = $this->html_preg($item['description'], $project_id, $domain, $web_url_domain, $home_url);  
873 - if ($source_list) {  
874 - foreach ($source_list as $vs) {  
875 - if ($vs['download']) {  
876 - //需要下载资源  
877 - $down_url = $this->source_download($vs['url_complete'], $project_id, $domain, $web_url_domain, $home_url);  
878 - } else {  
879 - //已经下载过资源  
880 - $down_url = getImageUrl($vs['url_complete']);  
881 - }  
882 - $item['description'] = str_replace($vs['url'], $down_url, $item['description']);  
883 - } 848 + $item['name'] = $this->special2str($item['name'] ?? '');
  849 + //图片
  850 + if (is_array($item['images'] ?? '')) {
  851 + $image = $item['images'][0] ?? '';
  852 + } else {
  853 + $image = $item['images'] ?? '';
  854 + }
  855 + $new_img = $this->source_download($image, $project_id, $domain, $web_url_domain, $home_url);
  856 + //描述
  857 + $describe = '';
  858 + if (isset($item['description']) && $item['description']) {
  859 + $describe = $item['description'];
  860 + //匹配描述资源
  861 + $source_list = $this->html_preg($describe, $project_id, $domain, $web_url_domain, $home_url);
  862 + if ($source_list) {
  863 + foreach ($source_list as $vs) {
  864 + if ($vs['download']) {
  865 + //需要下载资源
  866 + $down_url = $this->source_download($vs['url_complete'], $project_id, $domain, $web_url_domain, $home_url);
  867 + } else {
  868 + //已经下载过资源
  869 + $down_url = getImageUrl($vs['url_complete']);
884 } 870 }
  871 + $describe = str_replace($vs['url'], $down_url, $describe);
885 } 872 }
  873 + }
  874 + }
  875 + try {
  876 + $parent = $model->read(['route' => $route], 'id');
  877 + if (!$parent) {
886 $parent_id = $model->addReturnId([ 878 $parent_id = $model->addReturnId([
887 'project_id' => $project_id, 879 'project_id' => $project_id,
888 'title' => $item['name'], 880 'title' => $item['name'],
889 'image' => $new_img, 881 'image' => $new_img,
890 'pid' => $pid, 882 'pid' => $pid,
891 'keywords' => $item['keywords'] ?? '', 883 'keywords' => $item['keywords'] ?? '',
892 - 'describe' => (isset($item['description']) && $item['description']) ? $item['description'] : '', 884 + 'describe' => $describe,
893 'original_id' => $item['id'], 885 'original_id' => $item['id'],
894 'route' => $route 886 'route' => $route
895 ]); 887 ]);
896 $this->set_map($route, RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id); 888 $this->set_map($route, RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
897 - } catch (\Exception $e) {  
898 - echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL;  
899 - continue; 889 + } else {
  890 + $parent_id = $parent['id'];
  891 + $model->edit([
  892 + 'title' => $item['name'],
  893 + 'image' => $new_img,
  894 + 'pid' => $pid,
  895 + 'keywords' => $item['keywords'] ?? '',
  896 + 'describe' => $describe,
  897 + 'original_id' => $item['id']
  898 + ], ['id' => $parent_id]);
900 } 899 }
901 - } else {  
902 - $parent_id = $parent['id']; 900 + } catch (\Exception $e) {
  901 + echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL;
  902 + continue;
903 } 903 }
904 904
905 if (!empty($item['children'] ?? [])) { 905 if (!empty($item['children'] ?? [])) {
@@ -916,10 +916,10 @@ class ProjectUpdate extends Command @@ -916,10 +916,10 @@ class ProjectUpdate extends Command
916 foreach ($items as $item) { 916 foreach ($items as $item) {
917 $route = $this->get_url_route($item['url'] ?? ''); 917 $route = $this->get_url_route($item['url'] ?? '');
918 if ($route) { 918 if ($route) {
919 - $parent = $model->read(['pid' => $pid, 'alias' => $route], 'id');  
920 - if (!$parent) {  
921 - try {  
922 - $item['name'] = $this->special2str($item['name'] ?? ''); 919 + $item['name'] = $this->special2str($item['name'] ?? '');
  920 + try {
  921 + $parent = $model->read(['alias' => $route], 'id');
  922 + if (!$parent) {
923 $parent_id = $model->addReturnId([ 923 $parent_id = $model->addReturnId([
924 'project_id' => $project_id, 924 'project_id' => $project_id,
925 'name' => $item['name'], 925 'name' => $item['name'],
@@ -928,12 +928,18 @@ class ProjectUpdate extends Command @@ -928,12 +928,18 @@ class ProjectUpdate extends Command
928 'alias' => $route 928 'alias' => $route
929 ]); 929 ]);
930 $this->set_map($route, RouteMap::SOURCE_NEWS_CATE, $parent_id, $project_id); 930 $this->set_map($route, RouteMap::SOURCE_NEWS_CATE, $parent_id, $project_id);
931 - } catch (\Exception $e) {  
932 - echo 'date:' . date('Y-m-d H:i:s') . ', category_news_insert error: ' . $e->getMessage() . PHP_EOL;  
933 - continue; 931 +
  932 + } else {
  933 + $parent_id = $parent['id'];
  934 + $model->edit([
  935 + 'name' => $item['name'],
  936 + 'pid' => $pid,
  937 + 'original_id' => $item['id'],
  938 + ], ['id' => $parent_id]);
934 } 939 }
935 - } else {  
936 - $parent_id = $parent['id']; 940 + } catch (\Exception $e) {
  941 + echo 'date:' . date('Y-m-d H:i:s') . ', category_news_insert error: ' . $e->getMessage() . PHP_EOL;
  942 + continue;
937 } 943 }
938 944
939 if (!empty($item['children'] ?? [])) { 945 if (!empty($item['children'] ?? [])) {
@@ -99,53 +99,6 @@ class UpdateController extends BaseController @@ -99,53 +99,6 @@ class UpdateController extends BaseController
99 $this->fail('已上线项目需填写采集的测试站域名'); 99 $this->fail('已上线项目需填写采集的测试站域名');
100 } 100 }
101 101
102 - $product_cate_type = 0;//产品分类是否重采  
103 - $news_cate_type = 0;//新闻分类是否重采  
104 -  
105 - if ($this->param['type'] == 1) {  
106 - $product_cate_type = 1;  
107 - $news_cate_type = 1;  
108 -  
109 - $bSettingModel = new Setting();  
110 - $template_info = $bSettingModel->read(['project_id' => $this->param['project_id']]);  
111 - $template_id = $template_info ? $template_info['template_id'] : 0;//获取模版id  
112 -  
113 - //产品分类重采之前,判断产品分类是否开启了可视化  
114 - $category_list = Category::where('project_id', $this->param['project_id'])->get();  
115 - if ($category_list->count() > 0) {  
116 - foreach ($category_list as $category) {  
117 - if ($this->getRenovation($this->param['project_id'], BTemplate::SOURCE_PRODUCT, BTemplate::IS_LIST, $template_id, $category['id']) == 1) {  
118 - //有分类开启了可视化  
119 - $product_cate_type = 0;  
120 - break;  
121 - }  
122 - }  
123 - }  
124 -  
125 - //如果自己创建了6.0产品关联了分类,也不能再重采分类  
126 - $product_v6_list = Product::where('project_id', $this->param['project_id'])->where('is_upgrade', 0)->get();  
127 - if ($product_v6_list->count() > 0) {  
128 - foreach ($product_v6_list as $product_v6) {  
129 - if ($product_v6->category_id) {  
130 - $product_cate_type = 0;  
131 - break;  
132 - }  
133 - }  
134 - }  
135 -  
136 - //新闻分类重采之前,判断新闻分类是否开启了可视化  
137 - $category_news_list = NewsCategory::where('project_id', $this->param['project_id'])->get();  
138 - if ($category_news_list->count() > 0) {  
139 - foreach ($category_news_list as $category_news) {  
140 - if ($this->getRenovation($this->param['project_id'], BTemplate::SOURCE_NEWS, BTemplate::IS_LIST, $template_id, $category_news['id']) == 1) {  
141 - //有分类开启了可视化  
142 - $news_cate_type = 0;  
143 - break;  
144 - }  
145 - }  
146 - }  
147 - }  
148 -  
149 try { 102 try {
150 if ($this->param['old_collect'] == 1) { 103 if ($this->param['old_collect'] == 1) {
151 //现有数据需要重新采集页面 104 //现有数据需要重新采集页面
@@ -175,21 +128,6 @@ class UpdateController extends BaseController @@ -175,21 +128,6 @@ class UpdateController extends BaseController
175 } 128 }
176 } 129 }
177 } 130 }
178 -  
179 - if ($product_cate_type == 1) {  
180 - //需要重新采集产品分类  
181 - DB::connection('custom_mysql')->statement("TRUNCATE `gl_product_category`");  
182 - DB::connection('custom_mysql')->statement("TRUNCATE `gl_product_category_related`");  
183 -  
184 - DB::connection('custom_mysql')->statement("DELETE FROM `gl_route_map` WHERE `source` = 'product_category'");  
185 - }  
186 -  
187 - if ($news_cate_type == 1) {  
188 - //需要重新采集新闻分类  
189 - DB::connection('custom_mysql')->statement("TRUNCATE `gl_news_category`");  
190 -  
191 - DB::connection('custom_mysql')->statement("DELETE FROM `gl_route_map` WHERE `source` = 'news_category'");  
192 - }  
193 } catch (\Exception $e) { 131 } catch (\Exception $e) {
194 errorLog('重新采集升级项目数据', $this->param, $e); 132 errorLog('重新采集升级项目数据', $this->param, $e);
195 133
@@ -211,15 +149,9 @@ class UpdateController extends BaseController @@ -211,15 +149,9 @@ class UpdateController extends BaseController
211 $old_info->save(); 149 $old_info->save();
212 } 150 }
213 151
214 - if ($product_cate_type == 1 && $news_cate_type == 1) { 152 + if ($this->param['type'] == 1) {
215 //需要重新采集产品分类和新闻分类 153 //需要重新采集产品分类和新闻分类
216 $logs = UpdateLog::where('project_id', $this->param['project_id'])->orderBy('sort', 'asc')->get(); 154 $logs = UpdateLog::where('project_id', $this->param['project_id'])->orderBy('sort', 'asc')->get();
217 - } elseif ($product_cate_type == 1 && $news_cate_type == 0) {  
218 - //只重采产品分类  
219 - $logs = UpdateLog::where('project_id', $this->param['project_id'])->where('api_type', '!=', 'category_news')->orderBy('sort', 'asc')->get();  
220 - } elseif ($product_cate_type == 0 && $news_cate_type == 1) {  
221 - //只重采新闻分类  
222 - $logs = UpdateLog::where('project_id', $this->param['project_id'])->where('api_type', '!=', 'category')->orderBy('sort', 'asc')->get();  
223 } else { 155 } else {
224 //分类都不重采 156 //分类都不重采
225 $logs = UpdateLog::where('project_id', $this->param['project_id'])->whereNotIn('api_type', ['category', 'category_news'])->orderBy('sort', 'asc')->get(); 157 $logs = UpdateLog::where('project_id', $this->param['project_id'])->whereNotIn('api_type', ['category', 'category_news'])->orderBy('sort', 'asc')->get();
@@ -256,22 +188,4 @@ class UpdateController extends BaseController @@ -256,22 +188,4 @@ class UpdateController extends BaseController
256 188
257 $this->response('采集任务添加成功'); 189 $this->response('采集任务添加成功');
258 } 190 }
259 -  
260 - public function getRenovation($project_id, $source, $is_list, $template_id, $id, $is_custom = 0)  
261 - {  
262 - $webTemplateModel = new BTemplate();  
263 - $param = [  
264 - 'source' => $source,  
265 - 'project_id' => $project_id,  
266 - 'source_id' => $id,  
267 - 'template_id' => $template_id,  
268 - 'is_list' => $is_list,  
269 - 'is_custom' => $is_custom  
270 - ];  
271 - $templateInfo = $webTemplateModel->read($param);  
272 - if ($templateInfo !== false) {  
273 - return 1;  
274 - }  
275 - return 0;  
276 - }  
277 } 191 }