diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 985558cd..b5000273 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -263,6 +263,7 @@ class Goods extends BaseModel foreach ($list as &$goods) { $goods['dic'] = 'admin'; $goods['after_markup_price'] = round($goods['cost_price_min'] / (1 - ($goods['markup_rate'] / 100)), 0); + $goods['import_time'] = date("Y-m-d H:i:s", $goods['import_time']); $goods = $this->setGoodsData($goods, null); } return $list; diff --git a/app/job/service/goods/Collector.php b/app/job/service/goods/Collector.php index a0fe970e..0a270501 100644 --- a/app/job/service/goods/Collector.php +++ b/app/job/service/goods/Collector.php @@ -274,18 +274,20 @@ class Collector extends BaseService * @param int $storeId [description] * @return [type] [description] */ - public function updateGoods(string $url, array $form, int $storeId): bool + public function updateGoods(string $url, array $form, int $storeId): array { - $goods = GoodsModel::where('goods_id', $form['goods_id'])->find(); - + $goods = GoodsModel::where('goods_id', $form['goods_id'])->where('is_delete',0)->find(); + $errorLog = []; //商品不存在 if (!$goods || !$url) { - return true; + $errorLog = ['goodsSn' => $form['goods_id'], 'message' =>trim($url)."商品或者url不存在"]; + return [false, $errorLog]; } //新阙通信的抓取过了,就不抓取了;京东价拖抓取过了就不抓取了 if (isset($form['is_cover']) && $form['is_cover'] == 0) { if (($goods['channel'] == 'xqtx' && $goods['content']) || $goods->goods_no_other) { - return true; + GoodsModel::where('goods_id', $form['goods_id'])->update(['import_time' => time()]); + return [true, $errorLog]; } } @@ -323,8 +325,8 @@ class Collector extends BaseService // var_dump($e->getMessage()); // exit; tre($e->getTraceAsString()); - $this->errorLog[] = ['url' => trim($url), 'message' => $e->getMessage()]; - return false; + $errorLog = ['goodsSn' => $form['goods_id'], 'message' => trim($url).$e->getMessage()]; + return [true, $errorLog]; } // if ($original['goods_price'] == 0) { // return false; @@ -388,6 +390,7 @@ class Collector extends BaseService // exit(); $model->transaction(function () use ($form, $data, $original, $goodsSku) { $data['update_time'] = time(); + $data['import_time'] = time(); // 添加商品 GoodsModel::where('goods_id', $form['goods_id'])->update($data); // 新增商品与图片关联 @@ -395,8 +398,8 @@ class Collector extends BaseService //更新sku信息 GoodsSkuModel::where('goods_id', $form['goods_id'])->update($goodsSku); }); - - return true; + // 更新采集记录 + return [true, $errorLog]; } /** * 检查采集记录状态是否异常 diff --git a/app/job/service/goods/GoodsUpdateImport.php b/app/job/service/goods/GoodsUpdateImport.php index dc816611..98f2a2c0 100644 --- a/app/job/service/goods/GoodsUpdateImport.php +++ b/app/job/service/goods/GoodsUpdateImport.php @@ -68,8 +68,9 @@ class GoodsUpdateImport extends BaseService if (!isset($item['G']) || !$item['G']) { continue; } - $ret = $service->updateGoods($item['G'], $data, $storeId); + list($ret, $errorLog) = $service->updateGoods($item['G'], $data, $storeId); if ($ret == false) { + $this->errorLog[] = $errorLog; continue; } // 记录导入成功