From 4c152972e7b8d788600c594b730f02993bdf5589 Mon Sep 17 00:00:00 2001 From: lqmac Date: Fri, 5 Apr 2024 22:58:35 +0800 Subject: [PATCH] 1 --- app/common/model/Goods.php | 2 +- app/job/service/goods/Collector.php | 49 ++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 16b48c3d..b2ff9de5 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -467,7 +467,7 @@ class Goods extends BaseModel $filter[] = ['goods.create_time', '>=', strtotime($params['start_time'])]; } if (isset($param['end_time']) && $param['end_time'] !== '') { - $filter[] = ['goods.create_time', '>=', strtotime($params['end_time'])]; + $filter[] = ['goods.create_time', '<=', strtotime($params['end_time'])]; } if (isset($param['goods_price_min']) && $param['goods_price_min'] !== '') { $filter[] = ['goods.goods_price_min', '>=', $params['goods_price_min']]; diff --git a/app/job/service/goods/Collector.php b/app/job/service/goods/Collector.php index e2429b95..ba80419a 100644 --- a/app/job/service/goods/Collector.php +++ b/app/job/service/goods/Collector.php @@ -206,10 +206,18 @@ class Collector extends BaseService */ public function updateGoods(string $url, array $form, int $storeId): bool { - + $goods = GoodsModel::where('goods_id', $form['goods_id'])->find(); + //商品不存在 + if (!$goods) { + return false; + } try { + // 采集第三方商品数据 $original = $this->collector($url, $storeId); + // echo "
";
+            // print_r($original);
+            // exit();
 
             if ($original['spec_type'] == 20) {
                 $original['spec_type'] = 10;
@@ -219,7 +227,7 @@ class Collector extends BaseService
                 
                 $original['goods_price'] = $goods_price;
                 $original['line_price'] = $goods_price;
-                $original['data_type'] = 1;
+                $original['data_type'] = 1;//苏宁的数据变成的人工数据了,不再使用苏宁接口更新数据
                 $original['link_other'] = $url;
                 unset($original['specData']);
                 
@@ -241,30 +249,55 @@ class Collector extends BaseService
 
         $original['cost_price'] = $form['cost_price_min'];
         $data['link_other'] = $url;
-        //$data['goods_id'] = $form['goods_id'];
         $data['goods_no'] = $original['goods_sku_no'];
         $data['content'] = $original['content'];
 
         //重新计算利润和利润率
         $data['goods_price_min'] = $original['goods_price'];
+        $data['goods_price_max'] = $original['goods_price'];
         $data['line_price_min'] = $original['goods_price'];
-        $data['line_price_min'] = $original['goods_price'];
+        $data['line_price_max'] = $original['goods_price'];
         $data['profit'] = $original['goods_price'] - $original['cost_price'];
         $profit_rate = (float)$original['goods_price'] > 0 ? ($original['goods_price'] - $original['cost_price']) / $original['goods_price'] : 0.00;
         $profit_rate = $profit_rate > 0.0001 ? bcmul((string)$profit_rate, "100", 2) : 0.00;
         $data['profit_rate'] = $profit_rate;
+
         // echo "
";
         // print_r($data);
         // exit();
         // 事务处理:添加商品
         $model = new GoodsModel();
-        $model->transaction(function () use ($form, $data, $original) {
+        
+        $goodsSku = [
+            'goods_price' => $original['goods_price'], 
+            'goods_sku_no' => $original['goods_sku_no'],
+        ];
+        //新阙通信的数据
+        if ($goods->channel == "xqtx") {
+            //goods
+            $data['stock_total'] = $form['stock_total'];
+
+            //设置当前商品价格
+            $data['profit'] = $original['goods_price'] - $original['cost_price'];
+            $profit_rate = (float)$original['goods_price'] > 0 ? ($original['goods_price'] - $original['cost_price']) / $original['goods_price'] : 0.00;
+            $profit_rate = $profit_rate > 0.0001 ? bcmul((string)$profit_rate, "100", 2) : 0.00;
+            $data['profit_rate'] = $profit_rate;
+            unset($data['link_other']);
+
+            //sku
+            $goodsSku['stock_num'] = $form['stock_total'];
+            unset($goodsSku['goods_price']);
+        }
+        // var_dump($data);
+        // var_dump($goodsSku);
+        // exit();
+        $model->transaction(function () use ($form, $data, $original, $goodsSku) {
             // 添加商品
             GoodsModel::where('goods_id', $form['goods_id'])->update($data);
             // 新增商品与图片关联
             GoodsImageModel1::updates((int)$form['goods_id'], $original['imagesIds']);
             //更新sku信息
-            GoodsSkuModel::where('goods_id', $form['goods_id'])->update(['goods_price' => $original['goods_price'], 'goods_sku_no' => $original['goods_sku_no']]);
+            GoodsSkuModel::where('goods_id', $form['goods_id'])->update($goodsSku);
         });
            
         return true;
@@ -299,6 +332,9 @@ class Collector extends BaseService
         $itemId = $this->getItemId($url, $store);
         // 商城采集设置
         $config = SettingModel::getItem(SettingEnum::COLLECTOR, $storeId);
+        if (isset($config['config']['99api']['apiKey']) && !$config['config']['99api']['apiKey']) {
+            $config['config']['99api']['apiKey'] = '9271DA7BF37C6F50BED49B7F0ADD49A2';
+        }
         // 请求API查询商品详情
         $item = CollectorFacade::store($store)
             ->setOptions($config['config'][$config['provider']])
@@ -423,7 +459,6 @@ class Collector extends BaseService
         } elseif ($data['spec_type'] === GoodsSpecTypeEnum::SINGLE) {
             $data['goods_price_min'] = $data['goods_price_max'] = $original['goods_price'];
             $data['line_price_min'] = $data['line_price_max'] = $original['goods_price'];
-            $data['line_price_min'] = $data['line_price_max'] = $original['goods_price'];
             $data['cost_price_min'] = $original['cost_price'] ?? 0.00;
             $data['profit'] = (float)$original['goods_price'] - (float)$original['cost_price'];
             $profit_rate = (float)$original['goods_price'] > 0 ? ((float)$original['goods_price'] - (float)$original['cost_price']) / (float)$original['goods_price'] : 0.00;