From a4b3ee325c7354579d495bc74a777e494e5ec38c Mon Sep 17 00:00:00 2001
From: quanwei <419654421@qq.com>
Date: Fri, 06 Feb 2026 18:18:44 +0800
Subject: [PATCH] 商品可以价格面议 选择走访时显示输入走访企业名 分会添加活动时要总会审核 分类添加人数限制,添加活动选择了填写人数限制的分类时活动名额下显示该分类人数限制为15 同一个企业30天内只能走访一次,在30天内走访同一个企业时提示该企业已被走访xx天后才可以从新走访

---
 admin/app/api/model/supplier/Supplier.php |   38 +++++++++++++++++++++++++++++++++++---
 1 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/admin/app/api/model/supplier/Supplier.php b/admin/app/api/model/supplier/Supplier.php
index df7fbfb..200dd39 100644
--- a/admin/app/api/model/supplier/Supplier.php
+++ b/admin/app/api/model/supplier/Supplier.php
@@ -117,6 +117,7 @@
         $product_model = new ProductModel();
         foreach ($list as &$v) {
             $productList = $product_model->with(['image.file'])
+                ->where('is_gift_pack', '=', 0)
                 ->where([
                     'shop_supplier_id' => $v['shop_supplier_id'],
                     'product_status' => 10,
@@ -402,11 +403,21 @@
                 ->where('is_delete', '=', 0)
                 ->group('shop_supplier_id')
                 ->buildSql();
+            
+            // 添加评论数量子查询
+            $commentSubQuery = \app\common\model\product\Comment::alias('c')
+                ->field('shop_supplier_id, COUNT(*) as comment_count')
+                ->where('status', '=', 1) // 已审核通过的评论
+                ->where('is_delete', '=', 0)
+                ->group('shop_supplier_id')
+                ->buildSql();
                 
             $listRaw = $baseQuery
                 ->join([$subQuery => 'avg_sub'], 's.shop_supplier_id = avg_sub.shop_supplier_id', 'LEFT')
+                ->join([$commentSubQuery => 'comment_count_sub'], 's.shop_supplier_id = comment_count_sub.shop_supplier_id', 'LEFT')
                 ->field("s.shop_supplier_id,s.supplier_type,s.name as supplier_name,s.fav_count,logo_id,category_id,server_score,product_sales,address,link_phone,longitude,latitude,supplier_type,
-                    COALESCE(avg_sub.avg_price, 0) as avg_price")
+                    COALESCE(avg_sub.avg_price, 0) as avg_price,
+                    COALESCE(comment_count_sub.comment_count, 0) as comment_count")
                 ->with(['logo', 'category']);
                 
             // 添加价格范围筛选条件
@@ -422,17 +433,37 @@
             $listRaw = $listRaw->order('avg_sub.avg_price ' . ($priceSortOrder ?? 'desc') . ', s.create_time desc')
                 ->paginate($param);
         } else if ($needDistanceSort) {
+            // 添加评论数量子查询
+            $commentSubQuery = \app\common\model\product\Comment::alias('c')
+                ->field('shop_supplier_id, COUNT(*) as comment_count')
+                ->where('status', '=', 1) // 已审核通过的评论
+                ->where('is_delete', '=', 0)
+                ->group('shop_supplier_id')
+                ->buildSql();
+            
             // 使用子查询计算距离并排序(需要数据库支持地理函数)
             $listRaw = $baseQuery
+                ->join([$commentSubQuery => 'comment_count_sub'], 's.shop_supplier_id = comment_count_sub.shop_supplier_id', 'LEFT')
                 ->field("s.shop_supplier_id,s.supplier_type,s.name as supplier_name,s.fav_count,logo_id,category_id,server_score,product_sales,address,link_phone,longitude,latitude,supplier_type,
-                    IF(s.latitude > 0 AND s.longitude > 0, " . $user_latitude . ", 99999) as dist_sort")
+                    IF(s.latitude > 0 AND s.longitude > 0, " . $user_latitude . ", 99999) as dist_sort,
+                    COALESCE(comment_count_sub.comment_count, 0) as comment_count")
                 ->with(['logo', 'category'])
                 ->order('dist_sort asc, s.create_time desc')
                 ->paginate($param);
         } else {
+            // 添加评论数量子查询
+            $commentSubQuery = \app\common\model\product\Comment::alias('c')
+                ->field('shop_supplier_id, COUNT(*) as comment_count')
+                ->where('status', '=', 1) // 已审核通过的评论
+                ->where('is_delete', '=', 0)
+                ->group('shop_supplier_id')
+                ->buildSql();
+            
             // 普通查询
             $listRaw = $baseQuery
-                ->field("s.shop_supplier_id,s.supplier_type,s.name as supplier_name,s.fav_count,logo_id,category_id,server_score,product_sales,address,link_phone,longitude,latitude,supplier_type")
+                ->join([$commentSubQuery => 'comment_count_sub'], 's.shop_supplier_id = comment_count_sub.shop_supplier_id', 'LEFT')
+                ->field("s.shop_supplier_id,s.supplier_type,s.name as supplier_name,s.fav_count,logo_id,category_id,server_score,product_sales,address,link_phone,longitude,latitude,supplier_type,
+                    COALESCE(comment_count_sub.comment_count, 0) as comment_count")
                 ->order($sort)
                 ->paginate($param);
         }
@@ -535,6 +566,7 @@
                 $v['server_score_text'] = ' 超赞';
             }
             $v['comment'] = $v['fav_count'] ?: 0;
+            $v['comment_count'] = isset($v['comment_count']) ? $v['comment_count'] : 0; // 评论数量
             $v['average_price'] = $average_price; // 人均消费,根据历史订单计算
             $v['distance'] = $distance; // 距离,根据经纬度计算
             $v['max_reduce_price'] = $max_reduce_price; // 最高减价,根据优惠券计算

--
Gitblit v1.9.2