作者 lyh
@@ -233,9 +233,18 @@ class SyncProject extends Command @@ -233,9 +233,18 @@ class SyncProject extends Command
233 $this->createUser($data['project']['mobile'],$id,$data['project']['lead_name']); 233 $this->createUser($data['project']['mobile'],$id,$data['project']['lead_name']);
234 234
235 //新增数据抓取任务 235 //新增数据抓取任务
  236 + $task_list = [];
236 foreach ($param['api_type'] as $v_type){ 237 foreach ($param['api_type'] as $v_type){
237 - UpdateLog::createLog($id,$v_type,$param['get_data_url']); 238 + if($v_type == 'category'){
  239 + UpdateLog::createLog($id,$v_type,$param['get_data_url']);
  240 + }else{
  241 + $task_list[] = $v_type;
  242 + }
238 } 243 }
  244 + foreach ($task_list as $task){
  245 + UpdateLog::createLog($id,$task,$param['get_data_url']);
  246 + }
  247 +
239 } 248 }
240 249
241 DB::commit(); 250 DB::commit();
@@ -8,10 +8,12 @@ use App\Http\Logic\Bside\Product\KeywordLogic; @@ -8,10 +8,12 @@ use App\Http\Logic\Bside\Product\KeywordLogic;
8 use App\Models\Blog\Blog; 8 use App\Models\Blog\Blog;
9 use App\Models\Com\UpdateLog; 9 use App\Models\Com\UpdateLog;
10 use App\Models\News\News; 10 use App\Models\News\News;
  11 +use App\Models\Product\Category;
11 use App\Models\Product\Keyword; 12 use App\Models\Product\Keyword;
12 use App\Models\Product\Product; 13 use App\Models\Product\Product;
13 use App\Models\RouteMap\RouteMap; 14 use App\Models\RouteMap\RouteMap;
14 use App\Models\Template\BCustomTemplate; 15 use App\Models\Template\BCustomTemplate;
  16 +use App\Models\WebSetting\WebSettingReceiving;
