From 5161573844fbb341abfbb45a9eda74256051f281 Mon Sep 17 00:00:00 2001 From: ztt <835303992@qq.com> Date: Wed, 22 May 2024 09:38:39 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/model/Order.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/api/model/Order.php b/app/api/model/Order.php index a6f6c54c..079bcf70 100644 --- a/app/api/model/Order.php +++ b/app/api/model/Order.php @@ -172,6 +172,17 @@ class Order extends OrderModel $this->error = $orderSource->getError(); return false; } + //订单已取消提示 + if ($this['order_status'] == OrderStatusEnum::CANCELLED) { + $this->error = '订单已取消成功,无需重复操作'; + return false; + } + + if ($this['order_status'] == OrderStatusEnum::APPLY_CANCEL) { + $this->error = '订单已申请取消,需等待后台审核'; + return false; + } + // 订单是否已支付 $isPay = $this['pay_status'] == PayStatusEnum::SUCCESS; // 提示信息 From b090f55ce45e8b21284d0eaba8f4821ddf17d20e Mon Sep 17 00:00:00 2001 From: lqmac Date: Thu, 23 May 2024 23:34:15 +0800 Subject: [PATCH 02/13] 1 --- app/common/model/Goods.php | 2 +- app/store/controller/Goods.php | 14 ++++++++++++- app/store/model/goods/Import.php | 34 +++++++++++++++++++++++++------- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 286a6a82..af7bbc41 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -208,7 +208,7 @@ class Goods extends BaseModel // 执行查询 $list = $query ->alias($this->name) - ->field(['goods.goods_id', 'goods.goods_name', 'cmmdty_model', 'remark', 'cost_price_min', 'stock_total', 'is_check', 'goods_price_min','goods_no','goods_source','delivery_time','delivery_id','status','link','link_other']) + ->field(['goods.goods_id', 'goods.goods_name', 'cmmdty_model', 'remark', 'cost_price_min', 'stock_total', 'is_check', 'goods_price_min','goods_no','goods_source','delivery_time','delivery_id','status','link','link_other','channel']) ->where('is_delete', '=', 0) ->order($sort) ->paginate($listRows); diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php index 03d3c89c..4f097e1e 100644 --- a/app/store/controller/Goods.php +++ b/app/store/controller/Goods.php @@ -204,12 +204,24 @@ class Goods extends Controller $params['store_id'] = $this->storeId; $perSize = 10000; $params['page'] = 1; - $params['channels'] = ['zy']; + //$params['channels'] = ['zy']; + // echo "
";
+        // print_r($params);
+        //exit();
         $data = $model->getAdminListExport($params, $perSize)->toArray();
         // echo "
";
         // print_r($data['data']);
