作者 刘锟

项目升级

... ... @@ -3,9 +3,12 @@
namespace App\Console\Commands\Update;
use App\Helper\Arr;
use App\Http\Logic\Bside\Product\CategoryLogic;
use App\Http\Logic\Bside\Product\KeywordLogic;
use App\Models\Blog\Blog;
use App\Models\Com\UpdateLog;
use App\Models\News\News;
use App\Models\Product\Category;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
... ... @@ -118,21 +121,46 @@ class ProjectUpdate extends Command
$product = $model->read(['title' => $item['ttile']], 'id');
if (!$product) {
//图片
$gallery = [];
foreach ($item['images'] as $k_img => $img) {
$gallery[] = ['alt' => '这是一张产品图', 'url' => $img];
}
//关键词
$keyword_id = '';
if ($item['keywords']) {
$keywordLogic = new KeywordLogic();
$keyword_id = $keywordLogic->importProductKeyword($project_id, $item['keywords']);
}
//分类
$category_id = '';
if ($item['category']) {
$category_arr = [];
foreach ($item['category'] as $cate) {
if ($cate['parent'] == 0) {
array_unshift($category_arr, $cate['name']);
} else {
array_push($category_arr, $cate['name']);
}
}
if ($category_arr) {
$categoryLogic = new CategoryLogic();
$category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr));
}
}
$id = $model->addReturnId([
'project_id' => $project_id,
'title' => $item['ttile'],
'intro' => '',
'intro' => $item['description'],
'content' => $item['content'],
'keyword_id' => $keyword_id,
'category_id' => $category_id,
'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
'gallery' => Arr::a2s($gallery),
'seo_mate' => Arr::a2s([
'title' => $item['ttile'],
'keyword' => '',
'description' => ''
'keyword' => $item['keywords'],
'description' => $item['description']
]),
'status' => Product::STATUS_ON
]);
... ... @@ -182,7 +210,7 @@ class ProjectUpdate extends Command
}
}
}
}else{
} else {
//单页
$url = $api_url . '?' . http_build_query(['w' => 'page', 'page' => 1, 'pagesize' => 0]);
$data = http_get($url, ['charset' => 'UTF-8']);
... ... @@ -204,7 +232,8 @@ class ProjectUpdate extends Command
if (!$custom) {
$id = $model->addReturnId([
'project_id' => $project_id,
'name' => $item['ttile']
'name' => $item['ttile'],
'html' => $item['content']
]);
$route = RouteMap::setRoute($item['ttile'], RouteMap::SOURCE_PAGE, $id, $project_id);
$model->edit(['url' => $route], ['id' => $id]);
... ...