VoteController.php
2.1 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
class VoteController extends AdminBaseController{
//投票列表
public function voteList(){
$data = Db::name('vote') -> where('pid',0) -> select();
$this -> assign('data',$data);
return $this -> fetch();
}
//添加投票
public function voteadd(){
$title = input('post.title');
$options = input('post.xuan');
$radio = input('post.radio');
$option = explode(',', $options);
$arr['title'] = $title;
$arr['pid'] = 0;
$arr['radio'] = $radio;
$arr['time'] = date('y-m-d H:i:s');
$id = Db::name('vote') -> insertGetId($arr);
foreach ($option as $key => $value) {
$data['pid'] = $id;
$data['options'] = $value;
Db::name('vote') -> insert($data);
}
return $id;
}
//当点击编辑时
public function votebian(){
$id = input('post.id');
$data['title'] = Db::name('vote') -> where('id',$id) -> find();
$shuju = Db::name('vote') -> where('pid',$id) -> select();
$data['option'] = $shuju;
return json_encode($data);
}
//更新数据
public function voteupdate(){
$id = input('post.id');
$title = input('post.title');
$radio = input('post.radio');
$arr['id'] = $id;
$arr['title'] = $title;
$arr['radio'] = $radio;
$updata = Db::name('vote') -> update($arr);
$xid = input('post.xid');
$xshu = input('post.xshu');
$xid = explode(',',$xid);
$xshu = explode(',',$xshu);
foreach ($xid as $key => $value) {
Db::name('vote') -> where('id',$value) ->update(['options'=>$xshu[$key]]);
}
return true;
}
//删除数据
public function votedel(){
$id = input('post.id');
Db::name('vote') -> delete($id);
Db::name('vote') -> where('pid',$id) ->delete();
if($id){
return true;
}else{
return false;
}
}
//投票结果页
public function index(){
$data = Db::name('vote') -> where('id',0) -> select();
$this -> assign('data',$data);
return $this -> fetch();
}
}
?>