diff --git a/src/dao/user_virtual_coin_flow_dao.go b/src/dao/user_virtual_coin_flow_dao.go index ada176d..e0b8570 100644 --- a/src/dao/user_virtual_coin_flow_dao.go +++ b/src/dao/user_virtual_coin_flow_dao.go @@ -7,5 +7,5 @@ import ( type UserVirtualCoinFlowDao interface { UserVirtualCoinFlowInsertBySession(session *xorm.Session, UserVirtualCoinFlow *model.UserVirtualCoinFlow) (int64, error) - UserVirtualCoinFlowFindByCoinAndUser(page, pageSize int, coinID int, uid int64, startAt string, endAt string, direction int) ([]model.UserVirtualCoinFlow, int64, error) + UserVirtualCoinFlowFindByCoinAndUser(page, pageSize int, coinID int, uid int64, startAt string, endAt string, direction int, isAsc bool) ([]model.UserVirtualCoinFlow, int64, error) } diff --git a/src/implement/user_virtual_coin_flow_implement.go b/src/implement/user_virtual_coin_flow_implement.go index 4cc4d09..8687677 100644 --- a/src/implement/user_virtual_coin_flow_implement.go +++ b/src/implement/user_virtual_coin_flow_implement.go @@ -22,7 +22,7 @@ func (u UserVirtualCoinFlowDb) UserVirtualCoinFlowInsertBySession(session *xorm. return UserVirtualCoinFlow.Id, nil } -func (u UserVirtualCoinFlowDb) UserVirtualCoinFlowFindByCoinAndUser(page, pageSize int, coinID int, uid int64, startAt string, endAt string, direction int) ([]model.UserVirtualCoinFlow, int64, error) { +func (u UserVirtualCoinFlowDb) UserVirtualCoinFlowFindByCoinAndUser(page, pageSize int, coinID int, uid int64, startAt string, endAt string, direction int, isAsc bool) ([]model.UserVirtualCoinFlow, int64, error) { var m []model.UserVirtualCoinFlow session := u.Db.Where("uid = ?", uid).And("coin_id = ?", coinID) if startAt != "" && endAt != "" { @@ -31,8 +31,13 @@ func (u UserVirtualCoinFlowDb) UserVirtualCoinFlowFindByCoinAndUser(page, pageSi if direction != 0 { session = session.And("direction = ?", direction) } - - total, err := session.Limit(pageSize, (page-1)*pageSize).Desc("create_at").FindAndCount(&m) + session = session.Limit(pageSize, (page-1)*pageSize) + if isAsc { + session = session.Asc("create_at") + } else { + session = session.Desc("create_at") + } + total, err := session.FindAndCount(&m) if err != nil { return nil, 0, err }