From 7083d727d4dbb6fba7cd1d456f8ffc39cb0efbed Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Mon, 27 May 2024 16:49:50 +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/dbs_order.go | 2 +- app/db/model/user_day_amount.go | 8 +++ app/db/model/user_month_amount.go | 11 +++ app/svc/svc_order_return_money_save.go | 96 ++++++++++++++++++++++++++ app/svc/svc_order_track_save.go | 47 +++++++++++++ 5 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 app/db/model/user_day_amount.go create mode 100644 app/db/model/user_month_amount.go diff --git a/app/db/dbs_order.go b/app/db/dbs_order.go index 3c7b063..7f54aec 100644 --- a/app/db/dbs_order.go +++ b/app/db/dbs_order.go @@ -49,7 +49,7 @@ func DbsOrderFindById(eg *xorm.Engine, pvd string, ids string) (*model.OrdList, } func DbsOrderUpdate(eg *xorm.Engine, id int64, ord *model.OrdList) error { - if _, err := eg.Where("`ord_id` = ?", id).Cols("parent_ord_id,order_compare,state,paid_price,confirm_at,check_success_at,update_at,pvd_settle_at").Update(ord); err != nil { + if _, err := eg.Where("`ord_id` = ?", id).Cols("parent_ord_id,reason,order_compare,state,paid_price,confirm_at,check_success_at,update_at,pvd_settle_at").Update(ord); err != nil { return logx.Warn(err) } return nil 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 new file mode 100644 index 0000000..7d2ff1d --- /dev/null +++ b/app/db/model/user_month_amount.go @@ -0,0 +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)"` + 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/app/svc/svc_order_return_money_save.go b/app/svc/svc_order_return_money_save.go index f2bd98f..dad363c 100644 --- a/app/svc/svc_order_return_money_save.go +++ b/app/svc/svc_order_return_money_save.go @@ -17,6 +17,54 @@ func OrderReturnMoneyRelateInsert(eg *xorm.Engine, oid int64, pvd string, create return } if isDelete { + if newOrd.IsTotal == 1 { + var ordRelate = make([]model.OrdListRelate, 0) + eg.Where("oid=?", newOrd.OrdId).Find(&ordRelate) + now := time.Unix(int64(newOrd.CreateAt), 0).Format("200601") + nowDay := time.Unix(int64(newOrd.CreateAt), 0).Format("20060102") + if len(ordRelate) > 0 { + isDeduct := 0 + for _, v := range ordRelate { + if v.Amount == 0 && utils.StrToFloat64(v.AdditionalSubsidy) == 0 { + continue + } + var userStatistics model.UserMonthAmount + eg.Where("uid=? and date=?", v.Uid, now).Get(&userStatistics) + if userStatistics.Id != 0 { + userStatistics.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(userStatistics.Amount)-v.Amount-utils.StrToFloat64(v.AdditionalSubsidy), 4) + eg.Where("id=?", userStatistics.Id).Cols("amount").Update(&userStatistics) + } + if v.CreateAt > 1711086661 { + var userStatistics1 model.UserDayAmount + eg.Where("uid=? and date=?", v.Uid, nowDay).Get(&userStatistics1) + if userStatistics1.Id != 0 { + userStatistics1 = model.UserDayAmount{ + Date: utils.StrToInt(nowDay), + Uid: v.Uid, + } + userStatistics1.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(userStatistics1.Amount)-v.Amount-utils.StrToFloat64(v.AdditionalSubsidy), 4) + eg.Where("id=?", userStatistics1.Id).Cols("amount").Update(&userStatistics1) + } + } + var userStatistics1 model.UserWaitAmount + eg.Where("uid=? ", v.Uid).Get(&userStatistics1) + if userStatistics1.Id != 0 { + userStatistics1.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(userStatistics1.Amount)-v.Amount-utils.StrToFloat64(v.AdditionalSubsidy), 4) + eg.Where("id=?", userStatistics1.Id).Cols("amount").Update(&userStatistics1) + } + isDeduct = 1 + } + if isDeduct == 1 { + if newOrd.State == 4 { + newOrd.IsTotal = 2 + } else { + newOrd.IsTotal = 0 + } + eg.Where("pvd_oid=?", newOrd.PvdOid).Cols("is_total").Update(newOrd) + } + } + } + fmt.Println("=====================写入明细2", newOrd.PvdOid) if newOrd.ReturnMoneySettleAt > 0 { db.OrderRelateDeleteByOidbylevel(eg, oid, pvd) @@ -101,6 +149,54 @@ func PlayLetOrderReturnMoneyRelateInsert(eg *xorm.Engine, oid int64, pvd string, return } if isDelete { + if newOrd.IsTotal == 1 { + var ordRelate = make([]model.OrdListRelate, 0) + eg.Where("oid=?", newOrd.OrdId).Find(&ordRelate) + now := time.Unix(int64(newOrd.CreateAt), 0).Format("200601") + nowDay := time.Unix(int64(newOrd.CreateAt), 0).Format("20060102") + if len(ordRelate) > 0 { + isDeduct := 0 + for _, v := range ordRelate { + if v.Amount == 0 && utils.StrToFloat64(v.AdditionalSubsidy) == 0 { + continue + } + var userStatistics model.UserMonthAmount + eg.Where("uid=? and date=?", v.Uid, now).Get(&userStatistics) + if userStatistics.Id != 0 { + userStatistics.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(userStatistics.Amount)-v.Amount-utils.StrToFloat64(v.AdditionalSubsidy), 4) + eg.Where("id=?", userStatistics.Id).Cols("amount").Update(&userStatistics) + } + if v.CreateAt > 1711086661 { + var userStatistics1 model.UserDayAmount + eg.Where("uid=? and date=?", v.Uid, nowDay).Get(&userStatistics1) + if userStatistics1.Id != 0 { + userStatistics1 = model.UserDayAmount{ + Date: utils.StrToInt(nowDay), + Uid: v.Uid, + } + userStatistics1.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(userStatistics1.Amount)-v.Amount-utils.StrToFloat64(v.AdditionalSubsidy), 4) + eg.Where("id=?", userStatistics1.Id).Cols("amount").Update(&userStatistics1) + } + } + var userStatistics1 model.UserWaitAmount + eg.Where("uid=? ", v.Uid).Get(&userStatistics1) + if userStatistics1.Id != 0 { + userStatistics1.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(userStatistics1.Amount)-v.Amount-utils.StrToFloat64(v.AdditionalSubsidy), 4) + eg.Where("id=?", userStatistics1.Id).Cols("amount").Update(&userStatistics1) + } + isDeduct = 1 + } + if isDeduct == 1 { + if newOrd.State == 4 { + newOrd.IsTotal = 2 + } else { + newOrd.IsTotal = 0 + } + eg.Where("pvd_oid=?", newOrd.PvdOid).Cols("is_total").Update(newOrd) + } + } + } + fmt.Println("=====================写入明细2", newOrd.PvdOid) if newOrd.ReturnMoneySettleAt > 0 { db.OrderRelateDeleteByOidbylevel(eg, oid, pvd) diff --git a/app/svc/svc_order_track_save.go b/app/svc/svc_order_track_save.go index 244611d..8539a53 100644 --- a/app/svc/svc_order_track_save.go +++ b/app/svc/svc_order_track_save.go @@ -439,6 +439,53 @@ func OrderRelateInsert(eg *xorm.Engine, oid int64, pvd string, createTime int, l fmt.Println(isDelete) //先删掉 if isDelete { + if newOrd.IsTotal == 1 { + var ordRelate = make([]model.OrdListRelate, 0) + eg.Where("oid=?", newOrd.OrdId).Find(&ordRelate) + now := time.Unix(int64(newOrd.CreateAt), 0).Format("200601") + nowDay := time.Unix(int64(newOrd.CreateAt), 0).Format("20060102") + if len(ordRelate) > 0 { + isDeduct := 0 + for _, v := range ordRelate { + if v.Amount == 0 && utils.StrToFloat64(v.AdditionalSubsidy) == 0 { + continue + } + var userStatistics model.UserMonthAmount + eg.Where("uid=? and date=?", v.Uid, now).Get(&userStatistics) + if userStatistics.Id != 0 { + userStatistics.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(userStatistics.Amount)-v.Amount-utils.StrToFloat64(v.AdditionalSubsidy), 4) + eg.Where("id=?", userStatistics.Id).Cols("amount").Update(&userStatistics) + } + if v.CreateAt > 1711086661 { + var userStatistics1 model.UserDayAmount + eg.Where("uid=? and date=?", v.Uid, nowDay).Get(&userStatistics1) + if userStatistics1.Id != 0 { + userStatistics1 = model.UserDayAmount{ + Date: utils.StrToInt(nowDay), + Uid: v.Uid, + } + userStatistics1.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(userStatistics1.Amount)-v.Amount-utils.StrToFloat64(v.AdditionalSubsidy), 4) + eg.Where("id=?", userStatistics1.Id).Cols("amount").Update(&userStatistics1) + } + } + var userStatistics1 model.UserWaitAmount + eg.Where("uid=? ", v.Uid).Get(&userStatistics1) + if userStatistics1.Id != 0 { + userStatistics1.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(userStatistics1.Amount)-v.Amount-utils.StrToFloat64(v.AdditionalSubsidy), 4) + eg.Where("id=?", userStatistics1.Id).Cols("amount").Update(&userStatistics1) + } + isDeduct = 1 + } + if isDeduct == 1 { + if newOrd.State == 4 { + newOrd.IsTotal = 2 + } else { + newOrd.IsTotal = 0 + } + eg.Where("pvd_oid=?", newOrd.PvdOid).Cols("is_total").Update(newOrd) + } + } + } fmt.Println("=====================写入明细2", newOrd.PvdOid) if pvd == md.PVD_JDOwn { db.OrderRelateDeleteByOid(eg, oid, md.PVD_JD)