Kaynağa Gözat

update

master
dengbiao 3 ay önce
ebeveyn
işleme
da7c2fc02d
2 değiştirilmiş dosya ile 41 ekleme ve 53 silme
  1. +13
    -0
      md/mq.go
  2. +28
    -53
      rule/one_circles/one_circles_sign_in_green_energy_settlement.go

+ 13
- 0
md/mq.go Dosyayı Görüntüle

@@ -9,6 +9,7 @@ const (
OneCirclesRoutKeyForAutoExchangeGreenEnergyToPerson = "auto_exchange_green_energy_to_person_1" // 自动兑换个人绿色能量
OneCirclesRoutKeyForAutoExchangeGreenEnergyToTeam = "auto_exchange_green_energy_to_team" // 自动兑换团队绿色能量
OneCirclesRoutKeyForSettlementPublicGiveActivityCoin = "settlement_public_give_activity_coin" // 计算观看激励视屏得到活跃积分
OneCirclesRoutKeyForRewardUserCoin = "reward_user_coin" // 奖励用户虚拟币

)

@@ -35,3 +36,15 @@ type OneCirclesStructForStarLevelDividends struct {
Uid int `json:"uid"`
SignDividend float64 `json:"sign_dividend"`
}

type OneCirclesDealUserCoinStruct struct {
Kind string `json:"kind"`
Mid string `json:"mid"`
Title string `json:"title"`
TransferType int `json:"transfer_type"`
OrdId string `json:"ord_id"`
CoinId int `json:"coin_id"`
Uid int `json:"uid"`
ToUid int `json:"to_uid"`
Amount float64 `json:"amount"`
}

+ 28
- 53
rule/one_circles/one_circles_sign_in_green_energy_settlement.go Dosyayı Görüntüle

@@ -5,13 +5,10 @@ import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/enum"
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/svc"
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"
"encoding/json"
"errors"
"fmt"
@@ -75,17 +72,18 @@ func SettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, ch *rabbi

func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine, masterId string, id int64, uid int, endTime string) (err error) {
//1、查找 `one_circles_green_energy_basic_setting` 基础设置
//oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{
// "key": "is_open",
// "value": 1,
//})
oneCirclesGreenEnergyBasicSetting, cb, err := svc.GetPrice(engine, masterId)
if err != nil {
return
}
if cb != nil {
defer cb() // 释放锁
}
//oneCirclesGreenEnergyBasicSetting, cb, err := svc.GetPrice(engine, masterId)
//if err != nil {
// return
//}
//if cb != nil {
// defer cb() // 释放锁
//}

oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{
"key": "is_open",
"value": 1,
})

var teamRewardSetting *md2.TeamRewardSettingStruct
err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.TeamReward), &teamRewardSetting)
@@ -110,18 +108,10 @@ func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine,
rewardValue := zhios_order_relate_utils.Float64ToStrPrec8(zhios_order_relate_utils.StrToFloat64(reward) * float64(oneRoundDuration) * 60 * 60)

//3、统计签到结束的用户数据
session := engine.NewSession()
defer func() {
session.Close()
if err := recover(); err != nil {
_ = zhios_order_relate_logx.Error(err)
}
}()
session.Begin()

