shenjiachi 2 дні тому
джерело
коміт
234f68733a
6 змінених файлів з 401 додано та 2 видалено
  1. +2
    -2
      go.mod
  2. +4
    -0
      go.sum
  3. +106
    -0
      rule/egg_energy/home_page_start_sign_in.go
  4. +265
    -0
      rule/egg_energy/home_page_watch_over_ad.go
  5. +14
    -0
      rule/egg_energy/md/md_home_page.go
  6. +10
    -0
      rule/egg_energy/md/mq.go

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

@@ -3,7 +3,7 @@ module code.fnuoos.com/EggPlanet/egg_system_rules.git
go 1.19

// go.mod文件中
//replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models
// replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models

require (
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
@@ -40,7 +40,7 @@ require (
)

require (
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241119093836-37be936b83fc
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241128102555-fc839292d728
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/json-iterator/go v1.1.12 // indirect


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

@@ -2,6 +2,10 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241119093836-37be936b83fc h1:ZCnxqXjf4WDPUk55yWTixpt05zLqqnxS3D6DEs2L730=
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241119093836-37be936b83fc/go.mod h1:+bDK4gfBq4LEkhh6K/A46+0urH/sgxDxnjIjlxb9HI8=
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241128073036-d909efb5edd0 h1:MQ430z584rNgjstWv9XB/bbYiJuLB1Vv21jJFIAmx8s=
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241128073036-d909efb5edd0/go.mod h1:+bDK4gfBq4LEkhh6K/A46+0urH/sgxDxnjIjlxb9HI8=
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241128102555-fc839292d728 h1:BHW0yPeka1RRS4pIcZKwiatVg9U4mE8iiTl1+YCk1vQ=
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241128102555-fc839292d728/go.mod h1:+bDK4gfBq4LEkhh6K/A46+0urH/sgxDxnjIjlxb9HI8=
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 h1:dqvWJqlJi0WXCwTxbWPLvSOsKPjP+iEDBVgLcAl9nOE=
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5/go.mod h1:TTcCnFn/LhBGapnutpezlW+GXkLRNPMWkziOoCsXQqY=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=


+ 106
- 0
rule/egg_energy/home_page_start_sign_in.go Переглянути файл

@@ -0,0 +1,106 @@
package egg_energy

import (
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
zhios_order_relate_utils "code.fnuoos.com/EggPlanet/egg_models.git/utils"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"encoding/json"
"errors"
"time"
"xorm.io/xorm"
)

// HomePageStartSignIn 主页发起签到
func HomePageStartSignIn(engine *xorm.Engine, req md.HomePageStartSignInReq) error {
now := time.Now()
zhios_order_relate_utils.FilePutContents("HomePageStartSignIn", zhios_order_relate_utils.SerializeStr(map[string]interface{}{
"body": string(req.Body),
"token": req.Token,
"user_phone": req.Phone,
"user_uid": req.UID,
"time": now.Format("2006-01-02 15:04:05"),
"ip": req.IP,
}))

//1、查找基础设置
basicSettingDb := implement.NewEggEnergyBasicSettingDb(engine)
basicSetting, err := basicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{
"key": "is_open",
"value": 1,
})
if err != nil {
return err
}

var directPushRewardSetting *md.DirectPushRewardSettingStruct
err = json.Unmarshal([]byte(basicSetting.DirectPushReward), &directPushRewardSetting)
if err != nil {
return err
}

//TODO:: 查询当前用户观看视屏记录
var videoRewardSystem *md.VideoRewardSystemStruct
err = json.Unmarshal([]byte(basicSetting.VideoRewardSystem), &videoRewardSystem)
if err != nil {
return err
}
rewardTotalNum := zhios_order_relate_utils.StrToInt(videoRewardSystem.RewardTotalNum)
recordsDb := implement.NewEggEnergyUserWatchRecordsDb(engine)
records, err := recordsDb.EggEnergyUserWatchRecordsGetOneByParams(map[string]interface{}{
"key": "uid",
"value": req.UID,
})
if err != nil {
return err
}
var isCan bool
if records != nil && records.ResidueWatchAdNum == rewardTotalNum && records.NextWatchAdDate.After(now) {
//TODO::观看记录不为空, 剩余观看次数 = 一共X个奖励视屏, 下轮观看视屏时间在当前时间之后
isCan = true
}
if !isCan {
zhios_order_relate_utils.FilePutContents("HomePageStartSignInBad", zhios_order_relate_utils.SerializeStr(map[string]interface{}{
"body": string(req.Body),
"token": req.Token,
"header": req.Header,
"user_phone": req.Phone,
"user_uid": req.UID,
"time": now.Format("2006-01-02 15:04:05"),
"ip": req.IP,
}))
return errors.New("不满足签到条件")
}

signInDb := implement.NewEggSignInDb(engine)
var oneRoundDuration = zhios_order_relate_utils.StrToInt(videoRewardSystem.EachRoundHour)
startTime := now.Add(-time.Hour * time.Duration(oneRoundDuration)).Format("2006-01-02 15:04:05")
get, eggSignIn, err := signInDb.EggSignINGetOneByTimeAndUid(startTime, "", req.UID, 0)
if err != nil {
return err
}
if get && zhios_order_relate_utils.String2Time(eggSignIn.EndTime).After(now) {
zhios_order_relate_utils.FilePutContents("HomePageStartSignInERR", zhios_order_relate_utils.SerializeStr(map[string]interface{}{
"body": string(req.Body),
"token": req.Token,
"header": req.Header,
"user_phone": req.Phone,
"user_uid": req.UID,
"time": now.Format("2006-01-02 15:04:05"),
"ip": req.IP,
}))
return errors.New("非签到时间," + "请求账号:" + req.Phone + ",请求时间:" + now.Format("2006-01-02 15:04:05") + ",签到时间:" + eggSignIn.EndTime)
}

ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {
return err
}
defer ch.Release()

err = ActivityCoinReadyExchangeEggEnergy(engine, req.UID, ch)
if err != nil {
return err
}
return nil
}

+ 265
- 0
rule/egg_energy/home_page_watch_over_ad.go Переглянути файл

@@ -0,0 +1,265 @@
package egg_energy

import (
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
zhios_order_relate_utils "code.fnuoos.com/EggPlanet/egg_models.git/utils"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/cache"
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/logx"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"encoding/json"
"errors"
"fmt"
"strings"
"time"
"xorm.io/xorm"
)

// HomePageWatchOverAd 观看完广告
func HomePageWatchOverAd(engine *xorm.Engine, req md.HomePageWatchOverAdReq) error {
redisKey := fmt.Sprintf(md.UserNextWatchAdDate, req.UID)
nextWatchAdDate, _ := cache.GetString(redisKey)
if nextWatchAdDate != "" {
nextWatchAdDateValue := zhios_order_relate_utils.String2Time(nextWatchAdDate)
if nextWatchAdDateValue.After(time.Now()) {
return errors.New("非观看广告时间")
}
}
ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {
return err
}
defer ch.Release()

err = settlementPublicGiveActivityCoin(engine, req.UID, ch)
if err != nil {
return err
}

return nil
}

func settlementPublicGiveActivityCoin(engine *xorm.Engine, uid int64, ch *rabbit.Channel) error {
//1、查找 `basic_setting` 基础设置
settingDb := implement.NewEggEnergyBasicSettingDb(engine)
setting, err := settingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{
"key": "is_open",
"value": 1,
})
if err != nil {
return err
}

if setting.VideoRewardIsOpen == 1 {
var videoRewardSystem *md.VideoRewardSystemStruct
err = json.Unmarshal([]byte(setting.VideoRewardSystem), &videoRewardSystem)
if err != nil {
return err
}
if videoRewardSystem.RewardValue == "" || videoRewardSystem.RewardTotalNum == "" || videoRewardSystem.IntervalMinutes == "" || videoRewardSystem.EachRoundHour == "" {
err = errors.New("视屏奖励机制设置未完全!")
return err
}
var rewardSystem []*md.RewardSystemStruct
err = json.Unmarshal([]byte(setting.RewardSystem), &rewardSystem)
if err != nil {
return err
}
if len(rewardSystem) == 0 {
err = errors.New("未设置奖励机制!")
return err
}
rewardValue := zhios_order_relate_utils.StrToFloat64(videoRewardSystem.RewardValue) //奖励多少个活跃积分
var rewardSystemMap = map[int]*md.RewardSystemStruct{}
for _, v := range rewardSystem {
rewardSystemMap[v.Level] = v
}
publicPlatoonUserRelationDb := implement.NewPublicPlatoonUserRelationDb(engine)
publicPlatoonUserRelation, err1 := publicPlatoonUserRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
"key": "uid",
"value": uid,
})
if err1 != nil {
return err1
}

