Browse Source

feat(category): 添加栏目状态更新功能

- 在路由文件中添加 updateStatus POST 接口
- 在 CategoryController 中实现 updateStatus 方法处理状态更新请求
- 在 CategoryService 中添加 updateStatus 业务逻辑
- 引入 Nav 模型用于缓存清理
- 更新栏目状态时同时清理 Category 和 Nav 的关联缓存
- 添加参数验证确保 id 和 status 字段的有效性
master
reidier 6 days ago
parent
commit
101c59a515
  1. 11
      app/controller/backend/CategoryController.php
  2. 14
      app/service/CategoryService.php
  3. 1
      route/admin.php

11
app/controller/backend/CategoryController.php

@ -517,4 +517,15 @@ class CategoryController extends BaseController
return json($categoryService -> copyCategoryToOtherLang($param['from'],$param['to'],$param['site_id'],$this->admin['seller_id']));
}
public function updateStatus(CategoryService $categoryService): \think\response\Json
{
$param = $this->request->only(['id','status']);
try {
validate(CategoryValidate::class)->scene('updateStatus')->check($param);
} catch (ValidateException $e) {
return jsonReturn(-1, $e->getError());
}
return json($categoryService -> updateStatus($param['id'],$param['status'],$this->admin['seller_id']));
}
}

14
app/service/CategoryService.php

@ -7,6 +7,7 @@ use app\exception\ModelException;
use app\model\Attachment;
use app\model\Category;
use app\model\CategoryCheck;
use app\model\Nav;
use app\model\Route;
use app\model\WebsiteLang;
use think\facade\Cache;
@ -381,5 +382,18 @@ class CategoryService
$Category->saveAll($cateData);
}
/**
* 修改栏目状态
* @throws \ReflectionException
* @throws ModelException
*/
public function updateStatus($id, $status, $seller_id): array
{
$Category = new Category();
$res = $Category->updateCategory(['id' => $id, 'seller_id' => $seller_id], ['status' => $status]);
CacheService::deleteRelationCacheByObject($Category);
CacheService::deleteRelationCacheByObject(Nav::class);
return $res;
}
}

1
route/admin.php

@ -155,6 +155,7 @@ Route::group(function () {
// 导入excel文章列表
Route::post('/importExcel', '/importExcel');
// 内容复制到其他语言
Route::post('updateStatus', '/updateStatus');
Route::post('/copyToOtherLang', '/copyToOtherLang');
})->prefix(config('route.admin') . '.content');

Loading…
Cancel
Save