diff --git a/db/db_day_luck_draw_order_jackpot.go b/db/db_day_luck_draw_order_jackpot.go index c97e3bd..42aa913 100644 --- a/db/db_day_luck_draw_order_jackpot.go +++ b/db/db_day_luck_draw_order_jackpot.go @@ -29,7 +29,13 @@ func AddOrderJackpot(eg *xorm.Engine, req md.DayLuckDrawOrderJackpotReq) error { } return nil } - +func GetOrderJackpotCount(sess *xorm.Session, period string) int64 { + if period == "0" || zhios_day_luck_draw_utils.StrToInt(period) > 0 { + sess.Where("period=?", period) + } + sum, _ := sess.Count(&model.DayLuckDrawOrderJackpot{}) + return sum +} func GetAllOrderOid(sess *xorm.Session) []string { sql := `SELECT oid,uid FROM day_luck_draw_order_jackpot where period=0;` @@ -37,7 +43,7 @@ func GetAllOrderOid(sess *xorm.Session) []string { var list = make([]string, 0) if len(data) > 0 { for _, v := range data { - list = append(list, v["uid"]) + list = append(list, v["oid"]+"_"+v["uid"]) } } return list diff --git a/db/db_day_luck_draw_settle_order.go b/db/db_day_luck_draw_settle_order.go index 9ba4513..e5df648 100644 --- a/db/db_day_luck_draw_settle_order.go +++ b/db/db_day_luck_draw_settle_order.go @@ -9,8 +9,11 @@ import ( "xorm.io/xorm" ) -func GetSettleAllOrderSum(sess *xorm.Session) float64 { - sum, _ := sess.Where("is_send=0").Sum(&model.DayLuckDrawSettleOrder{}, "commission") +func GetSettleAllOrderSum(sess *xorm.Session, isSend string) float64 { + if isSend == "0" || isSend == "1" { + sess.Where("is_send=?", isSend) + } + sum, _ := sess.Sum(&model.DayLuckDrawSettleOrder{}, "commission") return sum } diff --git a/db/model/day_luck_draw_period.go b/db/model/day_luck_draw_period.go index 1465eeb..e1426fa 100644 --- a/db/model/day_luck_draw_period.go +++ b/db/model/day_luck_draw_period.go @@ -10,4 +10,5 @@ type DayLuckDrawPeriod struct { Base string `json:"base" xorm:"TEXT"` CreateTime time.Time `json:"create_time" xorm:"DATETIME"` Period int `json:"period" xorm:"default 0 INT(11)"` + Data string `json:"data" xorm:"TEXT"` } diff --git a/svc/svc_day_luck_draw_reward.go b/svc/svc_day_luck_draw_reward.go index a2df61a..fd719b1 100644 --- a/svc/svc_day_luck_draw_reward.go +++ b/svc/svc_day_luck_draw_reward.go @@ -11,6 +11,7 @@ import ( "fmt" "github.com/shopspring/decimal" "math/rand" + "strings" "time" "xorm.io/xorm" ) @@ -24,7 +25,8 @@ func InitForDayLuckDraw(redisAddr string) (err error) { } //随机几个用户 -func RandUser(sess *xorm.Session, setting *model.DayLuckDrawSetting) []string { +func RandUser(sess *xorm.Session, setting *model.DayLuckDrawSetting) ([]string, []string) { + var newUid = make([]string, 0) var newOid = make([]string, 0) count := 0 var rewardData = make([]md.RewardData, 0) @@ -36,10 +38,10 @@ func RandUser(sess *xorm.Session, setting *model.DayLuckDrawSetting) []string { } if count > 0 { oids := db.GetAllOrderOid(sess) - newOid = MicsSlice(oids, count) - return newOid + newUid, newOid = MicsSlice(oids, count) + return newUid, newOid } - return newOid + return newUid, newOid } @@ -110,7 +112,7 @@ func GetUserReward(eg *xorm.Engine, mid string, isTask bool) error { } //设置期数 max := db.GetPeriodMax(sess) - sum := db.GetSettleAllOrderSum(sess) + sum := db.GetSettleAllOrderSum(sess, "0") if setting.Source == "amount" { sum = zhios_day_luck_draw_utils.StrToFloat64(setting.Amount) } else { @@ -144,7 +146,7 @@ func GetUserReward(eg *xorm.Engine, mid string, isTask bool) error { for _, v := range rewardData { rewardDataMap[zhios_day_luck_draw_utils.StrToInt64(v.Key)] = zhios_day_luck_draw_utils.StrToInt(v.Num) } - uids := RandUser(sess, setting) + uids, oids := RandUser(sess, setting) var award = make(map[string]int64) var awardIdMap = make(map[int64]int) for _, v := range uids { @@ -216,6 +218,12 @@ func GetUserReward(eg *xorm.Engine, mid string, isTask bool) error { sess.Rollback() return errors.New("失败") } + oidsStr, _ := json.Marshal(oids) + update3, err3 := sess.Where("period=?", period).Cols("data").Update(&model.DayLuckDrawPeriod{Data: string(oidsStr)}) + if err3 != nil || update3 == 0 { + sess.Rollback() + return errors.New("失败") + } sess.Commit() return nil } @@ -263,7 +271,7 @@ func AwardRandomNumberFor100000() int { return num } -func MicsSlice(origin []string, count int) []string { +func MicsSlice(origin []string, count int) ([]string, []string) { tmpOrigin := make([]string, len(origin)) copy(tmpOrigin, origin) //一定要seed @@ -273,16 +281,22 @@ func MicsSlice(origin []string, count int) []string { }) result := make([]string, 0) + oids := make([]string, 0) for _, value := range tmpOrigin { if len(result) == count { break } - if zhios_day_luck_draw_utils.InArr(value, result) { - continue + split := strings.Split(value, "_") + if len(split) == 2 { + if zhios_day_luck_draw_utils.InArr(split[1], result) { + continue + } + result = append(result, split[1]) + oids = append(oids, split[0]) } - result = append(result, value) + } - return result + return result, oids } func SetAllAwardsProbability(sess *xorm.Session, mid string) error {