diff --git a/db/db_user_level.go b/db/db_user_level.go index 6990057..47ece52 100644 --- a/db/db_user_level.go +++ b/db/db_user_level.go @@ -3,6 +3,7 @@ package db import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" + "errors" "xorm.io/xorm" ) @@ -16,6 +17,28 @@ func UserLevelInIDescByWeightLow(Db *xorm.Engine) ([]*model.UserLevel, error) { } +//UserLevelDescByWeightLow 查询获取 权重最低 对应等级 +func UserLevelDescByWeightLow(session *xorm.Session) (userIds []int, err error) { + var m model.UserLevel + isGet, err := session.Asc("level_weight").Limit(1).Get(&m) + if err != nil { + return userIds, err + } + if !isGet { + return userIds, errors.New("未查询到普通会员等级记录") + } + var userList []*model.User + err = session.Table("user").In("level", m.Id).Find(&userList) + if err != nil { + return userIds, err + } + for _, item := range userList { + userIds = append(userIds, item.Uid) + } + return userIds, nil + +} + // UserLevlEgAll is 获取所有开启等级并且升序返回 func UserLevlEgAll(Db *xorm.Engine) ([]*model.UserLevel, error) { var m []*model.UserLevel diff --git a/rule/block_star_chain_settlement.go b/rule/block_star_chain_settlement.go index b746105..a91c762 100644 --- a/rule/block_star_chain_settlement.go +++ b/rule/block_star_chain_settlement.go @@ -84,12 +84,18 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string) (err error) return err } + userIds, err := db.UserLevelDescByWeightLow(session) + if err != nil { + _ = session.Rollback() + return err + } + //4、进行静态区-区块币统计分配 var staticAreaCoinNums float64 //静态区分配区块币总数 publishCoinStaticRate, _ := decimal.NewFromString(blockStarChain.PublishCoinStaticRate) //区块币发行静态占比 publishCoinStaticRate = publishCoinStaticRate.Div(decimal.NewFromFloat(100)) staticAreaCoinNums = zhios_order_relate_utils.StrToFloat64(decimal.NewFromFloat(publishCoin).Mul(publishCoinStaticRate).String()) - err, destroyCoinForStatic := statisticsAndDistributeCoinForStatic(session, mid, staticAreaCoinNums, *blockStarChain) + err, destroyCoinForStatic := statisticsAndDistributeCoinForStatic(session, userIds, mid, staticAreaCoinNums, *blockStarChain) if err != nil { _ = session.Rollback() return err @@ -100,7 +106,7 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string) (err error) publishCoinDynamicRate, _ := decimal.NewFromString(blockStarChain.PublishCoinDynamicRate) //区块币发行动态占比 publishCoinDynamicRate = publishCoinDynamicRate.Div(decimal.NewFromFloat(100)) dynamicAreaCoinNums = zhios_order_relate_utils.StrToFloat64(decimal.NewFromFloat(publishCoin).Mul(publishCoinDynamicRate).String()) - err, destroyCoinForDynamic := statisticsAndDistributeCoinForDynamic(session, mid, dynamicAreaCoinNums, *blockStarChain) + err, destroyCoinForDynamic := statisticsAndDistributeCoinForDynamic(session, userIds, mid, dynamicAreaCoinNums, *blockStarChain) if err != nil { _ = session.Rollback() return err @@ -197,21 +203,21 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string) (err error) 统计分配区块币-静态区 TODO:: 公式【 个人贡献值/全网贡献值x2100枚=每天获取的惠积分 】 */ -func statisticsAndDistributeCoinForStatic(session *xorm.Session, mid string, publishCoin float64, chain model.BlockStarChain) (err error, unassignedTotalCoinValue float64) { +func statisticsAndDistributeCoinForStatic(session *xorm.Session, userIds []int, mid string, publishCoin float64, chain model.BlockStarChain) (err error, unassignedTotalCoinValue float64) { publishCoinValue := decimal.NewFromFloat(publishCoin) //静态区发行区块币数量 platformGuidePriceForCoinValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(chain.PlatformGuidePriceForCoin)) //今日平台区块币指导价 var unassignedTotalCoin = decimal.NewFromFloat(0) //未分配完的区块币 var userVirtualAmount model.UserVirtualAmount var userVirtualAmounts []model.UserVirtualAmount //1、统计出静态区总贡献值 - sumStatic, err := session.Table("user_virtual_amount").Where("coin_id =?", chain.Coin2).Sum(&userVirtualAmount, "amount") + sumStatic, err := session.Table("user_virtual_amount").In("uid", userIds).Where("coin_id =?", chain.Coin2).Sum(&userVirtualAmount, "amount") if err != nil { return err, unassignedTotalCoinValue } sumStaticValue := decimal.NewFromFloat(sumStatic) //2、查询出所有拥有静态贡献值的用户 - err = session.Table("user_virtual_amount").Where("coin_id =?", chain.Coin2).And("amount > 0").Find(&userVirtualAmounts) + err = session.Table("user_virtual_amount").In("uid", userIds).Where("coin_id =?", chain.Coin2).And("amount > 0").Find(&userVirtualAmounts) if err != nil { return err, unassignedTotalCoinValue } @@ -275,21 +281,22 @@ func statisticsAndDistributeCoinForStatic(session *xorm.Session, mid string, pub /* 统计分配区块币-动态区 */ -func statisticsAndDistributeCoinForDynamic(session *xorm.Session, mid string, publishCoin float64, chain model.BlockStarChain) (err error, unassignedTotalCoinValue float64) { +func statisticsAndDistributeCoinForDynamic(session *xorm.Session, userIds []int, mid string, publishCoin float64, chain model.BlockStarChain) (err error, unassignedTotalCoinValue float64) { publishCoinValue := decimal.NewFromFloat(publishCoin) //动态区发行区块币数量 platformGuidePriceForCoinValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(chain.PlatformGuidePriceForCoin)) //今日平台区块币指导价 var unassignedTotalCoin = decimal.NewFromFloat(0) //未分配完的区块币 var userVirtualAmount model.UserVirtualAmount var userVirtualAmounts []model.UserVirtualAmount + //1、统计出动态区总贡献值 - sumStatic, err := session.Table("user_virtual_amount").Where("coin_id =?", chain.Coin3).Sum(&userVirtualAmount, "amount") + sumStatic, err := session.Table("user_virtual_amount").In("uid", userIds).Where("coin_id =?", chain.Coin3).Sum(&userVirtualAmount, "amount") if err != nil { return err, unassignedTotalCoinValue } sumStaticValue := decimal.NewFromFloat(sumStatic) //2、查询出所有拥有静态贡献值的用户 - err = session.Table("user_virtual_amount").Where("coin_id =?", chain.Coin2).And("amount > 0").Find(&userVirtualAmounts) + err = session.Table("user_virtual_amount").In("uid", userIds).Where("coin_id =?", chain.Coin2).And("amount > 0").Find(&userVirtualAmounts) if err != nil { return err, unassignedTotalCoinValue }