Explorar el Código

test

tags/v4.3.1
huangjiajun hace 1 año
padre
commit
72bb9f9fa4
Se han modificado 1 ficheros con 21 adiciones y 15 borrados
  1. +21
    -15
      rule/self_buy_global.go

+ 21
- 15
rule/self_buy_global.go Ver fichero

@@ -36,28 +36,32 @@ func AddOrder(eg *xorm.Engine, req map[string]string) {
}
}

func Pool(eg *xorm.Engine, price string) {
func Pool(eg *xorm.Engine, price string) error {
if zhios_order_relate_utils.StrToFloat64(price) == 0 {
return
return errors.New("没有可分配金额")
}
session := eg.NewSession()
defer session.Close()
err := session.Begin()
if err != nil {
session.Rollback()
return
return err
}
//统计数量
//礼包的
sql := `SELECT SUM(sum) as sum,uid FROM mall_ord_capital_pool_total WHERE leave_price>0 and type=1 GROUP BY uid;`
nativeString, err := db.QueryNativeStringSess(session, sql)
if err != nil {
return
session.Rollback()

return err
}
sqlFirst := `SELECT uid FROM mall_ord_capital_pool_total WHERE type=0 GROUP BY uid;`
nativeStringFirst, errFirst := db.QueryNativeStringSess(session, sqlFirst)
if errFirst != nil {
return
session.Rollback()

return err
}
sum := 0
ids := make([]string, 0)
@@ -84,13 +88,13 @@ func Pool(eg *xorm.Engine, price string) {
err := eg.Where("uid=? and type=? and leave_price>?", v, 1, 0).Find(&data)
if err != nil {
session.Rollback()
return
return err
}
for _, v1 := range data {
leave, err = OneDoing(session, v1, oneMoney, leave)
if err != nil {
session.Rollback()
return
return err
}
}
//这里判断下有没有初始记录有金额 如果没有的话就进入损失金额
@@ -99,7 +103,7 @@ func Pool(eg *xorm.Engine, price string) {
has, err := session.Where("uid=? and type=? ", v, 0).Get(&oneData)
if err != nil {
session.Rollback()
return
return err
}
if has {
//先扣除 剩下的进损失
@@ -113,14 +117,14 @@ func Pool(eg *xorm.Engine, price string) {
update, err := session.Where("id=?", oneData.Id).Cols("leave_price").Update(&oneData)
if update == 0 || err != nil {
session.Rollback()
return
return err
}
}
//剩下的进损失
err = db.InsertCapitalPoolLossMoney(session, v, zhios_order_relate_utils.Float64ToStrByPrec(leave, 3), "分红损失", "0", "capital_pool")
if err != nil {
session.Rollback()
return
return err
}

leave = 0
@@ -138,13 +142,13 @@ func Pool(eg *xorm.Engine, price string) {
_, err := session.Where("uid=? and type=? ", v["uid"], 0).Get(&oneData)
if err != nil {
session.Rollback()
return
return err
}
//这里还能分
leave, err = OneDoing(session, oneData, oneMoney, leave)
if err != nil {
session.Rollback()
return
return err
}
} else {
//这里只需要判断要不要扣 多出的进入损失金额
@@ -153,7 +157,7 @@ func Pool(eg *xorm.Engine, price string) {
has, err := session.Where("uid=? and type=? ", v, 0).Get(&oneData)
if err != nil {
session.Rollback()
return
return err
}
if has {
//先扣除 剩下的进损失
@@ -167,7 +171,7 @@ func Pool(eg *xorm.Engine, price string) {
update, err := session.Where("id=?", oneData.Id).Cols("leave_price").Update(&oneData)
if update == 0 || err != nil {
session.Rollback()
return
return err
}
}
}
@@ -178,10 +182,12 @@ func Pool(eg *xorm.Engine, price string) {
err = db.InsertCapitalPoolLossMoney(session, v["uid"], zhios_order_relate_utils.Float64ToStrByPrec(leave, 3), "分红损失", "0", "capital_pool")
if err != nil {
session.Rollback()
return
return err
}
}
}
session.Commit()
return nil
}
func OneDoing(sess *xorm.Session, data model.MallOrdCapitalPoolTotal, oneMoney, leave float64) (float64, error) {
money := oneMoney + leave


Cargando…
Cancelar
Guardar