Browse Source

增加是否会员

ZxcZxc123 1 year ago
parent
commit
a1bea9b6ab
1 changed files with 24 additions and 48 deletions
  1. 24 48
      app/api/controller/order/StoreOrderController.php

+ 24 - 48
app/api/controller/order/StoreOrderController.php

@@ -2,6 +2,7 @@
 
 namespace app\api\controller\order;
 
+use Qiniu\Auth;
 use app\admin\model\system\{
     SystemAttachment, ShippingTemplates
 };
@@ -326,14 +327,14 @@ class StoreOrderController
                 if ($from == 'weixinh5') {
                     return app('json')->status('wechat_h5_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
                 } else {
-                    $this->set_parent($request);
+                    $this->set_parent($request->uid());
 
                     return app('json')->status('wechat_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
                 }
                 break;
             case 'yue':
                 if (StoreOrder::yuePay($order['order_id'], $request->uid())) {
-                    $this->set_parent($request);
+                    $this->set_parent($request->uid());
 
                     return app('json')->status('success', '余额支付成功');
                 } else {
@@ -358,63 +359,38 @@ class StoreOrderController
 
 
 
-    public function set_parent(Request $request)
+    public function set_parent($uid)
     {
-        $uid = $request->uid(); // 获取当前用户ID
-        $user = User2::getUserInfo($uid);
 
-        // 检查该用户是否已经设置了接点
+        // 获取用户信息
+        $user = User::getUserInfo($uid);
         if ($user['parent']) {
             return app('json')->fail('该用户已设置接点');
         }
-
-        // 检查该用户是否购买了会员商品
-        $isMemberProduct = StoreProduct::where('is_best', 1)->where('id', $user['product_id'])->find();
-        if (!$isMemberProduct) {
-            return app('json')->fail('该用户尚未购买会员商品');
+        if (!StoreOrder::where('uid', $uid)->where('store_order', 1)->where('paid', 1)->find()) {
+            return app('json')->fail('该用户尚未完成报单');
         }
 
-        // 检查ABC区是否已满
-        $aCount = User2::where('parent', $uid)->where('parent_area', 'A')->count();
-        $bCount = User2::where('parent', $uid)->where('parent_area', 'B')->count();
-        $cCount = User2::where('parent', $uid)->where('parent_area', 'C')->count();
-
-        if ($cCount > 0 || $aCount > 0 || $bCount > 0) {
-            return app('json')->fail('ABC区已满,无法进行自动绑定');
+        $product = StoreProduct::where('is_best', 1)->find();
+        if (!$product) {
+            return app('json')->fail('没有找到满足条件的商品');
         }
 
-        // 获取当前用户的上级用户
-        $spreadUser = User2::get($user['spread_uid']);
-
-        // 检查C区是否是自己直推的
-        if ($spreadUser && $spreadUser['uid'] === $uid) {
-            $parent = $uid;
-            $parent_area = 'C';
-        } else {
-            return app('json')->fail('C区必须是自己直推的');
-        }
-
-        // 查找A区和B区下级最少的区域
-        $aChildCount = User2::where('parent', $uid)->where('parent_area', 'A')->count();
-        $bChildCount = User2::where('parent', $uid)->where('parent_area', 'B')->count();
-
-        if ($aChildCount <= $bChildCount) {
-            $parent_area = 'A';
-        } else {
-            $parent_area = 'B';
+        $spreadUid = $user['spread_uid'];
+        if ($spreadUid) {
+            $spreadUser = User::where('uid', $spreadUid)->find();
+            if ($spreadUser) {
+                if ($spreadUser['C_count'] == 0) {
+                    User::where('uid', $spreadUid)->update(['C_count' => 1]);
+                    User::where('uid', $uid)->update(['parent' => $spreadUid]);
+                    return app('json')->success('设置成功');
+                } else {
+                    return app('json')->fail('目标C区已有下级');
+                }
+            }
         }
 
-        // 更新用户的接点和接点区域信息
-        User2::where('uid', $uid)->update(['parent' => $parent, 'parent_area' => $parent_area]);
-
-        // 设置用户的上级关系
-        $res = User2::setParentUser($uid, $parent, $parent_area);
-
-        if ($res) {
-            return app('json')->success('自动绑定ABC区成功');
-        } else {
-            return app('json')->fail('自动绑定ABC区失败');
-        }
+        return app('json')->fail('找不到满足条件的用户');
     }
 
     /**