Compare commits

..

No commits in common. "f4841ed7726fd7f0c62a5de9d14666115721d19d" and "63516ad0a8c579f045f2bdb6504787be50b9bc43" have entirely different histories.

View File

@ -99,22 +99,25 @@ func GetBundleExtendRecordList(req *bundle.BundleExtendRecordsListRequest) (data
} }
func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.BundleBalancePo, total int64, err error) { func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.BundleBalancePo, total int64, err error) {
subQuery := app.ModuleClients.BundleDB.Table("bundle_order_records as bor1"). subQuery := app.ModuleClients.BundleDB.Table("bundle_order_records").
Select("bor1.*"). Select("customer_id, MAX(created_at) AS max_created_time").
Joins(`INNER JOIN ( Group("customer_id")
SELECT customer_id, MAX(created_at) AS max_created_time
FROM bundle_order_records
GROUP BY customer_id
) bor2 ON bor1.customer_id = bor2.customer_id AND bor1.created_at = bor2.max_created_time`)
session := app.ModuleClients.BundleDB.Table("`micro-account`.`user` AS u"). session := app.ModuleClients.BundleDB.Table("`micro-account`.`user` AS u").
Select(`bb.*, bor.expiration_time as expired_time, bor.bundle_name, bor.status, Select(`
bor.uuid as order_uuid, rn.name as user_name, bb.*,
u.tel_num as user_phone_number, u.id as user_id`). bor.expiration_time as expired_time,
Joins("LEFT JOIN `micro-account`.real_name rn ON u.real_name_id = rn.id"). bor.bundle_name,
Joins("LEFT JOIN (?) as bor ON bor.customer_id = u.id", subQuery). bor.status,
Joins("LEFT JOIN fiee_bundle.bundle_balance bb ON u.id = bb.user_id AND bb.order_uuid = bor.uuid"). bor.uuid as order_uuid,
Where("rn.name IS NOT NULL"). rn.name as user_name,
Where("u.deleted_at = 0") u.tel_num as user_phone_number,
u.id as user_id
`).
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("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 req.UserName != "" {
if utils.IsPhoneNumber(req.UserName) { if utils.IsPhoneNumber(req.UserName) {
session = session.Where("u.tel_num = ?", req.UserName) session = session.Where("u.tel_num = ?", req.UserName)