-
Notifications
You must be signed in to change notification settings - Fork 5
/
coupon.php
185 lines (145 loc) · 6.83 KB
/
coupon.php
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
<?php
define('IN_SMT',true);
define('CURSCRIPT','coupon');
define('IN_MYMPS',TRUE);
define('DIR_NAV',dirname(__FILE__));
require_once DIR_NAV.'/include/global.php';
require_once MYMPS_DATA."/config.php";
require_once MYMPS_DATA."/config.db.php";
require_once MYMPS_INC."/db.class.php";
ifsiteopen();
$cate_id = isset($cate_id) ? intval($cate_id) : '';
$areaid = isset($areaid) ? intval($areaid) : '';
$cityid = isset($cityid) ? intval($cityid) : 0;
$id = isset($id) ? intval($id) : '';
$orderby = isset($orderby) ? trim($orderby) : '';
$data = $pluginsettings = '';
$action = isset($action) ? trim($action) : '';
if(!in_array($orderby,array('prints','dateline','hit'))) $orderby = 'hit';
$city = get_city_caches($cityid);
/*自动补充总站数据start*/
if($mymps_global['cfg_independency'] && $cityid){
$maincity = get_city_caches(0);
$independency = explode(',',$mymps_global['cfg_independency']);
$independency = is_array($independency) ? $independency : array();
if(in_array('advertisement',$independency)){
$city['advertisement'] = empty($city['advertisement']) ? $maincity['advertisement'] : $city['advertisement'];
}
$maincity = NULL;
}
!ifplugin(CURSCRIPT) && exit('管理员已禁用或未安装优惠券插件...');
require_once DIR_NAV.'/plugin/coupon/include/functions.php';
$couponclass = $coupon_class = get_coupon_class();
$coupon_class = is_array($coupon_class) ? array_merge(
array(
0=>array(
'cate_id'=>0,
'cate_name'=>'全部',
'cate_uri'=>plugin_url(CURSCRIPT,array('cate_id'=>0))
)
)
,$coupon_class
) : array();
if($city['cityid']){
$area_class = $city['area'];
if(is_array($area_class)){
//$area_class = array_merge(array('0'=>array('areaid'=>'','areaname'=>'全部')),$area_class);
if(is_array($area_class)){
foreach($area_class as $areakey => $areaval){
$area_class[$areakey]['uri'] = plugin_url(CURSCRIPT,array('cate_id'=>$cate_id,'areaid'=>$areaval['areaid']));
$area_class[$areakey]['select'] = $areaval['areaid'] == $areaid ? '1' : 0;
}
}
}
}
$advertisement = get_advertisement('other');
$adveritems = $city['advertisement'];
$advertisement = $advertisement['all'];
$where .= $city[cityid] ? " AND cityid = '$city[cityid]'" : "";
$counts = $db -> getAll("SELECT cate_id,count(id) AS num FROM {$db_mymps}coupon AS i WHERE status = '1' AND grade > '0' {$where} GROUP BY cate_id ");
$count = array();
$count['total'] = $db->getOne("SELECT count(id) FROM {$db_mymps}coupon WHERE status = '1' AND grade > '0' {$where}");
foreach($counts as $k=>$v){
$count[$v['cate_id']] = !empty($v['num']) ? $v['num'] : 0 ;
}
if($id) {
$coupon = $db -> getRow("SELECT * FROM `{$db_mymps}coupon` WHERE id = '$id' AND status = '1' AND grade > '0'");
if(!$coupon['id']) write_msg('该优惠券已失效或者尚未通过审核!','olmsg');
if($action == 'print'){
$db -> query("UPDATE `{$db_mymps}coupon` SET prints = prints + 1 WHERE id = '$id'");
globalassign();
include mymps_tpl('print');
} else {
$db -> query("UPDATE `{$db_mymps}coupon` SET hit = hit + 1 WHERE id = '$id'");
$coupon['content'] = replace_insidelink($coupon['content'],'coupon');
$space = $db -> getRow("SELECT tname,address,busway,tel FROM `{$db_mymps}member` WHERE userid = '$coupon[userid]'");
$uid = $db -> getOne("SELECT id FROM `{$db_mymps}member` WHERE userid = '$coupon[userid]'");
$space['uri'] = Rewrite('store',array('uid'=>$uid,'action'=>'index'));
$space['tname'] = $space['tname'] ? $space['tname'] : $space['userid'];
$space['address'] = $space['address'] ? $space['address'] : $space['busway'];
$loc = get_coupon_location($coupon['cate_id'],$coupon['title']);
$page_title = $loc['page_title'];
$location = $loc['location'];
globalassign();
include mymps_tpl('view');
}
} else {
$where = "WHERE status = '1' AND grade > '0'";
if($cate_id) $where .= " AND cate_id = '$cate_id'";
if($cityid) $where .= " AND cityid = '$cityid'";
if($areaid) $where .= " AND areaid = '$areaid'";
if($streetid) $where .= " AND streetid = '$streetid'";
$rows_num = $db->getOne("SELECT count(id) FROM {$db_mymps}coupon $where");
$param = setParam(array('cateid','areaid','orderby'));
$coupon = page1("SELECT * FROM `{$db_mymps}coupon` $where ORDER BY $orderby DESC");
$list = array();
foreach($coupon as $k => $v){
$list[$v['id']]['id'] = $v['id'];
$list[$v['id']]['title'] = $v['title'];
$list[$v['id']]['des'] = $v['des'];
$list[$v['id']]['enddate'] = $v['enddate'];
$list[$v['id']]['begindate'] = $v['begindate'];
$list[$v['id']]['prints'] = $v['prints'];
$list[$v['id']]['pre_picture'] = $v['pre_picture'];
$list[$v['id']]['sup'] = $v['sup'];
$list[$v['id']]['uri'] = plugin_url('coupon',array('id'=>$v['id']));
}
foreach(array('hit'=>'默认','prints'=>'打印','dateline'=>'最新') as $k => $v){
$orderby_url[$k]['selected'] = $orderby == $k ? 1 : 0;
$orderby_url[$k]['name'] = $v;
$orderby_url[$k]['url'] = plugin_url(CURSCRIPT,array('cate_id'=>$cate_id,'areaid'=>$areaid,'orderby'=>$k));
}
$page_view = page2();
$loc = get_coupon_location($cate_id);
$page_title = (empty($cate_id) && empty($areaid)) ? ($pluginsettings[CURSCRIPT]['seotitle'] ? $pluginsettings[CURSCRIPT]['seotitle'] : $loc['page_title']) : $loc['page_title'];
$page_title = str_replace('{city}',$city['cityname'],$page_title);
$location = $loc['location'];
$seo = array();
$seo['keywords'] = str_replace('{city}',$city['cityname'],$pluginsettings[CURSCRIPT]['seokeywords']);
$seo['description'] = str_replace('{city}',$city['cityname'],$pluginsettings[CURSCRIPT]['seodescription']);
$currentlocate = $areaname.$couponclass[$cate_id]['cate_name'].'优惠券';
globalassign();
include mymps_tpl('index');
}
is_object($db) && $db->Close();
function get_coupon_location($cate_id=0,$str=''){
global $db,$db_mymps,$couponclass,$areaid,$areaname,$mymps_global,$city;
$raquo = $mymps_global['cfg_raquo'];
$location = '当前位置:<a href="'.$mymps_global['SiteUrl'].'">'.$city['cityname'].$GLOBALS['mymps_global']['SiteName'].'</a>'.' <code>'.$raquo.'</code> '.' <a href="'.plugin_url(CURSCRIPT,array('cate_id'=>0)).'">'.$city[cityname].'优惠券</a>';
$page_title = $city['cityname'].'优惠券 - '.$mymps_global['SiteName'];
if(!empty($cate_id)){
$page_title = htmlspecialchars($couponclass[$cate_id]['cate_name']) . ' - ' . $page_title;
$location .= ' <code> '.$raquo.' </code> <a href="' . $couponclass[$cate_id]['cate_uri'] . '">' .
htmlspecialchars($couponclass[$cate_id]['cate_name']).'</a>';
}
$areaname = $mymps_global['SiteCity'].($areaid ? get_areaname($areaid) : '');
$page_title = $areaname.$page_title;
if (!empty($str)){
$page_title = $str.' - '.$page_title;
$location .= ' <code>'.$raquo.'</code> ' .$str;
}
$cur = array('page_title'=>$page_title,'location'=>$location);
unset($page_title,$cat,$location,$type,$couponclass);
return $cur;
}
?>