ソースを参照

update 活跃积分自动兑换成绿色能量

master
dengbiao 8ヶ月前
コミット
4de614508a
2個のファイルの変更23行の追加134行の削除
  1. +4
    -2
      md/mq.go
  2. +19
    -132
      rule/one_circles/one_circles_activity_coin_auto_exchange_green_energy.go

+ 4
- 2
md/mq.go ファイルの表示

@@ -17,8 +17,10 @@ type OneCirclesStructForSignIn struct {
}

type OneCirclesStructForAutoExchangeGreenEnergy struct {
MasterId string `json:"master_id"`
Uid int `json:"uid"`
MasterId string `json:"master_id"`
Uid int `json:"uid"`
CoinId int `json:"coin_id"`
AutoExchangeNumsAmount string `json:"auto_exchange_nums_amount"`
}
type OneCirclesStructForStarLevelDividends struct {
MasterId string `json:"master_id"`


+ 19
- 132
rule/one_circles/one_circles_activity_coin_auto_exchange_green_energy.go ファイルの表示

@@ -19,13 +19,13 @@ import (
// ActivityCoinAutoExchangeGreenEnergyNew 活跃积分自动兑换成绿色能量
func ActivityCoinAutoExchangeGreenEnergyNew(engine *xorm.Engine, masterId string, ch *rabbit.Channel) (err error) {
//1、查找 `one_circles_green_energy_basic_setting` 基础设置 && `one_circles_public_platoon_basic_setting` 基础设置
oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{
"key": "is_open",
"value": 1,
})
if err != nil {
return
}
//oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{
// "key": "is_open",
// "value": 1,
//})
//if err != nil {
// return
//}

oneCirclesPublicPlatoonBasicSetting, err := db.OneCirclesPublicPlatoonBasicSettingGetOneByParams(engine, map[string]interface{}{
"key": "is_open",
@@ -84,142 +84,29 @@ func ActivityCoinAutoExchangeGreenEnergyNew(engine *xorm.Engine, masterId string
session.Begin()

for _, v := range list1 {
autoExchangeNumsByPersonValue, _ := decimal.NewFromString(v.Amount)
autoExchangeNumsByPersonAmount := autoExchangeNumsByPersonValue.Div(personActivePointsCoinExchangeRatioValue).String()
//TODO::推入rabbitmq 异步处理
ch.Publish(md.OneCirclesExchange, md.OneCirclesStructForAutoExchangeGreenEnergy{
MasterId: masterId,
Uid: v.Uid,
MasterId: masterId,
Uid: v.Uid,
CoinId: coin1.Id,
AutoExchangeNumsAmount: autoExchangeNumsByPersonAmount,
}, md.OneCirclesRoutKeyForAutoExchangeGreenEnergyToPerson)
}

for _, v := range list2 {
autoExchangeNumsByTeamValue, _ := decimal.NewFromString(v.Amount)
autoExchangeNumsByTeamAmount := autoExchangeNumsByTeamValue.Div(teamActivePointsCoinExchangeRatioValue).String()
//TODO::推入rabbitmq 异步处理
ch.Publish(md.OneCirclesExchange, md.OneCirclesStructForAutoExchangeGreenEnergy{
MasterId: masterId,
Uid: v.Uid,
MasterId: masterId,
Uid: v.Uid,
CoinId: coin1.Id,
AutoExchangeNumsAmount: autoExchangeNumsByTeamAmount,
}, md.OneCirclesRoutKeyForAutoExchangeGreenEnergyToTeam)
}

//4、处理"个人活跃积分"兑换
for _, v := range list1 {
autoExchangeNumsByPersonValue, _ := decimal.NewFromString(v.Amount)
autoExchangeNumsByPersonAmount := autoExchangeNumsByPersonValue.Div(personActivePointsCoinExchangeRatioValue).String()
//4.1计算涨价公式
err1, values, _, afterPriceValue := NewCalcPriceIncreaseFormula(autoExchangeNumsByPersonAmount, oneCirclesGreenEnergyBasicSetting)
if err1 != nil {
_ = session.Rollback()
return err1
}

//4.2给相应的用户加上个人的绿色积分(可用数量)
err = DealUserCoin(session, md.DealUserCoinReq{
Kind: "add",
Mid: masterId,
Title: md.OneCirclesPersonalActiveCoinExchangeGreenEnergy,
TransferType: md.OneCirclesPersonalActiveCoinExchangeGreenEnergyForUserVirtualCoinFlow,
OrdId: "",
CoinId: oneCirclesGreenEnergyBasicSetting.PersonGreenEnergyCoinId,
Uid: v.Uid,
Amount: zhios_order_relate_utils.StrToFloat64(values),
})
if err != nil {
_ = session.Rollback()
fmt.Println("err:::::33333", err)
return err
}

//4.3给相应的用户减去个人活跃积分
err = DealUserCoin(session, md.DealUserCoinReq{
Kind: "sub",
Mid: masterId,
Title: md.OneCirclesPersonalActiveCoinExchangeToBeGreenEnergy,
TransferType: md.OneCirclesPersonalActiveCoinExchangeToBeGreenEnergyForUserVirtualCoinFlow,
OrdId: "",
CoinId: oneCirclesPublicPlatoonBasicSetting.PersonActivePointsCoinId,
Uid: v.Uid,
Amount: zhios_order_relate_utils.StrToFloat64(v.Amount),
})
if err != nil {
_ = session.Rollback()
fmt.Println("err:::::33333", err)
return err
}

//4.4 减少“原始数量”中的绿色能量
err = DealAvailableGreenEnergyCoin(session, int(enum.PersonalActivePointRedemption), zhios_order_relate_utils.StrToFloat64(values), zhios_order_relate_utils.StrToFloat64(autoExchangeNumsByPersonAmount), enum.PersonalActivePointRedemption.String(), oneCirclesGreenEnergyBasicSetting, afterPriceValue)
if err != nil {
_ = session.Rollback()
fmt.Println("err:::::44444", err)
return err
}
}

//5、处理"团队活跃积分"兑换
for _, v := range list2 {
autoExchangeNumsByTeamValue, _ := decimal.NewFromString(v.Amount)
autoExchangeNumsByTeamAmount := autoExchangeNumsByTeamValue.Div(teamActivePointsCoinExchangeRatioValue).String()
//5.1计算涨价公式
err1, values, _, afterPriceValue := NewCalcPriceIncreaseFormula(autoExchangeNumsByTeamAmount, oneCirclesGreenEnergyBasicSetting)
if err1 != nil {
_ = session.Rollback()
return err1
}

//5.2给相应的用户加上个人的绿色积分(结算数量)
err = DealUserCoin(session, md.DealUserCoinReq{
Kind: "add",
Mid: masterId,
Title: md.OneCirclesTeamActiveCoinExchangeGreenEnergy,
TransferType: md.OneCirclesTeamActiveCoinExchangeGreenEnergyForUserVirtualCoinFlow,
OrdId: "",
CoinId: oneCirclesGreenEnergyBasicSetting.TeamGreenEnergyCoinId,
Uid: v.Uid,
Amount: zhios_order_relate_utils.StrToFloat64(values),
})
if err != nil {
_ = session.Rollback()
fmt.Println("err:::::33333", err)
return err
}

//5.3给相应的用户减去个人团队积分
err = DealUserCoin(session, md.DealUserCoinReq{
Kind: "sub",
Mid: masterId,
Title: md.OneCirclesTeamActiveCoinExchangeToBeGreenEnergy,
TransferType: md.OneCirclesTeamActiveCoinExchangeToBeGreenEnergyForUserVirtualCoinFlow,
OrdId: "",
CoinId: oneCirclesPublicPlatoonBasicSetting.TeamActivePointsCoinId,
Uid: v.Uid,
Amount: zhios_order_relate_utils.StrToFloat64(v.Amount),
})
if err != nil {
_ = session.Rollback()
fmt.Println("err:::::66666", err)
return err
}

//5.4 减少“原始数量”中的绿色能量
err = DealAvailableGreenEnergyCoin(session, int(enum.TeamActivePointRedemption), zhios_order_relate_utils.StrToFloat64(values), zhios_order_relate_utils.StrToFloat64(autoExchangeNumsByTeamAmount), enum.TeamActivePointRedemption.String(), oneCirclesGreenEnergyBasicSetting, afterPriceValue)
if err != nil {
_ = session.Rollback()
fmt.Println("err:::::44444", err)
return err
}
}

//6、修改 one_circles_green_energy_basic_setting 的 now_price
_, err = db.OneCirclesGreenEnergyBasicSettingUpdate(session, oneCirclesGreenEnergyBasicSetting.Id, oneCirclesGreenEnergyBasicSetting)
if err != nil {
_ = session.Rollback()
fmt.Println("err:::::77777", err)
return err
}

err = session.Commit()
if err != nil {
_ = session.Rollback()
return errors.New("事务提交失败")
}
return
}



読み込み中…
キャンセル
保存