From 4032070510ad78789ca5a987c970a24c93e5ce2a Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Fri, 29 Dec 2023 19:17:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=85=91=E6=8D=A2=E5=90=8E=E5=87=8F=E5=B0=91?= =?UTF-8?q?=E8=B1=86=E8=B1=86=E7=A7=AF=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/PointsOrderCreateRepository.php | 113 ++++++++++-------- .../order/StoreOrderCreateRepository.php | 1 - 2 files changed, 63 insertions(+), 51 deletions(-) diff --git a/app/common/repositories/store/order/PointsOrderCreateRepository.php b/app/common/repositories/store/order/PointsOrderCreateRepository.php index 8457b3f..ef272c7 100644 --- a/app/common/repositories/store/order/PointsOrderCreateRepository.php +++ b/app/common/repositories/store/order/PointsOrderCreateRepository.php @@ -3,6 +3,7 @@ namespace app\common\repositories\store\order; use app\common\dao\store\order\StoreOrderDao; +use app\common\model\store\platformCommission\LegumesLog; use app\common\repositories\store\coupon\StoreCouponUserRepository; use app\common\repositories\store\product\ProductAssistSkuRepository; use app\common\repositories\store\product\ProductAttrValueRepository; @@ -15,8 +16,10 @@ use app\common\repositories\user\IntegralRepository; use app\common\repositories\user\UserAddressRepository; use app\common\repositories\user\UserBillRepository; use app\common\repositories\user\UserMerchantRepository; +use app\jobs\store\platformCommission\UseLegumesIntegralJob; use think\exception\ValidateException; use think\facade\Db; +use think\facade\Queue; class PointsOrderCreateRepository { @@ -147,8 +150,13 @@ class PointsOrderCreateRepository $cart['cost'] = $total_cost; } // 判断:当前商户积分是否充足 - $holdMerIntegral = app()->make(IntegralRepository::class)->getMerIntegral((int)$user->uid,(int)$merchantCart['mer_id']);// 用户持有的该商户积分总数 - if($holdMerIntegral < $total_integral) throw new ValidateException("积分不足,剩余{$holdMerIntegral}商户积分"); + // $holdMerIntegral = app()->make(IntegralRepository::class)->getMerIntegral((int)$user->uid,(int)$merchantCart['mer_id']);// 用户持有的该商户积分总数 + // if($holdMerIntegral < $total_integral) throw new ValidateException("积分不足,剩余{$holdMerIntegral}商户积分"); + $legumesModel = (new LegumesLog())->where('uid', (int)$user->uid)->where('status', 1); + $totalGetIntegral = $legumesModel->sum('get_integral');// 总获取积分 + $totalUseIntegral = $legumesModel->sum('use_integral');// 总已使用积分 + $hold_legumes_integral = (float)sprintf("%.2f",$totalGetIntegral - $totalUseIntegral);// 持有可使用积分 + if($hold_legumes_integral < $total_integral) throw new ValidateException("积分不足,剩余{$hold_legumes_integral}可用积分"); unset($cart); if (count($merchantCartList) > 1 || count($merchantCart['list']) > 1) { @@ -200,39 +208,40 @@ class PointsOrderCreateRepository foreach ($merchantCartList as $k => $merchantCart) { //整理订单数据 $_order = [ - 'cartInfo' => $merchantCart, - 'activity_type' => $order_type, - 'commission_rate' => 0, - 'order_type' => $order_type, - 'is_virtual' => $order_model, - 'extension_one' => $total_extension_one ?? 0, - 'extension_two' => $total_extension_two ?? 0, - 'order_sn' => $make->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER) . ($k + 1), - 'uid' => $user->uid, - 'spread_uid' => $spreadUid ?? 0, - 'top_uid' => $topUid ?? 0, - 'is_selfbuy' => $isSelfBuy ?? 0, - 'real_name' => $address['real_name'] ?? '', - 'user_phone' => $address['phone'] ?? '', - 'user_address' => $user_address, - 'cart_id' => implode(',', array_column($merchantCart['list'], 'cart_id')), - 'total_num' => $merchantCart['order']['total_num'], - 'total_price' => $merchantCart['order']['total_price'], - 'total_postage' => 0, - 'pay_postage' => 0, - 'svip_discount' => 0, - 'pay_price' => $merchantCart['order']['pay_price'], - 'integral' => $merchantCart['order']['total_integral'], - 'integral_price' => 0, - 'give_integral' => 0, - 'mer_id' => $merchantCart['mer_id'], - 'cost' => $merchantCart['order']['total_cost'], - 'order_extend' => count($extend) ? json_encode($extend, JSON_UNESCAPED_UNICODE) : '', - 'coupon_id' => '', - 'mark' => $mark, - 'coupon_price' => 0, + 'cartInfo' => $merchantCart, + 'activity_type' => $order_type, + 'commission_rate' => 0, + 'order_type' => $order_type, + 'is_virtual' => $order_model, + 'extension_one' => $total_extension_one ?? 0, + 'extension_two' => $total_extension_two ?? 0, + 'order_sn' => $make->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER).($k + 1), + 'uid' => $user->uid, + 'spread_uid' => $spreadUid ?? 0, + 'top_uid' => $topUid ?? 0, + 'is_selfbuy' => $isSelfBuy ?? 0, + 'real_name' => $address['real_name'] ?? '', + 'user_phone' => $address['phone'] ?? '', + 'user_address' => $user_address, + 'cart_id' => implode(',',array_column($merchantCart['list'],'cart_id')), + 'total_num' => $merchantCart['order']['total_num'], + 'total_price' => $merchantCart['order']['total_price'], + 'total_postage' => 0, + 'pay_postage' => 0, + 'svip_discount' => 0, + 'pay_price' => $merchantCart['order']['pay_price'], + 'integral' => $merchantCart['order']['total_integral'], + 'integral_price' => 0, + 'give_integral' => 0, + 'mer_id' => $merchantCart['mer_id'], + 'cost' => $merchantCart['order']['total_cost'], + 'order_extend' => count($extend) ? json_encode($extend,JSON_UNESCAPED_UNICODE) : '', + 'coupon_id' => '', + 'mark' => $mark, + 'coupon_price' => 0, 'platform_coupon_price' => 0, - 'pay_type' => $pay_type + 'pay_type' => $pay_type, + 'use_legumes_integral' => $merchantCart['order']['total_integral'], ]; $orderList[] = $_order; $totalCost = bcadd($totalCost, $_order['cost'], 2); @@ -335,23 +344,23 @@ class PointsOrderCreateRepository $groupOrder = $storeGroupOrderRepository->create($groupOrder); // 减少积分 if ($groupOrder['integral'] > 0) { - foreach ($_orderList as $k => $order) { - foreach ($order['cartInfo']['list'] as $cart) { - // 减少对应的商户积分 - app()->make(IntegralRepository::class)->changeIntegral((int)$user['uid'],(int)$cart->mer_id,(float)sprintf("%.2f",0 - (int)$cart->integral)); - } - } + // foreach ($_orderList as $k => $order) { + // foreach ($order['cartInfo']['list'] as $cart) { + // // 减少对应的商户积分 + // app()->make(IntegralRepository::class)->changeIntegral((int)$user['uid'],(int)$cart->mer_id,(float)sprintf("%.2f",0 - (int)$cart->integral)); + // } + // } // 减少总持有积分 - $user->integral = bcsub($user->integral, $groupOrder['integral'], 0); - $userBillRepository->decBill($user['uid'],'integral','points_order',[ - 'link_id' => $groupOrder['group_order_id'], - 'status' => 1, - 'title' => '积分商城兑换商品', - 'number' => $groupOrder['integral'], - 'mark' => '积分商城兑换商品使用商户积分'.floatval($groupOrder['integral']), - 'balance' => $user->integral - ]); - $user->save(); + // $user->integral = bcsub($user->integral, $groupOrder['integral'], 0); + // $userBillRepository->decBill($user['uid'],'integral','points_order',[ + // 'link_id' => $groupOrder['group_order_id'], + // 'status' => 1, + // 'title' => '积分商城兑换商品', + // 'number' => $groupOrder['integral'], + // 'mark' => '积分商城兑换商品使用商户积分'.floatval($groupOrder['integral']), + // 'balance' => $user->integral + // ]); + // $user->save(); } foreach ($_orderList as $k => $order) { @@ -408,6 +417,10 @@ class PointsOrderCreateRepository 'nickname' => $user->nickname, 'user_type' => $storeOrderStatusRepository::U_TYPE_USER, ]; + // 减少豆豆积分 + Queue::push(UseLegumesIntegralJob::class,[ + 'order_id' => $_order->order_id + ]); } $storeOrderStatusRepository->batchCreateLog($orderStatus); diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 680552e..5b5f72b 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -1439,7 +1439,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository // 修改:用户持有的豆豆积分 if((float)$order['use_legumes_integral'] > 0) { - // 推广员佣金结算 Queue::push(UseLegumesIntegralJob::class,[ 'order_id' => $_order->order_id ]);