Browse Source

[智价云] 公司分类禁用校验更新

tangyuanwang 2 months ago
parent
commit
0baaee758b
1 changed files with 9 additions and 2 deletions
  1. 9 2
      app/Http/Controllers/Manager/WashConfig/CompanyCategory.php

+ 9 - 2
app/Http/Controllers/Manager/WashConfig/CompanyCategory.php

@@ -5,7 +5,7 @@ namespace App\Http\Controllers\manager\washConfig;
 use App\Http\Controllers\Controller;
 use App\Http\Requests\Manager\WashConfig\CompanyCategory as Request;
 use App\Models\Manager\WashConfig\CompanyCategory as CompanyCategoryModel;
-
+use App\Models\Manager\WashConfig\ViolationStore as ViolationStoreModel;
 
 /**
  * 清洗配置-公司分类
@@ -172,13 +172,20 @@ class CompanyCategory extends Controller
      * @date      2025-12-19
      * 
      */
-    public function set_status(Request $request, CompanyCategoryModel $CompanyCategoryModel)
+    public function set_status(Request $request, CompanyCategoryModel $CompanyCategoryModel,ViolationStoreModel $ViolationStoreModel)
     {
         // 验证参数
         $request->scene('set_status')->validate();
         // 接收数据
         $id                = request('id', 0);
         $status            = request('status', 0);
+        //如果是禁用,校验是否被使用
+        if ($status == 1) {
+            $violation_store_count = $ViolationStoreModel->where(['category_id' => $id])->count();
+            if ($violation_store_count > 0) {
+                return json_send(['code' => 'error', 'msg' => '该分类下存在公司配置,禁用失败']);
+            }
+        }
         // 查询用户
         $where = ['id' => $id];
         $CompanyCategory = $CompanyCategoryModel->where($where)->first();