// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\api\controller; use think\response\Json; use app\api\model\User as UserModel; use app\api\model\UserCoupon as UserCouponModel; use app\api\service\User as UserService; use cores\exception\BaseException; use think\facade\Db; /** * 用户管理 * Class User * @package app\api */ class User extends Controller { /** * 当前用户详情 * @return Json * @throws BaseException */ public function info(): Json { // 当前用户信息 $userInfo = UserService::getCurrentLoginUser(true); // 获取用户头像 $userInfo['avatar']; // 获取会员等级 $userInfo['grade']; return $this->renderSuccess(compact('userInfo')); } /** * 账户资产 * @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 \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 BaseException */ public function realname(): Json { $userInfo = UserService::getCurrentLoginUser(true); return $this->renderSuccess([ 'realname' => [ 'realName' => (string)$userInfo['real_name'], 'idCard' => (string)$userInfo['id_card'], 'plateNo' => (string)$userInfo['plate_no'], // 身份证号已用于分油后不允许再改(上游按身份证号累计司机额度) 'idCardLocked' => (string)$userInfo['id_card'] !== '' && Db::name('partners_order') ->where('user_id', '=', (int)$userInfo['user_id']) ->where('source', '=', 'mall') ->count() > 0, 'isReady' => UserModel::isRealnameReady($userInfo), ] ]); } /** * 保存实名信息 * @return Json * @throws BaseException */ public function saveRealname(): Json { $model = new UserModel; if (!$model->realname($this->postForm())) { return $this->renderError($model->getError() ?: '保存失败'); } return $this->renderSuccess('保存成功'); } /** * 修改个人信息(头像昵称) * @return Json * @throws \cores\exception\BaseException */ public function personal(): Json { $model = new UserModel; if (!$model->personal($this->postForm())) { return $this->renderSuccess($model->getError() ?: '操作失败'); } return $this->renderSuccess('恭喜您,信息修改成功'); } }