From d18e655e96a9d182c9e55ee109ffb8365ac28954 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Tue, 26 Mar 2024 17:08:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E4=B9=B0=E5=8D=95=20-=20=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E8=B1=86=E8=B1=86=E7=A7=AF=E5=88=86=E8=BF=9B=E8=A1=8C=E6=94=AF?= =?UTF-8?q?=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/StoreOrderCreateRepository.php | 6 +- .../store/order/StoreOrderRepository.php | 82 +++++++++++++++++-- 2 files changed, 78 insertions(+), 10 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index ff597c6..e329e42 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -1597,9 +1597,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository // 整理订单数据 $orderList[] = [ 'cartInfo' => [], - 'activity_type' => $activityType,// 30=在线买单;32=代理入驻;33=参加活动支付 + 'activity_type' => $activityType,// 30=在线买单; 'commission_rate' => 0, - 'order_type' => 0, + 'order_type' => $activityType, 'is_virtual' => 1, 'extension_one' => 0, 'extension_two' => 0, @@ -1652,6 +1652,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository 'give_integral' => 0, 'activity_type' => $activityType,// 30=在线买单;32=代理入驻;33=参加活动支付 ]; + + $group = Db::transaction(function() use ($user,$groupOrder,$orderList){ $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class); $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 22ea839..2b1b498 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -6,11 +6,13 @@ namespace app\common\repositories\store\order; use app\common\dao\store\order\StoreOrderDao; use app\common\model\store\order\StoreGroupOrder; use app\common\model\store\order\StoreOrder; +use app\common\model\store\platformCommission\LegumesLog; use app\common\model\user\User; use app\common\repositories\BaseRepository; use app\common\repositories\delivery\DeliveryOrderRepository; use app\common\repositories\store\coupon\StoreCouponRepository; use app\common\repositories\store\coupon\StoreCouponUserRepository; +use app\common\repositories\store\platformCommission\LegumesLogRepository; use app\common\repositories\store\product\ProductAssistSetRepository; use app\common\repositories\store\product\ProductAttrValueRepository; use app\common\repositories\store\product\ProductCopyRepository; @@ -67,9 +69,9 @@ use think\model\Relation; class StoreOrderRepository extends BaseRepository { /** - * 支付类型 0余额 1 微信 2 小程序 3 微信 4 支付宝 5 支付宝 6 微信 + * 支付类型 0=余额;1=微信;2=小程序;3=微信;4=支付宝;5=支付宝;6=微信;7=豆豆积分 */ - const PAY_TYPE = ['balance', 'weixin', 'routine', 'h5', 'alipay', 'alipayQr', 'weixinQr']; + const PAY_TYPE = ['balance', 'weixin', 'routine', 'h5', 'alipay', 'alipayQr', 'weixinQr', 'legumes_integral']; const PAY_TYPE_FILTEER = [ 0 => 0, 1 => '1,2,3,6', @@ -101,14 +103,15 @@ class StoreOrderRepository extends BaseRepository */ public function pay(string $type, User $user, StoreGroupOrder $groupOrder, $return_url = '', $isApp = false) { + // 判断:余额支付 || 豆豆积分支付 特殊处理 - if ($type === 'balance') { - return $this->payBalance($user, $groupOrder); - } + // debug($type); + if ($type === 'balance') return $this->payBalance($user, $groupOrder); + else if ($type === 'legumes_integral') return $this->payLegumesIntegral($user, $groupOrder); + + // 其他支付处理 + if (in_array($type, ['weixin', 'alipay'], true) && $isApp) $type .= 'App'; - if (in_array($type, ['weixin', 'alipay'], true) && $isApp) { - $type .= 'App'; - } event('order.pay.before', compact('groupOrder', 'type', 'isApp')); if (in_array($type, ['weixin', 'weixinApp', 'routine', 'h5', 'weixinQr'], true) && systemConfig('open_wx_combine')) { $service = new CombinePayService($type, $groupOrder->getCombinePayParams()); @@ -156,6 +159,69 @@ class StoreOrderRepository extends BaseRepository }); return app('json')->status('success', '余额支付成功', ['order_id' => $groupOrder['group_order_id']]); } + // 豆豆积分支付 + public function payLegumesIntegral(User $user, StoreGroupOrder $groupOrder){ + // 判断:用户豆豆积分是否可用 + $hold_legumes_integral = app()->make(LegumesLogRepository::class)->getHoldLegumesIntegral((int)$user['uid']); + if($hold_legumes_integral < $groupOrder['pay_price']) throw new ValidateException("积分不足,剩余{$hold_legumes_integral}可用积分"); + // 订单处理 + Db::transaction(function () use ($user, $groupOrder) { + $groupOrder->append(['orderList.orderProduct']); + foreach ($groupOrder->orderList as $orderKey => $orderInfo) { + // 获取订单信息 + if(!$orderInfo) continue; + $orderInfo = $orderInfo->toArray(); + $useLegumesIntegral = (float)$orderInfo['pay_price']; + // 查询需要使用的分配记录 + $useLegumesLogList = app()->make(LegumesLogRepository::class)->getUseList((int)$orderInfo['uid'],(float)$orderInfo['pay_price']); + // 循环处理 + $updateData = []; + foreach($useLegumesLogList as $logInfo){ + $useIntegral = $useLegumesIntegral >= $logInfo['surplus_integral'] ? (float)$logInfo['surplus_integral'] : (float)$useLegumesIntegral; + $useLegumesIntegral = (float)sprintf("%.2f",$useLegumesIntegral - $useIntegral); + $updateData[] = [ + 'id' => $logInfo['id'], + 'use_integral' => (float)sprintf("%.2f",$logInfo['use_integral'] + $useIntegral) + ]; + if($useLegumesIntegral <= 0) break; + } + // 修改成功信息 + if($updateData){ + LegumesLog::batchUpdate(array_values($updateData)); + // 获取用户可用豆豆积分 + $hold_legumes_integral = app()->make(LegumesLogRepository::class)->getHoldLegumesIntegral((int)$orderInfo['uid']); + // 添加用户账单信息变更记录 + if($orderInfo['order_type'] == 30) { + $title = '在线买单'; + $mark = '在线买单消耗'.$orderInfo['pay_price'].'积分'; + } + else { + $title = '购买商品'; + $mark = '购买商品使用'.$orderInfo['pay_price'].'积分抵扣'.floatval($orderInfo['pay_price']).'元'; + } + $bills[] = [ + 'uid' => $orderInfo['uid'], + 'link_id' => $orderInfo['order_id'], + 'pm' => 0, + 'title' => $title, + 'category' => 'integral', + 'type' => 'deduction', + 'number' => (float)$orderInfo['pay_price'], + 'balance' => $hold_legumes_integral, + 'mark' => $mark, + 'mer_id' => 0, + 'status' => 1 + ]; + app()->make(UserBillRepository::class)->insertAll($bills); + } + } + + $this->paySuccess($groupOrder); + }); + return app('json')->status('success', '积分支付成功', ['order_id' => $groupOrder['group_order_id']]); + } + + public function changePayType(StoreGroupOrder $groupOrder, int $pay_type) {