You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.0 KiB
79 lines
2.0 KiB
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class MigrateMarketData extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'migrateData:market';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'migrate market data';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
|
|
// get old data from old table
|
|
$oldData = DB::table('ims_cjdc_market')->get();
|
|
|
|
$bar = $this->output->createProgressBar(count($oldData));
|
|
$bar->start();
|
|
|
|
$newData = [];
|
|
foreach ($oldData as $key => $value) {
|
|
$coordinates = explode(',', $value->coordinates);
|
|
$newData[] = [
|
|
'mp_id' => $value->mp_id ?? 0,
|
|
'name' => $value->name ?? '',
|
|
'logo' => $value->logo ?? '',
|
|
'introduce' => $value->introduce ?? '',
|
|
'imgs' => $value->imgs ?? '',
|
|
'province_id' => 2162,
|
|
'city_id' => 2163,
|
|
'region_id' => 0,
|
|
'address' => $value->address ?? '',
|
|
'tel' => $value->tel ?? '',
|
|
'lat' => $coordinates[0] ?? '',
|
|
'lng' => $coordinates[1] ?? '',
|
|
'status' => $value->status ?? 1,
|
|
'sort' => $value->sort ?? 1,
|
|
'created_at' => $value->addtime ? strtotime($value->addtime) : 0,
|
|
'updated_at' => $value->addtime ? strtotime($value->addtime) : 0,
|
|
];
|
|
|
|
$bar->advance();
|
|
}
|
|
|
|
// insert new data to new table
|
|
DB::table('lanzu_market')->insert($newData);
|
|
|
|
$bar->finish();
|
|
return 0;
|
|
}
|
|
}
|