From bf30ec3369b53d7b77997ef137301681bb7e718a Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Sat, 23 Mar 2024 19:03:54 +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 | 38 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/rule/consume_integral_settlement.go b/rule/consume_integral_settlement.go index 9959038..7bc433a 100644 --- a/rule/consume_integral_settlement.go +++ b/rule/consume_integral_settlement.go @@ -29,7 +29,7 @@ const PessimismLockKeyForConsumeIntegral = "daily_settlement_consume_integral_lo const PessimismLockValueForConsumeIntegral = "running" // DailySettlementBlockConsumeIntegral 每日结算“消费积分” -func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask bool) (err error, totalMap map[int]decimal.Decimal) { +func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask bool) (err error, totalMap map[int]decimal.Decimal, storeTotalMap map[int]decimal.Decimal) { session := engine.NewSession() defer func() { session.Close() @@ -57,19 +57,19 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask if isTask && (now.Hour() > 8 || now.Before(settleTime)) { session.Rollback() //TODO::结算时间 ~ 凌晨 8 点运行 - return errors.New("非运行时间"), totalMap + return errors.New("非运行时间"), totalMap, storeTotalMap } if isTask && zhios_order_relate_utils.InArr(now.Weekday().String(), []string{"Sunday", "Saturday"}) && subsidyBase.HolidaySettleOpen != 1 { session.Rollback() - return errors.New("周末不运行"), totalMap + return errors.New("周末不运行"), totalMap, storeTotalMap } if err != nil { _ = session.Rollback() - return err, totalMap + return err, totalMap, storeTotalMap } if isTask && subsidyBase.SettlementDate == today { _ = session.Rollback() - return errors.New("今日“消费计费”已结算"), totalMap + return errors.New("今日“消费计费”已结算"), totalMap, storeTotalMap } key := fmt.Sprintf(PessimismLockKeyForConsumeIntegral, mid) //TODO::增加“悲观锁”防止串行 @@ -79,7 +79,7 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask //} if getString == PessimismLockValueForConsumeIntegral { fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", "上一次结算未执行完") - return errors.New("上一次结算未执行完"), totalMap + return errors.New("上一次结算未执行完"), totalMap, storeTotalMap } cache.SetEx(key, PessimismLockValueForConsumeIntegral, 3600*8) //8小时 @@ -117,7 +117,7 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask consumeValue, err = calcNowEverydayConsumeIntegral(subsidyBase, total) if err != nil { _ = session.Rollback() - return err, totalMap + return err, totalMap, storeTotalMap } if hasConsumeTotal > 0 { for _, v := range subsidyWithUserForConsumeList { @@ -128,7 +128,7 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask err1 := DealUserConsumeIntegral(session, &v, consumeValue, mid) if err1 != nil { _ = session.Rollback() - return err1, totalMap + return err1, totalMap, storeTotalMap } } } @@ -138,7 +138,7 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask err1 := DealUserConsumeAmountFlow(session, k, zhios_order_relate_utils.StrToFloat64(v.String()), mid, zhios_order_relate_utils.IntToStr(consumeTotalCountMap[k])) if err1 != nil { _ = session.Rollback() - return err1, totalMap + return err1, totalMap, storeTotalMap } } } @@ -150,7 +150,7 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask experienceValue, err = calcNowEverydayExperienceIntegral(consumeValue) if err != nil { _ = session.Rollback() - return err, totalMap + return err, totalMap, storeTotalMap } for _, v := range subsidyWithUserForExperienceList { experienceTotalCountMap[v.Uid]++ @@ -160,7 +160,7 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask err1 := DealUserExperienceIntegral(session, &v, experienceValue, mid) if err1 != nil { _ = session.Rollback() - return err1, totalMap + return err1, totalMap, storeTotalMap } } } @@ -170,21 +170,19 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask err1 := DealUserExperienceAmountFlow(session, k, zhios_order_relate_utils.StrToFloat64(v.String()), mid, zhios_order_relate_utils.IntToStr(experienceTotalCountMap[k])) if err1 != nil { _ = session.Rollback() - return err1, totalMap + return err1, totalMap, storeTotalMap } } } //2、统计当前拥有多少份门店补贴 if subsidyBase.StoreOpen == 1 { - - var storeTotalMap = make(map[int]decimal.Decimal) var storeTotalCountMap = make(map[int]int) if hasStoreTotal > 0 && consumeValue > 0 { storeValue, err = calcNowEverydayStoreIntegral(consumeValue, zhios_order_relate_utils.StrToFloat64(subsidyBase.StoreIntegral)/zhios_order_relate_utils.StrToFloat64(subsidyBase.ConsumptionIntegral)) if err != nil { _ = session.Rollback() - return err, totalMap + return err, totalMap, storeTotalMap } for _, v := range subsidyWithUserForStoreList { storeTotalCountMap[v.Uid]++ @@ -193,7 +191,7 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask err1 := DealUserStoreIntegral(session, &v, storeValue, mid) if err1 != nil { _ = session.Rollback() - return err1, totalMap + return err1, totalMap, storeTotalMap } } } @@ -203,7 +201,7 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask err1 := DealUserStoreAmountFlow(session, k, zhios_order_relate_utils.StrToFloat64(v.String()), mid, zhios_order_relate_utils.IntToStr(experienceTotalCountMap[k])) if err1 != nil { _ = session.Rollback() - return err1, totalMap + return err1, totalMap, storeTotalMap } } } @@ -224,20 +222,20 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask } if updateAffected <= 0 { _ = session.Rollback() - return errors.New("修改 subsidy_base 失败"), totalMap + return errors.New("修改 subsidy_base 失败"), totalMap, storeTotalMap } //4、提交事务 err = session.Commit() if err != nil { _ = session.Rollback() - return errors.New("事务提交失败"), totalMap + return errors.New("事务提交失败"), totalMap, storeTotalMap } cache.Del(key) fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>消费积分结束<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") - return nil, totalMap + return nil, totalMap, storeTotalMap } //计算当前消费积分价值(公式 "((资金池的金额 * 浮动比例) / 消费补贴总数) + 基础补贴")