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.
98 lines
2.6 KiB
98 lines
2.6 KiB
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class MigrateStoreWithdrawal extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'migrateData:storeWithdrawal';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Command 迁移店铺提现记录数据';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$oldTableName = 'ims_cjdc_withdrawal';
|
|
$newTableName = 'lanzu_store_withdrawal';
|
|
// 判断表是否存在
|
|
if(!Schema::hasTable($oldTableName)){
|
|
var_dump('旧表不存在');
|
|
return 0;
|
|
}
|
|
if(!Schema::hasTable($newTableName)){
|
|
var_dump('新表不存在');
|
|
return 0;
|
|
}
|
|
|
|
$typeData = [2 => 1,3 => 3, 1 => 4];
|
|
$oldData = DB::table($oldTableName)->orderBy('id','asc')->get();
|
|
$bar = $this->output->createProgressBar(count($oldData));
|
|
$bar->start();
|
|
$startTime = time();
|
|
$error = [];
|
|
foreach ($oldData as $key => $value){
|
|
$withdrawalId = $value->id;
|
|
// 判断记录在新表是否存在
|
|
$exist = DB::table($newTableName)->where('id',$withdrawalId)->exists();
|
|
if($exist){
|
|
continue;
|
|
}
|
|
$newData =[
|
|
'id'=>$withdrawalId,
|
|
'store_id'=>$value->store_id,
|
|
|
|
'name'=>$value->name,
|
|
'tel'=>$value->tel,
|
|
'type'=> isset($typeData[$value->type])?$typeData[$value->type]:0,
|
|
'check_time'=>strtotime($value->sh_time),
|
|
'state'=>$value->state,
|
|
|
|
'apply_cash'=>$value->tx_cost,
|
|
'real_cash'=>$value->sj_cost,
|
|
'bank_card'=>$value->yhk_num,
|
|
'bank_info'=>$value->yh_info,
|
|
|
|
'created_at' => strtotime($value->time),
|
|
'updated_at' => strtotime($value->sh_time),
|
|
];
|
|
|
|
$res = DB::table($newTableName)->insert($newData);
|
|
if(!$res){
|
|
$error[] = ['id'=>$withdrawalId];
|
|
break;
|
|
}
|
|
$bar->advance();
|
|
}
|
|
$bar->finish();
|
|
var_dump([time()-$startTime]);
|
|
var_dump($error);
|
|
return 0;
|
|
}
|
|
}
|