|
@@ -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 { |
|
|
if zhios_order_relate_utils.StrToFloat64(price) == 0 { |
|
|
return |
|
|
|
|
|
|
|
|
return errors.New("没有可分配金额") |
|
|
} |
|
|
} |
|
|
session := eg.NewSession() |
|
|
session := eg.NewSession() |
|
|
defer session.Close() |
|
|
defer session.Close() |
|
|
err := session.Begin() |
|
|
err := session.Begin() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
session.Rollback() |
|
|
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;` |
|
|
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) |
|
|
nativeString, err := db.QueryNativeStringSess(session, sql) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return |
|
|
|
|
|
|
|
|
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 type=0 GROUP BY uid;` |
|
|
nativeStringFirst, errFirst := db.QueryNativeStringSess(session, sqlFirst) |
|
|
nativeStringFirst, errFirst := db.QueryNativeStringSess(session, sqlFirst) |
|
|
if errFirst != nil { |
|
|
if errFirst != nil { |
|
|
return |
|
|
|
|
|
|
|
|
session.Rollback() |
|
|
|
|
|
|
|
|
|
|
|
return err |
|
|
} |
|
|
} |
|
|
sum := 0 |
|
|
sum := 0 |
|
|
ids := make([]string, 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) |
|
|
err := eg.Where("uid=? and type=? and leave_price>?", v, 1, 0).Find(&data) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
session.Rollback() |
|
|
session.Rollback() |
|
|
return |
|
|
|
|
|
|
|
|
return err |
|
|
} |
|
|
} |
|
|
for _, v1 := range data { |
|
|
for _, v1 := range data { |
|
|
leave, err = OneDoing(session, v1, oneMoney, leave) |
|
|
leave, err = OneDoing(session, v1, oneMoney, leave) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
session.Rollback() |
|
|
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) |
|
|
has, err := session.Where("uid=? and type=? ", v, 0).Get(&oneData) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
session.Rollback() |
|
|
session.Rollback() |
|
|
return |
|
|
|
|
|
|
|
|
return err |
|
|
} |
|
|
} |
|
|
if has { |
|
|
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) |
|
|
update, err := session.Where("id=?", oneData.Id).Cols("leave_price").Update(&oneData) |
|
|
if update == 0 || err != nil { |
|
|
if update == 0 || err != nil { |
|
|
session.Rollback() |
|
|
session.Rollback() |
|
|
return |
|
|
|
|
|
|
|
|
return err |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
//剩下的进损失 |
|
|
//剩下的进损失 |
|
|
err = db.InsertCapitalPoolLossMoney(session, v, zhios_order_relate_utils.Float64ToStrByPrec(leave, 3), "分红损失", "0", "capital_pool") |
|
|
err = db.InsertCapitalPoolLossMoney(session, v, zhios_order_relate_utils.Float64ToStrByPrec(leave, 3), "分红损失", "0", "capital_pool") |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
session.Rollback() |
|
|
session.Rollback() |
|
|
return |
|
|
|
|
|
|
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
leave = 0 |
|
|
leave = 0 |
|
@@ -138,13 +142,13 @@ func Pool(eg *xorm.Engine, price string) { |
|
|
_, err := session.Where("uid=? and type=? ", v["uid"], 0).Get(&oneData) |
|
|
_, err := session.Where("uid=? and type=? ", v["uid"], 0).Get(&oneData) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
session.Rollback() |
|
|
session.Rollback() |
|
|
return |
|
|
|
|
|
|
|
|
return err |
|
|
} |
|
|
} |
|
|
//这里还能分 |
|
|
//这里还能分 |
|
|
leave, err = OneDoing(session, oneData, oneMoney, leave) |
|
|
leave, err = OneDoing(session, oneData, oneMoney, leave) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
session.Rollback() |
|
|
session.Rollback() |
|
|
return |
|
|
|
|
|
|
|
|
return err |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
//这里只需要判断要不要扣 多出的进入损失金额 |
|
|
//这里只需要判断要不要扣 多出的进入损失金额 |
|
@@ -153,7 +157,7 @@ func Pool(eg *xorm.Engine, price string) { |
|
|
has, err := session.Where("uid=? and type=? ", v, 0).Get(&oneData) |
|
|
has, err := session.Where("uid=? and type=? ", v, 0).Get(&oneData) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
session.Rollback() |
|
|
session.Rollback() |
|
|
return |
|
|
|
|
|
|
|
|
return err |
|
|
} |
|
|
} |
|
|
if has { |
|
|
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) |
|
|
update, err := session.Where("id=?", oneData.Id).Cols("leave_price").Update(&oneData) |
|
|
if update == 0 || err != nil { |
|
|
if update == 0 || err != nil { |
|
|
session.Rollback() |
|
|
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") |
|
|
err = db.InsertCapitalPoolLossMoney(session, v["uid"], zhios_order_relate_utils.Float64ToStrByPrec(leave, 3), "分红损失", "0", "capital_pool") |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
session.Rollback() |
|
|
session.Rollback() |
|
|
return |
|
|
|
|
|
|
|
|
return err |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
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 float64) (float64, error) { |
|
|
money := oneMoney + leave |
|
|
money := oneMoney + leave |
|
|