Yahoo пре 4 година
родитељ
комит
77e8c81b69

+ 15 - 0
app/api/service/Setting.php

@@ -42,6 +42,8 @@ class Setting extends BaseService
         $data[SettingEnum::POINTS] = $this->getPoints();
         // 充值设置
         $data[SettingEnum::RECHARGE] = $this->getRecharge();
+        // 注册设置
+        $data[SettingEnum::REGISTER] = $this->getRegister();
         // 其他设置
         $data['_other'] = $this->getOtherSetting();
         return $data;
@@ -87,6 +89,19 @@ class Setting extends BaseService
         return helper::pick($values, ['is_entrance', 'is_custom', 'describe']);
     }
 
+    /**
+     * 注册设置 (默认登录方式、是否开启微信小程序授权登录)
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    private function getRegister(): array
+    {
+        $values = SettingModel::getItem(SettingEnum::REGISTER);
+        return helper::pick($values, ['registerMethod', 'isOauthMpweixin', 'isManualBind']);
+    }
+
     /**
      * 获取分类页模板设置
      * @return array|mixed

+ 10 - 31
app/api/service/passport/Login.php

@@ -14,7 +14,7 @@ namespace app\api\service\passport;
 
 use think\facade\Cache;
 use yiovo\captcha\facade\CaptchaApi;
-use app\api\model\{User as UserModel, Setting as SettingModel, dealer\Referee as RefereeModel};
+use app\api\model\{User as UserModel, Setting as SettingModel};
 use app\api\service\{user\Oauth as OauthService, user\Avatar as AvatarService, passport\Party as PartyService};
 use app\api\validate\passport\Login as ValidateLogin;
 use app\common\service\BaseService;
@@ -28,7 +28,10 @@ use cores\exception\BaseException;
  */
 class Login extends BaseService
 {
-    // 用户信息 (登录成功后才记录)
+    /**
+     * 用户信息 (登录成功后才记录)
+     * @var UserModel|null $userInfo
+     */
     private $userInfo;
 
     // 用于生成token的自定义盐
@@ -77,7 +80,7 @@ class Login extends BaseService
         $userInfo = !empty($userId) ? UserModel::detail($userId) : null;
 
         // 用户信息存在, 更新登录信息
-        if (!empty($userInfo)) {
+        if (!empty($userInfo) && $userInfo instanceof UserModel) {
             // 更新用户登录信息
             $this->updateUser($userInfo, true, $form['partyData']);
             // 记录登录态
@@ -92,10 +95,8 @@ class Login extends BaseService
         }
         // 后台设置了强制绑定手机号, 直接保存新用户
         if (!$setting['isForceBindMpweixin']) {
-            // 推荐人ID
-            $refereeId = $form['refereeId'] ?? null;
             // 用户不存在: 创建一个新用户
-            $this->createUser('', true, $form['partyData'], (int)$refereeId);
+            $this->createUser('', true, $form['partyData']);
             // 保存第三方用户信息
             $this->createUserOauth($this->getUserId(), true, $form['partyData']);
             return true;
@@ -124,7 +125,6 @@ class Login extends BaseService
             'mobile' => $wxData['purePhoneNumber'],
             'isParty' => $form['isParty'],
             'partyData' => $form['partyData'],
-            'refereeId' => $form['refereeId'] ?? null
         ];
         // 自动登录注册
         $this->register($loginData);
@@ -134,21 +134,6 @@ class Login extends BaseService
         return $this->setSession();
     }
 
-    /**
-     * 绑定推荐关系
-     * @param int $userId 当前用户ID
-     * @param int $refereeId 推荐人ID
-     * @return bool
-     * @throws \think\Exception
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
-     */
-    private function bindRelation(int $userId, int $refereeId): bool
-    {
-        return $refereeId > 0 && RefereeModel::createRelation($userId, $refereeId);
-    }
-
     /**
      * 保存oauth信息(第三方用户信息)
      * @param int $userId 用户ID
@@ -171,9 +156,8 @@ class Login extends BaseService
 
     /**
      * 当前登录的用户信息
-     * @return array
      */
-    public function getUserInfo(): array
+    public function getUserInfo(): ?UserModel
     {
         return $this->userInfo;
     }
@@ -204,10 +188,8 @@ class Login extends BaseService
         if ($userInfo) {
             return $this->updateUser($userInfo, $data['isParty'], $data['partyData']);
         }
-        // 推荐人ID
-        $refereeId = (int)$data['refereeId'] ?? null;
         // 用户不存在: 创建一个新用户
-        return $this->createUser($data['mobile'], $data['isParty'], $data['partyData'], $refereeId);
+        return $this->createUser($data['mobile'], $data['isParty'], $data['partyData']);
     }
 
     /**
@@ -215,14 +197,13 @@ class Login extends BaseService
      * @param string $mobile 手机号
      * @param bool $isParty 是否存在第三方用户信息
      * @param array $partyData 用户信息(第三方)
-     * @param int|null $refereeId 推荐人ID
      * @return bool
      * @throws \think\Exception
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    private function createUser(string $mobile, bool $isParty, array $partyData = [], ?int $refereeId = null): bool
+    private function createUser(string $mobile, bool $isParty, array $partyData = []): bool
     {
         // 用户信息
         $data = [
@@ -242,8 +223,6 @@ class Login extends BaseService
         $status = $model->save($data);
         // 记录用户信息
         $this->userInfo = $model;
-        // 记录推荐人关系
-        $this->bindRelation($this->getUserId(), (int)$refereeId);
         return $status;
     }
 

+ 13 - 7
app/common/enum/Setting.php

@@ -8,7 +8,7 @@
 // +----------------------------------------------------------------------
 // | Author: 萤火科技 <admin@yiovo.com>
 // +----------------------------------------------------------------------
-declare (strict_types = 1);
+declare (strict_types=1);
 
 namespace app\common\enum;
 
@@ -34,6 +34,9 @@ class Setting extends EnumBasics
     // 满额包邮设置
     const FULL_FREE = 'full_free';
 
+    // 账户注册设置
+    const REGISTER = 'register';
+
     // 充值设置
     const RECHARGE = 'recharge';
 
@@ -47,7 +50,7 @@ class Setting extends EnumBasics
      * 获取订单类型值
      * @return array
      */
