From f1f2246c43eaa979d825a3d94cb42b132f04229f Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Thu, 28 Dec 2023 18:18:17 +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 --- db/db_subsidy_with_month.go | 20 +++++++++++++------- db/model/subsidy_with_user_month.go | 9 +++++---- rule/consume_integral_settlement.go | 24 +++++++++++++++++++----- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/db/db_subsidy_with_month.go b/db/db_subsidy_with_month.go index 324b77e..7d9c3f6 100644 --- a/db/db_subsidy_with_month.go +++ b/db/db_subsidy_with_month.go @@ -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 } diff --git a/db/model/subsidy_with_user_month.go b/db/model/subsidy_with_user_month.go index 2f6ece9..78bbd0f 100644 --- a/db/model/subsidy_with_user_month.go +++ b/db/model/subsidy_with_user_month.go @@ -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)"` } diff --git a/rule/consume_integral_settlement.go b/rule/consume_integral_settlement.go index b7f9f23..a1dbb26 100644 --- a/rule/consume_integral_settlement.go +++ b/rule/consume_integral_settlement.go @@ -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 {