Update:更新查询逻辑
This commit is contained in:
parent
3ea4a9f1d8
commit
45385724d1
@ -73,6 +73,7 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.Bun
|
||||
Joins(`INNER JOIN (
|
||||
SELECT customer_id, MAX(created_at) AS max_created_time
|
||||
FROM bundle_order_records
|
||||
WHERE order_type = 1 AND deleted_at is NULL
|
||||
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").Unscoped().
|
||||
@ -90,7 +91,8 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.Bun
|
||||
Where("rn.name IS NOT NULL").
|
||||
Where("u.deleted_at = 0").
|
||||
Where("bor.deleted_at IS NULL").
|
||||
Where("bor.status = 2").
|
||||
Where("((bor.order_mode = 2 AND bor.pay_later_status > 0 ) OR (bor.order_mode = 1 AND bor.status = 2 ))").
|
||||
Where("bb.bundle_type = ?", model.BundleTypeBasic).
|
||||
Order("bor.expiration_time desc")
|
||||
if req.UserName != "" {
|
||||
if utils.IsPhoneNumber(req.UserName) {
|
||||
@ -120,9 +122,6 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.Bun
|
||||
if req.Bought == 1 {
|
||||
session = session.Where("bb.user_id IS NULL")
|
||||
}
|
||||
if req.BundleType != 0 {
|
||||
session = session.Where("bb.bundle_type = ?", req.BundleType)
|
||||
}
|
||||
t := time.Now()
|
||||
if req.StatusType != 0 {
|
||||
if req.ExpiredTimeStart > time.Now().UnixMilli() {
|
||||
@ -187,7 +186,7 @@ func GetPayLaterBundleBalanceList(req *bundle.GetPayLaterBundleBalanceListReq) (
|
||||
Joins(`INNER JOIN (
|
||||
SELECT customer_id, MAX(created_at) AS max_created_time
|
||||
FROM bundle_order_records
|
||||
WHERE order_type = 2 AND deleted_at is NULL
|
||||
WHERE order_type = 2 AND deleted_at is NULL AND bor.pay_later_status > 0
|
||||
GROUP BY customer_id
|
||||
) bor2 ON bor1.customer_id = bor2.customer_id AND bor1.created_at = bor2.max_created_time`)
|
||||
|
||||
@ -242,11 +241,11 @@ func GetBundleBalanceByUserId(req *bundle.GetBundleBalanceByUserIdReq) (data mod
|
||||
subQuery := app.ModuleClients.BundleDB.Table("bundle_order_records as bor1").
|
||||
Select("bor1.*").
|
||||
Joins(`INNER JOIN (
|
||||
SELECT customer_id, MAX(created_at) AS max_created_time
|
||||
SELECT customer_id
|
||||
FROM bundle_order_records
|
||||
WHERE status = 2 AND deleted_at is NULL
|
||||
WHERE ((order_mode = 2 AND pay_later_status > 0 ) OR (order_mode = 1 AND status = 2 )) AND deleted_at is NULL
|
||||
GROUP BY customer_id
|
||||
) bor2 ON bor1.customer_id = bor2.customer_id AND bor1.created_at = bor2.max_created_time`)
|
||||
) bor2 ON bor1.customer_id = bor2.customer_id`)
|
||||
session := app.ModuleClients.BundleDB.Table("`micro-account`.`user` AS u").Unscoped().
|
||||
Select(`bb.*, bor.bundle_name, bor.status,bor.amount AS payment_amount,bor.amount_type AS payment_type,bor.customer_num,
|
||||
bor.uuid as order_uuid, rn.name as user_name,bc.activate,bor.created_at as pay_time,
|
||||
@ -259,9 +258,10 @@ func GetBundleBalanceByUserId(req *bundle.GetBundleBalanceByUserIdReq) (data mod
|
||||
Where("u.deleted_at = 0").
|
||||
Where("u.id = ?", req.UserId).
|
||||
Where("bb.month = ?", time.Now().Format("2006-01")).
|
||||
Where("bb.expired_at >= ?", time.Now()).
|
||||
Order("bor.expiration_time desc")
|
||||
if req.OrderUUID != "" {
|
||||
session = session.Where("bb.order_uuid = ?", req.OrderUUID)
|
||||
session = session.Where("bor.uuid = ?", req.OrderUUID).Where("bb.order_uuid = ?", req.OrderUUID)
|
||||
}
|
||||
err = session.First(&data).Error
|
||||
return
|
||||
|
||||
Loading…
Reference in New Issue
Block a user