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 {