Quellcode durchsuchen

小程序APP-用户登录-团队验证码校验:优化功能添加注释

xupuyuan vor 1 Jahr
Ursprung
Commit
44ac285bbe
1 geänderte Dateien mit 22 neuen und 20 gelöschten Zeilen
  1. 22 20
      app/controller/api/Auth.php

+ 22 - 20
app/controller/api/Auth.php

@@ -1464,30 +1464,32 @@ class Auth extends BaseController
1464 1464
 
1465 1465
         $domain = $this->request->domain();
1466 1466
 
1467
-        if (!$this->checkSmsCode($data['phone'], $data['sms_code'])) {
1468
-            if (($data['sms_code'] != '6865')) {
1469
-                $uid= Db::name('user')->where("phone", $data["phone"])->value('uid');
1470
-                if($uid){
1471
-                    $allTeams = Db::name('user_zero_line')->field('team_uid,custom_code')->select()->toArray();
1472
-                    $hasTeam = false;
1473
-                    foreach ($allTeams as $team) {
1474
-                        $sql = "select getUserLevelId({$team['team_uid']}) as uids";
1475
-                        $spread_user_list = Db::query($sql);
1476
-                        $member_uids = explode(",", trim($spread_user_list[0]['uids'], '$,'));
1477
-                        if (in_array($uid, $member_uids)){
1478
-                            $hasTeam = true;
1479
-                            if ($data['sms_code'] != $team['custom_code']) {
1480
-                                return app('json')->fail('验证码不正确');
1481
-                            }
1482
-                            break;
1467
+        //如果手机验证码错误并且验证码不是6865,进入查验团队验证码环节
1468
+        if (!$this->checkSmsCode($data['phone'], $data['sms_code']) && $data['sms_code'] !== '6865') {
1469
+            $uid= Db::name('user')->where("phone", $data["phone"])->value('uid');//通过输入的手机号查询用户的uid
1470
+            if($uid){
1471
+                $allTeams = Db::name('user_zero_line')->field('team_uid,custom_code')->select()->toArray();//去user_zero_line表查询团队team_uid和团队自定义的验证码
1472
+                $hasTeam = false;  //先将用户设成不为团队成员
1473
+                foreach ($allTeams as $team) {
1474
+                    $cacheKey = 'team_members_' . $team['team_uid'];
1475
+                    $member_uids = Cache::get($cacheKey);
1476
+                    $sql = "select getUserLevelId({$team['team_uid']}) as uids";  //查询所有团队下成员的uid
1477
+                    $spread_user_list = Db::query($sql);
1478
+                    $member_uids = explode(",", trim($spread_user_list[0]['uids'], '$,'));
1479
+                    Cache::set($cacheKey, $member_uids, 300);  //结果缓存5分钟
1480
+                    if (in_array($uid, $member_uids)){
1481
+                        $hasTeam = true;   //若用户属于团队,将其设为团队成员
1482
+                        if ($data['sms_code'] != $team['custom_code']) {
1483
+                            return app('json')->fail('验证码不正确');  //如果与用户所属团队的验证码不一致,返回验证码不正确
1483 1484
                         }
1485
+                        break;
1484 1486
                     }
1485
-                    if (!$hasTeam) {
1486
-                        return app('json')->fail('验证码不正确');
1487
-                    }
1488
-                } else {
1487
+                }
1488
+                if (!$hasTeam) {
1489 1489
                     return app('json')->fail('验证码不正确');
1490 1490
                 }
1491
+                } else {
1492
+                return app('json')->fail('验证码不正确');
1491 1493
             }
1492 1494
         }
1493 1495