1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- /**
- * Created by PhpStorm
- * User:林志杰
- * Email:[email protected]
- * Motto:纵有疾风起,人生不言弃!
- * Time:2020/2/8 23:12
- */
- namespace app\api\controller;
- use app\api\validate\User as UserValidate;
- use app\common\business\User as UserBusiness;
- class User extends AuthBase
- {
- public function index()
- {
- $user = (new UserBusiness)->getNormalUserById($this->userId);
- $resultUser = [
- 'id' => $this->userId,
- 'username' => $user['username'],
- 'sex' => $user['sex'],
- ];
- return show(config('status.success'), 'OK', $resultUser);
- }
- public function update()
- {
- $username = $this->request->param('username', '', 'trim');
- $sex = input('param.sex', 0, 'intval');
- //
- $data = [
- 'username' => $username,
- 'sex' => $sex,
- ];
- $validate = (new UserValidate)->scene('update_user');
- if (!$validate->check($data)) {
- return show(config('status.error'), $validate->getError());
- }
- $user = (new UserBusiness())->update($this->userId, $data);
- if (!$user) {
- return show(config('status.error'), '更新失败');
- }
- // 如果用户名被修改,Redis里面的数据也需要同步一下
- // todo
- return show(1, 'OK');
- }
- }
|