1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\Accounts;
- use app\common\service\AccountService;
- use app\common\service\CategoryService;
- use app\common\service\DemandBiddingService;
- use app\common\service\DemandService;
- use app\common\service\GoodsService;
- use app\common\model\Category;
- use app\common\service\OrderService;
- use app\common\service\UserService;
- use fast\Tree;
- use think\Exception;
- use think\exception\HttpResponseException;
- use think\Validate;
- class Profile extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- /**
- * 获取用户中心数据
- *
- * @ApiMethod (POST)
- * @ApiParams (name="mobile", type="string", required=true, description="手机号")
- * @ApiParams (name="newpassword", type="string", required=true, description="新密码")
- * @ApiParams (name="captcha", type="string", required=true, description="验证码")
- */
- public function userCenter()
- {
- $userInfo = $this->auth->getUserinfo();
- $userInfo = [
- 'id' => $userInfo['id'],
- 'avatarUrl' => $userInfo['avatar'] ?: $this->request->domain() . '/uploads/avatar/default.png',
- 'nickName' => $userInfo['nickname'],
- 'phoneNumber' => '',
- 'gender' => $userInfo['gender'],
- 'role' => $userInfo['role'],
- ];
- $publishCount = DemandService::where('user_id', $userInfo['id'])->count();
- $quoteCount = DemandBiddingService::where(['user_id' => $userInfo['id']])->count();
- $balance = AccountService::where('user_id', $userInfo['id'])->field(['user_id', 'amount', 'freeze', '(amount + freeze) AS total_amount'])->find();
- $countsData = [
- ['num' => $publishCount, 'name' => '我发布的需求', 'type' => 'publish'],
- ['num' => $quoteCount, 'name' => '我投标的需求', 'type' => 'quote'],
- ['num' => $balance->total_amount ?? 0, 'name' => '余额', 'type' => 'balance'],
- ['num' => 0, 'name' => '优惠券', 'type' => 'coupon'],
- ];
- $orderTagInfos = OrderService::getOrderCount($userInfo['id']);
- $customerServiceInfo = [
- 'servicePhone' => '4006336868',
- 'serviceTimeDuration' => '每周三至周五 9:00-12:00 13:00-15:00',
- ];
- $data = [
- 'userInfo' => $userInfo,
- 'countsData' => $countsData,
- 'orderTagInfos' => $orderTagInfos,
- 'customerServiceInfo' => $customerServiceInfo,
- ];
- $this->success('success', $data);
- }
- public function personInfo()
- {
- $userInfo = $this->auth->getUserinfo();
- $data = [
- 'avatarUrl' => $userInfo['avatar'] ?: $this->request->domain() . '/uploads/avatar/default.png',
- 'nickName' => $userInfo['nickname'],
- 'phoneNumber' => '',
- 'gender' => $userInfo['gender'],
- 'role' => $userInfo['role'],
- 'address' => [
- 'provinceName' => '',
- 'provinceCode' => '',
- 'cityName' => '',
- 'cityCode' => '',
- ],
- ];
- $this->success('success', $data);
- }
- public function setPersonInfo()
- {
- $userId = $this->auth->id ?? -1;
- $params = $this->request->only(['avatar', 'nickname', 'gender', 'mobile']);
- $data = array_filter($params);
- $res = UserService::where('id', $userId)->update($data);
- if ($res) {
- $this->success('success', $data);
- }
- $this->error('更新失败!');
- }
- }
|