var rewardFather []struct {
Uid int `json:"uid"` //用户id
RewardValue float64 `json:"reward_value"` //奖励值
}

var fatherUids []string
if publicPlatoonUserRelation != nil {
fatherUids = strings.Split(publicPlatoonUserRelation.FatherUid, "-")
}
signInDb := implement.NewEggSignInDb(engine)
userRelateDb := implement.NewUserRelateDb(engine)
for k, id := range fatherUids {
tempRelation, err2 := publicPlatoonUserRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
"key": "id",
"value": id,
})
if err2 != nil {
return err2
}

if tempRelation == nil {
continue
}
if tempRelation.Uid <= 0 {
//待填充位
continue
}

fatherUid := zhios_order_relate_utils.Int64ToStr(tempRelation.Uid)
fatherReward := rewardSystemMap[k+1]
//TODO::判断是否活跃
has, _, err := signInDb.EggSignINGetOneByTimeAndUid("", time.Now().Format("2006-01-02 15:04:05"), zhios_order_relate_utils.StrToInt64(fatherUid), 1)
if err != nil {
return err
}
if !has {
//不活跃不需要奖励
continue
}
//判断是否满足奖励条件
userCount, _, err := userRelateDb.SumUserRelateByParentUid(fatherUid)
if err != nil {
return err
}

