Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit 40625a8

Browse files
committed
fix: blog_id > blog_idx
1 parent c262b7e commit 40625a8

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

app/admin/controller/blog.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ class Blog
1818
*/
1919
public function update(Request $request): Response
2020
{
21-
$role = $request->role;
22-
$user_id = $request->userid;
23-
Redis::expire($request->redisKey, 3600 * 2);
24-
return api(data: [
25-
'role' => 111111,
26-
'user_id' => $user_id,
27-
]);
21+
$blog_idx = $request->input('blog_idx');
22+
// check blog exists
23+
if (!BlogHelper::checkBlogExistsByBlogIdx($blog_idx)) {
24+
return api(false, '博客不存在');
25+
}
2826
}
2927

3028
/**
@@ -35,24 +33,24 @@ public function update(Request $request): Response
3533
*/
3634
public function del(Request $request): Response
3735
{
38-
$blog_id = $request->input('blog_id');
39-
if ($blog_id === null) {
36+
$blog_idx = $request->input('blog_idx');
37+
if ($blog_idx === null) {
4038
return api(false, 'blog_id不能为空');
4139
}
42-
if (!is_numeric($blog_id)) {
40+
if (!is_numeric($blog_idx)) {
4341
return api(false, '非法的blog_id');
4442
}
4543

4644
// check blog_id exists
47-
if (!BlogHelper::checkBlogExistsByBlogId($blog_id)) {
45+
if (!BlogHelper::checkBlogExistsByBlogIdx($blog_idx)) {
4846
return api(false, '博客不存在');
4947
}
5048

5149
// 删除博客
5250
try {
5351
Db::beginTransaction();
54-
Db::table('blog')->where('idx', $blog_id)->delete();
55-
Db::table('tag')->where('blog_id', $blog_id)->delete();
52+
Db::table('blog')->where('idx', $blog_idx)->delete();
53+
Db::table('tag')->where('blog_id', $blog_idx)->delete();
5654
Db::commit();
5755
} catch (\Throwable $e) {
5856
Db::rollBack();

common/Helper/BlogHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public static function checkBlogExists(string $blog_url): bool
5656
* @param int $blog_id
5757
* @return bool
5858
*/
59-
public static function checkBlogExistsByBlogId(int $blog_id): bool
59+
public static function checkBlogExistsByBlogIdx(int $blog_idx): bool
6060
{
61-
return Db::table('blog')->select('idx')->where('idx', $blog_id)->exists();
61+
return Db::table('blog')->select('idx')->where('idx', $blog_idx)->exists();
6262
}
6363

6464
/**

0 commit comments

Comments
 (0)