|
@@ -201,54 +201,13 @@ class GoodsCategoryService extends BaseService
|
|
|
// 参数
|
|
// 参数
|
|
|
$param = request()->all();
|
|
$param = request()->all();
|
|
|
// 记录ID
|
|
// 记录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");
|
|
$ids = getter($param, "id");
|
|
|
if (empty($ids)) {
|
|
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)) {
|
|
if (is_array($ids)) {
|
|
|
$childCount = $this->model->whereIn('pid',$ids)->where(['mark' => 1])->count();
|
|
$childCount = $this->model->whereIn('pid',$ids)->where(['mark' => 1])->count();
|
|
|
if ($childCount > 0) {
|
|
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) {
|
|
if (!$result) {
|
|
|
return message("删除失败", false);
|
|
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) {
|
|
if ($result !== false) {
|
|
|
return message();
|
|
return message();
|
|
|
}
|
|
}
|