fix(search): 修复跨租户重复手机号查询报错

This commit is contained in:
yml
2026-11-29 20:07:57 +08:00
parent 2e0018b943
commit a1e6089aa5
15 changed files with 382 additions and 28 deletions
@@ -234,7 +234,7 @@ func (r *Repository) disbursementListBaseQuery(ctx context.Context, phoneKeyword
}
if phoneKeyword = strings.TrimSpace(phoneKeyword); isPhoneKeyword(phoneKeyword) {
withdrawal = withdrawal.Where("wr.user_id = (SELECT id FROM users WHERE phone = ?)", phoneKeyword)
withdrawal = withdrawal.Where("wr.user_id IN (SELECT id FROM users WHERE phone = ?)", phoneKeyword)
return db.Table("(?) AS d", withdrawal)
}
@@ -298,8 +298,8 @@ func (r *Repository) applyDisbursementFilters(db *gorm.DB, query DisbursementQue
if query.Keyword != "" {
keyword := strings.TrimSpace(query.Keyword)
if isPhoneKeyword(keyword) {
// 完整手机号只可能命中提现收款人,先经 users(phone) 唯一索引解析用户。
db = db.Where("d.source_type = ? AND d.user_id = (SELECT id FROM users WHERE phone = ?)", "withdrawal", keyword)
// 完整手机号只匹配提现收款人,先查询该手机号对应的所有租户和站点账号。
db = db.Where("d.source_type = ? AND d.user_id IN (SELECT id FROM users WHERE phone = ?)", "withdrawal", keyword)
} else {
like := "%" + keyword + "%"
db = db.Where(`(d.business_no LIKE ? OR d.payee_name LIKE ? OR d.payee_phone LIKE ?