|
|
|
@ -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; |
|
|
|
|