|
@@ -135,4 +135,68 @@ class Auth extends InspectionApi
|
|
|
$this->error($this->auth->getError() ?: '密码设置失败');
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传头像
|
|
|
+ */
|
|
|
+ public function uploadAvatar()
|
|
|
+ {
|
|
|
+ $file = $this->request->file('avatar');
|
|
|
+ if (!$file) {
|
|
|
+ $this->error('请选择头像文件');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 移动到框架应用根目录/uploads/ 目录下
|
|
|
+ $info = $file->validate(['size' => 2 * 1024 * 1024, 'ext' => 'jpg,jpeg,png,gif'])
|
|
|
+ ->move(ROOT_PATH . 'public' . DS . 'uploads' . DS . 'avatar' . DS . 'inspection');
|
|
|
+
|
|
|
+ if (!$info) {
|
|
|
+ $this->error($file->getError());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取上传文件的相对路径
|
|
|
+ $avatar = '/uploads/avatar/inspection/' . $info->getSaveName();
|
|
|
+
|
|
|
+ // 更新头像
|
|
|
+ $result = $this->auth->updateAvatar($avatar);
|
|
|
+ if ($result) {
|
|
|
+ $this->success('头像上传成功', [
|
|
|
+ 'avatar' => cdnurl($avatar, true)
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ $this->error($this->auth->getError() ?: '头像更新失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新个人信息
|
|
|
+ */
|
|
|
+ public function updateProfile()
|
|
|
+ {
|
|
|
+ $name = $this->request->post('name');
|
|
|
+ $avatar = $this->request->post('avatar');
|
|
|
+
|
|
|
+ if ($name) {
|
|
|
+ $this->application->name = $name;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($avatar) {
|
|
|
+ // 处理头像路径,去除域名部分
|
|
|
+ $avatar = str_replace(request()->domain(), '', $avatar);
|
|
|
+ $result = $this->auth->updateAvatar($avatar);
|
|
|
+ if (!$result) {
|
|
|
+ $this->error($this->auth->getError() ?: '头像更新失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($name) {
|
|
|
+ try {
|
|
|
+ $this->application->save();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $this->error('信息更新失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('信息更新成功', $this->getInspectorInfo());
|
|
|
+ }
|
|
|
}
|