| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- <?php
- // +----------------------------------------------------------------------
- // | 商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.thinkphp.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: thinkphp <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types = 1);
- namespace app\api\controller;
- use app\api\model\User as UserModel;
- use app\api\model\UserDynamic;
- use app\api\model\UserFans;
- use app\common\exception\BaseException;
- use app\api\model\UserCoupon as UserCouponModel;
- use app\api\service\User as UserService;
- use app\common\model\StudentEduexp;
- use app\common\model\UserInfo;
- use think\response\Json;
- /**
- * 用户管理
- * Class User
- * @package app\api
- */
- class User extends Controller
- {
- /**
- * 当前用户详情
- * @return Json
- * @throws BaseException
- */
- public function info(): Json
- {
- // 当前用户信息
- $userId = $this->request->param('user_id',0);
- if($userId>0){
- $userInfo = \app\api\model\User::detail($userId);
- if($userInfo){
- $userInfo['info'] = isset($userInfo['info'])? $userInfo['info'] : [];
- $userInfo['info']['school'] = isset($userInfo['info']['school'])? $userInfo['info']['school'] : [];
- $userInfo['avatar'] = isset($userInfo['avatar'])? $userInfo['avatar'] : [];
- }
- }else{
- $userInfo = UserService::getCurrentLoginUser(true);
- $userInfo['avatar'] = isset($userInfo['avatar'])? $userInfo['avatar'] : [];
- }
- if(empty($userInfo)){
- return $this->renderSuccess('获取失败');
- }
- $userInfo['score'] = $userInfo['score']? $userInfo['score'] : round(4+($userInfo['user_id']%3/5), 1);
- return $this->renderSuccess(compact('userInfo'));
- }
- /**
- * 当前用户详情
- * @return Json
- * @throws BaseException
- */
- public function detail(): Json
- {
- // 当前用户信息
- $userId = $this->request->param('user_id',0);
- if($userId>0){
- $userInfo = \app\api\model\User::detail($userId);
- if($userInfo){
- $userInfo['avatar'] = isset($userInfo['avatar'])? $userInfo['avatar'] : [];
- }
- }else{
- $userInfo = UserService::getCurrentLoginUser(true);
- $userInfo['avatar'] = isset($userInfo['avatar'])? $userInfo['avatar'] : [];
- }
- if(empty($userInfo)){
- return $this->renderSuccess('获取失败');
- }
- $info = [
- 'user_id'=> $userInfo['user_id'],
- 'nick_name'=> $userInfo['nick_name'],
- 'user_type'=> $userInfo['user_type'],
- 'answer_num'=> $userInfo['answer_num'],
- 'score'=> $userInfo['score']? $userInfo['score'] : round(4+($userInfo['user_id']%3/5), 1),
- 'avatar_url'=> $userInfo['avatar_url'],
- ];
- unset($userInfo['avatar']);
- return $this->renderSuccess(compact('info'));
- }
- /**
- * 当前用户主页详情
- * @return Json
- * @throws BaseException
- */
- public function homeInfo(): Json
- {
- // 当前用户信息
- $userId = $this->request->param('user_id',0);
- if($userId>0){
- $userInfo = \app\api\model\User::detail($userId,['info']);
- if($userInfo){
- $userInfo['avatar'] = isset($userInfo['avatar'])? $userInfo['avatar'] : [];
- }
- }else{
- $userInfo = UserService::getCurrentLoginUser(true);
- $userInfo['avatar'] = isset($userInfo['avatar'])? $userInfo['avatar'] : [];
- }
- if(empty($userInfo)){
- return $this->renderSuccess('获取失败');
- }
- $position = isset($userInfo['info']['position'])? $userInfo['info']['position'] : '';
- $admissionYar = isset($userInfo['info']['admission_year'])? $userInfo['info']['admission_year'] : '';
- $info = [
- 'user_id'=> $userInfo['user_id'],
- 'nick_name'=> $userInfo['nick_name'],
- 'user_type'=> $userInfo['user_type'],
- 'avatar_url'=> $userInfo['avatar_url'],
- 'school_id'=> isset($userInfo['info']['school_id'])? $userInfo['info']['school_id'] : 0,
- 'school_name'=> isset($userInfo['info']['school_name'])? $userInfo['info']['school_name'] : '',
- 'admission_year'=> isset($userInfo['info']['admission_year'])? $userInfo['info']['admission_year'] : '',
- 'parent_name'=> isset($userInfo['info']['parent_name'])? $userInfo['info']['parent_name'] : '',
- 'position'=> $position,
- 'user_type_text'=> $userInfo['user_type']==3? ($position==1? '科任老师':'招生老师') : ($admissionYar? $admissionYar.'级':'学生'),
- 'home_bg'=> $userInfo['home_bg'],
- 'counts'=> UserDynamic::getCountsByUser($userInfo['user_id']),
- ];
- unset($userInfo['avatar']);
- return $this->renderSuccess(compact('info'));
- }
- /**
- * @return Json
- * @throws \cores\exception\BaseException
- */
- public function setInfo(): Json
- {
- $model = new UserModel;
- if (!$result = $model->saveInfo($this->request->param())) {
- return $this->renderSuccess($model->getError() ?: '保存失败');
- }
- return $this->renderSuccess($result? $result : '保存成功');
- }
- /**
- * 账户资产
- * @return Json
- * @throws BaseException
- */
- public function assets(): Json
- {
- // 当前用户信息
- $userInfo = UserService::getCurrentLoginUser(true);
- // 用户优惠券模型
- $model = new UserCouponModel;
- // 返回数据
- return $this->renderSuccess([
- 'assets' => [
- 'balance' => $userInfo['balance'], // 账户余额
- 'points' => $userInfo['points'], // 会员积分
- 'coupon' => $model->getCount($userInfo['user_id']), // 优惠券数量(可用)
- ]
- ]);
- }
- /**
- * 教育经历
- * @return Json
- * @throws BaseException
- */
- public function education(): Json
- {
- // 当前用户信息
- $userInfo = UserService::getCurrentLoginUser(true);
- $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
- $info = StudentEduexp::getInfoByUser($userId);
- $info = $info? $info : [];
- return $this->renderSuccess(compact('info'));
- }
- /**
- * 绑定教育经历
- * @return Json
- * @throws BaseException
- */
- public function bindEducation(): Json
- {
- $model = new StudentEduexp();
- if(!$model->setData($this->request->param())){
- return $this->renderSuccess($model->getError() ?: '设置失败');
- }
- return $this->renderSuccess('您的学历已经提交,请等待审核绑定');
- }
- /**
- * 手机号绑定
- * @return Json
- * @throws \cores\exception\BaseException
- */
- public function bindMobile(): Json
- {
- $model = new UserModel;
- if (!$model->bindMobile($this->postForm())) {
- return $this->renderSuccess($model->getError() ?: '操作失败');
- }
- return $this->renderSuccess('恭喜您,手机号绑定成功');
- }
- /**
- * 学长学姐列表
- * @return Json
- * @throws \cores\exception\BaseException
- * @throws \think\db\exception\DbException
- */
- public function seniorList()
- {
- // 当前用户信息
- $userInfo = UserService::getCurrentLoginUser(true);
- $info = isset($userInfo['info'])? $userInfo['info'] : [];
- $admissionYear = isset($info['admission_year'])? $info['admission_year'] : 0;
- $model = new UserModel;
- $params = $this->request->param();
- $params['admission_year'] = isset($params['admission_year'])? $params['admission_year'] : $admissionYear;
- $params['user_id'] = $userInfo['user_id'];
- $list = $model->getList($params, 15);
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 获取我关注的用户列表
- * @return Json
- * @throws \cores\exception\BaseException
- * @throws \think\db\exception\DbException
- */
- public function followList()
- {
- // 当前用户信息
- $userInfo = UserService::getCurrentLoginUser(true);
- $userId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
- $model = new UserFans;
- $params = $this->request->param();
- $list = $model->getFollowList($userId, $params, 15);
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 获取关注我的用户列表
- * @return Json
- * @throws \cores\exception\BaseException
- * @throws \think\db\exception\DbException
- */
- public function fans()
- {
- // 当前用户信息
- $userInfo = UserService::getCurrentLoginUser(true);
- $userId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
- $model = new UserFans;
- $params = $this->request->param();
- $list = $model->getFansList($userId, $params, 15);
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 设置头像或背景图片
- * @return Json
- * @throws \cores\exception\BaseException
- */
- public function setImage()
- {
- $model = new UserModel;
- if (!$model->setImage($this->request->param())) {
- return $this->renderSuccess($model->getError() ?: '设置失败');
- }
- return $this->renderSuccess('设置成功');
- }
- }
|