15 use App\Services\ProjectServer; 17 use App\Services\ProjectServer;
16 use Illuminate\Console\Command; 18 use Illuminate\Console\Command;
17 use Illuminate\Support\Facades\DB; 19 use Illuminate\Support\Facades\DB;
@@ -52,7 +54,7 @@ class ProjectUpdate extends Command @@ -52,7 +54,7 @@ class ProjectUpdate extends Command
52 { 54 {
53 $task_id = $this->get_task(); 55 $task_id = $this->get_task();
54 if (!$task_id) { 56 if (!$task_id) {
55 - sleep(2); 57 + sleep(60);
56 return true; 58 return true;
57 } 59 }
58 60
@@ -77,26 +79,119 @@ class ProjectUpdate extends Command @@ -77,26 +79,119 @@ class ProjectUpdate extends Command
77 //设置数据库 79 //设置数据库
78 $project = ProjectServer::useProject($task->project_id); 80 $project = ProjectServer::useProject($task->project_id);
79 if ($project) { 81 if ($project) {
80 - if ($api_type == 'website_info') { 82 + if ($api_type == 'category') {
  83 + //分类
  84 + $url = $api_url . '?' . http_build_query(['w' => 'category']);
  85 + $data = http_get($url, ['charset' => 'UTF-8']);
  86 + if (isset($data['code']) && $data['code'] == 200) {
  87 + $items = $data['data'] ?? [];
  88 + $model = new Category();
  89 + foreach ($items as $item) {
  90 + $parent = $model->read(['pid' => 0, 'title' => $item['name']], 'id');
  91 + if (!$parent) {
  92 + try {
  93 + $parent_id = $model->addReturnId([
  94 + 'project_id' => $project_id,
  95 + 'title' => $item['name'],
  96 + 'pid' => 0,
  97 + 'keywords' => $item['keywords'],
  98 + 'describe' => $item['description']
  99 + ]);
  100 + $route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['name'], RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
  101 + $model->edit(['route' => $route], ['id' => $parent_id]);
  102 + } catch (\Exception $e) {
  103 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  104 + continue;
  105 + }
  106 + }else{
  107 + $parent_id = $parent['id'];
  108 + }
  109 +
  110 + foreach ($item['children'] as $child) {
  111 + $child_info = $model->read(['pid' => $parent_id, 'title' => $child['name']]);
  112 + if (!$child_info) {
  113 + try {
  114 + $child_id = $model->addReturnId([
  115 + 'project_id' => $project_id,
  116 + 'title' => $child['name'],
  117 + 'pid' => $parent_id,
  118 + 'keywords' => $child['keywords'],
  119 + 'describe' => $child['description']
  120 + ]);
  121 + $route = RouteMap::setRoute($child['url'] ? $this->get_url_route($child['url']) : $child['name'], RouteMap::SOURCE_PRODUCT_CATE, $child_id, $project_id);
  122 + $model->edit(['route' => $route], ['id' => $child_id]);
  123 + } catch (\Exception $e) {
  124 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  125 + continue;
  126 + }
  127 + }
  128 + }
  129 + }
  130 + }
  131 + } elseif ($api_type == 'tag') {
81 //关键词 132 //关键词
82 - $url = $api_url . '?' . http_build_query(['w' => 'website_info']); 133 + $url = $api_url . '?' . http_build_query(['w' => 'tag', 'page' => 1, 'pagesize' => 0]);
83 $data = http_get($url, ['charset' => 'UTF-8']); 134 $data = http_get($url, ['charset' => 'UTF-8']);
84 if (isset($data['code']) && $data['code'] == 200) { 135 if (isset($data['code']) && $data['code'] == 200) {
85 - $items = $data['data']['tags'] ?? []; 136 + $count = $data['data']['count'] ?? 0;
86 137
87 - $model = new Keyword();  
88 - foreach ($items as $item) {  
89 - if (strlen($item) > 50) {  
90 - continue; 138 + $total_page = ceil($count / $page_size);
  139 + for ($page = 1; $page <= $total_page; $page++) {
  140 + $url_page = $api_url . '?' . http_build_query(['w' => 'tag', 'page' => $page, 'pagesize' => $page_size]);
  141 + $data_page = http_get($url_page, ['charset' => 'UTF-8']);
  142 + if (isset($data_page['code']) && $data_page['code'] == 200) {
  143 + $items = $data_page['data']['data'] ?? [];
  144 +
  145 + $model = new Keyword();
  146 + foreach ($items as $item) {
  147 + $keyword = $model->read(['title' => $item['text_title']], 'id');
  148 + if (!$keyword) {
  149 + try {
  150 + $id = $model->addReturnId([
  151 + 'project_id' => $project_id,
  152 + 'title' => $item['text_title'],
  153 + 'seo_title' => $item['seo_title'],
  154 + 'seo_keywords' => $item['seo_keywords'],
  155 + 'seo_description' => $item['seo_description'],
  156 + ]);
  157 + $route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['text_title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
  158 + $model->edit(['route' => $route], ['id' => $id]);
  159 + } catch (\Exception $e) {
  160 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  161 + continue;
  162 + }
  163 + }
  164 + }
  165 + }
  166 + }
  167 + }
  168 + } elseif ($api_type == 'website_info') {
  169 + //网站信息
  170 + $url = $api_url . '?' . http_build_query(['w' => 'website_info']);
  171 + $data = http_get($url, ['charset' => 'UTF-8']);
  172 + if (isset($data['code']) && $data['code'] == 200) {
  173 + $phones = $data['data']['phones'] ?? '';
  174 + $emails = $data['data']['emails'] ?? '';
  175 +
  176 + $model = new WebSettingReceiving();
  177 + if ($phones) {
  178 + $receiving_phones = $model->read(['type' => 1, 'values' => $phones]);
  179 + if (!$receiving_phones) {
  180 + $model->add([
  181 + 'type' => 1,
  182 + 'values' => $phones,
  183 + 'project_id' => $project_id
  184 + ]);
91 } 185 }
92 - $keyword = $model->read(['title' => $item], 'id');  
93 - if (!$keyword) {  
94 - $id = $model->addReturnId([  
95 - 'project_id' => $project_id,  
96 - 'title' => $item 186 + }
  187 + if ($emails) {
  188 + $receiving_emails = $model->read(['type' => 2, 'values' => $emails]);
  189 + if (!$receiving_emails) {
  190 + $model->add([
  191 + 'type' => 2,
  192 + 'values' => $emails,
  193 + 'project_id' => $project_id
97 ]); 194 ]);
98 - $route = RouteMap::setRoute($item, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);  
99 - $model->edit(['route' => $route], ['id' => $id]);  
100 } 195 }
101 } 196 }
102 } 197 }
@@ -125,12 +220,6 @@ class ProjectUpdate extends Command @@ -125,12 +220,6 @@ class ProjectUpdate extends Command
125 foreach ($item['images'] as $k_img => $img) { 220 foreach ($item['images'] as $k_img => $img) {
126 $gallery[] = ['alt' => '这是一张产品图', 'url' => $img]; 221 $gallery[] = ['alt' => '这是一张产品图', 'url' => $img];
127 } 222 }
128 - //关键词  
129 - $keyword_id = '';  
130 - if ($item['keywords']) {  
131 - $keywordLogic = new KeywordLogic();  
132 - $keyword_id = $keywordLogic->importProductKeyword($project_id, $item['keywords']);  
133 - }  
134 //分类 223 //分类
135 $category_id = ''; 224 $category_id = '';
136 if ($item['category']) { 225 if ($item['category']) {
@@ -147,24 +236,28 @@ class ProjectUpdate extends Command @@ -147,24 +236,28 @@ class ProjectUpdate extends Command
147 $category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr)); 236 $category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr));
148 } 237 }
149 } 238 }
150 - $id = $model->addReturnId([  
151 - 'project_id' => $project_id,  
152 - 'title' => $item['ttile'],  
153 - 'intro' => $item['description'],  
154 - 'content' => $item['content'],  
155 - 'keyword_id' => $keyword_id,  
156 - 'category_id' => $category_id,  
157 - 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',  
158 - 'gallery' => Arr::a2s($gallery),  
159 - 'seo_mate' => Arr::a2s([ 239 + try {
  240 + $id = $model->addReturnId([
  241 + 'project_id' => $project_id,
160 'title' => $item['ttile'], 242 'title' => $item['ttile'],
161 - 'keyword' => $item['keywords'],  
162 - 'description' => $item['description']  
163 - ]),  
164 - 'status' => Product::STATUS_ON  
165 - ]);  
166 - $route = RouteMap::setRoute($item['ttile'], RouteMap::SOURCE_PRODUCT, $id, $project_id);  
167 - $model->edit(['route' => $route], ['id' => $id]); 243 + 'intro' => $item['description'],
  244 + 'content' => $item['content'],
  245 + 'category_id' => $category_id,
  246 + 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
  247 + 'gallery' => Arr::a2s($gallery),
  248 + 'seo_mate' => Arr::a2s([
  249 + 'title' => $item['ttile'],
  250 + 'keyword' => $item['keywords'],
  251 + 'description' => $item['description']
  252 + ]),
  253 + 'status' => Product::STATUS_ON
  254 + ]);
  255 + $route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], RouteMap::SOURCE_PRODUCT, $id, $project_id);
  256 + $model->edit(['route' => $route], ['id' => $id]);
  257 + } catch (\Exception $e) {
  258 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  259 + continue;
  260 + }
