12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- /**
- * @Created by PhpStorm
- * @author: Kirin
- * @day: 2024/12/16
- * @time: 10:43
- */
- namespace app\controller\api\user;
- use app\common\ApiBaseController;
- use app\Request;
- use app\services\user\UserLevelServices;
- use app\services\user\UserServices;
- use app\validate\api\LoginValidate;
- use think\exception\ValidateException;
- /**
- * 用户基本类
- * Class User
- * @package app\controller\api\user
- */
- class User extends ApiBaseController
- {
- public function __construct(Request $request, UserServices $services)
- {
- parent::__construct($request);
- $this->service = $services;
- }
- public function info()
- {
- //用户信息
- $user = $this->request->user();
- if (is_object($user)) $user = $user->toArray();
- /** @var UserLevelServices $levelService */
- $levelService = app()->make(UserLevelServices::class);
- //用户等级
- $level = $levelService->getUserLevelInfo($user['uid']);
- $user['level_info'] = $level;
- return $this->success('ok', $user);
- }
- public function setAccount()
- {
- $user = $this->request->user();
- if ($user['change_account_time'] > strtotime(date('Y-01-01', time()) && $user['change_account_time'] < strtotime(date('Y-12-31', time())))) {
- $this->error('今年已经修改过账号,不能再修改了');
- }
- $new = $this->request->post('new_account');
- if ($this->service->be(['account' => $new])) $this->error('账号已存在');
- try {
- validate(LoginValidate::class)->check([
- 'account' => $new,
- ]);
- } catch (ValidateException $e) {
- return $this->error($e->getError());
- }
- $res = $this->service->update($user['uid'], ['account' => $new, 'change_account_time' => time()]);
- if ($res) {
- return $this->success('修改成功');
- } else {
- return $this->error('修改失败');
- }
- }
- }
|