VoteController.php
1.6 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
<?php
namespace app\portal\controller;
use cmf\controller\WeChatBaseController;
use EasyWeChat\Foundation\Application;
use EasyWeChat\Payment\Order;
use think\Db;
class VoteController extends WeChatBaseController{
//显示投票页
public function index(){
$mid = cmf_get_current_user_id();
$data = Db::name('mevo') -> alias('a') -> join('vote b','a.vid=b.id','LEFT') -> where('a.mid',$mid) -> select() ;
$coun = count($data);
if($coun == 0){
$shuju = Db::name('vote') -> where('pid',0) -> select();
$this -> assign('shuju',$shuju);
$this -> assign('canyu','');
$this -> assign('weican','');
}else{
$this -> assign('canyu',$data);
$this -> assign('shuju','');
foreach ($data as $key => $value) {
$arr[] = $value['id'];
}
$shuju = Db::name('vote') -> where('pid',0) -> select();
foreach ($shuju as $key => $value) {
if(in_array($value['id'],$arr )){
unset($shuju[$key]);
}
}
$this -> assign('weican',$shuju);
}
return $this -> fetch();
}
//投票内容显示页
public function showVote(){
$id= $this -> request -> param();
$title = Db::name('vote') -> where('id',$id['id']) -> find();
$xuan = Db::name('vote') -> where('pid',$id['id']) -> select();
$this -> assign('title',$title);
$this -> assign('xuan',$xuan);
return $this -> fetch();
}
//单选添加票数
public function vdan(){
$id = input('post.id');
$data = Db::name('vote') -> where('id',$id) -> setInc('votes');
if($data){
return false;
}else{
return true;
}
}
}
?>