|
|
@@ -220,9 +220,10 @@ func statisticsAndDistributeCoinForStatic(session *xorm.Session, mid string, pub |
|
|
|
amount := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(item.Amount)) //用户贡献值余额 |
|
|
|
getCoin := amount.Div(sumStaticValue).Mul(publishCoinValue) //得到的区块币 |
|
|
|
needDestroyContribution := getCoin.Mul(platformGuidePriceForCoinValue) //需销毁贡献值 |
|
|
|
|
|
|
|
//3.1判断静态贡献值是否足够 |
|
|
|
if needDestroyContribution.GreaterThan(amount) { |
|
|
|
//TODO::公式【得到的区块币 - ((需销毁贡献值 - 用户贡献值余额) / 今日平台区块币指导价)】 |
|
|
|
//TODO::公式【得到的区块币 = ((需销毁贡献值 - 用户贡献值余额) / 今日平台区块币指导价)】 |
|
|
|
tempCoin := (needDestroyContribution.Sub(amount)).Div(platformGuidePriceForCoinValue) |
|
|
|
getCoin = getCoin.Sub(tempCoin) |
|
|
|
unassignedTotalCoin.Add(tempCoin) |
|
|
@@ -253,7 +254,7 @@ func statisticsAndDistributeCoinForStatic(session *xorm.Session, mid string, pub |
|
|
|
OrdId: "", |
|
|
|
CoinId: chain.Coin2, |
|
|
|
Uid: item.Uid, |
|
|
|
Amount: zhios_order_relate_utils.StrToFloat64(getCoin.String()), |
|
|
|
Amount: zhios_order_relate_utils.StrToFloat64(needDestroyContribution.String()), |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return err, unassignedTotalCoinValue |
|
|
@@ -287,8 +288,8 @@ func statisticsAndDistributeCoinForDynamic(session *xorm.Session, mid string, pu |
|
|
|
} |
|
|
|
sumStaticValue := decimal.NewFromFloat(sumStatic) |
|
|
|
|
|
|
|
//2、查询出所有拥有动态贡献值的用户 |
|
|
|
err = session.Table("user_virtual_amount").Where("coin_id =?", chain.Coin3).And("amount > 0").Find(&userVirtualAmounts) |
|
|
|
//2、查询出所有拥有静态贡献值的用户 |
|
|
|
err = session.Table("user_virtual_amount").Where("coin_id =?", chain.Coin2).And("amount > 0").Find(&userVirtualAmounts) |
|
|
|
if err != nil { |
|
|
|
return err, unassignedTotalCoinValue |
|
|
|
} |
|
|
@@ -303,7 +304,7 @@ func statisticsAndDistributeCoinForDynamic(session *xorm.Session, mid string, pu |
|
|
|
//TODO::公式【得到的区块币 - ((需销毁贡献值 - 用户贡献值余额) / 今日平台区块币指导价)】 |
|
|
|
tempCoin := (needDestroyContribution.Sub(amount)).Div(platformGuidePriceForCoinValue) |
|
|
|
getCoin = getCoin.Sub(tempCoin) |
|
|
|
unassignedTotalCoin.Add(tempCoin) |
|
|
|
unassignedTotalCoin.Add(getCoin) |
|
|
|
needDestroyContribution = amount |
|
|
|
} |
|
|
|
|
|
|
@@ -331,7 +332,7 @@ func statisticsAndDistributeCoinForDynamic(session *xorm.Session, mid string, pu |
|
|
|
OrdId: "", |
|
|
|
CoinId: chain.Coin2, |
|
|
|
Uid: item.Uid, |
|
|
|
Amount: zhios_order_relate_utils.StrToFloat64(getCoin.String()), |
|
|
|
Amount: zhios_order_relate_utils.StrToFloat64(needDestroyContribution.String()), |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return err, unassignedTotalCoinValue |
|
|
@@ -339,8 +340,10 @@ func statisticsAndDistributeCoinForDynamic(session *xorm.Session, mid string, pu |
|
|
|
} |
|
|
|
|
|
|
|
//4、处理未分配完的区块币-动态区 |
|
|
|
unassignedTotalCoinValue = zhios_order_relate_utils.StrToFloat64(unassignedTotalCoin.String()) |
|
|
|
if unassignedTotalCoinValue > 0 { |
|
|
|
//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.DynamicallyUnallocatedAndDestroy), unassignedTotalCoinValue, enum.DynamicallyUnallocatedAndDestroy.String(), &chain) |
|
|
|
if err != nil { |
|
|
|
return err, unassignedTotalCoinValue |
|
|
@@ -675,6 +678,7 @@ func DealUserCoin(session *xorm.Session, req md.DealUserCoinReq) (err error) { |
|
|
|
userVirtualCoinFlow.Title = req.Title |
|
|
|
userVirtualCoinFlow.TransferType = req.TransferType |
|
|
|
userVirtualCoinFlow.Uid = req.Uid |
|
|
|
userVirtualCoinFlow.BeforeAmout = coinAmount |
|
|
|
userVirtualCoinFlow.Amout = amountValue.String() |
|
|
|
userVirtualCoinFlow.CreateTime = now |
|
|
|
|
|
|
@@ -688,7 +692,9 @@ func DealUserCoin(session *xorm.Session, req md.DealUserCoinReq) (err error) { |
|
|
|
err = errors.New("错误的kind类型") |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
if zhios_order_relate_utils.StrToFloat64(userVirtualCoinFlow.AfterAmout) < 0 { |
|
|
|
return errors.New("用户虚拟币积分不足,无法扣除。") |
|
|
|
} |
|
|
|
//3、插入 `user_virtual_coin_flow` 记录 |
|
|
|
_, err = db.UserVirtualCoinFlowInsert(session, &userVirtualCoinFlow) |
|
|
|
if err != nil { |
|
|
|