lqmac 9 months ago
parent 694b59eec6
commit bc05fd7a54
  1. 8
      app/admin/controller/Goods.php
  2. 4
      app/admin/controller/goods/Import.php
  3. 6
      app/job/service/goods/AdminImport.php
  4. 14
      app/store/model/goods/Import.php

@ -32,7 +32,7 @@ class Goods extends Controller
* @var array
*/
protected array $allowAllAction = [
"goods/export",
//"goods/export",
];
/**
* 商品列表
@ -206,6 +206,8 @@ class Goods extends Controller
$params['store_id'] = 0;
$perSize = 10000;
$params['page'] = 1;
$platform = $this->getUserPlatform();
$params['channels'] = $platform ? array_column($platform->toArray(), "code") : [];
$data = $model->getAdminListExport($params, $perSize)->toArray();
// echo "<pre>";
// print_r($data);
@ -318,7 +320,9 @@ class Goods extends Controller
public function import(){
// 新增记录
$model = new ImportModel;
if ($model->goodsUpdateBatch($this->postData())) {
$params = $this->postData();
$params['channel'] = $this->admin['user']['channel'];
if ($model->goodsUpdateBatch($params)) {
return $this->renderSuccess('已添加到导入任务中,请在历史导入记录中查看结果');
}
return $this->renderError($model->getError() ?: '操作失败');

@ -49,9 +49,11 @@ class Import extends Controller
*/
public function batch(): Json
{
$params = $this->postData();
$params['channel'] = $this->getUserAddPlatform();
// 新增记录
$model = new ImportModel;
if ($model->adminBatch($this->postData())) {
if ($model->adminBatch($params)) {
return $this->renderSuccess('已添加到导入任务中,请在历史导入记录中查看结果');
}
return $this->renderError($model->getError() ?: '操作失败');

@ -104,7 +104,7 @@ class AdminImport extends BaseService
$service = new \app\job\service\goods\Collector();
foreach ($list as $item) {
//sku存在了就不抓取了
$info = GoodsModel::where('goods_no', $item['C'])->where('store_id', $storeId)->where('is_delete',0)->find();
$info = GoodsModel::where('goods_no', $item['C'])->where('store_id', $storeId)->where('channel', $item['B'])->where('is_delete',0)->find();
if ($info) {
$this->successCount++;
continue;
@ -202,7 +202,7 @@ class AdminImport extends BaseService
public function createData(array $original, int $storeId): array
{
$channel = Channel::where('name', $original["B"])->find();
//$channel = Channel::where('name', $original["B"])->find();
//批量导入销售区域处理
$region = [];
@ -236,7 +236,7 @@ class AdminImport extends BaseService
// 整理商品数据
$data = [
'cmmdty_model' => $original["A"],
'channel' => $channel['code'] ?? "zy",
'channel' => $original["B"] ?? "zy",
'goods_no' => $original["C"],
'goods_price' => $original["F"],
'cost_price' => $original["G"],

@ -83,6 +83,9 @@ class Import extends ImportModel
$this->checkLimit($execlData);
self::$storeId = $form['store_id'] ?? 0;
foreach ($execlData as &$value) {
$value['B'] = $form['channel']??'zy';
}
// $obj = new \app\job\service\goods\AdminImport();
// $service = new \app\job\service\goods\Collector();
// foreach ($execlData as $item) {
@ -95,7 +98,7 @@ class Import extends ImportModel
// var_dump(\count($execlData));
// exit();
// 新增商品导入记录
$recordId = $this->addRecord(\count($execlData));
$recordId = $this->addRecord(\count($execlData), $form['channel'] ?? 'zy');
// 调度计划任务
@ -103,7 +106,7 @@ class Import extends ImportModel
return true;
}
/**
* 执行批量导入
* 执行批量更新
* @param array $form
* @return bool
* @throws BaseException
@ -137,7 +140,7 @@ class Import extends ImportModel
// }
// 新增商品导入记录
$recordId = $this->addRecord(\count($execlData));
$recordId = $this->addRecord(\count($execlData), $form['channel'] ?? 'zy');
// 调度计划任务
@ -309,14 +312,15 @@ class Import extends ImportModel
* @param int $totalCount 商品总数量
* @return int
*/
private function addRecord(int $totalCount): int
private function addRecord(int $totalCount, string $channel = 'zy'): int
{
$this->save([
'total_count' => $totalCount,
'start_time' => \time(),
'fail_log' => [],
'status' => GoodsImportStatusEnum::NORMAL,
'store_id' => self::$storeId
'store_id' => self::$storeId,
'channel' => $channel,
]);
return (int)$this['id'];
}

Loading…
Cancel
Save