huangjiajun 5 місяці тому
джерело
коміт
4648274884
4 змінених файлів з 178 додано та 1 видалено
  1. +1
    -1
      go.mod
  2. +2
    -0
      go.sum
  3. +164
    -0
      rule/happy_orchard/happy_orchard_give_water.go
  4. +11
    -0
      rule/happy_orchard/md/happy_orchard.go

+ 1
- 1
go.mod Переглянути файл

@@ -7,7 +7,7 @@ go 1.15

require (
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240701102131-0408d7ee8572
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240723073901-849ec3e356f3
github.com/gin-gonic/gin v1.9.1
github.com/go-redis/redis v6.15.9+incompatible
github.com/gomodule/redigo v1.8.9


+ 2
- 0
go.sum Переглянути файл

@@ -4,6 +4,8 @@ code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 h1:dqvWJqlJi0WXCwTxbWPLv
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5/go.mod h1:TTcCnFn/LhBGapnutpezlW+GXkLRNPMWkziOoCsXQqY=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240701102131-0408d7ee8572 h1:HncIr54hrhKSgOpq/KQiOiMdf4895JpxIUk56UyAsMY=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240701102131-0408d7ee8572/go.mod h1:nT2x13YFgrS3tS1fDyUR6q/GNIK+hPw7bdzZXz99SM0=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240723073901-849ec3e356f3 h1:YQhrYavdlE5gUpQ6tm7029ONJVyy9IcSw4W1vU52+3E=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240723073901-849ec3e356f3/go.mod h1:nT2x13YFgrS3tS1fDyUR6q/GNIK+hPw7bdzZXz99SM0=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=


+ 164
- 0
rule/happy_orchard/happy_orchard_give_water.go Переглянути файл

@@ -0,0 +1,164 @@
package happy_orchard

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model"
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/happy_orchard/md"
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache"
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/implement"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/models"
"encoding/json"
"errors"
"fmt"
"time"
"xorm.io/xorm"
)

