diff --git a/app/controller/backend/CategoryController.php b/app/controller/backend/CategoryController.php index d5dde5e..af5b856 100644 --- a/app/controller/backend/CategoryController.php +++ b/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'])); + } } diff --git a/app/service/CategoryService.php b/app/service/CategoryService.php index 9af0270..9a0a36b 100644 --- a/app/service/CategoryService.php +++ b/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; + } } diff --git a/route/admin.php b/route/admin.php index 9d12a97..c5f7a1b 100644 --- a/route/admin.php +++ b/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');