diff --git a/app/common/controller/PostCommentController.php b/app/common/controller/PostCommentController.php index 2ff4c80..ec1da99 100644 --- a/app/common/controller/PostCommentController.php +++ b/app/common/controller/PostCommentController.php @@ -6,6 +6,7 @@ use app\common\model\User; use app\common\service\OssService; use app\common\traits\crud\CrudControllerTrait; use app\common\service\PostCommentService; +use support\Request; class PostCommentController extends BaseController { @@ -41,4 +42,20 @@ class PostCommentController extends BaseController } return $data; } + + /** + * 删除 + * + * @param Request $request 请求对象 + * @return mixed 返回删除操作结果 + */ + public function delete(Request $request) + { + try { + $count = $this->service->serviceDelete($request); + return $this->success([], "删除评论成功"); + } catch (\Throwable $e) { + return $this->error($e->getMessage().$e->getLine().$e->getFile()); + } + } } \ No newline at end of file diff --git a/app/common/controller/PostFavoriteController.php b/app/common/controller/PostFavoriteController.php index 2e75a84..1997f86 100644 --- a/app/common/controller/PostFavoriteController.php +++ b/app/common/controller/PostFavoriteController.php @@ -2,6 +2,9 @@ namespace app\common\controller; use app\common\controller\BaseController; +use app\common\model\Post; +use app\common\model\User; +use app\common\service\OssService; use app\common\traits\crud\CrudControllerTrait; use app\common\service\PostFavoriteService; use support\Request; @@ -23,7 +26,7 @@ class PostFavoriteController extends BaseController * @param Request $request 请求对象 * @return mixed 返回分页数据及总数 */ - public function index(Request $request) + public function self(Request $request) { try { $raw = $this->service->serviceSelfList($request); @@ -48,6 +51,24 @@ class PostFavoriteController extends BaseController $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['post_id'])){ + $ossservice = new OssService(); + $post = Post::where('id', $data['post_id'])->first()->toArray(); + + if (isset( $post['user_id'])){ + $user = User::where('id', $post['user_id'])->first(); + $postUser = []; + $postUser['name'] = $user['name']; + $postUser['nickname'] = $user['nickname']; + $postUser['avatar'] = $user['avatar']; + $postUser['avatar_pull'] = $user['avatar']; + if(!str_contains($postUser['avatar'], 'http') && !empty($postUser['avatar'])){ + $postUser['avatar_pull'] = $ossservice->generatePrivateUrl($postUser['avatar']); + } + $post['user'] = $postUser; + } + $data['post'] = $post; + } return $data; } diff --git a/app/common/service/PostCommentService.php b/app/common/service/PostCommentService.php index 6cfd0a6..495a2ff 100644 --- a/app/common/service/PostCommentService.php +++ b/app/common/service/PostCommentService.php @@ -105,8 +105,6 @@ class PostCommentService return $data; } - - /** * 添加后置处理 */ @@ -123,4 +121,30 @@ class PostCommentService $post['comment'] = $post['comment']+1; $post->save(); } + + + + /** + * 添加后置处理 + */ + public function serviceDelete(Request $request) + { + $param = $request->all(); + + if (empty($param['id'])) { + throw new \Exception("参数错误"); + } + + $where = []; + $where['id'] = $param['id']; + $comment = PostComment::where($where)->first(); + + $post = Post::where(['id' => $comment['post_id']])->first(); + $post['comment'] = $post['comment']-1; + $post->save(); + + $count = $comment->delete(); + + return $count; + } } \ No newline at end of file diff --git a/app/common/service/UserService.php b/app/common/service/UserService.php index 1876859..70bbd2a 100644 --- a/app/common/service/UserService.php +++ b/app/common/service/UserService.php @@ -106,8 +106,6 @@ class UserService 'openid' => $user->openid, 'unionid' => $user->unionid, ], - // 'menu' => $menuTree, - // 'permissions' => $permissionCodes ]; } @@ -182,7 +180,7 @@ class UserService { // 对密码进行哈希处理 $user = User::find($uid); - $keysToKeep = ['name', 'avatar']; + $keysToKeep = ['name', 'nickname', 'avatar']; $data = array_intersect_key($data, array_flip($keysToKeep)); diff --git a/config/route.php b/config/route.php index 9680098..1b8b3b5 100644 --- a/config/route.php +++ b/config/route.php @@ -62,7 +62,7 @@ Route::group('/common', function () { Route::group('/comment', function () { Route::any('/list', [app\common\controller\PostCommentController::class, 'index']); Route::any('/store', [app\common\controller\PostCommentController::class, 'store']); - Route::any('/destroy', [app\common\controller\PostCommentController::class, 'destroy']); + Route::any('/destroy', [app\common\controller\PostCommentController::class, 'delete']); }); // 点赞 @@ -74,7 +74,7 @@ Route::group('/common', function () { // 收藏 Route::group('/favorite', function () { - Route::any('/list', [app\common\controller\PostFavoriteController::class, 'index']); + Route::any('/self', [app\common\controller\PostFavoriteController::class, 'self']); Route::any('/store', [app\common\controller\PostFavoriteController::class, 'store']); Route::any('/destroy', [app\common\controller\PostFavoriteController::class, 'delete']); });