添加用户邀请码绑定功能

main
ztt 10 months ago
parent c14c817698
commit 4cd2ff17e8
  1. 3
      addons/shopro/controller/Index.php
  2. 11
      addons/shopro/controller/user/User.php
  3. 3
      addons/shopro/service/user/UserAuth.php
  4. 13
      application/common.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')) {

@ -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 {

@ -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);

@ -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;
}
}

Loading…
Cancel
Save