From c807b99a912249e75db7e1a4eec314c86e705c85 Mon Sep 17 00:00:00 2001 From: huang Date: Sat, 11 Apr 2026 11:06:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BD=A3=E9=87=91?= =?UTF-8?q?=E6=98=8E=E7=BB=86=E5=88=97=E8=A1=A8=E5=A4=9A=E8=A1=A8=20JOIN?= =?UTF-8?q?=20=E6=97=B6=20shop=5Fid=20=E5=AD=97=E6=AE=B5=E6=AD=A7=E4=B9=89?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ListByShopID 使用 tb_commission_record.shop_id 限定表名, 避免与 JOIN 的 tb_order/tb_iot_card/tb_device 表中同名字段冲突, 解决 SQLSTATE 42702 ambiguous column reference 错误。 Co-authored-by: Sisyphus --- internal/store/postgres/commission_record_store.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/store/postgres/commission_record_store.go b/internal/store/postgres/commission_record_store.go index 1e0ea1c..6e47fb5 100644 --- a/internal/store/postgres/commission_record_store.go +++ b/internal/store/postgres/commission_record_store.go @@ -74,7 +74,9 @@ func (s *CommissionRecordStore) ListByShopID(ctx context.Context, opts *store.Qu Joins("LEFT JOIN tb_order o ON tb_commission_record.order_id = o.id AND o.deleted_at IS NULL"). Joins("LEFT JOIN tb_iot_card ic ON tb_commission_record.iot_card_id = ic.id AND ic.deleted_at IS NULL"). Joins("LEFT JOIN tb_device d ON tb_commission_record.device_id = d.id AND d.deleted_at IS NULL") - query = middleware.ApplyShopFilter(ctx, query) + if shopIDs := middleware.GetSubordinateShopIDs(ctx); len(shopIDs) > 0 { + query = query.Where("tb_commission_record.shop_id IN ?", shopIDs) + } if filters != nil { if filters.ShopID > 0 {