|
|
@@ -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 { |
|
|
|