ソースを参照

Merge branch 'master' into 商品挂网统计

tangyuanwang 2 ヶ月 前
コミット
3d3062bad9

+ 14 - 3
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();
@@ -204,12 +211,16 @@ class CompanyCategory extends Controller
      * @date      2025-12-19
      * 
      */
-    public function delete(Request $request, CompanyCategoryModel $CompanyCategoryModel)
+    public function delete(Request $request, CompanyCategoryModel $CompanyCategoryModel,ViolationStoreModel $ViolationStoreModel)
     {
         // 验证参数
         $request->scene('delete')->validate();
         // 接收数据
         $id = request('id', 0);
+        $violation_store_count = $ViolationStoreModel->where(['category_id' => $id])->count();
+        if ($violation_store_count > 0) {
+            return json_send(['code' => 'error', 'msg' => '该分类下存在公司配置,删除失败']);
+        }
         // 查询用户
         $where = ['id' => $id];
         // 执行删除

+ 23 - 2
app/Http/Controllers/Manager/WashConfig/ProductCategory.php

@@ -5,6 +5,8 @@ namespace App\Http\Controllers\manager\washConfig;
 use App\Http\Controllers\Controller;
 use App\Http\Requests\Manager\WashConfig\ProductCategory as Request;
 use App\Models\Manager\WashConfig\ProductCategory as ProductCategoryModel;
+use App\Models\Manager\WashConfig\LowPriceGoods as LowPriceGoodsModel;
+use App\Models\Manager\WashConfig\ViolationProduct as ViolationProductModel;
 
 /**
  * 清洗配置-产品分类
@@ -170,13 +172,24 @@ class ProductCategory extends Controller
      * @date      2025-12-18
      * 
      */
-    public function set_status(Request $request, ProductCategoryModel $ProductCategoryModel)
+    public function set_status(Request $request, ProductCategoryModel $ProductCategoryModel,LowPriceGoodsModel $LowPriceGoodsModel,ViolationProductModel $ViolationProductModel)
     {
         // 验证参数
         $request->scene('set_status')->validate();
         // 接收数据
         $id                = request('id', 0);
         $status            = request('status', 0);
+        //如果是禁用,校验是否被使用
+        if ($status == 1) {
+            $low_price_goods_count = $LowPriceGoodsModel->where(['category_id' => $id])->count();
+            if ($low_price_goods_count > 0) {
+                return json_send(['code' => 'error', 'msg' => '该分类下存在低价商品配置,禁用失败']);
+            }
+            $violation_product_count = $ViolationProductModel->where(['category_id' => $id])->count();
+            if ($violation_product_count > 0) {
+                return json_send(['code' => 'error', 'msg' => '该分类下存在禁止商品配置,禁用失败']);
+            }
+        }
         // 查询用户
         $where = ['id' => $id];
         $ProductCategory = $ProductCategoryModel->where($where)->first();
@@ -202,12 +215,20 @@ class ProductCategory extends Controller
      * @date      2025-12-18
      * 
      */
-    public function delete(Request $request, ProductCategoryModel $ProductCategoryModel)
+    public function delete(Request $request, ProductCategoryModel $ProductCategoryModel,LowPriceGoodsModel $LowPriceGoodsModel,ViolationProductModel $ViolationProductModel)
     {
         // 验证参数
         $request->scene('delete')->validate();
         // 接收数据
         $id = request('id', 0);
+        $low_price_goods_count = $LowPriceGoodsModel->where(['category_id' => $id])->count();
+        if ($low_price_goods_count > 0) {
+            return json_send(['code' => 'error', 'msg' => '该分类下存在低价商品配置,删除失败']);
+        }
+        $violation_product_count = $ViolationProductModel->where(['category_id' => $id])->count();
+        if ($violation_product_count > 0) {
+            return json_send(['code' => 'error', 'msg' => '该分类下存在禁止商品配置,删除失败']);
+        }
         // 查询用户
         $where = ['id' => $id];
         // 执行删除