diff --git a/app/admin/controller/Store.php b/app/admin/controller/Store.php index ead2b3b4..b09daf1a 100644 --- a/app/admin/controller/Store.php +++ b/app/admin/controller/Store.php @@ -1,13 +1,4 @@ -// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\admin\controller; @@ -21,6 +12,12 @@ use app\common\model\Merchant; use app\store\model\store\User as StoreUserModel; use app\store\model\store\Role as role; use think\facade\Db; +use app\store\model\Goods as GoodsModel; +use app\store\model\GoodsCategoryRel; +use app\store\model\GoodsSku; +use app\store\model\GoodsImage; +use app\store\model\Category; +use app\store\model\GoodsSpecRel; /** * 商城管理 @@ -187,24 +184,6 @@ class Store extends Controller */ public function platformList(): Json { - // if ($this->admin['user']['role'] == 1) { - // //京东账号可以看到京东和自营的 - // if ($this->admin['user']['channel'] == 'jd') { - // $list = Channel::where('status', 1)->whereIn('code',['jd','zy'])->select(); - // //苏宁账号可以看到苏宁和自营的 - // } elseif($this->admin['user']['channel'] == 'sn'){ - // $list = Channel::where('status', 1)->whereIn('code',['sn','zy'])->select(); - // //新阙通信账号可以看到新阙通信和自营的 - // } elseif($this->admin['user']['channel'] == 'xqtx'){ - // $list = Channel::where('status', 1)->whereIn('code',['xqtx','zy'])->select(); - // //其他账号供应商只能看到自己的 - // } else { - // $list = Channel::where('status', 1)->whereIn('code',[$this->admin['user']['channel']])->select(); - // } - // } else { - // //超级管理员看到所有的 - // $list = Channel::where('status', 1)->select(); - // } $list = $this->getUserPlatform(); $platformList = []; foreach ($list as $key => $value) { @@ -388,14 +367,39 @@ class Store extends Controller } /** - * 多商户初始化 + * 删除商城的商品和商品分类 * [merchant description] * @param int $storeId [description] * @return [type] [description] */ public function deleteGoods(int $storeId): Json { + ini_set('memory_limit', '2024M'); + set_time_limit(0); + $model = StoreModel::detail($storeId); + 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++; + } return $this->renderSuccess(); }