...
|
...
|
@@ -38,7 +38,7 @@ use Endroid\QrCode\QrCode; |
|
|
*/
|
|
|
class User extends Api
|
|
|
{
|
|
|
protected $noNeedLogin = ['registerUser','agreementUser','registerCompany','agreementCompany','agreementPrivacy','login','resetpwd','exam','noLogin','problemList','problemInfo'];
|
|
|
protected $noNeedLogin = ['registerUser','agreementUser','registerCompany','agreementCompany','agreementPrivacy','login','thirdLogin','thirdBindMobile','resetpwd','exam','noLogin','problemList','problemInfo'];
|
|
|
protected $noNeedRight = ['*'];
|
|
|
|
|
|
public function _initialize()
|
...
|
...
|
@@ -321,11 +321,12 @@ class User extends Api |
|
|
'code':'1',
|
|
|
'msg':'返回成功',
|
|
|
"data": {
|
|
|
"bind_mobile": 是否已绑定手机号码0=否1=是,
|
|
|
"token": 用户token
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function userThird() {
|
|
|
public function thirdLogin() {
|
|
|
$param = $this->request->param();
|
|
|
$validate = new Validate([
|
|
|
'nickname' => 'require',
|
...
|
...
|
@@ -339,19 +340,21 @@ class User extends Api |
|
|
$this->error($validate->getError());
|
|
|
}
|
|
|
// 判断用户是否已绑定该openid
|
|
|
$bind_mobile = 0;
|
|
|
$time = time();
|
|
|
$ip = request()->ip();
|
|
|
$third = UserThird::where('openid',$param['openid'])->find();
|
|
|
Db::startTrans();
|
|
|
if($third) {
|
|
|
$user = \app\common\model\User::get($third['user_id']);
|
|
|
if($user){
|
|
|
Db::startTrans();
|
|
|
// 修改第三方信息
|
|
|
$result = UserThird::where('id',$third['id'])->update([
|
|
|
$result = $third->save([
|
|
|
'openname' => $param['nickname'],
|
|
|
'logintime'=>$time
|
|
|
]);
|
|
|
// 修改用户信息
|
|
|
$user = \app\common\model\User::get($third['user_id']);
|
|
|
if(!empty($param['nickname']) && empty($user['nickname'])){
|
|
|
if(empty($user['nickname'])){
|
|
|
$user->nickname = $param['nickname'];
|
|
|
}
|
|
|
if(!empty($param['avatar']) && (empty($user['image']) || stripos($user['image'], 'http') !== false)){
|
...
|
...
|
@@ -366,22 +369,17 @@ class User extends Api |
|
|
$results = $user->save();
|
|
|
// 登录
|
|
|
$login = $this->auth->direct($third['user_id']);
|
|
|
if(!$result || !$results || !$login) {
|
|
|
Db::rollback();
|
|
|
$this->error('授权登录失败');
|
|
|
}
|
|
|
Db::commit();
|
|
|
$bind_mobile = 1;
|
|
|
$token = $this->auth->getToken();
|
|
|
}
|
|
|
} else {
|
|
|
// 添加用户信息
|
|
|
$result = \app\common\model\User::create([
|
|
|
'nickname' => $param['nickname'],
|
|
|
'sex' => $param['gender'] == 2 ? 0 : $param['gender'],
|
|
|
'image' => $param['avatar'],
|
|
|
'status' => 'normal',
|
|
|
'jointime' => $time,
|
|
|
'joinip' => $ip,
|
|
|
'logintime' => $time,
|
|
|
'loginip' => $ip,
|
|
|
'prevtime' => $time
|
|
|
]);
|
|
|
// 添加第三方信息
|
|
|
$results = UserThird::create([
|
|
|
'user_id' => $result['id'],
|
|
|
$result = UserThird::create([
|
|
|
'openname' => $param['nickname'],
|
|
|
'platform' => 'wechat',
|
|
|
'openid' => $param['openid'],
|
...
|
...
|
@@ -390,15 +388,169 @@ class User extends Api |
|
|
'logintime' => $time,
|
|
|
'unionid' => $param['unionid'],
|
|
|
]);
|
|
|
// 登录
|
|
|
$login = $this->auth->direct($result['id']);
|
|
|
}
|
|
|
if(!$result || !$results || !$login) {
|
|
|
if(!$result) {
|
|
|
Db::rollback();
|
|
|
$this->error('授权登录失败');
|
|
|
}
|
|
|
}
|
|
|
Db::commit();
|
|
|
$this->success('成功',['token'=>$this->auth->getToken()]);
|
|
|
$this->success('成功',['bind_mobile'=>$bind_mobile,'token'=>empty($token)?'':$token]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 绑定手机号
|
|
|
* @ApiWeigh (91)
|
|
|
*
|
|
|
* @ApiTitle (第三方登录-绑定手机号)
|
|
|
* @ApiSummary (第三方登录-绑定手机号)
|
|
|
* @ApiMethod (POST)
|
|
|
*
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="mobile", type="integer", required=true, description="手机号码")
|
|
|
* @ApiParams (name="code", type="integer", required=true, description="验证码")
|
|
|
* @ApiParams (name="openid", type="integer", required=true, description="第三方登录返回的唯一识别数据")
|
|
|
* @ApiParams (name="nickname", type="integer", required=true, description="第三方账号昵称")
|
|
|
* @ApiParams (name="avatar", type="integer", required=false, description="第三方账号头像")
|
|
|
* @ApiParams (name="gender", type="integer", required=false, description="第三方性别")
|
|
|
*
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'返回成功',
|
|
|
"data": {
|
|
|
"token": 用户token,
|
|
|
"is_password": 是否设置密码(0,否;1,是)
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function thirdBindMobile() {
|
|
|
if($this->request->isPost()) {
|
|
|
$param = $this->request->param();
|
|
|
$validate = new Validate([
|
|
|
'mobile' => 'require',
|
|
|
'code' => 'require|number|length:4',
|
|
|
'openid' => 'require',
|
|
|
]);
|
|
|
$validate->message([
|
|
|
'mobile.require' => '请输入您的手机号!',
|
|
|
'code.require' => '请输入数字验证码!',
|
|
|
'code.number' => '请输入正确的数字验证码!',
|
|
|
'code.length' => '数字验证码长度错误!',
|
|
|
'openid.require' => '缺少参数openid!',
|
|
|
]);
|
|
|
if (!$validate->check($param)) {
|
|
|
$this->error($validate->getError());
|
|
|
}
|
|
|
if (!Sms::check($param['mobile'], $param['code'], 'bind')) {
|
|
|
$this->error(__('Captcha is incorrect'));
|
|
|
}
|
|
|
// 判断用户是否已绑定该openid
|
|
|
$third = UserThird::where('openid',$param['openid'])->find();
|
|
|
if($third) {
|
|
|
$user_model = new \app\common\model\User();
|
|
|
$user = $user_model->get($third['user_id']);
|
|
|
Db::startTrans();
|
|
|
if($user) {
|
|
|
$this->error('已绑定手机号');
|
|
|
}
|
|
|
// 判断是否存在该手机号
|
|
|
$user = $user_model->where('mobile',$param['mobile'])->find();
|
|
|
$ip = request()->ip();
|
|
|
$time = time();
|
|
|
if(!$user) {
|
|
|
$user_insert = [
|
|
|
'username' => $param['mobile'],
|
|
|
'nickname' => $param['nickname'],
|
|
|
'image' => empty($param['avatar']) ? '/assets/img/avatar.png' : $param['avatar'],
|
|
|
'sex' => isset($param['gender']) && $param['gender'] == 0 ? 2 : 1,
|
|
|
'mobile' => $param['mobile'],
|
|
|
'jointime' => $time,
|
|
|
'joinip' => $ip,
|
|
|
'logintime' => $time,
|
|
|
'loginip' => $ip,
|
|
|
'prevtime' => $time,
|
|
|
'status' => 'normal',
|
|
|
];
|
|
|
$results = $user_model->isUpdate(false)->save($user_insert);
|
|
|
$this->auth->direct($user_model['id']);
|
|
|
$is_password = 0;
|
|
|
} else {
|
|
|
// 判断手机号是否已经绑定第三方
|
|
|
$third_user_data = UserThird::where('user_id',$user['id'])
|
|
|
->where('platform','wechat')
|
|
|
->find();
|
|
|
if($third_user_data) {
|
|
|
Db::rollback();
|
|
|
$this->error('该手机号已绑定微信');
|
|
|
}
|
|
|
// 修改用户信息
|
|
|
if(empty($user['nickname'])){
|
|
|
$user->nickname = $param['nickname'];
|
|
|
}
|
|
|
if(!empty($param['avatar']) && (empty($user['image']) || stripos($user['image'], 'http') !== false)){
|
|
|
$user->image = $param['avatar'];
|
|
|
}
|
|
|
if(!empty($param['gender']) && !isset($user['sex'])){
|
|
|
$user->sex = $param['gender'] == 2 ? 0 : $param['gender'];
|
|
|
}
|
|
|
$user->loginip = $ip;
|
|
|
$user->logintime = $time;
|
|
|
$user->updatetime = $time;
|
|
|
$results = $user->save();
|
|
|
$this->auth->direct($user['id']);
|
|
|
$is_password = $user['password'] ? 1 : 0;
|
|
|
}
|
|
|
$result = $third->save([
|
|
|
'logintime' => $time,
|
|
|
'user_id' => $user['id'],
|
|
|
]);
|
|
|
if(!$result || !$results) {
|
|
|
Db::rollback();
|
|
|
$this->error('第三方绑定失败');
|
|
|
}
|
|
|
Db::commit();
|
|
|
// 生成token
|
|
|
$token = $this->auth->getToken();
|
|
|
$this->success('绑定成功',['token'=>$token,'is_password'=>$is_password]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 第三方登录-设置密码
|
|
|
* @ApiWeigh (91)
|
|
|
*
|
|
|
* @param string $password 密码
|
|
|
* @param string $confirm_password 确认密码
|
|
|
* @param string $mobile 手机号
|
|
|
* @param string $code 验证码
|
|
|
*/
|
|
|
public function thirdPassword()
|
|
|
{
|
|
|
$password = $this->request->request('password');
|
|
|
$confirm_password = $this->request->request('confirm_password');
|
|
|
$mobile = $this->request->request('mobile');
|
|
|
$code = $this->request->request('code');
|
|
|
if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
$this->error(__('Mobile is incorrect'));
|
|
|
}
|
|
|
if ($confirm_password != $password) {
|
|
|
$this->error(__('密码与确认密码不一致'));
|
|
|
}
|
|
|
$ret = Sms::check($mobile, $code, 'bind');
|
|
|
if (!$ret) {
|
|
|
$this->error(__('Captcha is incorrect'));
|
|
|
}
|
|
|
if ($this->auth->password) {
|
|
|
$this->error('已设置过密码');
|
|
|
}
|
|
|
$salt = Random::alnum();
|
|
|
$password = $this->auth->getEncryptPassword($password, $salt);
|
|
|
$user_model = new \app\common\model\User();
|
|
|
$result = $user_model->update(['id' => $this->auth->id, 'password' => $password, 'salt' => $salt]);
|
|
|
if (!$result) {
|
|
|
$this->error('密码设置失败');
|
|
|
}
|
|
|
$this->success('密码设置成功');
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -1240,6 +1392,11 @@ class User extends Api |
|
|
}
|
|
|
// 创建订单
|
|
|
$model->add($this->auth->getUser(), $order, $param['pay_type']);
|
|
|
// 零元直接支付成功
|
|
|
if($model['pay_price'] <= 0){
|
|
|
(new Notify)->notifyScoreZero($model['order_sn'],$model['pay_price'],$param['pay_type']);
|
|
|
$this->success('成功',[]);
|
|
|
}
|
|
|
//回调链接
|
|
|
$notifyurl = $this->request->root(true) . '/mobile/notify/notifyScore/paytype/' . $param['pay_type'];
|
|
|
$model['pay_price'] = 0.01; //测试金额
|
...
|
...
|
|