lqmac 7 months ago
parent 143c616f0c
commit 9ab46d8eca
  1. 40
      app/admin/controller/Store.php

@ -380,26 +380,30 @@ class Store extends Controller
if (!$model || $storeId <= 0) {
return $this->renderError('商城不存在');
}
$page = 1;
//删除分类
Category::where('store_id', $storeId)->delete();
while (TRUE) {
$goods_list = GoodsModel::where('store_id', $storeId)->field('goods_id')->page($page)->limit(2000)->select();
if ($goods_list->isEmpty()) {
return $this->renderSuccess();
}
$goods_ids = array_column($goods_list->toArray(), "goods_id");
//删除商品sku
GoodsSku::whereIn('goods_id', $goods_ids)->delete();
//删除商品图片
GoodsImage::whereIn('goods_id', $goods_ids)->delete();
//删除商品规格
GoodsSpecRel::whereIn('goods_id', $goods_ids)->delete();
//删除商品
GoodsModel::whereIn('goods_id', $goods_ids)->delete();
$page++;
}
GoodsSku::where('store_id', $storeId)->delete();
GoodsImage::where('store_id', $storeId)->delete();
GoodsSpecRel::where('store_id', $storeId)->delete();
GoodsModel::where('store_id', $storeId)->delete();
// $page = 1;
// while (TRUE) {
// $goods_list = GoodsModel::where('store_id', $storeId)->field('goods_id')->page($page)->limit(2000)->select();
// if ($goods_list->isEmpty()) {
// return $this->renderSuccess();
// }
// $goods_ids = array_column($goods_list->toArray(), "goods_id");
// //删除商品sku
// GoodsSku::whereIn('goods_id', $goods_ids)->delete();
// //删除商品图片
// GoodsImage::whereIn('goods_id', $goods_ids)->delete();
// //删除商品规格
// GoodsSpecRel::whereIn('goods_id', $goods_ids)->delete();
// //删除商品
// GoodsModel::whereIn('goods_id', $goods_ids)->delete();
// $page++;
// }
return $this->renderSuccess();
}

Loading…
Cancel
Save