diff --git a/app/common/dao/user/ExchangeQuotaDao.php b/app/common/dao/user/ExchangeQuotaDao.php index cd9da5c..d1de59b 100644 --- a/app/common/dao/user/ExchangeQuotaDao.php +++ b/app/common/dao/user/ExchangeQuotaDao.php @@ -32,6 +32,9 @@ class ExchangeQuotaDao extends BaseDao{ ->when(isset($params['uid']) && $params['uid'] !== '',function($query) use ($params){ $query->where('uid', (int)$params['uid']); }) + ->when(isset($params['mer_id']) && $params['mer_id'] !== '',function($query) use ($params){ + $query->where('mer_id', (int)$params['mer_id']); + }) ->with([ 'user' => function($query){ $query->field('uid,nickname,avatar')->bind(['nickname','avatar']); diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index a8749b3..8297083 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -3118,7 +3118,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ // 在线买单 - 订单、代理入驻 - 订单 public function onlinePayment($payType, $payInfo, $user, $activityType = 30){ - $payMoney = abs((float)$payInfo['money']); + $totalPrice = $payMoney = abs((float)$payInfo['money']); $merId = array_key_exists('mer_id',$payInfo) ? (int)$payInfo['mer_id'] : 0; $uid = $user->uid; // 判断:在线买单时 计算积分抵扣信息 @@ -3154,7 +3154,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ 'user_address' => $user->addres ?? '', 'cart_id' => '', 'total_num' => 1, - 'total_price' => $payMoney, + 'total_price' => $totalPrice, 'total_postage' => 0, 'pay_postage' => 0, 'svip_discount' => 0, @@ -3177,7 +3177,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ 'uid' => $uid, 'group_order_sn' => count($orderList) === 1 ? $orderList[0]['order_sn'] : ($this->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER).'0'), 'total_postage' => 0, - 'total_price' => $payMoney, + 'total_price' => $totalPrice, 'total_num' => 1, 'real_name' => $user->real_name ?? '', 'user_phone' => $user->phone ?? '', @@ -3228,7 +3228,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ } // 商品兑换 - 订单 public function exchangeGoods($payType, $payInfo, $user){ - $payMoney = abs((float)$payInfo['money']); + $totalPrice = $payMoney = abs((float)$payInfo['money']); $uid = $user->uid; // 是否自购 $isSelfBuy = $user->is_promoter && systemConfig('extension_self') ? 1 : 0; @@ -3258,7 +3258,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ 'user_address' => $user->addres ?? '', 'cart_id' => '', 'total_num' => 1, - 'total_price' => $payMoney, + 'total_price' => $totalPrice, 'total_postage' => 0, 'pay_postage' => 0, 'svip_discount' => 0, @@ -3281,7 +3281,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ 'uid' => $uid, 'group_order_sn' => count($orderList) === 1 ? $orderList[0]['order_sn'] : ($this->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER).'0'), 'total_postage' => 0, - 'total_price' => $payMoney, + 'total_price' => $totalPrice, 'total_num' => 1, 'real_name' => $user->real_name ?? '', 'user_phone' => $user->phone ?? '', diff --git a/app/common/repositories/user/ExchangeQuotaRepository.php b/app/common/repositories/user/ExchangeQuotaRepository.php index 8e0dc29..959a1d6 100644 --- a/app/common/repositories/user/ExchangeQuotaRepository.php +++ b/app/common/repositories/user/ExchangeQuotaRepository.php @@ -161,6 +161,30 @@ class ExchangeQuotaRepository extends BaseRepository{ return $info; } + /** + * Common: 获取持有额度信息 + * Author: wu-hui + * Time: 2024/07/01 13:53 + * @param $uid + * @param $type + * @param int $merId + * @return mixed + */ + public function getHoldInfo($uid, $type, $merId = 0){ + $where = [ + 'uid' => $uid, + 'quota_type' => $type, + 'mer_id' => $merId, + ]; + $holdInfo = $this->searchModel($where)->findOrEmpty(); + if((int)$holdInfo->uid <= 0) { + $holdInfo->uid = $uid; + $holdInfo->quota_type = $type; + $holdInfo->mer_id = $merId; + } + + return $holdInfo; + } /** @@ -171,6 +195,7 @@ class ExchangeQuotaRepository extends BaseRepository{ */ public function getConfig(){ $config = systemConfig([ + 'quota_integral_switch', 'quota_integral_rate', 'quota_integral_diff_rate', 'quota_integral_upgrade_switch', @@ -178,6 +203,7 @@ class ExchangeQuotaRepository extends BaseRepository{ 'quota_integral_upgrade_level', ]); // 信息处理 + $config['quota_integral_switch'] = (int)$config['quota_integral_switch']; $config['quota_integral_upgrade_switch'] = (int)$config['quota_integral_upgrade_switch']; diff --git a/app/controller/admin/user/ExchangeQuota.php b/app/controller/admin/user/ExchangeQuota.php index 72c9a5a..050bc2d 100644 --- a/app/controller/admin/user/ExchangeQuota.php +++ b/app/controller/admin/user/ExchangeQuota.php @@ -202,11 +202,12 @@ class ExchangeQuota extends BaseController{ */ public function setConfig(){ $config = $this->request->params([ - ['quota_integral_rate',0],// 赠送比例 - ['quota_integral_diff_rate',0],// 补差折扣,以原价的百分之多少进行现金支付 - ['quota_integral_upgrade_switch',0],// 是否开启消费升级 - ['quota_integral_upgrade_money',0],// 升级分销商要求金额 - ['quota_integral_upgrade_level',0],// 升级后等级 + ['quota_integral_switch',0], + ['quota_integral_rate',0], + ['quota_integral_diff_rate',0], + ['quota_integral_upgrade_switch',0], + ['quota_integral_upgrade_money',0], + ['quota_integral_upgrade_level',0], ]); // 保存信息 $cid = app()->make(ConfigClassifyRepository::class)->getConfigClassifyKeyById('quota_config', '额度与积分配置'); diff --git a/app/listener/exchangeQuota/OrderAgreeRefundEvent.php b/app/listener/exchangeQuota/OrderAgreeRefundEvent.php index 2d99149..cc4e96a 100644 --- a/app/listener/exchangeQuota/OrderAgreeRefundEvent.php +++ b/app/listener/exchangeQuota/OrderAgreeRefundEvent.php @@ -33,64 +33,12 @@ class OrderAgreeRefundEvent{ // 获取当前商品退款比例 if((int)$refundProductInfo['refund_num'] <= 0) continue; $refundRate = (float)sprintf("%.2f",(int)$refundProductInfo['refund_num'] / (int)$refundProductInfo['product']['product_num'] * 100); - // 计算减少额度 - 酒卡额度 - $sum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel([ - 'order_product_id' => $refundProductInfo['order_product_id'], - 'change_type' => 1 - ])->sum('change_quantity'); - $refundQuota = (float)sprintf("%.2f",$sum * $refundRate / 100); - if($refundQuota > 0){ - // 修改用户持有信息 - $userHoldInfo = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$refund['uid']])->findOrEmpty(); - $changeFront = (float)$userHoldInfo->surplus_quota; - $userHoldInfo->total_quota -= (float)$refundQuota;// 总额度 - $userHoldInfo->surplus_quota -= (float)$refundQuota;// 剩余额度 - $userHoldInfo->freeze_quota -= (float)$refundQuota;// 冻结额度 - $userHoldInfo->save(); - // 添加变更记录 - ExchangeQuotaRecord::insert([ - 'uid' => $refund['uid'], - 'product_id' => $refundProductInfo['product']['product_id'], - 'order_id' => $refundProductInfo['product']['order_id'], - 'order_product_id' => $refundProductInfo['order_product_id'], - 'change_type' => 0, - 'change_quantity' => (float)$refundQuota, - 'change_front' => $changeFront, - 'change_after' => (float)$userHoldInfo->surplus_quota, - 'remark' => "订单退款减少", - 'source' => 1, - ]); - } - // 计算减少额度 - 菜卡额度 - $dishSum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel([ - 'order_product_id' => $refundProductInfo['order_product_id'], - 'change_type' => 1, - 'quota_type' => 2 - ])->sum('change_quantity'); - $dishRefundQuota = (float)sprintf("%.2f",$dishSum * $refundRate / 100); - if($dishRefundQuota > 0){ - // 修改用户持有信息 - $dishUserHoldInfo = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$refund['uid'],'quota_type'=>2])->findOrEmpty(); - $dishChangeFront = (float)$dishUserHoldInfo->surplus_quota; - $dishUserHoldInfo->total_quota -= (float)$dishRefundQuota;// 总额度 - $dishUserHoldInfo->surplus_quota -= (float)$dishRefundQuota;// 剩余额度 - $dishUserHoldInfo->freeze_quota -= (float)$dishRefundQuota;// 冻结额度 - $dishUserHoldInfo->save(); - // 添加变更记录 - ExchangeQuotaRecord::insert([ - 'uid' => $refund['uid'], - 'product_id' => $refundProductInfo['product']['product_id'], - 'order_id' => $refundProductInfo['product']['order_id'], - 'order_product_id' => $refundProductInfo['order_product_id'], - 'change_type' => 0, - 'change_quantity' => (float)$dishRefundQuota, - 'change_front' => $dishChangeFront, - 'change_after' => (float)$dishUserHoldInfo->surplus_quota, - 'remark' => "订单退款减少", - 'source' => 1, - ]); - } - + // 相关额度和积分退款处理;额度类型:1=酒卡额度,2=菜卡额度,3=封坛酒额度,4=加油卡额度,5=惠民积分 + $this->exchangeQuotaRefund($refundProductInfo, $refundRate, $refund); + $this->exchangeQuotaRefund($refundProductInfo, $refundRate, $refund, 2); + $this->exchangeQuotaRefund($refundProductInfo, $refundRate, $refund, 3); + $this->exchangeQuotaRefund($refundProductInfo, $refundRate, $refund, 4); + $this->exchangeQuotaRefund($refundProductInfo, $refundRate, $refund, 5); @@ -104,4 +52,65 @@ class OrderAgreeRefundEvent{ Log::info('订单进入退款成功 - 酒卡额度相关处理 - 错误:'.var_export($error,1)); } } + + // 相关额度和积分退款处理 额度类型:1=酒卡额度(瓶装酒),2=菜卡额度,3=封坛酒额度,4=加油卡额度,5=惠民积分 + private function exchangeQuotaRefund($refundProductInfo, $refundRate, $refund, $quotaType = 1){ + // 获取本订单总赠送数量 + $info = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel([ + 'order_product_id' => $refundProductInfo['order_product_id'], + 'change_type' => 1, + 'quota_type' => $quotaType + ])->findOrEmpty()->toArray(); + $sum = $info['change_quantity'] ?? 0; + // 计算应退款数量 + $refundQuota = $sum > 0 ? (float)sprintf("%.2f",$sum * $refundRate / 100) : 0; + // 数量大于0 + if($refundQuota > 0){ + // 修改用户持有信息 + $userHoldInfo = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$refund['uid']])->findOrEmpty(); + $changeFront = (float)$userHoldInfo->surplus_quota; + $userHoldInfo->total_quota -= (float)$refundQuota;// 总额度 + $userHoldInfo->surplus_quota -= (float)$refundQuota;// 剩余额度 + $userHoldInfo->freeze_quota -= (float)$refundQuota;// 冻结额度 + $userHoldInfo->save(); + // 添加变更记录 + ExchangeQuotaRecord::insert([ + 'uid' => $refund['uid'], + 'product_id' => $refundProductInfo['product']['product_id'], + 'order_id' => $refundProductInfo['product']['order_id'], + 'order_product_id' => $refundProductInfo['order_product_id'], + 'change_type' => 0, + 'change_quantity' => (float)$refundQuota, + 'change_front' => $changeFront, + 'change_after' => (float)$userHoldInfo->surplus_quota, + 'remark' => "订单退款减少", + 'source' => 1, + 'quota_type' => $info['quota_type'] ?? $quotaType, + 'mer_id' => $info['quota_type'] ?? 0, + ]); + } + + return true; + } + + + + + + + + + + + + + + + + + + + + + } \ No newline at end of file diff --git a/app/listener/exchangeQuota/OrderPaySuccessEvent.php b/app/listener/exchangeQuota/OrderPaySuccessEvent.php index 4761066..2a1b29e 100644 --- a/app/listener/exchangeQuota/OrderPaySuccessEvent.php +++ b/app/listener/exchangeQuota/OrderPaySuccessEvent.php @@ -4,6 +4,7 @@ namespace app\listener\exchangeQuota; use app\common\model\marketing\activity\Record; use app\common\model\marketing\agent\AgentDelivery; +use app\common\model\system\merchant\Merchant; use app\common\model\system\merchant\MerchantShareholderIntegral; use app\common\model\user\ExchangeIntegralRecord; use app\common\model\user\ExchangeQuota; @@ -115,25 +116,18 @@ class OrderPaySuccessEvent{ // 支付成功 - 赠送酒卡额度 public function orderPaySuccessHandle($groupOrder):bool{ // 用户当前持有 酒卡额度 - $userHoldInfo = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$groupOrder->uid])->findOrEmpty(); - if((int)$userHoldInfo->uid <= 0) $userHoldInfo->uid = $groupOrder->uid; + $userHoldInfo = app()->make(ExchangeQuotaRepository::class)->getHoldInfo($groupOrder->uid, 1, 0); // 用户当前持有 菜卡额度 - $userHoldInfoDish = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$groupOrder->uid,'quota_type'=>2])->findOrEmpty(); - if((int)$userHoldInfoDish->uid <= 0) { - $userHoldInfoDish->uid = $groupOrder->uid; - $userHoldInfoDish->quota_type = 2; - } + $userHoldInfoDish = app()->make(ExchangeQuotaRepository::class)->getHoldInfo($groupOrder->uid, 2, 0); // 用户当前持有 封坛酒额度 - $userHoldInfoWine = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$groupOrder->uid,'quota_type'=>3])->findOrEmpty(); - if((int)$userHoldInfoWine->uid <= 0) { - $userHoldInfoWine->uid = $groupOrder->uid; - $userHoldInfoWine->quota_type = 3; - } + $userHoldInfoWine = app()->make(ExchangeQuotaRepository::class)->getHoldInfo($groupOrder->uid, 3, 0); // 总平台统一设置 赠送酒卡额度倍数 $exchangeQuotaMultiple = (int)systemConfig('exchange_quota_multiple'); // 循环处理单个商品 $insertData = []; foreach($groupOrder->orderList as $orderInfo){ + $merSubType = (int)Merchant::where('mer_id', $orderInfo->mer_id)->value('merchant_sub_type'); + // 循环商品处理额度信息 foreach($orderInfo->orderProduct as $orderProductInfo){ // 判断:商品是否开启赠送酒卡额度 if($orderProductInfo->product->is_give_quota == 1){ @@ -145,7 +139,6 @@ class OrderPaySuccessEvent{ // 判断:独立设置 还是使用统一设置 if((float)$orderProductInfo->product->give_quota_num > 0) $giveNum = (float)$orderProductInfo->product->give_quota_num; // 赠送酒卡额度处理 - // 赠送 $changeFront = (float)$userHoldInfo->surplus_quota; $userHoldInfo->total_quota += (float)$giveNum;// 总额度 $userHoldInfo->surplus_quota += (float)$giveNum;// 剩余额度 @@ -221,6 +214,8 @@ class OrderPaySuccessEvent{ 'quota_type' => 3 ]; } + // 判断:当前商户类型 如果是中小型餐厅则赠送惠民积分;如果是大型餐厅则赠送酒水卡积分;商户子类型:0=默认,1=酒道馆/大型餐厅,2=小酒馆/中小型餐厅 + if($merSubType == 2) $this->giveQuotaIntegral($orderInfo,'购买商品赠送',0, (float)$orderProductInfo->product_price,$orderProductInfo->product_id,$orderProductInfo->order_product_id ); } } // 修改用户持有 @@ -232,54 +227,63 @@ class OrderPaySuccessEvent{ return true; } - // 支付成功 - 赠送酒水卡积分 + // 支付成功 - 赠送酒水卡积分&赠送惠民积分 public function giveExchangeIntegral($groupOrder){ // 获取用户当前持有 $userHoldInfo = User::where('uid',$groupOrder->uid)->findOrEmpty(); // 循环处理单个商品 $insertData = []; foreach($groupOrder->orderList as $orderInfo){ - // 判断:存在预支积分时 当前订单赠送积分抵消预支积分后是否存在结余 - $surplus = (float)$orderInfo->pay_price; - if((float)$userHoldInfo->advance_exchange_integral > 0){ - // 抵消减少的积分 预支积分 小于等于 赠送积分,减少预支积分,否则减少赠送积分 - $reduceIntegral = (float)$userHoldInfo->advance_exchange_integral <= $surplus ? (float)$userHoldInfo->advance_exchange_integral : $surplus; - // 存在预支积分 减少预支积分,赠送积分为0 - $changeFront = (float)$userHoldInfo->advance_exchange_integral; - $userHoldInfo->advance_exchange_integral -= (float)$reduceIntegral;// 总额度 - $insertData[] = [ - 'uid' => $orderInfo->uid, - 'product_id' => $orderInfo->product_id ?? 0, - 'order_id' => $orderInfo->order_id ?? 0, - 'order_product_id' => $orderInfo->order_product_id ?? 0, - 'change_type' => 0, - 'change_quantity' => (float)$reduceIntegral, - 'change_front' => $changeFront, - 'change_after' => (float)$userHoldInfo->advance_exchange_integral, - 'remark' => "消费抵消预支积分" . (float)$reduceIntegral, - 'source' => 1 - ]; - // 是否存在结余 - $surplus = (float)sprintf("%.2f",$surplus - $reduceIntegral); + // 判断:当前商户类型 如果是中小型餐厅则赠送惠民积分;如果是大型餐厅则赠送酒水卡积分;商户子类型:0=默认,1=酒道馆/大型餐厅,2=小酒馆/中小型餐厅 + $merSubType = (int)Merchant::where('mer_id', $orderInfo->mer_id)->value('merchant_sub_type'); + if($merSubType == 2){ + // 中小型餐厅 惠民积分 + $this->giveQuotaIntegral($orderInfo,'在线买单赠送',6, $orderInfo->pay_price ); } - // 判断:抵消预支积分后 是否存在结余,存在则未抵消完成,进行赠送操作 - if((float)$surplus > 0){ - // 无预支积分 正常赠送 - $changeFront = (float)$userHoldInfo->exchange_integral; - $userHoldInfo->exchange_integral += (float)$surplus;// 总额度 - // 记录 - $insertData[] = [ - 'uid' => $orderInfo->uid, - 'product_id' => $orderInfo->product_id ?? 0, - 'order_id' => $orderInfo->order_id ?? 0, - 'order_product_id' => $orderInfo->order_product_id ?? 0, - 'change_type' => 1, - 'change_quantity' => (float)$surplus, - 'change_front' => $changeFront, - 'change_after' => (float)$userHoldInfo->exchange_integral, - 'remark' => "消费赠送酒水卡积分", - 'source' => 0 - ]; + else{ + // 大型餐厅 赠送酒水卡积分 + $surplus = (float)$orderInfo->pay_price; + // 判断:存在预支积分时 当前订单赠送积分抵消预支积分后是否存在结余 + if((float)$userHoldInfo->advance_exchange_integral > 0){ + // 抵消减少的积分 预支积分 小于等于 赠送积分,减少预支积分,否则减少赠送积分 + $reduceIntegral = (float)$userHoldInfo->advance_exchange_integral <= $surplus ? (float)$userHoldInfo->advance_exchange_integral : $surplus; + // 存在预支积分 减少预支积分,赠送积分为0 + $changeFront = (float)$userHoldInfo->advance_exchange_integral; + $userHoldInfo->advance_exchange_integral -= (float)$reduceIntegral;// 总额度 + $insertData[] = [ + 'uid' => $orderInfo->uid, + 'product_id' => $orderInfo->product_id ?? 0, + 'order_id' => $orderInfo->order_id ?? 0, + 'order_product_id' => $orderInfo->order_product_id ?? 0, + 'change_type' => 0, + 'change_quantity' => (float)$reduceIntegral, + 'change_front' => $changeFront, + 'change_after' => (float)$userHoldInfo->advance_exchange_integral, + 'remark' => "消费抵消预支积分" . (float)$reduceIntegral, + 'source' => 1 + ]; + // 是否存在结余 + $surplus = (float)sprintf("%.2f",$surplus - $reduceIntegral); + } + // 判断:抵消预支积分后 是否存在结余,存在则未抵消完成,进行赠送操作 + if((float)$surplus > 0){ + // 无预支积分 正常赠送 + $changeFront = (float)$userHoldInfo->exchange_integral; + $userHoldInfo->exchange_integral += (float)$surplus;// 总额度 + // 记录 + $insertData[] = [ + 'uid' => $orderInfo->uid, + 'product_id' => $orderInfo->product_id ?? 0, + 'order_id' => $orderInfo->order_id ?? 0, + 'order_product_id' => $orderInfo->order_product_id ?? 0, + 'change_type' => 1, + 'change_quantity' => (float)$surplus, + 'change_front' => $changeFront, + 'change_after' => (float)$userHoldInfo->exchange_integral, + 'remark' => "消费赠送酒水卡积分", + 'source' => 0 + ]; + } } // 是否存在餐费积分使用情况 存在则减少餐费积分 $useIntegral = $orderInfo->merchant_shareholder_integral ?? 0; @@ -337,6 +341,52 @@ class OrderPaySuccessEvent{ return true; } + /** + * Common: 赠送惠民积分处理 + * Author: wu-hui + * Time: 2024/07/01 14:35 + * @param $uid + * @param $merId + * @param $orderInfo + * @param $remark + * @param $source + * @return bool + */ + private function giveQuotaIntegral($orderInfo, $remark, $source, $payPrice, $productId = 0, $orderProductId = 0){ + // 设置信息获取 + $config = app()->make(ExchangeQuotaRepository::class)->getConfig(); + $quotaIntegralRate = (float)$config['quota_integral_rate']; + // 赠送惠民积分 + if($config['quota_integral_switch'] == 1 && $quotaIntegralRate > 0){ + $quotaIntegralHoldInfo = app()->make(ExchangeQuotaRepository::class)->getHoldInfo($orderInfo->uid, 5, $orderInfo->mer_id); + $giveNum = (float)sprintf("%.2f",$quotaIntegralRate * $payPrice); + // 赠送 + $changeFront = (float)$quotaIntegralHoldInfo->surplus_quota; + $quotaIntegralHoldInfo->total_quota += (float)$giveNum;// 总额度 + $quotaIntegralHoldInfo->surplus_quota += (float)$giveNum;// 剩余额度 + // 在线买单订单无需冻结 非在线买单订单需要冻结,待订单完成后解冻 + if($orderInfo->activity_type != 30) $quotaIntegralHoldInfo->freeze_quota += (float)$giveNum;// 冻结额度 + // 记录 + ExchangeQuotaRecord::insert([ + 'uid' => $orderInfo->uid, + 'product_id' => $productId, + 'order_id' => $orderInfo->order_id, + 'order_product_id' => $orderProductId, + 'change_type' => 1, + 'change_quantity' => (float)$giveNum, + 'change_front' => $changeFront, + 'change_after' => (float)$quotaIntegralHoldInfo->surplus_quota, + 'mer_id' => $orderInfo->mer_id, + 'remark' => $remark, + 'quota_type' => 5, + 'source' => $source, + ]); + $quotaIntegralHoldInfo->save(); + } + + return true; + } + diff --git a/app/listener/exchangeQuota/OrderTakeEvent.php b/app/listener/exchangeQuota/OrderTakeEvent.php index 6f847ff..aba45db 100644 --- a/app/listener/exchangeQuota/OrderTakeEvent.php +++ b/app/listener/exchangeQuota/OrderTakeEvent.php @@ -36,19 +36,24 @@ class OrderTakeEvent{ // 'uid' => $order->uid, // 'activity_type' => $order->activity_type // ],1)); - // 其他商品 + // 酒卡额度解冻 - $this->quotaThawing($order); + $this->exchangeQuotaThawing($order, 1); // 菜卡额度解冻 - $this->vegetableQuotaThawing($order); + $this->exchangeQuotaThawing($order, 2); // 封坛酒额度解冻 - $this->wineQuotaThawing($order); + $this->exchangeQuotaThawing($order, 3); + // 惠民积分解冻 + $this->exchangeQuotaThawing($order, 5); + + // 商户佣金结算 $this->merMoneyHandle($order->order_id); // 品牌额度返还 $this->returnBrandQuota($order->order_id,$order->mer_id); - + + } }catch(\Exception $e){ if($order->activity_type == 35){ @@ -59,77 +64,36 @@ class OrderTakeEvent{ } } - // 酒卡额度解冻 - private function quotaThawing($order){ - # 获取变更记录 条件:order_id=当前订单id、变更类型=增加 - $sum = (float)app()->make(ExchangeQuotaRecordRepository::class) - ->searchModel([ - 'order_id' => $order->order_id, - 'change_type' => 1, - 'source' => 0,// 仅查询购买赠送 进行解冻 - ])->sum('change_quantity'); - $refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class) - ->searchModel([ - 'order_id' => $order->order_id, - 'change_type' => 0, - 'source' => 1,// 仅查询订单退款 减少内容 - ])->sum('change_quantity'); - // 剩余数量 解冻 + + // 相关额度和积分解冻 额度类型:1=酒卡额度(瓶装酒),2=菜卡额度,3=封坛酒额度,4=加油卡额度,5=惠民积分 + private function exchangeQuotaThawing($order, $quotaType){ + // 获取本订单赠送数量 + $giveWhere = [ + 'order_id' => $order->order_id, + 'change_type' => 1, + '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' => $order->order_id, + '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){ - $hold = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$order->uid])->findOrEmpty(); - $freezeQuota = sprintf("%.2f",$hold->freeze_quota - $surplusQuota); - $hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota; - $hold->save(); - } - } - // 菜卡额度解冻 - private function vegetableQuotaThawing($order){ - # 获取变更记录 条件:order_id=当前订单id、变更类型=增加 - $sum = (float)app()->make(ExchangeQuotaRecordRepository::class) - ->searchModel([ - 'order_id' => $order->order_id, - 'change_type' => 1, - 'source' => 0,// 仅查询购买赠送 进行解冻 - 'quota_type' => 2, - ])->sum('change_quantity'); - $refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class) - ->searchModel([ - 'order_id' => $order->order_id, - 'change_type' => 0, - 'source' => 1,// 仅查询订单退款 减少内容 - 'quota_type' => 2, - ])->sum('change_quantity'); - // 剩余数量 解冻 - $surplusQuota = (float)sprintf("%.2f",$sum - $refundSum); - if($surplusQuota > 0){ - $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(); - } - } - // 封坛酒额度解冻 - private function wineQuotaThawing($order){ - # 获取变更记录 条件:order_id=当前订单id、变更类型=增加 - $sum = (float)app()->make(ExchangeQuotaRecordRepository::class) - ->searchModel([ - 'order_id' => $order->order_id, - 'change_type' => 1, - 'source' => 0,// 仅查询购买赠送 进行解冻 - 'quota_type' => 3, - ])->sum('change_quantity'); - $refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class) - ->searchModel([ - 'order_id' => $order->order_id, - 'change_type' => 0, - 'source' => 1,// 仅查询订单退款 减少内容 - 'quota_type' => 3, - ])->sum('change_quantity'); - // 剩余数量 解冻 - $surplusQuota = (float)sprintf("%.2f",$sum - $refundSum); - if($surplusQuota > 0){ - $hold = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$order->uid,'quota_type'=>3])->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(); diff --git a/route/admin/member.php b/route/admin/member.php index 779501b..bc1f781 100644 --- a/route/admin/member.php +++ b/route/admin/member.php @@ -91,13 +91,6 @@ Route::group(function () { '_path' => '/user/member/inviteCode', '_auth' => true, ]); - - - - - - - // 会员订单列表 Route::get('user/svip/order_lst', 'admin.user.Svip/payList')->name('systemUserSvipPayLst')->option([ '_alias' => '列表',