func HappyOrchardGiveWater(eg *xorm.Engine, masterId string, uid int, isMultiple int) (err error) {
newHappyOrchardBasicSettingDb := implement.NewHappyOrchardBasicSettingDb(eg)
base, _ := newHappyOrchardBasicSettingDb.GetHappyOrchardBasicSetting()

if base.IsOpenSixEnergyBall == 1 {
var videoRewardSystem *md2.HappyOrchardVideoRewardSystemStruct
err = json.Unmarshal([]byte(base.VideoRewardSystem), &videoRewardSystem)
if err != nil {
return
}
if videoRewardSystem.RewardValue == "" || videoRewardSystem.RewardTotalNum == "" || videoRewardSystem.IntervalMinutes == "" || videoRewardSystem.EachRoundHour == "" {
err = errors.New("视屏奖励机制设置未完全!")
return
}
var rewardSystem []*md2.HappyOrchardVideoRewardSystemStruct
err = json.Unmarshal([]byte(base.VideoRewardSystem), &rewardSystem)
if err != nil {
return
}
if len(rewardSystem) == 0 {
err = errors.New("未设置奖励机制!")
return
}
//增加 one_circles_user_watch_records 记录
NewHappyOrchardUserWatchRecordsDb := implement.NewHappyOrchardUserWatchRecordsDb(svc.MasterDb(c))
UserWatchRecords, _ := NewHappyOrchardUserWatchRecordsDb.GetHappyOrchardUserWatchRecords(user.Info.Uid)
now := time.Now()
if UserWatchRecords == nil {
residueWatchAdNum := zhios_order_relate_utils.StrToInt(videoRewardSystem.RewardTotalNum) - 1
if residueWatchAdNum < 0 {
residueWatchAdNum = zhios_order_relate_utils.StrToInt(videoRewardSystem.RewardTotalNum)
}
_, err2 := eg.Insert(&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 := UserWatchRecords.ResidueWatchAdNum - 1
nextWatchAdDate := UserWatchRecords.NextWatchAdDate
if residueWatchAdNum == 0 { //最后一条广告
residueWatchAdNum = zhios_order_relate_utils.StrToInt(videoRewardSystem.RewardTotalNum)
}
if residueWatchAdNum == zhios_order_relate_utils.StrToInt(videoRewardSystem.RewardTotalNum)-1 { //第一条广告
nextWatchAdDate = now.Add(time.Hour * time.Duration(zhios_order_relate_utils.StrToInt(videoRewardSystem.EachRoundHour)))
}
UserWatchRecords.ResidueWatchAdNum = residueWatchAdNum
UserWatchRecords.NextWatchAdDate = nextWatchAdDate
_, err2 := NewHappyOrchardUserWatchRecordsDb.HappyOrchardUserWatchRecordsUpdate(UserWatchRecords.Id, UserWatchRecords, "residue_watch_ad_num")
if err2 != nil {
return
}
}

session := eg.NewSession()
defer func() {
session.Close()
if err := recover(); err != nil {
_ = zhios_order_relate_logx.Error(err)
}
}()
session.Begin()
amount := videoRewardSystem.RewardValue
if isMultiple == 1 {
amount = videoRewardSystem.MultipleRewardValue
}

if zhios_order_relate_utils.StrToFloat64(amount) > 0 {
//奖励
bools, _ := AddWaterNums(eg, session, uid, 1, amount, "领取水滴球")
if bools == false {
session.Rollback()
return
}
}
err = session.Commit()
if err != nil {
_ = session.Rollback()
return errors.New("事务提交失败")
}

redisKey := fmt.Sprintf(md2.HappyOrchardUserNextWatchAdDate, masterId, uid)
var watchAdDate string
if UserWatchRecords.ResidueWatchAdNum == zhios_order_relate_utils.StrToInt(videoRewardSystem.RewardTotalNum) {
if UserWatchRecords.NextWatchAdDate.Before(time.Now()) {
watchAdDate = ""
} else {
watchAdDate = UserWatchRecords.NextWatchAdDate.Format("2006-01-02 15:04:05")
}
} else {
watchAdDate = time.Now().Add(time.Duration(zhios_order_relate_utils.StrToInt64(videoRewardSystem.IntervalMinutes)) * time.Second).Format("2006-01-02 15:04:05")
}
cache.SetEx(redisKey, watchAdDate, 60*60*24) //TODO::默认缓存1小时
}
return
}
func AddWaterNums(eg *xorm.Engine, sess *xorm.Session, uid, kind int, amount, title string) (bool, error) {
newHappyOrchardUserWatersSess := implement.NewHappyOrchardUserWatersSess(sess)
watersSess, _ := newHappyOrchardUserWatersSess.GetHappyOrchardUserWatersSess(uid)
if watersSess == nil {
newHappyOrchardBasicSettingDb := implement.NewHappyOrchardBasicSettingDb(eg)
base, _ := newHappyOrchardBasicSettingDb.GetHappyOrchardBasicSetting()
watersSess = &models.HappyOrchardUserWaters{
Uid: uid,
CreateAt: time.Now().Format("2006-01-02 15:04:05"),
ReplaceSeedNums: base.ReplaceSeedNums,
}
insert, err := sess.Insert(watersSess)
if insert == 0 || err != nil {
return false, errors.New("获取水滴失败")
}
}
WaterNums := watersSess.WaterNums
if kind == 1 {
watersSess.WaterNums += zhios_order_relate_utils.StrToInt(amount)
} else {
watersSess.WaterNums -= zhios_order_relate_utils.StrToInt(amount)
if watersSess.WaterNums < 0 {
return false, errors.New("水滴不足")
}
}
watersSess.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
update, err := sess.Where("id=?", watersSess.Id).Update(watersSess)
if update == 0 || err != nil {
return false, errors.New("获取水滴失败")
}
log := &models.HappyOrchardUserWatersLog{
Uid: uid,
WaterNums: zhios_order_relate_utils.StrToInt(amount),
Title: title,
Kind: kind,
BeforeWaterNums: WaterNums,
AfterWaterNums: watersSess.WaterNums,
CreateAt: time.Now().Format("2006-01-02 15:04:05"),
UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
}
insert, err := sess.Insert(log)
if insert == 0 || err != nil {
return false, errors.New("获取水滴失败")
}
return true, nil
}

+ 11
- 0
rule/happy_orchard/md/happy_orchard.go Переглянути файл

@@ -0,0 +1,11 @@
package md

type HappyOrchardVideoRewardSystemStruct struct {
RewardValue string `json:"reward_value"` //奖励X个活跃积分
MultipleRewardValue string `json:"multiple_reward_value"` //奖励X个活跃积分
RewardTotalNum string `json:"reward_total_num"` //一共X个奖励视屏
IntervalMinutes string `json:"interval_minutes"` //间隔X秒
EachRoundHour string `json:"each_round_hour"` //每一轮X个小时
}

const HappyOrchardUserNextWatchAdDate = "%s:happy_orchard:user_next_watch_date:%d"

Завантаження…
Відмінити
Зберегти