diff --git a/rule/self_buy_global.go b/rule/self_buy_global.go index fcf6c1b..529a256 100644 --- a/rule/self_buy_global.go +++ b/rule/self_buy_global.go @@ -78,7 +78,7 @@ func Pool(eg *xorm.Engine, price string) error { } //统计数量 //礼包的 - sql := `SELECT SUM(sum) 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 and type=1 GROUP BY uid;` nativeString, err := db.QueryNativeStringSess(session, sql) if err != nil { session.Rollback() @@ -107,6 +107,10 @@ func Pool(eg *xorm.Engine, price string) error { newIds = append(newIds, v["uid"]) } } + if sum == 0 { + session.Rollback() + return errors.New("没有分配份数") + } oneMoney := zhios_order_relate_utils.StrToFloat64(price) / float64(sum) //金额小的先扣 扣不完 给下一个 var userMap = make(map[string]float64) @@ -136,7 +140,7 @@ func Pool(eg *xorm.Engine, price string) error { session.Rollback() return err } - if has { + 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) @@ -157,7 +161,7 @@ func Pool(eg *xorm.Engine, price string) error { session.Rollback() return err } - + userSumMap[v] -= leave leave = 0 } userMap[v] = leave @@ -191,7 +195,7 @@ func Pool(eg *xorm.Engine, price string) error { session.Rollback() return err } - if has { + 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) @@ -215,10 +219,13 @@ func Pool(eg *xorm.Engine, price string) error { session.Rollback() return err } - userSumMap[v["uid"]] -= oneMoney + userSumMap[v["uid"]] -= leave } } for k, v := range userSumMap { + if v <= 0 { + continue + } bools := Finflow(session, k, v) if bools == false { session.Rollback() @@ -238,8 +245,10 @@ func Pool(eg *xorm.Engine, price string) error { } func OneDoing(sess *xorm.Session, data model.MallOrdCapitalPoolTotal, oneMoney, leave float64) (float64, error) { money := oneMoney + leave + if zhios_order_relate_utils.StrToFloat64(data.LeavePrice) <= 0 { + return money, nil + } if zhios_order_relate_utils.StrToFloat64(data.LeavePrice)-money < 0 { - money = zhios_order_relate_utils.StrToFloat64(data.LeavePrice) leave = money - zhios_order_relate_utils.StrToFloat64(data.LeavePrice) data.LeavePrice = "0" } else {