site.php
5.99 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
<?php
/**
* @author WeEngine Team
* @url http://bbs.we7.cc/forum.php?mod=forumdisplay&fid=36&filter=typeid&typeid=1
*/
defined('IN_IA') or exit('Access Denied');
class We7_businessModuleSite extends WeModuleSite {
public function doWebPost() {
global $_GPC, $_W;
if (empty($_GPC['do'])) {
$_GPC['do'] = 'post';
}
$id = intval($_GPC['id']);
if (!empty($id)) {
$item = pdo_fetch("SELECT * FROM " . tablename('business') . " WHERE id = :id", array(':id' => $id));
if (empty($item)) {
message('抱歉,商户不存在或是已经删除!', '', 'error');
}
}
if (checksubmit('submit')) {
if (empty($_GPC['title'])) {
message('请输入商户名称!');
}
$data = array(
'weid' => $_W['weid'],
'title' => $_GPC['title'],
'content' => $_GPC['content'],
'phone' => $_GPC['phone'],
'qq' => $_GPC['qq'],
'province' => $_GPC['district']['province'],
'city' => $_GPC['district']['city'],
'dist' =>$_GPC['district']['district'],
'address' => $_GPC['address'],
'lng' => $_GPC['baidumap']['lng'],
'lat' => $_GPC['baidumap']['lat'],
'industry1' => $_GPC['industry']['parent'],
'industry2' => $_GPC['industry']['child'],
'createtime' => TIMESTAMP,
);
if (!empty($_GPC['thumb'])) {
$data['thumb'] = $_GPC['thumb'];
load()->func('file');
file_delete($_GPC['thumb-old']);
}
if (empty($id)) {
pdo_insert('business', $data);
} else {
unset($data['createtime']);
pdo_update('business', $data, array('id' => $id));
}
message('商户信息更新成功!', $this->createWebUrl('display'), 'success');
}
include $this->template('post');
}
public function doWebDisplay() {
global $_W, $_GPC;
$pindex = max(1, intval($_GPC['page']));
$psize = 10;
$condition = '';
if (!empty($_GPC['keyword'])) {
$condition .= " AND title LIKE '%{$_GPC['keyword']}%'";
}
if (is_array($_GPC['industry'])) {
if (!empty($_GPC['industry']['parent'])) {
$condition .= " AND industry1 = '{$_GPC['industry']['parent']}'";
}
if (!empty($_GPC['industry']['child'])) {
$condition .= " AND industry2 = '{$_GPC['industry']['child']}'";
}
}
$sql = 'SELECT COUNT(*) FROM ' . tablename('business') . ' WHERE `weid` = :weid ' . $condition;
$params = array(':weid' => $_W['uniacid']);
$total = pdo_fetchcolumn($sql, $params);
if ($total > 0) {
$sql = 'SELECT * FROM ' . tablename('business') . ' WHERE `weid` = :weid ' . $condition . ' ORDER BY `id`
DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
$list = pdo_fetchall($sql, $params);
$pager = pagination($total, $pindex, $psize);
}
if (!empty($_GPC['export'])) {
/* 输入到CSV文件 */
$html = "\xEF\xBB\xBF";
/* 输出表头 */
$filter = array(
'title' => '名称',
'phone' => '电话',
'address' => '地址',
'industry1' => '行业',
);
foreach ($filter as $key => $value) {
$html .= $value . "\t,";
}
$html .= "\n";
$key_array = array_keys($filter);
foreach ($list as $k => $v) {
foreach ($v as $k1 => $v1) {
if (in_array($k1, $key_array)) {
if ($k1 == 'createtime' || $k1 == 'dateline') {
$html .= date('Y-m-d H:i:s', $v1) . "\t ,";
} else {
$html .= $v1 . "\t,";
}
}
}
$html .= "\n";
}
/* 输出CSV文件 */
header("Content-type:text/csv");
header("Content-Disposition:attachment; filename=全部数据.csv");
echo $html;
exit();
}
load()->func('tpl');
include $this->template('display');
}
public function doWebDelete() {
global $_GPC;
$id = intval($_GPC['id']);
$item = pdo_fetch("SELECT * FROM " . tablename('business') . " WHERE id = :id", array(':id' => $id));
if (empty($item)) {
message('抱歉,商户不存在或是已经删除!', '', 'error');
}
if (!empty($item['thumb'])) {
load()->func('file');
file_delete($item['thumb']);
}
pdo_delete('business', array('id' => $item['id']));
message('删除成功!', referer(), 'success');
}
public function doMobileDetail() {
global $_W, $_GPC;
$id = intval($_GPC['id']);
$item = pdo_fetch("SELECT * FROM " . tablename('business') . " WHERE id = :id", array(':id' => $id));
if (empty($item)) {
message('抱歉,该商家不存在或是已经被删除!');
}
$content = strip_tags($item['content']);
$content = cutstr($content, 50, true);
include $this->template('detail');
}
public function getHomeTiles() {
global $_W;
$urls = array();
$sql = 'SELECT `id`, `title` FROM ' . tablename('business') . ' WHERE `weid` = :weid';
$replies = pdo_fetchall($sql, array(':weid' => $_W['uniacid']));
if (!empty($replies)) {
foreach ($replies as $reply) {
$urls[] = array('title' => $reply['title'], 'url' => $this->createMobileUrl('detail', array('id' => $reply['id'])));
}
}
return $urls;
}
}