|
|
|
@ -373,59 +373,65 @@ class Store extends Controller |
|
|
|
|
* @param int $storeId [description] |
|
|
|
|
* @return [type] [description] |
|
|
|
|
*/ |
|
|
|
|
public function deleteGoods(int $storeId): Json |
|
|
|
|
public function deleteGoods(): Json |
|
|
|
|
{ |
|
|
|
|
$params = $this->postData(); |
|
|
|
|
$storeId = $params['storeId'] ?? 0; |
|
|
|
|
$type = $params['type'] ?? 0; |
|
|
|
|
ini_set('memory_limit', '1024M'); |
|
|
|
|
set_time_limit(0); |
|
|
|
|
$model = StoreModel::detail($storeId); |
|
|
|
|
if (!$model || $storeId <= 0) { |
|
|
|
|
return $this->renderError('商城不存在'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//删除分类 |
|
|
|
|
Category::where('store_id', $storeId)->delete(); |
|
|
|
|
// 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) { |
|
|
|
|
//echo $page.PHP_EOL; |
|
|
|
|
$goods_list = GoodsModel::where('store_id', $storeId) |
|
|
|
|
->where('channel','<>', 'zy') |
|
|
|
|
->field('goods_id') |
|
|
|
|
->order("goods_id desc") |
|
|
|
|
->page($page) |
|
|
|
|
->limit(2000) |
|
|
|
|
->select(); |
|
|
|
|
if ($goods_list->isEmpty()) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
$goods_ids = array_column($goods_list->toArray(), "goods_id"); |
|
|
|
|
// 分批每次导入20条 |
|
|
|
|
$limit = 200; |
|
|
|
|
// 根据商品总数量计算需要的队列任务数量 |
|
|
|
|
$jobCount = \count($goods_ids) / $limit; |
|
|
|
|
// 逐次发布队列任务 |
|
|
|
|
for ($i = 0; $i < $jobCount; $i++) { |
|
|
|
|
$data = array_slice($goods_ids, $i * $limit, $limit); |
|
|
|
|
GoodsRealDeleteJob::dispatch([ |
|
|
|
|
'list' => $data, |
|
|
|
|
]); |
|
|
|
|
if ($type == "cate") { |
|
|
|
|
Category::where('store_id', $storeId)->delete(); |
|
|
|
|
return $this->renderSuccess(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($type == "goods") { |
|
|
|
|
$page = 1; |
|
|
|
|
while (TRUE) { |
|
|
|
|
//echo $page.PHP_EOL; |
|
|
|
|
$goods_list = GoodsModel::where('store_id', $storeId) |
|
|
|
|
->where('channel','<>', 'zy') |
|
|
|
|
->field('goods_id') |
|
|
|
|
->order("goods_id desc") |
|
|
|
|
->page($page) |
|
|
|
|
->limit(2000) |
|
|
|
|
->select(); |
|
|
|
|
if ($goods_list->isEmpty()) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
$goods_ids = array_column($goods_list->toArray(), "goods_id"); |
|
|
|
|
// 分批每次导入20条 |
|
|
|
|
$limit = 200; |
|
|
|
|
// 根据商品总数量计算需要的队列任务数量 |
|
|
|
|
$jobCount = \count($goods_ids) / $limit; |
|
|
|
|
// 逐次发布队列任务 |
|
|
|
|
for ($i = 0; $i < $jobCount; $i++) { |
|
|
|
|
$data = array_slice($goods_ids, $i * $limit, $limit); |
|
|
|
|
GoodsRealDeleteJob::dispatch([ |
|
|
|
|
'list' => $data, |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//删除商品sku |
|
|
|
|
GoodsSku::whereIn('goods_id', $goods_ids)->delete(); |
|
|
|
|
//删除商品图片 |
|
|
|
|
GoodsImage::whereIn('goods_id', $goods_ids)->delete(); |
|
|
|
|
//删除商品规格 |
|
|
|
|
GoodsSpecRel::whereIn('goods_id', $goods_ids)->delete(); |
|
|
|
|
|
|
|
|
|
$page++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//删除商品sku |
|
|
|
|
GoodsSku::whereIn('goods_id', $goods_ids)->delete(); |
|
|
|
|
//删除商品图片 |
|
|
|
|
GoodsImage::whereIn('goods_id', $goods_ids)->delete(); |
|
|
|
|
//删除商品规格 |
|
|
|
|
GoodsSpecRel::whereIn('goods_id', $goods_ids)->delete(); |
|
|
|
|
|
|
|
|
|
$page++; |
|
|
|
|
//删除商品 |
|
|
|
|
GoodsModel::where('store_id', $storeId)->where('channel','<>', 'zy')->delete(); |
|
|
|
|
} |
|
|
|
|
//删除商品 |
|
|
|
|
GoodsModel::where('store_id', $storeId)->where('channel','<>', 'zy')->delete(); |
|
|
|
|
|
|
|
|
|
return $this->renderSuccess(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|