Browse Source

会员升级

Kirin 1 year ago
parent
commit
6945632035

+ 65 - 50
app/controller/admin/v1/user/User.php

@@ -15,6 +15,7 @@ use app\services\other\queue\QueueServices;
 use app\services\product\product\StoreProductLogServices;
 use app\services\user\group\UserGroupServices;
 use app\services\user\label\UserLabelServices;
+use app\services\user\level\UserLevelServices;
 use app\services\user\UserBatchProcessServices;
 use app\services\user\UserServices;
 use app\controller\admin\AuthController;
@@ -106,9 +107,9 @@ class User extends AuthController
     {
         $data = $this->request->post();
         if (!$data) {
-			return $this->fail('请提交要保存信息');
-		}
-		$this->services->saveExtendForm((int)$id, $data);
+            return $this->fail('请提交要保存信息');
+        }
+        $this->services->saveExtendForm((int)$id, $data);
         return $this->success('保存成功');
     }
 
@@ -153,7 +154,7 @@ class User extends AuthController
             ['street', 0],
             ['extend_info', []],
         ]);
-		$this->validate(['pwd' => $data['pwd']],  \app\validate\admin\user\UserValidate::class);
+        $this->validate(['pwd' => $data['pwd']], \app\validate\admin\user\UserValidate::class);
         if ($data['phone']) {
             if (!check_phone($data['phone'])) {
                 return $this->fail('手机号码格式不正确');
@@ -164,11 +165,11 @@ class User extends AuthController
             $data['nickname'] = substr_replace($data['phone'], '****', 3, 4);
         }
         if ($data['card_id']) {
-			try {
-				if (!check_card($data['card_id'])) return $this->fail('请输入正确的身份证');
- 			} catch (\Throwable $e) {
+            try {
+                if (!check_card($data['card_id'])) return $this->fail('请输入正确的身份证');
+            } catch (\Throwable $e) {
 //				return $this->fail('请输入正确的身份证');
- 			}
+            }
         }
         if ($data['birthday']) {
             if (strtotime($data['birthday']) > time()) return $this->fail('生日请选择今天之前日期');
@@ -205,7 +206,7 @@ class User extends AuthController
             $res = true;
             $userInfo = $this->services->save($data);
 
-			$res = $this->services->saveSetLabel([$userInfo->uid], $labels);
+            $res = $this->services->saveSetLabel([$userInfo->uid], $labels);
 
             if ($data['level']) {
                 $res = $this->services->saveGiveLevel((int)$userInfo->uid, (int)$data['level']);
@@ -277,11 +278,11 @@ class User extends AuthController
     public function save_give_level_time($id)
     {
         if (!$id) return $this->fail('缺少参数');
-		[$days_status, $days] = $this->request->postMore([
-			['days_status', 1],
-			['days', 0],
-		], true);
-		return $this->success($this->services->saveGiveLevelTime((int)$id, (int)$days, (int)$days_status) ? '赠送成功' : '赠送失败');
+        [$days_status, $days] = $this->request->postMore([
+            ['days_status', 1],
+            ['days', 0],
+        ], true);
+        return $this->success($this->services->saveGiveLevelTime((int)$id, (int)$days, (int)$days_status) ? '赠送成功' : '赠送失败');
     }
 
     /**
@@ -506,11 +507,11 @@ class User extends AuthController
             if (!check_phone($data['phone'])) return $this->fail('手机号码格式不正确');
         }
         if ($data['card_id']) {
-			try {
-				if (!check_card($data['card_id'])) return $this->fail('请输入正确的身份证');
- 			} catch (\Throwable $e) {
+            try {
+                if (!check_card($data['card_id'])) return $this->fail('请输入正确的身份证');
+            } catch (\Throwable $e) {
 //				return $this->fail('请输入正确的身份证');
- 			}
+            }
         }
         if ($data['birthday']) {
             if (strtotime($data['birthday']) > time()) return $this->fail('生日请选择今天之前日期');
@@ -522,10 +523,10 @@ class User extends AuthController
             if ($data['pwd'] != $data['true_pwd']) {
                 return $this->fail('两次输入的密码不一致');
             }
-			if ($data['pwd'] == '123456') {
-				return $this->fail('您设置的密码太过简单');
-			}
-			$this->validate(['pwd' => $data['pwd']],  \app\validate\admin\user\UserValidate::class);
+            if ($data['pwd'] == '123456') {
+                return $this->fail('您设置的密码太过简单');
+            }
+            $this->validate(['pwd' => $data['pwd']], \app\validate\admin\user\UserValidate::class);
             $data['pwd'] = md5($data['pwd']);
         } else {
             unset($data['pwd']);
@@ -552,10 +553,24 @@ class User extends AuthController
         $data['adminId'] = $this->adminId;
         $data['money'] = (string)$data['money'];
         $data['integration'] = (string)$data['integration'];
-		if ($data['extend_info']) {
-			$data['extend_info'] = $this->services->handelExtendInfo($data['extend_info']);
-		}
-        return $this->success($this->services->updateInfo((int)$id, $data) ? '修改成功' : '修改失败');
+        if ($data['extend_info']) {
+            $data['extend_info'] = $this->services->handelExtendInfo($data['extend_info']);
+        }
+        $res = $this->services->updateInfo((int)$id, $data);
+        if ($res) {
+            $userInfo = $this->services->get($id);
+            /** @var UserLevelServices $levelServices */
+            $levelServices = app()->make(UserLevelServices::class);
+            $levelServices->detection((int)$userInfo['uid']);
+            $pass = [$userInfo['uid']];
+            $spread = $this->services->getUserInfo($userInfo['spread_uid']);
+            while ($spread && !in_array($spread['uid'], $pass)) {
+                $levelServices->detection((int)$spread['uid']);
+                $pass[] = $spread['uid'];
+                $spread = $this->services->getUserInfo($spread['spread_uid']);
+            }
+        }
+        return $this->success($res ? '修改成功' : '修改失败');
     }
 
     /**
@@ -616,28 +631,28 @@ class User extends AuthController
         return app('json')->success($services->getSpreadList($where, '*', ['spreadUser', 'admin'], false));
     }
 
-	/**
-	 * 用户批量操作
-	 * @return mixed
-	 * @throws \think\db\exception\DataNotFoundException
-	 * @throws \think\db\exception\DbException
-	 * @throws \think\db\exception\ModelNotFoundException
-	 */
-	public function batchProcess(UserBatchProcessServices $batchProcessServices)
-	{
-		[$type, $uids, $all, $where, $data] = $this->request->postMore([
-			['type', 1],
-			['uids', ''],
-			['all', 0],
-			['where', ""],
-			['data', []]
-		], true);
-		if (!$uids && $all == 0) return $this->fail('请选择批处理用户');
-		if (!$data) {
-			return $this->fail('请选择批处理数据');
-		}
-		//批量操作
-		$batchProcessServices->batchProcess((int)$type, $uids, $data, !!$all, (array)$where);
-		return app('json')->success('已加入消息队列,请稍后查看');
-	}
+    /**
+     * 用户批量操作
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function batchProcess(UserBatchProcessServices $batchProcessServices)
+    {
+        [$type, $uids, $all, $where, $data] = $this->request->postMore([
+            ['type', 1],
+            ['uids', ''],
+            ['all', 0],
+            ['where', ""],
+            ['data', []]
+        ], true);
+        if (!$uids && $all == 0) return $this->fail('请选择批处理用户');
+        if (!$data) {
+            return $this->fail('请选择批处理数据');
+        }
+        //批量操作
+        $batchProcessServices->batchProcess((int)$type, $uids, $data, !!$all, (array)$where);
+        return app('json')->success('已加入消息队列,请稍后查看');
+    }
 }

+ 3 - 2
app/jobs/integral/IntegralJob.php

@@ -85,11 +85,12 @@ class IntegralJob extends BaseJobs
                     $give_action_integral = bcdiv(bcmul($award_price, $ratio), 100, 2);
                     if ($give_action_integral > $send) {
                         $real_send = bcsub($give_action_integral, $send, 2);
-                        if ($real_send < 0) $real_send = 0;
+//                        if ($awardIntegralService->getHourExtractPaySum($spread['uid'], 24) > 0) {
                         $extract_sum = bcmul($real_send, $rate, 2);
                         $mark = '团队用户' . $user['nickname'] . "({$user['uid']})" . '购买商品,获得团队级差积分';
                         $awardIntegralService->incIntegral($spread['uid'], $integral_price, $real_send, $total_price, 1, $extract_sum, $order['id'], $mark);
-                        if ($real_send > 0) $send = $give_action_integral;
+//                        }
+                        $send = $give_action_integral;
                     }
                     $levelServices->detection((int)$spread['uid']);
                     $pass[] = $spread['uid'];

+ 4 - 0
app/services/user/level/UserLevelServices.php

@@ -413,12 +413,16 @@ class UserLevelServices extends BaseServices
             if (!count($sub_user)) {
                 $num = 0;
             } else {
+//                if ($vipinfo['grade'] == 1) {
+//                    $num = count($sub_user);
+//                } else {
                 foreach ($sub_user as $v) {
                     $subUsers = $this->dao->getColumn([['grade', '>=', $vipinfo['grade'] - 1], ['status', '=', 1], ['is_del', '=', 0], ['uid', 'in', array_merge([$v], get_group_user($v))]], 'uid');
                     if (count(array_unique($subUsers)) > 0) {
                         $num++;
                     }
                 }
+//                }
             }
             if ($vipinfo['sub_grade_num'] > $num) {
                 break;