+        // exit();
         if ($data['data']) {
             foreach ($data['data'] as &$value) {
+                if (!in_array($value['channel'], ['zy'])) {
+                    $value['goods_price_min'] = self::$show_content;
+                    $value['goods_price_max'] = self::$show_content;
+                    $value['line_price_max'] = self::$show_content;
+                    $value['line_price_min'] = self::$show_content;
+                    $value['cost_price_min'] = self::$show_content;
+                    $value['goods_no'] = self::$show_content;
+                }
                 $cates = GoodsCategoryRel::where('goods_id', $value['goods_id'])->select()->toArray();
                 $value['category_id'] = $cates ? implode(",", array_column($cates, "category_id")) : "";
             }
diff --git a/app/store/model/goods/Import.php b/app/store/model/goods/Import.php
index 15ef06a6..e5927c1a 100644
--- a/app/store/model/goods/Import.php
+++ b/app/store/model/goods/Import.php
@@ -231,28 +231,48 @@ class Import extends ImportModel
         
         self::$storeId = $form['store_id'] ?? 0;
         foreach ($execlData as $key => $value) {
+
             $upData = [
                 'goods_name'=> $value['B'],
                 'cmmdty_model'=> $value['C'],
                 'goods_source'=> $value['D'],
-                'goods_no'=> $value['E'],
+                //'goods_no'=> $value['E'],
                 'delivery_time'=> $value['G'],
                 'is_check'=> $value['H'],
                 'delivery_id'=> $value['I'],
                 'status'=> $value['J'],
-                'cost_price_min'=> $value['K'],
-                'goods_price_min'=> $value['L'],
-                'goods_price_max'=> $value['L'],
-                'line_price_min'=> $value['L'],
-                'line_price_max'=> $value['L'],
+                // 'cost_price_min'=> $value['K'],
+                // 'goods_price_min'=> $value['L'],
+                // 'goods_price_max'=> $value['L'],
+                // 'line_price_min'=> $value['L'],
+                // 'line_price_max'=> $value['L'],
                 'stock_total'=> $value['M'],
                 'remark'=> $value['N'],
             ];
+            $goods = GoodsModel::where('goods_id', $value['A'])->find();
+            if (!$goods) {
+                continue;
+            }
+            //自营数据才能更新价格
+            if (in_array($goods['channel'], ['zy'])) {
+                $upData['goods_no'] = $value['E'];
+                $upData['cost_price_min'] = $value['K'];
+                $upData['goods_price_min' ]= $value['L'];
+                $upData['goods_price_max'] = $value['L'];
+                $upData['line_price_min'] = $value['L'];
+                $upData['line_price_max'] = $value['L'];
+                $profit = (float)$upData['goods_price_min'] - (float)$upData['cost_price_min'];
+                $profit_rate = (float)$upData['goods_price_min'] > 0 ? bcmul(bcdiv((string)$profit, (string)$upData['goods_price_min'], 2), (string)100, 2) : 0.00;
+                $upData['profit'] = $profit;
+                $upData['profit_rate'] = $profit_rate;
+                GoodsSkuModel::where('goods_id', $value['A'])->update(['cost_price' => $value['K'], 'goods_price' => $value['L']]);
+            }
+
             // echo "
";
             // print_r(explode(",", $value['F']));
             // exit();
             GoodsModel::where('goods_id', $value['A'])->update($upData);
-            GoodsSkuModel::where('goods_id', $value['A'])->update(['cost_price' => $value['K'], 'goods_price' => $value['L']]);
+            
             GoodsCategoryRelModel::updates((int)$value['A'], explode(",", $value['F']));
         }
         return true;

From 9042626a7718a3cd3db5dc8b58fe175b5679ecbc Mon Sep 17 00:00:00 2001
From: lqmac 
Date: Sat, 25 May 2024 15:20:01 +0800
Subject: [PATCH 03/13] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/admin/controller/Goods.php             | 76 ++++++++++++-------
 app/common.php                             | 18 +++++
 app/common/model/Goods.php                 | 15 +++-
 app/job/controller/goods/GoodsAddPrice.php | 49 ++++++++++++
 app/job/service/goods/GoodsAddPrice.php    | 86 ++++++++++++++++++++++
 5 files changed, 217 insertions(+), 27 deletions(-)
 create mode 100644 app/job/controller/goods/GoodsAddPrice.php
 create mode 100644 app/job/service/goods/GoodsAddPrice.php

diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php
index e161e755..714ab055 100644
--- a/app/admin/controller/Goods.php
+++ b/app/admin/controller/Goods.php
@@ -19,6 +19,7 @@ use app\store\model\Goods as GoodsModel;
 use app\store\model\GoodsCategoryRel;
 use app\store\model\GoodsSku;
 use app\store\model\goods\Import as ImportModel;
+use app\job\controller\goods\GoodsAddPrice as GoodsAddPriceJob;
 
 /**
  * 商品管理控制器
@@ -132,7 +133,7 @@ class Goods extends Controller
         // 商品详情
         $model = GoodsModel::detail($goodsId);
         // echo "
";
-        // print_r($this->postForm());
+        // print_r($model);
         // exit();
         // 更新记录
         if ($model->edit($this->postForm(), $model)) {
@@ -144,7 +145,18 @@ class Goods extends Controller
                 return $this->renderSuccess('更新成功');
             }
             $goods_sku = GoodsModel::where('goods_id', $goodsId)->where('store_id', 0)->find();
-
+            // var_dump($goods_sku->cost_price_min);
+            // var_dump($goods_sku->markup_rate);
+            //成本价加价之后的处理
+            list($cost_price, $profit, $profit_rate) = getGoodsCostAndProfitAndProfitRate($goods_sku->goods_price_min, $goods_sku->cost_price_min, $goods_sku->markup_rate);
+            $goods_sku->cost_price_min = $cost_price;
+            $goods_sku->profit = $profit;
+            $goods_sku->profit_rate = $profit_rate;
+            
+            // var_dump($cost_price);
+            // var_dump($profit);
+            // var_dump($profit_rate);
+            // exit();
             $goods_data = [
                 'goods_name' => $goods_sku->name,
                 'content' => $goods_sku->content,
@@ -335,36 +347,50 @@ class Goods extends Controller
      * @param int   $rate        [description]
      */
     public function addPrice(array $categoryIds, int $rate){
-        ini_set('memory_limit', '1024M');
-        set_time_limit(0);
+        // ini_set('memory_limit', '1024M');
+        // set_time_limit(0);
         $goods = GoodsCategoryRel::whereIn('category_id',$categoryIds)->where('store_id', 0)->select()->toArray();
         if (!$goods) {
             return $this->renderSuccess('没有需要加价的商品');
         }
-        $goods = GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->where('store_id', 0)->select()->toArray();
+        $goods = GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->where('store_id', 0)->where('channel','sjdngys')->select()->toArray();
         if (!$goods) {
             return $this->renderSuccess('没有需要加价的商品');
         }
-        foreach ($goods as $key => $value) {
-            $net_price = round($value['goods_price_min'] / (1 - ($rate / 100)), 0);
-            $profit = (float)$net_price - (float)$value['cost_price_min'];
-            $profit_rate = (float)$net_price > 0 ? bcmul((string)($profit / (float)$net_price) , (string)100, 2) : 0.00;
-            $goodsData = [
-                'goods_price_min' => $net_price,
-                'goods_price_max' => $net_price,
-                'line_price_min' => $net_price,
-                'line_price_max' => $net_price,
-                'profit_rate' => $profit_rate,
-                'profit' => $profit,
-                'update_time' => time()
-            ];
-            GoodsModel::where('goods_id', $value['goods_id'])->where('store_id', 0)->update($goodsData);
-            $goodsSkuData = [
-                'goods_price' => $net_price,
-                'update_time' => time()
-            ];
-            GoodsSku::where('goods_id', $value['goods_id'])->where('store_id', 0)->update();
-        }
+        GoodsAddPriceJob::dispatch([
+                'categoryIds' => $categoryIds,
+                'rate' => $rate,
+            ]);
+        // foreach ($goods as $key => $value) {
+        //     //更新总后台当前商品的价格
+        //     GoodsModel::where('goods_id', $value['goods_id'])->where('is_delete', 0)->where('store_id', 0)->update(['markup_rate' => $rate, 'update_time' => time()]);
+        //     //更新origin_goods_id为当前商品id的价格
+        //     $goods_list = GoodsModel::where('origin_goods_id', $value['goods_id'])->where('is_delete', 0)->select();
+        //     if (!$goods_list) {
+        //         continue;
+        //     }
+        //     foreach ($goods_list as $item) {
+        //         $cost_price = round($item['cost_price_min'] / (1 - ($rate / 100)), 0);
+        //         $profit = (float)$item['goods_price_min'] - (float)$cost_price;
+        //         $profit_rate = (float)$item['goods_price_min'] > 0 ? bcmul((string)($profit / (float)$item['goods_price_min']) , (string)100, 2) : 0.00;
+        //         $goodsData = [
+        //             'cost_price_min' => $cost_price,
+        //             'profit_rate' => $profit_rate,
+        //             'profit' => $profit,
+        //             'markup_rate' => $rate,
+        //             'update_time' => time()
+        //         ];
+        //         // var_dump($goodsData);
+        //         // exit();
+        //         GoodsModel::where('goods_id', $item['goods_id'])->where('store_id', $item['store_id'])->update($goodsData);
+        //         $goodsSkuData = [
+        //             'cost_price' => $cost_price,
+        //             'update_time' => time()
+        //         ];
+        //         GoodsSku::where('goods_id', $item['goods_id'])->where('store_id', $item['store_id'])->update($goodsSkuData);
+        //     }
+            
+        // }
         return $this->renderSuccess('加价成功');
     }
 
diff --git a/app/common.php b/app/common.php
index 53199696..98c782b0 100644
--- a/app/common.php
+++ b/app/common.php
@@ -594,3 +594,21 @@ function httpRequest($url, $method="GET", $postfields = null, $headers = array()
     return json_decode($response, true);
     //return array($http_code, $response,$requestinfo);
 }
+
+
+
+/**
+ * 获取加价之后的成本价
+ * [getGoodsCostPrice description]
+ * @param  [type] $cost_price [description]
+ * @param  [type] $rate       [description]
+ * @return [type]             [description]
+ */
+function getGoodsCostAndProfitAndProfitRate($net_price, $cost_price, $rate){
+    if ($rate > 0) {
+        $cost_price = round($cost_price / (1 - ($rate / 100)), 0);
+    }
+    $profit = (float)$net_price - (float)$cost_price;
+    $profit_rate = (float)$net_price > 0 ? bcmul(bcdiv((string)$profit, (string)$net_price, 4), (string)100, 2) : 0.00;
+    return [$cost_price, $profit, $profit_rate];
+}
diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php
index af7bbc41..d6225f85 100644
--- a/app/common/model/Goods.php
+++ b/app/common/model/Goods.php
@@ -254,7 +254,13 @@ class Goods extends BaseModel
             ->paginate($listRows);
 
         // 整理列表数据并返回
-        return $this->setGoodsListData($list);
+        
+        foreach ($list as &$goods) {
+            $goods['dic'] = 'admin';
+            $goods = $this->setGoodsData($goods, null);
+        }
+        return $list;
+        //return $this->setGoodsListData($list);
     }
 
     /**
@@ -584,7 +590,12 @@ class Goods extends BaseModel
     protected function setGoodsData($goodsInfo, callable $callback = null)
     {
         $channel = Channel::withoutGlobalScope()->where('code', $goodsInfo['channel'])->find();
-        $goodsInfo['channel_name'] = $channel['alias'] ?? "";
+        if (isset($goodsInfo['dic']) && $goodsInfo['dic'] == 'admin') {
+            $goodsInfo['channel_name'] = $channel['name'] ?? "";
+        } else {
+            $goodsInfo['channel_name'] = $channel['alias'] ?? "";
+        }
+        
 
         $goodsInfo['goods_images'] = helper::getArrayColumn($goodsInfo['images'], 'file');
         // 商品主图
diff --git a/app/job/controller/goods/GoodsAddPrice.php b/app/job/controller/goods/GoodsAddPrice.php
new file mode 100644
index 00000000..4dd04ab0
--- /dev/null
+++ b/app/job/controller/goods/GoodsAddPrice.php
@@ -0,0 +1,49 @@
+
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\job\controller\goods;
+
+use app\job\service\goods\GoodsAddPrice as GoodsAddPriceService;
+use cores\BaseJob;
+use cores\traits\QueueTrait;
+use cores\exception\BaseException;
+use think\db\exception\DataNotFoundException;
+use think\db\exception\DbException;
+use think\db\exception\ModelNotFoundException;
+
+/**
+ * 队列任务:商品批量导入
+ * Class Import
+ * @package app\job\controller
+ */
+class GoodsAddPrice extends BaseJob
+{
+    use QueueTrait;
+
+    /**
+     * 消费队列任务:商品导入
+     * @param array $data 参数 [index队列顺序;totalCount商品总数量;list商品列表;storeId商城ID]
+     * @return bool 返回结果
+     * @throws BaseException
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     */
+    public function handle(array $data): bool
+    {
+        $time = date('H:i:s');
+        echo "\n  ---- GoodsAddPrice ----  {$time} ----   \n";
+
+        $service = new GoodsAddPriceService;
+        return $service->batch($data['categoryIds'], $data['rate']);
+    }
+}
\ No newline at end of file
diff --git a/app/job/service/goods/GoodsAddPrice.php b/app/job/service/goods/GoodsAddPrice.php
new file mode 100644
index 00000000..6bf25a7a
--- /dev/null
+++ b/app/job/service/goods/GoodsAddPrice.php
@@ -0,0 +1,86 @@
+
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\job\service\goods;
+
+use app\common\library\helper;
+use app\common\service\BaseService;
+use app\common\model\Goods as GoodsModel;
+use app\common\model\GoodsSku;
+use app\store\model\GoodsCategoryRel;
+use cores\exception\BaseException;
+use think\facade\Log;
+use app\common\model\Channel;
+use app\common\model\Region;
+/**
+ * 服务类:商品批量导入
+ * Class Import
+ * @package app\job\service\goods
+ */
+class GoodsAddPrice extends BaseService
+{
+    /**
+     * 批量导入商品
+     * @param array $list
+     * @param int $recordId
+     * @param int $storeId
+     * @return bool
+     * @throws BaseException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function batch(array $categoryIds, int $rate): bool
+    {
+    	$goods = GoodsCategoryRel::whereIn('category_id',$categoryIds)->where('store_id', 0)->select()->toArray();
+        if (!$goods) {
+            return true;
+        }
+        $goods = GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->where('store_id', 0)->where('channel','sjdngys')->select()->toArray();
+        if (!$goods) {
+            return true;
+        }
+        foreach ($goods as $key => $value) {
+            //更新总后台当前商品的价格
+            GoodsModel::where('goods_id', $value['goods_id'])->where('is_delete', 0)->where('store_id', 0)->update(['markup_rate' => $rate, 'update_time' => time()]);
+            //更新origin_goods_id为当前商品id的价格
+            $goods_list = GoodsModel::where('origin_goods_id', $value['goods_id'])->where('is_delete', 0)->select();
+            if (!$goods_list) {
+                continue;
+            }
+            foreach ($goods_list as $item) {
+                $cost_price = round($item['cost_price_min'] / (1 - ($rate / 100)), 0);
+                $profit = (float)$item['goods_price_min'] - (float)$cost_price;
+                $profit_rate = (float)$item['goods_price_min'] > 0 ? bcmul((string)($profit / (float)$item['goods_price_min']) , (string)100, 2) : 0.00;
+                $goodsData = [
+                    'cost_price_min' => $cost_price,
+                    'profit_rate' => $profit_rate,
+                    'profit' => $profit,
+                    'markup_rate' => $rate,
+                    'update_time' => time()
+                ];
+                // var_dump($goodsData);
+                // exit();
+                GoodsModel::where('goods_id', $item['goods_id'])->where('store_id', $item['store_id'])->update($goodsData);
+                $goodsSkuData = [
+                    'cost_price' => $cost_price,
+                    'update_time' => time()
+                ];
+                GoodsSku::where('goods_id', $item['goods_id'])->where('store_id', $item['store_id'])->update($goodsSkuData);
+            }
+            
+        }
+        return true;
+    }
+
+   
+}
\ No newline at end of file

From 14301327060b14e724149e7e3ea22b025a0c195a Mon Sep 17 00:00:00 2001
From: ztt <835303992@qq.com>
Date: Mon, 27 May 2024 10:14:01 +0800
Subject: [PATCH 04/13] ES

---
 app/command/SyncGoodsToEs.php               |  23 ++
 app/common/library/elasticsearch/Client.php | 183 ++++++++++++
 app/common/service/GoodsEs.php              | 146 ++++++++++
 composer.json                               |   3 +-
 composer.lock                               | 301 +++++++++++++++++++-
 config/console.php                          |   1 +
 vendor/services.php                         |   6 +-
 7 files changed, 658 insertions(+), 5 deletions(-)
 create mode 100644 app/command/SyncGoodsToEs.php
 create mode 100644 app/common/library/elasticsearch/Client.php
 create mode 100644 app/common/service/GoodsEs.php

diff --git a/app/command/SyncGoodsToEs.php b/app/command/SyncGoodsToEs.php
new file mode 100644
index 00000000..6255698c
--- /dev/null
+++ b/app/command/SyncGoodsToEs.php
@@ -0,0 +1,23 @@
+setName('syncGoodsToEs')
+            ->setDescription('同步商品数据到ES');
+    }
+
+
+    protected function execute(Input $input, Output $output)
+    {
+        $output->writeln('syncGoodsToEs');
+    }
+
+}
\ No newline at end of file
diff --git a/app/common/library/elasticsearch/Client.php b/app/common/library/elasticsearch/Client.php
new file mode 100644
index 00000000..0d84acf5
--- /dev/null
+++ b/app/common/library/elasticsearch/Client.php
@@ -0,0 +1,183 @@
+client = ClientBuilder::create()->setHosts([self::ES_HOST_NAME])->build();
+    }
+
+    private function __clone() {
+
+    }
+
+    public static function getInstance(){
+        if (is_null(self::$instance)) {
+            self::$instance = new self();
+        }
+        return self::$instance;
+    }
+
+    public function existsIndex(String $index_name) {
+        $params = [
+            'index' => $index_name
+        ];
+        return $this->client->indices()->exists($params);
+    }
+
+    /**
+     * 创建索引
+     */
+    public function createIndex(String $index_name, array $mapping = []): array
+    {
+        if ($this->existsIndex($index_name)) {
+            throw new Exception('索引已存在'. $index_name);
+        }
+
+        //只能创建一次
+        $params = [
+            'index' => $index_name,
+            'body' => [
+                'settings' => [
+                    'number_of_shards' => 5,
+                    'number_of_replicas' => 1
+                ],
+                'mappings' => $mapping
+            ]
+        ];
+        return $this->client->indices()->create($params);
+    }
+
+    /**
+     * 删除索引
+     */
+    public function deleteIndex(String $index_name = ''): array{
+        $params = ['index' => $index_name];
+        return $this->client->indices()->delete($params);
+    }
+
+    /**
+     * 添加文档
+     * @param $id
+     * @param $doc ['id'=>100, 'title'=>'phone']
+     * @param string $index_name
+     * @param string $type_name
+     */
+    public function addDoc($id, $doc, string $index_name = 'gyx_ik', string $type_name = '_doc'): array
+    {
+        $params = [
+            'index' => $index_name,
+            'type' => $type_name,
+            'id' => $id,
+            'body' => $doc
+        ];
+
+        return $this->client->index($params);
+    }
+
+    /**
+     * 判断文档存在
+     * @param int $id
+     * @param string $index_name
+     * @param string $type_name
+     * @return bool
+     */
+    public function existsDoc(int $id = 1, string $index_name = 'gyx_ik', string $type_name = '_doc'): bool
+    {
+        $params = [
+            'index' => $index_name,
+            'type' => $type_name,
+            'id' => $id
+        ];
+
+        return $this->client->exists($params);
+
+    }
+
+    /**
+     * 获取文档
+     * @param int $id
+     * @param string $index_name
+     * @param string $type_name
+     * @return array
+     */
+    public function getDoc(int $id = 1, string $index_name = 'gyx_ik', string $type_name = '_doc'): array
+    {
+        $params = [
+            'index' => $index_name,
+            'type' => $type_name,
+            'id' => $id
+        ];
+
+        return $this->client->get($params);
+    }
+
+    /**
+     * 更新文档
+     * @param int $id
+     * @param string $index_name
+     * @param string $type_name
+     * @param array $body
+     * @return array
+     */
+    public function updateDoc(int $id = 1, array $body = [], string $index_name = 'gyx_ik', string $type_name = '_doc'): array
+    {
+        //  可以灵活添加新字段,最好不要乱添加
+        $params = [
+            'index' => $index_name,
+            'type' => $type_name,
+            'id' => $id,
+            'body' => $body
+        ];
+
+        return $this->client->update($params);
+    }
+
+    /**
+     * 删除文档
+     * @param int $id
+     * @param string $index_name
+     * @param string $type_name
+     * @return array
+     */
+    public function deleteDoc(int $id = 1, string $index_name = 'gyx_ik', string $type_name = '_doc'): array
+    {
+        $params = [
+            'index' => $index_name,
+            'type' => $type_name,
+            'id' => $id
+        ];
+
+        return $this->client->delete($params);
+    }
+
+
+    /**
+     * 搜索文档:分页,排序,权重,过滤
+     * @param string $index_name
+     * @param string $type_name
+     * @param array $body
+     * @return array
+     */
+    public function searchDoc(array $body = [], string $index_name = "gyx_ik", string $type_name = "_doc"): array
+    {
+        $params = [
+            'index' => $index_name,
+            'type' => $type_name,
+            'body' => $body
+        ];
+
+        return $this->client->search($params);
+    }
+}
diff --git a/app/common/service/GoodsEs.php b/app/common/service/GoodsEs.php
new file mode 100644
index 00000000..8e6f6233
--- /dev/null
+++ b/app/common/service/GoodsEs.php
@@ -0,0 +1,146 @@
+esService = Client::getInstance();
+    }
+
+    /**
+     * 查询商品列表
+     * @param $params
+     * @return
+     */
+    public function list($params)
+    {
+        $page = 1;
+        $limit = 10;
+        $body = [
+            'query' => [
+                'match_all' => []
+            ],
+            'from' => ($page - 1) * $limit,
+            'size' => $limit,
+            'sort' => [
+                'id' => [
+                    'order' => 'desc'
+                ]
+            ]
+        ];
+        return $this->esService->searchDoc($body);
+    }
+
+
+
+
+    /**
+     * 更新商品
+     */
+    public function updateDoc($goods_id)
+    {
+        $goods_id = 1;
+        $doc = [
+            'id' => $goods_id,
+            'video_title' => '少爷的甜蜜良药',
+            'director' => '吴宇森',
+            'intro' => '吴宇森导演的《少爷的甜蜜良药》是吴宇森导演的经典作品,讲述了一个boyfriend和girlfriend的故事,boyfriend因为工作原因,被拒了girlfriend的offer,然后boyfriend和girlfriend一起去一个地方,然后boyfriend和girlfriend',
+            'cover' => 'https://oss-duanju-file.luochen.com/cover/202404/62249c6a-5f57-45cf-90ac-be6de5890ce0.jpg?x-oss-process=image/resize,m_fixed,h_400,w_360',
+            'episode_count' => '12',
+            'wechat_vid' => 'wx_vid_1',
+            'duration' => '01:02:03',
+            'service_types' => '2,3',
+        ];
+        $res = $this->esService->updateDoc($goods_id, $doc);
+        var_dump($res);
+    }
+
+
+    /**
+     * 创建商品
+     * @return
+     */
+    public function createDoc($goods_id)
+    {
+        $goods_id = 1;
+        $doc = [
+            'id' => $goods_id,
+            'video_title' => '少爷的甜蜜良药',
+            'director' => '吴宇森',
+            'intro' => '吴宇森导演的《少爷的甜蜜良药》是吴宇森导演的经典作品,讲述了一个boyfriend和girlfriend的故事,boyfriend因为工作原因,被拒了girlfriend的offer,然后boyfriend和girlfriend一起去一个地方,然后boyfriend和girlfriend',
+            'cover' => 'https://oss-duanju-file.luochen.com/cover/202404/62249c6a-5f57-45cf-90ac-be6de5890ce0.jpg?x-oss-process=image/resize,m_fixed,h_400,w_360',
+            'episode_count' => '12',
+            'wechat_vid' => 'wx_vid_1',
+            'duration' => '01:02:03',
+            'service_types' => '2,3',
+        ];
+        $res = $this->esService->addDoc($goods_id, $doc);
+        var_dump($res);
+    }
+
+    /**
+     * 删除商品
+     */
+    public function deleteDoc($goods_id)
+    {
+        $res = $this->esService->deleteDoc($goods_id);
+        var_dump($res);
+    }
+
+
+
+    /**
+     * 创建商品Index
+     * @return void
+     * @throws Exception
+     */
+    function createGoodsIndex()
+    {
+        $mapping = [
+            'properties' => [
+                'id' => [
+                    'type' => 'keyword'
+                ],
+                'video_title' => [
+                    'type' => 'text',
+                    "analyzer" => "ik_smart"
+                ],
+                'director' => [
+                    'type' => 'text',
+                    "analyzer" => "ik_smart"
+                ],
+                'intro' => [
+                    'type' => 'text',
+                    "analyzer" => "ik_smart"
+                ],
+                'cover' => [
+                    'type' => 'keyword'
+                ],
+                'episode_count' => [
+                    'type' => 'keyword'
+                ],
+                'wechat_vid' => [
+                    'type' => 'keyword'
+                ],
+                'duration' => [
+                    'type' => 'keyword'
+                ],
+                'service_types' => [
+                    'type' => 'keyword'
+                ],
+            ]
+        ];
+
+        $res = $this->esService->createIndex('video_list', $mapping);
+        var_dump($res);
+    }
+
+
+
+}
\ No newline at end of file
diff --git a/composer.json b/composer.json
index d87578df..71f1ccae 100644
--- a/composer.json
+++ b/composer.json
@@ -53,7 +53,8 @@
         "overtrue/easy-sms": "^2.0",
         "overtrue/wechat": "~4.0",
         "alipaysdk/easysdk": "^2.2",
