From bea32e221ec57e87648edfa5a6aac815f8ca9e40 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 26 Nov 2025 14:10:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BC=96=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E5=B8=96=E5=AD=90=E5=88=9B=E5=BB=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/UserController.php | 18 ++++++++++++++++++ app/common/service/PostService.php | 9 ++++++--- app/common/service/UserService.php | 15 +++++++++++++-- config/route.php | 1 + 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/app/common/controller/UserController.php b/app/common/controller/UserController.php index bb8fd6a..335f816 100644 --- a/app/common/controller/UserController.php +++ b/app/common/controller/UserController.php @@ -127,6 +127,24 @@ class UserController extends BaseController } } + /** + * 修改名字与头像 + * @param Request $request + * @return \support\Response + * @throws \Random\RandomException + */ + public function save(Request $request) + { + try { + $uid = $request->user->uid; + $data = $request->all(); + $result = (new UserService())->save($uid,$data);; + return $this->success($result, '编辑成功'); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + diff --git a/app/common/service/PostService.php b/app/common/service/PostService.php index d4c213e..1fbef8e 100644 --- a/app/common/service/PostService.php +++ b/app/common/service/PostService.php @@ -51,7 +51,7 @@ class PostService if (isset($p['category_id']) && $p['category_id']) { $config['where']['category_id'] = $p['category_id']; } - if (isset($p['self']) && $p['self']) { + if (isset($p['scene']) && $p['scene']=='self') { $config['where']['user_id'] = $request->user->uid; } $config['where']['status'] = 1; @@ -95,11 +95,14 @@ class PostService { $media = redis::get('PostMedia_'.$res['user_id']); $media = unserialize($media); + if(!is_array($media)){ + $media = explode(',',$media); + } foreach ($media as $v) { PostMedia::create([ 'post_id' => $res->id, - 'media_type' => $this->getMediaTypeByUrl($v['url']), - 'url' => $v['url'], + 'media_type' => $this->getMediaTypeByUrl($v), + 'url' => $v, ]); } } diff --git a/app/common/service/UserService.php b/app/common/service/UserService.php index cbf20ba..9b19ee4 100644 --- a/app/common/service/UserService.php +++ b/app/common/service/UserService.php @@ -157,8 +157,6 @@ class UserService return $this->logic->getList(); } - - /** * 修改用户密码 */ @@ -175,7 +173,20 @@ class UserService return $user; } + /** + * 修改用户密码 + */ + public function save(int $uid, array $data) + { + // 对密码进行哈希处理 + $user = User::find($uid); + $keysToKeep = ['name', 'avatar']; + $data = array_intersect_key($data, array_flip($keysToKeep)); + + $user = $user::update($data); + return $user; + } /** * 获取微信小程序用户信息(登录及获取手机号) diff --git a/config/route.php b/config/route.php index 62740cc..a1d9425 100644 --- a/config/route.php +++ b/config/route.php @@ -43,6 +43,7 @@ Route::group('/common', function () { Route::group('/user', function () { Route::any('/info', [app\common\controller\UserController::class, 'info']); Route::any('/update/password', [app\common\controller\UserController::class, 'savePassword']); + Route::any('/update', [app\common\controller\UserController::class, 'save']); }); Route::group('/preset', function () {