瀏覽代碼

新增:修改个人信息(头像昵称)

萤火科技 3 年之前
父節點
當前提交
0c5a745352
共有 3 個文件被更改,包括 34 次插入 和 3 次删除
  1. 1 1
      app/api/controller/Upload.php
  2. 16 2
      app/api/controller/User.php
  3. 17 0
      app/api/model/User.php

+ 1 - 1
app/api/controller/Upload.php

@@ -60,7 +60,7 @@ class Upload extends Controller
         $storage = new StorageDriver($this->config);
         // 设置上传文件的信息
         $storage->setUploadFile('file')
-            ->setRootDirName((string)$this->getStoreId())
+            ->setRootDirName((string)$this->storeId)
             ->setValidationScene('image');
         // 执行文件上传
         if (!$storage->upload()) {

+ 16 - 2
app/api/controller/User.php

@@ -12,11 +12,11 @@ declare (strict_types = 1);
 
 namespace app\api\controller;
 
+use think\response\Json;
 use app\api\model\User as UserModel;
-use app\common\exception\BaseException;
 use app\api\model\UserCoupon as UserCouponModel;
 use app\api\service\User as UserService;
-use think\response\Json;
+use cores\exception\BaseException;
 
 /**
  * 用户管理
@@ -75,4 +75,18 @@ class User extends Controller
         }
         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('恭喜您,信息修改成功');
+    }
 }

+ 17 - 0
app/api/model/User.php

@@ -92,6 +92,23 @@ class User extends UserModel
         return $userInfo->save(['mobile' => $data['mobile']]);
     }
 
+    /**
+     * 修改个人信息(头像昵称)
+     * @param array $form
+     * @return bool
+     * @throws BaseException
+     */
+    public function personal(array $form): bool
+    {
+        // 当前登录的用户信息
+        $userInfo = UserService::getCurrentLoginUser(true);
+        // 默认数据
+        $data['avatar_id'] =  $form['avatarId'] ?: $userInfo['avatar_id'];
+        $data['nick_name'] =  $form['nickName'] ?: $userInfo['nick_name'];
+        // 更新用户记录
+        return $userInfo->save($data);
+    }
+
     /**
      * 验证绑定的手机号
      * @param array $data