链街Dcat后台
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.
 
 
 
 

157 lines
4.5 KiB

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class MigrateStoreAccount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrateData:storeAccount';
/**
* 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_store_account';
$newTableName = 'lanzu_financial_record';
// 判断表是否存在
if(!Schema::hasTable($oldTableName)){
var_dump('旧表不存在');
return 0;
}
if(!Schema::hasTable($newTableName)){
var_dump('新表不存在');
return 0;
}
$desc='用户店铺首单奖励';
$comment='用户当面付商户奖励';
$desc='新用户下单奖励';
$comment='用户当面付商户奖励';
$desc = '线上外卖订单收入';
$comment = '用户订单完成';
$desc = '线下当面付订单收入';
$comment = '用户订单完成';
$desc = '线上订单退款';
$comment = '线上订单退款到微信';
$desc = '商户提现';
$comment = '商户提现打款';
$oldData = DB::table($oldTableName)->orderBy('id','asc')->get();
$bar = $this->output->createProgressBar(count($oldData));
$bar->start();
$startTime = time();
$error = [];
foreach ($oldData as $key => $value){
$storeId = $value->store_id;
$userId = $value->user_id;
if(empty($userId)){
$error[] = ['id'=>$userId];
break;
}
// 判断是否存在 总账
$exist = DB::table($newTableName)
->where('user_id',$userId)
->where('user_type',5)
->where('source_id',$value->order_id)
->where('source_type',0)
->where('money_type')
->exists();
if(!$exist){
$newData =[
'id'=>$userId,
'nick_name'=>$value->name,
'avatar'=>$value->img,
'openid'=>$value->openid,
'total_score'=>$value->total_score,
'wallet'=>$value->wallet,
'real_name'=>$value->user_name,
'tel'=>$value->user_tel,
'unionid'=>$value->unionid,
'created_at' => strtotime($value->join_time),
'updated_at' => $value->updated_at,
];
$res = DB::table($newTableName)->insert($newData);
if(!$res){
$error[] = ['id'=>$userId];
break;
}
}
// 判断是否存在 详细账
$mod = bcmod((string)$userId, '5', 0);
$newSubTableName = $newTableName.'_'.$mod;
$existSub = DB::table($newSubTableName)->where('id',$userId)->exists();
if(!$existSub){
$newData =[
'id'=>$userId,
'nick_name'=>$value->name,
'avatar'=>$value->img,
'openid'=>$value->openid,
'total_score'=>$value->total_score,
'wallet'=>$value->wallet,
'real_name'=>$value->user_name,
'tel'=>$value->user_tel,
'unionid'=>$value->unionid,
'created_at' => strtotime($value->join_time),
'updated_at' => $value->updated_at,
];
$res = DB::table($newSubTableName)->insert($newData);
if(!$res){
$error[] = ['id'=>$userId];
break;
}
}
$bar->advance();
}
$bar->finish();
var_dump([time()-$startTime]);
var_dump($error);
return 0;
}
}