|
|
@@ -96,7 +96,7 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool) |
|
|
|
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, userIds, mid, staticAreaCoinNums, *blockStarChain) |
|
|
|
err, destroyCoinForStatic := statisticsAndDistributeCoinForStatic(session, userIds, mid, staticAreaCoinNums, blockStarChain) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err |
|
|
@@ -107,7 +107,7 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool) |
|
|
|
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, userIds, mid, dynamicAreaCoinNums, *blockStarChain) |
|
|
|
err, destroyCoinForDynamic := statisticsAndDistributeCoinForDynamic(session, userIds, mid, dynamicAreaCoinNums, blockStarChain) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err |
|
|
@@ -118,7 +118,7 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool) |
|
|
|
publishCoinOperationCenterRate, _ := decimal.NewFromString(blockStarChain.PublishCoinOperationCenterRate) //区块币发行运营中心占比 |
|
|
|
publishCoinOperationCenterRate = publishCoinOperationCenterRate.Div(decimal.NewFromFloat(100)) |
|
|
|
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 { |
|
|
|
_ = session.Rollback() |
|
|
|
return err |
|
|
@@ -129,7 +129,7 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool) |
|
|
|
publishCoinOperationOtherRate, _ := decimal.NewFromString(blockStarChain.PublishCoinOtherRate) //区块币发行 其他 占比 |
|
|
|
publishCoinOperationOtherRate = publishCoinOperationOtherRate.Div(decimal.NewFromFloat(100)) |
|
|
|
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 { |
|
|
|
_ = session.Rollback() |
|
|
|
return err |
|
|
@@ -204,10 +204,10 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool) |
|
|
|
统计分配区块币-静态区 |
|
|
|
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) //静态区发行区块币数量 |
|
|
|
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 userVirtualAmounts []model.UserVirtualAmount |
|
|
|
//1、统计出静态区总贡献值 |
|
|
@@ -239,7 +239,7 @@ func statisticsAndDistributeCoinForStatic(session *xorm.Session, userIds []int, |
|
|
|
//TODO::公式【得到的区块币 = ((需销毁贡献值 - 用户贡献值余额) / 今日平台区块币指导价)】 |
|
|
|
tempCoin := (needDestroyContribution.Sub(coinAmountValue)).Div(platformGuidePriceForCoinValue) |
|
|
|
getCoin = getCoin.Sub(tempCoin) |
|
|
|
unassignedTotalCoin.Add(tempCoin) |
|
|
|
unassignedTotalCoin.Add(getCoin) |
|
|
|
needDestroyContribution = coinAmountValue |
|
|
|
} |
|
|
|
|
|
|
@@ -275,9 +275,11 @@ func statisticsAndDistributeCoinForStatic(session *xorm.Session, userIds []int, |
|
|
|
} |
|
|
|
|
|
|
|
//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 { |
|
|
|
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) //动态区发行区块币数量 |
|
|
|
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 userVirtualAmounts []model.UserVirtualAmount |
|
|
|
|
|
|
@@ -365,7 +367,7 @@ func statisticsAndDistributeCoinForDynamic(session *xorm.Session, userIds []int, |
|
|
|
if publishCoinValue.GreaterThan(unassignedTotalCoin) { |
|
|
|
//if unassignedTotalCoinValue > 0 { |
|
|
|
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 { |
|
|
|
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) |
|
|
|
|
|
|
|
//1、查询出运营中心等级的所有用户 |
|
|
@@ -387,11 +390,36 @@ func statisticsAndDistributeCoinForOperationCenter(session *xorm.Session, mid st |
|
|
|
return err, unassignedTotalCoinValue |
|
|
|
} |
|
|
|
if totalUser > 0 { |
|
|
|
singleValue := publishCoinValue.Div(decimal.NewFromInt(totalUser)) |
|
|
|
//2、循环处理每个用户的数据(增加虚拟币) |
|
|
|
singleValue := publishCoinValue.Div(decimal.NewFromInt(totalUser)) // 得到的区块币 |
|
|
|
|
|
|
|
var userIds []int |
|
|
|
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", |
|
|
|
Mid: mid, |
|
|
|
Title: md.OperationCenterTitleForUserVirtualCoinFlow, |
|
|
@@ -404,13 +432,27 @@ func statisticsAndDistributeCoinForOperationCenter(session *xorm.Session, mid st |
|
|
|
if err != nil { |
|
|
|
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() |
|
|
|
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 { |
|
|
|
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 userLevel = make([]string, 0) |
|
|
@@ -431,18 +474,44 @@ func statisticsAndDistributeCoinForOther(session *xorm.Session, mid string, publ |
|
|
|
return err, unassignedTotalCoinValue |
|
|
|
} |
|
|
|
if len(userLevel) > 0 { |
|
|
|
//1、查询出运营中心等级的所有用户 |
|
|
|
//1、查询出其他等级的所有用户 |
|
|
|
var userList []*model.User |
|
|
|
totalUser, err := session.Table("user").In("level", userLevel).FindAndCount(&userList) |
|
|
|
if err != nil { |
|
|
|
return err, unassignedTotalCoinValue |
|
|
|
} |
|
|
|
if totalUser > 0 { |
|
|
|
singleValue := publishCoinValue.Div(decimal.NewFromInt(totalUser)) |
|
|
|
//2、循环处理每个用户的数据(增加虚拟币) |
|
|
|
singleValue := publishCoinValue.Div(decimal.NewFromInt(totalUser)) // 得到的区块币 |
|
|
|
|
|
|
|
var userIds []int |
|
|
|
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", |
|
|
|
Mid: mid, |
|
|
|
Title: md.OtherTitleForUserVirtualCoinFlow, |
|
|
@@ -455,14 +524,28 @@ func statisticsAndDistributeCoinForOther(session *xorm.Session, mid string, publ |
|
|
|
if err != nil { |
|
|
|
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() |
|
|
|
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 { |
|
|
|
return err, unassignedTotalCoinValue |
|
|
|
} |
|
|
@@ -504,6 +587,7 @@ func dealIssueCoin(session *xorm.Session, kind int, amount float64, title string |
|
|
|
blockStarChainFlow.Kind = kind |
|
|
|
blockStarChainFlow.Title = title |
|
|
|
blockStarChainFlow.CreateTime = now |
|
|
|
blockStarChainFlow.Amount = zhios_order_relate_utils.Float64ToStrPrec10(amount) |
|
|
|
switch kind { |
|
|
|
case int(enum.SystemTimingIssue): |
|
|
|
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin |
|
|
|