-        "wechatpay/wechatpay": "^1.4"
+        "wechatpay/wechatpay": "^1.4",
+        "elasticsearch/elasticsearch": "v8.6.0"
     },
     "require-dev": {
         "symfony/var-dumper": "^4.2"
diff --git a/composer.lock b/composer.lock
index 2059ec81..f0edd536 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "6a7996d88fd82c5b30b1a2ce37fdcce9",
+    "content-hash": "b5ed7820a7c4b5d436edd224b891a3ba",
     "packages": [
         {
             "name": "adbario/php-dot-notation",
@@ -432,6 +432,117 @@
             },
             "time": "2021-07-05T04:03:22+00:00"
         },
+        {
+            "name": "elastic/transport",
+            "version": "v8.8.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/elastic/elastic-transport-php.git",
+                "reference": "cdf9f63a16ec6bfb4c881ab89aa0e2a61fb7c20b"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/elastic/elastic-transport-php/zipball/cdf9f63a16ec6bfb4c881ab89aa0e2a61fb7c20b",
+                "reference": "cdf9f63a16ec6bfb4c881ab89aa0e2a61fb7c20b",
+                "shasum": ""
+            },
+            "require": {
+                "composer-runtime-api": "^2.0",
+                "php": "^7.4 || ^8.0",
+                "php-http/discovery": "^1.14",
+                "php-http/httplug": "^2.3",
+                "psr/http-client": "^1.0",
+                "psr/http-factory": "^1.0",
+                "psr/http-message": "^1.0 || ^2.0",
+                "psr/log": "^1 || ^2 || ^3"
+            },
+            "require-dev": {
+                "nyholm/psr7": "^1.5",
+                "php-http/mock-client": "^1.5",
+                "phpstan/phpstan": "^1.4",
+                "phpunit/phpunit": "^9.5"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Elastic\\Transport\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "description": "HTTP transport PHP library for Elastic products",
+            "keywords": [
+                "PSR_17",
+                "elastic",
+                "http",
+                "psr-18",
+                "psr-7",
+                "transport"
+            ],
+            "support": {
+                "issues": "https://github.com/elastic/elastic-transport-php/issues",
+                "source": "https://github.com/elastic/elastic-transport-php/tree/v8.8.0"
+            },
+            "time": "2023-11-08T10:51:51+00:00"
+        },
+        {
+            "name": "elasticsearch/elasticsearch",
+            "version": "v8.6.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/elastic/elasticsearch-php.git",
+                "reference": "03b145a3fd1dc984d7c2c79638c9257b1a17f8b7"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/elastic/elasticsearch-php/zipball/03b145a3fd1dc984d7c2c79638c9257b1a17f8b7",
+                "reference": "03b145a3fd1dc984d7c2c79638c9257b1a17f8b7",
+                "shasum": ""
+            },
+            "require": {
+                "elastic/transport": "^8.5",
+                "guzzlehttp/guzzle": "^7.0",
+                "php": "^7.4 || ^8.0",
+                "psr/http-client": "^1.0",
+                "psr/http-message": "^1.0",
+                "psr/log": "^1|^2|^3"
+            },
+            "require-dev": {
+                "ext-yaml": "*",
+                "ext-zip": "*",
+                "mockery/mockery": "^1.5",
+                "nyholm/psr7": "^1.5",
+                "php-http/mock-client": "^1.5",
+                "phpstan/phpstan": "^1.4",
+                "phpunit/phpunit": "^9.5",
+                "symfony/finder": "~4.0",
+                "symfony/http-client": "^5.0|^6.0"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Elastic\\Elasticsearch\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "description": "PHP Client for Elasticsearch",
+            "keywords": [
+                "client",
+                "elastic",
+                "elasticsearch",
+                "search"
+            ],
+            "support": {
+                "issues": "https://github.com/elastic/elasticsearch-php/issues",
+                "source": "https://github.com/elastic/elasticsearch-php/tree/v8.6.0"
+            },
+            "time": "2022-10-18T13:38:48+00:00"
+        },
         {
             "name": "ezyang/htmlpurifier",
             "version": "v4.14.0",
@@ -1983,6 +2094,194 @@
             "abandoned": "w7corp/easywechat",
             "time": "2021-12-27T13:56:47+00:00"
         },
+        {
+            "name": "php-http/discovery",
+            "version": "1.19.4",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/php-http/discovery.git",
+                "reference": "0700efda8d7526335132360167315fdab3aeb599"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/php-http/discovery/zipball/0700efda8d7526335132360167315fdab3aeb599",
+                "reference": "0700efda8d7526335132360167315fdab3aeb599",
+                "shasum": ""
+            },
+            "require": {
+                "composer-plugin-api": "^1.0|^2.0",
+                "php": "^7.1 || ^8.0"
+            },
+            "conflict": {
+                "nyholm/psr7": "<1.0",
+                "zendframework/zend-diactoros": "*"
+            },
+            "provide": {
+                "php-http/async-client-implementation": "*",
+                "php-http/client-implementation": "*",
+                "psr/http-client-implementation": "*",
+                "psr/http-factory-implementation": "*",
+                "psr/http-message-implementation": "*"
+            },
+            "require-dev": {
+                "composer/composer": "^1.0.2|^2.0",
+                "graham-campbell/phpspec-skip-example-extension": "^5.0",
+                "php-http/httplug": "^1.0 || ^2.0",
+                "php-http/message-factory": "^1.0",
+                "phpspec/phpspec": "^5.1 || ^6.1 || ^7.3",
+                "sebastian/comparator": "^3.0.5 || ^4.0.8",
+                "symfony/phpunit-bridge": "^6.4.4 || ^7.0.1"
+            },
+            "type": "composer-plugin",
+            "extra": {
+                "class": "Http\\Discovery\\Composer\\Plugin",
+                "plugin-optional": true
+            },
+            "autoload": {
+                "psr-4": {
+                    "Http\\Discovery\\": "src/"
+                },
+                "exclude-from-classmap": [
+                    "src/Composer/Plugin.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Márk Sági-Kazár",
+                    "email": "mark.sagikazar@gmail.com"
+                }
+            ],
+            "description": "Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations",
+            "homepage": "http://php-http.org",
+            "keywords": [
+                "adapter",
+                "client",
+                "discovery",
+                "factory",
+                "http",
+                "message",
+                "psr17",
+                "psr7"
+            ],
+            "support": {
+                "issues": "https://github.com/php-http/discovery/issues",
+                "source": "https://github.com/php-http/discovery/tree/1.19.4"
+            },
+            "time": "2024-03-29T13:00:05+00:00"
+        },
+        {
+            "name": "php-http/httplug",
+            "version": "2.4.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/php-http/httplug.git",
+                "reference": "625ad742c360c8ac580fcc647a1541d29e257f67"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/php-http/httplug/zipball/625ad742c360c8ac580fcc647a1541d29e257f67",
+                "reference": "625ad742c360c8ac580fcc647a1541d29e257f67",
+                "shasum": ""
+            },
+            "require": {
+                "php": "^7.1 || ^8.0",
+                "php-http/promise": "^1.1",
+                "psr/http-client": "^1.0",
+                "psr/http-message": "^1.0 || ^2.0"
+            },
+            "require-dev": {
+                "friends-of-phpspec/phpspec-code-coverage": "^4.1 || ^5.0 || ^6.0",
+                "phpspec/phpspec": "^5.1 || ^6.0 || ^7.0"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Http\\Client\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Eric GELOEN",
+                    "email": "geloen.eric@gmail.com"
+                },
+                {
+                    "name": "Márk Sági-Kazár",
+                    "email": "mark.sagikazar@gmail.com",
+                    "homepage": "https://sagikazarmark.hu"
+                }
+            ],
+            "description": "HTTPlug, the HTTP client abstraction for PHP",
+            "homepage": "http://httplug.io",
+            "keywords": [
+                "client",
+                "http"
+            ],
+            "support": {
+                "issues": "https://github.com/php-http/httplug/issues",
+                "source": "https://github.com/php-http/httplug/tree/2.4.0"
+            },
+            "time": "2023-04-14T15:10:03+00:00"
+        },
+        {
+            "name": "php-http/promise",
+            "version": "1.3.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/php-http/promise.git",
+                "reference": "fc85b1fba37c169a69a07ef0d5a8075770cc1f83"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/php-http/promise/zipball/fc85b1fba37c169a69a07ef0d5a8075770cc1f83",
+                "reference": "fc85b1fba37c169a69a07ef0d5a8075770cc1f83",
+                "shasum": ""
+            },
+            "require": {
+                "php": "^7.1 || ^8.0"
+            },
+            "require-dev": {
+                "friends-of-phpspec/phpspec-code-coverage": "^4.3.2 || ^6.3",
+                "phpspec/phpspec": "^5.1.2 || ^6.2 || ^7.4"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Http\\Promise\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Joel Wurtz",
+                    "email": "joel.wurtz@gmail.com"
+                },
+                {
+                    "name": "Márk Sági-Kazár",
+                    "email": "mark.sagikazar@gmail.com"
+                }
+            ],
+            "description": "Promise used for asynchronous HTTP requests",
+            "homepage": "http://httplug.io",
+            "keywords": [
+                "promise"
+            ],
+            "support": {
+                "issues": "https://github.com/php-http/promise/issues",
+                "source": "https://github.com/php-http/promise/tree/1.3.1"
+            },
+            "time": "2024-03-15T13:55:21+00:00"
+        },
         {
             "name": "phpoffice/phpspreadsheet",
             "version": "1.22.0",
diff --git a/config/console.php b/config/console.php
index d64e0746..dbcf36f3 100644
--- a/config/console.php
+++ b/config/console.php
@@ -12,5 +12,6 @@ return [
         'CalDealerTime' => 'app\command\CalDealerTime',
         'UpdateCollectGoodsPrice' => 'app\command\UpdateCollectGoodsPrice',
         'SyncStoreBasicData' => 'app\command\SyncStoreBasicData',
+        'syncGoodsToEs' => 'app\command\syncGoodsToEs',
     ],
 ];
