作者 刘锟

update

... ... @@ -855,51 +855,61 @@ class ProjectUpdate extends Command
foreach ($items as $item) {
$route = $this->get_url_route($item['url'] ?? '');
if ($route) {
$parent = $model->read(['pid' => $pid, 'route' => $route], 'id');
if (!$parent) {
try {
$item['name'] = $this->special2str($item['name'] ?? '');
//图片
if (is_array($item['images'] ?? '')) {
$image = $item['images'][0] ?? '';
} else {
$image = $item['images'] ?? '';
}
$new_img = $this->source_download($image, $project_id, $domain, $web_url_domain, $home_url);
//描述
if (isset($item['description']) && $item['description']) {
//匹配描述资源
$source_list = $this->html_preg($item['description'], $project_id, $domain, $web_url_domain, $home_url);
if ($source_list) {
foreach ($source_list as $vs) {
if ($vs['download']) {
//需要下载资源
$down_url = $this->source_download($vs['url_complete'], $project_id, $domain, $web_url_domain, $home_url);
} else {
//已经下载过资源
$down_url = getImageUrl($vs['url_complete']);
}
$item['description'] = str_replace($vs['url'], $down_url, $item['description']);
}
$item['name'] = $this->special2str($item['name'] ?? '');
//图片
if (is_array($item['images'] ?? '')) {
$image = $item['images'][0] ?? '';
} else {
$image = $item['images'] ?? '';
}
$new_img = $this->source_download($image, $project_id, $domain, $web_url_domain, $home_url);
//描述
$describe = '';
if (isset($item['description']) && $item['description']) {
$describe = $item['description'];
//匹配描述资源
$source_list = $this->html_preg($describe, $project_id, $domain, $web_url_domain, $home_url);
if ($source_list) {
foreach ($source_list as $vs) {
if ($vs['download']) {
//需要下载资源
$down_url = $this->source_download($vs['url_complete'], $project_id, $domain, $web_url_domain, $home_url);
} else {
//已经下载过资源
$down_url = getImageUrl($vs['url_complete']);
}
$describe = str_replace($vs['url'], $down_url, $describe);
}
}
}
try {
$parent = $model->read(['route' => $route], 'id');
if (!$parent) {
$parent_id = $model->addReturnId([
'project_id' => $project_id,
'title' => $item['name'],
'image' => $new_img,
'pid' => $pid,
'keywords' => $item['keywords'] ?? '',
'describe' => (isset($item['description']) && $item['description']) ? $item['description'] : '',
'describe' => $describe,
'original_id' => $item['id'],
'route' => $route
]);
$this->set_map($route, RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL;
continue;
} else {
$parent_id = $parent['id'];
$model->edit([
'title' => $item['name'],
'image' => $new_img,
'pid' => $pid,
'keywords' => $item['keywords'] ?? '',
'describe' => $describe,
'original_id' => $item['id']
], ['id' => $parent_id]);
}
} else {
$parent_id = $parent['id'];
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL;
continue;
}
if (!empty($item['children'] ?? [])) {
... ... @@ -916,10 +926,10 @@ class ProjectUpdate extends Command
foreach ($items as $item) {
$route = $this->get_url_route($item['url'] ?? '');
if ($route) {
$parent = $model->read(['pid' => $pid, 'alias' => $route], 'id');
if (!$parent) {
try {
$item['name'] = $this->special2str($item['name'] ?? '');
$item['name'] = $this->special2str($item['name'] ?? '');
try {
$parent = $model->read(['alias' => $route], 'id');
if (!$parent) {
$parent_id = $model->addReturnId([
'project_id' => $project_id,
'name' => $item['name'],
... ... @@ -928,12 +938,18 @@ class ProjectUpdate extends Command
'alias' => $route
]);
$this->set_map($route, RouteMap::SOURCE_NEWS_CATE, $parent_id, $project_id);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', category_news_insert error: ' . $e->getMessage() . PHP_EOL;
continue;
} else {
$parent_id = $parent['id'];
$model->edit([
'name' => $item['name'],
'pid' => $pid,
'original_id' => $item['id'],
], ['id' => $parent_id]);
}
} else {
$parent_id = $parent['id'];
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', category_news_insert error: ' . $e->getMessage() . PHP_EOL;
continue;
}
if (!empty($item['children'] ?? [])) {
... ...
... ... @@ -99,53 +99,6 @@ class UpdateController extends BaseController
$this->fail('已上线项目需填写采集的测试站域名');
}
$product_cate_type = 0;//产品分类是否重采
$news_cate_type = 0;//新闻分类是否重采
if ($this->param['type'] == 1) {
$product_cate_type = 1;
$news_cate_type = 1;
$bSettingModel = new Setting();
$template_info = $bSettingModel->read(['project_id' => $this->param['project_id']]);
$template_id = $template_info ? $template_info['template_id'] : 0;//获取模版id
//产品分类重采之前,判断产品分类是否开启了可视化
$category_list = Category::where('project_id', $this->param['project_id'])->get();
if ($category_list->count() > 0) {
foreach ($category_list as $category) {
if ($this->getRenovation($this->param['project_id'], BTemplate::SOURCE_PRODUCT, BTemplate::IS_LIST, $template_id, $category['id']) == 1) {
//有分类开启了可视化
$product_cate_type = 0;
break;
}
}
}
//如果自己创建了6.0产品关联了分类,也不能再重采分类
$product_v6_list = Product::where('project_id', $this->param['project_id'])->where('is_upgrade', 0)->get();
if ($product_v6_list->count() > 0) {
foreach ($product_v6_list as $product_v6) {
if ($product_v6->category_id) {
$product_cate_type = 0;
break;
}
}
}
//新闻分类重采之前,判断新闻分类是否开启了可视化
$category_news_list = NewsCategory::where('project_id', $this->param['project_id'])->get();
if ($category_news_list->count() > 0) {
foreach ($category_news_list as $category_news) {
if ($this->getRenovation($this->param['project_id'], BTemplate::SOURCE_NEWS, BTemplate::IS_LIST, $template_id, $category_news['id']) == 1) {
//有分类开启了可视化
$news_cate_type = 0;
break;
}
}
}
}
try {
if ($this->param['old_collect'] == 1) {
//现有数据需要重新采集页面
... ... @@ -175,21 +128,6 @@ class UpdateController extends BaseController
}
}
}
if ($product_cate_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("DELETE FROM `gl_route_map` WHERE `source` = 'product_category'");
}
if ($news_cate_type == 1) {
//需要重新采集新闻分类
DB::connection('custom_mysql')->statement("TRUNCATE `gl_news_category`");
DB::connection('custom_mysql')->statement("DELETE FROM `gl_route_map` WHERE `source` = 'news_category'");
}
} catch (\Exception $e) {
errorLog('重新采集升级项目数据', $this->param, $e);
... ... @@ -211,15 +149,9 @@ class UpdateController extends BaseController
$old_info->save();
}
if ($product_cate_type == 1 && $news_cate_type == 1) {
if ($this->param['type'] == 1) {
//需要重新采集产品分类和新闻分类
$logs = UpdateLog::where('project_id', $this->param['project_id'])->orderBy('sort', 'asc')->get();
} elseif ($product_cate_type == 1 && $news_cate_type == 0) {
//只重采产品分类
$logs = UpdateLog::where('project_id', $this->param['project_id'])->where('api_type', '!=', 'category_news')->orderBy('sort', 'asc')->get();
} elseif ($product_cate_type == 0 && $news_cate_type == 1) {
//只重采新闻分类
$logs = UpdateLog::where('project_id', $this->param['project_id'])->where('api_type', '!=', 'category')->orderBy('sort', 'asc')->get();
} else {
//分类都不重采
$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
$this->response('采集任务添加成功');
}
public function getRenovation($project_id, $source, $is_list, $template_id, $id, $is_custom = 0)
{
$webTemplateModel = new BTemplate();
$param = [
'source' => $source,
'project_id' => $project_id,
'source_id' => $id,
'template_id' => $template_id,
'is_list' => $is_list,
'is_custom' => $is_custom
];
$templateInfo = $webTemplateModel->read($param);
if ($templateInfo !== false) {
return 1;
}
return 0;
}
}
... ...