site.php
4.14 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
<?php
defined('IN_IA') or exit('Access Denied');
class Weihaom_wbModuleSite extends WeModuleSite {
public function doMobileIndex() {
global $_W, $_GPC;
if (empty($_W['fans']['nickname'])) {
mc_oauth_userinfo();
}
if (empty($_W['fans']['openid'])) {
message('请先关注公众号再来参加活动吧!');
}
$rid = intval($_GPC['rid']);
$sql = 'SELECT * FROM ' . tablename('weihaom_wb_reply') .' WHERE `rid` = :rid';
$params = array(':rid' => $rid);
$set = pdo_fetch($sql, $params);
if (empty($set)) {
message('活动不存在或已经被删除');
}
$sql = 'SELECT * FROM ' . tablename('weihaom_wb_user') . ' WHERE `weid` = :weid AND `rid` = :rid AND
`from_user` = :openid';
$params[':weid'] = $_W['uniacid'];
$params[':openid'] = $_W['fans']['openid'];
$user = pdo_fetch($sql, $params);
if (intval($_GPC['id'])) {
$score = intval($_GPC['score']);
if ($user['score'] < $score) {
$user['score'] = $score;
$update = array('score' => $score);
pdo_update('weihaom_wb_user', $update, array('id' => intval($_GPC['id'])));
}
message($user['score'], '', 'ajax');
}
if (empty($user)) {
// 必须设置昵称才能踩白块
mc_require($_W['member']['uid'], array('nickname') , '需要完善资料后才能踩白块.');
$result = mc_fetch($_W['member']['uid'], array('nickname'));
$insert = array(
'weid' => $_W['uniacid'],
'rid' => $params[':rid'],
'from_user' => $_W['fans']['openid'],
'realname' => $result['nickname'], // $_W['fans']['nickname']
'score' => 0
);
pdo_insert('weihaom_wb_user', $insert);
$user = array('id' => pdo_insertid());
}
if (empty($user['realname'])) {
pdo_update('weihaom_wb_user', array('realname' => $_W['fans']['nickname']), array('id' => $user['id']));
}
$realname = $_W['fans']['nickname'];
$set['description'] = str_replace("\r\n", '', $set['description']);
include $this->template('index');
}
public function doMobilePhb() {
global $_W, $_GPC;
$rid = intval($_GPC['rid']);
$sql = 'SELECT * FROM ' . tablename('weihaom_wb_reply') . ' WHERE `rid` = :rid';
$params = array(':rid' => $rid);
$set = pdo_fetch($sql, $params);
$set['description'] = str_replace("\r\n", '', $set['description']);
$sql = 'SELECT * FROM ' . tablename('weihaom_wb_user') . ' WHERE `rid` = :rid ORDER BY `score` DESC LIMIT 10';
$users = pdo_fetchall($sql, $params);
include $this->template('phb');
}
public function doWebuserlist(){
global $_W,$_GPC;
$rid = intval($_GPC['id']);
$pindex = max(1, intval($_GPC['page']));
$psize = 20;
$sql = 'SELECT * FROM ' . tablename('weihaom_wb_user') . " WHERE `rid`=:rid order by score DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize;
$params = array();
$params[':rid'] = $rid;
$total = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('weihaom_wb_user') . " WHERE `rid`=:rid", $params);
$pager = pagination($total, $pindex, $psize);
$list = pdo_fetchall($sql, $params);
$n = ($pindex -1) * $psize;
foreach($list as &$row){
$row['rank'] = ++$n;
}
unset($row);
include $this->template('userlist');
}
public function getHomeTiles() {
global $_W;
$urls = array();
$sql = 'SELECT `id`, `rid`, `title` FROM ' . tablename('weihaom_wb_reply') . ' WHERE `uniacid` = :uniacid';
$replies = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']));
if (!empty($replies)) {
foreach ($replies as $reply) {
$urls[] = array('title' => $reply['title'], 'url' => $this->createMobileUrl('index', array('rid' => $reply['rid'])));
}
}
return $urls;
}
}