From b47ab918d627674034fd4cdb5bbac5f67fe13fbf Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 16 Sep 2020 15:59:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BD=99=E9=A2=9D=E8=A1=A8--?= =?UTF-8?q?=E6=B8=85=E6=B4=97=E6=95=B0=E6=8D=AE=20=EF=BC=8Cuser=5Ftype=20?= =?UTF-8?q?=E4=B8=BA3=E7=9A=84=E6=B4=97=E4=B8=BA4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/SetStoreBalance.php | 16 +++-- app/Console/Commands/SetUserBalanceType.php | 67 +++++++++++++++++++++ 2 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 app/Console/Commands/SetUserBalanceType.php 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; + } +}