168 } 261 }
169 } 262 }
170 } 263 }
@@ -194,16 +287,23 @@ class ProjectUpdate extends Command @@ -194,16 +287,23 @@ class ProjectUpdate extends Command
194 287
195 $news = $model->read(['name' => $item['ttile']], 'id'); 288 $news = $model->read(['name' => $item['ttile']], 'id');
196 if (!$news) { 289 if (!$news) {
197 - $id = $model->addReturnId([  
198 - 'project_id' => $project_id,  
199 - 'name' => $item['ttile'],  
200 - 'seo_title' => $item['ttile'],  
201 - 'text' => $item['content'],  
202 - 'image' => $item['images'][0] ?? '',  
203 - 'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE  
204 - ]);  
205 - $route = RouteMap::setRoute($item['ttile'], $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);  
206 - $model->edit(['url' => $route], ['id' => $id]); 290 + try {
  291 + $id = $model->addReturnId([
  292 + 'project_id' => $project_id,
  293 + 'name' => $item['ttile'],
  294 + 'seo_title' => $item['ttile'],
  295 + 'seo_keywords' => $item['keywords'],
  296 + 'seo_description' => $item['description'],
  297 + 'text' => $item['content'],
  298 + 'image' => $item['images'][0] ?? '',
  299 + 'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE
  300 + ]);
  301 + $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);
  302 + $model->edit(['url' => $route], ['id' => $id]);
  303 + } catch (\Exception $e) {
  304 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  305 + continue;
  306 + }
207 } 307 }
208 } 308 }
209 } 309 }
@@ -229,13 +329,22 @@ class ProjectUpdate extends Command @@ -229,13 +329,22 @@ class ProjectUpdate extends Command
229 329
230 $custom = $model->read(['name' => $item['ttile']], 'id'); 330 $custom = $model->read(['name' => $item['ttile']], 'id');
231 if (!$custom) { 331 if (!$custom) {
232 - $id = $model->addReturnId([  
233 - 'project_id' => $project_id,  
234 - 'name' => $item['ttile'],  
235 - 'html' => $item['content']  
236 - ]);  
237 - $route = RouteMap::setRoute($item['ttile'], RouteMap::SOURCE_PAGE, $id, $project_id);  
238 - $model->edit(['url' => $route], ['id' => $id]); 332 + try {
  333 + $id = $model->addReturnId([
  334 + 'project_id' => $project_id,
  335 + 'name' => $item['ttile'],
  336 + 'title' => $item['ttile'],
  337 + 'keywords' => $item['keywords'],
  338 + 'description' => $item['description'],
  339 + 'html' => $item['content'],
  340 + 'status' => 1
  341 + ]);
  342 + $route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], RouteMap::SOURCE_PAGE, $id, $project_id);
  343 + $model->edit(['url' => $route], ['id' => $id]);
  344 + } catch (\Exception $e) {
  345 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  346 + continue;
  347 + }
239 } 348 }
240 } 349 }
241 } 350 }
@@ -263,7 +372,7 @@ class ProjectUpdate extends Command @@ -263,7 +372,7 @@ class ProjectUpdate extends Command
263 return $task_id; 372 return $task_id;
264 } 373 }
265 374
266 - $task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->limit(20)->get(); 375 + $task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get();
267 if ($task_list->count() == 0) { 376 if ($task_list->count() == 0) {
268 return false; 377 return false;
269 } 378 }
@@ -276,4 +385,10 @@ class ProjectUpdate extends Command @@ -276,4 +385,10 @@ class ProjectUpdate extends Command
276 return $task_id; 385 return $task_id;
277 } 386 }
278 387
  388 + //获取地址路由
  389 + protected function get_url_route($url)
  390 + {
  391 + $arr = explode('/', $url);
  392 + return $arr[count($arr) - 2];
  393 + }
279 } 394 }