From 5475b310cc75349f1d2c571f6a79fa31498d1236 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Mon, 11 Nov 2024 19:27:48 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=9F=A5=E8=AF=A2=E7=BB=BF=E8=89=B2?= =?UTF-8?q?=E8=83=BD=E9=87=8F=E3=80=81=E6=B4=BB=E8=B7=83=E7=A7=AF=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dao/user_virtual_amount_dao.go | 2 ++ src/dao/user_virtual_coin_flow_dao.go | 1 + src/dao/virtual_coin_dao.go | 3 +++ ...platoon_free_punish_with_user_implement.go | 4 +-- .../user_virtual_amount_implement.go | 25 +++++++++++++++++++ .../user_virtual_coin_flow_implement.go | 21 ++++++++++++++++ src/implement/virtual_coin_implement.go | 17 +++++++++++++ 7 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/dao/user_virtual_amount_dao.go b/src/dao/user_virtual_amount_dao.go index 87f43f5..202f68a 100644 --- a/src/dao/user_virtual_amount_dao.go +++ b/src/dao/user_virtual_amount_dao.go @@ -6,4 +6,6 @@ import ( type UserVirtualAmountDao interface { GetUserVirtualWalletBySession(uid int64, coinId int) (*model.UserVirtualAmount, error) + UserVirtualAmountFindAndCountByCoinKind(coinID int, page, pageSize int) ([]model.UserVirtualAmount, int64, error) + UserVirtualAmountGetSumByCoinKind(coinId int) (float64, error) } diff --git a/src/dao/user_virtual_coin_flow_dao.go b/src/dao/user_virtual_coin_flow_dao.go index 655506a..ada176d 100644 --- a/src/dao/user_virtual_coin_flow_dao.go +++ b/src/dao/user_virtual_coin_flow_dao.go @@ -7,4 +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) } diff --git a/src/dao/virtual_coin_dao.go b/src/dao/virtual_coin_dao.go index 9c5c4d9..1fb1366 100644 --- a/src/dao/virtual_coin_dao.go +++ b/src/dao/virtual_coin_dao.go @@ -1,5 +1,8 @@ package dao +import "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + type VirtualCoinDao interface { //TODO:: You can add specific method definitions here + VirtualCoinFindAllAndCount(pageSize, page int) (kindList []model.VirtualCoin, total int64, err error) } diff --git a/src/implement/public_platoon_free_punish_with_user_implement.go b/src/implement/public_platoon_free_punish_with_user_implement.go index 092ee26..6a4672f 100644 --- a/src/implement/public_platoon_free_punish_with_user_implement.go +++ b/src/implement/public_platoon_free_punish_with_user_implement.go @@ -66,9 +66,9 @@ func (p PublicPlatoonFreePunishWithUserDb) PublicPlatoonFreePunishWithUserCountA var err1 error if params != nil { query := fmt.Sprintf("%s = ?", params["key"]) - err1 = session.Where(query, params["value"]).Limit(limit, page-1).Find(&m) + err1 = session.Where(query, params["value"]).Limit(limit, (page-1)*limit).Find(&m) } else { - err1 = session.Where("1=1").Limit(limit, page-1).Find(&m) + err1 = session.Where("1=1").Limit(limit, (page-1)*limit).Find(&m) } if err1 != nil { return nil, 0, zhios_order_relate_logx.Error(err1) diff --git a/src/implement/user_virtual_amount_implement.go b/src/implement/user_virtual_amount_implement.go index 8be29fb..d1bb31c 100644 --- a/src/implement/user_virtual_amount_implement.go +++ b/src/implement/user_virtual_amount_implement.go @@ -3,6 +3,7 @@ import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" "xorm.io/xorm" ) @@ -33,3 +34,27 @@ func (u UserVirtualAmountDb) GetUserVirtualWalletBySession(uid int64, coinId int return &UserVirtualWallet, nil } } + +func (u UserVirtualAmountDb) UserVirtualAmountFindAndCountByCoinKind(coinID int, page, pageSize int) ([]model.UserVirtualAmount, int64, error) { + var userVirtualWallets []model.UserVirtualAmount + session := u.Db.Where("coin_id = ?", coinID) + total, err1 := session.Count(&userVirtualWallets) + if err1 != nil { + return nil, 0, zhios_order_relate_logx.Error(err1.Error()) + } + + err := session.Limit(pageSize, (page-1)*pageSize).Desc("amount").Find(&userVirtualWallets) + if err != nil { + return nil, 0, zhios_order_relate_logx.Error(err.Error()) + } + return userVirtualWallets, total, nil +} + +func (u UserVirtualAmountDb) UserVirtualAmountGetSumByCoinKind(coinId int) (float64, error) { + var m model.UserVirtualAmount + sum, err := u.Db.Where("coin_id = ?", coinId).Sum(m, "amount") + if err != nil { + return 0, zhios_order_relate_logx.Error(err.Error()) + } + return sum, nil +} diff --git a/src/implement/user_virtual_coin_flow_implement.go b/src/implement/user_virtual_coin_flow_implement.go index 7fbd214..5595024 100644 --- a/src/implement/user_virtual_coin_flow_implement.go +++ b/src/implement/user_virtual_coin_flow_implement.go @@ -3,6 +3,7 @@ import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" "xorm.io/xorm" ) @@ -21,3 +22,23 @@ 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) { + var m []model.UserVirtualCoinFlow + session := u.Db.Where("uid = ?", uid).And("coin_id = ?", coinID).And("create_at > ?", startAt).And("create_at < ?", endAt) + if direction != 0 { + session = session.And("direction = ?", direction) + } + + total, err1 := session.Count(&m) + if err1 != nil { + return nil, 0, zhios_order_relate_logx.Error(err1.Error()) + } + + err2 := session.Limit(pageSize, (page-1)*pageSize).Desc("create_at").Find(m) + if err2 != nil { + return nil, 0, err2 + } + + return m, total, nil +} diff --git a/src/implement/virtual_coin_implement.go b/src/implement/virtual_coin_implement.go index dc254c7..46c190b 100644 --- a/src/implement/virtual_coin_implement.go +++ b/src/implement/virtual_coin_implement.go @@ -2,6 +2,8 @@ import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" "xorm.io/xorm" ) @@ -12,3 +14,18 @@ func NewVirtualCoinDb(engine *xorm.Engine) dao.VirtualCoinDao { type VirtualCoinDb struct { Db *xorm.Engine } + +func (v VirtualCoinDb) VirtualCoinFindAllAndCount(pageSize, page int) (kindList []model.VirtualCoin, total int64, err error) { + var m []model.VirtualCoin + session := v.Db.Where("is_use = ?", 1) + total, err = session.Count(&m) + if err != nil { + return nil, 0, err + } + + err = session.Asc("id").Limit(pageSize, (page-1)*pageSize).Find(&m) + if err != nil { + return nil, 0, zhios_order_relate_logx.Error(err) + } + return m, total, nil +}