Browse Source

增加是否会员

ZxcZxc123 1 year ago
parent
commit
50dde791ba

+ 102 - 50
app/api/controller/order/StoreOrderController.php

@@ -8,8 +8,7 @@ use app\admin\model\system\{
 use app\admin\model\user\User;
 use app\models\routine\RoutineFormId;
 use crmeb\repositories\OrderRepository;
-use app\models\store\{
-    StoreBargainUser,
+use app\models\store\{StoreBargainUser,
     StoreCart,
     StoreCoupon,
     StoreCouponIssue,
@@ -18,11 +17,12 @@ use app\models\store\{
     StoreOrderCartInfo,
     StoreOrderStatus,
     StorePink,
-    StoreProductReply
-};
+    StoreProduct,
+    StoreProductReply};
 use app\models\system\SystemStore;
 use app\models\user\UserAddress;
 use app\models\user\UserLevel;
+use app\models\user\User as User2;
 use app\Request;
 use crmeb\services\{
     CacheService,
@@ -283,87 +283,139 @@ class StoreOrderController
      */
     public function pay(Request $request)
     {
+        // 获取请求参数
         list($uni, $paytype, $from) = UtilService::postMore([
             ['uni', ''],
             ['paytype', 'weixin'],
             ['from', 'weixin']
         ], $request, true);
-        if (!$uni) return app('json')->fail('参数错误!');
+
+        // 根据订单号和用户ID获取订单信息
         $order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
-        if (!$order)
-            return app('json')->fail('订单不存在!');
-        if ($order['paid'])
-            return app('json')->fail('该订单已支付!');
-        if ($order['pink_id']) if (StorePink::isPinkStatus($order['pink_id']))
-            return app('json')->fail('该订单已失效!');
-
-        if ($from == 'weixin') {//0
-            if (in_array($order->is_channel, [1, 2]))
-                $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
-        }
-        if ($from == 'weixinh5') {//2
-            if (in_array($order->is_channel, [0, 1]))
-                $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
-        }
-        if ($from == 'routine') {//1
-            if (in_array($order->is_channel, [0, 2]))
-                $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
+
+        // 检查订单是否存在
+        if (!$order) return app('json')->fail('订单不存在!');
+
+        // 检查订单是否已支付
+        if ($order['paid']) return app('json')->fail('该订单已支付!');
+
+        // 检查订单是否失效
+        if ($order['pink_id'] && StorePink::isPinkStatus($order['pink_id'])) return app('json')->fail('该订单已失效!');
+
+        // 根据支付来源调整订单ID
+        if ($from == 'weixin' && in_array($order->is_channel, [1, 2])) {
+            $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
+        } elseif ($from == 'weixinh5' && in_array($order->is_channel, [0, 1])) {
+            $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
+        } elseif ($from == 'routine' && in_array($order->is_channel, [0, 2])) {
+            $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
         }
 
-        $order['pay_type'] = $paytype; //重新支付选择支付方式
+        // 重新设置支付方式
+        $order['pay_type'] = $paytype;
+
+        // 根据支付方式进行处理
         switch ($order['pay_type']) {
             case 'weixin':
                 try {
-                    if ($from == 'routine') {
-                        $jsConfig = OrderRepository::jsPay($order); //订单列表发起支付
-                    } else if ($from == 'weixinh5') {
-                        $jsConfig = OrderRepository::h5Pay($order);
-                    } else {
-                        $jsConfig = OrderRepository::wxPay($order);
-                    }
-
-                    $uid = $request->uid();
-                    $parent = ''; // 获取推荐人的逻辑,根据您的绑定规则来获取
-                    $parentArea = ''; // 获取推荐人的区域的逻辑,根据您的绑定规则来获取
-
-                    if ($parent) {
-                        // 根据推荐人的逻辑来判断是否需要绑定
-                        $user = User::where('uid', $uid)->first();
-                        if (!$user->parent) {
-                            // 更新用户表中的parent和parent_area字段
-                            User::where('uid', $uid)->update(['parent' => $parent, 'parent_area' => $parentArea]);
-                            // 调用User模型中的setParentUser()方法
-                            $user->setParentUser();
-                        }
-                    }
+                    $jsConfig = OrderRepository::jsPay($order);
                 } catch (\Exception $e) {
                     return app('json')->fail($e->getMessage());
                 }
+
                 if ($from == 'weixinh5') {
                     return app('json')->status('wechat_h5_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
                 } else {
+                    $this->set_parent($request);
+
                     return app('json')->status('wechat_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
                 }
                 break;
             case 'yue':
-                if (StoreOrder::yuePay($order['order_id'], $request->uid()))
+                if (StoreOrder::yuePay($order['order_id'], $request->uid())) {
+                    $this->set_parent($request);
+
                     return app('json')->status('success', '余额支付成功');
-                else {
+                } else {
                     $error = StoreOrder::getErrorInfo();
                     return app('json')->fail(is_array($error) && isset($error['msg']) ? $error['msg'] : $error);
                 }
                 break;
             case 'offline':
                 StoreOrder::createOrderTemplate($order);
-                if (StoreOrder::setOrderTypePayOffline($order['order_id']))
+                if (StoreOrder::setOrderTypePayOffline($order['order_id'])) {
                     return app('json')->status('success', '订单创建成功');
-                else
+                } else {
                     return app('json')->status('success', '支付失败');
+                }
                 break;
         }
+
         return app('json')->fail('支付方式错误');
     }
 
+
+
+
+
+    public function set_parent(Request $request)
+    {
+        $uid = $request->uid(); // 获取当前用户ID
+        $user = User::getUserInfo($uid);
+
+        // 检查该用户是否是当前用户的下级
+        if ($user['spread_uid'] != $uid) return app('json')->fail('该用户并非你的下级');
+
+        // 检查该用户是否已经设置了接点
+        if ($user['parent']) return app('json')->fail('该用户已设置接点');
+
+        // 检查该用户是否已完成报单
+        $storeOrder = StoreOrder::where('uid', $uid)->where('store_order', 1)->where('paid', 1)->find();
+        if (!$storeOrder) return app('json')->fail('该用户尚未完成报单');
+
+        // 检查该用户是否购买了会员商品
+        $isMemberProduct = StoreProduct::where('is_best', 1)->where('id', $user['product_id'])->find();
+        if (!$isMemberProduct) return app('json')->fail('该用户尚未购买会员商品');
+
+        // 根据当前用户的AB区情况选择合适的接点和接点区域
+        $parent = 0;
+        $parent_area = '';
+
+        if ($request->user()['A_count'] == 0) {
+            $parent = $uid; // 接点为当前用户自己
+            $parent_area = 'A';
+        } elseif ($request->user()['B_count'] == 0) {
+            $parent = $uid; // 接点为当前用户自己
+            $parent_area = 'B';
+        } elseif ($request->user()['C_count'] == 0) {
+            // 查找当前用户A区和B区下级最少的区域
+            $aCount = User2::where('parent', $uid)->where('parent_area', 'A')->count();
+            $bCount = User2::where('parent', $uid)->where('parent_area', 'B')->count();
+
+            if ($aCount <= $bCount) {
+                $parent = $uid; // 接点为当前用户自己
+                $parent_area = 'A';
+            } else {
+                $parent = $uid; // 接点为当前用户自己
+                $parent_area = 'B';
+            }
+        } else {
+            return app('json')->fail('当前用户的ABC区已满');
+        }
+
+        // 更新用户的接点和接点区域信息
+        User2::where('uid', $uid)->update(['parent' => $parent, 'parent_area' => $parent_area]);
+
+        // 设置用户的上级关系
+        $res = User2::setParentUser($uid, $parent, $parent_area);
+
+        if ($res) {
+            return app('json')->success('设置成功');
+        } else {
+            return app('json')->fail(User2::getErrorInfo('设置失败'));
+        }
+    }
+
     /**
      * 订单列表
      * @param Request $request

+ 63 - 66
app/api/controller/user/UserController.php

@@ -3,6 +3,7 @@
 namespace app\api\controller\user;
 
 use app\http\validates\user\AddressValidate;
+use app\models\store\StoreProduct;
 use app\models\system\SystemCity;
 use app\models\user\UserVisit;
 use think\db\exception\DataNotFoundException;
@@ -616,72 +617,68 @@ class UserController
 
 
 
-    /**
-     * @param Request $request
-     * @return mixed
-     * @throws DataNotFoundException
-     * @throws DbException
-     * @throws ModelNotFoundException
-     */
-    public function set_parent(Request $request)
-    {
-        list($parent, $parent_area, $uid) = UtilService::postMore([
-            ['parent', 0],
-            ['parent_area'],
-            ['uid']
-        ], $request, true);
-        $user = User::getUserInfo($uid);
-        if ($user['spread_uid'] != $request->uid()) return app('json')->fail('该用户并非你的下级');
-        if ($user['parent']) return app('json')->fail('该用户已设置接点');
-        if (!StoreOrder::where('uid', $uid)->where('store_order', 1)->where('paid', 1)->find()) return app('json')->fail('该用户尚未完成报单');
-        if (!($request->user()['A_count'] && $request->user()['B_count'])) {
-            if ($parent == $request->uid()) {
-                if ($parent_area == 'C') {
-                    return app('json')->fail('请先在A区和B区报单');
-                }
-                if ($request->user()[$parent_area . '_count'] > 0) {
-                    return app('json')->fail('该区已存在用户,请选择其他区');
-                }
-            } else {
-                return app('json')->fail('请先选择自己的AB区进行报单');
-            }
-        }
-
-        if (!$parent || !$parent_area) return app('json')->fail('请设置接点');
-        $user_info = User::get($parent);
-        if ($parent_area == 'C') {
-            if ($user_info['parent'] != $request->uid()) {
-                return app('json')->fail('C区必须是自己直推的');
-            }
-            if ($user_info['C_count'] > 0) {
-                return app('json')->fail('C区已存在用户');
-            }
-        }
-        if ($user_info['A_count'] >= 1 && $user_info['B_count'] >= 1) {
-            $parent = $user_info['uid'];
-            $parent_area = 'C';
-        } elseif ($user_info['A_count'] == 0) {
-            $parent_area = 'A';
-        } elseif ($user_info['B_count'] == 0) {
-            $parent_area = 'B';
-        }
-
-        BaseModel::beginTrans();
-        try {
-            User::where('uid', $uid)->update(['parent' => $parent, 'parent_area' => $parent_area]);
-            $res = User::setParentUser($uid, $parent, $parent_area);
-            if ($res) {
-                BaseModel::commitTrans();
-                return app('json')->success('设置成功');
-            } else {
-                BaseModel::rollbackTrans();
-                return app('json')->fail(User::getErrorInfo('设置失败'));
-            }
-        } catch (\Exception $e) {
-            BaseModel::rollbackTrans();
-            return app('json')->fail('设置失败' . $e->getMessage());
-        }
-    }
+//    /**
+//     * @param Request $request
+//     * @return mixed
+//     * @throws DataNotFoundException
+//     * @throws DbException
+//     * @throws ModelNotFoundException
+//     */
+//    public function set_parent(Request $request)
+//    {
+//        list($parent, $parent_area, $uid) = UtilService::postMore([
+//            ['parent', 0],
+//            ['parent_area'],
+//            ['uid']
+//        ], $request, true);
+//        $user = User::getUserInfo($uid);
+//        if ($user['spread_uid'] != $request->uid()) return app('json')->fail('该用户并非你的下级');
+//        if ($user['parent']) return app('json')->fail('该用户已设置接点');
+//        if (!StoreOrder::where('uid', $uid)->where('store_order', 1)->where('paid', 1)->find()) return app('json')->fail('该用户尚未完成报单');
+//
+//        $isMemberProduct = StoreProduct::where('is_best', 1)->where('id', $user['product_id'])->find();
+//        if (!$isMemberProduct) return app('json')->fail('该用户尚未购买会员商品');
+//
+//
+//        $aCount = User::where('parent', $parent)->where('parent_area', 'A')->count();
+//        $bCount = User::where('parent', $parent)->where('parent_area', 'B')->count();
+//        $cCount = User::where('parent', $parent)->where('parent_area', 'C')->count();
+//
+//        if ($parent_area == 'C') {
+//            if ($parent != $request->uid()) {
+//                return app('json')->fail('C区必须是自己直推的');
+//            }
+//            if ($cCount > 0) {
+//                return app('json')->fail('C区已存在下级');
+//            }
+//            if ($aCount == 0 || $bCount == 0) {
+//                return app('json')->fail('AB区未满');
+//            }
+//        } else {
+//            if ($aCount > 0 && $bCount > 0) {
+//                return app('json')->fail('AB区已满');
+//            }
+//            if ($cCount > 0) {
+//                return app('json')->fail('C区下级已满');
+//            }
+//        }
+//
+//        BaseModel::beginTrans();
+//        try {
+//            User::where('uid', $uid)->update(['parent' => $parent, 'parent_area' => $parent_area]);
+//            $res = User::setParentUser($uid, $parent, $parent_area);
+//            if ($res) {
+//                BaseModel::commitTrans();
+//                return app('json')->success('设置成功');
+//            } else {
+//                BaseModel::rollbackTrans();
+//                return app('json')->fail(User::getErrorInfo('设置失败'));
+//            }
+//        } catch (\Exception $e) {
+//            BaseModel::rollbackTrans();
+//            return app('json')->fail('设置失败' . $e->getMessage());
+//        }
+//    }