陈伟 9 months ago
commit 0848106453
  1. 6
      app/api/model/Goods.php
  2. 41
      app/job/service/goods/AdminImport.php
  3. 2
      app/job/service/goods/Collector.php
  4. 10
      app/store/model/Goods.php
  5. 10
      app/store/model/goods/Import.php

@ -247,7 +247,7 @@ class Goods extends GoodsModel
->where([
'a.store_id' => request()->header()['storeid'],
'a.status' => 10,
'b.category_id' => $_GET['category_id']
//'b.category_id' => $_GET['category_id']
])->whereIn('a.goods_id', $goods)->field('a.goods_id,a.goods_name,a.goods_price_min,b.category_id,a.sales_initial,a.sales_actual')->select()->toArray();
//暂时 要优化
foreach ($list as &$v) {
@ -258,8 +258,8 @@ class Goods extends GoodsModel
$file_path = UploadFileModel::where([
'store_id' => request()->header()['storeid'],
'file_id' => $file_id,
])->field('file_path')->find()->file_path;
$v['image'] = "https://".$_SERVER['HTTP_HOST'] . '/uploads/' . $file_path;
])->find();
$v['image'] = getUrl($file_path['file_path'], $file_path['domain']);
//$v['end_time'] = strtotime($info->p_time) - time();
$v['end_time'] = $info->p_time ? strtotime($info->p_time) - time() : 0;

