修改:订单核销后 瓶装酒额度、菜卡额度、封坛酒额度解冻合并一起处理,不在单独处理。并且增加惠民积分解冻
This commit is contained in:
parent
c5bebddb99
commit
4c7d02f4b3
|
|
@ -22,13 +22,14 @@ class OrderVerifyEvent{
|
||||||
// Log::info('订单核销 - 额度相关处理 - 开始: '.var_export(['order_id' => $order->order_id,'uid' => $order->uid],1));
|
// Log::info('订单核销 - 额度相关处理 - 开始: '.var_export(['order_id' => $order->order_id,'uid' => $order->uid],1));
|
||||||
// 判断:如果存在上级id 则使用上级id
|
// 判断:如果存在上级id 则使用上级id
|
||||||
$orderId = $order->main_id > 0 ? $order->main_id : $order->order_id;
|
$orderId = $order->main_id > 0 ? $order->main_id : $order->order_id;
|
||||||
|
|
||||||
// 酒水卡额度解冻
|
// 酒水卡额度解冻
|
||||||
$this->wineCard($orderId, $order);
|
$this->exchangeQuotaThawing($orderId, $order, 1);
|
||||||
// 菜卡额度解冻
|
// 菜卡额度解冻
|
||||||
$this->dish($orderId, $order);
|
$this->exchangeQuotaThawing($orderId, $order, 2);
|
||||||
// 封坛酒额度解冻
|
// 封坛酒额度解冻
|
||||||
$this->windQuota($orderId, $order);
|
$this->exchangeQuotaThawing($orderId, $order, 3);
|
||||||
|
// 惠民积分解冻
|
||||||
|
$this->exchangeQuotaThawing($orderId, $order, 5);
|
||||||
// 商户佣金结算
|
// 商户佣金结算
|
||||||
$this->merMoneyHandle($orderId);
|
$this->merMoneyHandle($orderId);
|
||||||
|
|
||||||
|
|
@ -41,28 +42,34 @@ class OrderVerifyEvent{
|
||||||
* @param $orderId
|
* @param $orderId
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getRate($orderId){
|
private function getRate($orderId){
|
||||||
return (float)app()->make(StoreOrderRepository::class)
|
return (float)app()->make(StoreOrderRepository::class)
|
||||||
->getSearch([])
|
->getSearch([])
|
||||||
->where(function($query) use ($orderId){
|
->where(function($query) use ($orderId){
|
||||||
$query->where('order_id',$orderId)->whereOr('main_id',$orderId);
|
$query->where('order_id',$orderId)->whereOr('main_id',$orderId);
|
||||||
})->sum('total_num');
|
})->sum('total_num');
|
||||||
}
|
}
|
||||||
// 酒水卡额度解冻
|
// 相关额度和积分解冻 额度类型:1=酒卡额度(瓶装酒),2=菜卡额度,3=封坛酒额度,4=加油卡额度,5=惠民积分
|
||||||
public function wineCard($orderId, $order){
|
private function exchangeQuotaThawing($orderId, $order, $quotaType){
|
||||||
try{
|
try{
|
||||||
# 获取变更记录 条件:order_id=当前订单id、变更类型=增加
|
// 获取本订单总获得
|
||||||
$sum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel([
|
$giveWhere = [
|
||||||
'order_id' => $orderId,
|
'order_id' => $order->order_id,
|
||||||
'change_type' => 1,
|
'change_type' => 1,
|
||||||
'source' => 0,// 仅查询购买赠送 进行解冻
|
'source' => 0,// 仅查询购买赠送 进行解冻
|
||||||
])->sum('change_quantity');
|
'quota_type' => $quotaType,
|
||||||
$refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class)
|
];
|
||||||
->searchModel([
|
if($quotaType == 5) $giveWhere['mer_id'] = $order->mer_id;
|
||||||
|
$sum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel($giveWhere)->sum('change_quantity');
|
||||||
|
// 获取本订单退款的数量
|
||||||
|
$refundWhere = [
|
||||||
'order_id' => $orderId,
|
'order_id' => $orderId,
|
||||||
'change_type' => 0,
|
'change_type' => 0,
|
||||||
'source' => 1,// 仅查询订单退款 减少内容
|
'source' => 1,// 仅查询订单退款 减少内容
|
||||||
])->sum('change_quantity');
|
'quota_type' => $quotaType,
|
||||||
|
];
|
||||||
|
if($quotaType == 5) $refundWhere['mer_id'] = $order->mer_id;
|
||||||
|
$refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel($refundWhere)->sum('change_quantity');
|
||||||
// 剩余数量 解冻
|
// 剩余数量 解冻
|
||||||
$surplusQuota = (float)sprintf("%.2f",$sum - $refundSum);
|
$surplusQuota = (float)sprintf("%.2f",$sum - $refundSum);
|
||||||
if($surplusQuota > 0){
|
if($surplusQuota > 0){
|
||||||
|
|
@ -72,86 +79,24 @@ class OrderVerifyEvent{
|
||||||
$rate = (float)sprintf("%.2f",$currentTotalNum / $totalNum * 100);
|
$rate = (float)sprintf("%.2f",$currentTotalNum / $totalNum * 100);
|
||||||
$surplusQuota = (float)sprintf("%.2f",$surplusQuota * $rate / 100);
|
$surplusQuota = (float)sprintf("%.2f",$surplusQuota * $rate / 100);
|
||||||
// 解冻操作
|
// 解冻操作
|
||||||
$hold = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$order->uid])->findOrEmpty();
|
$freezeWhere = [
|
||||||
|
'uid'=>$order->uid,
|
||||||
|
'quota_type'=>$quotaType
|
||||||
|
];
|
||||||
|
if($quotaType == 5) $freezeWhere['mer_id'] = $order->mer_id;
|
||||||
|
$hold = app()->make(ExchangeQuotaRepository::class)->searchModel($freezeWhere)->findOrEmpty();
|
||||||
$freezeQuota = sprintf("%.2f",$hold->freeze_quota - $surplusQuota);
|
$freezeQuota = sprintf("%.2f",$hold->freeze_quota - $surplusQuota);
|
||||||
$hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota;
|
$hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota;
|
||||||
$hold->save();
|
$hold->save();
|
||||||
}
|
}
|
||||||
}catch(\Exception $e){
|
}catch(\Exception $e){
|
||||||
Log::info('订单核销 - 酒卡额度相关处理 - 错误: '.$e->getMessage());
|
Log::info('订单核销 - 相关额度和积分解冻 - 错误: '.var_export([
|
||||||
}
|
'msg' => $e->getMessage(),
|
||||||
}
|
'quota_type' => $quotaType,
|
||||||
// 菜卡额度解冻
|
|
||||||
public function dish($orderId, $order){
|
|
||||||
try{
|
|
||||||
# 获取变更记录 条件:order_id=当前订单id、变更类型=增加
|
|
||||||
$sum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel([
|
|
||||||
'order_id' => $orderId,
|
'order_id' => $orderId,
|
||||||
'change_type' => 1,
|
],1));
|
||||||
'source' => 0,// 仅查询购买赠送 进行解冻
|
|
||||||
'quota_type' => 2,
|
|
||||||
])->sum('change_quantity');
|
|
||||||
$refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class)
|
|
||||||
->searchModel([
|
|
||||||
'order_id' => $orderId,
|
|
||||||
'change_type' => 0,
|
|
||||||
'source' => 1,// 仅查询订单退款 减少内容
|
|
||||||
'quota_type' => 2,
|
|
||||||
])->sum('change_quantity');
|
|
||||||
// 剩余数量 解冻
|
|
||||||
$surplusQuota = (float)sprintf("%.2f",$sum - $refundSum);
|
|
||||||
if($surplusQuota > 0){
|
|
||||||
// 核销订单 会进行拆分操作 需要获取当前订单占总订单数量的比例
|
|
||||||
$totalNum = (float)$this->getRate($orderId);
|
|
||||||
$currentTotalNum = (float)$order->total_num;
|
|
||||||
$rate = (float)sprintf("%.2f",$currentTotalNum / $totalNum * 100);
|
|
||||||
$surplusQuota = (float)sprintf("%.2f",$surplusQuota * $rate / 100);
|
|
||||||
// 解冻操作
|
|
||||||
$hold = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$order->uid,'quota_type'=>2])->findOrEmpty();
|
|
||||||
$freezeQuota = sprintf("%.2f",$hold->freeze_quota - $surplusQuota);
|
|
||||||
$hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota;
|
|
||||||
$hold->save();
|
|
||||||
}
|
|
||||||
}catch(\Exception $e){
|
|
||||||
Log::info('订单核销 - 菜卡额度相关处理 - 错误: '.$e->getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 封坛酒额度解冻
|
|
||||||
public function windQuota($orderId, $order){
|
|
||||||
try{
|
|
||||||
# 获取变更记录 条件:order_id=当前订单id、变更类型=增加
|
|
||||||
$sum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel([
|
|
||||||
'order_id' => $orderId,
|
|
||||||
'change_type' => 1,
|
|
||||||
'source' => 0,// 仅查询购买赠送 进行解冻
|
|
||||||
'quota_type' => 3,
|
|
||||||
])->sum('change_quantity');
|
|
||||||
$refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class)
|
|
||||||
->searchModel([
|
|
||||||
'order_id' => $orderId,
|
|
||||||
'change_type' => 0,
|
|
||||||
'source' => 1,// 仅查询订单退款 减少内容
|
|
||||||
'quota_type' => 3,
|
|
||||||
])->sum('change_quantity');
|
|
||||||
// 剩余数量 解冻
|
|
||||||
$surplusQuota = (float)sprintf("%.2f",$sum - $refundSum);
|
|
||||||
if($surplusQuota > 0){
|
|
||||||
// 核销订单 会进行拆分操作 需要获取当前订单占总订单数量的比例
|
|
||||||
$totalNum = (float)$this->getRate($orderId);
|
|
||||||
$currentTotalNum = (float)$order->total_num;
|
|
||||||
$rate = (float)sprintf("%.2f",$currentTotalNum / $totalNum * 100);
|
|
||||||
$surplusQuota = (float)sprintf("%.2f",$surplusQuota * $rate / 100);
|
|
||||||
// 解冻操作
|
|
||||||
$hold = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$order->uid,'quota_type'=>3])->findOrEmpty();
|
|
||||||
$freezeQuota = sprintf("%.2f",$hold->freeze_quota - $surplusQuota);
|
|
||||||
$hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota;
|
|
||||||
$hold->save();
|
|
||||||
}
|
|
||||||
}catch(\Exception $e){
|
|
||||||
Log::info('订单核销 - 菜卡额度相关处理 - 错误: '.$e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 商户佣金结算
|
// 商户佣金结算
|
||||||
private function merMoneyHandle($order_id){
|
private function merMoneyHandle($order_id){
|
||||||
$list = FinancialRecord::getDB()
|
$list = FinancialRecord::getDB()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue