|
|
@@ -354,18 +354,17 @@ func calcNowEverydayStoreIntegral(consumeValue, bili float64) (value float64, er |
|
|
|
func DealUserConsumeIntegral(session *xorm.Session, subsidyWithUser *model.SubsidyWithUser, consumeIntegralValue float64, mid string) (err error) { |
|
|
|
now := time.Now() |
|
|
|
//1、扣除 subsidy_with_user 的 balance_amount、state |
|
|
|
if subsidyWithUser.Amount == subsidyWithUser.BalanceAmount { |
|
|
|
if subsidyWithUser.Day >= subsidyWithUser.LeaveDay && subsidyWithUser.State < 2 { |
|
|
|
subsidyWithUser.State = 2 //补贴中 |
|
|
|
} |
|
|
|
balanceAmount, _ := decimal.NewFromString(subsidyWithUser.BalanceAmount) |
|
|
|
afterAmount, _ := balanceAmount.Sub(decimal.NewFromFloat(consumeIntegralValue)).Float64() |
|
|
|
balanceAmount := subsidyWithUser.LeaveDay |
|
|
|
afterAmount := balanceAmount - 1 |
|
|
|
if afterAmount <= 0 { |
|
|
|
afterAmount = 0 |
|
|
|
consumeIntegralValue = zhios_order_relate_utils.StrToFloat64(subsidyWithUser.BalanceAmount) |
|
|
|
subsidyWithUser.State = 3 //补贴完 |
|
|
|
} |
|
|
|
subsidyWithUser.BalanceAmount = zhios_order_relate_utils.Float64ToStr(afterAmount) |
|
|
|
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "balance_amount", "state") |
|
|
|
subsidyWithUser.LeaveDay = afterAmount |
|
|
|
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "leave_day", "state") |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
@@ -375,15 +374,15 @@ func DealUserConsumeIntegral(session *xorm.Session, subsidyWithUser *model.Subsi |
|
|
|
|
|
|
|
//2、新增 subsidy_with_user_flow 记录 |
|
|
|
var subsidyWitUserFlow = &model.SubsidyWithUserFlow{ |
|
|
|
RecordsId: subsidyWithUser.Id, |
|
|
|
Amount: zhios_order_relate_utils.Float64ToStr(consumeIntegralValue), |
|
|
|
BalanceAmount: zhios_order_relate_utils.Float64ToStr(afterAmount), |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
Date: now.Format("2006-01-02"), |
|
|
|
Uid: subsidyWithUser.Uid, |
|
|
|
Kind: subsidyWithUser.Kind, |
|
|
|
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")), |
|
|
|
RecordsId: subsidyWithUser.Id, |
|
|
|
Day: 1, |
|
|
|
LeaveDay: afterAmount, |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
Date: now.Format("2006-01-02"), |
|
|
|
Uid: subsidyWithUser.Uid, |
|
|
|
Kind: subsidyWithUser.Kind, |
|
|
|
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")), |
|
|
|
} |
|
|
|
insertAffected, err := db.SubsidyWithUserFlowInsert(session, subsidyWitUserFlow) |
|
|
|
if err != nil { |
|
|
@@ -427,18 +426,17 @@ func DealUserConsumeIntegral(session *xorm.Session, subsidyWithUser *model.Subsi |
|
|
|
func DealUserExperienceIntegral(session *xorm.Session, subsidyWithUser *model.SubsidyWithUser, experienceIntegralValue float64, mid string) (err error) { |
|
|
|
now := time.Now() |
|
|
|
//1、扣除 subsidy_with_user 的 balance_amount、state |
|
|
|
if subsidyWithUser.Amount == subsidyWithUser.BalanceAmount { |
|
|
|
if subsidyWithUser.Day >= subsidyWithUser.LeaveDay && subsidyWithUser.State < 2 { |
|
|
|
subsidyWithUser.State = 2 //补贴中 |
|
|
|
} |
|
|
|
balanceAmount, _ := decimal.NewFromString(subsidyWithUser.BalanceAmount) |
|
|
|
afterAmount, _ := balanceAmount.Sub(decimal.NewFromFloat(experienceIntegralValue)).Float64() |
|
|
|
balanceAmount := subsidyWithUser.LeaveDay |
|
|
|
afterAmount := balanceAmount - 1 |
|
|
|
if afterAmount <= 0 { |
|
|
|
afterAmount = 0 |
|
|
|
experienceIntegralValue = zhios_order_relate_utils.StrToFloat64(subsidyWithUser.BalanceAmount) |
|
|
|
subsidyWithUser.State = 3 //补贴完 |
|
|
|
} |
|
|
|
subsidyWithUser.BalanceAmount = zhios_order_relate_utils.Float64ToStr(afterAmount) |
|
|
|
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "balance_amount", "state") |
|
|
|
subsidyWithUser.LeaveDay = afterAmount |
|
|
|
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "leave_day", "state") |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
@@ -448,15 +446,15 @@ func DealUserExperienceIntegral(session *xorm.Session, subsidyWithUser *model.Su |
|
|
|
|
|
|
|
//2、新增 subsidy_with_user_flow 记录 |
|
|
|
var subsidyWitUserFlow = &model.SubsidyWithUserFlow{ |
|
|
|
RecordsId: subsidyWithUser.Id, |
|
|
|
Uid: subsidyWithUser.Uid, |
|
|
|
Kind: subsidyWithUser.Kind, |
|
|
|
Amount: zhios_order_relate_utils.Float64ToStr(experienceIntegralValue), |
|
|
|
BalanceAmount: zhios_order_relate_utils.Float64ToStr(afterAmount), |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
Date: now.Format("2006-01-02"), |
|
|
|
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
RecordsId: subsidyWithUser.Id, |
|
|
|
Uid: subsidyWithUser.Uid, |
|
|
|
Kind: subsidyWithUser.Kind, |
|
|
|
Day: 1, |
|
|
|
LeaveDay: afterAmount, |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
Date: now.Format("2006-01-02"), |
|
|
|
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
} |
|
|
|
insertAffected, err := db.SubsidyWithUserFlowInsert(session, subsidyWitUserFlow) |
|
|
|
if err != nil { |
|
|
|