|
|
@@ -32,6 +32,9 @@ func DealUserGreenCoinDoubleChainIntegral(Db *xorm.Engine, uid int, ordId, maste |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if greenCoinDoubleChain == nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//2、判断当前会员等级 |
|
|
|
user, err := db.DbsUserFindByUid(Db, uid) |
|
|
@@ -75,7 +78,7 @@ func HandleUserGreenCoinDoubleChainIntegralByParent(Db *xorm.Engine, uid int, or |
|
|
|
return |
|
|
|
} |
|
|
|
parentAmountValue, _ := decimal.NewFromString(parentAmount) |
|
|
|
if parentAmountValue.LessThan(decimal.NewFromFloat(0)) { |
|
|
|
if parentAmountValue.LessThanOrEqual(decimal.NewFromFloat(0)) { |
|
|
|
//TODO::上级绿色积分小于0不需要进行兑换 |
|
|
|
return |
|
|
|
} |
|
|
@@ -86,14 +89,12 @@ func HandleUserGreenCoinDoubleChainIntegralByParent(Db *xorm.Engine, uid int, or |
|
|
|
return |
|
|
|
} |
|
|
|
if sonUserRelates == nil { |
|
|
|
err = errors.New("未查询到直推下级") |
|
|
|
//未查询到直推下级 |
|
|
|
return |
|
|
|
} |
|
|
|
var sonUserIds []int |
|
|
|
for _, v := range *sonUserRelates { |
|
|
|
if v.Uid != uid { |
|
|
|
sonUserIds = append(sonUserIds, v.Uid) |
|
|
|
} |
|
|
|
sonUserIds = append(sonUserIds, v.Uid) |
|
|
|
} |
|
|
|
|
|
|
|
users, err := db.DbsUserFindByIds(Db, sonUserIds) |
|
|
@@ -110,7 +111,7 @@ func HandleUserGreenCoinDoubleChainIntegralByParent(Db *xorm.Engine, uid int, or |
|
|
|
|
|
|
|
//4、查询上级直推的所有下级用户的虚拟币金额(按升序) |
|
|
|
var sonUserVirtualWallet []model.UserVirtualAmount |
|
|
|
Db.Where(" coin_id = ?", greenCoinDoubleChain.Coin2).In("uid", userIds).Asc("amount").Find(&sonUserVirtualWallet) |
|
|
|
Db.Where(" coin_id = ? and amount > 0", greenCoinDoubleChain.Coin2).In("uid", userIds).Asc("amount").Find(&sonUserVirtualWallet) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
@@ -118,15 +119,16 @@ func HandleUserGreenCoinDoubleChainIntegralByParent(Db *xorm.Engine, uid int, or |
|
|
|
/* |
|
|
|
TODO::5、进行“数据变更” |
|
|
|
*/ |
|
|
|
var amount string |
|
|
|
var lastUid int |
|
|
|
session := Db.NewSession() |
|
|
|
session.Begin() |
|
|
|
defer func() { |
|
|
|
session.Close() |
|
|
|
if err := recover(); err != nil { |
|
|
|
_ = zhios_order_relate_logx.Error(err) |
|
|
|
} |
|
|
|
}() |
|
|
|
var amount string |
|
|
|
var lastUid int |
|
|
|
for _, v := range sonUserVirtualWallet { |
|
|
|
if lastUid == -1 { |
|
|
|
break |
|
|
@@ -140,17 +142,16 @@ func HandleUserGreenCoinDoubleChainIntegralByParent(Db *xorm.Engine, uid int, or |
|
|
|
} |
|
|
|
|
|
|
|
amountValue, _ := decimal.NewFromString(amount) |
|
|
|
if userAmount.LessThan(amountValue) { |
|
|
|
//当前用户虚拟币金额小于上一个用户虚拟币金额 |
|
|
|
amountValue = userAmount |
|
|
|
} |
|
|
|
//if userAmount.LessThan(amountValue) { |
|
|
|
// //当前用户虚拟币金额小于上一个用户虚拟币金额 |
|
|
|
// amountValue = userAmount |
|
|
|
//} |
|
|
|
|
|
|
|
if parentAmountValue.LessThan(amountValue) { |
|
|
|
//TODO::上级绿色积分小于当前需要兑换积分金额 |
|
|
|
amountValue = parentAmountValue |
|
|
|
} |
|
|
|
|
|
|
|
session.Begin() |
|
|
|
//5.1、上级减少amount 绿色积分 |
|
|
|
err = DealUserCoin(session, md.DealUserCoinReq{ |
|
|
|
Kind: "sub", |
|
|
@@ -164,8 +165,9 @@ func HandleUserGreenCoinDoubleChainIntegralByParent(Db *xorm.Engine, uid int, or |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
//5.2、用户减少amount 贡献积分 |
|
|
|
err = DealUserCoin(session, md.DealUserCoinReq{ |
|
|
|
Kind: "sub", |
|
|
@@ -177,6 +179,10 @@ func HandleUserGreenCoinDoubleChainIntegralByParent(Db *xorm.Engine, uid int, or |
|
|
|
Uid: v.Uid, |
|
|
|
Amount: zhios_order_relate_utils.StrToFloat64(amountValue.String()), |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
break |
|
|
|
} |
|
|
|
//5.3、另一下级减少amount 贡献积分 |
|
|
|
err = DealUserCoin(session, md.DealUserCoinReq{ |
|
|
|
Kind: "sub", |
|
|
@@ -190,14 +196,14 @@ func HandleUserGreenCoinDoubleChainIntegralByParent(Db *xorm.Engine, uid int, or |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
//5.4上级余额增加 |
|
|
|
var coin model.VirtualCoin |
|
|
|
_, err = session.Where("id = ?", greenCoinDoubleChain.Coin1).Get(&coin) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
coinExchangeRatioValue, _ := decimal.NewFromString(coin.ExchangeRatio) |
|
|
|
exchangeAmount, _ := amountValue.Div(coinExchangeRatioValue).Float64() |
|
|
@@ -215,25 +221,26 @@ func HandleUserGreenCoinDoubleChainIntegralByParent(Db *xorm.Engine, uid int, or |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
//6、新增 green_coin_double_chain_exchange_records 记录 |
|
|
|
afterUserCoinAmount, err := svc.GetUserCoinAmount(session, masterId, greenCoinDoubleChain.Coin1, parentUserRelate.ParentUid) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
afterCoinAmountContributeUser1, err := svc.GetUserCoinAmount(session, masterId, greenCoinDoubleChain.Coin2, v.Uid) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
afterCoinAmountContributeUser2, err := svc.GetUserCoinAmount(session, masterId, greenCoinDoubleChain.Coin2, lastUid) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
now := time.Now() |
|
|
|
_, err = db.GreenCoinDoubleChainExchangeRecordsInsert(Db, &model.GreenCoinDoubleChainExchangeRecords{ |
|
|
|
Uid: parentUserRelate.ParentUid, |
|
|
@@ -253,21 +260,20 @@ func HandleUserGreenCoinDoubleChainIntegralByParent(Db *xorm.Engine, uid int, or |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
session.Commit() |
|
|
|
|
|
|
|
if zhios_order_relate_utils.StrToFloat64(afterUserCoinAmount) == 0 { |
|
|
|
lastUid = -1 |
|
|
|
} else { |
|
|
|
if amountValue.String() == amount { |
|
|
|
amount = afterCoinAmountContributeUser2 |
|
|
|
} else { |
|
|
|
amount = afterCoinAmountContributeUser1 |
|
|
|
lastUid = v.Uid |
|
|
|
} |
|
|
|
amount = afterCoinAmountContributeUser1 |
|
|
|
lastUid = v.Uid |
|
|
|
} |
|
|
|
if zhios_order_relate_utils.StrToFloat64(amount) == 0 { |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
session.Commit() |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
@@ -278,7 +284,7 @@ func HandleUserGreenCoinDoubleChainIntegralBySon(Db *xorm.Engine, uid int, ordId |
|
|
|
return |
|
|
|
} |
|
|
|
parentAmountValue, _ := decimal.NewFromString(parentAmount) |
|
|
|
if parentAmountValue.LessThan(decimal.NewFromFloat(0)) { |
|
|
|
if parentAmountValue.LessThanOrEqual(decimal.NewFromFloat(0)) { |
|
|
|
//TODO::上级绿色积分小于0不需要进行兑换 |
|
|
|
return |
|
|
|
} |
|
|
@@ -289,14 +295,12 @@ func HandleUserGreenCoinDoubleChainIntegralBySon(Db *xorm.Engine, uid int, ordId |
|
|
|
return |
|
|
|
} |
|
|
|
if sonUserRelates == nil { |
|
|
|
err = errors.New("未查询到直推下级") |
|
|
|
//未查询到直推下级 |
|
|
|
return |
|
|
|
} |
|
|
|
var sonUserIds []int |
|
|
|
for _, v := range *sonUserRelates { |
|
|
|
if v.Uid != uid { |
|
|
|
sonUserIds = append(sonUserIds, v.Uid) |
|
|
|
} |
|
|
|
sonUserIds = append(sonUserIds, v.Uid) |
|
|
|
} |
|
|
|
|
|
|
|
users, err := db.DbsUserFindByIds(Db, sonUserIds) |
|
|
@@ -313,7 +317,7 @@ func HandleUserGreenCoinDoubleChainIntegralBySon(Db *xorm.Engine, uid int, ordId |
|
|
|
|
|
|
|
//3、查询上级直推的所有下级用户的虚拟币金额(按升序) |
|
|
|
var sonUserVirtualWallet []model.UserVirtualAmount |
|
|
|
Db.Where(" coin_id = ?", greenCoinDoubleChain.Coin2).In("uid", userIds).Asc("amount").Find(&sonUserVirtualWallet) |
|
|
|
Db.Where(" coin_id = ? and amount > 0 ", greenCoinDoubleChain.Coin2).In("uid", userIds).Asc("amount").Find(&sonUserVirtualWallet) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
@@ -321,16 +325,18 @@ func HandleUserGreenCoinDoubleChainIntegralBySon(Db *xorm.Engine, uid int, ordId |
|
|
|
/* |
|
|
|
TODO::4、进行“数据变更” |
|
|
|
*/ |
|
|
|
var amount string |
|
|
|
var lastUid int |
|
|
|
session := Db.NewSession() |
|
|
|
session.Begin() |
|
|
|
defer func() { |
|
|
|
session.Close() |
|
|
|
if err := recover(); err != nil { |
|
|
|
_ = zhios_order_relate_logx.Error(err) |
|
|
|
} |
|
|
|
}() |
|
|
|
var amount string |
|
|
|
var lastUid int |
|
|
|
for _, v := range sonUserVirtualWallet { |
|
|
|
|
|
|
|
if lastUid == -1 { |
|
|
|
break |
|
|
|
} |
|
|
@@ -343,17 +349,16 @@ func HandleUserGreenCoinDoubleChainIntegralBySon(Db *xorm.Engine, uid int, ordId |
|
|
|
} |
|
|
|
|
|
|
|
amountValue, _ := decimal.NewFromString(amount) |
|
|
|
if userAmount.LessThan(amountValue) { |
|
|
|
//当前用户虚拟币金额小于上一个用户虚拟币金额 |
|
|
|
amountValue = userAmount |
|
|
|
} |
|
|
|
//if userAmount.LessThan(amountValue) { |
|
|
|
// //当前用户虚拟币金额小于上一个用户虚拟币金额 |
|
|
|
// amountValue = userAmount |
|
|
|
//} |
|
|
|
|
|
|
|
if parentAmountValue.LessThan(amountValue) { |
|
|
|
//TODO::上级绿色积分小于当前需要兑换积分金额 |
|
|
|
amountValue = parentAmountValue |
|
|
|
} |
|
|
|
|
|
|
|
session.Begin() |
|
|
|
//4.1、上级减少amount 绿色积分 |
|
|
|
err = DealUserCoin(session, md.DealUserCoinReq{ |
|
|
|
Kind: "sub", |
|
|
@@ -367,7 +372,7 @@ func HandleUserGreenCoinDoubleChainIntegralBySon(Db *xorm.Engine, uid int, ordId |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
//4.2、用户减少amount 贡献积分 |
|
|
|
err = DealUserCoin(session, md.DealUserCoinReq{ |
|
|
@@ -380,6 +385,10 @@ func HandleUserGreenCoinDoubleChainIntegralBySon(Db *xorm.Engine, uid int, ordId |
|
|
|
Uid: v.Uid, |
|
|
|
Amount: zhios_order_relate_utils.StrToFloat64(amountValue.String()), |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
break |
|
|
|
} |
|
|
|
//4.3、另一下级减少amount 贡献积分 |
|
|
|
err = DealUserCoin(session, md.DealUserCoinReq{ |
|
|
|
Kind: "sub", |
|
|
@@ -393,14 +402,14 @@ func HandleUserGreenCoinDoubleChainIntegralBySon(Db *xorm.Engine, uid int, ordId |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
//4.4上级余额增加 |
|
|
|
var coin model.VirtualCoin |
|
|
|
_, err = session.Where("id = ?", greenCoinDoubleChain.Coin1).Get(&coin) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
coinExchangeRatioValue, _ := decimal.NewFromString(coin.ExchangeRatio) |
|
|
|
exchangeAmount, _ := amountValue.Div(coinExchangeRatioValue).Float64() |
|
|
@@ -418,24 +427,24 @@ func HandleUserGreenCoinDoubleChainIntegralBySon(Db *xorm.Engine, uid int, ordId |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
//5、新增 green_coin_double_chain_exchange_records 记录 |
|
|
|
afterUserCoinAmount, err := svc.GetUserCoinAmount(session, masterId, greenCoinDoubleChain.Coin1, uid) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
afterCoinAmountContributeUser1, err := svc.GetUserCoinAmount(session, masterId, greenCoinDoubleChain.Coin2, v.Uid) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
afterCoinAmountContributeUser2, err := svc.GetUserCoinAmount(session, masterId, greenCoinDoubleChain.Coin2, lastUid) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
now := time.Now() |
|
|
|
_, err = db.GreenCoinDoubleChainExchangeRecordsInsert(Db, &model.GreenCoinDoubleChainExchangeRecords{ |
|
|
@@ -456,20 +465,19 @@ func HandleUserGreenCoinDoubleChainIntegralBySon(Db *xorm.Engine, uid int, ordId |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
session.Commit() |
|
|
|
|
|
|
|
if zhios_order_relate_utils.StrToFloat64(afterUserCoinAmount) == 0 { |
|
|
|
lastUid = -1 |
|
|
|
} else { |
|
|
|
if amountValue.String() == amount { |
|
|
|
amount = afterCoinAmountContributeUser2 |
|
|
|
} else { |
|
|
|
amount = afterCoinAmountContributeUser1 |
|
|
|
lastUid = v.Uid |
|
|
|
} |
|
|
|
amount = afterCoinAmountContributeUser1 |
|
|
|
lastUid = v.Uid |
|
|
|
} |
|
|
|
if zhios_order_relate_utils.StrToFloat64(amount) == 0 { |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
session.Commit() |
|
|
|
return |
|
|
|
} |