lqmac 8 months ago
parent 475ddb16be
commit 0978bad2ab
  1. 4
      app/api/service/order/Checkout.php
  2. 37
      app/job/service/goods/AdminImport.php
  3. 6
      app/job/service/goods/Collector.php
  4. 11
      app/store/model/Goods.php
  5. 23
      app/store/model/goods/Import.php

@ -185,10 +185,6 @@ class Checkout extends BaseService
if (!in_array($this->orderData['address']->city_id, json_decode($value['region']))) {
$this->setError("您的收货地址不在商品 [{$value['goods_name']}] 的销售区域内");
}
// if (strpos($this->orderData['address']->province_id.".".$this->orderData['address']->city_id, $value['sale_areas']) === false) {
// $this->setError("您的收货地址不在商品 [{$value['goods_name']}] 的销售区域内");
// break;
// }
}
// 验证商品状态, 是否允许购买

@ -199,13 +199,32 @@ class AdminImport extends BaseService
$channel = Channel::where('name', $original["B"])->find();
$arr = [];
$sale_areas = $original["J"] ? explode("、", $original["J"]) : [];
if ($sale_areas) {
//批量导入销售区域处理
$region = [];
$region_text = [];
if ($original["J"]) {
$sale_areas = $original["J"] ? explode("、", $original["J"]) : [];
$cityNames = [];
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'];
list($province, $city) = explode(".", $value);
$cityNames[] = $city;
}
$regions = Region::whereIn('name', $cityNames)->select()->toArray();
$regionsnew = [];
foreach ($regions as $key => $value) {
$regionsnew[$value['pid']][] = $value;
}
foreach ($regionsnew as $pid => $value) {
$privince = Region::where('id', $pid)->find();
$region_text[$pid]['name'] = $privince['name'] ?? "";
$citys = [];
foreach ($value as $val) {
$region[] = $val['id'];
$citys[] = ['name' => $val['name']];
}
$region_text[$pid]['citys'] = $citys;
}
}
@ -225,9 +244,9 @@ class AdminImport extends BaseService
'goods_type' => 10,//实物
'goods_status' => 10,//上架
'store_id' => $storeId,
'sale_areas' => $arr ? implode("、", $arr) : "",
'region' => $arr ? implode("、", $arr) : "",
'region_text' => $arr ? implode("、", $arr) : "",
//'sale_areas' => $arr ? implode("、", $arr) : "",
'region' => $region ? json_encode($region) : "",
'region_text' => $region_text ? json_encode(array_values($region_text)) : "",
'import' => 1,//是否是导入采集
];
// echo "<pre>";

@ -159,7 +159,8 @@ 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['region'] = $form['region'] ?? "";
$original['region_text'] = $form['region_text'] ?? "";
$original['data_type'] = 1;
$original['link'] = $url;
@ -433,7 +434,8 @@ 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'] ?? "";
$data['region'] = $original['region'] ?? "";
$data['region_text'] = $original['region_text'] ?? "";
}
// 规格和sku数据处理
if ($data['spec_type'] === GoodsSpecTypeEnum::MULTI) {

@ -252,15 +252,6 @@ class Goods extends GoodsModel
*/
private function createData(array $data): array
{
$arr = [];
$sale_areas = (isset($data["sale_areas"]) && $data["sale_areas"]) ? explode("、", $data["sale_areas"]) : [];
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['goods_sku_no'] = $data['goods_no'] ?? "";
// 默认数据
$data = array_merge($data, [
@ -270,7 +261,7 @@ class Goods extends GoodsModel
'data_type' => 1,//数据类型
'newSkuList' => [],
'store_id' => self::$storeId,
'sale_areas' => $arr ? implode("、", $arr) : "",
//'sale_areas' => $arr ? implode("、", $arr) : "",
]);
if (isset($data['rules'])) {
$data['region'] = isset($data['rules'][0]['region']) ? json_encode($data['rules'][0]['region']) :"";

@ -78,20 +78,17 @@ class Import extends ImportModel
$this->checkLimit($execlData);
self::$storeId = $form['store_id'] ?? 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);
echo "<pre>";
print_r($data);
exit();
$service->single($item['D'], $data, self::$storeId);
// // 记录导入成功
// $this->successCount++;
}
exit();
// $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, self::$storeId);
// // // 记录导入成功
// // $this->successCount++;
// }
// var_dump(\count($execlData));
// exit();
// 新增商品导入记录
$recordId = $this->addRecord(\count($execlData));

Loading…
Cancel
Save