@ -35,6 +35,7 @@ use app\common\validate\goods\AdminImport as GoodsAdminImportValidate;
use cores\exception\BaseException;
use think\facade\Log;
use app\common\model\Channel;
use app\common\model\Region;
/**
* 服务类:商品批量导入
* Class Import
@ -105,31 +106,6 @@ class AdminImport extends BaseService
$data = $this->createData($item, $storeId);
$service->single($item['D'], $data, $storeId);
// 生成商品数据(用于写入数据库)
// $data = $this->createData($item, $storeId);
// Log::record("data".json_encode($data));
// // 数据验证
// if (!$this->validateGoodsData($data, $storeId)) {
// $this->errorLog[] = ['goodsSn' => $item['A'], 'message' => $this->getError()];
// continue;
// }
// // 事务处理:添加商品
// $model = new GoodsModel();
// $model->transaction(function () use ($model, $data, $storeId) {
// // 添加商品
// $model->save($data);
// // 新增商品与分类关联
// GoodsCategoryRelModel::increased((int)$model['goods_id'], $data['categoryIds'], $storeId);
// // 新增商品与图片关联
// GoodsImageModel::increased((int)$model['goods_id'], $data['imagesIds'], $storeId);
// // 新增商品与规格关联
// GoodsSpecRelModel::increased((int)$model['goods_id'], $data['newSpecList'], $storeId);
// // 新增商品sku信息
// GoodsSkuModel::add((int)$model['goods_id'], $data['spec_type'], $data['newSkuList'], $storeId);
// // 新增服务与承诺关联
// GoodsServiceRelModel::increased((int)$model['goods_id'], $data['serviceIds'], $storeId);
// });
// 记录导入成功
$this->successCount++;
}
@ -221,6 +197,17 @@ class AdminImport extends BaseService
public function createData(array $original, int $storeId): array
{
$channel = Channel::where('name', $original["B"])->find();
$arr = [];
$sale_areas = $original["J"] ? explode("、", $original["J"]) : [];
if ($sale_areas) {
foreach ($sale_areas as $value) {
$regions = Region::whereIn('name', explode(".", $value))->select()->toArray();
$regions = array_column($regions, null, "level");
$arr[] = $regions[1]['id'].".".$regions[2]['id'];
}
}
// 整理商品数据
$data = [
'cmmdty_model' => $original["A"],
@ -235,7 +222,11 @@ class AdminImport extends BaseService
'goods_type' => 10,//实物
'goods_status' => 10,//上架
'store_id' => $storeId,
'sale_areas' => implode("、", $arr)
];
// echo "<pre>";
// print_r($data);
// exit();
// 过滤不存在的ID集数据
$data['categoryIds'] = CategoryModel::filterCategoryIds($data['categoryIds'], $storeId);
return $data;

@ -143,6 +143,7 @@ class Collector extends BaseService
$original['remark'] = $form['remark'] ?? "";
$original['cmmdty_model'] = $form['cmmdty_model'] ?? "";
$original['goods_no'] = $form['goods_no'] ?? "";
$original['sale_areas'] = $form['sale_areas'] ?? "";
// 下载远程商品图片
$original = $this->thirdPartyImages($original, $form['imageStorage'], $storeId);
@ -327,6 +328,7 @@ class Collector extends BaseService
$data['remark'] = $original['remark'] ?? "";
$data['cmmdty_model'] = $original['cmmdty_model'] ?? "";
$data['goods_no'] = $original['goods_no'] ?? "";
$data['sale_areas'] = $original['sale_areas'] ?? "";
}
// 规格和sku数据处理
if ($data['spec_type'] === GoodsSpecTypeEnum::MULTI) {

@ -122,6 +122,8 @@ class Goods extends GoodsModel
$data = $this->createData($data);
// 事务处理
$this->transaction(function () use ($data) {
// var_dump($data);
// exit();
// 更新商品
$this->save($data);
// 更新商品与分类关联
@ -206,6 +208,8 @@ class Goods extends GoodsModel
'newSkuList' => [],
'store_id' => self::$storeId,
]);
// var_dump($data);
// exit();
// 整理商品的价格和库存总量
if ($data['spec_type'] == GoodsSpecTypeEnum::MULTI) {
$data['stock_total'] = GoodsSkuModel::getStockTotal($data['specData']['skuList']);
@ -213,8 +217,10 @@ class Goods extends GoodsModel
[$data['line_price_min'], $data['line_price_max']] = GoodsSkuModel::getLinePrices($data['specData']['skuList']);
} elseif ($data['spec_type'] == GoodsSpecTypeEnum::SINGLE) {
$data['goods_price_min'] = $data['goods_price_max'] = $data['goods_price'];
$data['line_price_min'] = $data['line_price_max'] = $data['line_price'];
//$data['line_price_min'] = $data['line_price_max'] = $data['line_price'];
$data['line_price_min'] = $data['line_price_max'] = $data['goods_price'];
$data['stock_total'] = $data['stock_num'];
$data['cost_price_min'] = $data['cost_price'];
}
// 规格和sku数据处理
if ($data['spec_type'] == GoodsSpecTypeEnum::MULTI) {
@ -226,7 +232,7 @@ class Goods extends GoodsModel
$data['newSkuList'] = GoodsSkuModel::getNewSkuList($data['newSpecList'], $data['specData']['skuList']);
} elseif ($data['spec_type'] == GoodsSpecTypeEnum::SINGLE) {
// 生成skuItem
$data['newSkuList'] = helper::pick($data, ['goods_price', 'line_price', 'stock_num', 'goods_weight']);
$data['newSkuList'] = helper::pick($data, ['goods_price', 'line_price', 'cost_price','stock_num', 'goods_weight']);
}
// 单独设置折扣的配置
$data['is_enable_grade'] == 0 && $data['is_alone_grade'] = 0;

@ -75,6 +75,16 @@ class Import extends ImportModel
$this->checkLimit($execlData);
self::$storeId = 0;
$obj = new \app\job\service\goods\AdminImport();
$service = new \app\job\service\goods\Collector();
foreach ($execlData as $item) {
$data = $obj->createData($item, self::$storeId);
// $service->single($item['D'], $data, $storeId);
// // 记录导入成功
// $this->successCount++;
}
// 新增商品导入记录
$recordId = $this->addRecord(\count($execlData));

Loading…
Cancel
Save