var reduceTotalGreenEnergy float64
//4.2给相应的用户加上个人的绿色积分(可用数量)
err = rule.DealUserCoin(session, md.DealUserCoinReq{
var oneCirclesDealUserCoinData = md.OneCirclesDealUserCoinStruct{
Kind: "add",
Mid: masterId,
Title: md.OneCirclesGreenEnergySignInSettlementPersonalReward,
@@ -130,21 +120,16 @@ func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine,
CoinId: oneCirclesGreenEnergyBasicSetting.PersonGreenEnergyCoinId,
Uid: uid,
Amount: zhios_order_relate_utils.StrToFloat64(rewardValue),
})
if err != nil {
_ = session.Rollback()
fmt.Println("err:::::2222", err)
return err
}
reduceTotalGreenEnergy += zhios_order_relate_utils.StrToFloat64(rewardValue)

reduceTotalGreenEnergy += zhios_order_relate_utils.StrToFloat64(rewardValue)
//4.2给相应的上级用户加上团队奖励的绿色积分(结算数量)
relates, err1 := db.DbsUserRelate(engine, uid, 0)
if err1 != nil {
_ = session.Rollback()
fmt.Println("err:::::3333", err1)
return err1
}
var oneCirclesDealUserCoinDataForParents []md.OneCirclesDealUserCoinStruct
var parentRewardValue = zhios_order_relate_utils.StrToFloat64(rewardValue)
if relates != nil {
for _, relate := range *relates {
@@ -157,7 +142,6 @@ func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine,
if endTime != "" {
has, err3333333 := engine.Where("uid =?", relate.ParentUid).And("end_time >=?", endTime).Get(&m)
if err3333333 != nil {
_ = session.Rollback()
fmt.Println("err:::::3333333", err3333333)
return err3333333
}
@@ -168,7 +152,6 @@ func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine,
} else {
has, err3333333 := engine.Where("uid =?", relate.ParentUid).And("end_time >=?", time.Now().Format("2006-01-02 15:04:05")).Get(&m)
if err3333333 != nil {
_ = session.Rollback()
fmt.Println("err:::::3333333", err3333333)
return err3333333
}
@@ -178,7 +161,7 @@ func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine,
}
}

err = rule.DealUserCoin(session, md.DealUserCoinReq{
oneCirclesDealUserCoinDataForParents = append(oneCirclesDealUserCoinDataForParents, md.OneCirclesDealUserCoinStruct{
Kind: "add",
Mid: masterId,
Title: md.OneCirclesGreenEnergySignInSettlementTeamReward,
@@ -188,40 +171,32 @@ func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine,
Uid: relate.ParentUid,
Amount: parentRewardValue,
})
if err != nil {
_ = session.Rollback()
fmt.Println("err:::::44444", err)
return err
}
reduceTotalGreenEnergy += parentRewardValue
}
}

//5、减少“活跃赠送” 中的绿色能量
if reduceTotalGreenEnergy > 0 {
err = DealAvailableGreenEnergyCoin(session, int(enum.SignInReward), reduceTotalGreenEnergy, 0, enum.SignInReward.String(), oneCirclesGreenEnergyBasicSetting, oneCirclesGreenEnergyBasicSetting.NowPrice, masterId)
//err = DealAvailableGreenEnergyCoin(session, int(enum.SignInReward), reduceTotalGreenEnergy, 0, enum.SignInReward.String(), nil, "", masterId)
err = DealAvailableGreenEnergyCoin(engine.NewSession(), int(enum.SignInReward), reduceTotalGreenEnergy, 0, enum.SignInReward.String(), oneCirclesGreenEnergyBasicSetting, oneCirclesGreenEnergyBasicSetting.NowPrice, masterId)
if err != nil {
_ = session.Rollback()
fmt.Println("err:::::55555", err)
return err
}
}

//6、更新 `one_circles_green_energy_sign_in` 中的 is_completed 状态
//_, err = session.Where("id = ?", id).Update(&model.OneCirclesGreenEnergySignIn{
// IsCompleted: 1,
//})
//TODO::推入rabbitmq 异步处理
ch.Publish(md.OneCirclesExchange, md.UpdateOneCirclesStructForSignInRecords{
Uid: uid,
Id: id,
}, md.OneCirclesRoutKeyForSignInUpdateRecords)

err = session.Commit()
_, err = engine.Where("id = ?", id).Update(&model.OneCirclesGreenEnergySignIn{
IsCompleted: 1,
})
if err != nil {
_ = session.Rollback()
return errors.New("事务提交失败")
fmt.Println("err:::::66666", err)
return err
}

////TODO::推入rabbitmq 异步处理
ch.Publish(md.OneCirclesExchange, oneCirclesDealUserCoinData, md.OneCirclesRoutKeyForRewardUserCoin) //个人的奖励
for _, oneCirclesDealUserCoinDataForParent := range oneCirclesDealUserCoinDataForParents {
ch.Publish(md.OneCirclesExchange, oneCirclesDealUserCoinDataForParent, md.OneCirclesRoutKeyForRewardUserCoin) //上级的奖励
}

return


Yükleniyor…
İptal
Kaydet