-    public static function data()
+    public static function data(): array
     {
         return [
             self::DELIVERY => [
@@ -58,10 +61,10 @@ class Setting extends EnumBasics
                 'value' => self::TRADE,
                 'describe' => '交易设置',
             ],
-                self::SMS => [
-                    'value' => self::SMS,
-                    'describe' => '短信通知',
-                ],
+            self::SMS => [
+                'value' => self::SMS,
+                'describe' => '短信通知',
+            ],
             self::STORAGE => [
                 'value' => self::STORAGE,
                 'describe' => '上传设置',
@@ -70,6 +73,10 @@ class Setting extends EnumBasics
                 'value' => self::FULL_FREE,
                 'describe' => '满额包邮设置',
             ],
+            self::REGISTER => [
+                'value' => self::REGISTER,
+                'describe' => '账户注册设置',
+            ],
             self::RECHARGE => [
                 'value' => self::RECHARGE,
                 'describe' => '充值设置',
@@ -84,5 +91,4 @@ class Setting extends EnumBasics
             ],
         ];
     }
-
 }

+ 11 - 0
app/common/model/store/Setting.php

@@ -263,6 +263,17 @@ class Setting extends BaseModel
                     'describe' => ''            // 满额包邮说明
                 ],
             ],
+            // 账户注册设置
+            SettingEnum::REGISTER => [
+                'key' => SettingEnum::REGISTER,
+                'describe' => '账户注册设置',
+                'values' => [
+                    'registerMethod' => 10,   // 默认注册方式: 10=>手机号+短信验证码
+                    'isOauthMpweixin' => 1,   // 是否开启微信小程序一键授权登录
+                    'isForceBindMpweixin' => 1,   // 客户端是否强制绑定手机号(微信小程序)
+                    'isManualBind' => 1,   // 个人中心页显示手动绑定手机号
+                ],
+            ],
             // 用户充值设置
             SettingEnum::RECHARGE => [
                 'key' => SettingEnum::RECHARGE,