From 4c7d02f4b39570968a1f9fdc4c1fd3aeda64fa32 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Mon, 1 Jul 2024 16:23:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=A0=B8=E9=94=80=E5=90=8E=20=E7=93=B6=E8=A3=85=E9=85=92?= =?UTF-8?q?=E9=A2=9D=E5=BA=A6=E3=80=81=E8=8F=9C=E5=8D=A1=E9=A2=9D=E5=BA=A6?= =?UTF-8?q?=E3=80=81=E5=B0=81=E5=9D=9B=E9=85=92=E9=A2=9D=E5=BA=A6=E8=A7=A3?= =?UTF-8?q?=E5=86=BB=E5=90=88=E5=B9=B6=E4=B8=80=E8=B5=B7=E5=A4=84=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E5=9C=A8=E5=8D=95=E7=8B=AC=E5=A4=84=E7=90=86?= =?UTF-8?q?=E3=80=82=E5=B9=B6=E4=B8=94=E5=A2=9E=E5=8A=A0=E6=83=A0=E6=B0=91?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E8=A7=A3=E5=86=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exchangeQuota/OrderVerifyEvent.php | 125 +++++------------- 1 file changed, 35 insertions(+), 90 deletions(-) diff --git a/app/listener/exchangeQuota/OrderVerifyEvent.php b/app/listener/exchangeQuota/OrderVerifyEvent.php index 6ab156a..685deaa 100644 --- a/app/listener/exchangeQuota/OrderVerifyEvent.php +++ b/app/listener/exchangeQuota/OrderVerifyEvent.php @@ -22,13 +22,14 @@ class OrderVerifyEvent{ // Log::info('订单核销 - 额度相关处理 - 开始: '.var_export(['order_id' => $order->order_id,'uid' => $order->uid],1)); // 判断:如果存在上级id 则使用上级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); @@ -41,28 +42,34 @@ class OrderVerifyEvent{ * @param $orderId * @return mixed */ - public function getRate($orderId){ + private function getRate($orderId){ return (float)app()->make(StoreOrderRepository::class) ->getSearch([]) ->where(function($query) use ($orderId){ $query->where('order_id',$orderId)->whereOr('main_id',$orderId); })->sum('total_num'); } - // 酒水卡额度解冻 - public function wineCard($orderId, $order){ + // 相关额度和积分解冻 额度类型:1=酒卡额度(瓶装酒),2=菜卡额度,3=封坛酒额度,4=加油卡额度,5=惠民积分 + private function exchangeQuotaThawing($orderId, $order, $quotaType){ try{ - # 获取变更记录 条件:order_id=当前订单id、变更类型=增加 - $sum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel([ - 'order_id' => $orderId, + // 获取本订单总获得 + $giveWhere = [ + 'order_id' => $order->order_id, 'change_type' => 1, - 'source' => 0,// 仅查询购买赠送 进行解冻 - ])->sum('change_quantity'); - $refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class) - ->searchModel([ - 'order_id' => $orderId, - 'change_type' => 0, - 'source' => 1,// 仅查询订单退款 减少内容 - ])->sum('change_quantity'); + 'source' => 0,// 仅查询购买赠送 进行解冻 + 'quota_type' => $quotaType, + ]; + if($quotaType == 5) $giveWhere['mer_id'] = $order->mer_id; + $sum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel($giveWhere)->sum('change_quantity'); + // 获取本订单退款的数量 + $refundWhere = [ + 'order_id' => $orderId, + 'change_type' => 0, + 'source' => 1,// 仅查询订单退款 减少内容 + '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); if($surplusQuota > 0){ @@ -72,86 +79,24 @@ class OrderVerifyEvent{ $rate = (float)sprintf("%.2f",$currentTotalNum / $totalNum * 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); $hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota; $hold->save(); } }catch(\Exception $e){ - Log::info('订单核销 - 酒卡额度相关处理 - 错误: '.$e->getMessage()); - } - } - // 菜卡额度解冻 - public function dish($orderId, $order){ - try{ - # 获取变更记录 条件:order_id=当前订单id、变更类型=增加 - $sum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel([ - 'order_id' => $orderId, - 'change_type' => 1, - 'source' => 0,// 仅查询购买赠送 进行解冻 - 'quota_type' => 2, - ])->sum('change_quantity'); - $refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class) - ->searchModel([ + Log::info('订单核销 - 相关额度和积分解冻 - 错误: '.var_export([ + 'msg' => $e->getMessage(), + 'quota_type' => $quotaType, '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()); + ],1)); } } - // 封坛酒额度解冻 - 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){ $list = FinancialRecord::getDB()