Browse Source

线上店铺余额迁移功能完成

master
liangyuyan 5 years ago
parent
commit
6e6b11c083
  1. 88
      app/Console/Commands/MigrateStoreBalance.php
  2. 10
      app/Console/Commands/SetStoreUsers.php

88
app/Console/Commands/MigrateStoreBalance.php

@ -39,10 +39,6 @@ class MigrateStoreBalance extends Command
*/
public function handle()
{
$oldStoreTableName = 'ims_cjdc_store';
$oldOrderTableName = 'ims_cjdc_order';
$oldWithdrawalTableName = 'ims_cjdc_withdrawal';
$oldAccountTableName = 'ims_cjdc_store_account';
$newBalanceTableName = 'lanzu_user_balance';
@ -58,14 +54,14 @@ class MigrateStoreBalance extends Command
}
// 流水算法
// $newData = $this->countStore($oldAccountTableName);
$newData = $this->countStore($oldAccountTableName);
// 订单算法
$newData = $this->countOrder($oldStoreTableName,$oldOrderTableName,$oldWithdrawalTableName);
// $newData = $this->countOrder();
var_dump($newData);
// var_dump(number_format($newData[12],2));
// var_dump($newData);
// var_dump(count($newData));
// return 0;
return 0;
$bar = $this->output->createProgressBar(count($newData));
$bar->start();
$startTime = time();
@ -75,11 +71,12 @@ return 0;
$exist = DB::table($newBalanceTableName)->where('source_id',$store_id)->where('user_type',5)->exists();
if($exist){
$saveData = [
'balance' => number_format($money,2),
'balance' => number_format($money,2,'.',''),
'updated_at' => time()
];
return 0;
$res = DB::table($newBalanceTableName)->update($saveData);
// var_dump($saveData);
// return 0;
$res = DB::table($newBalanceTableName)->where('source_id',$store_id)->where('user_type',5)->update($saveData);
if(!$res){
$error[] = ['store_id'=>$store_id,'money'=>$money];
}
@ -87,10 +84,11 @@ return 0;
$saveData = [
'source_id' => $store_id,
'user_type' => 5,
'balance' => number_format($money),
'balance' => number_format($money,2,'.',''),
'updated_at' => time()
];
return 0;
// var_dump($saveData);
// return 0;
$res = DB::table($newBalanceTableName)->insert($saveData);
if(!$res){
$error[] = ['store_id'=>$store_id,'money'=>$money];
@ -130,30 +128,34 @@ return 0;
/**
* 根据订单进行计算
*/
public function countOrder( $oldStoreTableName, $oldOrderTableName, $oldWithdrawalTableName)
public function countOrder()
{
$oldStoreTableName = 'ims_cjdc_store';
$oldStoreSetTableName = 'ims_cjdc_storeset';
$oldStoreTypeTableName = 'ims_cjdc_storetype';
$oldOrderTableName = 'ims_cjdc_order';
$oldWithdrawalTableName = 'ims_cjdc_withdrawal';
$newData = [];
// 查询所有店铺
$stores = DB::table($oldStoreTableName)->select('id','md_type','award_money')->get();
$stores = DB::table($oldStoreTableName)->select('id','md_type','ps_poundage','award_money')->get();
//店铺设置
$storeSets = DB::table('ims_cjdc_storeset')->get()->toArray();
$storeSets = DB::table($oldStoreSetTableName)->select('id','store_id','is_poundage','poundage','dn_poundage','dm_poundage','yd_poundage')->get()->toArray();
$storeSetArr = array_column($storeSets,null,'store_id');
// 所有商家分类
$storeTypes = DB::table('ims_cjdc_storetype')->get()->toArray();
$storeTypes = DB::table($oldStoreTypeTableName)->get()->toArray();
$storeTypeArr = array_column($storeTypes,null,'id');
return $storeTypeArr;
foreach($stores as $key => $value){
$storeId = $value->id;
// 获取商家手续费 % 如果商家设置有自己的手续费则用商家的
if($storeSets[$storeId]['is_poundage'] == 1){
if(isset($storeSetArr[$storeId]) && $storeSetArr[$storeId]->is_poundage == 1){
$poundage = $storeSetArr[$storeId];
}else{
$poundage = $storeTypeArr[$storeId];
$poundage = $storeTypeArr[$value->md_type];
}
// 商家订单金额
@ -162,60 +164,66 @@ return 0;
// state '1.待付款2.待结单3.等待送达4.完成5.已评价6.取消7.拒绝8.退款中9.已退款10.退款拒绝',
// 外卖
$wmOrder = DB::table('ims_cjdc_order')
$wmOrder = DB::table($oldOrderTableName)
->select(DB::raw('sum(money) as total_money'),DB::raw('sum(ps_money) as ps_money'),DB::raw('sum(yhq_money2) as hb_money'))
->where('store_id',$storeId)
->where('type',1)
->whereIn('state',[4,5,10])
->whereIn('pay_type',[1,2])
->get();
->first();
// 店内
$dnOrder = DB::table('ims_cjdc_order')
$dnOrder = DB::table($oldOrderTableName)
->select(DB::raw('sum(money) as total_money'),DB::raw('sum(yhq_money2) as hb_money'))
->where('store_id',$storeId)
->where('type',2)
->where('dn_state',2)
->whereIn('pay_type',[1,2])
->get();
->first();
// 当面
$dmOrder = DB::table('ims_cjdc_order')
$dmOrder = DB::table($oldOrderTableName)
->select(DB::raw('sum(money) as total_money'))
->where('store_id',$storeId)
->where('type',4)
->where('dm_state',2)
->whereIn('pay_type',[1,2])
->get();
->first();
// 预约
$yyOrder = DB::table('ims_cjdc_order')
$yyOrder = DB::table($oldOrderTableName)
->select(DB::raw('sum(money) as total_money'))
->where('store_id',$storeId)
->where('type',3)
->where('yy_state',3)
->whereIn('pay_type',[1,2])
->get();
->first();
// 提现
$txTotal = DB::table('ims_cjdc_withdrawal')
$txTotal = DB::table($oldWithdrawalTableName)
->select(DB::raw('sum(tx_cost) as total'))
->where('store_id',$storeId)
->whereIn('state',[1,2])
->get();
->first();
// 商家奖励
$awardTotal = empty($value->award_money) ? 0 : $value->award_money;
// 计算 金额 = 奖励 + 订单() - 手续费 - 提现
// 商户配送手续费
$psMoney = number_format(floatval($wmOrder->ps_money)*floatval($value->ps_poundage)/100,2,'.','');
// 不计算拼团和抢购的订单,目前没有这样的订单,在另外的订单表
// 计算 金额 = 奖励 + 订单(外卖+店内+当面+预约) - 手续费 - 提现 - 配送费
$balance = $awardTotal
+ ($wmOrder->total_money + $wmOrder->hb_money + $dnOrder->total_money + $dnOrder->hb_money + $dmOrder->total_money + $yyOrder->total_money )
- ((
($wmOrder->total_money + $wmOrder->ps_money + $wmOrder->hb_money) * $poundage->poundage
+ ($dnOrder->total_money + $dnOrder->hb_money ) * $poundage->dn_poundage
+ $dmOrder->total_money * $poundage->dm_poundage
+ $yyOrder->total_money * $poundage->yd_poundage
($wmOrder->total_money + $wmOrder->ps_money + $wmOrder->hb_money) * floatval($poundage->poundage)
+ ($dnOrder->total_money + $dnOrder->hb_money ) * floatval($poundage->dn_poundage)
+ $dmOrder->total_money * floatval($poundage->dm_poundage)
+ $yyOrder->total_money * floatval($poundage->yd_poundage)
)/100)
- ($txTotal->total)
;
- $txTotal->total
- $psMoney;
$newData[$storeId] = number_format($balance,2);
$newData[$storeId] = $balance;
}
return $newData;

10
app/Console/Commands/SetStoreUsers.php

@ -42,11 +42,11 @@ class SetStoreUsers extends Command
public function handle()
{
// 如果表不存在则创建
if(!Schema::hasTable('lanzu_store_users')){
Schema::create('lanzu_store_users',function (Blueprint $table){
$table->id();
});
}
// if(!Schema::hasTable('lanzu_store_users')){
// Schema::create('lanzu_store_users',function (Blueprint $table){
// $table->id();
// });
// }
$account = DB::table('ims_cjdc_account')->get();
$bar = $this->output->createProgressBar(count($account));
$bar->start();

Loading…
Cancel
Save