123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- /**
- * Author: luzheng.liu
- * Time: 2020/12/5 17:15
- */
- namespace app\api\controller;
- use app\api\model\HomeModel;
- use app\common\service\CommonService;
- use app\api\BaseController;
- use app\api\exception\ApiException;
- use app\api\model\UserModel;
- use app\api\model\VisitorModel;
- use app\common\service\UserService;
- use app\common\until\Until;
- use think\facade\Cache;
- use think\facade\Session;
- class User extends BaseController {
- /**
- * @OA\Get (path="/api/User",
- * tags={"用户管理"},
- * summary="用户列表",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\Parameter(description="页码",in="query", name="page",@OA\Schema(type="string",default="1")),
- * @OA\Parameter(description="页尺寸", in="query",name="pageSize",@OA\Schema(type="string",default="10")),
- * @OA\Parameter(description="状态 1正常 2删除",in="query", name="status",@OA\Schema(type="string")),
- * @OA\Parameter(description="手机号", in="query",name="mobile",@OA\Schema(type="string")),
- * @OA\Parameter(description="昵称", in="query",name="name",@OA\Schema(type="string")),
- * @OA\Parameter(description="会员等级 1非会员,2金卡会员,3铂金会员",in="query",name="cardLevel",@OA\Schema(type="string")),
- * @OA\Parameter(description="加入方式 1小程序 2后台预约",in="query", name="joinType",@OA\Schema(type="string")),
- * @OA\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function index() {
- $input = Until::getInput();
- $model = new UserModel();
- $model->setPage($input['page'] ?? 1);
- $model->setPageSize($input['pageSize'] ?? 10);
- $where = [];
- if (!empty($input['status'])) {
- $where[] = ['u.status', '=', $input['status']];
- } else {
- $where[] = ['u.status', '=', $model::NORMAL];
- }
- if (!empty($input['mobile']) || (isset($input['mobile']) && $input['mobile'] == '0')) {
- $where[] = ['u.mobile', 'like', '%' . $input['mobile'] . '%'];
- }
- if (!empty($input['name']) || (isset($input['name']) && $input['name'] == '0')) {
- $where[] = ['u.name', 'like', '%' . $input['name'] . '%'];
- }
- if (!empty($input['cardLevel'])) {
- $where[] = ['u.card_level', '=', $input['cardLevel']];
- }
- if (!empty($input['joinType'])) {
- $where[] = ['u.join_type', '=', $input['joinType']];
- }
- $model->setWhere($where);
- $data = $model->getUserList();
- Until::output($data);
- }
- /**
- * @OA\Post(path="/api/user/save",
- * tags={"用户管理"},
- * summary="保存用户(有id就更新,没id就新增)",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\RequestBody(
- * @OA\MediaType(
- * mediaType="application/json",
- * @OA\Schema(
- * @OA\Property(description="微信小程序", property="code", type="string", default="dd"),
- * required={"title", "content"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function save() {
- $input = Until::getInput();
- $rule = [
- 'code' => 'require',
- ];
- Until::check($rule, $input);
- $server = new UserService();
- $userInfo = $server->decode($input['code']);
- $userServer = new UserService();
- $info = $userServer->saveUserInfo($input, $userInfo['openid']);
- $info['token'] = (new \app\common\until\Token())->getToken($info['userId'], '', false);
- Until::output(['userInfo' => $info]);
- }
- public function getMobile() {
- $input = Until::getInput();
- $rule = [
- 'code' => 'require',
- 'encryptedData' => 'require',
- 'iv' => 'require'
- ];
- Until::check($rule, $input);
- $server = new UserService();
- $mobile = $server->getPhoneMobile($input['code'],$input['iv'],$input['encryptedData']);
- $userModel = new UserModel();
- $userModel::where(['id' => $this->userId])->update(['mobile' => $mobile]);
- $info = $userModel->getUserInfo($this->userId);
- $info['token'] = (new \app\common\until\Token())->getToken($info['userId'], '', false);
- Until::output(['userInfo' => $info]);
- }
- /**
- * @OA\Post(path="/api/User/editUser",
- * tags={"用户管理"},
- * summary="修改用户信息",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\RequestBody(
- * @OA\MediaType(
- * mediaType="multipart/form-data",
- * @OA\Schema(
- * @OA\Property(description="用户姓名", property="name", type="string", default="小明"),
- * @OA\Property(description="生日", property="birthday", type="string", default="1889-02-03"),
- * @OA\Property(description="头像", property="avatar", type="string", default="http://xxx.com"),
- * @OA\Property(description="性别 0未知 1男 2女", property="sex", type="string", default="http://xxx.com"),
- * required={"name", "birthday","avatar"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function editUser() {
- $input = Until::getInput();
- $rule = [
- 'name' => 'require',
- 'birthday' => 'require',
- 'avatar' => 'require',
- 'sex' => 'require'
- ];
- Until::check($rule, $input);
- $model = new UserModel();
- $model::where(['id' => $this->userId])->update([
- 'name' => $input['name'],
- 'birthday' => $input['birthday'],
- 'avatar' => $input['avatar'],
- 'sex' => $input['sex']
- ]);
- $info = $model->getUserInfo($this->userId);
- Until::output(['info'=>$info]);
- }
- /**
- * @OA\Get(path="/api/User/read",
- * tags={"用户管理"},
- * summary="读取单个用户信息",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\RequestBody(
- * @OA\MediaType(
- * mediaType="multipart/form-data",
- * @OA\Schema(
- * @OA\Property(description="用户id", property="id", type="int"),
- * required={"id"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function read(int $id) {
- $info = (new UserModel())::where(['id' => $id])->find();
- Until::output(['info' => Until::modelToArray($info)]);
- }
- }
|