1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace app\api\controller;
- use app\common\validate\UserVali;
- use app\common\model\User;
- use app\common\model\UserWallet;
- use library\service\CaptchaService;
- use library\tools\Data;
- use think\Db;
- use EasyWeChat\Factory;
- use app\common\model\InviteInfo;
- use function AlibabaCloud\Client\value;
- /**
- * @title 用户登录
- * @controller Login
- */
- class Login extends Base
- {
- /**
- * @title 用户统一登录
- * @desc 用户登录
- * @author qc
- * @url /api/Login/unifiedLogin
- * @method POST
- * @tag 登录 授权
- * @param name:account_type type:int require:1 default:1 desc:账号类型1企业2个人
- * @param name:account type:int require:1 default:-- desc:账号
- * @param name:code type:int require:1 default:-- desc:验证码
- * @return name:token type:string default:-- desc:用户登录成功后的token值
- */
- public function unifiedLogin()
- {
- $code = input('post.code','');
- $account = input('post.account','');
- $account_type = input('post.account_type', 1);
- $ret_data = ['code' => 200, 'token' => ''];
- $msg = '登录成功';
- try {
- $check_code = $this->checkPhoneCode($account,$code);
- if(!$check_code) $this->exception('验证码错误');
- $this->updatePhoneCode($check_code);
- $where = [];
- $where[] = $account_type == 1 ? ['email','=',$account] : ['phone','=',$account];
- $user_info = User::where($where)->find();
- if(!$user_info) {
- $reg_data = [];
- $reg_data['account_type'] = $account_type;
- $account_type == 1 ? $reg_data['email'] = $account : $ret_data['phone'] = $account;
- $account_type == 1 ? $reg_data['name'] = 'G企业用户_'.explode(',',$account)[0] : 'G'. substr_replace($account,'****',3,4);
- $user_info = User::create($reg_data);
- }
- $ret_data['token'] = $this->createJwt($user_info->id);;
- }catch (\Exception $e){
- $ret_data['code'] = 201;
- $msg =$e->getMessage();
- }
- $ret_data['code'] == 200 ? $this->success($msg,$ret_data):$this->error($msg,$ret_data);
- }
- /**
- * @title 获取验证码
- * @desc 获取验证码
- * @author qc
- * @url /api/Login/getCaptcha
- * @method GET
- * @return name:image type:string default:-- desc:图片
- * @return name:uniqid type:string default:-- desc:uniqid
- */
- public function getCaptcha()
- {
- $image = CaptchaService::instance();
- $captcha = ['image' => $image->getData(), 'uniqid' => $image->getUniqid()];
- $this->success('生成验证码成功', $captcha);
- }
- }
|