site.php
11.7 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<?php
/**
* 打气球抽奖模块
*
* [皓蓝] www.weixiamen.cn 5517286
*/
defined('IN_IA') or exit('Access Denied');
class Hl_dqqModuleSite extends WeModuleSite {
public function doWebAwardlist() {
global $_GPC, $_W;
$id = intval($_GPC['id']);
if (checksubmit('delete')) {
if (empty($_GPC['select'])) {
message('请先选择要删除的记录', referer(), 'error');
}
pdo_delete('dqq_winner', " id IN ('".implode("','", $_GPC['select'])."')");
message('奖品记录删除成功!', referer(), 'success');
}
if (!empty($_GPC['wid'])) {
$wid = intval($_GPC['wid']);
pdo_update('dqq_winner', array('status' => intval($_GPC['status'])), array('id' => $wid));
message('奖品状态更改成功!', referer(), 'success');
}
$where = ' WHERE `a`.`rid` = :rid AND `f`.`uniacid` = :uniacid';
$params = array(':rid' => intval($_GPC['id']), ':uniacid' => $_W['uniacid']);
if (empty($starttime) || empty($endtime)) {
$starttime = strtotime('-1 month');
$endtime = time();
}
if (!empty($_GPC['daterange'])) {
$starttime = strtotime($_GPC['daterange']['start']);
$endtime = strtotime($_GPC['daterange']['end']) + 86399;
}
$condition = array(
'isregister' => array(
'',
" AND m.realname <> ''",
" AND m.realname = ''",
),
'isaward' => array(
'',
" AND a.award <> ''",
" AND a.award = ''",
),
'award' => array(
'title' => " AND a.award LIKE '%{$_GPC['awardvalue']}%'",
'description' => " AND a.description LIKE '%{$_GPC['awardvalue']}%'",
),
'qq' => " AND m.qq LIKE '%{$_GPC['profilevalue']}%'",
'mobile' => " AND m.mobile LIKE '%{$_GPC['profilevalue']}%'",
'realname' => " AND m.realname LIKE '%{$_GPC['profilevalue']}%'",
'starttime' => " AND a.createtime >= '$starttime'",
'endtime' => " AND a.createtime <= '$endtime'",
);
$where .= $condition['isregister'][$_GPC['isregister']];
$where .= $condition['isaward'][$_GPC['isaward']];
$where .= $condition['award'][$_GPC['award']];
if (!empty($_GPC['profile'])) {
$where .= $condition[$_GPC['profile']];
}
if (!empty($_GPC['award'])) {
$where .= $condition[$_GPC['award']];
}
if (!empty($starttime)) {
$where .= $condition['starttime'];
}
if (!empty($endtime)) {
$where .= $condition['endtime'];
}
$join = ' FROM ' . tablename('dqq_winner') . ' AS `a` JOIN ' . tablename('mc_mapping_fans') . ' AS `f` ON
`a`.`from_user` = `f`.`openid` JOIN ' . tablename('mc_members') . ' AS `m` ON `f`.`uid` = `m`.`uid`';
$sql = 'SELECT COUNT(*) ' . $join . $where;
$total = pdo_fetchcolumn($sql, $params);
if ($total > 0) {
$pindex = max(1, intval($_GPC['page']));
$psize = 15;
$sql = 'SELECT `a`.*, `m`.`realname`, `m`.`mobile`, `m`.`qq` ' . $join . $where;
$list = pdo_fetchall($sql, $params);
$pager = pagination($total, $pindex, $psize);
}
if (!empty($_GPC['export'])) {
/* 输入到CSV文件 */
$html = "\xEF\xBB\xBF";
/* 输出表头 */
$filter = array(
'realname' => '姓名',
'mobile' => '手机',
'qq' => 'QQ',
'award' => '奖品',
'createtime' => '获取时间',
);
foreach ($filter as $key => $value) {
$html .= $value . "\t,";
}
$html .= "\n";
foreach ($list as $key => $value) {
foreach ($filter as $index => $title) {
if ($index != 'createtime') {
$html .= $value[$index] . "\t, ";
} else {
$html .= date('Y-m-d H:i:s', $value[$index]);
}
}
$html .= "\n";
}
/* 输出CSV文件 */
header("Content-type:text/csv");
header("Content-Disposition:attachment; filename=全部数据.csv");
echo $html;
exit();
}
include $this->template('awardlist');
}
public function getProfileTiles() {
}
public function getHomeTiles($keyword = '') {
global $_W;
$urls = array();
$list = pdo_fetchall("SELECT name, id FROM ".tablename('rule')." WHERE uniacid = '{$_W['weid']}' AND module = 'hl_dqq'".(!empty($keyword) ? " AND name LIKE '%{$keyword}%'" : ''));
if (!empty($list)) {
foreach ($list as $row) {
$urls[] = array('title'=>$row['name'], 'url'=> $this->createMobileUrl('lottery', array('id' => $row['id'])));
}
}
return $urls;
}
public function doMobileLottery() {
global $_GPC, $_W;
$title = '打气球送积分';
$useragent = addslashes($_SERVER['HTTP_USER_AGENT']);
if(strpos($useragent, 'MicroMessenger') === false && strpos($useragent, 'Windows Phone') === false ){
//message('请使用微信客户端进入打气球吧!');
}
checkauth();
load()->model('mc');
mc_require($_W['member']['uid'], array('realname', 'mobile') , '需要完善资料后才能打气球.');
$fromuser = $_W['fans']['from_user'];
//$profile = fans_require($fromuser, array('realname', 'mobile', 'qq'), '需要完善资料后才能打气球.');
$id = intval($_GPC['id']);
$dqq = pdo_fetch("SELECT id, maxlottery, default_tips, rule FROM ".tablename('dqq_reply')." WHERE rid = '$id' LIMIT 1");
if (empty($dqq)) {
message('非法访问,请重新发送消息进入打气球页面!');
}
$total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('dqq_winner')." WHERE createtime > '".strtotime(date('Y-m-d'))."' AND from_user = '$fromuser' ");
$member = fans_search($fromuser);
$myaward = pdo_fetchall("SELECT award, description FROM ".tablename('dqq_winner')." WHERE from_user = '{$fromuser}' AND rid = '$id' ORDER BY createtime DESC");
$sql = "SELECT a.award, b.realname FROM ".tablename('dqq_winner')." AS a
LEFT JOIN " . tablename('mc_mapping_fans')." f on f.openid = a.from_user
LEFT JOIN " . tablename('mc_members') . " b ON b.uid = f.uid WHERE b.mobile <> '' AND b.realname <> '' AND a.rid = '$id' ORDER BY a.createtime DESC LIMIT 20";
$otheraward = pdo_fetchall($sql);
include $this->template('lottery');
}
public function doMobileGetAward() {
global $_GPC, $_W;
checkauth();
$fromuser = $_W['fans']['from_user'];
$id = intval($_GPC['id']);
$dqq = pdo_fetch("SELECT id, periodlottery, maxlottery, default_tips, misscredit, hitcredit FROM ".tablename('dqq_reply')." WHERE rid = '$id' LIMIT 1");
if (empty($dqq)) {
message('非法访问,请重新发送消息进入打气球页面!4');
}
$result = array('status' => -1, 'message' => '');
if (!empty($dqq['periodlottery'])) {
$total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('dqq_winner')." WHERE createtime > '".strtotime(date('Y-m-d'))."' AND from_user = '$fromuser' AND rid = '$id'");
$lastdate = pdo_fetchcolumn("SELECT createtime FROM ".tablename('dqq_winner')." WHERE from_user = '$fromuser' ORDER BY createtime DESC");
if (($total >= intval($dqq['maxlottery'])) && strtotime(date('Y-m-d')) < strtotime(date('Y-m-d', $lastdate)) + $dqq['periodlottery'] * 86400) {
$result['message'] = '没箭啦';
message($result, '', 'ajax');
}
} else {
$total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('dqq_winner')." WHERE createtime > '".strtotime(date('Y-m-d'))."' AND from_user = '$fromuser' ");
if (!empty($dqq['maxlottery']) && $total >= $dqq['maxlottery']) {
$result['message'] = '今天没箭了';
message($result, '', 'ajax');
}
}
$gifts = pdo_fetchall("SELECT id, probalilty FROM ".tablename('dqq_award')." WHERE rid = '$id' ORDER BY probalilty ASC");
//计算每个礼物的概率
$probability = 0;
$rate = 1;
$award = array();
foreach ($gifts as $name => $gift){
if (empty($gift['probalilty'])) {
continue;
}
if ($gift['probalilty'] < 1) {
$temp = explode('.', $gift['probalilty']);
$temp = pow(10, strlen($temp[1]));
$rate = $temp < $rate ? $rate : $temp;
}
$probability = $probability + $gift['probalilty'] * $rate;
$award[] = array('id' => $gift['id'], 'probalilty' => $probability);
}
$all = 100 * $rate;
if($probability < $all){
$award[] = array('title' => '','probalilty' => $all);
}
mt_srand((double) microtime()*1000000);
$rand = mt_rand(1, $all);
foreach ($award as $key => $gift) {
if (isset($award[$key - 1])) {
if ($rand > $award[$key - 1]['probalilty'] && $rand <= $gift['probalilty']) {
$awardid = $gift['id'];
break;
}
} else {
if ($rand > 0 && $rand <= $gift['probalilty']) {
$awardid = $gift['id'];
break;
}
}
}
$result['message'] = '唉,没中';
$data = array(
'rid' => $id,
'from_user' => $fromuser,
'status' => empty($gift['inkind']) ? 1 : 0,
'createtime' => TIMESTAMP,
);
$credit = array(
'rid' => $id,
'award' => (empty($awardid) ? '未中' : '中') . '奖励积分',
'from_user' => $fromuser,
'status' => 3,
'description' => (empty($awardid) ? $dqq['misscredit'] : $dqq['hitcredit']),
'createtime' => TIMESTAMP,
);
if (!empty($awardid)) {
$sql = 'SELECT * FROM ' . tablename('dqq_award') . ' WHERE `rid` = :rid AND `id` = :id';
$params = array(':rid' => $id, ':id' => $awardid);
$gift = pdo_fetch($sql, $params);
if ($gift['total'] > 0) {
$data['award'] = $gift['title'];
$credit1 = intval($gift['get_jf']);
load()->model('mc');
mc_credit_update($_W['member']['uid'], "credit1", $credit1, null);
$data['description'] = $gift['description'];
$result['message'] = '' . $data['award'] . '!';
$result['status'] = 0;
pdo_update('dqq_award', array('total' => --$gift['total']), array('id' => $gift['id']));
} else {
$credit['description'] = $dqq['misscredit'];
$credit['award'] = '未中奖励积分';
}
}
!empty($credit['description']) && $result['message'] .= '<br />' . $credit['award'] . ':'. $credit['description'];
$data['aid'] = $gift['id'];
if (!empty($credit['description'])) {
pdo_insert('dqq_winner', $credit);
}
pdo_insert('dqq_winner', $data);
message($result, '', 'ajax');
}
public function doMobileRegister() {
global $_GPC, $_W;
$title = '打气球领奖登记个人信息';
checkauth();
if (!empty($_GPC['submit'])) {
$data = array(
'realname' => $_GPC['realname'],
'mobile' => $_GPC['mobile'],
);
if (empty($data['realname'])) {
die('<script>alert("请填写您的真实姓名!");location.reload();</script>');
}
if (empty($data['mobile'])) {
die('<script>alert("请填写您的手机号码!");location.reload();</script>');
}
fans_update($_W['fans']['from_user'], $data);
die('<script>alert("登记成功!");location.href = "'.$this->createMobileUrl('lottery', array('id' => $_GPC['id'])).'";</script>');
}
include $this->template('register');
}
public function doMobileGetMyAward() {
global $_GPC, $_W;
$params = $awards = array();
$sql = 'SELECT `award`, `createtime`, `description` FROM ' . tablename('dqq_winner') . " WHERE `rid` = :rid AND `from_user` = :fromuser AND `award` <> :award
ORDER BY `createtime` DESC";
$params[':rid'] = intval($_GPC['id']);
$params[':fromuser'] = $_W['fans']['from_user'];
$params[':award'] = '';
$awards = pdo_fetchall($sql, $params);
if (!empty($awards)) {
foreach ($awards as &$award) {
$award['createtime'] = date('Y-m-d H:i', $award['createtime']);
}
}
exit(json_encode($awards));
}
public function doMobileGetScore() {
global $_GPC, $_W;
$params = $scores = array();
$sql = 'SELECT COUNT(*) AS `count`,`award`, `from_user` FROM ' . tablename('dqq_winner') . " WHERE `rid` = :rid AND `award` <> :award GROUP BY `from_user`
ORDER BY `count` DESC LIMIT 0, 10";
$params[':rid'] = intval($_GPC['id']);
$params[':award'] = '';
$scores = pdo_fetchall($sql, $params, 'from_user');
if (!empty($scores)) {
load()->model('mc');
$fromusers = array_keys($scores);
$members = mc_fetch($fromusers, array('realname'));
foreach ($scores as &$score) {
$member = mc_fetch($score['from_user'], array('realname'));
$score['member'] = $member['realname'];
}
}
exit(json_encode($scores));
}
}