|
|
@@ -9,6 +9,7 @@ import ( |
|
|
|
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache" |
|
|
|
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"github.com/shopspring/decimal" |
|
|
@@ -292,6 +293,103 @@ func statisticsAndDistributeCoinForDynamic(session *xorm.Session, mid string, pu |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
统计分配区块币-运营中心 |
|
|
|
*/ |
|
|
|
func statisticsAndDistributeCoinForOperationCenter(session *xorm.Session, mid string, publishCoin float64, chain model.BlockStarChain) (err error, unassignedTotalCoinValue float64) { |
|
|
|
publishCoinValue := decimal.NewFromFloat(publishCoin) //运营中心-发行区块币数量 |
|
|
|
var totalCoin = decimal.NewFromFloat(0) |
|
|
|
|
|
|
|
//1、查询出运营中心等级的所有用户 |
|
|
|
var userList []*model.User |
|
|
|
totalUser, err := session.Table("user").Where("level =?", chain.OperationCenterForUserLevel).FindAndCount(&userList) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if totalUser > 0 { |
|
|
|
singleValue := publishCoinValue.Div(decimal.NewFromInt(totalUser)) |
|
|
|
//2、循环处理每个用户的数据(增加虚拟币) |
|
|
|
for _, item := range userList { |
|
|
|
totalCoin = totalCoin.Add(singleValue) |
|
|
|
err := DealUserCoin(session, md.DealUserCoinReq{ |
|
|
|
Kind: "add", |
|
|
|
Mid: mid, |
|
|
|
Title: md.OperationCenterTitleForUserVirtualCoinFlow, |
|
|
|
TransferType: md.OperationCenterTransferTypeForUserVirtualCoinFlow, |
|
|
|
OrdId: "", |
|
|
|
CoinId: chain.Coin1, |
|
|
|
Uid: item.Uid, |
|
|
|
Amount: zhios_order_relate_utils.StrToFloat64(singleValue.String()), |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//3、处理未分配完的区块币-运营中心 |
|
|
|
unassignedTotalCoinValue, _ = publishCoinValue.Sub(totalCoin).Float64() |
|
|
|
if unassignedTotalCoinValue > 0 { |
|
|
|
err := DealDestroyCoin(session, int(enum.OperationCenterUnallocatedAndDestroy), unassignedTotalCoinValue, enum.OperationCenterUnallocatedAndDestroy.String(), &chain) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
统计分配区块币-其他 |
|
|
|
*/ |
|
|
|
func statisticsAndDistributeCoinForOther(session *xorm.Session, mid string, publishCoin float64, chain model.BlockStarChain) (err error, unassignedTotalCoinValue float64) { |
|
|
|
publishCoinValue := decimal.NewFromFloat(publishCoin) //运营中心-发行区块币数量 |
|
|
|
var totalCoin = decimal.NewFromFloat(0) |
|
|
|
|
|
|
|
var userLevel = make([]string, 0) |
|
|
|
err = json.Unmarshal([]byte(chain.OtherForUserLevel), &userLevel) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if len(userLevel) > 0 { |
|
|
|
//1、查询出运营中心等级的所有用户 |
|
|
|
var userList []*model.User |
|
|
|
totalUser, err := session.Table("user").In("level", userLevel).FindAndCount(&userList) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if totalUser > 0 { |
|
|
|
singleValue := publishCoinValue.Div(decimal.NewFromInt(totalUser)) |
|
|
|
//2、循环处理每个用户的数据(增加虚拟币) |
|
|
|
for _, item := range userList { |
|
|
|
totalCoin = totalCoin.Add(singleValue) |
|
|
|
err := DealUserCoin(session, md.DealUserCoinReq{ |
|
|
|
Kind: "add", |
|
|
|
Mid: mid, |
|
|
|
Title: md.OtherTitleForUserVirtualCoinFlow, |
|
|
|
TransferType: md.OtherTransferTypeForUserVirtualCoinFlow, |
|
|
|
OrdId: "", |
|
|
|
CoinId: chain.Coin1, |
|
|
|
Uid: item.Uid, |
|
|
|
Amount: zhios_order_relate_utils.StrToFloat64(singleValue.String()), |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//3、处理未分配完的区块币-其他 |
|
|
|
unassignedTotalCoinValue, _ = publishCoinValue.Sub(totalCoin).Float64() |
|
|
|
if unassignedTotalCoinValue > 0 { |
|
|
|
err := DealDestroyCoin(session, int(enum.OtherUnallocatedAndDestroy), unassignedTotalCoinValue, enum.OtherUnallocatedAndDestroy.String(), &chain) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//计算当前每日区块币应发行数量 |
|
|
|
func calcNowEverydayPublishCoin(session *xorm.Session, chain model.BlockStarChain) error { |
|
|
|
now := time.Now() |
|
|
|