@@ -13,9 +13,8 @@ func SubsidyWithMonthInsert(session *xorm.Session, SubsidyWithUserFlow *model.Su | |||
session.Where("date=? and uid=?", SubsidyWithUserFlow.Date, SubsidyWithUserFlow.Uid).Get(&data) | |||
if data.Id == 0 { | |||
data = model.SubsidyWithUserMonth{ | |||
Uid: SubsidyWithUserFlow.Uid, | |||
Date: SubsidyWithUserFlow.Date, | |||
Amount: "", | |||
Uid: SubsidyWithUserFlow.Uid, | |||
Date: SubsidyWithUserFlow.Date, | |||
} | |||
_, err := session.InsertOne(&SubsidyWithUserFlow) | |||
if err != nil { | |||
@@ -23,10 +22,17 @@ func SubsidyWithMonthInsert(session *xorm.Session, SubsidyWithUserFlow *model.Su | |||
} | |||
} | |||
userAmountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(data.Amount)) | |||
amountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(SubsidyWithUserFlow.Amount)) | |||
data.Amount = userAmountValue.Add(amountValue).RoundFloor(8).String() | |||
_, err := session.Where("id=?", data.Id).Cols("amount").Update(&data) | |||
if zhios_order_relate_utils.StrToFloat64(SubsidyWithUserFlow.ConsumeAmount) > 0 { | |||
userAmountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(data.ConsumeAmount)) | |||
amountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(SubsidyWithUserFlow.ConsumeAmount)) | |||
data.ConsumeAmount = userAmountValue.Add(amountValue).RoundFloor(8).String() | |||
} | |||
if zhios_order_relate_utils.StrToFloat64(SubsidyWithUserFlow.ExperienceAmount) > 0 { | |||
userAmountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(data.ExperienceAmount)) | |||
amountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(SubsidyWithUserFlow.ExperienceAmount)) | |||
data.ExperienceAmount = userAmountValue.Add(amountValue).RoundFloor(8).String() | |||
} | |||
_, err := session.Where("id=?", data.Id).Cols("amount,experience_amount").Update(&data) | |||
if err != nil { | |||
return 0, err | |||
} | |||
@@ -1,8 +1,9 @@ | |||
package model | |||
type SubsidyWithUserMonth struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||
Date string `json:"date" xorm:"comment('2023-12') VARCHAR(255)"` | |||
Amount string `json:"amount" xorm:"default 0.00 DECIMAL(20,2)"` | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||
Date string `json:"date" xorm:"comment('2023-12') VARCHAR(255)"` | |||
ConsumeAmount string `json:"consume_amount" xorm:"default 0.00 DECIMAL(20,2)"` | |||
ExperienceAmount string `json:"experience_amount" xorm:"default 0.00 DECIMAL(20,2)"` | |||
} |
@@ -210,6 +210,9 @@ func DealUserConsumeIntegral(session *xorm.Session, subsidyWithUser *model.Subsi | |||
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"), | |||
Uid: subsidyWithUser.Uid, | |||
Kind: subsidyWithUser.Kind, | |||
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")), | |||
} | |||
insertAffected, err := db.SubsidyWithUserFlowInsert(session, subsidyWitUserFlow) | |||
if err != nil { | |||
@@ -218,8 +221,19 @@ func DealUserConsumeIntegral(session *xorm.Session, subsidyWithUser *model.Subsi | |||
if insertAffected <= 0 { | |||
return errors.New("新增 subsidy_with_user_flow 记录失败") | |||
} | |||
//3、给用户添加余额 | |||
//3、加入每月统计 | |||
if consumeIntegralValue > 0 { | |||
var subsidyWitUserMonth = &model.SubsidyWithUserMonth{ | |||
Uid: subsidyWithUser.Uid, | |||
ConsumeAmount: zhios_order_relate_utils.Float64ToStr(consumeIntegralValue), | |||
Date: now.Format("2006-01"), | |||
} | |||
_, err1 := db.SubsidyWithMonthInsert(session, subsidyWitUserMonth) | |||
if err1 != nil { | |||
return err | |||
} | |||
} | |||
//4、给用户添加余额 | |||
orderType := enum.FinUserFlowOrderActionString(md.ConsumeSubsidyOrdActionForFinUserFlow) | |||
var dealUserAmount = md.DealUserAmount{ | |||
Kind: "add", | |||
@@ -282,9 +296,9 @@ func DealUserExperienceIntegral(session *xorm.Session, subsidyWithUser *model.Su | |||
//3、加入每月统计 | |||
if experienceIntegralValue > 0 { | |||
var subsidyWitUserMonth = &model.SubsidyWithUserMonth{ | |||
Uid: subsidyWithUser.Uid, | |||
Amount: zhios_order_relate_utils.Float64ToStr(experienceIntegralValue), | |||
Date: now.Format("2006-01"), | |||
Uid: subsidyWithUser.Uid, | |||
ExperienceAmount: zhios_order_relate_utils.Float64ToStr(experienceIntegralValue), | |||
Date: now.Format("2006-01"), | |||
} | |||
_, err1 := db.SubsidyWithMonthInsert(session, subsidyWitUserMonth) | |||
if err1 != nil { | |||