123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <?php
- namespace app\api\controller\company;
- use app\common\controller\Apic;
- use app\common\library\Sms;
- use fast\Random;
- use think\Config;
- use think\Validate;
- use think\Db;
- /**
- * 会员接口
- */
- class User extends Apic
- {
- protected $noNeedLogin = ['mobilelogin'];
- protected $noNeedRight = '*';
- public function _initialize()
- {
- parent::_initialize();
- }
- /**
- * 手机验证码登录
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function mobilelogin()
- {
- $mobile = $this->request->post('mobile');
- $captcha = $this->request->post('captcha');
- if (!$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error('请填写正确的手机号');
- }
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- //登录与注册
- $ret = false;
- $user = \app\common\model\Company::getByMobile($mobile);
- if ($user) {
- /*if ($user->status == 0) {
- $this->error(__('Account is locked'));
- }
- if ($user->status == 2) {
- $this->error('该用户已注销');
- }*/
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- } else {
- //找员工
- $userstaff = Db::name('company_staff')->where('mobile',$mobile)->find();
- if($userstaff)
- {
- $user = \app\common\model\Company::get($userstaff['company_id']);
- if($user)
- {
- $ret = $this->auth->direct($user->id);
- }
- }
- if($ret === false){
- // 用户信息不存在时使用
- $extend = [];
- $ret = $this->auth->register_mobile($mobile, Random::alnum(), '', $mobile, $extend);
- }
- }
- if ($ret) {
- Sms::flush($mobile, 'mobilelogin');
- $data = ['userinfo' => $this->getUserinfo('return')];
- $this->success('登录成功', $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 退出登录
- * @ApiMethod (POST)
- */
- public function logout()
- {
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
- $this->auth->logout();
- $this->success(__('Logout successful'));
- }
- //用户详细资料
- public function getUserinfo($type = 1){
- $info = $this->auth->getUserinfo();
- if($type == 'return'){
- return $info;
- }
- $this->success(__('success'),$info);
- }
- //用户申请资料
- public function getUserapplyinfo(){
- $field = [
- 'company_name',
- 'company_code',
- 'company_registerdate',
- 'company_address',
- 'company_image',
- 'truename',
- 'idcard',
- 'idcard_images',
- 'bank_name',
- 'bank_branchname',
- 'bank_account',
- 'bank_card',
- ];
- $info = Db::name('company')->field($field)->where('id',$this->auth->id)->find();
- $info = info_domain_image($info,['company_image','idcard_images']);
- $this->success(1,$info);
- }
- /**
- * 修改会员个人信息
- *
- * @ApiMethod (POST)
- * @param string $avatar 头像地址
- * @param string $username 用户名
- * @param string $nickname 昵称
- * @param string $bio 个人简介
- */
- public function profile()
- {
- //检查
- $check = Db::name('company')->where('id',$this->auth->id)->find();
- if($check['status'] == 1){
- $this->success('资料审核通过后需联系客服修改');
- }
- $field = [
- 'company_name',
- 'company_code',
- 'company_registerdate',
- 'company_address',
- 'company_image',
- 'truename',
- 'idcard',
- 'idcard_images',
- 'bank_name',
- 'bank_branchname',
- 'bank_account',
- 'bank_card',
- ];
- $data = request_post_hub($field);
- $data['status'] = 0;
- $update_rs = Db::name('company')->where('id',$this->auth->id)->update($data);
- $this->success('资料更新完成');
- }
- }
|