2 changed files with 104 additions and 15 deletions
@ -0,0 +1,80 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Console\Commands; |
||||
|
|
||||
|
use Illuminate\Console\Command; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use Illuminate\Support\Facades\Schema; |
||||
|
|
||||
|
class MigrateStoreBalance extends Command |
||||
|
{ |
||||
|
/** |
||||
|
* The name and signature of the console command. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $signature = 'migrateData:storeBalance'; |
||||
|
|
||||
|
/** |
||||
|
* The console command description. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $description = 'Command 迁移商户余额数据到lanzu_user_balance表'; |
||||
|
|
||||
|
/** |
||||
|
* Create a new command instance. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
parent::__construct(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Execute the console command. |
||||
|
* |
||||
|
* @return int |
||||
|
*/ |
||||
|
public function handle() |
||||
|
{ |
||||
|
$oldOrderTableName = 'ims_cjdc_order'; |
||||
|
$oldWithdrawalTableName = 'ims_cjdc_withdrawal'; |
||||
|
|
||||
|
$oldAccountTableName = 'ims_cjdc_store_account'; |
||||
|
|
||||
|
$newTableName = 'lanzu_user_balance'; |
||||
|
|
||||
|
// 判断表是否存在
|
||||
|
if(!Schema::hasTable($oldAccountTableName)){ |
||||
|
var_dump('旧表不存在'); |
||||
|
return 0; |
||||
|
} |
||||
|
if(!Schema::hasTable($newTableName)){ |
||||
|
var_dump('新表不存在'); |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
$oldData = DB::table($oldAccountTableName)->orderBy('id','asc')->get(); |
||||
|
$bar = $this->output->createProgressBar(count($oldData)); |
||||
|
$bar->start(); |
||||
|
$startTime = time(); |
||||
|
$error = []; |
||||
|
$newData = []; |
||||
|
foreach ($oldData as $key => $value){ |
||||
|
$storeId = $value->store_id; |
||||
|
|
||||
|
|
||||
|
|
||||
|
$bar->advance(); |
||||
|
} |
||||
|
|
||||
|
DB::table($newTableName)->insert($newData); |
||||
|
|
||||
|
$bar->finish(); |
||||
|
var_dump([time()-$startTime]); |
||||
|
var_dump($error); |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue