소스 검색

会员升级

Kirin 1 개월 전
부모
커밋
69af9ffbc7

+ 49 - 27
app/controller/api/v1/order/StoreOrderController.php

@@ -14,6 +14,7 @@ use app\Request;
 use app\services\pay\PayServices;
 use app\services\other\ExpressServices;
 use app\services\product\branch\StoreBranchProductServices;
+use app\services\user\AwardIntegralServices;
 use app\services\user\UserAddressServices;
 use app\services\user\UserInvoiceServices;
 use app\services\user\UserServices;
@@ -197,7 +198,7 @@ class StoreOrderController
         $uid = (int)$request->uid();
         if ($checkOrder = $this->services->getOne(['unique' => $key, 'uid' => $uid, 'is_del' => 0], 'id,order_id'))
             return app('json')->status('extend_order', '订单已创建,请点击查看完成支付', ['orderId' => $checkOrder['order_id'], 'key' => $key]);
-        [$addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $collate_code_id, $bargainId, $newcomerId, $from, $shipping_type, $real_name, $phone, $storeId, $news, $invoice_id, $quitUrl, $discountId, $customForm] = $request->postMore([
+        [$addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $collate_code_id, $bargainId, $newcomerId, $from, $shipping_type, $real_name, $phone, $storeId, $news, $invoice_id, $quitUrl, $discountId, $customForm, $yue_pay] = $request->postMore([
             [['addressId', 'd'], 0],
             [['couponId', 'd'], 0],
             ['payType', ''],
@@ -219,6 +220,7 @@ class StoreOrderController
             ['quitUrl', ''],
             [['discountId', 'd'], 0],
             ['custom_form', []],
+            ['yue_pay', 0]
         ], true);
         $cartGroup = $this->services->getCacheOrderInfo($uid, $key);
         if (!$cartGroup) {
@@ -337,6 +339,9 @@ class StoreOrderController
             switch ($payType) {
                 case PayServices::WEIXIN_PAY:
                     if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
+                    if ($orderInfo['award_price'] <= $yue_pay) {
+                        return app('json')->fail('余额支付金额不能大于报单实际支付金额!');
+                    }
                     //支付金额为0
                     if (bcsub((string)$orderInfo['pay_price'], '0', 2) <= 0) {
                         //创建订单jspay支付
@@ -353,7 +358,7 @@ class StoreOrderController
                         if (!$from && $request->isApp()) {
                             $from = 'weixin';
                         }
-                        $info['jsConfig'] = $payServices->orderPay($orderInfo, $from);
+                        $info['jsConfig'] = $payServices->orderPay($orderInfo, $from, $yue_pay);
                         if ($from == 'weixinh5') {
                             return app('json')->status('wechat_h5_pay', '订单创建成功', $info);
                         } else {
@@ -362,6 +367,13 @@ class StoreOrderController
                     }
                     break;
                 case PayServices::YUE_PAY:
+                    $total_price = $order['award_price'];
+                    /** @var AwardIntegralServices $awardService */
+                    $awardService = app()->make(AwardIntegralServices::class);
+                    list($link_order, $reorder_count) = $awardService->checkReorder($uid, $total_price);
+                    if ($link_order && $reorder_count >= 2) {
+                        return app('json')->status('success', '复投建议使用其他支付或混合支付', ['link_id' => $link_order, 'reorder_count' => $reorder_count, 'order' => $info]);
+                    }
                     /** @var YuePayServices $yueServices */
                     $yueServices = app()->make(YuePayServices::class);
                     $pay = $yueServices->yueOrderPay($orderInfo, $uid);
@@ -385,6 +397,9 @@ class StoreOrderController
                     } else {
                         $quitUrl = $url . '?order_id=' . $orderInfo['order_id'];
                     }
+                    if ($orderInfo['award_price'] <= $yue_pay) {
+                        return app('json')->fail('余额支付金额不能大于报单实际支付金额!');
+                    }
                     //支付金额为0
                     if (bcsub((string)$orderInfo['pay_price'], '0', 2) <= 0) {
                         //创建订单jspay支付
@@ -398,7 +413,7 @@ class StoreOrderController
                     } else {
                         /** @var OrderPayServices $payServices */
                         $payServices = app()->make(OrderPayServices::class);
-                        $info['jsConfig'] = $payServices->alipayOrder($orderInfo, $quitUrl, $from == 'routine');
+                        $info['jsConfig'] = $payServices->alipayOrder($orderInfo, $quitUrl, $from == 'routine', $yue_pay);
                         $payKey = md5($orderInfo['order_id']);
                         CacheService::set($payKey, ['order_id' => $orderInfo['order_id'], 'other_pay_type' => false], 300);
                         $info['pay_key'] = $payKey;
@@ -466,11 +481,12 @@ class StoreOrderController
      */
     public function pay(Request $request, StorePinkServices $services, OrderPayServices $payServices, YuePayServices $yuePayServices)
     {
-        [$uni, $paytype, $from, $quitUrl] = $request->postMore([
+        [$uni, $paytype, $from, $quitUrl, $yue_pay] = $request->postMore([
             ['uni', ''],
             ['paytype', 'weixin'],
             ['from', 'weixin'],
-            ['quitUrl', '']
+            ['quitUrl', ''],
+            ['yue_pay', 0]
         ], true);
         if (!$uni) return app('json')->fail('参数错误!');
         $order = $this->services->getUserOrderDetail($uni, (int)$request->uid());
@@ -524,7 +540,10 @@ class StoreOrderController
         $order['pay_type'] = $paytype; //重新支付选择支付方式
         switch ($order['pay_type']) {
             case PayServices::WEIXIN_PAY:
-                $jsConfig = $payServices->orderPay($order->toArray(), $from);
+                if ($order['award_price'] <= $yue_pay) {
+                    return app('json')->fail('余额支付金额不能大于报单实际支付金额!');
+                }
+                $jsConfig = $payServices->orderPay($order->toArray(), $from, $yue_pay);
                 if ($from == 'weixinh5') {
                     return app('json')->status('wechat_h5_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
                 } elseif ($from == 'weixin' || $from == 'routine') {
@@ -537,8 +556,11 @@ class StoreOrderController
                 if (!$quitUrl && $from != 'routine') {
                     return app('json')->fail('请传入支付宝支付回调URL');
                 }
+                if ($order['award_price'] <= $yue_pay) {
+                    return app('json')->fail('余额支付金额不能大于报单实际支付金额!');
+                }
                 $isCode = $from == 'routine' || $from == 'pc';
-                $jsConfig = $payServices->alipayOrder($order->toArray(), $quitUrl, $isCode);
+                $jsConfig = $payServices->alipayOrder($order->toArray(), $quitUrl, $isCode, $yue_pay);
                 if ($isCode && !($jsConfig->invalid ?? false)) $jsConfig->invalid = time() + 60;
                 $payKey = md5($order['order_id']);
                 CacheService::set($payKey, ['order_id' => $order['order_id'], 'other_pay_type' => false], 300);
@@ -584,13 +606,13 @@ class StoreOrderController
         if (!isset($orderCache['order_id'])) {
             return app('json')->fail('该订单无法支付');
         }
-		$order_id = $orderCache['order_id'];
-		if (strpos($orderCache['order_id'], '_')) {
-			$orderArr = explode('_', $orderCache['order_id']);
-			if (count($orderArr) == 2) {
-				$order_id = $orderArr[1] ?? $order_id;
-			}
-		}
+        $order_id = $orderCache['order_id'];
+        if (strpos($orderCache['order_id'], '_')) {
+            $orderArr = explode('_', $orderCache['order_id']);
+            if (count($orderArr) == 2) {
+                $order_id = $orderArr[1] ?? $order_id;
+            }
+        }
         $payType = isset($orderCache['other_pay_type']) && $orderCache['other_pay_type'] == true;
         if ($payType) {
             $orderInfo = $services->getOne(['order_id' => $order_id, 'is_del' => 0, 'paid' => 0]);
@@ -779,19 +801,19 @@ class StoreOrderController
                 $orderData['write_day'] = ($start ? date('Y-m-d', $start) : '') . '/' . ($end ? date('Y-m-d', $end) : '');
             }
         }
-		// 判断是否开启小程序订单管理
-		$orderData['order_shipping_open'] = false;
-		if (sys_config('order_shipping_open', 0) && MiniProgram::isManaged() && $order['is_channel'] == 1 && $order['pay_type'] == 'weixin') {
-			// 判断是否存在子未收货子订单
-			if ($order['pid'] > 0) {
-				if ($this->services->checkSubOrderNotTake((int)$order['pid'], (int)$order['id'])) {
-					$orderData['order_shipping_open'] = true;
-				}
-			} else {
-				$orderData['order_shipping_open'] = true;
-			}
+        // 判断是否开启小程序订单管理
+        $orderData['order_shipping_open'] = false;
+        if (sys_config('order_shipping_open', 0) && MiniProgram::isManaged() && $order['is_channel'] == 1 && $order['pay_type'] == 'weixin') {
+            // 判断是否存在子未收货子订单
+            if ($order['pid'] > 0) {
+                if ($this->services->checkSubOrderNotTake((int)$order['pid'], (int)$order['id'])) {
+                    $orderData['order_shipping_open'] = true;
+                }
+            } else {
+                $orderData['order_shipping_open'] = true;
+            }
 
-		}
+        }
         return app('json')->successful('ok', $orderData);
     }
 
@@ -1265,7 +1287,7 @@ class StoreOrderController
     {
         if (!$id) return app('json')->fail('参数错误');
         $uid = $request->uid();
-        return app('json')->successful($services->userOrderWriteOffRecords(['oid'=>$id, 'uid'=>$uid]));
+        return app('json')->successful($services->userOrderWriteOffRecords(['oid' => $id, 'uid' => $uid]));
     }
 
 }

+ 1 - 1
app/jobs/integral/IntegralJob.php

@@ -51,7 +51,7 @@ class IntegralJob extends BaseJobs
                 if ($give_static_integral > 0) {
 //                $extract_sum = bcmul($total_price, $rate, 2);
                     $mark = '购买商品,获得参考分';
-                    $integral_info = $awardIntegralService->incIntegral($order['uid'], $give_static_integral, $total_price, $order['id'], $mark, 0, $order['pay_type']);
+                    $integral_info = $awardIntegralService->incIntegral($order['uid'], $give_static_integral, $total_price, $order['id'], $mark, 0, $order['pay_type'], $order['yue_pay']);
                 }
                 //添加奖池
 //                $lake_ratio = sys_config('lake_ratio', 0);

+ 13 - 4
app/services/pay/OrderPayServices.php

@@ -12,6 +12,7 @@
 namespace app\services\pay;
 
 
+use app\model\order\StoreOrder;
 use app\services\order\StoreOrderCartInfoServices;
 use app\services\wechat\WechatUserServices;
 use think\exception\ValidateException;
@@ -39,7 +40,7 @@ class OrderPayServices
      * @param array $orderInfo
      * @return array|string
      */
-    public function orderPay(array $orderInfo, string $payType)
+    public function orderPay(array $orderInfo, string $payType, $yue_pay_price = 0)
     {
         if ($orderInfo['paid']) {
             throw new ValidateException('订单已支付!');
@@ -47,6 +48,9 @@ class OrderPayServices
         if ($orderInfo['pay_price'] <= 0) {
             throw new ValidateException('该支付无需支付!');
         }
+        if ($orderInfo['pay_price'] - $yue_pay_price <= 0) {
+            throw new ValidateException('该支付无需支付!');
+        }
         $openid = '';
         if (!in_array($payType, ['weixinh5', 'pc', 'store']) && !request()->isApp()) {
             if ($payType === 'weixin') {
@@ -76,7 +80,8 @@ class OrderPayServices
         if (!$body) {
             throw new ValidateException('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
         }
-        return $this->payServices->pay($payType, $openid, $orderInfo['order_id'], $orderInfo['pay_price'], $successAction, $body);
+        StoreOrder::where('id', $orderInfo['id'])->update(['yue_pay' => $yue_pay_price]);
+        return $this->payServices->pay($payType, $openid, $orderInfo['order_id'], $orderInfo['pay_price'] - $yue_pay_price, $successAction, $body);
     }
 
     /**
@@ -85,7 +90,7 @@ class OrderPayServices
      * @param string $quitUrl
      * @return array|string
      */
-    public function alipayOrder(array $orderInfo, string $quitUrl, bool $isCode = false)
+    public function alipayOrder(array $orderInfo, string $quitUrl, bool $isCode = false, $yue_pay_price = 0)
     {
         if ($orderInfo['paid']) {
             throw new ValidateException('订单已支付!');
@@ -93,6 +98,9 @@ class OrderPayServices
         if ($orderInfo['pay_price'] <= 0) {
             throw new ValidateException('该支付无需支付!');
         }
+        if ($orderInfo['pay_price'] - $yue_pay_price <= 0) {
+            throw new ValidateException('该支付无需支付!');
+        }
         $site_name = sys_config('site_name');
         if (isset($orderInfo['member_type'])) {
             $body = substrUTf8($site_name . '--' . $orderInfo['member_type'], 30);
@@ -108,7 +116,8 @@ class OrderPayServices
         if (!$body) {
             throw new ValidateException('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
         }
-        return $this->payServices->pay('alipay', $quitUrl, $orderInfo['order_id'], $orderInfo['pay_price'], $successAction, $body, $isCode);
+        StoreOrder::where('id', $orderInfo['id'])->update(['yue_pay' => $yue_pay_price]);
+        return $this->payServices->pay('alipay', $quitUrl, $orderInfo['order_id'], $orderInfo['pay_price'] - $yue_pay_price, $successAction, $body, $isCode);
     }
 
     /**

+ 35 - 2
app/services/user/AwardIntegralServices.php

@@ -147,7 +147,7 @@ class AwardIntegralServices extends BaseServices
      * @param string $mark
      * @return \crmeb\basic\BaseModel|\think\Model
      */
-    public function incIntegral(int $uid, string $total, float $order_price, int $order_id = 0, string $mark = '', $add_time = 0, $pay_type = 'yue')
+    public function incIntegral(int $uid, string $total, float $order_price, int $order_id = 0, string $mark = '', $add_time = 0, $pay_type = 'yue', $yue_pay_price = 0)
     {
 //        $inc_integral = bcdiv($total, $price, 5);
         //计算释放天数
@@ -173,6 +173,16 @@ class AwardIntegralServices extends BaseServices
             if ($link_id > 0) $send_day = $last_order_send_day + $reorder_inc;
             else  $send_day = $last_order_send_day + $order_inc;
         }
+
+        $ratio = 10 * ($reorder_count - 1);
+        if ($ratio > 0) {
+            if ($ratio > 100) $ratio = 100;
+            $yue_limit = bcdiv(bcmul(bcsub('100', (string)$ratio), (string)$order_price), '100', 2);
+            if ($yue_pay_price > $yue_limit) {
+                $add_integral = $ratio;
+            }
+        }
+
         return $this->dao->save([
             'uid' => $uid,
             'num' => $total,
@@ -187,10 +197,29 @@ class AwardIntegralServices extends BaseServices
             'order_price' => $order_price,
             'add_time' => $add_time ?: time(),
             'status' => $total > 0 ? 0 : 1,
-            'send_time' => time()
+            'yue_pay' => $yue_pay_price,
+            'send_time' => time(),
+            'add_integral' => $add_integral ?? 0
         ]);
     }
 
+    public function checkReorder($uid, $order_price)
+    {
+        //寻找复投机会
+        $main_orders = $this->dao->search(['uid' => $uid, 'link_id' => 0, 'order_price_elt' => $order_price, 'valid' => 2])->order('id asc')->column('id');//满足复投条件的主单
+        $link_id = 0;
+        $reorder_count = 0;
+        foreach ($main_orders as $v) {
+            $can_reorder = $this->dao->search(['uid' => $uid, 'valid' => 1, 'link_id' => $v])->find();
+            if (!$can_reorder) {
+                $link_id = $v;
+                $reorder_count = ($this->dao->search(['uid' => $uid, 'link_id' => $v])->max('reorder_count')) + 1;
+                break;
+            }
+        }
+        return [$link_id, $reorder_count];
+    }
+
 
 //    public function incIntegralAdmin(int $uid, string $price, string $total, float $order_price, int $type, string $extract_sum, int $link_id = 0, string $mark = '', $add_time = 0)
 //    {
@@ -350,6 +379,10 @@ class AwardIntegralServices extends BaseServices
         $user = $userService->getUserInfo($uid);
         $reorder_set = sys_config('reorder_times', 2);
         $to_integral = sys_config('shop_integral_ratio');
+        $to_integral = bcadd((string)$to_integral, (string)$origin['add_integral'], 2);
+        if ($to_integral > 100) {
+            $to_integral = 100;
+        }
         $mark = '用户参考分' . ($system ? '出局' : '提取') . $num;
         $to_integral = bcdiv(bcmul((string)$num, (string)$to_integral), '100', 2);
         if ($to_integral > 0) {