|
...
|
...
|
@@ -8,10 +8,12 @@ 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;
|
|
|
|
use App\Models\Template\BCustomTemplate;
|
|
|
|
use App\Models\WebSetting\WebSettingReceiving;
|
|
|
|
use App\Services\ProjectServer;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
...
|
...
|
@@ -52,7 +54,7 @@ class ProjectUpdate extends Command |
|
|
|
{
|
|
|
|
$task_id = $this->get_task();
|
|
|
|
if (!$task_id) {
|
|
|
|
sleep(2);
|
|
|
|
sleep(60);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -77,26 +79,119 @@ class ProjectUpdate extends Command |
|
|
|
//设置数据库
|
|
|
|
$project = ProjectServer::useProject($task->project_id);
|
|
|
|
if ($project) {
|
|
|
|
if ($api_type == 'website_info') {
|
|
|
|
if ($api_type == 'category') {
|
|
|
|
//分类
|
|
|
|
$url = $api_url . '?' . http_build_query(['w' => 'category']);
|
|
|
|
$data = http_get($url, ['charset' => 'UTF-8']);
|
|
|
|
if (isset($data['code']) && $data['code'] == 200) {
|
|
|
|
$items = $data['data'] ?? [];
|
|
|
|
$model = new Category();
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$parent = $model->read(['pid' => 0, 'title' => $item['name']], 'id');
|
|
|
|
if (!$parent) {
|
|
|
|
try {
|
|
|
|
$parent_id = $model->addReturnId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $item['name'],
|
|
|
|
'pid' => 0,
|
|
|
|
'keywords' => $item['keywords'],
|
|
|
|
'describe' => $item['description']
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['name'], RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
|
|
|
|
$model->edit(['route' => $route], ['id' => $parent_id]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$parent_id = $parent['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($item['children'] as $child) {
|
|
|
|
$child_info = $model->read(['pid' => $parent_id, 'title' => $child['name']]);
|
|
|
|
if (!$child_info) {
|
|
|
|
try {
|
|
|
|
$child_id = $model->addReturnId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $child['name'],
|
|
|
|
'pid' => $parent_id,
|
|
|
|
'keywords' => $child['keywords'],
|
|
|
|
'describe' => $child['description']
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($child['url'] ? $this->get_url_route($child['url']) : $child['name'], RouteMap::SOURCE_PRODUCT_CATE, $child_id, $project_id);
|
|
|
|
$model->edit(['route' => $route], ['id' => $child_id]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif ($api_type == 'tag') {
|
|
|
|
//关键词
|
|
|
|
$url = $api_url . '?' . http_build_query(['w' => 'website_info']);
|
|
|
|
$url = $api_url . '?' . http_build_query(['w' => 'tag', 'page' => 1, 'pagesize' => 0]);
|
|
|
|
$data = http_get($url, ['charset' => 'UTF-8']);
|
|
|
|
if (isset($data['code']) && $data['code'] == 200) {
|
|
|
|
$items = $data['data']['tags'] ?? [];
|
|
|
|
$count = $data['data']['count'] ?? 0;
|
|
|
|
|
|
|
|
$model = new Keyword();
|
|
|
|
foreach ($items as $item) {
|
|
|
|
if (strlen($item) > 50) {
|
|
|
|
continue;
|
|
|
|
$total_page = ceil($count / $page_size);
|
|
|
|
for ($page = 1; $page <= $total_page; $page++) {
|
|
|
|
$url_page = $api_url . '?' . http_build_query(['w' => 'tag', 'page' => $page, 'pagesize' => $page_size]);
|
|
|
|
$data_page = http_get($url_page, ['charset' => 'UTF-8']);
|
|
|
|
if (isset($data_page['code']) && $data_page['code'] == 200) {
|
|
|
|
$items = $data_page['data']['data'] ?? [];
|
|
|
|
|
|
|
|
$model = new Keyword();
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$keyword = $model->read(['title' => $item['text_title']], 'id');
|
|
|
|
if (!$keyword) {
|
|
|
|
try {
|
|
|
|
$id = $model->addReturnId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $item['text_title'],
|
|
|
|
'seo_title' => $item['seo_title'],
|
|
|
|
'seo_keywords' => $item['seo_keywords'],
|
|
|
|
'seo_description' => $item['seo_description'],
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['text_title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
|
|
|
|
$model->edit(['route' => $route], ['id' => $id]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif ($api_type == 'website_info') {
|
|
|
|
//网站信息
|
|
|
|
$url = $api_url . '?' . http_build_query(['w' => 'website_info']);
|
|
|
|
$data = http_get($url, ['charset' => 'UTF-8']);
|
|
|
|
if (isset($data['code']) && $data['code'] == 200) {
|
|
|
|
$phones = $data['data']['phones'] ?? '';
|
|
|
|
$emails = $data['data']['emails'] ?? '';
|
|
|
|
|
|
|
|
$model = new WebSettingReceiving();
|
|
|
|
if ($phones) {
|
|
|
|
$receiving_phones = $model->read(['type' => 1, 'values' => $phones]);
|
|
|
|
if (!$receiving_phones) {
|
|
|
|
$model->add([
|
|
|
|
'type' => 1,
|
|
|
|
'values' => $phones,
|
|
|
|
'project_id' => $project_id
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$keyword = $model->read(['title' => $item], 'id');
|
|
|
|
if (!$keyword) {
|
|
|
|
$id = $model->addReturnId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $item
|
|
|
|
}
|
|
|
|
if ($emails) {
|
|
|
|
$receiving_emails = $model->read(['type' => 2, 'values' => $emails]);
|
|
|
|
if (!$receiving_emails) {
|
|
|
|
$model->add([
|
|
|
|
'type' => 2,
|
|
|
|
'values' => $emails,
|
|
|
|
'project_id' => $project_id
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
|
|
|
|
$model->edit(['route' => $route], ['id' => $id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -125,12 +220,6 @@ class ProjectUpdate extends Command |
|
|
|
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']) {
|
|
...
|
...
|
@@ -147,24 +236,28 @@ class ProjectUpdate extends Command |
|
|
|
$category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$id = $model->addReturnId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $item['ttile'],
|
|
|
|
'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([
|
|
|
|
try {
|
|
|
|
$id = $model->addReturnId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $item['ttile'],
|
|
|
|
'keyword' => $item['keywords'],
|
|
|
|
'description' => $item['description']
|
|
|
|
]),
|
|
|
|
'status' => Product::STATUS_ON
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item['ttile'], RouteMap::SOURCE_PRODUCT, $id, $project_id);
|
|
|
|
$model->edit(['route' => $route], ['id' => $id]);
|
|
|
|
'intro' => $item['description'],
|
|
|
|
'content' => $item['content'],
|
|
|
|
'category_id' => $category_id,
|
|
|
|
'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
|
|
|
|
'gallery' => Arr::a2s($gallery),
|
|
|
|
'seo_mate' => Arr::a2s([
|
|
|
|
'title' => $item['ttile'],
|
|
|
|
'keyword' => $item['keywords'],
|
|
|
|
'description' => $item['description']
|
|
|
|
]),
|
|
|
|
'status' => Product::STATUS_ON
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], RouteMap::SOURCE_PRODUCT, $id, $project_id);
|
|
|
|
$model->edit(['route' => $route], ['id' => $id]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -194,16 +287,23 @@ class ProjectUpdate extends Command |
|
|
|
|
|
|
|
$news = $model->read(['name' => $item['ttile']], 'id');
|
|
|
|
if (!$news) {
|
|
|
|
$id = $model->addReturnId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'name' => $item['ttile'],
|
|
|
|
'seo_title' => $item['ttile'],
|
|
|
|
'text' => $item['content'],
|
|
|
|
'image' => $item['images'][0] ?? '',
|
|
|
|
'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item['ttile'], $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
|
|
|
|
$model->edit(['url' => $route], ['id' => $id]);
|
|
|
|
try {
|
|
|
|
$id = $model->addReturnId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'name' => $item['ttile'],
|
|
|
|
'seo_title' => $item['ttile'],
|
|
|
|
'seo_keywords' => $item['keywords'],
|
|
|
|
'seo_description' => $item['description'],
|
|
|
|
'text' => $item['content'],
|
|
|
|
'image' => $item['images'][0] ?? '',
|
|
|
|
'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
|
|
|
|
$model->edit(['url' => $route], ['id' => $id]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -229,13 +329,22 @@ class ProjectUpdate extends Command |
|
|
|
|
|
|
|
$custom = $model->read(['name' => $item['ttile']], 'id');
|
|
|
|
if (!$custom) {
|
|
|
|
$id = $model->addReturnId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'name' => $item['ttile'],
|
|
|
|
'html' => $item['content']
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item['ttile'], RouteMap::SOURCE_PAGE, $id, $project_id);
|
|
|
|
$model->edit(['url' => $route], ['id' => $id]);
|
|
|
|
try {
|
|
|
|
$id = $model->addReturnId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'name' => $item['ttile'],
|
|
|
|
'title' => $item['ttile'],
|
|
|
|
'keywords' => $item['keywords'],
|
|
|
|
'description' => $item['description'],
|
|
|
|
'html' => $item['content'],
|
|
|
|
'status' => 1
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], RouteMap::SOURCE_PAGE, $id, $project_id);
|
|
|
|
$model->edit(['url' => $route], ['id' => $id]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -263,7 +372,7 @@ class ProjectUpdate extends Command |
|
|
|
return $task_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->limit(20)->get();
|
|
|
|
$task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get();
|
|
|
|
if ($task_list->count() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
...
|
...
|
@@ -276,4 +385,10 @@ class ProjectUpdate extends Command |
|
|
|
return $task_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取地址路由
|
|
|
|
protected function get_url_route($url)
|
|
|
|
{
|
|
|
|
$arr = explode('/', $url);
|
|
|
|
return $arr[count($arr) - 2];
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|