From 61e513e7af1fc11e8c7f3feb4da30b02d76bb5c3 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Fri, 22 Mar 2024 12:55:53 +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 --- app/db/model/user_day_amount.go | 8 +++++++ app/db/model/user_month_amount.go | 11 +++++---- consume/zhios_order_total_second.go | 36 +++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 app/db/model/user_day_amount.go diff --git a/app/db/model/user_day_amount.go b/app/db/model/user_day_amount.go new file mode 100644 index 0000000..88e6b62 --- /dev/null +++ b/app/db/model/user_day_amount.go @@ -0,0 +1,8 @@ +package model + +type UserDayAmount struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + Uid int `json:"uid" xorm:"default 0 INT(11)"` + Date int `json:"date" xorm:"comment('202301') INT(11)"` + Amount string `json:"amount" xorm:"default 0.000000 DECIMAL(30,6)"` +} diff --git a/app/db/model/user_month_amount.go b/app/db/model/user_month_amount.go index 4f914f0..7d2ff1d 100644 --- a/app/db/model/user_month_amount.go +++ b/app/db/model/user_month_amount.go @@ -1,8 +1,11 @@ package model type UserMonthAmount struct { - Id int `json:"id" xorm:"not null pk autoincr INT(11)"` - Uid int `json:"uid" xorm:"default 0 INT(11)"` - Date int `json:"date" xorm:"comment('202301') INT(11)"` - Amount string `json:"amount" xorm:"default 0.000000 DECIMAL(30,6)"` + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + Uid int `json:"uid" xorm:"default 0 INT(11)"` + Date int `json:"date" xorm:"comment('202301') INT(11)"` + Amount string `json:"amount" xorm:"default 0.000000 DECIMAL(30,6)"` + PlatformAmount string `json:"platform_amount" xorm:"default 0.000000 DECIMAL(30,6)"` + ConfirmAmount string `json:"confirm_amount" xorm:"default 0.000000 DECIMAL(30,6)"` + SettleAmount string `json:"settle_amount" xorm:"default 0.000000 DECIMAL(30,6)"` } diff --git a/consume/zhios_order_total_second.go b/consume/zhios_order_total_second.go index a4d0b0a..03a0fcc 100644 --- a/consume/zhios_order_total_second.go +++ b/consume/zhios_order_total_second.go @@ -95,6 +95,7 @@ func handleZhiosOrderTotalSecond(msg []byte) error { } now := time.Unix(int64(ordData.CreateAt), 0).Format("200601") + nowDay := time.Unix(int64(ordData.CreateAt), 0).Format("20060102") isTotal := ordData.IsTotal if ordData.OrderFormType >= 0 { if ordData.IsTotal == 1 && ordData.State != 4 { @@ -149,6 +150,41 @@ func handleZhiosOrderTotalSecond(msg []byte) error { sess.Rollback() return errors.New("失败") } + var userStatistics1 model.UserDayAmount + sess.Where("uid=? and date=?", v.Uid, nowDay).Get(&userStatistics1) + if userStatistics1.Id == 0 { + userStatistics1 = model.UserDayAmount{ + Date: utils.StrToInt(now), + Uid: v.Uid, + } + has, err := sess.Insert(&userStatistics1) + if err != nil { + sess.Rollback() + return err + } + if has == 0 { + sess.Rollback() + return errors.New("失败") + } + } + isupdate1 := 0 + if ordData.State == 4 && ordData.IsTotal == 1 { + isupdate1 = 1 + userStatistics1.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(userStatistics1.Amount)-v.Amount-utils.StrToFloat64(v.AdditionalSubsidy), 4) + } + if ordData.State != 4 && ordData.IsTotal == 0 { + isupdate1 = 1 + userStatistics1.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(userStatistics1.Amount)+v.Amount+utils.StrToFloat64(v.AdditionalSubsidy), 4) + } + update1, err1 := sess.Where("id=?", userStatistics1.Id).Cols("amount").Update(&userStatistics1) + if err1 != nil { + sess.Rollback() + return err + } + if update1 == 0 && isupdate1 == 1 { + sess.Rollback() + return errors.New("失败") + } } } } else {