wesmiler 6 дней назад
Родитель
Сommit
8ad414a559
1 измененных файлов с 4 добавлено и 45 удалено
  1. 4 45
      app/Services/Common/GoodsCategoryService.php

+ 4 - 45
app/Services/Common/GoodsCategoryService.php

@@ -201,54 +201,13 @@ class GoodsCategoryService extends BaseService
         // 参数
         $param = request()->all();
         // 记录ID
-        $id = getter($param, "id");
-        if (empty($id)) {
-            return message("分类ID不能为空", false);
-        }
-
-        $info = $this->model->where(['id' => $id, 'mark' => 1])->first();
-        if (!$info) {
-            return message("分类信息不存在", false);
-        }
-
-        // 检查是否有子分类
-        $childCount = $this->model->where(['pid' => $id, 'mark' => 1])->count();
-        if ($childCount > 0) {
-            return message("存在子分类,无法删除", false);
-        }
-
-        // 检查是否有商品使用此分类
-        $goodsModel = new \App\Models\GoodsModel();
-        $goodsCount = $goodsModel->where(['category_id' => $id, 'mark' => 1])->count();
-        if ($goodsCount > 0) {
-            return message("该分类下有商品,无法删除", false);
-        }
-
-        // 删除(软删除)
-        $this->model->where('id', $id)->update([
-            'mark' => 0,
-            'update_time' => time()
-        ]);
-
-        return message("删除成功", true);
-
-        // 参数
-        $param = request()->all();
-        // 记录ID
         $ids = getter($param, "id");
         if (empty($ids)) {
-            return message("记录ID不能为空", false);
-        }
-
-        // 数据隔离:商户用户只能删除自己的商品
-        $query = $this->model;
-        if ($storeId > 0) {
-            $query = $query->where('store_id', $storeId);
+            return message("分类ID不能为空", false);
         }
 
         // 清理已删除的记录
-        $query->where(['mark' => 0])->where('update_time', '<=', time() - 600)->forceDelete();
-
+        $this->model->where(['mark' => 0])->where('update_time', '<=', time() - 600)->delete();
         if (is_array($ids)) {
             $childCount = $this->model->whereIn('pid',$ids)->where(['mark' => 1])->count();
             if ($childCount > 0) {
@@ -261,7 +220,7 @@ class GoodsCategoryService extends BaseService
             }
 
             // 批量删除
-            $result = $query->whereIn('id', $ids)->update(['mark' => 0, 'update_time' => time()]);
+            $result = $this->model->whereIn('id', $ids)->update(['mark' => 0, 'update_time' => time()]);
             if (!$result) {
                 return message("删除失败", false);
             }
@@ -278,7 +237,7 @@ class GoodsCategoryService extends BaseService
             }
 
             // 单个删除
-            $result = $query->where('id', $ids)->update(['mark' => 0, 'update_time' => time()]);
+            $result = $this->model->where('id', $ids)->update(['mark' => 0, 'update_time' => time()]);
             if ($result !== false) {
                 return message();
             }