Browse Source

update

master
dengbiao 8 months ago
parent
commit
e1724f140d
1 changed files with 72 additions and 14 deletions
  1. +72
    -14
      rule/one_circles/one_circles_activity_coin_auto_exchange_green_energy.go

+ 72
- 14
rule/one_circles/one_circles_activity_coin_auto_exchange_green_energy.go View File

@@ -251,35 +251,23 @@ func ActivityCoinAutoExchangeGreenEnergy(engine *xorm.Engine, masterId string) (
return return
} }
var autoExchangeNumsByPerson = zhios_order_relate_utils.StrToFloat64(exchangeRulesStruct.AutoExchangeNumsByPerson) //个人活跃积分X个自动兑换 var autoExchangeNumsByPerson = zhios_order_relate_utils.StrToFloat64(exchangeRulesStruct.AutoExchangeNumsByPerson) //个人活跃积分X个自动兑换
var autoExchangeNumsByTeam = zhios_order_relate_utils.StrToFloat64(exchangeRulesStruct.AutoExchangeNumsByTeam) //团队活跃积分X个自动兑换
fmt.Println("autoExchangeNumsByPerson>>>>>>>>>>>>", autoExchangeNumsByPerson) fmt.Println("autoExchangeNumsByPerson>>>>>>>>>>>>", autoExchangeNumsByPerson)
fmt.Println("autoExchangeNumsByTeam>>>>>>>>>>>>", autoExchangeNumsByTeam)


//2、获取"个人活跃积分" && 获取"团队活跃积分" //2、获取"个人活跃积分" && 获取"团队活跃积分"
var coin1, coin2 model.VirtualCoin
var coin1 model.VirtualCoin
_, err = engine.Where("id = ?", oneCirclesPublicPlatoonBasicSetting.PersonActivePointsCoinId).Get(&coin1) _, err = engine.Where("id = ?", oneCirclesPublicPlatoonBasicSetting.PersonActivePointsCoinId).Get(&coin1)
if err != nil { if err != nil {
return err return err
} }
_, err = engine.Where("id = ?", oneCirclesPublicPlatoonBasicSetting.TeamActivePointsCoinId).Get(&coin2)
if err != nil {
return err
}
personActivePointsCoinExchangeRatioValue, _ := decimal.NewFromString(coin1.ExchangeRatio) personActivePointsCoinExchangeRatioValue, _ := decimal.NewFromString(coin1.ExchangeRatio)
teamActivePointsCoinExchangeRatioValue, _ := decimal.NewFromString(coin2.ExchangeRatio)


//3、当前 "个人活跃积分"可以自动兑换的用户数据 && "团队活跃积分"可以自动兑换的用户数据 //3、当前 "个人活跃积分"可以自动兑换的用户数据 && "团队活跃积分"可以自动兑换的用户数据
var list1, list2 []model.UserVirtualAmount
var list1 []model.UserVirtualAmount
err = engine.Where("coin_id = ?", oneCirclesPublicPlatoonBasicSetting.PersonActivePointsCoinId).And("amount >=?", autoExchangeNumsByPerson).Limit(1000, 0).Find(&list1) err = engine.Where("coin_id = ?", oneCirclesPublicPlatoonBasicSetting.PersonActivePointsCoinId).And("amount >=?", autoExchangeNumsByPerson).Limit(1000, 0).Find(&list1)
if err != nil { if err != nil {
fmt.Println("err:::::1111", err.Error()) fmt.Println("err:::::1111", err.Error())
return return
} }
err = engine.Where("coin_id = ?", oneCirclesPublicPlatoonBasicSetting.TeamActivePointsCoinId).And("amount >=?", autoExchangeNumsByTeam).Limit(1000, 0).Find(&list2)
if err != nil {
fmt.Println("err:::::2222", err.Error())
return
}


//4、处理"个人活跃积分"兑换 //4、处理"个人活跃积分"兑换
for _, v := range list1 { for _, v := range list1 {
@@ -340,6 +328,76 @@ func ActivityCoinAutoExchangeGreenEnergy(engine *xorm.Engine, masterId string) (
session.Close() session.Close()
} }


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

//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.Error())
return err
}

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

// ActivityCoinAutoExchangeGreenEnergyForTeam 活跃积分自动兑换成绿色能量
func ActivityCoinAutoExchangeGreenEnergyForTeam(engine *xorm.Engine, masterId string) (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
}

oneCirclesPublicPlatoonBasicSetting, err := db.OneCirclesPublicPlatoonBasicSettingGetOneByParams(engine, map[string]interface{}{
"key": "is_open",
"value": 1,
})
if err != nil {
return
}
if oneCirclesPublicPlatoonBasicSetting.ExchangeRules == "" {
err = errors.New("自动兑换未设置!")
return
}
var exchangeRulesStruct *md2.ExchangeRulesStruct
err = json.Unmarshal([]byte(oneCirclesPublicPlatoonBasicSetting.ExchangeRules), &exchangeRulesStruct)
if err != nil {
return
}
var autoExchangeNumsByTeam = zhios_order_relate_utils.StrToFloat64(exchangeRulesStruct.AutoExchangeNumsByTeam) //团队活跃积分X个自动兑换
fmt.Println("autoExchangeNumsByTeam>>>>>>>>>>>>", autoExchangeNumsByTeam)

//2、获取"个人活跃积分" && 获取"团队活跃积分"
var coin2 model.VirtualCoin
_, err = engine.Where("id = ?", oneCirclesPublicPlatoonBasicSetting.TeamActivePointsCoinId).Get(&coin2)
if err != nil {
return err
}
teamActivePointsCoinExchangeRatioValue, _ := decimal.NewFromString(coin2.ExchangeRatio)

//3、当前 "个人活跃积分"可以自动兑换的用户数据 && "团队活跃积分"可以自动兑换的用户数据
var list2 []model.UserVirtualAmount
err = engine.Where("coin_id = ?", oneCirclesPublicPlatoonBasicSetting.TeamActivePointsCoinId).And("amount >=?", autoExchangeNumsByTeam).Limit(1000, 0).Find(&list2)
if err != nil {
fmt.Println("err:::::2222", err.Error())
return
}

//5、处理"团队活跃积分"兑换 //5、处理"团队活跃积分"兑换
for _, v := range list2 { for _, v := range list2 {
session := engine.NewSession() session := engine.NewSession()


Loading…
Cancel
Save