lqmac 6 months ago
parent 3e6617f9c8
commit 507c8efcb8
  1. 5
      app/admin/controller/Goods.php
  2. 90
      app/admin/controller/Store.php
  3. 1
      app/store/controller/Goods.php
  4. 9
      app/store/model/Goods.php

@ -135,11 +135,13 @@ class Goods extends Controller
{ {
// 商品详情 // 商品详情
$model = GoodsModel::detail($goodsId); $model = GoodsModel::detail($goodsId);
$params = $this->postForm();
$params['data_type'] = $model->data_type;
// echo "<pre>"; // echo "<pre>";
// print_r($model); // print_r($model);
// exit(); // exit();
// 更新记录 // 更新记录
if ($model->edit($this->postForm(), $model)) { if ($model->edit($params, $model)) {
//更新来源数据为当前数据的商品 //更新来源数据为当前数据的商品
@ -178,6 +180,7 @@ class Goods extends Controller
'is_jd_remove' => $goods_sku->is_jd_remove, 'is_jd_remove' => $goods_sku->is_jd_remove,
'goods_no_other' => $goods_sku->goods_no_other, 'goods_no_other' => $goods_sku->goods_no_other,
'link_other' => $goods_sku->link_other, 'link_other' => $goods_sku->link_other,
'data_type' => $goods_sku->data_type,
// 'is_pool' => $goods_sku->is_pool, // 'is_pool' => $goods_sku->is_pool,
// 'is_sale' => $goods_sku->is_sale, // 'is_sale' => $goods_sku->is_sale,
'update_time' => time(), 'update_time' => time(),

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

@ -167,6 +167,7 @@ class Goods extends Controller
// print_r($params); // print_r($params);
// print_r($model->toArray()); // print_r($model->toArray());
// exit(); // exit();
$params['data_type'] = $model->data_type;
// 更新记录 // 更新记录
if ($model->edit($params)) { if ($model->edit($params)) {
return $this->renderSuccess('更新成功'); return $this->renderSuccess('更新成功');

@ -114,7 +114,7 @@ class Goods extends GoodsModel
$data = $this->createData($data); $data = $this->createData($data);
// 事务处理 // 事务处理
$this->transaction(function () use ($data) { $this->transaction(function () use ($data) {
$data['data_type'] = $data['data_type'] ?? 1; $data['data_type'] = 1;
// 添加商品 // 添加商品
$this->save($data); $this->save($data);
// 新增商品与分类关联 // 新增商品与分类关联
@ -142,7 +142,6 @@ class Goods extends GoodsModel
*/ */
public function edit(array $data, $goodsModel = null): bool public function edit(array $data, $goodsModel = null): bool
{ {
// 创建商品数据 // 创建商品数据
$data = $this->createData($data); $data = $this->createData($data);
@ -335,7 +334,7 @@ class Goods extends GoodsModel
'line_price' => $data['line_price'] ?? 0, 'line_price' => $data['line_price'] ?? 0,
'content' => $data['content'] ?? '', 'content' => $data['content'] ?? '',
'newSpecList' => [], 'newSpecList' => [],
'data_type' => 1,//数据类型 //'data_type' => 1,//数据类型
'newSkuList' => [], 'newSkuList' => [],
'store_id' => self::$storeId, 'store_id' => self::$storeId,
//'sale_areas' => $arr ? implode("、", $arr) : "", //'sale_areas' => $arr ? implode("、", $arr) : "",
@ -412,7 +411,9 @@ class Goods extends GoodsModel
} }
$data['imagesIds'] = $images; $data['imagesIds'] = $images;
} }
if ($data['categoryIds']) {
$data['cate_status'] = 1;
}
return $data; return $data;
} }

Loading…
Cancel
Save