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