site.php
9.52 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
defined('IN_IA') or exit('Access Denied');
class We7_shakeModuleSite extends WeModuleSite {
public function doMobileWelcome() {
global $_W, $_GPC;
checkauth();
$rid = intval($_GPC['rid']);
$reply = pdo_fetch("SELECT * FROM " . tablename('shake_reply') . " WHERE rid = :rid", array(':rid' => $rid));
if (empty($reply)) {
message('抱歉,此活动不存在或是还未开始!', 'refresh', 'error');
}
load()->model('mc');
$profile = mc_fetch($_W['member']['uid'], array('realname', 'mobile', 'avatar'));
if (empty($profile['avatar'])) {
mc_oauth_userinfo();
}
if (empty($profile['realname']) || empty($profile['mobile'])) {
mc_require($_W['member']['uid'], array('realname', 'mobile'));
}
$member = pdo_fetch("SELECT * FROM " . tablename('shake_member') . " WHERE rid = :rid AND openid = :openid", array(':rid' => $reply['rid'], ':openid' => $_W['member']['uid']));
if (!empty($member)) {
header('Location: '.$this->createMobileUrl('detail', array('rid' => $reply['rid'])));
exit;
}
$reply['rule'] = html_entity_decode($reply['rule']);
include $this->template('welcome');
}
public function doMobileDetail() {
global $_W, $_GPC;
checkauth();
$rid = intval($_GPC['rid']);
$reply = pdo_fetch("SELECT * FROM " . tablename('shake_reply') . " WHERE rid = :rid", array(':rid' => $rid));
if (empty($reply)) {
message('抱歉,此活动不存在或是还未开始!', 'refresh', 'error');
}
$member = pdo_fetch("SELECT * FROM " . tablename('shake_member') . " WHERE rid = :rid AND openid = :openid", array(':rid' => $reply['rid'], ':openid' => $_W['member']['uid']));
if (empty($member)) {
$member = array(
'rid' => $rid,
'openid' => $_W['member']['uid'],
'createtime' => TIMESTAMP,
'shakecount' => 0,
'status' => 0,
);
$maxjoin = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('shake_member')." WHERE rid = '{$reply['rid']}' AND status = '1'");
if ($maxjoin < $reply['maxjoin']) {
mt_srand((double) microtime()*1000000);
$rand = mt_rand(1, 100);
if ($rand <= $reply['joinprobability']) {
$member['status'] = 1;
}
}
pdo_insert('shake_member', $member);
}
if (strexists(strtolower($_SERVER['HTTP_USER_AGENT']), 'android')) {
$reply['speed'] = $reply['speedandroid'];
}
include $this->template('detail');
}
public function doMobileShake() {
global $_W, $_GPC;
$rid = $_GPC['rid'];
$reply = pdo_fetch("SELECT * FROM " . tablename('shake_reply') . " WHERE rid = :rid AND status = 1", array(':rid' => $rid));
if (empty($reply)) {
message(array('status' => 0), '', 'ajax');
}
$maxshakecount = pdo_fetchcolumn("SELECT max(shakecount) FROM " . tablename('shake_member') . " WHERE rid = :rid", array(':rid' => $rid));
if ($maxshakecount >= $reply['maxshake']) {
pdo_update('shake_reply', array('status' => 2), array('rid' => $rid));
message(array('status' => 2), '', 'ajax');
} else {
pdo_query("UPDATE " . tablename('shake_member') . " SET shakecount = shakecount + 1, lastupdate = '" . TIMESTAMP . "' WHERE openid = :openid AND rid = :rid", array(':rid' => $rid, ':openid' => $_W['member']['uid']));
$member = pdo_fetch("SELECT * FROM " . tablename('shake_member') . " WHERE rid = :rid AND openid = :openid", array(':rid' => $rid, ':openid' => $_W['member']['uid']));
message(array('status' => 1, 'shakecount' => $member['shakecount'], 'lastupdate' => $member['lastupdate']), '', 'ajax');
}
}
public function doWebDetail() {
global $_W, $_GPC;
checklogin();
$id = intval($_GPC['id']);
$reply = pdo_fetch("SELECT * FROM " . tablename('shake_reply') . " WHERE rid = :id", array(':id' => $id));
if (empty($reply)) {
message('抱歉,此活动不存在或是还未开始!', 'refresh', 'error');
}
load()->model('mc');
if (empty($reply['status'])) {
$list = pdo_fetchall("SELECT openid, shakecount FROM " . tablename('shake_member') . " WHERE rid = :rid ORDER BY id ASC", array(':rid' => $reply['rid']), 'openid');
$total = count($list);
$fans = mc_fetch(array_keys($list), array('realname', 'mobile', 'avatar'));
$lastupdatetime = pdo_fetchcolumn("SELECT createtime FROM " . tablename('shake_member') . " WHERE rid = :rid ORDER BY createtime DESC LIMIT 1", array(':rid' => $reply['rid']));
} else {
$reply['rule'] = htmlspecialchars_decode($reply['rule']);
$limit = empty($reply['maxwinner']) ? 10 : $reply['maxwinner'];
$list = pdo_fetchall("SELECT openid, shakecount FROM " . tablename('shake_member') . " WHERE rid = :rid ORDER BY shakecount DESC LIMIT $limit", array(':rid' => $reply['rid']), 'openid');
$fans = mc_fetch(array_keys($list), array('realname', 'mobile', 'avatar', 'nickname'));
}
$reply['keyword'] = pdo_fetchall("SELECT content FROM " . tablename('rule_keyword') . " WHERE rid = '{$reply['rid']}'");
include $this->template('detail');
}
public function doWebGetRank() {
global $_GPC, $_W;
load()->model('mc');
checklogin();
$result = array('status' => 0, 'message' => '');
$id = intval($_GPC['id']);
$reply = pdo_fetch("SELECT * FROM " . tablename('shake_reply') . " WHERE id = :id", array(':id' => $id));
if (empty($reply['status'])) {
$result['message'] = '活动还未开始!';
message($result, $this->createWebUrl('detail', array('id' => $reply['rid'], 'weid' => $_W['uniacid'], 'status' => 0)), 'ajax');
}
if ($reply['status'] == 2) {
$result['status'] = 2;
$result['message'] = '活动已经结束!';
message($result, $this->createWebUrl('detail', array('id' => $reply['rid'], 'weid' => $_W['uniacid'])), 'ajax');
}
$limit = empty($reply['maxwinner']) ? 10 : $reply['maxwinner'];
$result['message'] = pdo_fetchall("SELECT openid, shakecount FROM " . tablename('shake_member') . " WHERE rid = :rid ORDER BY shakecount DESC LIMIT $limit", array(':rid' => $reply['rid']));
$result['status'] = 1;
message($result, '', 'ajax');
}
public function doWebGetJoin() {
global $_W, $_GPC;
load()->model('mc');
$rid = intval($_GPC['rid']);
$lastupdatetime = $_GPC['lastupdatetime'];
$list = pdo_fetchall("SELECT openid, shakecount FROM " . tablename('shake_member') . " WHERE rid = :rid AND createtime > '{$lastupdatetime}' ORDER BY id ASC", array(':rid' => $rid), 'openid');
$total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('shake_member')." WHERE rid = :rid", array(':rid' => $rid));
$fans = mc_fetch(array_keys($list), array('realname', 'mobile', 'avatar'));
if (!empty($fans)) {
foreach ($fans as $uid => $row) {
$list[$uid]['avatar'] = $row['avatar'];
}
}
message(array('list' => $list, 'total' => $total), '', 'ajax');
}
public function doWebManage() {
global $_W, $_GPC;
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
$rid = intval($_GPC['id']);
if ($operation == 'display') {
$pindex = max(1, intval($_GPC['page']));
$psize = 50;
if (!empty($_GPC['nickname'])) {
$openids = pdo_fetchall("SELECT * FROM " . tablename('mc_mapping_fans') . " WHERE nickname LIKE :nickname", array(':nickname' => '%' . $_GPC['nickname'] . '%'), 'openid');
if (!empty($openids)) {
$condition = " AND openid IN ('" . implode("','", array_keys($openids)) . "')";
}
}
if (!empty($condition) || empty($_GPC['nickname'])) {
$list = pdo_fetchall("SELECT * FROM " . tablename('shake_member') . " WHERE rid = :rid $condition ORDER BY shakecount DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize, array(':rid' => $rid), 'openid');
$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('shake_member') . " WHERE rid = :rid $condition", array(':rid' => $rid));
$pager = pagination($total, $pindex, $psize);
load()->model('mc');
$fans = mc_fetch(array_keys($list), array('realname', 'mobile'));
}
} elseif ($operation == 'post') {
$id = intval($_GPC['id']);
$item = pdo_fetch("SELECT * FROM " . tablename('shake_member') . " WHERE id = '$id'");
if (checksubmit('submit')) {
pdo_update('shake_member', array(
'remark' => $_GPC['remark'],
), array('id' => $id));
message('更新信息成功!', $this->createWebUrl('manage', array('id' => $item['rid'])), 'success');
}
$item['profile'] = fans_search($item['openid'], array('mobile', 'realname'));
} elseif ($operation == 'delete') {
$id = intval($_GPC['id']);
pdo_delete('shake_member', array('id' => $id));
}
include $this->template('manage');
}
public function doWebAddShakecount() {
global $_GPC, $_W;
checklogin();
$id = intval($_GPC['id']);
$shake = pdo_fetch("SELECT shakecount, rid FROM " . tablename('shake_member') . " WHERE id = :id", array(':id' => $id));
$item = pdo_fetch("SELECT maxshake FROM " . tablename('shake_reply') . " WHERE rid = '{$shake['rid']}'");
if ($item['maxshake'] > $shake['shakecount']) {
pdo_update('shake_member', array('shakecount' => $shake['shakecount'] + 1), array('id' => $id));
}
message($shake['shakecount'], '', 'ajax');
}
public function doWebChangeStatus() {
global $_W, $_GPC;
checklogin();
$id = intval($_GPC['id']);
$status = intval($_GPC['status']);
pdo_update('shake_reply', array('status' => $status), array('rid' => $id));
message(array('status' => 1), '', 'ajax');
}
public function getHomeTiles() {
global $_W;
$urls = array();
$sql = 'SELECT `id`, `name` FROM ' . tablename('rule') . ' WHERE `uniacid` = :uniacid AND `module` = :module';
$replies = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid'], ':module' => 'we7_shake'));
if (!empty($replies)) {
foreach ($replies as $reply) {
$urls[] = array('title' => $reply['name'], 'url' => $this->createMobileUrl('welcome', array('rid' => $reply['id'])));
}
}
return $urls;
}
}