VoteController.php
3.3 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?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);
}
$options=config('wechat_config');
$app = new Application($options);
$js = $app->js;
$jssdk=$js->config(array('onMenuShareAppMessage', 'onMenuShareTimeline','onMenuShareQQ'), false,false,true);
$this->assign('jssdk',$jssdk);
$url = "http://wangba.w.bronet.cn";
$this -> assign('url',$url);
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(){
$mid = cmf_get_current_user_id();
$id = input('post.id');
$tid = input('post.tid');
$tian['mid'] = $mid;
$tian['vid'] = $tid;
Db::name('mevo') -> insert($tian);
$data = Db::name('vote') -> where('id',$id) -> setInc('votes');
//投票优惠券
$uid = Db::name('members_user') -> where('uid',$mid) -> find();
$tpyh = Db::name('coupons') -> where('type',4) -> find();
$coupyh['uid'] = $uid['id'];
$coupyh['cid'] = $tpyh['id'];
$coupyh['state'] = 0;
$coupyh['code'] = date('md').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
Db::name('coupons_user') -> insert($coupyh);
if($data){
return false;
}else{
return true;
}
}
//多选增加票数
public function vshuang(){
$mid = cmf_get_current_user_id();
//投票优惠券
$uid = Db::name('members_user') -> where('uid',$mid) -> find();
$tpyh = Db::name('coupons') -> where('type',4) -> find();
$coupyh['uid'] = $uid['id'];
$coupyh['cid'] = $tpyh['id'];
$coupyh['state'] = 0;
$coupyh['code'] = date('md').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
Db::name('coupons_user') -> insert($coupyh);
$ids = explode(',', input('post.ids'));
foreach ($ids as $key => $value) {
Db::name('vote') -> where('id',$value) -> setInc('votes');
}
$tid = input('post.tid');
$data['mid'] = $mid;
$data['vid'] = $tid;
$pan = Db::name('mevo') -> insert($data);
if($pan){
return true;
}else{
return false;
}
}
}
?>