// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\api\controller; use app\api\model\User as UserModel; use app\api\model\user\BalanceLog; use app\api\model\user\GoodSource as GoodsSourceModel; use app\api\model\user\InvoiceOrder; use app\api\model\user\UserInvoice; use app\api\model\user\UserCoupon; use app\api\model\UserCoupon as UserCouponModel; use app\api\model\Agreement as AgreementModel; use app\api\service\Feedback; use app\api\service\User as UserService; use app\common\enum\dealer\withdraw\PayType; use app\common\model\Agreement; use cores\exception\BaseException; use think\facade\Log; use think\response\Json; /** * 用户管理 * Class User * @package app\api\controller */ class User extends Controller { /** * 注销账号 * [delete description] * @return [type] [description] */ public function delete(){ $user_id = UserService::getCurrentLoginUserId(); UserModel::where('user_id', $user_id)->update(['is_delete' => 1,'update_time' => time()]); } /** * 当前用户详情 * @return Json * @throws BaseException */ public function info(): Json { // 当前用户信息 $userInfo = UserService::getCurrentLoginUser(true); // 获取用户头像和会员等级 $userInfo = UserModel::related($userInfo, ['avatar', 'grade']); //获取提现次数 $userInfo['finace_count'] = BalanceLog::where(['user_id' => $userInfo->user_id, 'scene' => 50])->count() ?? 0; //获取用户收入 $userInfo['income'] = BalanceLog::where(['user_id' => $userInfo->user_id]) ->whereIn('scene', [10, 30, 40, 60]) ->where('money', '>', 0) ->sum('money') ?? 0; return $this->renderSuccess(compact('userInfo')); } /** * @notes:编辑用户信息 * @return Json|void * @throws BaseException * @author: wanghousheng */ public function editUser() { $userId = UserService::getCurrentLoginUserId(); $data = []; $avatar_id = intval($this->request->post('avatar_id')); if ($avatar_id) { $data['avatar_id'] = $avatar_id; } $nick_name = $this->request->post('nick_name'); if ($nick_name) { $data['nick_name'] = $nick_name; } $gender = intval($this->request->post('gender')); if ($gender) { $data['gender'] = $gender; } if ($data) { $model = new UserModel(); $model->where(['user_id' => $userId])->save($data); return $this->renderSuccess('操作成功'); } $this->renderError('操作失败'); } /** * 账户资产 * @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 bindMobile(): Json { $model = new UserModel; if (!$model->bindMobile($this->postForm())) { return $this->renderSuccess($model->getError() ?: '操作失败'); } return $this->renderSuccess('恭喜您,手机号绑定成功'); } /** * 修改个人信息(头像昵称) * @return Json * @throws BaseException */ public function personal(): Json { $model = new UserModel; if (!$model->personal($this->postForm())) { return $this->renderSuccess($model->getError() ?: '操作失败'); } return $this->renderSuccess('恭喜您,信息修改成功'); } /** * 提交反馈 */ public function addFeedback(): Json { // 当前用户信息 $userInfo = UserService::getCurrentLoginUser(true); $params = $this->request->param(); if (empty($params['content']) || (empty($params['shop_id']) && $params['object_type'] != 1) || empty($params['type'])) { return $this->renderError('请补全信息'); } $userData = [ 'user_id' => $userInfo->user_id, 'user_name' => $params['user_name'] ?? $userInfo->nick_name, 'mobile' => $params['mobile'] ? hide_mobile($params['mobile']) : $userInfo->mobile, ]; $service = new Feedback(); $res = $service->addFeedback($params, $userData); if ($res) { return $this->renderSuccess('提交成功,请耐心等待'); } else { return $this->renderError('提交失败'); } } //获取反馈列表 public function getFeedBack(): Json { $params = $this->request->param(); // 当前用户信息 if (!empty($params['is_my'])) { $userInfo = UserService::getCurrentLoginUser(true); $params['user_id'] = $userInfo->user_id; } $service = new Feedback(); $list = $service->getFeedback($params); return $this->renderSuccess(compact('list')); } //我要货源 public function addGoodsSource(): Json { $model = new GoodsSourceModel(); if (!$model->addSource($this->request->param())) { return $this->renderSuccess($model->getError() ?: '操作失败'); } return $this->renderSuccess('提交成功,请耐心等待'); } //发票抬头列表 public function myInvoicing(): Json { $service = new UserInvoice(); $list = $service->getList($this->request->param()); return $this->renderSuccess(compact('list')); } //发票抬头添加 public function addInvoicing(): Json { $service = new UserInvoice(); if (!$service->add($this->request->param())) { return $this->renderSuccess($service->getError() ?: '操作失败'); } return $this->renderSuccess('添加成功'); } //发票抬头编辑 public function editInvoicing(): Json { $service = new UserInvoice(); if (!$service->edit($this->request->param())) { return $this->renderSuccess($service->getError() ?: '操作失败'); } return $this->renderSuccess('修改成功'); } //发票抬头删除 public function delInvoicing(): Json { $service = new UserInvoice(); if(!$service->del($this->request->param())) { return $this->renderSuccess($service->getError() ?: '操作失败'); } return $this->renderSuccess('删除成功·'); } //开票记录 public function invoicingLog(): Json { $service = new InvoiceOrder(); $list = $service->getList($this->request->param()); return $this->renderSuccess(compact('list')); } //开票记录 public function invoicingDetail(): Json { $service = new InvoiceOrder(); $data = $service->getDetail($this->request->param('id')); return $this->renderSuccess(compact('data')); } //订单开票 public function invoicingAdd(): Json { $service = new InvoiceOrder(); if (!$service->invoicingAdd($this->request->param())) { return $this->renderSuccess($service->getError() ?: '操作失败'); } return $this->renderSuccess('提交成功,请耐心等待'); } //订单开票 public function invoicingEdit(): Json { $service = new InvoiceOrder(); if (!$service->invoicingEdit($this->request->param())) { return $this->renderSuccess($service->getError() ?: '操作失败'); } return $this->renderSuccess('提交成功,请耐心等待'); } /** * 个人中心协议 */ public function getAgreement(): Json { $params = $this->request->param(); if (empty($params['type'])) { return $this->renderSuccess("参数错误"); } $detail = AgreementModel::detail(['type' => $params['type']]); return $this->renderSuccess(compact('detail'), 'success'); } /** * 添加用户浏览记录 */ public function addView(): Json { $goods_id = $this->request->param('goods_id'); $user_id = UserService::getCurrentLoginUserId(); $userView = new UserCoupon(); if ($userView->add(['user_id' => $user_id, 'goods_id' => $goods_id, 'store_id' => $this->storeId])) { return $this->renderSuccess('记录成功'); } return $this->renderSuccess($userView->getError() ?: '记录失败'); } }