From 72b382228216548033fdd09a5208327352645250 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Thu, 28 Dec 2023 17:53:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rule/consume_integral_settlement.go | 54 ++++++++++++++++------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/rule/consume_integral_settlement.go b/rule/consume_integral_settlement.go index b027d17..db6728d 100644 --- a/rule/consume_integral_settlement.go +++ b/rule/consume_integral_settlement.go @@ -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 }