diff --git a/app/Console/Commands/SetGoodsMarketId.php b/app/Console/Commands/SetGoodsMarketId.php index 1bf52c4..7fd4f21 100644 --- a/app/Console/Commands/SetGoodsMarketId.php +++ b/app/Console/Commands/SetGoodsMarketId.php @@ -15,7 +15,7 @@ class SetGoodsMarketId extends Command * * @var string */ - protected $signature = 'command:SetGoodsMarketId'; + protected $signature = 'migrateData:SetGoodsMarketId'; /** * The console command description. diff --git a/app/Console/Commands/SetStoreBalance.php b/app/Console/Commands/SetStoreBalance.php index 2440b45..c61a322 100644 --- a/app/Console/Commands/SetStoreBalance.php +++ b/app/Console/Commands/SetStoreBalance.php @@ -3,6 +3,8 @@ namespace App\Console\Commands; use Illuminate\Console\Command; +use App\Models\v3\Store as StoreModel; +use Illuminate\Support\Facades\DB; class SetStoreBalance extends Command { @@ -11,14 +13,14 @@ class SetStoreBalance extends Command * * @var string */ - protected $signature = 'command:name'; + protected $signature = 'migrateData:setStoreBalance'; /** * The console command description. * * @var string */ - protected $description = 'Command description'; + protected $description = 'Command 在user_balance表添加商户钱包'; /** * Create a new command instance. @@ -32,11 +34,51 @@ class SetStoreBalance extends Command /** * Execute the console command. - * + * 添加商户钱包 + * 先判断是否存在,不存在则添加一条店铺的钱包记录 * @return int */ public function handle() { + $oldData = DB::table('ims_cjdc_store')->get(); + var_dump('start_time:'.date('H:i:s',time())); + $bar = $this->output->createProgressBar(count($oldData)); + $bar->start(); + + $data = []; + $newData = []; + foreach ($oldData as $key => $value){ + // 查询店铺是否存在balance + $exist = DB::table('lanzu_user_balance') + ->where('source_id',$value->id) + ->where('user_type',5) + ->first(); + + if(empty($exist)){ + $newData[] = [ + 'source_id' => $value->id, + 'user_type' => 5, + 'balance' => 0, + 'created_at' => time(), + 'updated_at' => time() + ]; + }else{ + $data[] = [ + 'store_id' => $value->id, + 'balance_id' => $exist->id + ]; + } + $bar->advance(); + } + // 添加到新表 + $res = DB::table('lanzu_user_balance')->insert($newData); + + $bar->finish(); + var_dump(' end_time: '.date('H:i:s',time())); + var_dump('new_total: '.count($newData)); + var_dump('exist: '.count($data)); + var_dump('res: '.$res); + // var_dump($data); return 0; } }