From 2739157c7f547cad71bc8cfc59e700e24d2335d0 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 9 May 2023 15:12:14 +0800 Subject: [PATCH] test --- db/db_mall_ord_capital_pool_total.go | 4 +- rule/self_buy_global.go | 68 +++++++++++++++++----------- 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/db/db_mall_ord_capital_pool_total.go b/db/db_mall_ord_capital_pool_total.go index 26966cb..5227d17 100644 --- a/db/db_mall_ord_capital_pool_total.go +++ b/db/db_mall_ord_capital_pool_total.go @@ -6,9 +6,9 @@ import ( "xorm.io/xorm" ) -func GetMaxPrice(eg *xorm.Engine, uid string, price float64) *model.MallOrdCapitalPoolTotal { +func GetMaxPrice(eg *xorm.Engine, uid string) *model.MallOrdCapitalPoolTotal { var data model.MallOrdCapitalPoolTotal - get, err := eg.Where("uid=? and type=? and other_price= minMoney { //如果超过了498 - leavePrice = sum - minMoney - if leavePrice > 0 { - getPrice(eg, req, minMoney, leavePrice) + max := db.GetMaxPrice(eg, req["uid"]) + if max != nil { + //判断之前剩下多少 + var leave float64 = 0 + onemoney := minMOney * capitalPoolMul + if zhios_order_relate_utils.StrToFloat64(max.OtherPrice) > 0 { + num := int(zhios_order_relate_utils.StrToFloat64(max.OtherPrice) / onemoney) + leave = zhios_order_relate_utils.StrToFloat64(max.OtherPrice) - onemoney*float64(num) } - leavePrice = minMoney - zhios_order_relate_utils.StrToFloat64(max.OtherPrice) - max.Num = 1 + nowMoney := leave + price*capitalPoolMul + nowNum := int(nowMoney / onemoney) + max.Num += nowNum + max.LeavePrice = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(max.LeavePrice)+zhios_order_relate_utils.StrToFloat64(req["price"]), 3) + max.OtherPrice = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(max.OtherPrice)+zhios_order_relate_utils.StrToFloat64(req["price"]), 3) + max.UpdateTime = time.Now() + eg.Where("id=?", max.Id).AllCols().Update(max) } - max.LeavePrice = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(max.LeavePrice)+leavePrice, 3) - max.OtherPrice = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(max.OtherPrice)+leavePrice, 3) - max.UpdateTime = time.Now() - eg.Where("id=?", max.Id).AllCols().Update(max) } + return } func Pool(eg *xorm.Engine, price string) error { if zhios_order_relate_utils.StrToFloat64(price) == 0 { return errors.New("没有可分配金额") } + ones, _ := db.SysCfgGetOne(eg, "capital_pool_mul") + minMOneyData, _ := db.SysCfgGetOne(eg, "capital_pool_min_money") + var capitalPoolMul float64 = 0 + var minMOney float64 = 498 + if ones != nil { + capitalPoolMul = zhios_order_relate_utils.StrToFloat64(ones.Val) + } + if minMOneyData != nil { + minMOney = zhios_order_relate_utils.StrToFloat64(minMOneyData.Val) + } session := eg.NewSession() defer session.Close() err := session.Begin() @@ -112,8 +118,8 @@ func Pool(eg *xorm.Engine, price string) error { return err } - sqlFirst := `SELECT uid FROM mall_ord_capital_pool_total WHERE 1=1 and num>0 GROUP BY uid;` - nativeStringFirst, errFirst := db.QueryNativeStringSess(session, sqlFirst) + sqlFirst := `SELECT uid FROM mall_ord_capital_pool_total WHERE 1=1 and (type=1 or other_price>=?) GROUP BY uid;` + nativeStringFirst, errFirst := db.QueryNativeStringSess(session, sqlFirst, capitalPoolMul*minMOney) if errFirst != nil { session.Rollback() @@ -152,8 +158,9 @@ func Pool(eg *xorm.Engine, price string) error { return err } for _, v1 := range data { - userSumMap[v] += oneMoney - leave, err = OneDoing(session, v1, oneMoney, leave) + onemoneydata := oneMoney * float64(v1.Num) + userSumMap[v] += onemoneydata + leave, err = OneDoing(session, v1, onemoneydata, leave, minMOney*capitalPoolMul) if err != nil { session.Rollback() return err @@ -208,7 +215,7 @@ func Pool(eg *xorm.Engine, price string) error { session.Commit() return nil } -func OneDoing(sess *xorm.Session, data model.MallOrdCapitalPoolTotal, oneMoney, leave float64) (float64, error) { +func OneDoing(sess *xorm.Session, data model.MallOrdCapitalPoolTotal, oneMoney, leave, minMoney float64) (float64, error) { money := oneMoney + leave if zhios_order_relate_utils.StrToFloat64(data.LeavePrice) <= 0 { return money, nil @@ -220,7 +227,14 @@ func OneDoing(sess *xorm.Session, data model.MallOrdCapitalPoolTotal, oneMoney, leave = 0 data.LeavePrice = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(data.LeavePrice)-money, 2) } - update, err := sess.Where("id=?", data.Id).Cols("leave_price").Update(&data) + //剩余有钱 并且是普通商品的 还有普通商品的金额大于最小分配金额 + if zhios_order_relate_utils.StrToFloat64(data.LeavePrice) > 0 && data.Type == 0 && zhios_order_relate_utils.StrToFloat64(data.OtherPrice) >= minMoney { + data.Num = int(zhios_order_relate_utils.StrToFloat64(data.LeavePrice) / minMoney) + if data.Num == 0 { + data.Num = 1 + } + } + update, err := sess.Where("id=?", data.Id).Cols("num,leave_price").Update(&data) if update == 0 || err != nil { return leave, errors.New("失败") }