2 changed files with 77 additions and 6 deletions
@ -0,0 +1,67 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Console\Commands; |
||||
|
|
||||
|
use Illuminate\Console\Command; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class SetUserBalanceType extends Command |
||||
|
{ |
||||
|
/** |
||||
|
* The name and signature of the console command. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $signature = 'migrateData:setUserBalanceType'; |
||||
|
|
||||
|
/** |
||||
|
* The console command description. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $description = 'Command 清洗用户余额表type字段值,type为3洗为4'; |
||||
|
|
||||
|
/** |
||||
|
* Create a new command instance. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
parent::__construct(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Execute the console command. |
||||
|
* @return int |
||||
|
*/ |
||||
|
public function handle() |
||||
|
{ |
||||
|
$oldData = DB::table('lanzu_user_balance')->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; |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue