"优化用户余额查询的JOIN方式并添加分组"

This commit is contained in:
lzh 2025-06-24 17:08:36 +08:00
parent f55af5f719
commit 1885d2b8dc

View File

@ -114,8 +114,8 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.Bun
Joins("LEFT JOIN fiee_bundle.bundle_balance AS bb on u.id = bb.user_id").
Joins("LEFT JOIN `micro-account`.`real_name` rn on u.real_name_id = rn.id").
Joins("LEFT JOIN bundle_order_records bor on bor.uuid = bb.order_uuid").
Joins("INNER JOIN (?) AS t ON bor.customer_id = t.customer_id AND bor.created_at = t.max_created_time", subQuery).
Where("rn.name IS NOT NULL and u.deleted_at = 0")
Joins("LEFT JOIN (?) AS t ON bor.customer_id = t.customer_id AND bor.created_at = t.max_created_time", subQuery).
Where("rn.name IS NOT NULL and u.deleted_at = 0").Group("u.id")
if req.UserName != "" {
if utils.IsPhoneNumber(req.UserName) {
session = session.Where("u.tel_num = ?", req.UserName)