|
...
|
...
|
@@ -85,48 +85,51 @@ class ProjectUpdate extends Command |
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->category_insert($project_id, $items, 0);
|
|
|
|
// $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;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} elseif ($api_type == 'tag') {
|
|
|
|
//关键词
|
|
...
|
...
|
@@ -144,26 +147,30 @@ class ProjectUpdate extends Command |
|
|
|
|
|
|
|
$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;
|
|
|
|
if ($item['name'] ?? '') {
|
|
|
|
$keyword = $model->read(['title' => $item['name']], 'id');
|
|
|
|
if (!$keyword) {
|
|
|
|
try {
|
|
|
|
$id = $model->addReturnId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $item['name'],
|
|
|
|
'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['name'], 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} elseif ($api_type == 'website_info') {
|
|
|
|
//网站信息
|
|
...
|
...
|
@@ -175,25 +182,37 @@ class ProjectUpdate extends Command |
|
|
|
|
|
|
|
$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
|
|
|
|
]);
|
|
|
|
$phone_arr = explode(',', $phones);
|
|
|
|
foreach ($phone_arr as $v_phone) {
|
|
|
|
if ($v_phone) {
|
|
|
|
$receiving_phones = $model->read(['type' => 2, 'values' => $v_phone]);
|
|
|
|
if (!$receiving_phones) {
|
|
|
|
$model->add([
|
|
|
|
'type' => 1,
|
|
|
|
'values' => $v_phone,
|
|
|
|
'project_id' => $project_id
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($emails) {
|
|
|
|
$receiving_emails = $model->read(['type' => 2, 'values' => $emails]);
|
|
|
|
if (!$receiving_emails) {
|
|
|
|
$model->add([
|
|
|
|
'type' => 2,
|
|
|
|
'values' => $emails,
|
|
|
|
'project_id' => $project_id
|
|
|
|
]);
|
|
|
|
$email_arr = explode(',', $emails);
|
|
|
|
foreach ($email_arr as $v_email) {
|
|
|
|
if ($v_email) {
|
|
|
|
$receiving_emails = $model->read(['type' => 1, 'values' => $v_email]);
|
|
|
|
if (!$receiving_emails) {
|
|
|
|
$model->add([
|
|
|
|
'type' => 2,
|
|
|
|
'values' => $v_email,
|
|
|
|
'project_id' => $project_id
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} elseif ($api_type == 'post') {
|
|
|
|
//产品
|
|
...
|
...
|
@@ -212,56 +231,61 @@ class ProjectUpdate extends Command |
|
|
|
$model = new Product();
|
|
|
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
|
|
|
|
$product = $model->read(['title' => $item['ttile']], 'id');
|
|
|
|
if (!$product) {
|
|
|
|
//图片
|
|
|
|
$gallery = [];
|
|
|
|
foreach ($item['images'] as $k_img => $img) {
|
|
|
|
$gallery[] = ['alt' => '这是一张产品图', 'url' => $img];
|
|
|
|
}
|
|
|
|
//分类
|
|
|
|
$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 ($item['ttile'] ?? '') {
|
|
|
|
$product = $model->read(['title' => $item['ttile']], 'id');
|
|
|
|
if (!$product) {
|
|
|
|
//图片
|
|
|
|
$gallery = [];
|
|
|
|
if ($item['images'] ?? []) {
|
|
|
|
foreach ($item['images'] as $k_img => $img) {
|
|
|
|
$gallery[] = ['alt' => '这是一张产品图', 'url' => $img];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($category_arr) {
|
|
|
|
$categoryLogic = new CategoryLogic();
|
|
|
|
$category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr));
|
|
|
|
//分类
|
|
|
|
$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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$id = $model->addReturnId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $item['ttile'],
|
|
|
|
'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([
|
|
|
|
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['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;
|
|
|
|
'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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} elseif ($api_type == 'news' || $api_type == 'blog') {
|
|
|
|
//新闻或博客
|
|
...
|
...
|
@@ -285,29 +309,33 @@ class ProjectUpdate extends Command |
|
|
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
|
|
|
|
$news = $model->read(['name' => $item['ttile']], 'id');
|
|
|
|
if (!$news) {
|
|
|
|
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;
|
|
|
|
if ($item['ttile'] ?? '') {
|
|
|
|
$news = $model->read(['name' => $item['ttile']], 'id');
|
|
|
|
if (!$news) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//单页
|
|
...
|
...
|
@@ -326,29 +354,32 @@ class ProjectUpdate extends Command |
|
|
|
$model = new BCustomTemplate();
|
|
|
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
|
|
|
|
$custom = $model->read(['name' => $item['ttile']], 'id');
|
|
|
|
if (!$custom) {
|
|
|
|
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;
|
|
|
|
if ($item['ttile'] ?? '') {
|
|
|
|
$custom = $model->read(['name' => $item['ttile']], 'id');
|
|
|
|
if (!$custom) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -391,4 +422,31 @@ class ProjectUpdate extends Command |
|
|
|
$arr = explode('/', $url);
|
|
|
|
return $arr[count($arr) - 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function category_insert($project_id, $items, $pid = 0)
|
|
|
|
{
|
|
|
|
$model = new Category();
|
|
|
|
foreach ($items as $item) {
|
|
|
|
if ($item['name'] ?? '') {
|
|
|
|
$parent = $model->read(['pid' => $pid, 'title' => $item['name']], 'id');
|
|
|
|
if (!$parent) {
|
|
|
|
$parent_id = $model->addReturnId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $item['name'],
|
|
|
|
'pid' => $pid,
|
|
|
|
'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]);
|
|
|
|
} else {
|
|
|
|
$parent_id = $parent['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($item['children'])) {
|
|
|
|
$this->category_insert($project_id, $item['children'], $parent_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|