我的收藏

This commit is contained in:
2025-11-26 17:35:38 +08:00
parent a924959365
commit 12812fa775
5 changed files with 68 additions and 8 deletions
@@ -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());
}
}
}
@@ -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;
}
+26 -2
View File
@@ -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;
}
}
+1 -3
View File
@@ -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));
+2 -2
View File
@@ -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']);
});