|
|
@@ -123,10 +123,12 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask |
|
|
|
} |
|
|
|
if hasConsumeTotal > 0 { |
|
|
|
for _, v := range subsidyWithUserForConsumeList { |
|
|
|
consumeTotalMap[v.Uid] = consumeTotalMap[v.Uid].Add(decimal.NewFromFloat(consumeValue)) |
|
|
|
totalMap[v.Uid] = totalMap[v.Uid].Add(decimal.NewFromFloat(consumeValue)) |
|
|
|
consumeTotalCountMap[v.Uid]++ |
|
|
|
consumeValueTotal = consumeValueTotal.Add(decimal.NewFromFloat(consumeValue)) |
|
|
|
if v.LeaveDay > 0 { |
|
|
|
consumeTotalMap[v.Uid] = consumeTotalMap[v.Uid].Add(decimal.NewFromFloat(consumeValue)) |
|
|
|
totalMap[v.Uid] = totalMap[v.Uid].Add(decimal.NewFromFloat(consumeValue)) |
|
|
|
consumeTotalCountMap[v.Uid]++ |
|
|
|
consumeValueTotal = consumeValueTotal.Add(decimal.NewFromFloat(consumeValue)) |
|
|
|
} |
|
|
|
err1 := DealUserConsumeIntegral(session, &v, consumeValue, mid) |
|
|
|
if err1 != nil { |
|
|
|
_ = session.Rollback() |
|
|
@@ -155,10 +157,12 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask |
|
|
|
return err, totalMap, storeTotalMap |
|
|
|
} |
|
|
|
for _, v := range subsidyWithUserForExperienceList { |
|
|
|
experienceTotalCountMap[v.Uid]++ |
|
|
|
totalMap[v.Uid] = totalMap[v.Uid].Add(decimal.NewFromFloat(experienceValue)) |
|
|
|
experienceTotalMap[v.Uid] = experienceTotalMap[v.Uid].Add(decimal.NewFromFloat(experienceValue)) |
|
|
|
experienceValueTotal = experienceValueTotal.Add(decimal.NewFromFloat(experienceValue)) |
|
|
|
if v.LeaveDay > 0 { |
|
|
|
experienceTotalCountMap[v.Uid]++ |
|
|
|
totalMap[v.Uid] = totalMap[v.Uid].Add(decimal.NewFromFloat(experienceValue)) |
|
|
|
experienceTotalMap[v.Uid] = experienceTotalMap[v.Uid].Add(decimal.NewFromFloat(experienceValue)) |
|
|
|
experienceValueTotal = experienceValueTotal.Add(decimal.NewFromFloat(experienceValue)) |
|
|
|
} |
|
|
|
err1 := DealUserExperienceIntegral(session, &v, experienceValue, mid) |
|
|
|
if err1 != nil { |
|
|
|
_ = session.Rollback() |
|
|
@@ -302,8 +306,8 @@ func Total(sess *xorm.Session, date, dayPayAmount string) error { |
|
|
|
data.AllAmount = AllAmount |
|
|
|
data.AllIntegral = AllIntegral |
|
|
|
data.AllIntegralAmount = AllIntegralAmount |
|
|
|
update, err := sess.Where("id=?", data.Id).Update(&data) |
|
|
|
if update == 0 || err != nil { |
|
|
|
_, err := sess.Where("id=?", data.Id).Update(&data) |
|
|
|
if err != nil { |
|
|
|
return errors.New("失败") |
|
|
|
} |
|
|
|
return nil |
|
|
@@ -354,36 +358,42 @@ 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 |
|
|
|
isEnd := 0 |
|
|
|
if afterAmount < 0 { |
|
|
|
isEnd = 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 |
|
|
|
} |
|
|
|
if updateAffected <= 0 { |
|
|
|
return errors.New("修改 subsidy_with_user 记录失败") |
|
|
|
} |
|
|
|
|
|
|
|
if isEnd == 1 { |
|
|
|
return nil |
|
|
|
} |
|
|
|
//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, |
|
|
|
Amount: zhios_order_relate_utils.Float64ToStr(consumeIntegralValue), |
|
|
|
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,36 +437,42 @@ 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 |
|
|
|
isEnd := 0 |
|
|
|
if afterAmount < 0 { |
|
|
|
isEnd = 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 |
|
|
|
} |
|
|
|
if updateAffected <= 0 { |
|
|
|
return errors.New("修改 subsidy_with_user 记录失败") |
|
|
|
} |
|
|
|
|
|
|
|
if isEnd == 1 { |
|
|
|
return nil |
|
|
|
} |
|
|
|
//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, |
|
|
|
Amount: zhios_order_relate_utils.Float64ToStr(experienceIntegralValue), |
|
|
|
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 { |
|
|
|