作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Test;
  4 +
  5 +use App\Models\Collect\CollectTask;
  6 +use App\Models\Com\UpdateLog;
  7 +use App\Services\ProjectServer;
  8 +use Illuminate\Console\Command;
  9 +use Illuminate\Support\Facades\DB;
  10 +
  11 +class Temp extends Command
  12 +{
  13 + /**
  14 + * The name and signature of the console command.
  15 + *
  16 + * @var string
  17 + */
  18 + protected $signature = 'test_temp';
  19 +
  20 + /**
  21 + * The console command description.
  22 + *
  23 + * @var string
  24 + */
  25 + protected $description = '临时脚本';
  26 +
  27 +
  28 + public function handle()
  29 + {
  30 + $data = UpdateLog::where('sort', 0)->get();
  31 +
  32 + foreach ($data as $item) {
  33 + $project_id = $item->project_id;
  34 + $project = ProjectServer::useProject($project_id);
  35 + if ($project) {
  36 + try {
  37 + DB::connection('custom_mysql')->statement("ALTER TABLE `gl_product_category` ADD COLUMN `original_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '来源id'");
  38 + } catch (\Exception $e) {
  39 + echo $project_id . '已存在';
  40 + continue;
  41 + }
  42 + }
  43 + //关闭数据库
  44 + DB::disconnect('custom_mysql');
  45 +
  46 + echo $project_id.'成功';
  47 + }
  48 + }
  49 +}
@@ -237,6 +237,8 @@ class ProjectUpdate extends Command @@ -237,6 +237,8 @@ class ProjectUpdate extends Command
237 $items = $data_page['data']['data'] ?? []; 237 $items = $data_page['data']['data'] ?? [];
238 238
239 $model = new Product(); 239 $model = new Product();
  240 + $category_model = new Category();
  241 + $logic = new CategoryLogic();
240 242
241 foreach ($items as $item) { 243 foreach ($items as $item) {
242 $route = $this->get_url_route($item['url'] ?? ''); 244 $route = $this->get_url_route($item['url'] ?? '');
@@ -256,33 +258,26 @@ class ProjectUpdate extends Command @@ -256,33 +258,26 @@ class ProjectUpdate extends Command
256 $product_type = ''; 258 $product_type = '';
257 259
258 if ($item['category'] ?? []) { 260 if ($item['category'] ?? []) {
259 - $category_arr = [];  
260 -  
261 - $pid = 0;  
262 - for ($i = 0; $i < count($item['category']); $i++) {  
263 - $return = $this->get_category_name_arr($item['category'], $pid);  
264 - if ($return) {  
265 - $category_arr[] = $this->special2str($return['name'] ?? '');  
266 - $pid = $return['id'];  
267 - }  
268 - }  
269 -  
270 - if ($category_arr) {  
271 - $categoryLogic = new CategoryLogic();  
272 - $category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr));  
273 - }  
274 -  
275 $type_arr = []; 261 $type_arr = [];
  262 + $new_category = [];
276 foreach ($item['category'] as $cate) { 263 foreach ($item['category'] as $cate) {
277 if ($cate['parent'] == 0 && $cate['name'] == 'Featured Products') { 264 if ($cate['parent'] == 0 && $cate['name'] == 'Featured Products') {
278 $type_arr[] = 2; 265 $type_arr[] = 2;
279 } elseif ($cate['parent'] == 0 && $cate['name'] == 'Hot Products') { 266 } elseif ($cate['parent'] == 0 && $cate['name'] == 'Hot Products') {
280 $type_arr[] = 3; 267 $type_arr[] = 3;
  268 + } else {
  269 + $new_category[] = $cate['id'];
281 } 270 }
282 } 271 }
  272 +
283 if ($type_arr) { 273 if ($type_arr) {
284 $product_type = ',' . implode(',', $type_arr); 274 $product_type = ',' . implode(',', $type_arr);
285 } 275 }
  276 +
  277 + if ($new_category) {
  278 + $category_arr = $category_model->list(['original_id' => ['in', $new_category]]);
  279 + $category_id = $logic->getLastCategory(array_column($category_arr, 'id'));
  280 + }
286 } 281 }
287 try { 282 try {
288 $item['ttile'] = $this->special2str($item['ttile'] ?? ''); 283 $item['ttile'] = $this->special2str($item['ttile'] ?? '');
@@ -507,6 +502,7 @@ class ProjectUpdate extends Command @@ -507,6 +502,7 @@ class ProjectUpdate extends Command
507 'pid' => $pid, 502 'pid' => $pid,
508 'keywords' => $item['keywords'] ?? '', 503 'keywords' => $item['keywords'] ?? '',
509 'describe' => $item['description'] ?? '', 504 'describe' => $item['description'] ?? '',
  505 + 'original_id' => $item['id'],
510 'route' => $route 506 'route' => $route
511 ]); 507 ]);
512 $this->set_map($route, RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id); 508 $this->set_map($route, RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
@@ -525,18 +521,6 @@ class ProjectUpdate extends Command @@ -525,18 +521,6 @@ class ProjectUpdate extends Command
525 } 521 }
526 } 522 }
527 523
528 - //获取分类名称数组  
529 - protected function get_category_name_arr($category, $pid = 0)  
530 - {  
531 - foreach ($category as $k => $v) {  
532 - if ($v['parent'] == $pid) {  
533 - return $v;  
534 - }  
535 - }  
536 -  
537 - return [];  
538 - }  
539 -  
540 //特殊字符转换 524 //特殊字符转换
541 protected function special2str($str) 525 protected function special2str($str)
542 { 526 {
@@ -154,6 +154,9 @@ class ProductLogic extends BaseLogic @@ -154,6 +154,9 @@ class ProductLogic extends BaseLogic
154 }else{ 154 }else{
155 $this->param['thumb'] = Arr::a2s([]); 155 $this->param['thumb'] = Arr::a2s([]);
156 } 156 }
  157 + if(isset($this->param['route']) && !empty($this->param['route'])){
  158 + $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']);
  159 + }
157 $this->model->edit($this->param,['id'=>$this->param['id']]); 160 $this->model->edit($this->param,['id'=>$this->param['id']]);
158 return $this->success(); 161 return $this->success();
159 } 162 }