|
|
|
@ -3,6 +3,7 @@ |
|
|
|
namespace App\Console\Commands; |
|
|
|
|
|
|
|
use App\Models\CollectProduct; |
|
|
|
use App\Models\Product; |
|
|
|
use Illuminate\Console\Command; |
|
|
|
use Illuminate\Support\Facades\Http; |
|
|
|
|
|
|
|
@ -13,7 +14,7 @@ class Collector extends Command |
|
|
|
* |
|
|
|
* @var string |
|
|
|
*/ |
|
|
|
protected $signature = 'collector'; |
|
|
|
protected $signature = 'collector {--import=} {--limit=}'; //php artisan collector --import=$supplier_id
|
|
|
|
|
|
|
|
/** |
|
|
|
* The console command description. |
|
|
|
@ -45,12 +46,46 @@ class Collector extends Command |
|
|
|
*/ |
|
|
|
public function handle() |
|
|
|
{ |
|
|
|
// $this->exists_update = false;
|
|
|
|
$this->scenic(); |
|
|
|
$this->hotel(); |
|
|
|
$supplier_id = $this->option('import'); |
|
|
|
if (!empty($supplier_id)) { |
|
|
|
if (ctype_digit($supplier_id)) { |
|
|
|
$this->import($supplier_id); |
|
|
|
} |
|
|
|
$this->line("供应商 $supplier_id 导入完毕"); |
|
|
|
} else { |
|
|
|
// $this->exists_update = false;
|
|
|
|
$this->scenic(); |
|
|
|
$this->hotel(); |
|
|
|
$this->line('全部采集完毕'); |
|
|
|
} |
|
|
|
return Command::SUCCESS; |
|
|
|
} |
|
|
|
//php artisan collector
|
|
|
|
|
|
|
|
//导入
|
|
|
|
private function import($supplier_id) |
|
|
|
{ |
|
|
|
$limit = $this->option('limit'); |
|
|
|
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) { |
|
|
|
$import_data = $cpModel->offset($arr[0])->limit($arr[1])->get()->toArray(); |
|
|
|
} else { |
|
|
|
$import_data = $cpModel->get()->toArray(); |
|
|
|
} |
|
|
|
|
|
|
|
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); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//酒店采集
|
|
|
|
private function hotel() |
|
|
|
|