diff --git a/app/Console/Commands/SetStoreBalance.php b/app/Console/Commands/SetStoreBalance.php index c61a322..3902d76 100644 --- a/app/Console/Commands/SetStoreBalance.php +++ b/app/Console/Commands/SetStoreBalance.php @@ -40,8 +40,11 @@ class SetStoreBalance extends Command */ public function handle() { - $oldData = DB::table('ims_cjdc_store')->get(); - var_dump('start_time:'.date('H:i:s',time())); + $oldTableName = 'ims_cjdc_store'; + $newTableName = 'lanzu_user_balance'; + + $oldData = DB::table($oldTableName)->get(); + $bar = $this->output->createProgressBar(count($oldData)); $bar->start(); @@ -49,7 +52,7 @@ class SetStoreBalance extends Command $newData = []; foreach ($oldData as $key => $value){ // 查询店铺是否存在balance - $exist = DB::table('lanzu_user_balance') + $exist = DB::table($newTableName) ->where('source_id',$value->id) ->where('user_type',5) ->first(); @@ -71,14 +74,15 @@ class SetStoreBalance extends Command $bar->advance(); } // 添加到新表 - $res = DB::table('lanzu_user_balance')->insert($newData); + $res = DB::table($newTableName)->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($data); var_dump('res: '.$res); - // var_dump($data); + return 0; } } diff --git a/app/Console/Commands/SetUserBalanceType.php b/app/Console/Commands/SetUserBalanceType.php new file mode 100644 index 0000000..0c13e32 --- /dev/null +++ b/app/Console/Commands/SetUserBalanceType.php @@ -0,0 +1,67 @@ +get(); + + $bar = $this->output->createProgressBar(count($oldData)); + $bar->start(); + + $total = 0; + $newData = []; + foreach ($oldData as $key => $value){ + + if($value->user_type == 3){ + $newData = [ + 'user_type' => 4, + 'updated_at' => time() + ]; + if(DB::table('lanzu_user_balance')->where('id',$value->id)->update($newData)){ + $total++; + } + } + $bar->advance(); + } + + $bar->finish(); + + var_dump('total: '.$total); + + return 0; + } +}