|
|
@@ -0,0 +1,58 @@ |
|
|
|
package svc |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/db" |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/md" |
|
|
|
zhios_day_luck_draw_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/utils" |
|
|
|
"encoding/json" |
|
|
|
"math/rand" |
|
|
|
"time" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
//随机几个用户 |
|
|
|
func RandUser(sess *xorm.Session) []string { |
|
|
|
var newOid = make([]string, 0) |
|
|
|
|
|
|
|
setting := db.GetDayLuckDrawSettingSess(sess) |
|
|
|
if setting == nil { |
|
|
|
return newOid |
|
|
|
} |
|
|
|
now := time.Now().Unix() |
|
|
|
if setting.IsUse == 0 || setting.StartTime.IsZero() || setting.EndTime.IsZero() || (now > setting.StartTime.Unix() && now < setting.EndTime.Unix()) { |
|
|
|
return newOid |
|
|
|
} |
|
|
|
count := 0 |
|
|
|
var rewardData = make([]md.RewardData, 0) |
|
|
|
err := json.Unmarshal([]byte(setting.RewardData), &rewardData) |
|
|
|
if err == nil { |
|
|
|
for _, v := range rewardData { |
|
|
|
count += zhios_day_luck_draw_utils.StrToInt(v.Num) |
|
|
|
} |
|
|
|
} |
|
|
|
if count > 0 { |
|
|
|
oids := db.GetAllOrderOid(sess) |
|
|
|
newOid = MicsSlice(oids, count) |
|
|
|
return newOid |
|
|
|
} |
|
|
|
return newOid |
|
|
|
|
|
|
|
} |
|
|
|
func MicsSlice(origin []string, count int) []string { |
|
|
|
tmpOrigin := make([]string, len(origin)) |
|
|
|
copy(tmpOrigin, origin) |
|
|
|
//一定要seed |
|
|
|
rand.Seed(time.Now().Unix()) |
|
|
|
rand.Shuffle(len(tmpOrigin), func(i int, j int) { |
|
|
|
tmpOrigin[i], tmpOrigin[j] = tmpOrigin[j], tmpOrigin[i] |
|
|
|
}) |
|
|
|
|
|
|
|
result := make([]string, 0, count) |
|
|
|
for index, value := range tmpOrigin { |
|
|
|
if index == count { |
|
|
|
break |
|
|
|
} |
|
|
|
result = append(result, value) |
|
|
|
} |
|
|
|
return result |
|
|
|
} |