From 23cc4354aa71c7e7962b5f9e93dd8dbf8a78ce44 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Fri, 19 Jan 2024 22:52:13 +0800 Subject: [PATCH] update --- db/db_one_circles_user_watch_records.go | 24 +++++++++++- db/model/one_circles_user_watch_records.go | 13 +++---- ...ircles_public_platoon_give_activty_coin.go | 37 ++++++++++++++++++- 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/db/db_one_circles_user_watch_records.go b/db/db_one_circles_user_watch_records.go index 4fdcc68..14b42f5 100644 --- a/db/db_one_circles_user_watch_records.go +++ b/db/db_one_circles_user_watch_records.go @@ -58,7 +58,23 @@ func OneCirclesUserWatchRecordsDelete(Db *xorm.Engine, id interface{}) (int64, e } // OneCirclesUserWatchRecordsUpdate 更新记录 -func OneCirclesUserWatchRecordsUpdate(session *xorm.Session, id interface{}, OneCirclesUserWatchRecords *model.OneCirclesUserWatchRecords, forceColums ...string) (int64, error) { +func OneCirclesUserWatchRecordsUpdate(Db *xorm.Engine, id interface{}, OneCirclesUserWatchRecords *model.OneCirclesUserWatchRecords, forceColums ...string) (int64, error) { + var ( + affected int64 + err error + ) + if forceColums != nil { + affected, err = Db.Where("id=?", id).Cols(forceColums...).Update(OneCirclesUserWatchRecords) + } else { + affected, err = Db.Where("id=?", id).Update(OneCirclesUserWatchRecords) + } + if err != nil { + return 0, err + } + return affected, nil +} + +func OneCirclesUserWatchRecordsUpdateBySession(session *xorm.Session, id interface{}, OneCirclesUserWatchRecords *model.OneCirclesUserWatchRecords, forceColums ...string) (int64, error) { var ( affected int64 err error @@ -92,9 +108,13 @@ func OneCirclesUserWatchRecordsGetOneByParamsBySession(session *xorm.Session, pa func OneCirclesUserWatchRecordsGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.OneCirclesUserWatchRecords, error) { var m model.OneCirclesUserWatchRecords var query = fmt.Sprintf("%s =?", params["key"]) - if has, err := Db.Where(query, params["value"]).Get(&m); err != nil || has == false { + has, err := Db.Where(query, params["value"]).Get(&m) + if err != nil { return nil, zhios_order_relate_logx.Error(err) } + if !has { + return nil, nil + } return &m, nil } diff --git a/db/model/one_circles_user_watch_records.go b/db/model/one_circles_user_watch_records.go index 4768119..4e02bd2 100644 --- a/db/model/one_circles_user_watch_records.go +++ b/db/model/one_circles_user_watch_records.go @@ -5,11 +5,10 @@ import ( ) type OneCirclesUserWatchRecords struct { - Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` - Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"` - NextWatchAdDate time.Time `json:"next_watch_ad_date" xorm:"not null default 'CURRENT_TIMESTAMP' comment('下一轮观看视屏时间') DATETIME"` - LastRoundWatchAdTotal int `json:"last_round_watch_ad_total" xorm:"not null default 0 comment('上一轮观看视屏总数') INT(11)"` - ResidueWatchAdNum int `json:"residue_watch_ad_num" xorm:"not null default 0 comment('剩余观看视屏数') INT(11)"` - CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` - UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` + Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` + Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"` + NextWatchAdDate time.Time `json:"next_watch_ad_date" xorm:"not null default 'CURRENT_TIMESTAMP' comment('下一轮观看视屏时间') DATETIME"` + ResidueWatchAdNum int `json:"residue_watch_ad_num" xorm:"not null default 0 comment('剩余观看视屏数') INT(11)"` + CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` + UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` } diff --git a/rule/one_circles/one_circles_public_platoon_give_activty_coin.go b/rule/one_circles/one_circles_public_platoon_give_activty_coin.go index 447152a..2b392a4 100644 --- a/rule/one_circles/one_circles_public_platoon_give_activty_coin.go +++ b/rule/one_circles/one_circles_public_platoon_give_activty_coin.go @@ -53,7 +53,7 @@ func SettlementPublicGiveActivityCoin(engine *xorm.Engine, masterId string, uid "value": uid, }) if err1 != nil { - return + return err1 } var rewardFather []struct { @@ -81,6 +81,41 @@ func SettlementPublicGiveActivityCoin(engine *xorm.Engine, masterId string, uid } } + //增加 one_circles_user_watch_records 记录 + oneCirclesUserWatchRecords, err1 := db.OneCirclesUserWatchRecordsGetOneByParams(engine, map[string]interface{}{ + "key": "uid", + "value": uid, + }) + if err1 != nil { + return err1 + } + now := time.Now() + if oneCirclesUserWatchRecords == nil { + _, err2 := db.OneCirclesUserWatchRecordsInsert(engine, &model.OneCirclesUserWatchRecords{ + Uid: uid, + NextWatchAdDate: now.Add(time.Hour * time.Duration(zhios_order_relate_utils.StrToInt(videoRewardSystem.EachRoundHour))), + ResidueWatchAdNum: zhios_order_relate_utils.StrToInt(videoRewardSystem.RewardTotalNum) - 1, + CreateAt: now, + UpdateAt: now, + }) + if err2 != nil { + return err2 + } + } else { + residueWatchAdNum := oneCirclesUserWatchRecords.ResidueWatchAdNum - 1 + nextWatchAdDate := oneCirclesUserWatchRecords.NextWatchAdDate + if residueWatchAdNum == 0 { + nextWatchAdDate = now.Add(time.Hour * time.Duration(zhios_order_relate_utils.StrToInt(videoRewardSystem.EachRoundHour))) + residueWatchAdNum = zhios_order_relate_utils.StrToInt(videoRewardSystem.EachRoundHour) + } + oneCirclesUserWatchRecords.ResidueWatchAdNum = residueWatchAdNum + oneCirclesUserWatchRecords.NextWatchAdDate = nextWatchAdDate + _, err2 := db.OneCirclesUserWatchRecordsUpdate(engine, oneCirclesUserWatchRecords.Id, oneCirclesUserWatchRecords, "residue_watch_ad_num", "next_watch_ad_date") + if err2 != nil { + return err2 + } + } + session := engine.NewSession() //给相应的用户加上"个人"活跃积分 err = DealUserCoin(session, md.DealUserCoinReq{