diff --git a/vendor/services.php b/vendor/services.php
index 846f604f..face640b 100755
--- a/vendor/services.php
+++ b/vendor/services.php
@@ -1,6 +1,6 @@
- 'think\\app\\Service',
   1 => 'think\\queue\\Service',

From 1c592065a0f3b9630b9a1c4a5ad3baec9046380d Mon Sep 17 00:00:00 2001
From: lqmac 
Date: Mon, 27 May 2024 12:16:00 +0800
Subject: [PATCH 05/13] 1

---
 app/admin/controller/Controller.php        |  4 +-
 app/admin/controller/Goods.php             | 88 ++++++++++++----------
 app/common/model/Goods.php                 | 14 +++-
 app/common/model/sharp/Goods.php           |  2 +-
 app/job/controller/goods/GoodsAddPrice.php |  2 +-
 app/job/service/goods/Collector.php        |  8 +-
 app/job/service/goods/GoodsAddPrice.php    | 70 ++++++++++-------
 config/log.php                             |  2 +-
 config/queue.php                           |  2 +-
 9 files changed, 114 insertions(+), 78 deletions(-)

diff --git a/app/admin/controller/Controller.php b/app/admin/controller/Controller.php
index 604966a8..9fcad99f 100644
--- a/app/admin/controller/Controller.php
+++ b/app/admin/controller/Controller.php
@@ -79,8 +79,8 @@ class Controller extends BaseController
             if (strpos($this->admin['user']['channel'], 'jd') !== false) {
                 $list = Channel::where('status', 1)->whereIn('code',[$this->admin['user']['channel'],'zy'])->select();
                 //苏宁账号可以看到苏宁和自营的
-            } elseif($this->admin['user']['channel'] == 'sn'){
-                $list = Channel::where('status', 1)->whereIn('code',['sn','zy'])->select();
+            } elseif(strpos($this->admin['user']['channel'], 'sn') !== false){
+                $list = Channel::where('status', 1)->whereIn('code',[$this->admin['user']['channel'],'zy'])->select();
                 //新阙通信账号可以看到新阙通信和自营的
             } elseif($this->admin['user']['channel'] == 'xqtx'){
                 $list = Channel::where('status', 1)->whereIn('code',['xqtx','zy'])->select();
diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php
index 714ab055..a4da2e11 100644
--- a/app/admin/controller/Goods.php
+++ b/app/admin/controller/Goods.php
@@ -349,48 +349,60 @@ class Goods extends Controller
     public function addPrice(array $categoryIds, int $rate){
         // ini_set('memory_limit', '1024M');
         // set_time_limit(0);
-        $goods = GoodsCategoryRel::whereIn('category_id',$categoryIds)->where('store_id', 0)->select()->toArray();
+        $platform = $this->getUserPlatform();
+        $channels = $platform ? array_column($platform->toArray(), "code") : [];
+        $goods = GoodsModel::alias('g')
+                    ->join('goods_category_rel c', 'g.goods_id = c.goods_id')
+                    ->where('c.store_id',0)
+                    ->where('g.is_delete',0)
+                    ->whereIn('c.category_id',$categoryIds)
+                    ->whereIn('g.channel', $channels)
+                    ->limit(100)
+                    ->select()
+                    ->toArray();
         if (!$goods) {
             return $this->renderSuccess('没有需要加价的商品');
         }
-        $goods = GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->where('store_id', 0)->where('channel','sjdngys')->select()->toArray();
-        if (!$goods) {
-            return $this->renderSuccess('没有需要加价的商品');
+        //更新总后台当前商品的价格
+        GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->update(['markup_rate' => $rate, 'update_time' => time()]);
+        foreach ($goods as $key => $value) {
+            //更新origin_goods_id为当前商品id的价格
+            $goods_list = GoodsModel::where('origin_goods_id', $value['goods_id'])
+                        ->where('is_delete', 0)
+                        ->field(['goods_id','cost_price_min','goods_price_min','markup_rate'])
+                        ->select()
+                        ->toArray();
+
+            if (!$goods_list) {
+                continue;
+            }
+            $item = $goods_list[0];
+            if ($item['markup_rate'] > 0) {
+                $item['cost_price_min'] = round($item['cost_price_min'] * (1 - ($rate / 100)), 0);
+            }
+            $cost_price = round($item['cost_price_min'] / (1 - ($rate / 100)), 0);
+            $profit = (float)$item['goods_price_min'] - (float)$cost_price;
+            $profit_rate = (float)$item['goods_price_min'] > 0 ? bcmul((string)($profit / (float)$item['goods_price_min']) , (string)100, 2) : 0.00;
+            $goodsData = [
+                'cost_price_min' => $cost_price,
+                'profit_rate' => $profit_rate,
+                'profit' => $profit,
+                'markup_rate' => $rate,
+                'update_time' => time()
+            ];
+            GoodsModel::whereIn('goods_id', array_column($goods_list, "goods_id"))->update($goodsData);
+            $goodsSkuData = [
+                'cost_price' => $cost_price,
+                'update_time' => time()
+            ];
+            GoodsSku::whereIn('goods_id', array_column($goods_list, "goods_id"))->update($goodsSkuData);
+           
         }
-        GoodsAddPriceJob::dispatch([
-                'categoryIds' => $categoryIds,
-                'rate' => $rate,
-            ]);
-        // foreach ($goods as $key => $value) {
-        //     //更新总后台当前商品的价格
-        //     GoodsModel::where('goods_id', $value['goods_id'])->where('is_delete', 0)->where('store_id', 0)->update(['markup_rate' => $rate, 'update_time' => time()]);
-        //     //更新origin_goods_id为当前商品id的价格
-        //     $goods_list = GoodsModel::where('origin_goods_id', $value['goods_id'])->where('is_delete', 0)->select();
-        //     if (!$goods_list) {
-        //         continue;
-        //     }
-        //     foreach ($goods_list as $item) {
-        //         $cost_price = round($item['cost_price_min'] / (1 - ($rate / 100)), 0);
-        //         $profit = (float)$item['goods_price_min'] - (float)$cost_price;
-        //         $profit_rate = (float)$item['goods_price_min'] > 0 ? bcmul((string)($profit / (float)$item['goods_price_min']) , (string)100, 2) : 0.00;
-        //         $goodsData = [
-        //             'cost_price_min' => $cost_price,
-        //             'profit_rate' => $profit_rate,
-        //             'profit' => $profit,
-        //             'markup_rate' => $rate,
-        //             'update_time' => time()
-        //         ];
-        //         // var_dump($goodsData);
-        //         // exit();
-        //         GoodsModel::where('goods_id', $item['goods_id'])->where('store_id', $item['store_id'])->update($goodsData);
-        //         $goodsSkuData = [
-        //             'cost_price' => $cost_price,
-        //             'update_time' => time()
-        //         ];
-        //         GoodsSku::where('goods_id', $item['goods_id'])->where('store_id', $item['store_id'])->update($goodsSkuData);
-        //     }
-            
-        // }
+        // GoodsAddPriceJob::dispatch([
+        //         'categoryIds' => $categoryIds,
+        //         'rate' => $rate,
+        //         'channels' => $channels,
+        //     ]);
         return $this->renderSuccess('加价成功');
     }
 
diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php
index d6225f85..1068c6ac 100644
--- a/app/common/model/Goods.php
+++ b/app/common/model/Goods.php
@@ -455,12 +455,15 @@ class Goods extends BaseModel
         $params['status'] > 0 && $filter[] = ['status', '=', (int)$params['status']];
         $a = 1;
         // 商品分类
-        if ($params['categoryId'] > 0) {
+        if ($params['categoryId'] > 0 || (isset($params['fliter_condition']) && $params['fliter_condition'])) {
             // 关联商品与分类关系记录表
             $GoodsCategoryRelName = (new GoodsCategoryRelModel())->getName();
             $query->join($GoodsCategoryRelName, "{$GoodsCategoryRelName}.goods_id = {$this->name}.goods_id");
-            // 设置分类ID条件
-            $query->where('goods_category_rel.category_id', 'in', explode(",", (string)$params['categoryId']));
+            if ($params['categoryId'] > 0) {
+                // 设置分类ID条件
+                $query->where('goods_category_rel.category_id', 'in', explode(",", (string)$params['categoryId']));
+            }
+            
 
         }
         if (isset($param['goodsIds']) && $param['goodsIds'] !== '') {
@@ -591,7 +594,7 @@ class Goods extends BaseModel
     {
         $channel = Channel::withoutGlobalScope()->where('code', $goodsInfo['channel'])->find();
         if (isset($goodsInfo['dic']) && $goodsInfo['dic'] == 'admin') {
-            $goodsInfo['channel_name'] = $channel['name'] ?? "";
+            $goodsInfo['channel_name'] = (isset($channel['name'])&& $channel['name']) ? $channel['alias']."-".$channel['name'] : "";
         } else {
             $goodsInfo['channel_name'] = $channel['alias'] ?? "";
         }
@@ -602,6 +605,9 @@ class Goods extends BaseModel
         $goodsInfo['goods_image'] = $goodsInfo['goods_images'] ? current($goodsInfo['goods_images'])['preview_url'] : "";
         // 商品销量(实际显示=初始虚拟销量+实际销量)
         $goodsInfo['goods_sales'] = $goodsInfo['sales_initial'] + $goodsInfo['sales_actual'];
+        if (in_array($goodsInfo['channel'], ['sn','sn1']) && $goodsInfo['link_other']) {
+            $goodsInfo['link'] = $goodsInfo['link_other'];
+        }
 //        //商品价格判断
 //        if (UserService::isLogin()) {
 //            if (UserService::isStore()) {//店主
diff --git a/app/common/model/sharp/Goods.php b/app/common/model/sharp/Goods.php
index a58523f2..084920a2 100644
--- a/app/common/model/sharp/Goods.php
+++ b/app/common/model/sharp/Goods.php
@@ -112,7 +112,7 @@ class Goods extends BaseModel
                 $item['goods_image'] = !empty($item['goods']['goods_image']) ? $item['goods']['goods_image'] : '';
                 // 秒杀商品原价 (获取主商品价格)
                 //$item['original_price'] = !empty($item['goods']['original_price']) ? $item['goods']['original_price']: $item['goods']['goods_price_min'];
-                $item['original_price'] = !empty($item['goods']['original_price']) ?? $item['goods']['goods_price_min'];
+                $item['original_price'] = isset($item['goods']['original_price']) ? $item['goods']['original_price'] : $item['goods']['goods_price_min'];
                 // 回调函数
                 is_callable($callback) && call_user_func($callback, $item);
             }
diff --git a/app/job/controller/goods/GoodsAddPrice.php b/app/job/controller/goods/GoodsAddPrice.php
index 4dd04ab0..776d28ef 100644
--- a/app/job/controller/goods/GoodsAddPrice.php
+++ b/app/job/controller/goods/GoodsAddPrice.php
@@ -44,6 +44,6 @@ class GoodsAddPrice extends BaseJob
         echo "\n  ---- GoodsAddPrice ----  {$time} ----   \n";
 
         $service = new GoodsAddPriceService;
-        return $service->batch($data['categoryIds'], $data['rate']);
+        return $service->batch($data['categoryIds'], $data['rate'], $data['channels']);
     }
 }
\ No newline at end of file
diff --git a/app/job/service/goods/Collector.php b/app/job/service/goods/Collector.php
index b59078f1..62fdc707 100644
--- a/app/job/service/goods/Collector.php
+++ b/app/job/service/goods/Collector.php
@@ -260,7 +260,8 @@ class Collector extends BaseService
 
         $original['cost_price'] = $form['cost_price_min'];
         $data['link_other'] = $url;
-        $data['goods_no'] = $original['goods_sku_no'];
+        
+        
         $data['content'] = $original['content'];
 
         //重新计算利润和利润率
@@ -285,6 +286,7 @@ class Collector extends BaseService
         ];
         //新阙通信的数据
         if ($goods->channel == "xqtx") {
+            $data['goods_no'] = $original['goods_sku_no'];
             //goods
             $data['stock_total'] = $form['stock_total'];
             $data['goods_name'] = $original['goods_name'];
@@ -294,11 +296,15 @@ class Collector extends BaseService
             $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;
+            $data['link'] = $data['link_other'];
             unset($data['link_other']);
 
             //sku
             $goodsSku['stock_num'] = $form['stock_total'];
             //unset($goodsSku['goods_price']);
+        } else {
+            //京东价拖
+            $data['goods_no_other'] = $original['goods_sku_no'];
         }
         // var_dump($data);
         // var_dump($goodsSku);
diff --git a/app/job/service/goods/GoodsAddPrice.php b/app/job/service/goods/GoodsAddPrice.php
index 6bf25a7a..20460fdf 100644
--- a/app/job/service/goods/GoodsAddPrice.php
+++ b/app/job/service/goods/GoodsAddPrice.php
@@ -39,46 +39,58 @@ class GoodsAddPrice extends BaseService
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function batch(array $categoryIds, int $rate): bool
+    public function batch(array $categoryIds, int $rate, array $channels): bool
     {
-    	$goods = GoodsCategoryRel::whereIn('category_id',$categoryIds)->where('store_id', 0)->select()->toArray();
-        if (!$goods) {
-            return true;
-        }
-        $goods = GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->where('store_id', 0)->where('channel','sjdngys')->select()->toArray();
+        ini_set('memory_limit', '1024M');
+        set_time_limit(0);
+        $goods = GoodsModel::alias('g')
+                    ->join('goods_category_rel c', 'g.goods_id = c.goods_id')
+                    ->where('c.store_id',0)
+                    ->where('g.is_delete',0)
+                    ->whereIn('c.category_id', $categoryIds)
+                    ->whereIn('g.channel',$channels)
+                    ->order("g.goods_id asc")
+                    ->select()
+                    ->toArray();
         if (!$goods) {
             return true;
         }
+        //更新总后台当前商品的价格
+        GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->update(['markup_rate' => $rate, 'update_time' => time()]);
         foreach ($goods as $key => $value) {
-            //更新总后台当前商品的价格
-            GoodsModel::where('goods_id', $value['goods_id'])->where('is_delete', 0)->where('store_id', 0)->update(['markup_rate' => $rate, 'update_time' => time()]);
             //更新origin_goods_id为当前商品id的价格
-            $goods_list = GoodsModel::where('origin_goods_id', $value['goods_id'])->where('is_delete', 0)->select();
+            $goods_list = GoodsModel::where('origin_goods_id', $value['goods_id'])
+                        ->where('is_delete', 0)
+                        ->field(['goods_id','cost_price_min','goods_price_min','markup_rate'])
+                        ->select()
+                        ->toArray();
+
             if (!$goods_list) {
                 continue;
             }
-            foreach ($goods_list as $item) {
-                $cost_price = round($item['cost_price_min'] / (1 - ($rate / 100)), 0);
-                $profit = (float)$item['goods_price_min'] - (float)$cost_price;
-                $profit_rate = (float)$item['goods_price_min'] > 0 ? bcmul((string)($profit / (float)$item['goods_price_min']) , (string)100, 2) : 0.00;
-                $goodsData = [
-                    'cost_price_min' => $cost_price,
-                    'profit_rate' => $profit_rate,
-                    'profit' => $profit,
-                    'markup_rate' => $rate,
-                    'update_time' => time()
-                ];
-                // var_dump($goodsData);
-                // exit();
-                GoodsModel::where('goods_id', $item['goods_id'])->where('store_id', $item['store_id'])->update($goodsData);
-                $goodsSkuData = [
-                    'cost_price' => $cost_price,
-                    'update_time' => time()
-                ];
-                GoodsSku::where('goods_id', $item['goods_id'])->where('store_id', $item['store_id'])->update($goodsSkuData);
+            $item = $goods_list[0];
+            if ($item['markup_rate'] > 0) {
+                $item['cost_price_min'] = round($item['cost_price_min'] * (1 - ($rate / 100)), 0);
             }
-            
+            $cost_price = round($item['cost_price_min'] / (1 - ($rate / 100)), 0);
+            $profit = (float)$item['goods_price_min'] - (float)$cost_price;
+            $profit_rate = (float)$item['goods_price_min'] > 0 ? bcmul((string)($profit / (float)$item['goods_price_min']) , (string)100, 2) : 0.00;
+            $goodsData = [
+                'cost_price_min' => $cost_price,
+                'profit_rate' => $profit_rate,
+                'profit' => $profit,
+                'markup_rate' => $rate,
+                'update_time' => time()
+            ];
+            GoodsModel::whereIn('goods_id', array_column($goods_list, "goods_id"))->update($goodsData);
+            $goodsSkuData = [
+                'cost_price' => $cost_price,
+                'update_time' => time()
+            ];
+            GoodsSku::whereIn('goods_id', array_column($goods_list, "goods_id"))->update($goodsSkuData);
+           
         }
+
         return true;
     }
 
diff --git a/config/log.php b/config/log.php
index 0bdb0303..6fe24583 100644
--- a/config/log.php
+++ b/config/log.php
@@ -7,7 +7,7 @@ return [
     // 默认日志记录通道
     'default'      => env('log.channel', 'file'),
     // 日志记录级别
-    'level'        => [],
+    'level'        => ['error', 'sql', 'info'],
     // 日志类型记录的通道 ['error'=>'email',...]
     'type_channel' => [],
     // 关闭全局日志写入
diff --git a/config/queue.php b/config/queue.php
index 7982d77c..52900d43 100644
--- a/config/queue.php
+++ b/config/queue.php
@@ -27,7 +27,7 @@ return [
             'host'       => env('redis.hostname', '127.0.0.1'),
             'port'       => env('redis.hostport', '6379'),
             'password'   => env('redis.password', ''),
-            'select'     => env('redis.select', '0'),
+            'select'     => 1,//env('redis.select', '0'),
             'timeout'    => 0,
             'persistent' => false,
             'retry_after' => 60, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒

From 3f3c00178e8b2ad8f663757086ea668124b23f64 Mon Sep 17 00:00:00 2001
From: "yangsai@163.com" <2624183217@qq.com>
Date: Mon, 27 May 2024 13:18:26 +0800
Subject: [PATCH 06/13] =?UTF-8?q?YS:=E4=BD=A3=E9=87=91=E4=BD=93=E7=8E=B0BU?=
 =?UTF-8?q?G?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/api/controller/Dealer.php          | 2 +-
 app/api/controller/dealer/Withdraw.php | 2 +-
 app/api/model/Setting.php              | 3 ++-
 app/api/model/dealer/Withdraw.php      | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/app/api/controller/Dealer.php b/app/api/controller/Dealer.php
index a49659df..951ad334 100644
--- a/app/api/controller/Dealer.php
+++ b/app/api/controller/Dealer.php
@@ -28,7 +28,7 @@ class Dealer extends Controller
 {
     // 当前用户信息
     /* @var UserModel $user */
-    private UserModel $user;
+    public  $user;
 
     // 当前分销商信息
     private ?DealerUserModel $dealer;
diff --git a/app/api/controller/dealer/Withdraw.php b/app/api/controller/dealer/Withdraw.php
index 7315cb77..75210f21 100644
--- a/app/api/controller/dealer/Withdraw.php
+++ b/app/api/controller/dealer/Withdraw.php
@@ -57,7 +57,7 @@ class Withdraw extends Controller
         // 提交提现申请
         $model = new WithdrawModel;
         $data = $this->request->post();
-        if ($model->submit($dealer, $data)) {
+        if ($model->submit($dealer, $data['from'])) {
             return $this->renderSuccess([], '提现申请已提交成功,请等待审核');
         }
         return $this->renderError($model->getError() ?: '提交失败');
diff --git a/app/api/model/Setting.php b/app/api/model/Setting.php
index a81bd165..63c6d651 100644
--- a/app/api/model/Setting.php
+++ b/app/api/model/Setting.php
@@ -55,7 +55,8 @@ class Setting extends SettingModel
      */
     public static function getFinanceCommission()
     {
-        return static::getItem(SettingEnum::TRADE)['finance_process'];
+        $return = empty(static::getItem(SettingEnum::TRADE)['finance_process'])?'':static::getItem(SettingEnum::TRADE)['finance_process'];
+        return $return;
     }
 
     /**
diff --git a/app/api/model/dealer/Withdraw.php b/app/api/model/dealer/Withdraw.php
index a40c2c99..36ece79e 100644
--- a/app/api/model/dealer/Withdraw.php
+++ b/app/api/model/dealer/Withdraw.php
@@ -76,7 +76,7 @@ class Withdraw extends WithdrawModel
         //手续费
         if (empty($data['is_invoice'])) {
             $commission = \app\api\model\Setting::getFinanceCommission();
-            if (empty($commission)) {
+            if (!empty($commission)) {
                 $data['commission_price'] = bcmath($data['money'], $commission / 100, 2);
             }
         }

From 9b275bf6b4602a690432101680a3b1efaf09d79e Mon Sep 17 00:00:00 2001
From: "yangsai@163.com" <2624183217@qq.com>
Date: Mon, 27 May 2024 13:26:58 +0800
Subject: [PATCH 07/13] YS

---
 app/api/controller/dealer/Withdraw.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/api/controller/dealer/Withdraw.php b/app/api/controller/dealer/Withdraw.php
index 75210f21..799f6775 100644
--- a/app/api/controller/dealer/Withdraw.php
+++ b/app/api/controller/dealer/Withdraw.php
@@ -57,7 +57,7 @@ class Withdraw extends Controller
         // 提交提现申请
         $model = new WithdrawModel;
         $data = $this->request->post();
-        if ($model->submit($dealer, $data['from'])) {
+        if ($model->submit($dealer, $data['form'])) {
             return $this->renderSuccess([], '提现申请已提交成功,请等待审核');
         }
         return $this->renderError($model->getError() ?: '提交失败');

From b06c5c07ff704651ab2e9e2c88c7a6fc473c8fb4 Mon Sep 17 00:00:00 2001
From: lqmac 
Date: Mon, 27 May 2024 13:37:06 +0800
Subject: [PATCH 08/13] =?UTF-8?q?=E5=8A=A0=E4=BB=B7=E7=8E=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/admin/controller/Goods.php          | 46 ++++---------------------
 app/common/model/Goods.php              |  2 ++
 app/job/service/goods/GoodsAddPrice.php |  4 +--
 config/queue.php                        |  2 +-
 4 files changed, 11 insertions(+), 43 deletions(-)

diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php
index a4da2e11..4206f05c 100644
--- a/app/admin/controller/Goods.php
+++ b/app/admin/controller/Goods.php
@@ -363,46 +363,12 @@ class Goods extends Controller
         if (!$goods) {
             return $this->renderSuccess('没有需要加价的商品');
         }
-        //更新总后台当前商品的价格
-        GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->update(['markup_rate' => $rate, 'update_time' => time()]);
-        foreach ($goods as $key => $value) {
-            //更新origin_goods_id为当前商品id的价格
-            $goods_list = GoodsModel::where('origin_goods_id', $value['goods_id'])
-                        ->where('is_delete', 0)
-                        ->field(['goods_id','cost_price_min','goods_price_min','markup_rate'])
-                        ->select()
-                        ->toArray();
-
-            if (!$goods_list) {
-                continue;
-            }
-            $item = $goods_list[0];
-            if ($item['markup_rate'] > 0) {
-                $item['cost_price_min'] = round($item['cost_price_min'] * (1 - ($rate / 100)), 0);
-            }
-            $cost_price = round($item['cost_price_min'] / (1 - ($rate / 100)), 0);
-            $profit = (float)$item['goods_price_min'] - (float)$cost_price;
-            $profit_rate = (float)$item['goods_price_min'] > 0 ? bcmul((string)($profit / (float)$item['goods_price_min']) , (string)100, 2) : 0.00;
-            $goodsData = [
-                'cost_price_min' => $cost_price,
-                'profit_rate' => $profit_rate,
-                'profit' => $profit,
-                'markup_rate' => $rate,
-                'update_time' => time()
-            ];
-            GoodsModel::whereIn('goods_id', array_column($goods_list, "goods_id"))->update($goodsData);
-            $goodsSkuData = [
-                'cost_price' => $cost_price,
-                'update_time' => time()
-            ];
-            GoodsSku::whereIn('goods_id', array_column($goods_list, "goods_id"))->update($goodsSkuData);
-           
-        }
-        // GoodsAddPriceJob::dispatch([
-        //         'categoryIds' => $categoryIds,
-        //         'rate' => $rate,
-        //         'channels' => $channels,
-        //     ]);
+        
+        GoodsAddPriceJob::dispatch([
+                'categoryIds' => $categoryIds,
+                'rate' => $rate,
+                'channels' => $channels,
+            ]);
         return $this->renderSuccess('加价成功');
     }
 
diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php
index 1068c6ac..38ba52ea 100644
--- a/app/common/model/Goods.php
+++ b/app/common/model/Goods.php
@@ -353,6 +353,7 @@ class Goods extends BaseModel
                 ->field($field)
                 ->where('is_delete', '=', 0)
                 ->where($str)
+                ->group("goods.goods_id")
                 ->order($sort)
                 ->paginate($listRows);
         } else {
@@ -361,6 +362,7 @@ class Goods extends BaseModel
                 ->alias($this->name)
                 ->field($field)
                 ->where('is_delete', '=', 0)
+                ->group("goods.goods_id")
                 ->order($sort)
                 ->paginate($listRows);
         }
diff --git a/app/job/service/goods/GoodsAddPrice.php b/app/job/service/goods/GoodsAddPrice.php
index 20460fdf..3fce33af 100644
--- a/app/job/service/goods/GoodsAddPrice.php
+++ b/app/job/service/goods/GoodsAddPrice.php
@@ -41,8 +41,8 @@ class GoodsAddPrice extends BaseService
      */
     public function batch(array $categoryIds, int $rate, array $channels): bool
     {
-        ini_set('memory_limit', '1024M');
-        set_time_limit(0);
+        // ini_set('memory_limit', '1024M');
+        // set_time_limit(0);
         $goods = GoodsModel::alias('g')
                     ->join('goods_category_rel c', 'g.goods_id = c.goods_id')
                     ->where('c.store_id',0)
diff --git a/config/queue.php b/config/queue.php
index 52900d43..1833e678 100644
--- a/config/queue.php
+++ b/config/queue.php
@@ -30,7 +30,7 @@ return [
             'select'     => 1,//env('redis.select', '0'),
             'timeout'    => 0,
             'persistent' => false,
-            'retry_after' => 60, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒
+            'retry_after' => 300, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒
         ],
     ],
     'failed'      => [

From 1978607b1770df567785105944ef0f6e44b91ed0 Mon Sep 17 00:00:00 2001
From: lqmac 
Date: Mon, 27 May 2024 14:48:02 +0800
Subject: [PATCH 09/13] =?UTF-8?q?=E5=8A=A0=E4=BB=B7=E7=8E=87=E5=A4=84?=
 =?UTF-8?q?=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/admin/controller/Goods.php             | 24 +++++++++++++++-------
 app/job/controller/goods/GoodsAddPrice.php |  2 +-
 app/job/service/goods/GoodsAddPrice.php    | 20 +++++++++---------
 config/queue.php                           |  2 +-
 4 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php
index 4206f05c..63099b90 100644
--- a/app/admin/controller/Goods.php
+++ b/app/admin/controller/Goods.php
@@ -351,24 +351,34 @@ class Goods extends Controller
         // set_time_limit(0);
         $platform = $this->getUserPlatform();
         $channels = $platform ? array_column($platform->toArray(), "code") : [];
-        $goods = GoodsModel::alias('g')
+        $goodsList = GoodsModel::alias('g')
                     ->join('goods_category_rel c', 'g.goods_id = c.goods_id')
                     ->where('c.store_id',0)
                     ->where('g.is_delete',0)
                     ->whereIn('c.category_id',$categoryIds)
                     ->whereIn('g.channel', $channels)
-                    ->limit(100)
+                    ->field(['g.goods_id'])
+                    ->group('g.goods_id')
+                    ->order("g.goods_id asc")
+                    // ->limit(100)
                     ->select()
                     ->toArray();
-        if (!$goods) {
+        if (!$goodsList) {
             return $this->renderSuccess('没有需要加价的商品');
         }
-        
-        GoodsAddPriceJob::dispatch([
-                'categoryIds' => $categoryIds,
+        // 分批每次导入20条
+        $limit = 50;
+        // 根据商品总数量计算需要的队列任务数量
+        $jobCount = \count($goodsList) / $limit;
+        // 逐次发布队列任务
+        for ($i = 0; $i < $jobCount; $i++) {
+            $data = array_slice($goodsList, $i * $limit, $limit);
+            GoodsAddPriceJob::dispatch([
+                'list' => $data,
                 'rate' => $rate,
-                'channels' => $channels,
             ]);
+        }
+        
         return $this->renderSuccess('加价成功');
     }
 
diff --git a/app/job/controller/goods/GoodsAddPrice.php b/app/job/controller/goods/GoodsAddPrice.php
index 776d28ef..c3d24f2c 100644
--- a/app/job/controller/goods/GoodsAddPrice.php
+++ b/app/job/controller/goods/GoodsAddPrice.php
@@ -44,6 +44,6 @@ class GoodsAddPrice extends BaseJob
         echo "\n  ---- GoodsAddPrice ----  {$time} ----   \n";
 
         $service = new GoodsAddPriceService;
-        return $service->batch($data['categoryIds'], $data['rate'], $data['channels']);
+        return $service->batch($data['list'], $data['rate']);
     }
 }
\ No newline at end of file
diff --git a/app/job/service/goods/GoodsAddPrice.php b/app/job/service/goods/GoodsAddPrice.php
index 3fce33af..c9d9cc24 100644
--- a/app/job/service/goods/GoodsAddPrice.php
+++ b/app/job/service/goods/GoodsAddPrice.php
@@ -39,19 +39,19 @@ class GoodsAddPrice extends BaseService
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function batch(array $categoryIds, int $rate, array $channels): bool
+    public function batch(array $goods, int $rate): bool
     {
         // ini_set('memory_limit', '1024M');
         // set_time_limit(0);
-        $goods = GoodsModel::alias('g')
-                    ->join('goods_category_rel c', 'g.goods_id = c.goods_id')
-                    ->where('c.store_id',0)
-                    ->where('g.is_delete',0)
-                    ->whereIn('c.category_id', $categoryIds)
-                    ->whereIn('g.channel',$channels)
-                    ->order("g.goods_id asc")
-                    ->select()
-                    ->toArray();
+        // $goods = GoodsModel::alias('g')
+        //             ->join('goods_category_rel c', 'g.goods_id = c.goods_id')
+        //             ->where('c.store_id',0)
+        //             ->where('g.is_delete',0)
+        //             ->whereIn('c.category_id', $categoryIds)
+        //             ->whereIn('g.channel',$channels)
+        //             ->order("g.goods_id asc")
+        //             ->select()
+        //             ->toArray();
         if (!$goods) {
             return true;
         }
diff --git a/config/queue.php b/config/queue.php
index 1833e678..52900d43 100644
--- a/config/queue.php
+++ b/config/queue.php
@@ -30,7 +30,7 @@ return [
             'select'     => 1,//env('redis.select', '0'),
             'timeout'    => 0,
             'persistent' => false,
-            'retry_after' => 300, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒
+            'retry_after' => 60, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒
         ],
     ],
     'failed'      => [

From 937cdd5ad4dbee736d68a7a61cbca4dfab836a08 Mon Sep 17 00:00:00 2001
From: ztt <835303992@qq.com>
Date: Mon, 27 May 2024 15:58:52 +0800
Subject: [PATCH 10/13] 1

---
 app/command/SyncGoodsToEs.php               |   7 +-
 app/common/library/elasticsearch/Client.php | 602 +++++++++++++++++++-
 app/common/service/GoodsEs.php              |  39 +-
 config/console.php                          |   2 +-
 4 files changed, 620 insertions(+), 30 deletions(-)

diff --git a/app/command/SyncGoodsToEs.php b/app/command/SyncGoodsToEs.php
index 6255698c..136cfedf 100644
--- a/app/command/SyncGoodsToEs.php
+++ b/app/command/SyncGoodsToEs.php
@@ -2,7 +2,10 @@
 
 namespace app\command;
 
+use app\common\service\GoodsEs;
 use think\console\Command;
+use think\console\Output;
+use think\console\Input;
 
 class SyncGoodsToEs extends Command
 {
@@ -17,7 +20,9 @@ class SyncGoodsToEs extends Command
 
     protected function execute(Input $input, Output $output)
     {
-        $output->writeln('syncGoodsToEs');
+        $goodsService = new GoodsEs();
+        $goods = $goodsService->list([]);
+        var_dump($goods);
     }
 
 }
\ No newline at end of file
diff --git a/app/common/library/elasticsearch/Client.php b/app/common/library/elasticsearch/Client.php
index 0d84acf5..5c042c22 100644
--- a/app/common/library/elasticsearch/Client.php
+++ b/app/common/library/elasticsearch/Client.php
@@ -11,13 +11,34 @@ class Client
     const ES_HOST_NAME = '114.55.95.135:9200';
 
 
-    private static Client $instance;
+    private static  $instance;
 
-    private function __construct()
+    /**
+     * @var 索引名称
+     */
+    protected $index;
+
+
+    public $alias;
+
+    protected $retries = 2;
+
+    /**
+     * 查询参数
+     * @var array $queryParams
+     */
+    protected $queryParams = [];
+
+    private $debug;
+
+    public function __construct()
     {
+
+        var_dump(self::ES_HOST_NAME);
         $this->client = ClientBuilder::create()->setHosts([self::ES_HOST_NAME])->build();
     }
 
+
     private function __clone() {
 
     }
@@ -29,6 +50,81 @@ class Client
         return self::$instance;
     }
 
+    /**
+     * 查询条件
+     * @param $params
+     * @return $this
+     */
+    public function select($params = '')
+    {
+        $this->queryParams['select'] = str_replace(' ', '', trim($params, " ,\t\r\n"));
+        return $this;
+    }
+
+    /**
+     * 分页
+     * @param $number
+     * @return $this
+     */
+    public function from($number = 0)
+    {
+        $this->queryParams['from'] = $number ? ($number-1)*10 : 0;
+        return $this;
+    }
+
+    /**
+     * 页码
+     * @param $number
+     * @return $this
+     */
+    public function size($number = 10)
+    {
+        $this->queryParams['size'] = $number;
+        return $this;
+    }
+
+    public function equal($params = [])
+    {
+        $this->queryParams['equal'][] = $params;
+        return $this;
+    }
+
+    public function in($params = [])
+    {
+        $this->queryParams['in'][] = $params;
+        return $this;
+    }
+
+    public function like($params = [])
+    {
+        $this->queryParams['like'][] = $params;
+        return $this;
+    }
+
+    public function orlike($params = [])
+    {
+        $this->queryParams['orlike'][] = $params;
+        return $this;
+    }
+
+    public function order($params = [])
+    {
+        $this->queryParams['order'][] = $params;
+        return $this;
+    }
+
+    /**
+     * 根据条件删除文档
+     * @param array $params
+     * @return array
+     */
+
+    public function deleteDoc($params = [])
+    {
+        return $this->client->deleteByQuery($params);
+    }
+
+
     public function existsIndex(String $index_name) {
         $params = [
             'index' => $index_name
@@ -67,6 +163,182 @@ class Client
         return $this->client->indices()->delete($params);
     }
 
+    /**
+     * 根据id删除文档
+     * @param int $id
+     * @return array
+     */
+    public function deleteDocById($id = 0)
+    {
+        $params = [
+            'index' => $this->index,
+            'id' => $id
+        ];
+        $response = $this->client->delete($params);
+        return $response;
+    }
+
+    /**
+     * 组装查询条件
+     * @param array $params
+     * @return $this
+     */
+    private function parseQueryParams()
+    {
+        $queryParams = [
+            'index' => $this->index,
+            'body' => [
+                'query' => [
+                    'bool' => [
+                        'must' => [],
+                        'filter' => []
+                    ]
+                ]
+            ],
+            'from' => $this->queryParams['from'] ?? 0,
+            'size' => $this->queryParams['size'] ?? 10
+        ];
+
+        $filter = $must = [];
+        if (!empty($this->queryParams['select'])) {
+            $queryParams['_source'] = explode(',', $this->queryParams['select']);
+        }
+
+        if (!empty($this->queryParams['equal'])) {
+            foreach ($this->queryParams['equal'] as $key => $row) {
+                foreach ($row as $filed => $value) {
+                    $filter[] = [
+                        'term' => [$filed => $value]
+                    ];
+                }
+            }
+        }
+
+        if (!empty($this->queryParams['in'])) {
+            foreach ($this->queryParams['in'] as $key => $row) {
+                foreach ($row as $filed => $value) {
+                    $filter[] = [
+                        'terms' => [$filed => array_values(array_unique(array_filter($value)))]
+                    ];
+                }
+            }
+        }
+
+        if (!empty($this->queryParams['like'])) {
+            foreach ($this->queryParams['like'] as $key => $row) {
+                foreach ($row as $filed => $value) {
+                    /*$must[] = [
+
+                        'wildcard' => [$filed => '*'. $value. '*']
+
+                    ];*/
+                    $must[] = [
+//                        'match' => [$filed => $value]
+                        'match_phrase' => [$filed => $value]
+                    ];
+                }
+            }
+
+            $queryParams['body']['query']['bool']['must'] = $must;
+
+        }
+
+        if (!empty($this->queryParams['orlike'])) {
+            foreach ($this->queryParams['orlike'] as $key => $row) {
+                foreach ($row as $filed => $value) {
+                    $orlike[] = [
+                        'match_phrase' => [$filed => $value]
+                    ];
+                }
+            }
+
+            $queryParams['body']['query']['bool']['must']['bool']['should'] = $orlike;
+        }
+
+        if (!empty($this->queryParams['order'])) {
+            $queryParams['body']['sort'] = [
+                key($this->queryParams['order']) => [
+                    'order' => current($this->queryParams['order'])
+                ]
+            ];
+        }
+
+        $queryParams['body']['query']['bool']['filter'] = $filter;
+
+        $this->queryParams = $queryParams;
+
+        return $this;
+
+    }
+
+
+    /**
+     * @param bool $isTotal isTotal=true时, 返回总数
+     * @return array|string
+     */
+
+    public function query($isTotal = false)
+    {
+        try {
+            $this->parseQueryParams();
+
+            if ($this->debug) {
+                return \GuzzleHttp\json_encode($this->queryParams);
+            }
+
+            if ($isTotal === true) {
+
+                unset(
+
+                    $this->queryParams['from'],
+
+                    $this->queryParams['size'],
+
+                    $this->queryParams['_source']
+
+                );
+
+                $count = $this->client->count($this->queryParams);
+
+                return (int)$count['count'];
+
+            }
+
+            if (!empty($this->queryParams)) {
+
+                $result = $this->client->search($this->queryParams);
+
+                if (!empty($result['hits']['hits'])) {
+
+                    $return = [];
+
+                    foreach ($result['hits']['hits'] as $row) {
+
+                        $return[] = $row['_source'];
+
+                    }
+
+                    return $return;
+
+                } else {
+
+                    return [];
+
+                }
+
+            }
+
+        } catch (\Exception $e) {
+
+            $msg = $e->getMessage();
+
+            $msg = '服务器开小差了~';
+
+            throw new Exception($msg);
+
+        }
+    }
+
     /**
      * 添加文档
      * @param $id
@@ -86,6 +358,36 @@ class Client
         return $this->client->index($params);
     }
 
+    public function getIndex()
+    {
+        return $this->index;
+    }
+
+    /**
+     * 返回ES实例
+     */
+
+    public static function setEs($index = '')
+    {
+        $class = get_called_class();
+        if (!self::$instance || !self::$instance instanceof $class) {
+            self::$instance = new static();
+        }
+        if ($index) {
+            self::$instance->index = $index;
+        }
+        return self::$instance;
+
+    }
+
+    protected function settings()
+    {
+        return [
+            'number_of_shards' => 1,
+            'number_of_replicas' => 0
+        ];
+    }
+
     /**
      * 判断文档存在
      * @param int $id
@@ -144,40 +446,306 @@ class Client
         return $this->client->update($params);
     }
 
+
     /**
-     * 删除文档
-     * @param int $id
+     * 搜索文档:分页,排序,权重,过滤
      * @param string $index_name
      * @param string $type_name
+     * @param array $body
      * @return array
      */
-    public function deleteDoc(int $id = 1, string $index_name = 'gyx_ik', string $type_name = '_doc'): array
+    public function searchDoc(array $body = [], string $index_name = "goods_list", string $type_name = "_doc"): array
     {
         $params = [
             'index' => $index_name,
             'type' => $type_name,
-            'id' => $id
+            'body' => $body
         ];
 
-        return $this->client->delete($params);
+        return $this->client->search($params);
+    }
+
+    /**
+
+     * @return bool
+
+     * @throws Exception
+
+     */
+
+    public function createIndexNew($mapping)
+    {
+        try {
+            $params = [
+                'index' => $this->index
+            ];
+
+            $check = $this->indices()->exists($params);
+
+            if ($check) {
+                throw new Exception('index: ' . $this->index . ' already exists');
+            }
+
+            $params = [
+                'index' => $this->index,
+                'body' => [
+                    'settings' => $this->settings(),
+                    'mappings' => [
+                        '_source' => [
+                            'enabled' => true,
+                        ],
+                        'properties' => $mapping
+                    ]
+                ]
+            ];
+
+            $result = $this->indices()->create($params);
+
+            return $result['acknowledged'] === true;
+
+        } catch (\Exception $e) {
+
+            throw new Exception($e->getMessage());
+
+        }
+
     }
 
+    /**
+
+     * 删除索引
+
+     *
+
+     * @return bool
+
+     * @throws Missing404Exception
+
+     */
+
+    public function deleteIndexNew()
+    {
+
+        try {
+
+            $params = [
+
+                'index' => $this->index
+
+            ];
+
+            $check = $this->indices()->exists($params);
+
+            if (!$check) {
+
+                return true;
+
+            }
+
+            $result = $this->indices()->delete([
+
+                'index' => $this->index
+
+            ]);
+
+            return $result['acknowledged'] === true;
+
+        } catch (Missing404Exception $e) {
+
+            throw new Missing404Exception('no such index ' . $this->index);
+
+        }
+
+    }
 
     /**
-     * 搜索文档:分页,排序,权重,过滤
-     * @param string $index_name
-     * @param string $type_name
-     * @param array $body
-     * @return array
+
+     * 批量写入
+
+     * type 1.增加/修改 2.删除
+
+     * $data = [
+
+     *      ['id' => 1, 'name' => 'llf', 'age' => 30],
+
+     *      ['id' => 1, 'name' => 'llf', 'age' => 30],
+
+     *      ['id' => 1, 'name' => 'llf', 'age' => 30],
+
+     *      ['id' => 1, 'name' => 'llf', 'age' => 30],
+
+     * ];
+
+     * @param array $data
+
+     */
+
+    public function doBulkDocument($type = 1,$data = [])
+
+    {
+
+        try {
+
+            $params = ['body' => []];
+
+            if($type == 1){
+
+                foreach ($data as $key => $row) {
+
+                    $params['body'][] = [
+
+                        'index' => [
+
+                            '_index' => $this->index,
+
+                            '_id' => $row['info_id'].'-'.$row['info_type']
+
+                        ]
+
+                    ];
+
+                    $params['body'][] = $row;
+
+                    if (($key+1)%10000 == 0) {
+
+                        $this->client->bulk($params);
+
+                        $params = ['body' => []];
+
+                    }
+
+                }
+
+            }else{
+
+                foreach ($data as $key => $row) {
+
+                    $params['body'][] = [
+
+                        'delete' => [
+
+                            '_index' => $this->index,
+
+                            '_id' => $row['info_id'].'-'.$row['info_type']
+
+                        ]
+
+                    ];
+
+                }
+
+            }
+
+            if (!empty($params['body'])) {
+
+                $this->client->bulk($params);
+
+                return true;
+
+            }
+
+        } catch (\Exception $e) {
+
+            throw new Exception($e->getMessage());
+
+        }
+
+    }
+
+    /**
+
+     * @return array @todo
+
      */
-    public function searchDoc(array $body = [], string $index_name = "gyx_ik", string $type_name = "_doc"): array
+
+    public function updateIndex()
+
     {
+
+        $putParams = [
+
+            'index' => $this->index,
+
+            //'type' => '_doc',
+
+            'body' => [
+
+                'properties' => $this->mappings()
+
+            ]
+
+        ];
+
+        return $this->indices()->putMapping($putParams);
+
+    }
+
+    /**
+
+     * 方便调试, 直接返回拼接的query
+
+     * @return $this
+
+     */
+
+    public function setDebug()
+
+    {
+
+        $this->debug = true;
+
+        return $this;
+
+    }
+
+    private function indices()
+
+    {
+
+        return $this->client->indices();
+
+    }
+
+    public function analyze($text = '')
+
+    {
+
         $params = [
-            'index' => $index_name,
-            'type' => $type_name,
-            'body' => $body
+
+            'index' => $this->index,
+
+            'body' => [
+
+                'analyzer' => 'ik_smart',
+
+                'text' => $text
+
+            ]
+
         ];
 
-        return $this->client->search($params);
+        return $this->indices()->analyze($params);
+
+    }
+
+    public function update($id = 0, $updateParams = [])
+
+    {
+
+        $params = [
+
+            'index' => $this->index,
+
+            'id' => $id,
+
+            'body' => [
+
+                'doc' => $updateParams
+
+            ]
+
+        ];
+
+        return $this->client->update($params);
     }
 }
diff --git a/app/common/service/GoodsEs.php b/app/common/service/GoodsEs.php
index 8e6f6233..f5106e6f 100644
--- a/app/common/service/GoodsEs.php
+++ b/app/common/service/GoodsEs.php
@@ -8,9 +8,11 @@ class GoodsEs
 {
     private Client $esService;
 
+    private $index_name = 'goods_list';
+
     public function __construct()
     {
-        $this->esService = Client::getInstance();
+        $this->esService = Client::setEs('goods_List');
     }
 
     /**
@@ -34,7 +36,13 @@ class GoodsEs
                 ]
             ]
         ];
-        return $this->esService->searchDoc($body);
+
+        return $this->esService
+            ->equal(['title' => 1])
+            ->from(0)
+            ->size(10)
+            ->order(['id' => 'desc'])
+            ->query($body);
     }
 
 
@@ -43,7 +51,7 @@ class GoodsEs
     /**
      * 更新商品
      */
-    public function updateDoc($goods_id)
+    public function update($goods_id)
     {
         $goods_id = 1;
         $doc = [
@@ -61,12 +69,22 @@ class GoodsEs
         var_dump($res);
     }
 
+    /**
+     * 查询商品详情
+     */
+    public function detail($goods_id)
+    {
+        $goods_id = 1;
+        $res = $this->esService->getDoc($goods_id);
+        var_dump($res);
+    }
+
 
     /**
      * 创建商品
      * @return
      */
-    public function createDoc($goods_id)
+    public function create($goods_id)
     {
         $goods_id = 1;
         $doc = [
@@ -87,7 +105,7 @@ class GoodsEs
     /**
      * 删除商品
      */
-    public function deleteDoc($goods_id)
+    public function delete($goods_id)
     {
         $res = $this->esService->deleteDoc($goods_id);
         var_dump($res);
@@ -104,12 +122,11 @@ class GoodsEs
     {
         $mapping = [
             'properties' => [
-                'id' => [
-                    'type' => 'keyword'
+                'goods_id' => [
+                    'type' => 'integer'
                 ],
-                'video_title' => [
-                    'type' => 'text',
-                    "analyzer" => "ik_smart"
+                'goods_type' => [
+                    'type' => 'keyword'
                 ],
                 'director' => [
                     'type' => 'text',
@@ -137,7 +154,7 @@ class GoodsEs
             ]
         ];
 
-        $res = $this->esService->createIndex('video_list', $mapping);
+        $res = $this->esService->createIndex($this->index_name, $mapping);
         var_dump($res);
     }
 
diff --git a/config/console.php b/config/console.php
index dbcf36f3..09465dc3 100644
--- a/config/console.php
+++ b/config/console.php
@@ -12,6 +12,6 @@ return [
         'CalDealerTime' => 'app\command\CalDealerTime',
         'UpdateCollectGoodsPrice' => 'app\command\UpdateCollectGoodsPrice',
         'SyncStoreBasicData' => 'app\command\SyncStoreBasicData',
-        'syncGoodsToEs' => 'app\command\syncGoodsToEs',
+        'syncGoodsToEs' => 'app\command\SyncGoodsToEs',
     ],
 ];

From 816d66254d5afd5d24e551cbd993bc7434e8d356 Mon Sep 17 00:00:00 2001
From: lqmac 
Date: Mon, 27 May 2024 20:58:26 +0800
Subject: [PATCH 11/13] =?UTF-8?q?=E5=8A=A0=E4=BB=B7=E5=92=8C=E8=AE=A2?=
 =?UTF-8?q?=E5=8D=95bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/admin/controller/Goods.php          |  2 +-
 app/api/controller/Goods.php            |  1 +
 app/api/model/Order.php                 | 10 ++++++++++
 app/job/service/goods/GoodsAddPrice.php |  7 ++++---
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php
index 63099b90..6d5d6715 100644
--- a/app/admin/controller/Goods.php
+++ b/app/admin/controller/Goods.php
@@ -357,7 +357,7 @@ class Goods extends Controller
                     ->where('g.is_delete',0)
                     ->whereIn('c.category_id',$categoryIds)
                     ->whereIn('g.channel', $channels)
-                    ->field(['g.goods_id'])
+                    ->field(['g.goods_id','g.cost_price_min'])
                     ->group('g.goods_id')
                     ->order("g.goods_id asc")
                     // ->limit(100)
diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php
index c1fe2ced..0ef059ad 100644
--- a/app/api/controller/Goods.php
+++ b/app/api/controller/Goods.php
@@ -148,6 +148,7 @@ class Goods extends Controller
                     ];
                     break;
                 default:
+                    
                     if ($goods->stock_total >= ($value['num'] ?? 1)) {
                         $res = "有货";
                     }
diff --git a/app/api/model/Order.php b/app/api/model/Order.php
index 2b187e09..3fa55aae 100644
--- a/app/api/model/Order.php
+++ b/app/api/model/Order.php
@@ -141,6 +141,11 @@ class Order extends OrderModel
             $info = $info['storeInfo']->toArray();
             foreach ($list['data'] as &$v) {
                 $v['storeInfo'] = $info;
+                $total_num = 0;
+                foreach ($v['goods'] as $value) {
+                    $total_num += $value['total_num'] ?? 0;
+                }
+                $v['total_num'] = $total_num;
                 $v['delivery'] = DeliveryModel::where('order_id', $v['order_id'])->find();
             }
         }
@@ -491,6 +496,11 @@ class Order extends OrderModel
         if (!empty($info['storeInfo'])) {
             $order->storeInfo = $info['storeInfo']->toArray();
         }
+        $total_num = 0;
+        foreach ($order->goods as $value) {
+            $total_num += $value->total_num ?? 0;
+        }
+        $order->total_num = $total_num;
         return $order;
     }
 
diff --git a/app/job/service/goods/GoodsAddPrice.php b/app/job/service/goods/GoodsAddPrice.php
index c9d9cc24..dabd7ded 100644
--- a/app/job/service/goods/GoodsAddPrice.php
+++ b/app/job/service/goods/GoodsAddPrice.php
@@ -69,9 +69,10 @@ class GoodsAddPrice extends BaseService
                 continue;
             }
             $item = $goods_list[0];
-            if ($item['markup_rate'] > 0) {
-                $item['cost_price_min'] = round($item['cost_price_min'] * (1 - ($rate / 100)), 0);
-            }
+            // if ($item['markup_rate'] > 0) {
+            //     $item['cost_price_min'] = round($item['cost_price_min'] * (1 - ($rate / 100)), 0);
+            // }
+            $item['cost_price_min'] = $value['cost_price_min'];//设置原始数据的成本价
             $cost_price = round($item['cost_price_min'] / (1 - ($rate / 100)), 0);
             $profit = (float)$item['goods_price_min'] - (float)$cost_price;
             $profit_rate = (float)$item['goods_price_min'] > 0 ? bcmul((string)($profit / (float)$item['goods_price_min']) , (string)100, 2) : 0.00;

From 83628be5a10755fb067d1b0091b46b3459be0b79 Mon Sep 17 00:00:00 2001
From: lqmac 
Date: Mon, 27 May 2024 23:46:52 +0800
Subject: [PATCH 12/13] 1

---
 app/admin/controller/Goods.php  |  8 ++++++++
 app/api/controller/Category.php |  8 ++++++++
 app/api/controller/Store.php    | 15 +++++++++++----
 app/api/model/Order.php         |  8 ++++++--
 4 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php
index 6d5d6715..cdc7d1ac 100644
--- a/app/admin/controller/Goods.php
+++ b/app/admin/controller/Goods.php
@@ -171,8 +171,16 @@ class Goods extends Controller
                 'goods_source' => $goods_sku->goods_source,
                 'is_check' => $goods_sku->is_check,
                 'delivery_time' => $goods_sku->delivery_time,
+                // 'is_pool' => $goods_sku->is_pool,
+                // 'is_sale' => $goods_sku->is_sale,
                 'update_time' => time(),
             ];
+            if ($goods_sku->is_pool == 0 || $goods_sku->is_sale == 0) {
+                $goods_data['status'] = 20;
+            }
+            if ($goods_sku->is_pool == 1 && $goods_sku->is_sale == 1) {
+                $goods_data['status'] = 10;
+            }
             GoodsModel::where('origin_goods_id', $goodsId)->update($goods_data);
             $goods_sku_data = [
                 'goods_price' => $goods_sku->goods_price_min,
diff --git a/app/api/controller/Category.php b/app/api/controller/Category.php
index c798ed76..f5fcb0b8 100644
--- a/app/api/controller/Category.php
+++ b/app/api/controller/Category.php
@@ -14,6 +14,7 @@ namespace app\api\controller;
 
 use think\response\Json;
 use app\api\model\Category as CategoryModel;
+use think\facade\Cache;
 
 /**
  * 商品分类控制器
@@ -31,13 +32,20 @@ class Category extends Controller
      */
     public function list(): Json
     {
+        $cache_key = "Category_list".$this->storeId;
+        if(Cache::has($cache_key)) {
+           $list = Cache::get($cache_key);
+           return $this->renderSuccess(compact('list'));
+        }
         $model = new CategoryModel;
         $list = $model->getListPublic($this->request->param());
+        Cache::set($cache_key, $list, 86400);
         return $this->renderSuccess(compact('list'));
     }
 
      public function childrenList(): Json
     {
+
         $model = new CategoryModel;
         $list = $model->getChildrenList($this->request->param());
         return $this->renderSuccess(compact('list'));
diff --git a/app/api/controller/Store.php b/app/api/controller/Store.php
index 01889344..402c180b 100644
--- a/app/api/controller/Store.php
+++ b/app/api/controller/Store.php
@@ -115,10 +115,17 @@ class Store extends Controller
     {
         $storeid = request()->header()['storeid'];
         $info = StoreInfoModel::where('store_id', $storeid)->find()->toArray();
-        $file = UploadFile::where('file_id', '=', $info['group_share_img_id'])->find();
-        $info['group_share_img'] = $file->preview_url;
-        $file = UploadFile::where('file_id', '=', $info['logo_image_id'])->find();
-        $info['logo_image'] = $file->preview_url;
+        $info['group_share_img'] = "";
+        if ($info['group_share_img_id']) {
+            $file = UploadFile::where('file_id', '=', $info['group_share_img_id'])->find();
+            $info['group_share_img'] = $file->preview_url;
+        }
+        $info['logo_image'] = "";
+        if ($info['logo_image_id']) {
+            $file = UploadFile::where('file_id', '=', $info['logo_image_id'])->find();
+            $info['logo_image'] = $file->preview_url;
+        }
+        
         return $this->renderSuccess($info);
     }
 
diff --git a/app/api/model/Order.php b/app/api/model/Order.php
index 3fa55aae..b284477b 100644
--- a/app/api/model/Order.php
+++ b/app/api/model/Order.php
@@ -497,9 +497,13 @@ class Order extends OrderModel
             $order->storeInfo = $info['storeInfo']->toArray();
         }
         $total_num = 0;
-        foreach ($order->goods as $value) {
-            $total_num += $value->total_num ?? 0;
+        if (isset($order->goods) && $order->goods) {
+            foreach ($order->goods as $value) {
+                $total_num += $value->total_num ?? 0;
+            }
         }
+        
+        
         $order->total_num = $total_num;
         return $order;
     }

From cfd24f99885cd65ab02165b45b62060daf9767e3 Mon Sep 17 00:00:00 2001
From: lqmac 
Date: Wed, 29 May 2024 00:09:50 +0800
Subject: [PATCH 13/13] 1

---
 app/common/model/Goods.php | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php
index 38ba52ea..9dc1b9b3 100644
--- a/app/common/model/Goods.php
+++ b/app/common/model/Goods.php
@@ -278,17 +278,26 @@ class Goods extends BaseModel
         // 设置显示的销量 goods_sales
         $query->field(['(sales_initial + sales_actual) as goods_sales', '(line_price_max - goods_price_min) as discount']);
         // 排序条件
-        $sort = $this->setQuerySort($param);
+        $sort1 = $this->setQuerySort($param);
+        // var_dump($sort);
+        // exit();
         $order = request()->get()['order'] ?? '';
         $sort = request()->get()['sort'] ?? '';
+        //商家端商品列表排序
         if ($order && $sort) {
             $sort = [
                 $sort => $order,
             ];
         } else {
-            $sort = [
-                $this->getPk() => 'desc',
-            ];
+            //小程序前台商品排序
+            if ($sort1) {
+                $sort = $sort1;
+            } else {
+                $sort = [
+                    $this->getPk() => 'desc',
+                ];
+            }
+            
         }
         // if (!empty($order)) {
         //     if ($order == 1) {