作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !33
... ... @@ -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,17 +147,18 @@ class ProjectUpdate extends Command
$model = new Keyword();
foreach ($items as $item) {
$keyword = $model->read(['title' => $item['text_title']], 'id');
if ($item['name'] ?? '') {
$keyword = $model->read(['title' => $item['name']], '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'],
'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['text_title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
$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;
... ... @@ -165,6 +169,9 @@ class ProjectUpdate extends Command
}
}
}
} else {
return true;
}
} elseif ($api_type == 'website_info') {
//网站信息
$url = $api_url . '?' . http_build_query(['w' => 'website_info']);
... ... @@ -175,26 +182,38 @@ class ProjectUpdate extends Command
$model = new WebSettingReceiving();
if ($phones) {
$receiving_phones = $model->read(['type' => 1, 'values' => $phones]);
$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' => $phones,
'values' => $v_phone,
'project_id' => $project_id
]);
}
}
}
}
if ($emails) {
$receiving_emails = $model->read(['type' => 2, 'values' => $emails]);
$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' => $emails,
'values' => $v_email,
'project_id' => $project_id
]);
}
}
}
}
} else {
return true;
}
} elseif ($api_type == 'post') {
//产品
$url = $api_url . '?' . http_build_query(['w' => 'post', 'page' => 1, 'pagesize' => 0]);
... ... @@ -212,17 +231,19 @@ class ProjectUpdate extends Command
$model = new Product();
foreach ($items as $item) {
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];
}
}
//分类
$category_id = '';
if ($item['category']) {
if ($item['category'] ?? []) {
$category_arr = [];
foreach ($item['category'] as $cate) {
if ($cate['parent'] == 0) {
... ... @@ -240,15 +261,15 @@ class ProjectUpdate extends Command
$id = $model->addReturnId([
'project_id' => $project_id,
'title' => $item['ttile'],
'intro' => $item['description'],
'content' => $item['content'],
'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']
'keyword' => $item['keywords'] ?? '',
'description' => $item['description'] ?? ''
]),
'status' => Product::STATUS_ON
]);
... ... @@ -263,6 +284,9 @@ class ProjectUpdate extends Command
}
}
}
} else {
return true;
}
} elseif ($api_type == 'news' || $api_type == 'blog') {
//新闻或博客
$url = $api_url . '?' . http_build_query(['w' => $api_type, 'page' => 1, 'pagesize' => 0]);
... ... @@ -285,6 +309,7 @@ class ProjectUpdate extends Command
foreach ($items as $item) {
if ($item['ttile'] ?? '') {
$news = $model->read(['name' => $item['ttile']], 'id');
if (!$news) {
try {
... ... @@ -292,9 +317,9 @@ class ProjectUpdate extends Command
'project_id' => $project_id,
'name' => $item['ttile'],
'seo_title' => $item['ttile'],
'seo_keywords' => $item['keywords'],
'seo_description' => $item['description'],
'text' => $item['content'],
'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
]);
... ... @@ -310,6 +335,9 @@ class ProjectUpdate extends Command
}
}
} else {
return true;
}
} else {
//单页
$url = $api_url . '?' . http_build_query(['w' => 'page', 'page' => 1, 'pagesize' => 0]);
$data = http_get($url, ['charset' => 'UTF-8']);
... ... @@ -326,7 +354,7 @@ class ProjectUpdate extends Command
$model = new BCustomTemplate();
foreach ($items as $item) {
if ($item['ttile'] ?? '') {
$custom = $model->read(['name' => $item['ttile']], 'id');
if (!$custom) {
try {
... ... @@ -334,9 +362,9 @@ class ProjectUpdate extends Command
'project_id' => $project_id,
'name' => $item['ttile'],
'title' => $item['ttile'],
'keywords' => $item['keywords'],
'description' => $item['description'],
'html' => $item['content'],
'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);
... ... @@ -350,6 +378,9 @@ class ProjectUpdate extends Command
}
}
}
} 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);
}
}
}
}
}
... ...