diff --git a/src/dao/user_wallet_flow_dao.go b/src/dao/user_wallet_flow_dao.go index fa8f33b..1d3aef5 100644 --- a/src/dao/user_wallet_flow_dao.go +++ b/src/dao/user_wallet_flow_dao.go @@ -7,4 +7,5 @@ import ( type UserWalletFlowDao interface { UserWalletFlowInsertBySession(session *xorm.Session, userWalletFlow *model.UserWalletFlow) (int64, error) + UserWalletFlowFindByParams(params map[string]interface{}, page, limit int) (*[]model.UserWalletFlow, int64, error) } diff --git a/src/implement/user_virtual_coin_flow_implement.go b/src/implement/user_virtual_coin_flow_implement.go index b205c33..4cc4d09 100644 --- a/src/implement/user_virtual_coin_flow_implement.go +++ b/src/implement/user_virtual_coin_flow_implement.go @@ -24,7 +24,10 @@ func (u UserVirtualCoinFlowDb) UserVirtualCoinFlowInsertBySession(session *xorm. func (u UserVirtualCoinFlowDb) UserVirtualCoinFlowFindByCoinAndUser(page, pageSize int, coinID int, uid int64, startAt string, endAt string, direction int) ([]model.UserVirtualCoinFlow, int64, error) { var m []model.UserVirtualCoinFlow - session := u.Db.Where("uid = ?", uid).And("coin_id = ?", coinID).And("create_at >= ?", startAt).And("create_at <= ?", endAt) + session := u.Db.Where("uid = ?", uid).And("coin_id = ?", coinID) + if startAt != "" && endAt != "" { + session = session.And("create_at >= ?", startAt).And("create_at <= ?", endAt) + } if direction != 0 { session = session.And("direction = ?", direction) } diff --git a/src/implement/user_wallet_flow_implement.go b/src/implement/user_wallet_flow_implement.go index 5a012a0..2ab00e1 100644 --- a/src/implement/user_wallet_flow_implement.go +++ b/src/implement/user_wallet_flow_implement.go @@ -3,6 +3,10 @@ import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + zhios_order_relate_utils "code.fnuoos.com/EggPlanet/egg_models.git/utils" + zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" + "fmt" + "reflect" "xorm.io/xorm" ) @@ -21,3 +25,26 @@ func (u UserWalletFlowDb) UserWalletFlowInsertBySession(session *xorm.Session, u } return userWalletFlow.Id, nil } + +func (u UserWalletFlowDb) UserWalletFlowFindByParams(params map[string]interface{}, page, limit int) (*[]model.UserWalletFlow, int64, error) { + var m []model.UserWalletFlow + if page == 0 || limit == 0 { + page = 1 + limit = 10 + } + var total int64 + var err error + if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { + //指定In查询 + if total, err = u.Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Limit(limit, (page-1)*limit).FindAndCount(&m); err != nil { + return nil, 0, zhios_order_relate_logx.Warn(err) + } + } else { + var query = fmt.Sprintf("%s =?", params["key"]) + total, err = u.Db.Where(query, params["value"]).Limit(limit, (page-1)*limit).FindAndCount(&m) + if err != nil { + return nil, 0, zhios_order_relate_logx.Error(err) + } + } + return &m, total, nil +}