Browse Source

更新

tags/v4.3.1
huangjiajun 1 year ago
parent
commit
3f6a97a490
1 changed files with 27 additions and 80 deletions
  1. +27
    -80
      rule/self_buy_global.go

+ 27
- 80
rule/self_buy_global.go View File

@@ -12,12 +12,17 @@ import (
)

func AddOrder(eg *xorm.Engine, req map[string]string) {
max := db.GetMaxPrice(eg, req["uid"])
one, _ := db.SysCfgGetOne(eg, "capital_pool_mul")
minMOneyData, _ := db.SysCfgGetOne(eg, "capital_pool_min_money")
var capitalPoolMul float64 = 0
var minMOney float64 = 498
if one != nil {
capitalPoolMul = zhios_order_relate_utils.StrToFloat64(one.Val)
}
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++ {
@@ -33,13 +38,21 @@ func AddOrder(eg *xorm.Engine, req map[string]string) {
eg.Insert(data)
}
} else {
if max != nil {
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)
if price < minMOney {
return
}
var data = &model.MallOrdCapitalPoolTotal{
Uid: zhios_order_relate_utils.StrToInt(req["uid"]),
Price: req["price"],
LeavePrice: req["price"],
Num: 1,
UpdateTime: time.Now(),
Oid: req["oid"],
Type: 0,
}
eg.Insert(data)
}
return
}

func Pool(eg *xorm.Engine, price string) error {
@@ -84,14 +97,14 @@ func Pool(eg *xorm.Engine, price string) error {
}
//统计数量
//礼包的
sql := `SELECT SUM(num) as sum,uid FROM mall_ord_capital_pool_total WHERE leave_price>0 and type=1 GROUP BY uid;`
sql := `SELECT SUM(num) as sum,uid FROM mall_ord_capital_pool_total WHERE leave_price>0 GROUP BY uid;`
nativeString, err := db.QueryNativeStringSess(session, sql)
if err != nil {
session.Rollback()

return err
}
sqlFirst := `SELECT uid FROM mall_ord_capital_pool_total WHERE type=0 GROUP BY uid;`
sqlFirst := `SELECT uid FROM mall_ord_capital_pool_total WHERE 1=1 GROUP BY uid;`
nativeStringFirst, errFirst := db.QueryNativeStringSess(session, sqlFirst)
if errFirst != nil {
session.Rollback()
@@ -101,12 +114,12 @@ func Pool(eg *xorm.Engine, price string) error {
sum := 0
ids := make([]string, 0)
newIds := make([]string, 0)
//礼包的算份数
//有的分的算份数
for _, v := range nativeString {
sum += zhios_order_relate_utils.StrToInt(v["sum"])
ids = append(ids, v["uid"])
}
//非礼包的 站位
//没得分的 站位
for _, v := range nativeStringFirst {
if zhios_order_relate_utils.InArr(v["uid"], ids) == false || len(ids) == 0 {
sum += 1
@@ -125,7 +138,7 @@ func Pool(eg *xorm.Engine, price string) error {
//读取用户的记录
var leave float64 = 0
var data []model.MallOrdCapitalPoolTotal
err := session.Where("uid=? and type=? and leave_price>?", v, 1, 0).Find(&data)
err := session.Where("uid=? and leave_price>?", v, 0).Find(&data)
if err != nil {
session.Rollback()
return err
@@ -138,29 +151,8 @@ func Pool(eg *xorm.Engine, price string) error {
return err
}
}
//这里判断下有没有初始记录有金额 如果没有的话就进入损失金额
//剩下的都进损失了
if leave > 0 {
var oneData model.MallOrdCapitalPoolTotal
has, err := session.Where("uid=? and type=? ", v, 0).Get(&oneData)
if err != nil {
session.Rollback()
return err
}
if has && zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice) > 0 {
//先扣除 剩下的进损失
if zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice)-leave < 0 {
leave = leave - zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice)
oneData.LeavePrice = "0"
} else {
oneData.LeavePrice = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice)-leave, 2)
leave = 0
}
update, err := session.Where("id=?", oneData.Id).Cols("leave_price").Update(&oneData)
if update == 0 || err != nil {
session.Rollback()
return err
}
}
//剩下的进损失
err = db.InsertCapitalPoolLossMoney(session, v, zhios_order_relate_utils.Float64ToStrByPrec(leave, 3), "分红损失", "0", "capital_pool")
if err != nil {
@@ -173,59 +165,14 @@ func Pool(eg *xorm.Engine, price string) error {
userMap[v] = leave
}
for _, v := range nativeStringFirst {
var leave float64 = 0
money, ok := userMap[v["uid"]]
if ok {
leave = money
}
if zhios_order_relate_utils.InArr(v["uid"], ids) == false || len(ids) == 0 {
userSumMap[v["uid"]] += oneMoney
var oneData model.MallOrdCapitalPoolTotal
_, err := session.Where("uid=? and type=? ", v["uid"], 0).Get(&oneData)
if err != nil {
session.Rollback()
return err
}
//这里还能分
leave, err = OneDoing(session, oneData, oneMoney, leave)
if err != nil {
session.Rollback()
return err
}
} else {
//这里只需要判断要不要扣 多出的进入损失金额
if leave > 0 {
var oneData model.MallOrdCapitalPoolTotal
has, err := session.Where("uid=? and type=? ", v, 0).Get(&oneData)
if err != nil {
session.Rollback()
return err
}
if has && zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice) > 0 {
//先扣除 剩下的进损失
if zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice)-leave < 0 {
leave = leave - zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice)
oneData.LeavePrice = "0"
} else {
leave = 0
oneData.LeavePrice = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice)-leave, 2)
}
update, err := session.Where("id=?", oneData.Id).Cols("leave_price").Update(&oneData)
if update == 0 || err != nil {
session.Rollback()
return err
}
}
}
}
if leave > 0 {
var leave = oneMoney
if zhios_order_relate_utils.InArr(v["uid"], ids) == false || len(ids) == 0 { //这些都是没的分的就进损失
//剩下的进损失
err = db.InsertCapitalPoolLossMoney(session, v["uid"], zhios_order_relate_utils.Float64ToStrByPrec(leave, 3), "分红损失", "0", "capital_pool")
if err != nil {
session.Rollback()
return err
}
userSumMap[v["uid"]] -= leave
}
}
var RealBonusValue float64 = 0


Loading…
Cancel
Save