if fatherReward != nil && userCount >= zhios_order_relate_utils.StrToInt64(fatherReward.RewardCondition) {
fatherRewardValue := rewardValue * (zhios_order_relate_utils.StrToFloat64(fatherReward.RewardValue) / 100)
rewardFather = append(rewardFather, struct {
Uid int `json:"uid"` //用户id
RewardValue float64 `json:"reward_value"` //奖励值
}{
Uid: zhios_order_relate_utils.StrToInt(fatherUid),
RewardValue: fatherRewardValue,
})
}
}

//增加 circles_user_watch_records 记录
watchRecordsDb := implement.NewEggEnergyUserWatchRecordsDb(engine)
watchRecord, err := watchRecordsDb.EggEnergyUserWatchRecordsGetOneByParams(map[string]interface{}{
"key": "uid",
"value": uid,
})
if err != nil {
return err
}
now := time.Now()
if watchRecord == nil {
residueWatchAdNum := zhios_order_relate_utils.StrToInt(videoRewardSystem.RewardTotalNum) - 1
if residueWatchAdNum < 0 {
residueWatchAdNum = zhios_order_relate_utils.StrToInt(videoRewardSystem.RewardTotalNum)
}
tempM := model.EggEnergyUserWatchRecords{
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.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
}
_, err := watchRecordsDb.EggEnergyUserWatchRecordsInsert(&tempM)
if err != nil {
return err
}
} else {
residueWatchAdNum := watchRecord.ResidueWatchAdNum - 1
nextWatchAdDate := watchRecord.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)))
}
watchRecord.ResidueWatchAdNum = residueWatchAdNum
watchRecord.NextWatchAdDate = nextWatchAdDate
_, err := watchRecordsDb.EggEnergyUserWatchRecordsUpdate(watchRecord.Id, watchRecord, "residue_watch_ad_num", "next_watch_ad_date")
if err != nil {
return err
}
}

session := engine.NewSession()
defer func() {
session.Close()
if err := recover(); err != nil {
_ = zhios_order_relate_logx.Error(err)
}
}()
session.Begin()

