Browse Source

迁移流水和商户余额

master
liangyuyan 5 years ago
parent
commit
09e2310676
  1. 39
      app/Console/Commands/MigrateStoreAccount.php
  2. 80
      app/Console/Commands/MigrateStoreBalance.php

39
app/Console/Commands/MigrateStoreAccount.php

@ -77,11 +77,14 @@ class MigrateStoreAccount extends Command
foreach ($oldData as $key => $value){ foreach ($oldData as $key => $value){
$storeId = $value->store_id; $storeId = $value->store_id;
$userId = $value->user_id; $userId = $value->user_id;
if(empty($userId)){
$error[] = ['id'=>$userId];
if(empty($userId) || empty($storeId)){
$error[] = ['user_id'=>$userId,'store_id'=>$storeId];
break; break;
} }
$userType = 0;
$moneyType = 0;
$sourceId = $value->order_id;
$sourceType = 0;
// 判断是否存在 总账 // 判断是否存在 总账
$exist = DB::table($newTableName) $exist = DB::table($newTableName)
->where('user_id',$userId) ->where('user_id',$userId)
@ -90,24 +93,25 @@ class MigrateStoreAccount extends Command
->where('source_type',0) ->where('source_type',0)
->where('money_type') ->where('money_type')
->exists(); ->exists();
$desc = '';
$comment = '';
if(!$exist){ if(!$exist){
$newData =[ $newData =[
'id'=>$userId,
'nick_name'=>$value->name,
'user_id'=>$userId,
'user_type'=>$userType,
'avatar'=>$value->img,
'openid'=>$value->openid,
'money'=>$value->money,
'money_type'=>$moneyType,
'total_score'=>$value->total_score,
'wallet'=>$value->wallet,
'source_id'=>$sourceId,
'source_type'=>$sourceType,
'real_name'=>$value->user_name,
'tel'=>$value->user_tel,
'unionid'=>$value->unionid,
'desc'=>$desc,
'comment'=>$comment,
'status'=>1,
'created_at' => strtotime($value->join_time),
'updated_at' => $value->updated_at,
'created_at' => time(),
'updated_at' => time(),
]; ];
$res = DB::table($newTableName)->insert($newData); $res = DB::table($newTableName)->insert($newData);
@ -154,4 +158,9 @@ class MigrateStoreAccount extends Command
var_dump($error); var_dump($error);
return 0; return 0;
} }
public function getMoneyType($type,$note)
{
}
} }

80
app/Console/Commands/MigrateStoreBalance.php

@ -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;
}
}
Loading…
Cancel
Save