作者 刘锟

update

... ... @@ -13,7 +13,9 @@ use App\Http\Controllers\Bside\BaseController;
use App\Models\Com\UpdateLog;
use App\Models\Com\UpdateOldInfo;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Category;
use App\Models\Project\ProjectUpdateTdk;
use App\Models\Template\BTemplate;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
... ... @@ -42,7 +44,7 @@ class UpdateController extends BaseController
]);
try {
ProjectUpdateTdk::add_task($this->param['project_id']);
}catch (\Exception $e){
} catch (\Exception $e) {
$this->fail($e->getMessage());
}
$this->response('任务添加成功');
... ... @@ -80,6 +82,19 @@ class UpdateController extends BaseController
$this->fail('非升级无法进行采集操作');
}
//产品分类开启了可视化之后,不能重新采集
$category_list = Category::where('project_id', $this->param['project_id'])->get();
if ($category_list->count() > 0) {
$template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT, BTemplate::IS_LIST);//获取模版id
foreach ($category_list as $category) {
if ($this->getIsRenovation(BTemplate::SOURCE_PRODUCT, BTemplate::IS_LIST, $template_id, $category['id']) == 1) {
//有分类开启了可视化
$this->param['type'] = 0;
break;
}
}
}
$test_domain = $this->param['test_domain'] ?? '';
if ($test_domain) {
$test_domain_arr = parse_url($test_domain);
... ... @@ -94,42 +109,41 @@ class UpdateController extends BaseController
}
try {
if($this->param['old_collect'] == 1){
if ($this->param['old_collect'] == 1) {
//现有数据需要重新采集页面
$collect_routes = '';
if(isset($this->param['collect_routes'])){
if (isset($this->param['collect_routes'])) {
//填写了采集路由
$routes_arr = explode(',',$this->param['collect_routes']);
foreach ($routes_arr as &$route){
$route = "'".$route."'";
$routes_arr = explode(',', $this->param['collect_routes']);
foreach ($routes_arr as &$route) {
$route = "'" . $route . "'";
}
$collect_routes = implode(',',$routes_arr);
$collect_routes = implode(',', $routes_arr);
}
DB::connection('custom_mysql')->statement("DELETE FROM `gl_collect_source` WHERE `origin` LIKE '%.css%' OR `origin` LIKE '%.js%'");
if ($domain_info) {
//已上线项目
if($collect_routes){
DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0,`domain` = '" . $test_domain . "' WHERE `language` = '' AND `route` IN (".$collect_routes.")");
}else{
if ($collect_routes) {
DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0,`domain` = '" . $test_domain . "' WHERE `language` = '' AND `route` IN (" . $collect_routes . ")");
} else {
DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0,`domain` = '" . $test_domain . "' WHERE `language` = ''");
}
} else {
if($collect_routes){
DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0 WHERE `language` = '' AND `route` IN (".$collect_routes.")");
}else{
if ($collect_routes) {
DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0 WHERE `language` = '' AND `route` IN (" . $collect_routes . ")");
} else {
DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0 WHERE `language` = ''");
}
}
}
if ($this->param['type'] == 1) {
//需要重新采集分类
//需要重新采集产品分类
DB::connection('custom_mysql')->statement("TRUNCATE `gl_product_category`");
DB::connection('custom_mysql')->statement("TRUNCATE `gl_product_category_related`");
DB::connection('custom_mysql')->statement("TRUNCATE `gl_news_category`");
DB::connection('custom_mysql')->statement("DELETE FROM `gl_route_map` WHERE `source` = 'product_category' OR `source` = 'news_category'");
DB::connection('custom_mysql')->statement("DELETE FROM `gl_route_map` WHERE `source` = 'product_category'");
}
} catch (\Exception $e) {
errorLog('重新采集升级项目数据', $this->param, $e);
... ... @@ -153,16 +167,19 @@ class UpdateController extends BaseController
}
if ($this->param['type'] == 1) {
//需要重新采集分类
$logs = UpdateLog::where('project_id', $this->param['project_id'])->orderBy('sort', 'asc')->get();
//需要重新采集产品分类,只排除新闻分类
$not_api_type = ['category_news'];
} else {
$logs = UpdateLog::where('project_id', $this->param['project_id'])->whereNotIn('api_type', ['category', 'category_news'])->orderBy('sort', 'asc')->get();
//无需重新采集产品分类,排除产品分类和新闻分类
$not_api_type = ['category', 'category_news'];
}
$logs = UpdateLog::where('project_id', $this->param['project_id'])->whereNotIn('api_type', $not_api_type)->orderBy('sort', 'asc')->get();
foreach ($logs as $log) {
$log->status = 0;
if (!in_array($log->api_type, ['website_info', 'tag', 'category', 'category_news'])) {
if (!in_array($log->api_type, ['website_info', 'tag', 'category'])) {
//website_info,tag,category三种类型无需采集页面
$log->collect_status = 0;
}
... ...