huangjiajun 7 miesięcy temu
rodzic
commit
b4b8b5db6e
3 zmienionych plików z 32 dodań i 30 usunięć
  1. +2
    -0
      db/model/subsidy_with_user.go
  2. +2
    -0
      db/model/subsidy_with_user_flow.go
  3. +28
    -30
      rule/consume_integral_settlement.go

+ 2
- 0
db/model/subsidy_with_user.go Wyświetl plik

@@ -12,4 +12,6 @@ type SubsidyWithUser struct {
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
IsCanSubsidy int `json:"is_can_subsidy" xorm:"not null default 1 comment('()') INT(1)"`
Day int `json:"day" xorm:"not null default 0 comment('') TINYINT(1)"`
LeaveDay int `json:"leave_day" xorm:"not null default 0 comment('') TINYINT(1)"`
}

+ 2
- 0
db/model/subsidy_with_user_flow.go Wyświetl plik

@@ -11,4 +11,6 @@ type SubsidyWithUserFlow struct {
Month int `json:"month" xorm:"default 0 comment('202312') INT(11)"`
Uid int `json:"uid" xorm:"default 0 INT(11)"`
Date string `json:"date" xorm:"comment('2023-12-01') VARCHAR(255)"`
Day int `json:"day" xorm:"not null default 0 comment('') TINYINT(1)"`
LeaveDay int `json:"leave_day" xorm:"not null default 0 comment('') TINYINT(1)"`
}

+ 28
- 30
rule/consume_integral_settlement.go Wyświetl plik

@@ -354,18 +354,17 @@ func calcNowEverydayStoreIntegral(consumeValue, bili float64) (value float64, er
func DealUserConsumeIntegral(session *xorm.Session, subsidyWithUser *model.SubsidyWithUser, consumeIntegralValue float64, mid string) (err error) {
now := time.Now()
//1、扣除 subsidy_with_user 的 balance_amount、state
if subsidyWithUser.Amount == subsidyWithUser.BalanceAmount {
if subsidyWithUser.Day >= subsidyWithUser.LeaveDay && subsidyWithUser.State < 2 {
subsidyWithUser.State = 2 //补贴中
}
balanceAmount, _ := decimal.NewFromString(subsidyWithUser.BalanceAmount)
afterAmount, _ := balanceAmount.Sub(decimal.NewFromFloat(consumeIntegralValue)).Float64()
balanceAmount := subsidyWithUser.LeaveDay
afterAmount := balanceAmount - 1
if afterAmount <= 0 {
afterAmount = 0
consumeIntegralValue = zhios_order_relate_utils.StrToFloat64(subsidyWithUser.BalanceAmount)
subsidyWithUser.State = 3 //补贴完
}
subsidyWithUser.BalanceAmount = zhios_order_relate_utils.Float64ToStr(afterAmount)
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "balance_amount", "state")
subsidyWithUser.LeaveDay = afterAmount
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "leave_day", "state")
if err != nil {
return err
}
@@ -375,15 +374,15 @@ func DealUserConsumeIntegral(session *xorm.Session, subsidyWithUser *model.Subsi

//2、新增 subsidy_with_user_flow 记录
var subsidyWitUserFlow = &model.SubsidyWithUserFlow{
RecordsId: subsidyWithUser.Id,
Amount: zhios_order_relate_utils.Float64ToStr(consumeIntegralValue),
BalanceAmount: zhios_order_relate_utils.Float64ToStr(afterAmount),
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
Date: now.Format("2006-01-02"),
Uid: subsidyWithUser.Uid,
Kind: subsidyWithUser.Kind,
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")),
RecordsId: subsidyWithUser.Id,
Day: 1,
LeaveDay: afterAmount,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
Date: now.Format("2006-01-02"),
Uid: subsidyWithUser.Uid,
Kind: subsidyWithUser.Kind,
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")),
}
insertAffected, err := db.SubsidyWithUserFlowInsert(session, subsidyWitUserFlow)
if err != nil {
@@ -427,18 +426,17 @@ func DealUserConsumeIntegral(session *xorm.Session, subsidyWithUser *model.Subsi
func DealUserExperienceIntegral(session *xorm.Session, subsidyWithUser *model.SubsidyWithUser, experienceIntegralValue float64, mid string) (err error) {
now := time.Now()
//1、扣除 subsidy_with_user 的 balance_amount、state
if subsidyWithUser.Amount == subsidyWithUser.BalanceAmount {
if subsidyWithUser.Day >= subsidyWithUser.LeaveDay && subsidyWithUser.State < 2 {
subsidyWithUser.State = 2 //补贴中
}
balanceAmount, _ := decimal.NewFromString(subsidyWithUser.BalanceAmount)
afterAmount, _ := balanceAmount.Sub(decimal.NewFromFloat(experienceIntegralValue)).Float64()
balanceAmount := subsidyWithUser.LeaveDay
afterAmount := balanceAmount - 1
if afterAmount <= 0 {
afterAmount = 0
experienceIntegralValue = zhios_order_relate_utils.StrToFloat64(subsidyWithUser.BalanceAmount)
subsidyWithUser.State = 3 //补贴完
}
subsidyWithUser.BalanceAmount = zhios_order_relate_utils.Float64ToStr(afterAmount)
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "balance_amount", "state")
subsidyWithUser.LeaveDay = afterAmount
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "leave_day", "state")
if err != nil {
return err
}
@@ -448,15 +446,15 @@ func DealUserExperienceIntegral(session *xorm.Session, subsidyWithUser *model.Su

//2、新增 subsidy_with_user_flow 记录
var subsidyWitUserFlow = &model.SubsidyWithUserFlow{
RecordsId: subsidyWithUser.Id,
Uid: subsidyWithUser.Uid,
Kind: subsidyWithUser.Kind,
Amount: zhios_order_relate_utils.Float64ToStr(experienceIntegralValue),
BalanceAmount: zhios_order_relate_utils.Float64ToStr(afterAmount),
CreateAt: now.Format("2006-01-02 15:04:05"),
Date: now.Format("2006-01-02"),
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")),
UpdateAt: now.Format("2006-01-02 15:04:05"),
RecordsId: subsidyWithUser.Id,
Uid: subsidyWithUser.Uid,
Kind: subsidyWithUser.Kind,
Day: 1,
LeaveDay: afterAmount,
CreateAt: now.Format("2006-01-02 15:04:05"),
Date: now.Format("2006-01-02"),
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")),
UpdateAt: now.Format("2006-01-02 15:04:05"),
}
insertAffected, err := db.SubsidyWithUserFlowInsert(session, subsidyWitUserFlow)
if err != nil {


Ładowanie…
Anuluj
Zapisz