apicp.UserList.php
1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* 跨域处理
*/
header('Access-Control-Allow-Origin:*');
header("Access-Control-Allow-Methods:GET,POST");
/**
* 返回随机用户列表
*/
include "Common/JsonResponse.php";
include "Common/mysqlHelper.php";
include "Common/WechatHelper.php";
include "Common/Encrypter.php";
$mysql = new mysqlHelper();
$userList = $mysql->fetchAll("SELECT id,realname,headimg,prize_no FROM user WHERE status = 1 AND headimg <> ''");
// 查询已中奖用户
$lotteryUserIds = [];
$lotteryUser = $mysql->fetchAll("SELECT user_id FROM lottery ");
if(!empty($lotteryUser)){
$lotteryUserIds = array_column($lotteryUser,'user_id');
}
// 去除已中奖用户
foreach ($userList as $key => &$value){
$value['id'] = (int)$value['id'];
if(in_array($value['id'],$lotteryUserIds)){
unset($userList[$key]);
}
}
$userList = array_values($userList);
// 将用户排序进行两次打乱
shuffle($userList);
shuffle($userList);
$res = [
'data' => $userList
];
// 返回桌位列表
JsonResponse::result($res);