|
@@ -22,6 +22,7 @@ func AddOrder(eg *xorm.Engine, req map[string]string) { |
|
|
if minMOneyData != nil { |
|
|
if minMOneyData != nil { |
|
|
minMOney = zhios_order_relate_utils.StrToFloat64(minMOneyData.Val) |
|
|
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) |
|
|
req["price"] = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(req["price"])*capitalPoolMul, 2) |
|
|
if req["type"] == "mall_goods_user_lv" { |
|
|
if req["type"] == "mall_goods_user_lv" { |
|
|
for i := 0; i < zhios_order_relate_utils.StrToInt(req["num"]); i++ { |
|
|
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) |
|
|
eg.Insert(data) |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} 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 { |
|
|
func Pool(eg *xorm.Engine, price string) error { |
|
|
if zhios_order_relate_utils.StrToFloat64(price) == 0 { |
|
|
if zhios_order_relate_utils.StrToFloat64(price) == 0 { |
|
|
return errors.New("没有可分配金额") |
|
|
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() |
|
|
session := eg.NewSession() |
|
|
defer session.Close() |
|
|
defer session.Close() |
|
|
err := session.Begin() |
|
|
err := session.Begin() |
|
@@ -112,8 +118,8 @@ func Pool(eg *xorm.Engine, price string) error { |
|
|
|
|
|
|
|
|
return err |
|
|
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 { |
|
|
if errFirst != nil { |
|
|
session.Rollback() |
|
|
session.Rollback() |
|
|
|
|
|
|
|
@@ -152,8 +158,9 @@ func Pool(eg *xorm.Engine, price string) error { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
for _, v1 := range data { |
|
|
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 { |
|
|
if err != nil { |
|
|
session.Rollback() |
|
|
session.Rollback() |
|
|
return err |
|
|
return err |
|
@@ -208,7 +215,7 @@ func Pool(eg *xorm.Engine, price string) error { |
|
|
session.Commit() |
|
|
session.Commit() |
|
|
return nil |
|
|
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 |
|
|
money := oneMoney + leave |
|
|
if zhios_order_relate_utils.StrToFloat64(data.LeavePrice) <= 0 { |
|
|
if zhios_order_relate_utils.StrToFloat64(data.LeavePrice) <= 0 { |
|
|
return money, nil |
|
|
return money, nil |
|
@@ -220,7 +227,14 @@ func OneDoing(sess *xorm.Session, data model.MallOrdCapitalPoolTotal, oneMoney, |
|
|
leave = 0 |
|
|
leave = 0 |
|
|
data.LeavePrice = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(data.LeavePrice)-money, 2) |
|
|
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 { |
|
|
if update == 0 || err != nil { |
|
|
return leave, errors.New("失败") |
|
|
return leave, errors.New("失败") |
|
|
} |
|
|
} |
|
|