作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !131
@@ -9,6 +9,7 @@ use App\Models\Collect\CollectSource; @@ -9,6 +9,7 @@ use App\Models\Collect\CollectSource;
9 use App\Models\Collect\CollectTask; 9 use App\Models\Collect\CollectTask;
10 use App\Models\Com\UpdateLog; 10 use App\Models\Com\UpdateLog;
11 use App\Models\News\News; 11 use App\Models\News\News;
  12 +use App\Models\News\NewsCategory;
12 use App\Models\Product\Category; 13 use App\Models\Product\Category;
13 use App\Models\Product\Keyword; 14 use App\Models\Product\Keyword;
14 use App\Models\Product\Product; 15 use App\Models\Product\Product;
@@ -117,7 +118,7 @@ class ProjectUpdate extends Command @@ -117,7 +118,7 @@ class ProjectUpdate extends Command
117 $project = ProjectServer::useProject($project_id); 118 $project = ProjectServer::useProject($project_id);
118 if ($project) { 119 if ($project) {
119 if ($api_type == 'category') { 120 if ($api_type == 'category') {
120 - //分类 121 + //产品分类
121 $url = $api_url . '?' . http_build_query(['w' => 'category']); 122 $url = $api_url . '?' . http_build_query(['w' => 'category']);
122 $data = curl_c($url); 123 $data = curl_c($url);
123 if (isset($data['code']) && $data['code'] == 200) { 124 if (isset($data['code']) && $data['code'] == 200) {
@@ -126,6 +127,16 @@ class ProjectUpdate extends Command @@ -126,6 +127,16 @@ class ProjectUpdate extends Command
126 } else { 127 } else {
127 return true; 128 return true;
128 } 129 }
  130 + } elseif ($api_type == 'category_news') {
  131 + // 新闻分类
  132 + $url = $api_url . '?' . http_build_query(['w' => 'category_news']);
  133 + $data = curl_c($url);
  134 + if (isset($data['code']) && $data['code'] == 200) {
  135 + $items = $data['data'] ?? [];
  136 + $this->category_news_insert($project_id, $items, 0);
  137 + } else {
  138 + return true;
  139 + }
129 } elseif ($api_type == 'tag') { 140 } elseif ($api_type == 'tag') {
130 //关键词 141 //关键词
131 $url = $api_url . '?' . http_build_query(['w' => 'tag', 'page' => 1, 'pagesize' => 0]); 142 $url = $api_url . '?' . http_build_query(['w' => 'tag', 'page' => 1, 'pagesize' => 0]);
@@ -457,7 +468,7 @@ class ProjectUpdate extends Command @@ -457,7 +468,7 @@ class ProjectUpdate extends Command
457 return $task_id; 468 return $task_id;
458 } 469 }
459 470
460 - $task_list = UpdateLog::where('project_id', 543)->where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get(); 471 + $task_list = UpdateLog::where('project_id', 528)->where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get();
461 if ($task_list->count() == 0) { 472 if ($task_list->count() == 0) {
462 return false; 473 return false;
463 } 474 }
@@ -488,7 +499,7 @@ class ProjectUpdate extends Command @@ -488,7 +499,7 @@ class ProjectUpdate extends Command
488 return end($path_arr) ? end($path_arr) : $path_arr[count($path_arr) - 2]; 499 return end($path_arr) ? end($path_arr) : $path_arr[count($path_arr) - 2];
489 } 500 }
490 501
491 - //多级分类入库 502 + //产品多级分类入库
492 protected function category_insert($project_id, $items, $pid = 0) 503 protected function category_insert($project_id, $items, $pid = 0)
493 { 504 {
494 $model = new Category(); 505 $model = new Category();
@@ -524,6 +535,37 @@ class ProjectUpdate extends Command @@ -524,6 +535,37 @@ class ProjectUpdate extends Command
524 } 535 }
525 } 536 }
526 537
  538 + //新闻多级分类入库
  539 + protected function category_news_insert($project_id, $items, $pid = 0)
  540 + {
  541 + $model = new NewsCategory();
  542 + foreach ($items as $item) {
  543 + $item['name'] = $this->special2str($item['name'] ?? '');
  544 + if($item['name']){
  545 + $parent = $model->read(['pid' => $pid, 'name' => $item['name']], 'id');
  546 + if (!$parent) {
  547 + try {
  548 + $parent_id = $model->addReturnId([
  549 + 'project_id' => $project_id,
  550 + 'name' => $item['name'],
  551 + 'pid' => $pid,
  552 + 'original_id' => $item['id']
  553 + ]);
  554 + } catch (\Exception $e) {
  555 + echo 'date:' . date('Y-m-d H:i:s') . ', category_news_insert error: ' . $e->getMessage() . PHP_EOL;
  556 + continue;
  557 + }
  558 + } else {
  559 + $parent_id = $parent['id'];
  560 + }
  561 +
  562 + if (!empty($item['children'])) {
  563 + $this->category_news_insert($project_id, $item['children'], $parent_id);
  564 + }
  565 + }
  566 + }
  567 + }
  568 +
527 //特殊字符转换 569 //特殊字符转换
528 protected function special2str($str) 570 protected function special2str($str)
529 { 571 {