From f579b7f54bab10e437ceecb5ebd2210504151ead Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Thu, 19 Dec 2024 15:28:08 +0800 Subject: [PATCH 1/4] update --- src/dao/advertising_callback_dao.go | 3 +- src/dao/egg_energy_team_assistance_dao.go | 4 ++- .../advertising_callback_implement.go | 4 +-- .../egg_energy_team_assistance_implement.go | 28 +++++++++++++++++-- src/model/egg_energy_team_assistance.go | 15 +++++----- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/dao/advertising_callback_dao.go b/src/dao/advertising_callback_dao.go index 4541b2c..31f7036 100644 --- a/src/dao/advertising_callback_dao.go +++ b/src/dao/advertising_callback_dao.go @@ -2,10 +2,9 @@ package dao import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/model" - "xorm.io/xorm" ) type AdvertisingCallbackDao interface { FindAdvertisingCallbackAndTotal(page, limit, amount, uid, startTime, endTime, platform, types string) (*[]model.AdvertisingCallback, int64, error) - AdvertisingCallbackCountBySession(session *xorm.Session, uid, startTime, endTime, types string) (int64, error) + AdvertisingCallbackCount(uid, startTime, endTime, types string) (int64, error) } diff --git a/src/dao/egg_energy_team_assistance_dao.go b/src/dao/egg_energy_team_assistance_dao.go index d48cc0f..e64eca7 100644 --- a/src/dao/egg_energy_team_assistance_dao.go +++ b/src/dao/egg_energy_team_assistance_dao.go @@ -9,5 +9,7 @@ type EggEnergyTeamAssistanceDao interface { EggEnergyTeamAssistanceInsertBySession(session *xorm.Session, EggEnergyTeamAssistance *model.EggEnergyTeamAssistance) (int64, error) EggEnergyTeamAssistanceUpdateBySession(session *xorm.Session, id interface{}, EggEnergyTeamAssistance *model.EggEnergyTeamAssistance, forceColums ...string) (int64, error) EggEnergyTeamAssistanceGetOneByParamsBySession(session *xorm.Session, params map[string]interface{}) (*model.EggEnergyTeamAssistance, error) - EggEnergyTeamAssistanceGetOneBySession(session *xorm.Session, uid int64, date string) (*model.EggEnergyTeamAssistance, error) + EggEnergyTeamAssistanceGetOne(uid int64, date string) (*model.EggEnergyTeamAssistance, error) + EggEnergyTeamAssistanceInsert(EggEnergyTeamAssistance *model.EggEnergyTeamAssistance) (int64, error) + EggEnergyTeamAssistanceUpdate(id interface{}, EggEnergyTeamAssistance *model.EggEnergyTeamAssistance, forceColums ...string) (int64, error) } diff --git a/src/implement/advertising_callback_implement.go b/src/implement/advertising_callback_implement.go index 13ea86e..1980006 100644 --- a/src/implement/advertising_callback_implement.go +++ b/src/implement/advertising_callback_implement.go @@ -45,8 +45,8 @@ func (a AdvertisingCallbackDb) FindAdvertisingCallbackAndTotal(page, limit, amou return &m, count, nil } -func (a AdvertisingCallbackDb) AdvertisingCallbackCountBySession(session *xorm.Session, uid, startTime, endTime, types string) (int64, error) { - sess := session.Where("1=1") +func (a AdvertisingCallbackDb) AdvertisingCallbackCount(uid, startTime, endTime, types string) (int64, error) { + sess := a.Db.Where("1=1") if uid != "" { sess.And("uid=?", uid) } diff --git a/src/implement/egg_energy_team_assistance_implement.go b/src/implement/egg_energy_team_assistance_implement.go index 9fc4966..a4e3a45 100644 --- a/src/implement/egg_energy_team_assistance_implement.go +++ b/src/implement/egg_energy_team_assistance_implement.go @@ -53,9 +53,9 @@ func (e EggEnergyTeamAssistanceDb) EggEnergyTeamAssistanceGetOneByParamsBySessio return &m, nil } -func (e EggEnergyTeamAssistanceDb) EggEnergyTeamAssistanceGetOneBySession(session *xorm.Session, uid int64, date string) (*model.EggEnergyTeamAssistance, error) { +func (e EggEnergyTeamAssistanceDb) EggEnergyTeamAssistanceGetOne(uid int64, date string) (*model.EggEnergyTeamAssistance, error) { var m model.EggEnergyTeamAssistance - has, err := session.Where("uid = ?", uid).And("date = ?", date).Get(&m) + has, err := e.Db.Where("uid = ?", uid).And("date = ?", date).Get(&m) if err != nil { return nil, err } @@ -64,3 +64,27 @@ func (e EggEnergyTeamAssistanceDb) EggEnergyTeamAssistanceGetOneBySession(sessio } return &m, nil } + +func (e EggEnergyTeamAssistanceDb) EggEnergyTeamAssistanceInsert(EggEnergyTeamAssistance *model.EggEnergyTeamAssistance) (int64, error) { + _, err := e.Db.InsertOne(EggEnergyTeamAssistance) + if err != nil { + return 0, err + } + return EggEnergyTeamAssistance.Id, nil +} + +func (e EggEnergyTeamAssistanceDb) EggEnergyTeamAssistanceUpdate(id interface{}, EggEnergyTeamAssistance *model.EggEnergyTeamAssistance, forceColums ...string) (int64, error) { + var ( + affected int64 + err error + ) + if forceColums != nil { + affected, err = e.Db.Where("id=?", id).Cols(forceColums...).Update(EggEnergyTeamAssistance) + } else { + affected, err = e.Db.Where("id=?", id).Update(EggEnergyTeamAssistance) + } + if err != nil { + return 0, err + } + return affected, nil +} diff --git a/src/model/egg_energy_team_assistance.go b/src/model/egg_energy_team_assistance.go index 40dd83c..30f0a70 100644 --- a/src/model/egg_energy_team_assistance.go +++ b/src/model/egg_energy_team_assistance.go @@ -1,11 +1,12 @@ package model type EggEnergyTeamAssistance struct { - Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` - Uid int64 `json:"uid" xorm:"not null default 0 comment('用户 ID') BIGINT(20)"` - AssistedNum int `json:"assisted_num" xorm:"not null default 0 comment('助力人数') INT(11)"` - RewardScore string `json:"reward_score" xorm:"not null default 0.00000000 comment('奖励积分数量') DECIMAL(20,8)"` - Date string `json:"date" xorm:"not null default '0000-00-00' comment('日期') CHAR(50)"` - CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` - UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` + Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` + Uid int64 `json:"uid" xorm:"not null default 0 comment('用户 ID') BIGINT(20)"` + AssistedNum int `json:"assisted_num" xorm:"not null default 0 comment('助力人数') INT(11)"` + AssistedTimes int `json:"assisted_times" xorm:"not null default 0 comment('助力次数') INT(11)"` + RewardScore string `json:"reward_score" xorm:"not null default 0.00000000 comment('奖励积分数量') DECIMAL(20,8)"` + Date string `json:"date" xorm:"not null default '0000-00-00' comment('日期') CHAR(50)"` + CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` + UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` } From 2e3b69fe024fb6fc2b5ed899bf6d7c4f80483410 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Thu, 19 Dec 2024 16:18:55 +0800 Subject: [PATCH 2/4] add delete AdvertisingCallback --- src/dao/advertising_callback_dao.go | 1 + src/implement/advertising_callback_implement.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/dao/advertising_callback_dao.go b/src/dao/advertising_callback_dao.go index 31f7036..2a23cd9 100644 --- a/src/dao/advertising_callback_dao.go +++ b/src/dao/advertising_callback_dao.go @@ -7,4 +7,5 @@ import ( type AdvertisingCallbackDao interface { FindAdvertisingCallbackAndTotal(page, limit, amount, uid, startTime, endTime, platform, types string) (*[]model.AdvertisingCallback, int64, error) AdvertisingCallbackCount(uid, startTime, endTime, types string) (int64, error) + AdvertisingCallbackDeleteByDateByPage(date string, limit int) (int64, error) } diff --git a/src/implement/advertising_callback_implement.go b/src/implement/advertising_callback_implement.go index 1980006..6ae2f43 100644 --- a/src/implement/advertising_callback_implement.go +++ b/src/implement/advertising_callback_implement.go @@ -65,3 +65,11 @@ func (a AdvertisingCallbackDb) AdvertisingCallbackCount(uid, startTime, endTime, } return count, nil } + +func (a AdvertisingCallbackDb) AdvertisingCallbackDeleteByDateByPage(date string, limit int) (int64, error) { + affected, err := a.Db.Where("create_at < ?", date).Limit(limit).Delete(&model.EggAccessRecords{}) + if err != nil { + return 0, zhios_order_relate_logx.Error(err.Error()) + } + return affected, nil +} From 8eba71239d4f30bbecec2127332ceeace72c237d Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Thu, 19 Dec 2024 16:38:24 +0800 Subject: [PATCH 3/4] update --- src/implement/advertising_callback_implement.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/implement/advertising_callback_implement.go b/src/implement/advertising_callback_implement.go index 6ae2f43..e86639a 100644 --- a/src/implement/advertising_callback_implement.go +++ b/src/implement/advertising_callback_implement.go @@ -67,7 +67,7 @@ func (a AdvertisingCallbackDb) AdvertisingCallbackCount(uid, startTime, endTime, } func (a AdvertisingCallbackDb) AdvertisingCallbackDeleteByDateByPage(date string, limit int) (int64, error) { - affected, err := a.Db.Where("create_at < ?", date).Limit(limit).Delete(&model.EggAccessRecords{}) + affected, err := a.Db.Where("create_at < ?", date).Limit(limit).Delete(&model.AdvertisingCallback{}) if err != nil { return 0, zhios_order_relate_logx.Error(err.Error()) } From 0d8e6dd68addc49889acd99198db31db5a2a0e9f Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Fri, 20 Dec 2024 14:26:24 +0800 Subject: [PATCH 4/4] update ad callback count by type prefix --- src/dao/advertising_callback_dao.go | 2 +- src/implement/advertising_callback_implement.go | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/dao/advertising_callback_dao.go b/src/dao/advertising_callback_dao.go index 2a23cd9..f5afecd 100644 --- a/src/dao/advertising_callback_dao.go +++ b/src/dao/advertising_callback_dao.go @@ -6,6 +6,6 @@ import ( type AdvertisingCallbackDao interface { FindAdvertisingCallbackAndTotal(page, limit, amount, uid, startTime, endTime, platform, types string) (*[]model.AdvertisingCallback, int64, error) - AdvertisingCallbackCount(uid, startTime, endTime, types string) (int64, error) + AdvertisingCallbackCount(uid, startTime, endTime, typePrefix string) (int64, error) AdvertisingCallbackDeleteByDateByPage(date string, limit int) (int64, error) } diff --git a/src/implement/advertising_callback_implement.go b/src/implement/advertising_callback_implement.go index e86639a..0bbd90d 100644 --- a/src/implement/advertising_callback_implement.go +++ b/src/implement/advertising_callback_implement.go @@ -5,6 +5,7 @@ import ( "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" "xorm.io/xorm" ) @@ -45,13 +46,14 @@ func (a AdvertisingCallbackDb) FindAdvertisingCallbackAndTotal(page, limit, amou return &m, count, nil } -func (a AdvertisingCallbackDb) AdvertisingCallbackCount(uid, startTime, endTime, types string) (int64, error) { +func (a AdvertisingCallbackDb) AdvertisingCallbackCount(uid, startTime, endTime, typePrefix string) (int64, error) { sess := a.Db.Where("1=1") if uid != "" { sess.And("uid=?", uid) } - if types != "" { - sess.And("type=?", types) + if typePrefix != "" { + types := fmt.Sprintf("type LIKE '%s'", typePrefix+"%") + sess.And(types) } if startTime != "" { sess.And("create_at>=?", startTime)