diff --git a/addons/shopro/controller/Index.php b/addons/shopro/controller/Index.php index 09423c3..1872f42 100755 --- a/addons/shopro/controller/Index.php +++ b/addons/shopro/controller/Index.php @@ -10,6 +10,7 @@ use app\admin\model\shopro\decorate\Page; use app\common\library\Sms as Smslib; use app\admin\model\shopro\user\User as UserModel; use addons\shopro\facade\Wechat; +use think\captcha\Captcha; use think\Hook; class Index extends Common @@ -177,7 +178,7 @@ class Index extends Common $auth = $userAuth->register(['mobile' => $mobile]); set_token_in_header($auth->getToken()); // set_token_in_header($auth->getToken()); -// $this->error(__('手机号未注册')); +// $this->error(__('手机号未注册')) } } if (!Hook::get('sms_send')) { diff --git a/addons/shopro/controller/user/User.php b/addons/shopro/controller/user/User.php index ea7d0a9..d76e8a0 100755 --- a/addons/shopro/controller/user/User.php +++ b/addons/shopro/controller/user/User.php @@ -135,7 +135,7 @@ class User extends Common $this->error('您已登录,不需要重新登录'); } - $params = $this->request->only(['mobile', 'code']); + $params = $this->request->only(['mobile', 'code', 'user_code']); $this->svalidate($params, '.smsLogin'); if (!Sms::check($params['mobile'], $params['code'], 'mobilelogin')) { $this->error(__('Captcha is incorrect')); @@ -145,6 +145,15 @@ class User extends Common if ($user->status != 'normal') { $this->error(__('Account is locked')); } + + //登录注册根据注册码绑定上级 + if (!empty($params['user_code'])) { + $parent_user_id = UserModel::where('user_code', $params['user_code'])->value('id'); + if (empty($parent_user_id)) { + $user->parent_user_id = $parent_user_id; + $user->save(); + } + } //如果已经有账号则直接登录 $ret = $this->auth->direct($user->id); }else { diff --git a/addons/shopro/service/user/UserAuth.php b/addons/shopro/service/user/UserAuth.php index a84f94f..a02829f 100755 --- a/addons/shopro/service/user/UserAuth.php +++ b/addons/shopro/service/user/UserAuth.php @@ -80,7 +80,8 @@ class UserAuth $extend = [ 'avatar' => !empty($params['avatar']) ? $params['avatar'] : $userDefaultConfig['avatar'], 'nickname' => !empty($params['nickname']) ? $params['nickname'] : $userDefaultConfig['nickname'] . $username, - 'group_id' => $userDefaultConfig['group_id'] ?? 1 + 'group_id' => $userDefaultConfig['group_id'] ?? 1, + 'user_code' => Random::alnum(8)//用户邀请码 ]; $ret = $this->auth->register($username, $password, $email, $mobile, $extend); diff --git a/application/common.php b/application/common.php index c47c368..2788fd4 100755 --- a/application/common.php +++ b/application/common.php @@ -570,3 +570,16 @@ function dd($data) { print_r($data); exit(); } + +if (!function_exists('get_code')) { + function get_code($len) { + $code = ''; + $length = $len; // 验证码长度 + $chars = '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY'; // 验证码字符集 + + for ($i = 0; $i < $length; $i++) { + $code .= $chars[mt_rand(0, strlen($chars) - 1)]; + } + return $code; + } +}