apicp.ItemVote.php
1.41 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
48
49
50
51
52
53
54
<?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();
$sql = "SELECT `value` from `setting` WHERE `key` = 'isStartVote' AND `value` = 1;";
$data = $mysql->fetch($sql);
if (empty($data)) {
JsonResponse::error('等候主持人宣布开启投票通道');
}
if(!isset($_POST['user_id'])){
JsonResponse::error('userID参数不能为空');
}
if(!isset($_POST['item_ids'])){
JsonResponse::error('请选择投票节目Id');
}
$item_ids = explode(',',$_POST['item_ids']);
if(count($item_ids) > 5){
JsonResponse::error('最多可以票选5个优秀节目');
}
$user_id = $_POST['user_id'];
// 查询用户是否投过票了
$userItemVoteInfo = $mysql->fetch("SELECT id FROM item_vote WHERE user_id = ?", [ $user_id ]);
if(!empty($userItemVoteInfo)){
JsonResponse::error('您已经投过票了不可再重复操作');
}
foreach ($item_ids as $item_id){
$mysql->insert('item_vote',['item_id' => $item_id, 'user_id' => $user_id ]);
}
// 返回桌位列表
JsonResponse::result([]);