|
|
@@ -87,50 +87,55 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask |
|
|
|
startAt := time.Now().Add(time.Duration(subsidyBase.ConsumptionDay) * -24 * time.Hour).Format("2006-01-02") //起始时间 |
|
|
|
var subsidyWithUserForConsumeList []model.SubsidyWithUser |
|
|
|
hasConsumeTotal, err := session.Where("date <= ?", startAt).And("kind = ? and is_can_subsidy=?", 1, 1).FindAndCount(&subsidyWithUserForConsumeList) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
consumeValue, err := calcNowEverydayConsumeIntegral(subsidyBase, hasConsumeTotal) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
for _, v := range subsidyWithUserForConsumeList { |
|
|
|
consumeValueTotal = consumeValueTotal.Add(decimal.NewFromFloat(consumeValue)) |
|
|
|
err1 := DealUserConsumeIntegral(session, &v, consumeValue, mid) |
|
|
|
if err1 != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if hasConsumeTotal > 0 { |
|
|
|
consumeValue, err := calcNowEverydayConsumeIntegral(subsidyBase, hasConsumeTotal) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err1 |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for _, v := range subsidyWithUserForConsumeList { |
|
|
|
consumeValueTotal = consumeValueTotal.Add(decimal.NewFromFloat(consumeValue)) |
|
|
|
err1 := DealUserConsumeIntegral(session, &v, consumeValue, mid) |
|
|
|
if err1 != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err1 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//2、统计当前拥有多少份体验补贴 |
|
|
|
var subsidyWithUserForExperienceList []model.SubsidyWithUser |
|
|
|
hasExperienceTotal, err := session.Where("date <= ?", startAt).And("kind = ? and is_can_subsidy=?", 2, 1).FindAndCount(&subsidyWithUserForExperienceList) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
experienceValue, err := calcNowEverydayExperienceIntegral(subsidyBase, hasExperienceTotal) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err |
|
|
|
return |
|
|
|
} |
|
|
|
for _, v := range subsidyWithUserForConsumeList { |
|
|
|
experienceValueTotal = experienceValueTotal.Add(decimal.NewFromFloat(experienceValue)) |
|
|
|
err1 := DealUserExperienceIntegral(session, &v, experienceValue, mid) |
|
|
|
if err1 != nil { |
|
|
|
if hasExperienceTotal > 0 { |
|
|
|
experienceValue, err := calcNowEverydayExperienceIntegral(subsidyBase, hasExperienceTotal) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err1 |
|
|
|
return err |
|
|
|
} |
|
|
|
for _, v := range subsidyWithUserForConsumeList { |
|
|
|
experienceValueTotal = experienceValueTotal.Add(decimal.NewFromFloat(experienceValue)) |
|
|
|
err1 := DealUserExperienceIntegral(session, &v, experienceValue, mid) |
|
|
|
if err1 != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err1 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//3、修改 subsidy_base 中 consumption_money、experience_money |
|
|
|
consumeTotal, _ := consumeValueTotal.Float64() |
|
|
|
experienceTotal, _ := experienceValueTotal.Float64() |
|
|
|
subsidyBase.ConsumptionTotalMoney = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(subsidyBase.ConsumptionTotalMoney) - consumeTotal) |
|
|
|
subsidyBase.ExperienceTotalMoney = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(subsidyBase.ExperienceTotalMoney) - experienceTotal) |
|
|
|
updateAffected, err := db.SubsidyBaseUpdate(session, subsidyBase.Id, subsidyBase, "consumption_money", "experience_money") |
|
|
|
updateAffected, err := db.SubsidyBaseUpdate(session, subsidyBase.Id, subsidyBase, "consumption_total_money", "experience_total_money") |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return |
|
|
@@ -302,5 +307,4 @@ func DealUserExperienceIntegral(session *xorm.Session, subsidyWithUser *model.Su |
|
|
|
} |
|
|
|
return nil |
|
|
|
|
|
|
|
return nil |
|
|
|
} |