From cb3732b9580542e60cf1690c790d7c4977559bd6 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Tue, 2 Jul 2024 17:01:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E9=85=92=E9=81=93?= =?UTF-8?q?=E9=A6=86=E5=85=91=E6=8D=A2=E5=95=86=E5=93=81=E5=8C=BA=E5=88=86?= =?UTF-8?q?=E4=B8=BA=E9=85=92=E9=81=93=E9=A6=86=E5=85=91=E6=8D=A2=E5=92=8C?= =?UTF-8?q?=E5=B0=8F=E9=85=92=E9=A6=86=E5=85=91=E6=8D=A2=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=EF=BC=9A=E5=B0=8F=E9=85=92=E9=A6=86=E5=85=91=E6=8D=A2?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=B5=81=E7=A8=8B=E5=8F=8A=E6=83=A0=E6=B0=91?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E4=BD=BF=E7=94=A8=E5=A4=84=E7=90=86=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=9A=E9=85=92=E9=81=93=E9=A6=86=E5=85=91?= =?UTF-8?q?=E6=8D=A2=E8=AE=A2=E5=8D=95=E7=94=9F=E6=88=90=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E9=85=92=E6=B0=B4=E5=8D=A1=E7=A7=AF=E5=88=86=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=88=B0=E6=83=A0=E6=B0=91=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E5=A4=84=E7=90=86=E4=B8=AD=EF=BC=8C=E5=B9=B6=E4=B8=94=E4=BB=8E?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E5=A4=84=E7=90=86=E6=96=B9=E6=B3=95=E4=B8=AD?= =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E5=87=BA=E6=9D=A5=E5=8D=95=E7=8B=AC=E5=A4=84?= =?UTF-8?q?=E7=90=86=20=E9=87=8D=E6=9E=84=EF=BC=9A=E9=85=92=E9=81=93?= =?UTF-8?q?=E9=A6=86=E5=85=91=E6=8D=A2=E8=AE=A2=E5=8D=95=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E7=9B=B8=E5=85=B3=E9=85=92=E5=8D=A1=E9=A2=9D?= =?UTF-8?q?=E5=BA=A6=E5=A4=84=E7=90=86=E4=BB=8E=E5=85=AC=E5=85=B1=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E4=B8=AD=E7=8B=AC=E7=AB=8B=E5=87=BA=E6=9D=A5=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/system/merchant/MerchantDao.php | 3 + .../store/order/StoreCartRepository.php | 24 ++ .../order/StoreOrderCreateRepository.php | 226 ++++++++++-------- .../store/product/ProductRepository.php | 3 + app/controller/api/Wine.php | 31 +-- app/event.php | 4 + .../exchangeQuota/OrderCreateEvent.php | 188 +++++++++++++++ .../exchangeQuota/OrderPaySuccessEvent.php | 79 +++--- 8 files changed, 394 insertions(+), 164 deletions(-) create mode 100644 app/listener/exchangeQuota/OrderCreateEvent.php diff --git a/app/common/dao/system/merchant/MerchantDao.php b/app/common/dao/system/merchant/MerchantDao.php index ed89dd3..4885597 100644 --- a/app/common/dao/system/merchant/MerchantDao.php +++ b/app/common/dao/system/merchant/MerchantDao.php @@ -92,6 +92,9 @@ class MerchantDao extends BaseDao }) ->when(isset($where['invite_agent_id']) && $where['invite_agent_id'] !== '',function($query) use ($where){ $query->whereLike('invite_agent_id', $where['invite_agent_id']); + }) + ->when(isset($where['merchant_sub_type']) && $where['merchant_sub_type'] !== '',function($query) use ($where){ + $query->whereLike('merchant_sub_type', $where['merchant_sub_type']); }); diff --git a/app/common/repositories/store/order/StoreCartRepository.php b/app/common/repositories/store/order/StoreCartRepository.php index 2acf7ca..588c9ec 100644 --- a/app/common/repositories/store/order/StoreCartRepository.php +++ b/app/common/repositories/store/order/StoreCartRepository.php @@ -175,4 +175,28 @@ class StoreCartRepository extends BaseRepository } return true; } + + /** + * Common: 酒道馆查询基本模型 + * Author: wu-hui + * Time: 2024/07/02 9:55 + * @param $params + * @return \think\db\BaseQuery + */ + public function wineSearchModel($params){ + return $this->getSearch([]) + ->hasWhere('merchant',function($query) use ($params){ + $query->where('merchant_sub_type', $params['merchant_sub_type']); + }) + ->where([ + 'StoreCart.is_pay' => 0, + 'StoreCart.is_del' => 0, + 'StoreCart.is_new' => 0, + 'StoreCart.is_fail' => 0, + 'StoreCart.product_type' => 36, + 'StoreCart.uid' => $params['uid'], + ]); + } + + } diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 8297083..54a8b25 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -3,6 +3,7 @@ namespace app\common\repositories\store\order; use app\common\model\store\product\Product; +use app\common\model\system\merchant\Merchant; use app\common\model\user\ExchangeIntegralRecord; use app\common\model\user\ExchangeQuotaRecord; use app\common\model\user\User; @@ -48,6 +49,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ $isWithGoods = $withGoods['is_with_goods'] ?? 0;// 0=用户购物,1=酒道馆进货 $with_goods_mer_id = $withGoods['with_goods_mer_id'] ?? 0; $diffRate = 30;// 酒道馆商品 补差价比例 这里暂时默认固定为30% + $quotaIntegralConfig = app()->make(ExchangeQuotaRepository::class)->getConfig(); $key = md5(json_encode(compact('cartId','takes','useCoupon','useIntegral','addressId'))).$uid; //去掉过期的优惠券信息 app()->make(StoreCouponUserRepository::class)->failCoupon(); @@ -737,6 +739,11 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ $orderTotalMerTitleQuota = 0;// 进货订单 - 补货额度 - 冠名品牌抵扣额度(总) $orderTotalMerOtherQuota = 0;// 进货订单 - 补货额度 - 其他品牌抵扣额度(总) + $orderTotalQuotaIntegral = 0;// 订单总使用的惠民积分 + $orderTotalQuotaIntegralPrice = 0;// 订单总使用惠民积分抵扣的金额 + $orderTotalQuotaDiff = 0;// 惠民积分抵扣后总差价 + $orderTotalQuotaDiffMoney = 0;// 惠民积分差价实际支付金额 + // 获取当前进货商户的补货额度 $merQuotaInfo = app()->make(MerchantQuotaRepository::class)->getMerQuotaAndBrandInfo((int)$with_goods_mer_id); $titleSurplusQuota = $merQuotaInfo['title_surplus_quota'] ?? 0; @@ -775,6 +782,18 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ $orderRandomReduction = 0;//当前订单随机立减金额 $orderMerTitleQuota = 0;// 进货订单 - 补货额度 - 冠名品牌抵扣额度(本订单) $orderMerOtherQuota = 0;// 进货订单 - 补货额度 - 其他品牌抵扣额度(本订单) + // 惠民积分相关内容 + $merInfo = Merchant::where('mer_id', $merchantCart['mer_id'])->field('merchant_sub_type,shop_mer_id')->findOrEmpty()->toArray(); + $holdQuotaIntegral = 0; + if($merInfo['shop_mer_id'] > 0) { + $quotaIntegralHoldInfo = app()->make(ExchangeQuotaRepository::class)->getHoldInfo($uid, 5, $merInfo['shop_mer_id']); + $holdQuotaIntegral = (float)sprintf("%.2f", $quotaIntegralHoldInfo->surplus_quota - $quotaIntegralHoldInfo->freeze_quota); + } + $orderQuotaIntegral = 0;// 当前订单使用的惠民积分 + $orderQuotaIntegralPrice = 0;// 当前订单使用惠民积分抵扣的金额 + $orderQuotaDiff = 0;// 惠民积分抵扣后当前订单差价 + $orderQuotaDiffMoney = 0;// 惠民积分当前订单差价实际支付金额 + //计算积分抵扣 foreach($merchantCart['list'] as &$cart){ if($cart['product_type'] == 35){ @@ -802,34 +821,63 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ $cart['true_price'] = bcsub($cart['true_price'],$deductionAmount,2); } else if($cart['product_type'] == 36){ - // 兑换酒道馆商品时 酒水卡积分抵扣处理 - // 当前商品消耗积分 如果持有酒水卡积分大于等于支付金额,使用支付金额;小于支付金额,使用酒水卡积分 - $deductionAmount = (float)$exchangeIntegral >= (float)$cart['true_price'] ? (float)$cart['true_price'] : (float)$exchangeIntegral;// 实际抵扣金额 - $exchangeIntegral = bcsub((float)$exchangeIntegral,(float)$deductionAmount,2);// 剩余酒水卡积分 - $cart['exchange_integral'] = $deductionAmount; - $cart['exchange_integral_price'] = $deductionAmount; - // 订单总支付金额 先减去酒水卡积分抵扣金额 - $merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'],$deductionAmount,2); - // 当前商品剩余应支付金额 进行补差价计算 - $cartTruePrice = bcsub($cart['true_price'],$deductionAmount,2); - if($cartTruePrice > 0){ - // 未完全抵扣 需要补差价 - $diffMoney = sprintf("%.2f", $cartTruePrice * $diffRate / 100);// 实际支付差价 - - $orderWineDiffMoney = bcadd($orderWineDiffMoney,$cartTruePrice,2);// 剩余差价 - $orderWineDiffMoneyPrice = bcadd($orderWineDiffMoneyPrice,$diffMoney,2);// 实际支付差价金额 - $cart['wine_diff_money'] = $cartTruePrice; - $cart['wine_diff_money_price'] = $diffMoney; - - // 修改商品支付金额 - $merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'], bcsub($cartTruePrice,$diffMoney,2),2); - $cartTruePrice = $diffMoney; + // 兑换酒道馆商品时 相关积分抵扣处理 商户子类型:0=默认,1=酒道馆/大型餐厅,2=小酒馆/中小型餐厅 + if($merInfo['merchant_sub_type'] == 2){ + // 小酒馆处理 + if($quotaIntegralConfig['quota_integral_switch'] == 1){ + $deductionAmount = (float)$holdQuotaIntegral >= (float)$cart['true_price'] ? (float)$cart['true_price'] : (float)$holdQuotaIntegral;// 实际抵扣金额 + $holdQuotaIntegral = bcsub((float)$holdQuotaIntegral,(float)$deductionAmount,2);// 剩余惠民积分 + $cart['quota_integral'] = $deductionAmount; + $cart['quota_integral_price'] = $deductionAmount; + // 订单总支付金额 先减去惠民积分抵扣金额 + $merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'],$deductionAmount,2); + // 当前商品剩余应支付金额 进行补差价计算 + $cartTruePrice = bcsub($cart['true_price'],$deductionAmount,2); + if($cartTruePrice > 0){ + // 未完全抵扣 需要补差价 + $diffMoney = sprintf("%.2f",$cartTruePrice * $quotaIntegralConfig['quota_integral_diff_rate'] / 100);// 实际支付差价 + $orderQuotaDiff = bcadd($orderQuotaDiff,$cartTruePrice,2);// 剩余差价 + $orderQuotaDiffMoney = bcadd($orderQuotaDiffMoney,$diffMoney,2);// 实际支付差价金额 + $cart['quota_integral_diff'] = $cartTruePrice; + $cart['quota_integral_diff_money'] = $diffMoney; + // 修改商品支付金额 + $merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'], bcsub($cartTruePrice,$diffMoney,2),2); + $cartTruePrice = $diffMoney; + } + $cart['true_price'] = $cartTruePrice; + // 当前订单使用的惠民积分和抵扣金额 + $orderQuotaIntegral = bcadd($orderQuotaIntegral,$deductionAmount,2); + $orderQuotaIntegralPrice = bcadd($orderQuotaIntegralPrice,$deductionAmount,2); + } } + else{ + // 酒道馆处理 当前商品消耗积分 如果持有酒水卡积分大于等于支付金额,使用支付金额;小于支付金额,使用酒水卡积分 + $deductionAmount = (float)$exchangeIntegral >= (float)$cart['true_price'] ? (float)$cart['true_price'] : (float)$exchangeIntegral;// 实际抵扣金额 + $exchangeIntegral = bcsub((float)$exchangeIntegral,(float)$deductionAmount,2);// 剩余酒水卡积分 + $cart['exchange_integral'] = $deductionAmount; + $cart['exchange_integral_price'] = $deductionAmount; + // 订单总支付金额 先减去酒水卡积分抵扣金额 + $merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'],$deductionAmount,2); + // 当前商品剩余应支付金额 进行补差价计算 + $cartTruePrice = bcsub($cart['true_price'],$deductionAmount,2); + if($cartTruePrice > 0){ + // 未完全抵扣 需要补差价 + $diffMoney = sprintf("%.2f", $cartTruePrice * $diffRate / 100);// 实际支付差价 - $cart['true_price'] = $cartTruePrice; - // 当前订单使用的酒水卡积分和抵扣金额 - $orderWineIntegral = bcadd($orderWineIntegral,$deductionAmount,2); - $orderWineIntegralPrice = bcadd($orderWineIntegralPrice,$deductionAmount,2); + $orderWineDiffMoney = bcadd($orderWineDiffMoney,$cartTruePrice,2);// 剩余差价 + $orderWineDiffMoneyPrice = bcadd($orderWineDiffMoneyPrice,$diffMoney,2);// 实际支付差价金额 + $cart['wine_diff_money'] = $cartTruePrice; + $cart['wine_diff_money_price'] = $diffMoney; + + // 修改商品支付金额 + $merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'], bcsub($cartTruePrice,$diffMoney,2),2); + $cartTruePrice = $diffMoney; + } + $cart['true_price'] = $cartTruePrice; + // 当前订单使用的酒水卡积分和抵扣金额 + $orderWineIntegral = bcadd($orderWineIntegral,$deductionAmount,2); + $orderWineIntegralPrice = bcadd($orderWineIntegralPrice,$deductionAmount,2); + } } else{ //只有普通商品可以抵扣 @@ -893,13 +941,18 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ $order_total_integral = bcadd($order_total_integral,$total_integral,0); $order_total_integral_price = bcadd($order_total_integral_price,$total_integral_price,2); - + // 随机立减 + $orderTotalRandomReduction = bcadd($orderTotalRandomReduction,$orderRandomReduction,2); // 订单总使用的酒水卡积分 & 总抵扣的金额 $orderTotalWineIntegral = bcadd($orderTotalWineIntegral,$orderWineIntegral,2); $orderTotalWineIntegralPrice = bcadd($orderTotalWineIntegralPrice,$orderWineIntegralPrice,2); - $orderTotalRandomReduction = bcadd($orderTotalRandomReduction,$orderRandomReduction,2); $orderTotalWineDiffMoney = bcadd($orderTotalWineDiffMoney,$orderWineDiffMoney,2); $orderTotalWineDiffMoneyPrice = bcadd($orderTotalWineDiffMoneyPrice,$orderWineDiffMoneyPrice,2); + // 订单总使用的惠民积分 & 总抵扣的金额 + $orderTotalQuotaIntegral = bcadd($orderTotalQuotaIntegral,$orderQuotaIntegral,2); + $orderTotalQuotaIntegralPrice = bcadd($orderTotalQuotaIntegralPrice,$orderQuotaIntegralPrice,2); + $orderTotalQuotaDiff = bcadd($orderTotalQuotaDiff,$orderQuotaDiff,2); + $orderTotalQuotaDiffMoney = bcadd($orderTotalQuotaDiffMoney,$orderQuotaDiffMoney,2); // 订单使用的补货额度 $orderTotalMerTitleQuota = bcadd($orderTotalMerTitleQuota,$orderMerTitleQuota,2); $orderTotalMerOtherQuota = bcadd($orderTotalMerOtherQuota,$orderMerOtherQuota,2); @@ -947,14 +1000,19 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ // 酒水卡积分抵扣情况 $merchantCart['order']['exchange_integral_price'] = $orderWineIntegralPrice; $merchantCart['order']['exchange_integral'] = $orderWineIntegral; - $merchantCart['order']['wine_diff_money'] = $orderWineDiffMoney; - $merchantCart['order']['wine_diff_money_price'] = $orderWineDiffMoneyPrice; - $merchantCart['order']['org_price'] = $org_price; - $merchantCart['order']['pay_price'] = $pay_price; - $merchantCart['order']['coupon_price'] = $coupon_price; + $merchantCart['order']['wine_diff_money'] = $orderWineDiffMoney; + $merchantCart['order']['wine_diff_money_price'] = $orderWineDiffMoneyPrice; + // 惠民积分抵扣情况 + $merchantCart['order']['quota_integral'] = $orderQuotaIntegral; + $merchantCart['order']['quota_integral_price'] = $orderQuotaIntegralPrice; + $merchantCart['order']['quota_integral_diff'] = $orderQuotaDiff; + $merchantCart['order']['quota_integral_diff_money'] = $orderQuotaDiffMoney; + $merchantCart['order']['org_price'] = $org_price; + $merchantCart['order']['pay_price'] = $pay_price; + $merchantCart['order']['coupon_price'] = $coupon_price; $merchantCart['order']['random_reduction'] = $orderRandomReduction; - $merchantCart['order']['mer_quota_title'] = $orderMerTitleQuota; - $merchantCart['order']['mer_quota_other'] = $orderMerOtherQuota; + $merchantCart['order']['mer_quota_title'] = $orderMerTitleQuota; + $merchantCart['order']['mer_quota_other'] = $orderMerOtherQuota; $order_price = bcadd($order_price,$pay_price,2); $order_total_price = bcadd($order_total_price,$total_price,2); @@ -979,8 +1037,14 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ $openIntegral = $merIntegralFlag && !$order_type && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0; - $integralDeductionAmount = bcadd($order_total_integral_price,$orderTotalWineIntegralPrice,2); - $total_coupon = bcadd($order_svip_discount,bcadd(bcadd($total_platform_coupon_price,$order_coupon_price,2),$integralDeductionAmount,2),2); + + + + + + + $deductionAmount = (float)sprintf("%.2f",$order_total_integral_price + $orderTotalWineIntegralPrice + $orderTotalQuotaIntegralPrice); + $total_coupon = bcadd($order_svip_discount,bcadd(bcadd($total_platform_coupon_price,$order_coupon_price,2),$deductionAmount,2),2); $data = compact( @@ -1001,6 +1065,12 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ 'orderTotalWineIntegralPrice', 'orderTotalWineDiffMoney', 'orderTotalWineDiffMoneyPrice', + + 'orderTotalQuotaIntegral', + 'orderTotalQuotaIntegralPrice', + 'orderTotalQuotaDiff', + 'orderTotalQuotaDiffMoney', + 'orderTotalRandomReduction', 'orderTotalMerOtherQuota', 'orderTotalMerTitleQuota', @@ -1225,6 +1295,11 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ // 进货订单 - 补货额度抵扣金额 'mer_quota_title' => $merchantCart['order']['mer_quota_title'] ?? 0, 'mer_quota_other' => $merchantCart['order']['mer_quota_other'] ?? 0, + // 惠民积分 + 'quota_integral' => $merchantCart['order']['quota_integral'] ?? 0, + 'quota_integral_price' => $merchantCart['order']['quota_integral_price'] ?? 0, + 'quota_integral_diff' => $merchantCart['order']['quota_integral_diff'] ?? 0, + 'quota_integral_diff_money' => $merchantCart['order']['quota_integral_diff_money'] ?? 0, ]; $allUseCoupon = array_merge($allUseCoupon,$merchantCart['order']['useCouponIds']); @@ -1355,40 +1430,16 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ ]); $user->save(); } - // 用户兑换酒道馆商品 减少酒水卡积分 - if($groupOrder['activity_type'] == 36 && $groupOrder['exchange_integral'] > 0){ - $userInfo = User::where('uid',$user['uid'])->findOrEmpty(); - $integralChangeFront = (float)$userInfo->exchange_integral; - $userInfo->exchange_integral -= (float)$groupOrder['exchange_integral']; - $userInfo->exchange_integral = $userInfo->exchange_integral > 0 ? $userInfo->exchange_integral : 0; - $userInfo->save(); - ExchangeIntegralRecord::insert([ - 'uid' => $user['uid'], - 'product_id' => 0, - 'order_id' => 0, - 'order_product_id' => 0, - 'change_type' => 0, - 'change_quantity' => (float)$groupOrder['exchange_integral'], - 'change_front' => $integralChangeFront, - 'change_after' => (float)$userInfo->exchange_integral, - 'remark' => "兑换消费", - ]); - } - - - foreach($orderList as $k => $order){ - $orderList[$k]['group_order_id'] = $groupOrder->group_order_id; - } + // 循环处理单个订单 $orderProduct = []; $orderStatus = []; - $quotaHoldInfo = app()->make(MerchantQuotaRepository::class)->getQuotaInfo($groupOrder['with_goods_mer_id']); $quotaRecordInsertData = []; - - foreach($orderList as $order){ + foreach($orderList as $k => $order){ + $order['group_order_id'] = $orderList[$k]['group_order_id'] = $groupOrder->group_order_id; $cartInfo = $order['cartInfo']; unset($order['cartInfo']); - //创建子订单 + // 创建子订单 $_order = $this->dao->create($order); if($order['integral'] > 0){ $bills[] = [ @@ -1405,7 +1456,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ 'status' => 1 ]; } - //创建发票信息 + // 创建发票信息 if(isset($receipt_data[$_order['mer_id']])){ app() ->make(StoreOrderReceiptRepository::class) @@ -1514,41 +1565,15 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ // 进货订单 - 补货额度抵扣金额 'mer_quota_title' => $cart['mer_quota_title'] ?? 0, 'mer_quota_other' => $cart['mer_quota_other'] ?? 0, + // 惠民积分 + 'quota_integral' => $cart['quota_integral'] ?? 0, + 'quota_integral_price' => $cart['quota_integral_price'] ?? 0, + 'quota_integral_diff' => $cart['quota_integral_diff'] ?? 0, + 'quota_integral_diff_money' => $cart['quota_integral_diff_money'] ?? 0, ]; - // 根据商品类型进行特殊处理 - if($cart['product_type'] == 36){ - // 用户兑换商品 变更相关额度 酒类型:0=未知,1=瓶装酒,2=封坛酒 - $wineType = (int)Product::where('product_id', $cart['product_id'])->value('wine_type'); - if($wineType > 0){ - // 额度类型:1=酒卡额度(瓶装酒),2=菜卡额度,3=封坛酒额度,4=加油卡额度 - $quotaType = $wineType == 2 ? 3 : 1; - - $userHoldInfo = app()->make(ExchangeQuotaRepository::class) - ->searchModel(['uid'=>$user['uid'],'quota_type'=>$quotaType]) - ->findOrEmpty(); - $changeFront = (float)$userHoldInfo->surplus_quota; - $userHoldInfo->use_quota += (float)$cart['total_price']; - $userHoldInfo->surplus_quota -= (float)$cart['total_price']; - $userHoldInfo->save(); - ExchangeQuotaRecord::insert([ - 'uid' => $user['uid'], - 'product_id' => 0, - 'order_id' => 0, - 'order_product_id' => 0, - 'change_type' => 0, - 'change_quantity' => (float)$cart['total_price'], - 'change_front' => $changeFront, - 'change_after' => (float)$userHoldInfo->surplus_quota, - 'remark' => "兑换消费", - 'source' => 2, - 'quota_type' => $quotaType, - ]); - } - } } $userMerchantRepository->getInfo($uid,$order['mer_id']); app()->make(MerchantRepository::class)->incSales($order['mer_id'],$order['total_num']); - // 进货订单 并且存在补货额度减免 减少进货商户的补货额度 if($_order->activity_type == 35 && $_order->with_goods_mer_id > 0){ // 判断:是否存在冠名品牌额度 @@ -1589,21 +1614,20 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ } } } - // 处理补货额度变更 if($groupOrder['activity_type'] == 35){ $quotaHoldInfo->save(); if(count($quotaRecordInsertData) > 0) app()->make(MerchantQuotaRecordRepository::class)->insertAll($quotaRecordInsertData); } - - if(count($bills) > 0){ app()->make(UserBillRepository::class)->insertAll($bills); } - $storeOrderStatusRepository->batchCreateLog($orderStatus); $storeOrderProductRepository->insertAll($orderProduct); event('order.create',compact('groupOrder')); + + + // debug("结束"); return $groupOrder; }); foreach($merchantCartList as $merchantCart){ diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 6f19621..efd5204 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2632,6 +2632,9 @@ class ProductRepository extends BaseRepository }) ->when(isset($search['brand_id']) && $search['brand_id'] !== '', function ($query) use ($search) { $query->where('Product.brand_id', $search['brand_id']); + }) + ->when(isset($search['merchant_sub_type']) && $search['merchant_sub_type'] !== '', function ($query) use ($search) { + $query->where('Merchant.merchant_sub_type', $search['merchant_sub_type']); }); // 查询内容 $field = [ diff --git a/app/controller/api/Wine.php b/app/controller/api/Wine.php index 9cdbdcf..631cc74 100644 --- a/app/controller/api/Wine.php +++ b/app/controller/api/Wine.php @@ -27,10 +27,12 @@ class Wine extends BaseController{ * @return mixed */ public function merList(){ + $merchantSubType = $this->request->param('merchant_sub_type', 1); // 商户类别:0=普通商户,1=酒道馆,2=供应商 $where['merchant_type'] = 1; $where['mer_state'] = 1; $where['status'] = 1; + $where['merchant_sub_type'] = $merchantSubType ?? 1; $list = app()->make(MerchantRepository::class) ->search($where) @@ -48,7 +50,7 @@ class Wine extends BaseController{ */ public function goodsList(){ // 参数获取 - $search = $this->request->params(['store_name','lat','lng','brand_id','store_category_id','mer_id']); + $search = $this->request->params(['store_name','lat','lng','brand_id','store_category_id','mer_id',['merchant_sub_type', 1]]); [$page, $limit] = $this->getPage(); $data = app()->make(ProductRepository::class)->getWineList($search, $page, $limit); @@ -63,15 +65,10 @@ class Wine extends BaseController{ public function cartList(){ // 参数获取 $uid = $this->request->uid(); - $list = (array)app()->make(StoreCartRepository::class) - ->getSearch([ - 'is_pay' => 0, - 'is_del' => 0, - 'is_new' => 0, - 'is_fail' => 0, - 'product_type' => 36, - 'uid' => $uid, - ]) + $params = $this->request->params(['merchant_sub_type', 1]); + $params['uid'] = $uid; + // 列表信息获取 + $list = app()->make(StoreCartRepository::class)->wineSearchModel($params) ->field(['cart_id','product_type','product_id','product_attr_unique','cart_num','is_batch','batch_num']) ->with([ 'productAttr' => function($query){ @@ -84,6 +81,7 @@ class Wine extends BaseController{ ->select() ->toArray(); + return app('json')->success($list); } /** @@ -95,15 +93,10 @@ class Wine extends BaseController{ public function cartIds(){ // 参数获取 $uid = $this->request->uid(); - $ids = (array)app()->make(StoreCartRepository::class) - ->getSearch([ - 'is_pay' => 0, - 'is_del' => 0, - 'is_new' => 0, - 'is_fail' => 0, - 'product_type' => 36, - 'uid' => $uid, - ])->column('cart_id'); + $params = $this->request->params(['merchant_sub_type', 1]); + $params['uid'] = $uid; + // 信息获取 + $ids = app()->make(StoreCartRepository::class)->wineSearchModel($params)->column('cart_id'); return app('json')->success($ids); } diff --git a/app/event.php b/app/event.php index fc900b7..b6ebac6 100644 --- a/app/event.php +++ b/app/event.php @@ -54,6 +54,10 @@ return [ 'pay_success_order' => [\crmeb\listens\pay\OrderPaySuccessListen::class], 'pay_success_presell' => [\crmeb\listens\pay\PresellPaySuccessListen::class], 'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class], + // 订单创建成功 + 'order.create' => [ + 'app\listener\exchangeQuota\OrderCreateEvent' + ], // 订单支付成功事件触发 'order.paySuccess' => [ // 赠送酒卡额度 diff --git a/app/listener/exchangeQuota/OrderCreateEvent.php b/app/listener/exchangeQuota/OrderCreateEvent.php new file mode 100644 index 0000000..ded2f43 --- /dev/null +++ b/app/listener/exchangeQuota/OrderCreateEvent.php @@ -0,0 +1,188 @@ +groupOrder = $params['groupOrder'] ?? []; + try{ + // 根据订单类型进行对应的处理 + switch((int)$this->groupOrder->activity_type){ + // 酒道馆和小酒馆兑换订单 + case 36:$this->quotaAndIntegralHandle();break; + } + + + + + }catch(\Exception $e){ + $data = [ + 'uid' => $this->groupOrder->uid, + 'group_order_id' => $this->groupOrder->group_order_id, + 'msg' => $e->getMessage() + ]; + Log::info('订单创建成功 - 错误: '.var_export($data,1)); + } + } + // 获取订单列表 + private function getOrderList($field = '*', $orderProductField = '*'){ + return app()->make(StoreOrderRepository::class) + ->getSearch(['group_order_id' => $this->groupOrder->group_order_id]) + ->field($field) + ->with([ + 'orderProduct' => function($query) use ($orderProductField){ + return $query->field($orderProductField)->with(['product'=>function($sql){ + $sql->field('product_id,wine_type')->bind(['wine_type']); + }]); + }, + 'merchant' => function($query){ + return $query->field('mer_id,mer_name,merchant_type,merchant_sub_type,shop_mer_id'); + }, + ]) + ->select() + ->toArray(); + } + // 酒道馆和小酒馆兑换订单生成前处理 + private function quotaAndIntegralHandle(){ + // 获取订单列表 + $orderField = 'order_id,group_order_id,uid,mer_id,quota_integral,quota_integral_price,quota_integral_diff,quota_integral_diff_money'; + $orderProductField = [ + 'uid', + 'order_product_id', + 'order_id', + 'product_id', + 'total_price', + 'exchange_integral', + 'exchange_integral_price', + 'wine_diff_money', + 'wine_diff_money_price', + 'quota_integral', + 'quota_integral_price', + 'quota_integral_diff', + 'quota_integral_diff_money' + ]; + $orderList = $this->getOrderList($orderField, $orderProductField); + // 用户持有酒水卡积分 + $userInfo = User::where('uid', $this->groupOrder->uid)->findOrEmpty(); + $holdQuotaInfo = app()->make(ExchangeQuotaRepository::class)->getHoldInfo($this->groupOrder->uid, 1);// 酒卡额度 + $holdWineQuotaInfo = app()->make(ExchangeQuotaRepository::class)->getHoldInfo($this->groupOrder->uid, 3);// 封坛酒额度 + // 循环处理 + $exchangeIntegralRecordData = []; + $exchangeQuotaRecordData = []; + foreach($orderList as $orderInfo){ + $merInfo = $orderInfo['merchant'] ?? []; + $quotaIntegralHoldInfo = app()->make(ExchangeQuotaRepository::class)->getHoldInfo($orderInfo['uid'], 5, $merInfo['shop_mer_id']); + // 循环订单商品 + foreach($orderInfo['orderProduct'] as $productInfo){ + if($merInfo['merchant_sub_type'] == 2 && $productInfo['quota_integral'] > 0){ + // 小酒馆 减少惠民积分 + $changeFront = (float)$quotaIntegralHoldInfo->surplus_quota; + $quotaIntegralHoldInfo->use_quota += (float)$productInfo['quota_integral'];// 总额度 + $quotaIntegralHoldInfo->surplus_quota -= (float)$productInfo['quota_integral'];// 剩余额度 + $exchangeQuotaRecordData[] = [ + 'uid' => $productInfo['uid'], + 'product_id' => $productInfo['product_id'], + 'order_id' => $productInfo['order_id'], + 'order_product_id' => $productInfo['order_product_id'], + 'change_type' => 0, + 'change_quantity' => (float)$productInfo['quota_integral'], + 'change_front' => $changeFront, + 'change_after' => (float)$quotaIntegralHoldInfo->surplus_quota, + 'mer_id' => $orderInfo['mer_id'], + 'remark' => '兑换商品减少', + 'quota_type' => 5, + 'source' => 2, + ]; + } + else if($merInfo['merchant_sub_type'] != 2 && $productInfo['exchange_integral'] > 0){ + // 酒道馆 减少酒水卡积分 + $integralChangeFront = (float)$userInfo->exchange_integral; + $userInfo->exchange_integral -= (float)$productInfo['exchange_integral']; + $userInfo->exchange_integral = $userInfo->exchange_integral > 0 ? $userInfo->exchange_integral : 0; + $exchangeIntegralRecordData[] = [ + 'uid' => $productInfo['uid'], + 'product_id' => $productInfo['product_id'], + 'order_id' => $productInfo['order_id'], + 'order_product_id' => $productInfo['order_product_id'], + 'change_type' => 0, + 'change_quantity' => (float)$productInfo['exchange_integral'], + 'change_front' => $integralChangeFront, + 'change_after' => (float)$userInfo->exchange_integral, + 'remark' => "兑换商品减少", + ]; + // 酒卡额度处理 酒类型:0=未知,1=瓶装酒,2=封坛酒 + $wineType = (int)$productInfo['wine_type'] ?? 1; + if($wineType == 1){ + // 瓶装酒额度变更 + $changeFront = (float)$holdQuotaInfo->surplus_quota; + $holdQuotaInfo->use_quota += (float)$productInfo['total_price']; + $holdQuotaInfo->surplus_quota -= (float)$productInfo['total_price']; + $exchangeQuotaRecordData[] = [ + 'uid' => $productInfo['uid'], + 'product_id' => $productInfo['product_id'], + 'order_id' => $productInfo['order_id'], + 'order_product_id' => $productInfo['order_product_id'], + 'change_type' => 0, + 'change_quantity' => (float)$productInfo['total_price'], + 'change_front' => $changeFront, + 'change_after' => (float)$quotaIntegralHoldInfo->surplus_quota, + 'mer_id' => $orderInfo['mer_id'], + 'remark' => '兑换商品减少', + 'quota_type' => 1, + 'source' => 2, + ]; + } + else if($wineType == 2){ + // 封坛酒额度变更 + $changeFront = (float)$holdWineQuotaInfo->surplus_quota; + $holdWineQuotaInfo->use_quota += (float)$productInfo['total_price']; + $holdWineQuotaInfo->surplus_quota -= (float)$productInfo['total_price']; + $exchangeQuotaRecordData[] = [ + 'uid' => $productInfo['uid'], + 'product_id' => $productInfo['product_id'], + 'order_id' => $productInfo['order_id'], + 'order_product_id' => $productInfo['order_product_id'], + 'change_type' => 0, + 'change_quantity' => (float)$productInfo['total_price'], + 'change_front' => $changeFront, + 'change_after' => (float)$quotaIntegralHoldInfo->surplus_quota, + 'mer_id' => $orderInfo['mer_id'], + 'remark' => '兑换商品减少', + 'quota_type' => 3, + 'source' => 2, + ]; + } + } + } + + $quotaIntegralHoldInfo->save(); + } + // 保存用户修改 + $userInfo->save(); + $holdQuotaInfo->save(); + $holdWineQuotaInfo->save(); + if(count($exchangeIntegralRecordData) > 0) ExchangeIntegralRecord::insertAll($exchangeIntegralRecordData); + if(count($exchangeQuotaRecordData) > 0) ExchangeQuotaRecord::insertAll($exchangeQuotaRecordData); + + return true; + } + + + + + + + + + +} \ No newline at end of file diff --git a/app/listener/exchangeQuota/OrderPaySuccessEvent.php b/app/listener/exchangeQuota/OrderPaySuccessEvent.php index 2a1b29e..9248b2c 100644 --- a/app/listener/exchangeQuota/OrderPaySuccessEvent.php +++ b/app/listener/exchangeQuota/OrderPaySuccessEvent.php @@ -28,61 +28,52 @@ class OrderPaySuccessEvent{ public function handle($groupOrder){ $groupOrder = $groupOrder['groupOrder']; + // Log::info('支付成功 - 赠送酒卡额度 - 开始: '.var_export([ + // 'uid' => $groupOrder->uid, + // 'group_order_id' => $groupOrder->group_order_id, + // 'activity_type' => $groupOrder->activity_type + // ],1)); try{ - // Log::info('支付成功 - 赠送酒卡额度 - 开始: '.var_export([ - // 'uid' => $groupOrder->uid, - // 'group_order_id' => $groupOrder->group_order_id, - // 'activity_type' => $groupOrder->activity_type - // ],1)); - if($groupOrder->activity_type == 30){ + // 根据订单类型进行对应的处理 + switch((int)$groupOrder->activity_type){ // 在线支付订单 - $this->giveExchangeIntegral($groupOrder); - } - else if($groupOrder->activity_type == 31){ + case 30:$this->giveExchangeIntegral($groupOrder);break; // 兑换商品补差价处理 - $this->exchangeGoodsHandle($groupOrder); - } - else if($groupOrder->activity_type == 32){ + case 31:$this->exchangeGoodsHandle($groupOrder);break; // 代理入驻支付 - $this->agentPaySuccessHandle($groupOrder); - } - else if($groupOrder->activity_type == 33){ + case 32:$this->agentPaySuccessHandle($groupOrder);break; // 加入活动支付成功 - $this->joinActivitySuccessHandle($groupOrder); - } - else if($groupOrder->activity_type == 34){ + case 33:$this->joinActivitySuccessHandle($groupOrder);break; // 邀请码激活 - $this->inviteCodeActivation($groupOrder); - } - else if($groupOrder->activity_type == 35){ + case 34:$this->inviteCodeActivation($groupOrder);break; // 进货订单 - - } - else if($groupOrder->activity_type == 37){ + case 35:break; + // 酒道馆和小酒馆兑换订单 + case 36:break; // 共创股东加入 - foreach($groupOrder->orderList as $orderInfo){ - $id = app()->make(MerchantShareholderRepository::class)->getSearch(['order_id'=>(int)$orderInfo->order_id])->value('id'); - if($id > 0) app()->make(MerchantShareholderRepository::class)->joinSuccess($id); - } - } - else if($groupOrder->activity_type == 38){ + case 37: + foreach($groupOrder->orderList as $orderInfo){ + $id = app()->make(MerchantShareholderRepository::class)->getSearch(['order_id'=>(int)$orderInfo->order_id])->value('id'); + if($id > 0) app()->make(MerchantShareholderRepository::class)->joinSuccess($id); + } + break; // 配送商缴费支付成功 - foreach($groupOrder->orderList as $orderInfo){ - AgentDelivery::update(['status' => 1],['order_id' => (int)$orderInfo->order_id]); - } - } - else{ + case 38: + foreach($groupOrder->orderList as $orderInfo){ + AgentDelivery::update(['status' => 1],['order_id' => (int)$orderInfo->order_id]); + } + break; // 其他订单 - $this->orderPaySuccessHandle($groupOrder); - // 订单支付成功 触发购买商品升级 - Queue::push(UserBrokerageLevelJob::class,[ - 'uid' => $groupOrder->uid, - 'type' => 'many_goods', - 'inc' => 0, - 'group_order_id' => $groupOrder->group_order_id - ]); + default: + $this->orderPaySuccessHandle($groupOrder); + // 订单支付成功 触发购买商品升级 + Queue::push(UserBrokerageLevelJob::class,[ + 'uid' => $groupOrder->uid, + 'type' => 'many_goods', + 'inc' => 0, + 'group_order_id' => $groupOrder->group_order_id + ]); } - }catch(\Exception $e){ $data = [ 'uid' => $groupOrder->uid,