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.
72 lines
1.6 KiB
72 lines
1.6 KiB
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class MigrateUserAddr extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'migrateData:userAddr';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'migrate user addr 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_useradd')->get();
|
|
|
|
$bar = $this->output->createProgressBar(count($oldData));
|
|
$bar->start();
|
|
|
|
$newData = [];
|
|
foreach ($oldData as $key => $value) {
|
|
$newData[] = [
|
|
'user_id' => $value->user_id ?? '',
|
|
'user_name' => $value->user_name ?? '',
|
|
'address' => $value->address ?? '',
|
|
'gender' => $value->sex ?? 0,
|
|
'lat' => $value->lat ?? '',
|
|
'lng' => $value->lng ?? '',
|
|
'tel' => $value->tel ?? '',
|
|
'tags' => json_encode([]),
|
|
'created_at' => time(),
|
|
'updated_at' => time(),
|
|
];
|
|
|
|
$bar->advance();
|
|
}
|
|
|
|
// insert new data to new table
|
|
DB::table('lanzu_user_address')->insert($newData);
|
|
|
|
$bar->finish();
|
|
return 0;
|
|
}
|
|
}
|