Browse Source

Merge branch 'phoenix' into develop

master
liangyuyan 5 years ago
parent
commit
a95c98e8b8
  1. 16
      app/Console/Commands/SetStoreBalance.php
  2. 67
      app/Console/Commands/SetUserBalanceType.php

16
app/Console/Commands/SetStoreBalance.php

@ -40,8 +40,11 @@ class SetStoreBalance extends Command
*/ */
public function handle() 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 = $this->output->createProgressBar(count($oldData));
$bar->start(); $bar->start();
@ -49,7 +52,7 @@ class SetStoreBalance extends Command
$newData = []; $newData = [];
foreach ($oldData as $key => $value){ foreach ($oldData as $key => $value){
// 查询店铺是否存在balance // 查询店铺是否存在balance
$exist = DB::table('lanzu_user_balance')
$exist = DB::table($newTableName)
->where('source_id',$value->id) ->where('source_id',$value->id)
->where('user_type',5) ->where('user_type',5)
->first(); ->first();
@ -71,14 +74,15 @@ class SetStoreBalance extends Command
$bar->advance(); $bar->advance();
} }
// 添加到新表 // 添加到新表
$res = DB::table('lanzu_user_balance')->insert($newData);
$res = DB::table($newTableName)->insert($newData);
$bar->finish(); $bar->finish();
var_dump(' end_time: '.date('H:i:s',time()));
var_dump('new_total: '.count($newData)); var_dump('new_total: '.count($newData));
var_dump('exist: '.count($data)); var_dump('exist: '.count($data));
var_dump($data);
var_dump('res: '.$res); var_dump('res: '.$res);
// var_dump($data);
return 0; return 0;
} }
} }

67
app/Console/Commands/SetUserBalanceType.php

@ -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;
}
}
Loading…
Cancel
Save