request->post('mobile'); $password = $this->request->post('password'); if (!$mobile || !$password) { $this->error(__('Invalid parameters')); } $ret = $this->auth->login($mobile, $password); if ($ret) { $data = $this->auth->getUserinfo(); $this->success(__('Logged in successful'), $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); } /** * 重置密码 * * @ApiMethod (POST) * @param string $mobile 手机号 * @param string $captcha 验证码 * @param string $newpassword 新密码 */ public function resetpwd() { $mobile = $this->request->post('mobile'); $captcha = $this->request->post('captcha'); $newpassword = $this->request->post("newpassword"); if (!$mobile || !$captcha || !$newpassword) { $this->error(__('Invalid parameters')); } //验证Token if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) { $this->error(__('Password must be 6 to 30 characters')); } if (!Validate::regex($mobile, "^1\d{10}$")) { $this->error(__('Mobile is incorrect')); } $user = \app\common\model\CompanyStaff::getByMobile($mobile); if (!$user) { $this->error(__('User not found')); } $ret = Sms::check($mobile, $captcha, 'resetpwd'); if (!$ret) { $this->error(__('Captcha is incorrect')); } Sms::flush($mobile, 'resetpwd'); //模拟一次登录 $this->auth->direct($user->id); $ret = $this->auth->resetpwd($newpassword, '', true); if ($ret) { $this->success(__('Reset password successful')); } else { $this->error($this->auth->getError()); } } /** * 修改会员个人信息 * * @ApiMethod (POST) * @param string $avatar 头像地址 * @param string $username 用户名 * @param string $nickname 昵称 * @param string $bio 个人简介 */ public function profile() { //验证 if($this->auth->type != 1){ $this->error('只有门店老板才能设置'); } $field = [ 'mobile', 'image', 'is_open', 'open_hours', ]; $data = request_post_hub($field); $data['updatetime'] = time(); $update_rs = Db::name('company')->where('id',$this->auth->company_id)->update($data); $this->success('资料更新完成'); } /** * 设置店铺地址 */ public function setaddress() { //验证 if($this->auth->type != 1){ $this->error('只有门店老板才能设置'); } $field = [ 'province_name', 'city_name', 'area_name', 'province_id', 'city_id', 'area_id', 'address', ]; $data = request_post_hub($field); $data['full_address'] = $data['province_name'].$data['city_name'].$data['area_name'].$data['address']; $data['updatetime'] = time(); $update_rs = Db::name('company')->where('id',$this->auth->company_id)->update($data); $this->success('资料更新完成'); } /** * 小程序码 * @return void */ public function getMiniCode() { try { $companyId = $this->auth->company_id; $companyWhere['id'] = $companyId; $companyWhere['status'] = 1; $company = Db::name('company')->where($companyWhere)->find(); if (empty($company)) { throw new Exception('未找到门店信息'); } $httpStr = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST']; if (empty($company['mini_code'])) { $client = new Client(); $tk = getAccessToken(); $res2 = $client->request('POST', 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$tk, [ 'json' => [ //'page' => 'pages/home/index', 'env_version'=>'trial', 'scene' => 'shopId='.$companyId, ] ]); $fileName = md5($companyId); $fileUrl = '/uploads/company/'.$fileName.'.png'; $code = $res2->getBody()->getContents(); file_put_contents(ROOT_PATH.'/public'.$fileUrl,$code); $companyData['mini_code'] = $fileUrl; $companyRes = Db::name('company')->where($companyWhere)->update($companyData); if (!$companyRes) { throw new Exception('更新门店信息失败'); } $miniCode = $httpStr.$fileUrl; } else { $miniCode = $httpStr.$company['mini_code']; } $result = [ 'mini_code' => $miniCode, 'company_name' => $this->auth->company->name, 'company_image' => one_domain_image($this->auth->company->image), ]; $this->success('获取成功',$result); } catch (Exception $e) { $this->error($e->getMessage()); } } }