Sfoglia il codice sorgente

update 区块星链

tags/v3.2.2
DengBiao 2 anni fa
parent
commit
c14eeb6919
2 ha cambiato i file con 138 aggiunte e 50 eliminazioni
  1. +24
    -20
      md/block_star_chain.go
  2. +114
    -30
      rule/block_star_chain_settlement.go

+ 24
- 20
md/block_star_chain.go Vedi File

@@ -11,12 +11,14 @@ const (
) )


const ( const (
StaticAreaDistributionTitleForUserVirtualCoinFlow = "区块星链-静态区发放"
DynamicAreaDistributionTitleForUserVirtualCoinFlow = "区块星链-动态区发放"
OperationCenterTitleForUserVirtualCoinFlow = "区块星链-运营中心发放"
OtherTitleForUserVirtualCoinFlow = "区块星链-其他发放"
StaticIssueAndDestroyStaticContributionTitleForUserVirtualCoinFlow = "区块星链-静态发放(销毁静态贡献值)"
DynamicIssueAndDestroyStaticContributionTitleForUserVirtualCoinFlow = "区块星链-动态发放(销毁静态贡献值)"
StaticAreaDistributionTitleForUserVirtualCoinFlow = "区块星链-静态区发放"
DynamicAreaDistributionTitleForUserVirtualCoinFlow = "区块星链-动态区发放"
OperationCenterTitleForUserVirtualCoinFlow = "区块星链-运营中心发放"
OtherTitleForUserVirtualCoinFlow = "区块星链-其他发放"
StaticIssueAndDestroyStaticContributionTitleForUserVirtualCoinFlow = "区块星链-静态发放(销毁静态贡献值)"
DynamicIssueAndDestroyStaticContributionTitleForUserVirtualCoinFlow = "区块星链-动态发放(销毁静态贡献值)"
OperationCenterAndDestroyStaticContributionTitleForUserVirtualCoinFlow = "区块星链-运营中心发放(销毁静态贡献值)"
OtherAndDestroyStaticContributionTitleForUserVirtualCoinFlow = "区块星链-其他发放(销毁静态贡献值)"


RegisterRewardTitleForUserVirtualCoinFlow = "区块星链-注册奖励" RegisterRewardTitleForUserVirtualCoinFlow = "区块星链-注册奖励"
InviteRegisterRewardTitleForUserVirtualCoinFlow = "区块星链-邀请注册奖励" InviteRegisterRewardTitleForUserVirtualCoinFlow = "区块星链-邀请注册奖励"
@@ -42,20 +44,22 @@ const (
OperationCenterTransferTypeForUserVirtualCoinFlow = 104 // 区块星链-运营中心发放 OperationCenterTransferTypeForUserVirtualCoinFlow = 104 // 区块星链-运营中心发放
OtherTransferTypeForUserVirtualCoinFlow = 105 // 区块星链-其他发放 OtherTransferTypeForUserVirtualCoinFlow = 105 // 区块星链-其他发放


RegisterRewardTransferTypeForUserVirtualCoinFlow = 106 //区块星链-注册奖励
InviteRegisterRewardTransferTypeForUserVirtualCoinFlow = 107 //区块星链-邀请注册奖励
OfflineConsumeDirectPushRewardByUserTransferTypeForUserVirtualCoinFlow = 108 //区块星链-线下消费直推奖励(用户)
OfflineConsumeDirectPushRewardByBusinessTransferTypeForUserVirtualCoinFlow = 109 //区块星链-线下消费直推奖励(商家)
OfflineConsumeGroupRewardByUserTransferTypeForUserVirtualCoinFlow = 110 //区块星链-线下消费团队奖励(用户)
OfflineConsumeGroupRewardByBusinessTransferTypeForUserVirtualCoinFlow = 111 //区块星链-线下消费团队奖励(商家)
OnlineConsumeDirectPushRewardTransferTypeForUserVirtualCoinFlow = 112 //区块星链-线上消费直推奖励
OnlineConsumeGroupRewardTransferTypeForUserVirtualCoinFlow = 113 //区块星链-线上消费团队奖励
OfflineConsumeBeRewardTransferTypeForUserVirtualCoinFlow = 114 //区块星链-线下消费被打赏
OfflineConsumeRewardTransferTypeForUserVirtualCoinFlow = 115 //区块星链-线下消费打赏
OfflineConsumeRewardTransferTypeForMerchantVirtualCoinFlow = 116 //区块星链-线下消费打赏(商家)
GroupLotteryAndDestroyTransferTypeForUserVirtualCoinFlow = 117 //区块星链-自营拼团抽奖销毁
GroupLotteryAndDirectPushRewardTransferTypeForUserVirtualCoinFlow = 118 //区块星链-自营拼团抽奖奖励(直推)
GroupLotteryAndGroupRewardTransferTypeForUserVirtualCoinFlow = 119 //区块星链-自营拼团抽奖奖励(团队)
RegisterRewardTransferTypeForUserVirtualCoinFlow = 106 //区块星链-注册奖励
InviteRegisterRewardTransferTypeForUserVirtualCoinFlow = 107 //区块星链-邀请注册奖励
OfflineConsumeDirectPushRewardByUserTransferTypeForUserVirtualCoinFlow = 108 //区块星链-线下消费直推奖励(用户)
OfflineConsumeDirectPushRewardByBusinessTransferTypeForUserVirtualCoinFlow = 109 //区块星链-线下消费直推奖励(商家)
OfflineConsumeGroupRewardByUserTransferTypeForUserVirtualCoinFlow = 110 //区块星链-线下消费团队奖励(用户)
OfflineConsumeGroupRewardByBusinessTransferTypeForUserVirtualCoinFlow = 111 //区块星链-线下消费团队奖励(商家)
OnlineConsumeDirectPushRewardTransferTypeForUserVirtualCoinFlow = 112 //区块星链-线上消费直推奖励
OnlineConsumeGroupRewardTransferTypeForUserVirtualCoinFlow = 113 //区块星链-线上消费团队奖励
OfflineConsumeBeRewardTransferTypeForUserVirtualCoinFlow = 114 //区块星链-线下消费被打赏
OfflineConsumeRewardTransferTypeForUserVirtualCoinFlow = 115 //区块星链-线下消费打赏
OfflineConsumeRewardTransferTypeForMerchantVirtualCoinFlow = 116 //区块星链-线下消费打赏(商家)
GroupLotteryAndDestroyTransferTypeForUserVirtualCoinFlow = 117 //区块星链-自营拼团抽奖销毁
GroupLotteryAndDirectPushRewardTransferTypeForUserVirtualCoinFlow = 118 //区块星链-自营拼团抽奖奖励(直推)
GroupLotteryAndGroupRewardTransferTypeForUserVirtualCoinFlow = 119 //区块星链-自营拼团抽奖奖励(团队)
OperationCenterAndDestroyStaticContributionTransferTypeForUserVirtualCoinFlow = 120 // 区块星链-运营中心发放(销毁静态贡献值)
OtherAndDestroyStaticContributionTransferTypeForUserVirtualCoinFlow = 121 // 区块星链-其他发放(销毁静态贡献值)
) )


const DealUserCoinRequestIdPrefix = "%s:block_star_chain_deal_user_coin:%d:uid:%d" const DealUserCoinRequestIdPrefix = "%s:block_star_chain_deal_user_coin:%d:uid:%d"


+ 114
- 30
rule/block_star_chain_settlement.go Vedi File

@@ -96,7 +96,7 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool)
publishCoinStaticRate, _ := decimal.NewFromString(blockStarChain.PublishCoinStaticRate) //区块币发行静态占比 publishCoinStaticRate, _ := decimal.NewFromString(blockStarChain.PublishCoinStaticRate) //区块币发行静态占比
publishCoinStaticRate = publishCoinStaticRate.Div(decimal.NewFromFloat(100)) publishCoinStaticRate = publishCoinStaticRate.Div(decimal.NewFromFloat(100))
staticAreaCoinNums = zhios_order_relate_utils.StrToFloat64(decimal.NewFromFloat(publishCoin).Mul(publishCoinStaticRate).String()) staticAreaCoinNums = zhios_order_relate_utils.StrToFloat64(decimal.NewFromFloat(publishCoin).Mul(publishCoinStaticRate).String())
err, destroyCoinForStatic := statisticsAndDistributeCoinForStatic(session, userIds, mid, staticAreaCoinNums, *blockStarChain)
err, destroyCoinForStatic := statisticsAndDistributeCoinForStatic(session, userIds, mid, staticAreaCoinNums, blockStarChain)
if err != nil { if err != nil {
_ = session.Rollback() _ = session.Rollback()
return err return err
@@ -107,7 +107,7 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool)
publishCoinDynamicRate, _ := decimal.NewFromString(blockStarChain.PublishCoinDynamicRate) //区块币发行动态占比 publishCoinDynamicRate, _ := decimal.NewFromString(blockStarChain.PublishCoinDynamicRate) //区块币发行动态占比
publishCoinDynamicRate = publishCoinDynamicRate.Div(decimal.NewFromFloat(100)) publishCoinDynamicRate = publishCoinDynamicRate.Div(decimal.NewFromFloat(100))
dynamicAreaCoinNums = zhios_order_relate_utils.StrToFloat64(decimal.NewFromFloat(publishCoin).Mul(publishCoinDynamicRate).String()) dynamicAreaCoinNums = zhios_order_relate_utils.StrToFloat64(decimal.NewFromFloat(publishCoin).Mul(publishCoinDynamicRate).String())
err, destroyCoinForDynamic := statisticsAndDistributeCoinForDynamic(session, userIds, mid, dynamicAreaCoinNums, *blockStarChain)
err, destroyCoinForDynamic := statisticsAndDistributeCoinForDynamic(session, userIds, mid, dynamicAreaCoinNums, blockStarChain)
if err != nil { if err != nil {
_ = session.Rollback() _ = session.Rollback()
return err return err
@@ -118,7 +118,7 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool)
publishCoinOperationCenterRate, _ := decimal.NewFromString(blockStarChain.PublishCoinOperationCenterRate) //区块币发行运营中心占比 publishCoinOperationCenterRate, _ := decimal.NewFromString(blockStarChain.PublishCoinOperationCenterRate) //区块币发行运营中心占比
publishCoinOperationCenterRate = publishCoinOperationCenterRate.Div(decimal.NewFromFloat(100)) publishCoinOperationCenterRate = publishCoinOperationCenterRate.Div(decimal.NewFromFloat(100))
operationCenterCoinNums = zhios_order_relate_utils.StrToFloat64(decimal.NewFromFloat(publishCoin).Mul(publishCoinOperationCenterRate).String()) operationCenterCoinNums = zhios_order_relate_utils.StrToFloat64(decimal.NewFromFloat(publishCoin).Mul(publishCoinOperationCenterRate).String())
err, destroyCoinForOperationCenter := statisticsAndDistributeCoinForOperationCenter(session, mid, operationCenterCoinNums, *blockStarChain)
err, destroyCoinForOperationCenter := statisticsAndDistributeCoinForOperationCenter(session, mid, operationCenterCoinNums, blockStarChain)
if err != nil { if err != nil {
_ = session.Rollback() _ = session.Rollback()
return err return err
@@ -129,7 +129,7 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool)
publishCoinOperationOtherRate, _ := decimal.NewFromString(blockStarChain.PublishCoinOtherRate) //区块币发行 其他 占比 publishCoinOperationOtherRate, _ := decimal.NewFromString(blockStarChain.PublishCoinOtherRate) //区块币发行 其他 占比
publishCoinOperationOtherRate = publishCoinOperationOtherRate.Div(decimal.NewFromFloat(100)) publishCoinOperationOtherRate = publishCoinOperationOtherRate.Div(decimal.NewFromFloat(100))
otherCoinNums = zhios_order_relate_utils.StrToFloat64(decimal.NewFromFloat(publishCoin).Mul(publishCoinOperationOtherRate).String()) otherCoinNums = zhios_order_relate_utils.StrToFloat64(decimal.NewFromFloat(publishCoin).Mul(publishCoinOperationOtherRate).String())
err, destroyCoinForOther := statisticsAndDistributeCoinForOther(session, mid, otherCoinNums, *blockStarChain)
err, destroyCoinForOther := statisticsAndDistributeCoinForOther(session, mid, otherCoinNums, blockStarChain)
if err != nil { if err != nil {
_ = session.Rollback() _ = session.Rollback()
return err return err
@@ -204,10 +204,10 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool)
统计分配区块币-静态区 统计分配区块币-静态区
TODO:: 公式【 个人贡献值/全网贡献值x2100枚=每天获取的惠积分 】 TODO:: 公式【 个人贡献值/全网贡献值x2100枚=每天获取的惠积分 】
*/ */
func statisticsAndDistributeCoinForStatic(session *xorm.Session, userIds []int, 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) //静态区发行区块币数量 publishCoinValue := decimal.NewFromFloat(publishCoin) //静态区发行区块币数量
platformGuidePriceForCoinValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(chain.PlatformGuidePriceForCoin)) //今日平台区块币指导价 platformGuidePriceForCoinValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(chain.PlatformGuidePriceForCoin)) //今日平台区块币指导价
var unassignedTotalCoin = decimal.NewFromFloat(0) //分配的区块币
var unassignedTotalCoin = decimal.NewFromFloat(0) //分配的区块币
var userVirtualAmount model.UserVirtualAmount var userVirtualAmount model.UserVirtualAmount
var userVirtualAmounts []model.UserVirtualAmount var userVirtualAmounts []model.UserVirtualAmount
//1、统计出静态区总贡献值 //1、统计出静态区总贡献值
@@ -239,7 +239,7 @@ func statisticsAndDistributeCoinForStatic(session *xorm.Session, userIds []int,
//TODO::公式【得到的区块币 = ((需销毁贡献值 - 用户贡献值余额) / 今日平台区块币指导价)】 //TODO::公式【得到的区块币 = ((需销毁贡献值 - 用户贡献值余额) / 今日平台区块币指导价)】
tempCoin := (needDestroyContribution.Sub(coinAmountValue)).Div(platformGuidePriceForCoinValue) tempCoin := (needDestroyContribution.Sub(coinAmountValue)).Div(platformGuidePriceForCoinValue)
getCoin = getCoin.Sub(tempCoin) getCoin = getCoin.Sub(tempCoin)
unassignedTotalCoin.Add(tempCoin)
unassignedTotalCoin.Add(getCoin)
needDestroyContribution = coinAmountValue needDestroyContribution = coinAmountValue
} }


@@ -275,9 +275,11 @@ func statisticsAndDistributeCoinForStatic(session *xorm.Session, userIds []int,
} }


//4、处理未分配完的区块币-静态区 //4、处理未分配完的区块币-静态区
unassignedTotalCoinValue = zhios_order_relate_utils.StrToFloat64(unassignedTotalCoin.String())
if unassignedTotalCoinValue > 0 {
err := DealDestroyCoin(session, int(enum.StaticUnallocatedAndDestroy), unassignedTotalCoinValue, enum.StaticUnallocatedAndDestroy.String(), &chain)
//unassignedTotalCoinValue = zhios_order_relate_utils.StrToFloat64(unassignedTotalCoin.String())
if publishCoinValue.GreaterThan(unassignedTotalCoin) {
//if unassignedTotalCoinValue > 0 {
unassignedTotalCoinValue, _ = publishCoinValue.Sub(unassignedTotalCoin).Float64()
err := DealDestroyCoin(session, int(enum.StaticUnallocatedAndDestroy), unassignedTotalCoinValue, enum.StaticUnallocatedAndDestroy.String(), chain)
if err != nil { if err != nil {
return err, unassignedTotalCoinValue return err, unassignedTotalCoinValue
} }
@@ -288,10 +290,10 @@ func statisticsAndDistributeCoinForStatic(session *xorm.Session, userIds []int,
/* /*
统计分配区块币-动态区 统计分配区块币-动态区
*/ */
func statisticsAndDistributeCoinForDynamic(session *xorm.Session, userIds []int, 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) //动态区发行区块币数量 publishCoinValue := decimal.NewFromFloat(publishCoin) //动态区发行区块币数量
platformGuidePriceForCoinValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(chain.PlatformGuidePriceForCoin)) //今日平台区块币指导价 platformGuidePriceForCoinValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(chain.PlatformGuidePriceForCoin)) //今日平台区块币指导价
var unassignedTotalCoin = decimal.NewFromFloat(0) //分配的区块币
var unassignedTotalCoin = decimal.NewFromFloat(0) //分配的区块币
var userVirtualAmount model.UserVirtualAmount var userVirtualAmount model.UserVirtualAmount
var userVirtualAmounts []model.UserVirtualAmount var userVirtualAmounts []model.UserVirtualAmount


@@ -365,7 +367,7 @@ func statisticsAndDistributeCoinForDynamic(session *xorm.Session, userIds []int,
if publishCoinValue.GreaterThan(unassignedTotalCoin) { if publishCoinValue.GreaterThan(unassignedTotalCoin) {
//if unassignedTotalCoinValue > 0 { //if unassignedTotalCoinValue > 0 {
unassignedTotalCoinValue, _ = publishCoinValue.Sub(unassignedTotalCoin).Float64() unassignedTotalCoinValue, _ = publishCoinValue.Sub(unassignedTotalCoin).Float64()
err := DealDestroyCoin(session, int(enum.DynamicallyUnallocatedAndDestroy), unassignedTotalCoinValue, enum.DynamicallyUnallocatedAndDestroy.String(), &chain)
err := DealDestroyCoin(session, int(enum.DynamicallyUnallocatedAndDestroy), unassignedTotalCoinValue, enum.DynamicallyUnallocatedAndDestroy.String(), chain)
if err != nil { if err != nil {
return err, unassignedTotalCoinValue return err, unassignedTotalCoinValue
} }
@@ -376,8 +378,9 @@ func statisticsAndDistributeCoinForDynamic(session *xorm.Session, userIds []int,
/* /*
统计分配区块币-运营中心 统计分配区块币-运营中心
*/ */
func statisticsAndDistributeCoinForOperationCenter(session *xorm.Session, mid string, publishCoin float64, chain model.BlockStarChain) (err error, unassignedTotalCoinValue float64) {
publishCoinValue := decimal.NewFromFloat(publishCoin) //运营中心-发行区块币数量
func statisticsAndDistributeCoinForOperationCenter(session *xorm.Session, 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 totalCoin = decimal.NewFromFloat(0) var totalCoin = decimal.NewFromFloat(0)


//1、查询出运营中心等级的所有用户 //1、查询出运营中心等级的所有用户
@@ -387,11 +390,36 @@ func statisticsAndDistributeCoinForOperationCenter(session *xorm.Session, mid st
return err, unassignedTotalCoinValue return err, unassignedTotalCoinValue
} }
if totalUser > 0 { if totalUser > 0 {
singleValue := publishCoinValue.Div(decimal.NewFromInt(totalUser))
//2、循环处理每个用户的数据(增加虚拟币)
singleValue := publishCoinValue.Div(decimal.NewFromInt(totalUser)) // 得到的区块币

var userIds []int
for _, item := range userList { for _, item := range userList {
totalCoin = totalCoin.Add(singleValue)
err := DealUserCoin(session, md.DealUserCoinReq{
userIds = append(userIds, item.Uid)
}
//2、查询出所有拥有静态贡献值的用户
var userVirtualAmounts []model.UserVirtualAmount
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
}
for _, item := range userVirtualAmounts {
needDestroyContribution := singleValue.Mul(platformGuidePriceForCoinValue) //需销毁贡献值
coinAmount, err := svc.GetUserCoinAmount(session, mid, chain.Coin2, item.Uid) //获取此时用户的"静态贡献值"
if err != nil {
return err, unassignedTotalCoinValue
}
coinAmountValue, _ := decimal.NewFromString(coinAmount) //用户静态贡献值余额

//3.1判断静态贡献值是否足够
if needDestroyContribution.GreaterThan(coinAmountValue) {
//TODO::公式【得到的区块币 = ((需销毁贡献值 - 用户贡献值余额) / 今日平台区块币指导价)】
tempCoin := (needDestroyContribution.Sub(coinAmountValue)).Div(platformGuidePriceForCoinValue)
singleValue = singleValue.Sub(tempCoin)
needDestroyContribution = coinAmountValue
}
totalCoin.Add(singleValue)
//3.2给相应用户加上分配到的虚拟币
err = DealUserCoin(session, md.DealUserCoinReq{
Kind: "add", Kind: "add",
Mid: mid, Mid: mid,
Title: md.OperationCenterTitleForUserVirtualCoinFlow, Title: md.OperationCenterTitleForUserVirtualCoinFlow,
@@ -404,13 +432,27 @@ func statisticsAndDistributeCoinForOperationCenter(session *xorm.Session, mid st
if err != nil { if err != nil {
return err, unassignedTotalCoinValue return err, unassignedTotalCoinValue
} }
//3.3给相应用户扣除 "静态发放(销毁静态贡献值)"
err = DealUserCoin(session, md.DealUserCoinReq{
Kind: "sub",
Mid: mid,
Title: md.OperationCenterAndDestroyStaticContributionTitleForUserVirtualCoinFlow,
TransferType: md.OperationCenterAndDestroyStaticContributionTransferTypeForUserVirtualCoinFlow,
OrdId: "",
CoinId: chain.Coin2,
Uid: item.Uid,
Amount: zhios_order_relate_utils.StrToFloat64(needDestroyContribution.String()),
})
if err != nil {
return err, unassignedTotalCoinValue
}
} }
} }


//3、处理未分配完的区块币-运营中心
//4、处理未分配完的区块币-运营中心
unassignedTotalCoinValue, _ = publishCoinValue.Sub(totalCoin).Float64() unassignedTotalCoinValue, _ = publishCoinValue.Sub(totalCoin).Float64()
if unassignedTotalCoinValue > 0 { if unassignedTotalCoinValue > 0 {
err := DealDestroyCoin(session, int(enum.OperationCenterUnallocatedAndDestroy), unassignedTotalCoinValue, enum.OperationCenterUnallocatedAndDestroy.String(), &chain)
err := DealDestroyCoin(session, int(enum.OtherUnallocatedAndDestroy), unassignedTotalCoinValue, enum.OtherUnallocatedAndDestroy.String(), chain)
if err != nil { if err != nil {
return err, unassignedTotalCoinValue return err, unassignedTotalCoinValue
} }
@@ -421,8 +463,9 @@ func statisticsAndDistributeCoinForOperationCenter(session *xorm.Session, mid st
/* /*
统计分配区块币-其他 统计分配区块币-其他
*/ */
func statisticsAndDistributeCoinForOther(session *xorm.Session, mid string, publishCoin float64, chain model.BlockStarChain) (err error, unassignedTotalCoinValue float64) {
publishCoinValue := decimal.NewFromFloat(publishCoin) //运营中心-发行区块币数量
func statisticsAndDistributeCoinForOther(session *xorm.Session, 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 totalCoin = decimal.NewFromFloat(0) var totalCoin = decimal.NewFromFloat(0)


var userLevel = make([]string, 0) var userLevel = make([]string, 0)
@@ -431,18 +474,44 @@ func statisticsAndDistributeCoinForOther(session *xorm.Session, mid string, publ
return err, unassignedTotalCoinValue return err, unassignedTotalCoinValue
} }
if len(userLevel) > 0 { if len(userLevel) > 0 {
//1、查询出运营中心等级的所有用户
//1、查询出其他等级的所有用户
var userList []*model.User var userList []*model.User
totalUser, err := session.Table("user").In("level", userLevel).FindAndCount(&userList) totalUser, err := session.Table("user").In("level", userLevel).FindAndCount(&userList)
if err != nil { if err != nil {
return err, unassignedTotalCoinValue return err, unassignedTotalCoinValue
} }
if totalUser > 0 { if totalUser > 0 {
singleValue := publishCoinValue.Div(decimal.NewFromInt(totalUser))
//2、循环处理每个用户的数据(增加虚拟币)
singleValue := publishCoinValue.Div(decimal.NewFromInt(totalUser)) // 得到的区块币

var userIds []int
for _, item := range userList { for _, item := range userList {
totalCoin = totalCoin.Add(singleValue)
err := DealUserCoin(session, md.DealUserCoinReq{
userIds = append(userIds, item.Uid)
}
//2、查询出所有拥有静态贡献值的用户
var userVirtualAmounts []model.UserVirtualAmount
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
}

for _, item := range userVirtualAmounts {
needDestroyContribution := singleValue.Mul(platformGuidePriceForCoinValue) //需销毁贡献值
coinAmount, err := svc.GetUserCoinAmount(session, mid, chain.Coin2, item.Uid) //获取此时用户的"静态贡献值"
if err != nil {
return err, unassignedTotalCoinValue
}
coinAmountValue, _ := decimal.NewFromString(coinAmount) //用户静态贡献值余额

//3.1判断静态贡献值是否足够
if needDestroyContribution.GreaterThan(coinAmountValue) {
//TODO::公式【得到的区块币 = ((需销毁贡献值 - 用户贡献值余额) / 今日平台区块币指导价)】
tempCoin := (needDestroyContribution.Sub(coinAmountValue)).Div(platformGuidePriceForCoinValue)
singleValue = singleValue.Sub(tempCoin)
needDestroyContribution = coinAmountValue
}
totalCoin.Add(singleValue)
//3.2给相应用户加上分配到的虚拟币
err = DealUserCoin(session, md.DealUserCoinReq{
Kind: "add", Kind: "add",
Mid: mid, Mid: mid,
Title: md.OtherTitleForUserVirtualCoinFlow, Title: md.OtherTitleForUserVirtualCoinFlow,
@@ -455,14 +524,28 @@ func statisticsAndDistributeCoinForOther(session *xorm.Session, mid string, publ
if err != nil { if err != nil {
return err, unassignedTotalCoinValue return err, unassignedTotalCoinValue
} }
//3.3给相应用户扣除 "静态发放(销毁静态贡献值)"
err = DealUserCoin(session, md.DealUserCoinReq{
Kind: "sub",
Mid: mid,
Title: md.OtherAndDestroyStaticContributionTitleForUserVirtualCoinFlow,
TransferType: md.OtherAndDestroyStaticContributionTransferTypeForUserVirtualCoinFlow,
OrdId: "",
CoinId: chain.Coin2,
Uid: item.Uid,
Amount: zhios_order_relate_utils.StrToFloat64(needDestroyContribution.String()),
})
if err != nil {
return err, unassignedTotalCoinValue
}
} }
} }
} }


//3、处理未分配完的区块币-其他
//4、处理未分配完的区块币-其他
unassignedTotalCoinValue, _ = publishCoinValue.Sub(totalCoin).Float64() unassignedTotalCoinValue, _ = publishCoinValue.Sub(totalCoin).Float64()
if unassignedTotalCoinValue > 0 { if unassignedTotalCoinValue > 0 {
err := DealDestroyCoin(session, int(enum.OtherUnallocatedAndDestroy), unassignedTotalCoinValue, enum.OtherUnallocatedAndDestroy.String(), &chain)
err := DealDestroyCoin(session, int(enum.OtherUnallocatedAndDestroy), unassignedTotalCoinValue, enum.OtherUnallocatedAndDestroy.String(), chain)
if err != nil { if err != nil {
return err, unassignedTotalCoinValue return err, unassignedTotalCoinValue
} }
@@ -504,6 +587,7 @@ func dealIssueCoin(session *xorm.Session, kind int, amount float64, title string
blockStarChainFlow.Kind = kind blockStarChainFlow.Kind = kind
blockStarChainFlow.Title = title blockStarChainFlow.Title = title
blockStarChainFlow.CreateTime = now blockStarChainFlow.CreateTime = now
blockStarChainFlow.Amount = zhios_order_relate_utils.Float64ToStrPrec10(amount)
switch kind { switch kind {
case int(enum.SystemTimingIssue): case int(enum.SystemTimingIssue):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin


Caricamento…
Annulla
Salva