Browse Source

test

tags/v4.3.1
huangjiajun 1 year ago
parent
commit
2739157c7f
2 changed files with 43 additions and 29 deletions
  1. +2
    -2
      db/db_mall_ord_capital_pool_total.go
  2. +41
    -27
      rule/self_buy_global.go

+ 2
- 2
db/db_mall_ord_capital_pool_total.go View File

@@ -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<?", uid, 0, price).Get(&data)
get, err := eg.Where("uid=? and type=?", uid, 0).Get(&data)
if err != nil {
return nil
}


+ 41
- 27
rule/self_buy_global.go View File

@@ -22,6 +22,7 @@ func AddOrder(eg *xorm.Engine, req map[string]string) {
if minMOneyData != nil {
minMOney = zhios_order_relate_utils.StrToFloat64(minMOneyData.Val)
}
price := zhios_order_relate_utils.StrToFloat64(req["price"])
req["price"] = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(req["price"])*capitalPoolMul, 2)
if req["type"] == "mall_goods_user_lv" {
for i := 0; i < zhios_order_relate_utils.StrToInt(req["num"]); i++ {
@@ -37,36 +38,41 @@ func AddOrder(eg *xorm.Engine, req map[string]string) {
eg.Insert(data)
}
} else {
getPrice(eg, req, minMOney*capitalPoolMul, zhios_order_relate_utils.StrToFloat64(req["price"]))
}
return
}
func getPrice(eg *xorm.Engine, req map[string]string, minMoney float64, leavePrice float64) {
if leavePrice <= 0 {
return
}
max := db.GetMaxPrice(eg, req["uid"], minMoney)
if max != nil {
sum := zhios_order_relate_utils.StrToFloat64(max.OtherPrice) + leavePrice
if sum >= 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("失败")
}


Loading…
Cancel
Save