作者 刘锟

update

@@ -13,6 +13,7 @@ use App\Http\Controllers\Bside\BaseController; @@ -13,6 +13,7 @@ use App\Http\Controllers\Bside\BaseController;
13 use App\Models\Com\UpdateLog; 13 use App\Models\Com\UpdateLog;
14 use App\Models\Com\UpdateOldInfo; 14 use App\Models\Com\UpdateOldInfo;
15 use App\Models\Domain\DomainInfo; 15 use App\Models\Domain\DomainInfo;
  16 +use App\Models\News\NewsCategory;
16 use App\Models\Product\Category; 17 use App\Models\Product\Category;
17 use App\Models\Project\ProjectUpdateTdk; 18 use App\Models\Project\ProjectUpdateTdk;
18 use App\Models\Template\BTemplate; 19 use App\Models\Template\BTemplate;
@@ -96,17 +97,36 @@ class UpdateController extends BaseController @@ -96,17 +97,36 @@ class UpdateController extends BaseController
96 $this->fail('已上线项目需填写采集的测试站域名'); 97 $this->fail('已上线项目需填写采集的测试站域名');
97 } 98 }
98 99
  100 + $product_cate_type = 0;//产品分类是否重采
  101 + $news_cate_type = 0;//新闻分类是否重采
  102 +
99 if ($this->param['type'] == 1) { 103 if ($this->param['type'] == 1) {
100 - //产品分类重采之前,判断产品分类是否开启了可视化  
101 - $category_list = Category::where('project_id', $this->param['project_id'])->get();  
102 - if ($category_list->count() > 0) { 104 + $product_cate_type = 1;
  105 + $news_cate_type = 1;
  106 +
103 $bSettingModel = new Setting(); 107 $bSettingModel = new Setting();
104 $template_info = $bSettingModel->read(['project_id' => $this->param['project_id']]); 108 $template_info = $bSettingModel->read(['project_id' => $this->param['project_id']]);
105 $template_id = $template_info ? $template_info['template_id'] : 0;//获取模版id 109 $template_id = $template_info ? $template_info['template_id'] : 0;//获取模版id
  110 +
  111 + //产品分类重采之前,判断产品分类是否开启了可视化
  112 + $category_list = Category::where('project_id', $this->param['project_id'])->get();
  113 + if ($category_list->count() > 0) {
106 foreach ($category_list as $category) { 114 foreach ($category_list as $category) {
107 if ($this->getRenovation($this->param['project_id'], BTemplate::SOURCE_PRODUCT, BTemplate::IS_LIST, $template_id, $category['id']) == 1) { 115 if ($this->getRenovation($this->param['project_id'], BTemplate::SOURCE_PRODUCT, BTemplate::IS_LIST, $template_id, $category['id']) == 1) {
108 //有分类开启了可视化 116 //有分类开启了可视化
109 - $this->param['type'] = 0; 117 + $product_cate_type = 0;
  118 + break;
  119 + }
  120 + }
  121 + }
  122 +
  123 + //新闻分类重采之前,判断新闻分类是否开启了可视化
  124 + $category_news_list = NewsCategory::where('project_id', $this->param['project_id'])->get();
  125 + if ($category_news_list->count() > 0) {
  126 + foreach ($category_news_list as $category_news) {
  127 + if ($this->getRenovation($this->param['project_id'], BTemplate::SOURCE_NEWS, BTemplate::IS_LIST, $template_id, $category_news['id']) == 1) {
  128 + //有分类开启了可视化
  129 + $news_cate_type = 0;
110 break; 130 break;
111 } 131 }
112 } 132 }
@@ -143,13 +163,20 @@ class UpdateController extends BaseController @@ -143,13 +163,20 @@ class UpdateController extends BaseController
143 } 163 }
144 } 164 }
145 165
146 - if ($this->param['type'] == 1) { 166 + if ($product_cate_type == 1) {
147 //需要重新采集产品分类 167 //需要重新采集产品分类
148 DB::connection('custom_mysql')->statement("TRUNCATE `gl_product_category`"); 168 DB::connection('custom_mysql')->statement("TRUNCATE `gl_product_category`");
149 DB::connection('custom_mysql')->statement("TRUNCATE `gl_product_category_related`"); 169 DB::connection('custom_mysql')->statement("TRUNCATE `gl_product_category_related`");
150 170
151 DB::connection('custom_mysql')->statement("DELETE FROM `gl_route_map` WHERE `source` = 'product_category'"); 171 DB::connection('custom_mysql')->statement("DELETE FROM `gl_route_map` WHERE `source` = 'product_category'");
152 } 172 }
  173 +
  174 + if ($news_cate_type == 1) {
  175 + //需要重新采集新闻分类
  176 + DB::connection('custom_mysql')->statement("TRUNCATE `gl_news_category`");
  177 +
  178 + DB::connection('custom_mysql')->statement("DELETE FROM `gl_route_map` WHERE `source` = 'news_category'");
  179 + }
153 } catch (\Exception $e) { 180 } catch (\Exception $e) {
154 errorLog('重新采集升级项目数据', $this->param, $e); 181 errorLog('重新采集升级项目数据', $this->param, $e);
155 182
@@ -171,14 +198,19 @@ class UpdateController extends BaseController @@ -171,14 +198,19 @@ class UpdateController extends BaseController
171 $old_info->save(); 198 $old_info->save();
172 } 199 }
173 200
174 - if ($this->param['type'] == 1) {  
175 - //需要重新采集产品分类,只排除新闻分类  
176 - $not_api_type = ['category_news']; 201 + if ($product_cate_type == 1 && $news_cate_type == 1) {
  202 + //需要重新采集产品分类和新闻分类
  203 + $logs = UpdateLog::where('project_id', $this->param['project_id'])->orderBy('sort', 'asc')->get();
  204 + } elseif ($product_cate_type == 1 && $news_cate_type == 0) {
  205 + //只重采产品分类
  206 + $logs = UpdateLog::where('project_id', $this->param['project_id'])->where('api_type', '!=', 'category_news')->orderBy('sort', 'asc')->get();
  207 + } elseif ($product_cate_type == 0 && $news_cate_type == 1) {
  208 + //只重采新闻分类
  209 + $logs = UpdateLog::where('project_id', $this->param['project_id'])->where('api_type', '!=', 'category')->orderBy('sort', 'asc')->get();
177 } else { 210 } else {
178 - //无需重新采集产品分类,排除产品分类和新闻分类  
179 - $not_api_type = ['category', 'category_news']; 211 + //分类都不重采
  212 + $logs = UpdateLog::where('project_id', $this->param['project_id'])->whereNotIn('api_type', ['category', 'category_news'])->orderBy('sort', 'asc')->get();
180 } 213 }
181 - $logs = UpdateLog::where('project_id', $this->param['project_id'])->whereNotIn('api_type', $not_api_type)->orderBy('sort', 'asc')->get();  
182 214
183 foreach ($logs as $log) { 215 foreach ($logs as $log) {
184 $log->status = 0; 216 $log->status = 0;