//给相应的用户加上"个人"活跃积分
err = rule.DealUserVirtualCoin(session, md2.DealUserVirtualCoinReq{
Kind: "add",
Title: enum.EggEnergyWatchAdRewardPersonalActiveCoin.String(),
TransferType: int(enum.EggEnergyWatchAdRewardPersonalActiveCoin),
CoinId: setting.PersonEggPointsCoinId,
Uid: uid,
Amount: rewardValue,
})
if err != nil {
_ = session.Rollback()
fmt.Println("after watch over ad to deal user virtual coin err:::::2222", err)
return err
}

//给相应的用户加上"团队"活跃积分
for _, vv := range rewardFather {
//TODO::推入rabbitmq 异步处理
ch.Publish(md.EggEnergyExchange, md.EggEnergyStructForDealUserVirtualCoinData{
Kind: "add",
Title: enum.EggEnergyWatchAdRewardTeamActiveCoin.String(),
TransferType: int(enum.EggEnergyWatchAdRewardTeamActiveCoin),
CoinId: setting.TeamEggPointsCoinId,
Uid: int64(vv.Uid),
Amount: vv.RewardValue,
}, md.EggEnergyRoutKeyForDealUserVirtualCoinData)
//err = DealUserCoin(session, md.DealUserCoinReq{
// Kind: "add",
// Mid: masterId,
// Title: md.OneCirclesWatchAdRewardTeamActiveCoin,
// TransferType: md.OneCirclesWatchAdRewardTeamActiveCoinForUserVirtualCoinFlow,
// OrdId: "",
// CoinId: oneCirclesPublicPlatoonBasicSetting.TeamActivePointsCoinId,
// Uid: vv.Uid,
// Amount: vv.RewardValue,
//})
//if err != nil {
// _ = session.Rollback()
// fmt.Println("err:::::2222", err)
// return err
//}
}
err = session.Commit()
if err != nil {
_ = session.Rollback()
return errors.New("事务提交失败")
}
if watchRecord == nil {
return nil
}

redisKey := fmt.Sprintf(md.UserNextWatchAdDate, uid)
var watchAdDate string
if watchRecord.ResidueWatchAdNum == zhios_order_relate_utils.StrToInt(videoRewardSystem.RewardTotalNum) {
if watchRecord.NextWatchAdDate.Before(time.Now()) {
watchAdDate = ""
} else {
watchAdDate = watchRecord.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")
//watchAdDate = oneCirclesUserWatchRecords.NextWatchAdDate.Format("2006-01-02 15:04:05")
}
cache.SetEx(redisKey, watchAdDate, 60*60*24) //TODO::默认缓存1小时
}
return nil
}

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

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

type HomePageStartSignInReq struct {
UID int64 `json:"uid"` // 用户 ID
Body []byte `json:"body"` // 请求体
Token string `json:"token"` // token
Phone string `json:"phone"` // 手机号
IP string `json:"ip"` // ip
Header string `json:"header"` // 请求头
}

type HomePageWatchOverAdReq struct {
UID int64 `json:"uid"` // 用户 ID
}

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

@@ -12,6 +12,7 @@ const (
EggEnergyRoutKeyForAutoExchangeGreenEnergyToTeam = "auto_exchange_egg_energy_to_team" // 自动兑换团队蛋蛋能量
EggEnergyRoutKeyForEggEnergyFundData = "fund_data" // 资金汇入
EggEnergyRoutKeyForPlatformRevenueData = "platform_revenue_data" // 平台收入
EggEnergyRoutKeyForDealUserVirtualCoinData = "deal_user_virtual_coin" // 处理给用户虚拟币积分
IMEggEnergyRoutKeyForBatchSendMessageData = "batch_send_message_data" // 批量发送信息
)

@@ -66,3 +67,12 @@ type IMEggEnergyStructForBatchSendMessageData struct {
ReceiveIMId int64 `json:"receive_id"` // 接受者IM id
Content string `json:"content"` // 消息内容
}

type EggEnergyStructForDealUserVirtualCoinData struct {
Kind string `json:"kind"`
Title string `json:"title"`
TransferType int `json:"transfer_type"`
CoinId int `json:"coin_id"`
Uid int64 `json:"uid"`
Amount float64 `json:"amount"`
}

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