|
|
|
@ -4,6 +4,7 @@ namespace App\Console\Commands; |
|
|
|
|
|
|
|
use App\Models\CollectProduct; |
|
|
|
use App\Models\Product; |
|
|
|
use App\Models\Supplier; |
|
|
|
use Illuminate\Console\Command; |
|
|
|
use Illuminate\Support\Facades\Http; |
|
|
|
|
|
|
|
@ -21,7 +22,7 @@ class Collector extends Command |
|
|
|
* |
|
|
|
* @var string |
|
|
|
*/ |
|
|
|
protected $description = '驴妈妈产品采集'; |
|
|
|
protected $description = '马蜂窝产品采集'; |
|
|
|
|
|
|
|
/** |
|
|
|
* 如果已经存在是否要更新,true更新,false不更新 |
|
|
|
@ -48,9 +49,7 @@ class Collector extends Command |
|
|
|
{ |
|
|
|
$supplier_id = $this->option('import'); |
|
|
|
if (!empty($supplier_id)) { |
|
|
|
if (ctype_digit($supplier_id)) { |
|
|
|
$this->import($supplier_id); |
|
|
|
} |
|
|
|
$this->import($supplier_id); |
|
|
|
$this->line("供应商 $supplier_id 导入完毕"); |
|
|
|
} else { |
|
|
|
// $this->exists_update = false;
|
|
|
|
@ -65,11 +64,11 @@ class Collector extends Command |
|
|
|
private function import($supplier_id) |
|
|
|
{ |
|
|
|
$limit = $this->option('limit'); |
|
|
|
$cpModel = CollectProduct::query()->orderBy('id', 'desc'); |
|
|
|
if (!empty($limit)) { |
|
|
|
$arr = explode(',', $limit); |
|
|
|
$count = count($arr); |
|
|
|
|
|
|
|
$cpModel = CollectProduct::query()->orderBy('id', 'desc'); |
|
|
|
if ($count == 1) { |
|
|
|
$import_data = $cpModel->limit($arr[0])->get()->toArray(); |
|
|
|
} else if ($count == 2) { |
|
|
|
@ -77,13 +76,27 @@ class Collector extends Command |
|
|
|
} else { |
|
|
|
$import_data = $cpModel->get()->toArray(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
$import_data = $cpModel->get()->toArray(); |
|
|
|
} |
|
|
|
|
|
|
|
if (ctype_digit($supplier_id)) { |
|
|
|
array_walk($import_data, function ($v) use ($supplier_id) { |
|
|
|
$v['supplier_id'] = $supplier_id; |
|
|
|
unset($v['unique_id'], $v['site']); |
|
|
|
|
|
|
|
Product::query()->updateOrCreate(['supplier_id' => $supplier_id, 'title' => $v['title']], $v); |
|
|
|
}); |
|
|
|
} else if ($supplier_id == 'all') { |
|
|
|
$ids = Supplier::query()->pluck('id'); |
|
|
|
foreach ($ids as $supplier_id) { |
|
|
|
array_walk($import_data, function ($v) use ($supplier_id) { |
|
|
|
$v['supplier_id'] = $supplier_id; |
|
|
|
unset($v['unique_id'], $v['site']); |
|
|
|
|
|
|
|
Product::query()->updateOrCreate(['supplier_id' => $supplier_id, 'title' => $v['title']], $v); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|