|
@@ -113,7 +113,19 @@ func DailySettlementNiuBeiRelease(engine *xorm.Engine, mid string, isTask bool) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//3、提交事务 |
|
|
|
|
|
|
|
|
//6、更新 `niu_bei_coin_basic` 表 |
|
|
|
|
|
niuBeiRelease.ReleaseDate = today |
|
|
|
|
|
updateAffected, err := db.NiuBeiCoinBasicUpdate(session, niuBeiRelease.Id, niuBeiRelease) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
if updateAffected == 0 { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
return errors.New("更新 niu_bei_coin_user_with_ord 记录失败") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//7、提交事务 |
|
|
err = session.Commit() |
|
|
err = session.Commit() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
_ = session.Rollback() |
|
|
_ = session.Rollback() |
|
@@ -138,6 +150,7 @@ type CalcNiuBeiReleaseResp struct { |
|
|
ReleaseCouponDestroyConsumeCoinNum string // 释放抵扣劵数量-消耗消费积分数量 |
|
|
ReleaseCouponDestroyConsumeCoinNum string // 释放抵扣劵数量-消耗消费积分数量 |
|
|
ReleaseOptionCoinNum string // 释放期权积分数量 |
|
|
ReleaseOptionCoinNum string // 释放期权积分数量 |
|
|
ReleaseOptionDestroyConsumeCoinNum string // 释放期权积分数量-消耗消费积分数量 |
|
|
ReleaseOptionDestroyConsumeCoinNum string // 释放期权积分数量-消耗消费积分数量 |
|
|
|
|
|
ReleasedRatio string // 已释放百分比 |
|
|
IsReleasedFinish bool // 是否释放完毕 |
|
|
IsReleasedFinish bool // 是否释放完毕 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -197,7 +210,7 @@ func CalcNiuBeiReleaseNums(session *xorm.Session, niuBeiCoinBasic *model.NiuBeiC |
|
|
|
|
|
|
|
|
resp.ReleaseCouponCoinNum = totalCoinRelease.Mul(dailyCouponCoinReleaseRatio.Mul(percentageValue)).Mul(coinOneValue.Div(coinThreeValue)).String() |
|
|
resp.ReleaseCouponCoinNum = totalCoinRelease.Mul(dailyCouponCoinReleaseRatio.Mul(percentageValue)).Mul(coinOneValue.Div(coinThreeValue)).String() |
|
|
resp.ReleaseCouponDestroyConsumeCoinNum = totalCoinRelease.Mul(dailyCouponCoinReleaseRatio.Mul(percentageValue)).Mul(coinOneValue).String() |
|
|
resp.ReleaseCouponDestroyConsumeCoinNum = totalCoinRelease.Mul(dailyCouponCoinReleaseRatio.Mul(percentageValue)).Mul(coinOneValue).String() |
|
|
|
|
|
|
|
|
|
|
|
resp.ReleasedRatio = releasedRatio.Add(dailyConsumeCoinReleaseRatio).String() |
|
|
resp.IsReleasedFinish = releasedRatio.Add(dailyConsumeCoinReleaseRatio).GreaterThanOrEqual(totalCoinReleaseRatio) |
|
|
resp.IsReleasedFinish = releasedRatio.Add(dailyConsumeCoinReleaseRatio).GreaterThanOrEqual(totalCoinReleaseRatio) |
|
|
if resp.IsReleasedFinish { |
|
|
if resp.IsReleasedFinish { |
|
|
//TODO:: (总消费积分数量 * (100 - 已释放百分比) / 100) *(消费积分兑换比例 / 牛贝积分兑换比例) |
|
|
//TODO:: (总消费积分数量 * (100 - 已释放百分比) / 100) *(消费积分兑换比例 / 牛贝积分兑换比例) |
|
@@ -209,6 +222,13 @@ func CalcNiuBeiReleaseNums(session *xorm.Session, niuBeiCoinBasic *model.NiuBeiC |
|
|
|
|
|
|
|
|
// ReleaseNiuBeiCoinForUser 释放用户积分 |
|
|
// ReleaseNiuBeiCoinForUser 释放用户积分 |
|
|
func ReleaseNiuBeiCoinForUser(session *xorm.Session, mid string, niuBeiRelease *model.NiuBeiCoinBasic, ord *model.NiuBeiCoinUserWithOrd, resp CalcNiuBeiReleaseResp) (err error) { |
|
|
func ReleaseNiuBeiCoinForUser(session *xorm.Session, mid string, niuBeiRelease *model.NiuBeiCoinBasic, ord *model.NiuBeiCoinUserWithOrd, resp CalcNiuBeiReleaseResp) (err error) { |
|
|
|
|
|
beforeReleasedNiubeiCoinNum, _ := decimal.NewFromString(ord.ReleasedNiubeiCoinNum) |
|
|
|
|
|
releasedNiubeiCoinNum, _ := decimal.NewFromString(resp.ReleaseNiuBeiCoinNum) |
|
|
|
|
|
beforeReleasedCouponCoinNum, _ := decimal.NewFromString(ord.ReleasedCouponCoinNum) |
|
|
|
|
|
releaseCouponCoinNum, _ := decimal.NewFromString(resp.ReleaseCouponCoinNum) |
|
|
|
|
|
beforeReleasedOptionCoinNum, _ := decimal.NewFromString(ord.ReleasedOptionCoinNum) |
|
|
|
|
|
releaseOptionCoinNum, _ := decimal.NewFromString(resp.ReleaseOptionCoinNum) |
|
|
|
|
|
|
|
|
//1、牛贝积分-释放牛贝积分 |
|
|
//1、牛贝积分-释放牛贝积分 |
|
|
err = DealUserCoinForNiuBeiRelease(session, md.DealUserCoinReq{ |
|
|
err = DealUserCoinForNiuBeiRelease(session, md.DealUserCoinReq{ |
|
|
Kind: "add", |
|
|
Kind: "add", |
|
@@ -268,33 +288,51 @@ func ReleaseNiuBeiCoinForUser(session *xorm.Session, mid string, niuBeiRelease * |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//5、牛贝积分-释放期权积分 |
|
|
|
|
|
err = DealUserCoinForNiuBeiRelease(session, md.DealUserCoinReq{ |
|
|
|
|
|
Kind: "add", |
|
|
|
|
|
Mid: mid, |
|
|
|
|
|
Title: md.NiuBeiCoinByReleaseOptionCoinNumTitleForUserVirtualCoinFlow, |
|
|
|
|
|
TransferType: md.NiuBeiCoinByReleaseOptionCoinNumTransferTypeForUserVirtualCoinFlow, |
|
|
|
|
|
OrdId: ord.OrdId, |
|
|
|
|
|
CoinId: niuBeiRelease.Coin2, |
|
|
|
|
|
Uid: ord.Uid, |
|
|
|
|
|
Amount: zhios_order_relate_utils.StrToFloat64(resp.ReleaseOptionCoinNum), |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
if resp.IsReleasedFinish { |
|
|
|
|
|
//5、牛贝积分-释放期权积分 |
|
|
|
|
|
err = DealUserCoinForNiuBeiRelease(session, md.DealUserCoinReq{ |
|
|
|
|
|
Kind: "add", |
|
|
|
|
|
Mid: mid, |
|
|
|
|
|
Title: md.NiuBeiCoinByReleaseOptionCoinNumTitleForUserVirtualCoinFlow, |
|
|
|
|
|
TransferType: md.NiuBeiCoinByReleaseOptionCoinNumTransferTypeForUserVirtualCoinFlow, |
|
|
|
|
|
OrdId: ord.OrdId, |
|
|
|
|
|
CoinId: niuBeiRelease.Coin2, |
|
|
|
|
|
Uid: ord.Uid, |
|
|
|
|
|
Amount: zhios_order_relate_utils.StrToFloat64(resp.ReleaseOptionCoinNum), |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//6、释放期权积分数量-消耗消费积分数量 |
|
|
|
|
|
err = DealUserCoinForNiuBeiRelease(session, md.DealUserCoinReq{ |
|
|
|
|
|
Kind: "sub", |
|
|
|
|
|
Mid: mid, |
|
|
|
|
|
Title: md.NiuBeiCoinByReleaseOptionDestroyConsumeCoinNumTitleForUserVirtualCoinFlow, |
|
|
|
|
|
TransferType: md.NiuBeiCoinByReleaseOptionDestroyConsumeCoinNumTransferTypeForUserVirtualCoinFlow, |
|
|
|
|
|
OrdId: ord.OrdId, |
|
|
|
|
|
CoinId: niuBeiRelease.Coin2, |
|
|
|
|
|
Uid: ord.Uid, |
|
|
|
|
|
Amount: zhios_order_relate_utils.StrToFloat64(resp.ReleaseOptionDestroyConsumeCoinNum), |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
ord.ReleasedOptionCoinNum = beforeReleasedOptionCoinNum.Add(releaseOptionCoinNum).String() |
|
|
|
|
|
} |
|
|
|
|
|
//8、修改 `niu_bei_coin_user_with_ord` 记录 |
|
|
|
|
|
ord.ReleasedNiubeiCoinNum = beforeReleasedNiubeiCoinNum.Add(releasedNiubeiCoinNum).String() |
|
|
|
|
|
ord.ReleasedCouponCoinNum = beforeReleasedCouponCoinNum.Add(releaseCouponCoinNum).String() |
|
|
|
|
|
ord.ReleasedRatio = resp.ReleasedRatio |
|
|
|
|
|
if resp.IsReleasedFinish { |
|
|
|
|
|
ord.IsReleasedFinish = 1 //释放完毕 |
|
|
|
|
|
} |
|
|
|
|
|
updateAffected, err := db.NiuBeiCoinUserWithOrdUpdate(session, ord.Id, ord) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//6、释放期权积分数量-消耗消费积分数量 |
|
|
|
|
|
err = DealUserCoinForNiuBeiRelease(session, md.DealUserCoinReq{ |
|
|
|
|
|
Kind: "sub", |
|
|
|
|
|
Mid: mid, |
|
|
|
|
|
Title: md.NiuBeiCoinByReleaseOptionDestroyConsumeCoinNumTitleForUserVirtualCoinFlow, |
|
|
|
|
|
TransferType: md.NiuBeiCoinByReleaseOptionDestroyConsumeCoinNumTransferTypeForUserVirtualCoinFlow, |
|
|
|
|
|
OrdId: ord.OrdId, |
|
|
|
|
|
CoinId: niuBeiRelease.Coin2, |
|
|
|
|
|
Uid: ord.Uid, |
|
|
|
|
|
Amount: zhios_order_relate_utils.StrToFloat64(resp.ReleaseOptionDestroyConsumeCoinNum), |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
|
if updateAffected == 0 { |
|
|
|
|
|
err = errors.New("更新 niu_bei_coin_user_with_ord 记录失败") |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
return nil |
|
|
return nil |
|
|