fix(schema): 修正 order_cash 表连接条件

- 移除使用 MAX ID 子查询连接 order_cash 的方式
- 采用普通 JOIN 按 order_number 字段连接 order_cash 表
- 修复因表无 id 字段导致的连接错误问题
- 优化查询语句结构,提升可读性和维护性
This commit is contained in:
zhouyonggao 2025-12-18 13:41:00 +08:00
parent 99ac6e3c2b
commit 3002590491
1 changed files with 2 additions and 2 deletions

View File

@ -13,8 +13,8 @@ func (marketingSchema) BuildJoins(need map[string]bool, main string) []string {
out = append(out, " LEFT JOIN `order_detail` ON `order_detail`.order_number = `order`.order_number")
}
if need["order_cash"] {
// MAX ID 子查询去重
out = append(out, " LEFT JOIN `order_cash` ON `order_cash`.id = (SELECT MAX(oc2.id) FROM `order_cash` oc2 WHERE oc2.order_number = `order`.order_number)")
// order_cash无id字段使用普通JOIN
out = append(out, " LEFT JOIN `order_cash` ON `order_cash`.order_number = `order`.order_number")
}
if need["order_voucher"] {
// MAX ID 子查询去重