| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\api\controller;
- use app\api\model\User as UserModel;
- use think\Exception;
- /**
- * 用户管理
- * Class User
- * @package app\api
- */
- class User extends Controller
- {
- /**
- * 用户自动登录
- * @return array
- * @throws \app\common\exception\BaseException
- * @throws \think\Exception
- * @throws \think\exception\DbException
- */
- public function login()
- {
- $model = new UserModel;
- return $this->renderSuccess([
- 'user_id' => $model->login($this->request->post()),
- 'token' => $model->getToken()
- ]);
- }
- /**
- * 当前用户详情
- * @return array
- * @throws \app\common\exception\BaseException
- * @throws \think\exception\DbException
- */
- public function detail()
- {
- // 当前用户信息
- $userInfo = $this->getUser();
- return $this->renderSuccess(compact('userInfo'));
- }
- /**
- * 设置支付密码
- * @return array
- * @throws \app\common\exception\BaseException
- * @throws \think\exception\DbException
- */
- public function setPayPassword()
- {
- try {
- $userInfo = $this->getUser();
- if(empty($userInfo)){
- throw new Exception('用户信息不存在或未登录');
- }
- $password = input('password','');
- if(\app\api\service\User::setPayPassword($userInfo['user_id'], $password)){
- return $this->renderSuccess([],'设置成功');
- }else{
- return $this->renderError('设置失败');
- }
- }catch (\Exception $exception){
- return $this->renderError($exception->getMessage()?:'设置失败');
- }
- }
- /**
- * 设置支付密码
- * @return array
- * @throws \app\common\exception\BaseException
- * @throws \think\exception\DbException
- */
- public function setProfile()
- {
- try {
- $userInfo = $this->getUser();
- if(empty($userInfo)){
- throw new Exception('用户信息不存在或未注册');
- }
- $post = input();
- if(\app\api\service\User::setProfile($userInfo['user_id'], $post)){
- return $this->renderSuccess([],$userInfo['status']==1? '设置成功':'设置成功,请耐心等候审核');
- }else{
- return $this->renderError('设置失败');
- }
- }catch (\Exception $exception){
- return $this->renderError($exception->getMessage()?:'设置失败');
- }
- }
- }
|