|
|
@@ -12,6 +12,7 @@
|
|
|
namespace App\Services\Common;
|
|
|
|
|
|
use App\Models\GoodsCategoryModel;
|
|
|
+use App\Models\GoodsModel;
|
|
|
use App\Services\BaseService;
|
|
|
|
|
|
/**
|
|
|
@@ -230,8 +231,63 @@ class GoodsCategoryService extends BaseService
|
|
|
]);
|
|
|
|
|
|
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);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 清理已删除的记录
|
|
|
+ $query->where(['mark' => 0])->where('update_time', '<=', time() - 600)->forceDelete();
|
|
|
+
|
|
|
+ if (is_array($ids)) {
|
|
|
+ $childCount = $this->model->whereIn('pid',$ids)->where(['mark' => 1])->count();
|
|
|
+ if ($childCount > 0) {
|
|
|
+ return message("存在有子分类的数据,无法删除", false);
|
|
|
+ }
|
|
|
+
|
|
|
+ $goodsCount = GoodsModel::whereIn('category_id',$ids)->where(['mark' => 1])->count();
|
|
|
+ if ($goodsCount > 0) {
|
|
|
+ return message("有分类存在商品,无法删除", false);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量删除
|
|
|
+ $result = $query->whereIn('id', $ids)->update(['mark' => 0, 'update_time' => time()]);
|
|
|
+ if (!$result) {
|
|
|
+ return message("删除失败", false);
|
|
|
+ }
|
|
|
+ return message("删除成功");
|
|
|
+ } else {
|
|
|
+ $childCount = $this->model->where(['pid'=>$ids,'mark' => 1])->count();
|
|
|
+ if ($childCount > 0) {
|
|
|
+ return message("存在子分类,无法删除", false);
|
|
|
+ }
|
|
|
+
|
|
|
+ $goodsCount = GoodsModel::where(['category_id' => $ids, 'mark' => 1])->count();
|
|
|
+ if ($goodsCount > 0) {
|
|
|
+ return message("有分类存在商品,无法删除", false);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 单个删除
|
|
|
+ $result = $query->where('id', $ids)->update(['mark' => 0, 'update_time' => time()]);
|
|
|
+ if ($result !== false) {
|
|
|
+ return message();
|
|
|
+ }
|
|
|
+ return message("删除失败", false);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 批量删除
|
|
|
* @param array $params
|