diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 12db188..26f359b 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -79,6 +79,9 @@ class ProductRepository extends BaseRepository ['integral_deduction_money',0], // 是否赠送酒卡额度 ['is_give_quota',0], + ['give_quota_num',0], + ['is_give_dish',0], + ['give_dish_num',0], // 按照批量购买设置 ['is_batch',0], ['batch_num',0], @@ -496,6 +499,9 @@ class ProductRepository extends BaseRepository 'integral_deduction_money' => $data['integral_deduction_money'] ?? 0, // 赠送酒卡额度 'is_give_quota' => $data['is_give_quota'] ?? 0, + 'give_quota_num' => $data['give_quota_num'] ?? 0, + 'is_give_dish' => $data['is_give_dish'] ?? 0, + 'give_dish_num' => $data['give_dish_num'] ?? 0, // 按照批量购买设置 'is_batch' => $data['is_batch'] ?? 0, 'batch_num' => $data['batch_num'] ?? 0, diff --git a/app/listener/exchangeQuota/OrderPaySuccessEvent.php b/app/listener/exchangeQuota/OrderPaySuccessEvent.php index b1d42ae..53085d0 100644 --- a/app/listener/exchangeQuota/OrderPaySuccessEvent.php +++ b/app/listener/exchangeQuota/OrderPaySuccessEvent.php @@ -73,26 +73,28 @@ 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; + // 用户当前持有 菜卡额度 + $userHoldInfoDish = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$groupOrder->uid,'quota_type'=>2])->findOrEmpty(); + if((int)$userHoldInfoDish->uid <= 0) $userHoldInfoDish->uid = $groupOrder->uid; + // 总平台统一设置 赠送酒卡额度倍数 $exchangeQuotaMultiple = (int)systemConfig('exchange_quota_multiple'); // 循环处理单个商品 $insertData = []; foreach($groupOrder->orderList as $orderInfo){ foreach($orderInfo->orderProduct as $orderProductInfo){ - // 判断:商品是否开启赠送酒卡额度 赠送的酒卡额度 = 当前商品实际支付的金额 * 倍数 - if($orderProductInfo->product->is_give_quota == 1 && $orderProductInfo->product_price > 0){ - // 赠送数量计算 - $giveNum = (float)$orderProductInfo->product_price; - $merExchangeQuotaMultiple = (int)app()->make(MerchantRepository::class) - ->getSearch(['mer_id' => $orderInfo->mer_id]) - ->value('mer_exchange_quota_multiple'); - if($merExchangeQuotaMultiple > 0){ - $giveNum = (float)sprintf("%2.f",$giveNum * $merExchangeQuotaMultiple); - }else if($exchangeQuotaMultiple > 0) { - $giveNum = (float)sprintf("%2.f",$giveNum * $exchangeQuotaMultiple); - } + // 判断:商品是否开启赠送酒卡额度 + if($orderProductInfo->product->is_give_quota == 1){ + // 计算默认额度 + $giveNum = (float)$orderProductInfo->product_price;// 默认为支付金额 + $merExchangeQuotaMultiple = (int)app()->make(MerchantRepository::class)->getSearch(['mer_id' => $orderInfo->mer_id])->value('mer_exchange_quota_multiple'); + if($merExchangeQuotaMultiple > 0) $giveNum = (float)sprintf("%2.f",$giveNum * $merExchangeQuotaMultiple); + else if($exchangeQuotaMultiple > 0) $giveNum = (float)sprintf("%2.f",$giveNum * $exchangeQuotaMultiple); + // 判断:独立设置 还是使用统一设置 + 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;// 总额度 @@ -109,12 +111,43 @@ class OrderPaySuccessEvent{ 'change_front' => $changeFront, 'change_after' => (float)$userHoldInfo->surplus_quota, 'remark' => "购买商品赠送", + 'quota_type' => 1 + ]; + } + // 判断:商品是否开启赠送菜卡额度 + if($orderProductInfo->product->is_give_dish == 1){ + // 计算默认额度 + $giveNum = (float)$orderProductInfo->product_price;// 默认为支付金额 + $merExchangeQuotaMultiple = (int)app()->make(MerchantRepository::class)->getSearch(['mer_id' => $orderInfo->mer_id])->value('mer_exchange_quota_multiple'); + if($merExchangeQuotaMultiple > 0) $giveNum = (float)sprintf("%2.f",$giveNum * $merExchangeQuotaMultiple); + else if($exchangeQuotaMultiple > 0) $giveNum = (float)sprintf("%2.f",$giveNum * $exchangeQuotaMultiple); + // 判断:独立设置 还是使用统一设置 + if((float)$orderProductInfo->product->give_dish_num > 0) $giveNum = (float)$orderProductInfo->product->give_dish_num; + // 赠送酒卡额度处理 + // 赠送 + $changeFront = (float)$userHoldInfoDish->surplus_quota; + $userHoldInfoDish->total_quota += (float)$giveNum;// 总额度 + $userHoldInfoDish->surplus_quota += (float)$giveNum;// 剩余额度 + $userHoldInfoDish->freeze_quota += (float)$giveNum;// 冻结额度 + // 记录 + $insertData[] = [ + 'uid' => $orderProductInfo->uid, + 'product_id' => $orderProductInfo->product_id, + 'order_id' => $orderProductInfo->order_id, + 'order_product_id' => $orderProductInfo->order_product_id, + 'change_type' => 1, + 'change_quantity' => (float)$giveNum, + 'change_front' => $changeFront, + 'change_after' => (float)$userHoldInfoDish->surplus_quota, + 'remark' => "购买商品赠送", + 'quota_type' => 2 ]; } } } // 修改用户持有 $userHoldInfo->save(); + $userHoldInfoDish->save(); // 记录酒卡额度信息 if(count($insertData) > 0) ExchangeQuotaRecord::insertAll($insertData);