From ec0b95240cb7fc11f06d75ecad4a0c99c44ee321 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Tue, 30 Aug 2022 21:40:25 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=8C=BA=E5=9D=97=E6=98=9F=E9=93=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/model/block_star_chain.go | 3 + md/block_star_chain.go | 5 ++ rule/block_star_chain_settlement.go | 98 +++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) diff --git a/db/model/block_star_chain.go b/db/model/block_star_chain.go index c98f9b8..e8d2fe1 100644 --- a/db/model/block_star_chain.go +++ b/db/model/block_star_chain.go @@ -26,7 +26,10 @@ type BlockStarChain struct { PublishCoinDynamicRate string `json:"publish_coin_dynamic_rate" xorm:"not null default 45.00 comment('区块币发行动态占比') DECIMAL(5,2)"` PublishCoinStaticRate string `json:"publish_coin_static_rate" xorm:"not null default 45.00 comment('区块币发行静态占比') DECIMAL(5,2)"` PublishCoinOperationCenterRate string `json:"publish_coin_operation_center_rate" xorm:"not null default 3.00 comment('区块币发行运营中心占比') DECIMAL(5,2)"` + OperationCenterForUserLevel int `json:"operation_center_for_user_level" xorm:"not null default 0 comment('运营中心分红对应会员等级') INT(11)"` PublishCoinOperationOtherRate string `json:"publish_coin_other_rate" xorm:"not null default 7.00 comment('区块币发行其他占比') DECIMAL(5,2)"` + OtherForUserLevel string `json:"other_for_user_level" xorm:"comment('其他分红对应会员等级') TEXT"` + RewardDestroyCoinRate string `json:"reward_destroy_coin_rate" xorm:"not null default 70.00 comment('商家打赏销毁区块币比例') DECIMAL(5,2)"` RewardSettings string `json:"reward_settings" xorm:"comment('奖励设置') TEXT"` CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') TIMESTAMP"` UpdateAt time.Time `json:"update_at" xorm:"default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"` diff --git a/md/block_star_chain.go b/md/block_star_chain.go index 4c68463..20f7b3e 100644 --- a/md/block_star_chain.go +++ b/md/block_star_chain.go @@ -13,14 +13,19 @@ const ( const ( StaticAreaDistributionTitleForUserVirtualCoinFlow = "区块星链-静态区发放" DynamicAreaDistributionTitleForUserVirtualCoinFlow = "区块星链-动态区发放" + OperationCenterTitleForUserVirtualCoinFlow = "区块星链-运营中心发放" + OtherTitleForUserVirtualCoinFlow = "区块星链-其他发放" StaticIssueAndDestroyStaticContributionTitleForUserVirtualCoinFlow = "区块星链-静态发放(销毁静态贡献值)" DynamicIssueAndDestroyStaticContributionTitleForUserVirtualCoinFlow = "区块星链-动态发放(销毁静态贡献值)" ) + const ( StaticAreaDistributionTransferTypeForUserVirtualCoinFlow = 100 DynamicAreaDistributionTransferTypeForUserVirtualCoinFlow = 101 StaticIssueAndDestroyStaticContributionTransferTypeForUserVirtualCoinFlow = 102 DynamicIssueAndDestroyStaticContributionTransferTypeForUserVirtualCoinFlow = 103 + OperationCenterTransferTypeForUserVirtualCoinFlow = 104 + OtherTransferTypeForUserVirtualCoinFlow = 105 ) const DealUserCoinRequestIdPrefix = "%s:block_star_chain_deal_user_coin:%d:uid:%d" diff --git a/rule/block_star_chain_settlement.go b/rule/block_star_chain_settlement.go index 23168ff..4e73f0d 100644 --- a/rule/block_star_chain_settlement.go +++ b/rule/block_star_chain_settlement.go @@ -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()