3 changed files with 86 additions and 2 deletions
-
2app/Admin/Controllers/v3/CategoryController.php
-
2app/Console/Commands/SetGoodsMarketId.php
-
84app/Console/Commands/SetStoreBalance.php
@ -0,0 +1,84 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use App\Models\v3\Store as StoreModel; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class SetStoreBalance extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'migrateData:setStoreBalance'; |
|||
|
|||
/** |
|||
* The console command description. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $description = 'Command 在user_balance表添加商户钱包'; |
|||
|
|||
/** |
|||
* Create a new command instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
/** |
|||
* 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; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue