作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !131
... ... @@ -9,6 +9,7 @@ use App\Models\Collect\CollectSource;
use App\Models\Collect\CollectTask;
use App\Models\Com\UpdateLog;
use App\Models\News\News;
use App\Models\News\NewsCategory;
use App\Models\Product\Category;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
... ... @@ -117,7 +118,7 @@ class ProjectUpdate extends Command
$project = ProjectServer::useProject($project_id);
if ($project) {
if ($api_type == 'category') {
//分类
//产品分类
$url = $api_url . '?' . http_build_query(['w' => 'category']);
$data = curl_c($url);
if (isset($data['code']) && $data['code'] == 200) {
... ... @@ -126,6 +127,16 @@ class ProjectUpdate extends Command
} else {
return true;
}
} elseif ($api_type == 'category_news') {
// 新闻分类
$url = $api_url . '?' . http_build_query(['w' => 'category_news']);
$data = curl_c($url);
if (isset($data['code']) && $data['code'] == 200) {
$items = $data['data'] ?? [];
$this->category_news_insert($project_id, $items, 0);
} else {
return true;
}
} elseif ($api_type == 'tag') {
//关键词
$url = $api_url . '?' . http_build_query(['w' => 'tag', 'page' => 1, 'pagesize' => 0]);
... ... @@ -457,7 +468,7 @@ class ProjectUpdate extends Command
return $task_id;
}
$task_list = UpdateLog::where('project_id', 543)->where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get();
$task_list = UpdateLog::where('project_id', 528)->where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get();
if ($task_list->count() == 0) {
return false;
}
... ... @@ -488,7 +499,7 @@ class ProjectUpdate extends Command
return end($path_arr) ? end($path_arr) : $path_arr[count($path_arr) - 2];
}
//多级分类入库
//产品多级分类入库
protected function category_insert($project_id, $items, $pid = 0)
{
$model = new Category();
... ... @@ -524,6 +535,37 @@ class ProjectUpdate extends Command
}
}
//新闻多级分类入库
protected function category_news_insert($project_id, $items, $pid = 0)
{
$model = new NewsCategory();
foreach ($items as $item) {
$item['name'] = $this->special2str($item['name'] ?? '');
if($item['name']){
$parent = $model->read(['pid' => $pid, 'name' => $item['name']], 'id');
if (!$parent) {
try {
$parent_id = $model->addReturnId([
'project_id' => $project_id,
'name' => $item['name'],
'pid' => $pid,
'original_id' => $item['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'];
}
if (!empty($item['children'])) {
$this->category_news_insert($project_id, $item['children'], $parent_id);
}
}
}
}
//特殊字符转换
protected function special2str($str)
{
... ...