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.
89 lines
2.2 KiB
89 lines
2.2 KiB
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Models\v3\Store as StoreModel;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class SetStoreBalance extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'migrateData:setStoreBalance';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Command 在user_balance表添加商户钱包';
|
|
|
|
/**
|
|
* 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';
|
|
$newTableName = 'lanzu_user_balance';
|
|
|
|
$oldData = DB::table($oldTableName)->get();
|
|
|
|
$bar = $this->output->createProgressBar(count($oldData));
|
|
$bar->start();
|
|
|
|
$data = [];
|
|
$newData = [];
|
|
foreach ($oldData as $key => $value){
|
|
// 查询店铺是否存在balance
|
|
$exist = DB::table($newTableName)
|
|
->where('source_id',$value->user_id)
|
|
->where('user_type',5)
|
|
->first();
|
|
|
|
if(empty($exist)){
|
|
$newData[] = [
|
|
'source_id' => $value->user_id,
|
|
'user_type' => 5,
|
|
'balance' => 0,
|
|
'created_at' => time(),
|
|
'updated_at' => time()
|
|
];
|
|
}else{
|
|
$data[] = [
|
|
'store_id' => $value->id,
|
|
'user_id' => $value->user_id,
|
|
'balance_id' => $exist->id
|
|
];
|
|
}
|
|
$bar->advance();
|
|
}
|
|
// 添加到新表
|
|
$res = DB::table($newTableName)->insert($newData);
|
|
|
|
$bar->finish();
|
|
|
|
var_dump('new_total: '.count($newData));
|
|
var_dump('exist: '.count($data));
|
|
var_dump($data);
|
|
var_dump('res: '.$res);
|
|
|
|
return 0;
|
|
}
|
|
}
|