diff --git a/rule/consume_integral_settlement.go b/rule/consume_integral_settlement.go index d9dfb5d..ff2a979 100644 --- a/rule/consume_integral_settlement.go +++ b/rule/consume_integral_settlement.go @@ -76,6 +76,8 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask return errors.New("上一次结算未执行完") } cache.SetEx(PessimismLockKeyForConsumeIntegral, PessimismLockValueForConsumeIntegral, 3600*8) //8小时 + + var consumeValueTotal, experienceValueTotal = decimal.NewFromInt(0), decimal.NewFromInt(0) //1、统计当前拥有多少份消费补贴 startAt := time.Now().Add(time.Duration(subsidyBase.ConsumptionDay) * -24 * time.Hour).Format("2006-01-02") //起始时间 var subsidyWithUserForConsumeList []model.SubsidyWithUser @@ -88,7 +90,9 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask _ = session.Rollback() return err } + for _, v := range subsidyWithUserForConsumeList { + consumeValueTotal = consumeValueTotal.Add(decimal.NewFromFloat(consumeValue)) err1 := DealUserConsumeIntegral(session, &v, consumeValue, mid) if err1 != nil { _ = session.Rollback() @@ -108,6 +112,7 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask return err } for _, v := range subsidyWithUserForConsumeList { + experienceValueTotal = experienceValueTotal.Add(decimal.NewFromFloat(experienceValue)) err1 := DealUserExperienceIntegral(session, &v, experienceValue, mid) if err1 != nil { _ = session.Rollback() @@ -115,6 +120,28 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask } } + //3、修改 subsidy_base 中 consumption_money、experience_money + consumeTotal, _ := consumeValueTotal.Float64() + experienceTotal, _ := experienceValueTotal.Float64() + subsidyBase.ConsumptionMoney = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(subsidyBase.ConsumptionMoney) - consumeTotal) + subsidyBase.ExperienceMoney = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(subsidyBase.ExperienceMoney) - experienceTotal) + updateAffected, err := db.SubsidyBaseUpdate(session, subsidyBase.Id, subsidyBase, "consumption_money", "experience_money") + if err != nil { + _ = session.Rollback() + return + } + if updateAffected <= 0 { + _ = session.Rollback() + return errors.New("修改 subsidy_base 失败") + } + + //4、提交事务 + err = session.Commit() + if err != nil { + _ = session.Rollback() + return errors.New("事务提交失败") + } + cache.Del(PessimismLockKeyForConsumeIntegral) fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>消费积分结束<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") return nil