|
|
|
@ -4,6 +4,7 @@ namespace App\Console\Commands; |
|
|
|
|
|
|
|
use Illuminate\Console\Command; |
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
use Illuminate\Support\Facades\Schema; |
|
|
|
|
|
|
|
class MigrateUserAddr extends Command |
|
|
|
{ |
|
|
|
@ -19,7 +20,7 @@ class MigrateUserAddr extends Command |
|
|
|
* |
|
|
|
* @var string |
|
|
|
*/ |
|
|
|
protected $description = 'migrate user addr data'; |
|
|
|
protected $description = 'migrate 迁移用户地址数据'; |
|
|
|
|
|
|
|
/** |
|
|
|
* Create a new command instance. |
|
|
|
@ -39,23 +40,41 @@ class MigrateUserAddr extends Command |
|
|
|
public function handle() |
|
|
|
{ |
|
|
|
|
|
|
|
// get old data from old table
|
|
|
|
$oldData = DB::table('ims_cjdc_useradd')->get(); |
|
|
|
$oldTableName = 'ims_cjdc_useradd'; |
|
|
|
$newTableName = 'lanzu_user_address'; |
|
|
|
// 判断表是否存在
|
|
|
|
if(!Schema::hasTable($oldTableName)){ |
|
|
|
var_dump('旧表不存在'); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
if(!Schema::hasTable($newTableName)){ |
|
|
|
var_dump('新表不存在'); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
$oldData = DB::table($oldTableName)->get(); |
|
|
|
|
|
|
|
$bar = $this->output->createProgressBar(count($oldData)); |
|
|
|
$bar->start(); |
|
|
|
|
|
|
|
$newData = []; |
|
|
|
foreach ($oldData as $key => $value) { |
|
|
|
|
|
|
|
$addressArr = explode('|',$value->address); |
|
|
|
$address = $addressArr[0]; |
|
|
|
$doorplate = isset($addressArr[1])?$addressArr[1]:''; |
|
|
|
|
|
|
|
$newData[] = [ |
|
|
|
'user_id' => $value->user_id ?? '', |
|
|
|
'user_name' => $value->user_name ?? '', |
|
|
|
'address' => $value->address ?? '', |
|
|
|
'id' => $value->id, |
|
|
|
'user_id' => $value->user_id ?? 0, |
|
|
|
'user_name' => $value->user_name == 'undefined'? '': $value->user_name, |
|
|
|
'address' => $address, |
|
|
|
'gender' => $value->sex ?? 0, |
|
|
|
'lat' => $value->lat ?? '', |
|
|
|
'lng' => $value->lng ?? '', |
|
|
|
'tel' => $value->tel ?? '', |
|
|
|
'tags' => json_encode([]), |
|
|
|
'tel' => $value->tel == 'undefined'? '': $value->tel, |
|
|
|
'doorplate' => $doorplate, |
|
|
|
'is_default' => $value->is_default ?? 0, |
|
|
|
'tags' => json_encode(''), |
|
|
|
'created_at' => time(), |
|
|
|
'updated_at' => time(), |
|
|
|
]; |
|
|
|
|