Преглед изворни кода

【智价云】 违规清洗配置删除校验更新

tangyuanwang пре 1 дан
родитељ
комит
70bb0d8dd6

+ 20 - 3
app/Http/Controllers/Manager/WashConfig/ViolationStore.php

@@ -5,6 +5,8 @@ namespace App\Http\Controllers\Manager\WashConfig;
 use App\Http\Controllers\Controller;
 use App\Http\Requests\Manager\WashConfig\ViolationStore as Request;
 use App\Models\Manager\WashConfig\ViolationStore as ViolationStoreModel;
+use App\Models\Manager\WashConfig\LowPriceGoodsCompany as LowPriceGoodsCompanyModel;
+use App\Models\Manager\WashConfig\ViolationProductCompany as ViolationProductCompanyModel;
 
 
 /**
@@ -123,7 +125,9 @@ class ViolationStore extends Controller
         // 接收数据
         $all_data = request()->all();
         $store_scope = request('store_scope', '');
-        $all_data['store_scope'] = $store_scope;
+        $all_data['store_scope'] = $store_scope;//店铺范围
+        $employee_ids = request('employee_ids', '');
+        $all_data['employee_ids'] = $employee_ids;
         //查询是否存在
         $map = ['social_credit_code' => $all_data['social_credit_code']];
         $data = $ViolationStoreModel->where($map)->first();
@@ -152,7 +156,9 @@ class ViolationStore extends Controller
         $all_data = request()->all();
         $store_scope = request('store_scope','');
         $all_data['store_scope'] = $store_scope;
-                //查询是否存在
+        $employee_ids = request('employee_ids', '');
+        $all_data['employee_ids'] = $employee_ids;
+        //查询是否存在
         $map = ['social_credit_code' => $all_data['social_credit_code']];
         $data = $ViolationStoreModel->where($map)->where('id', '!=', $id)->first();
         if ($data)     return json_send(['code' => 'error', 'msg' => '营业执照记录已存在']);
@@ -197,12 +203,23 @@ class ViolationStore extends Controller
      * @date      2025-12-03
      * 
      */
-    public function delete(Request $request, ViolationStoreModel $ViolationStoreModel)
+    public function delete(Request $request, ViolationStoreModel $ViolationStoreModel,LowPriceGoodsCompanyModel $LowPriceGoodsCompanyModel,ViolationProductCompanyModel $ViolationProductCompanyModel)
     {
         // 验证参数
         $request->scene('delete')->validate();
         // 接收数据
         $id = request('id', 0);
+        //查询是否已经被使用
+        if ($id > 0) {
+            $use_low_price_goods_company_log = $LowPriceGoodsCompanyModel->where('company_id', $id)->first();
+            if ($use_low_price_goods_company_log) {
+                return json_send(['code' => 'error', 'msg' => '该记录已被使用在低价商品配置中,不能删除']);
+            }
+            $use_violation_product_company_log = $ViolationProductCompanyModel->where('company_id', $id)->first();
+            if ($use_violation_product_company_log) {
+                return json_send(['code' => 'error', 'msg' => '该记录已被使用在违规商品配置中,不能删除']);
+            }
+        }
         // 查询用户
         $where = ['id' => $id];
         // 执行删除

+ 16 - 2
app/Models/Manager/WashConfig/LowPriceGoods.php

@@ -200,7 +200,21 @@ class LowPriceGoods extends Model
         if (!$LowProduct) {
             return false;
         }
-        $LowProduct->delete();
-        return true;
+        DB::beginTransaction();
+        try {
+            $LowPriceGoodsCompanyModel = new LowPriceGoodsCompanyModel();
+            $company_id_log = $LowPriceGoodsCompanyModel->where('company_id', $LowProduct->id)->get();
+            if (!empty($company_id_log)) {
+                $LowPriceGoodsCompanyModel->where('company_id', $LowProduct->id)->delete();
+            }
+            $LowProduct->delete();
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
     }
 }

+ 16 - 2
app/Models/Manager/WashConfig/ViolationProduct.php

@@ -196,7 +196,21 @@ class ViolationProduct extends Model
         if (!$ViolationProduct) {
             return false;
         }
-        $ViolationProduct->delete();
-        return true;
+        DB::beginTransaction();
+        try {
+            $ViolationProductCompanyModel = new ViolationProductCompanyModel();
+            $company_id_log = $ViolationProductCompanyModel->where('company_id', $ViolationProduct->id)->get();
+            if (!empty($company_id_log)) {
+                $ViolationProductCompanyModel->where('company_id', $ViolationProduct->id)->delete();
+            }
+            $ViolationProduct->delete();
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
     }
 }