Sidebar.php
9.25 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
<?php
class QLibView_Sidebar
{
public static $_G = array();
public static $path = '';
public static $noSingle = array('brand','style','parameter');
/**
* 显示内容
* @param String $template
* @param array $params
* @return string
*/
public static function show($template, array $params)
{
if (empty($template) || empty($params)) {
return '';
}
$templatePath = __DIR__ . '/Template/Sidebar/' . $template . '.phtml';
include $templatePath;
}
/**
* 获得url
*
* @param Array $param array('brand' => 1)
* @param String $type 1 添加参数 -1 是减少参数
* @param String $is_clear Y 为清空其他参数 N 为不清空其他参数
* @param String $is_multi Y 为复选 N 为单选
* @param String
*/
public static function getUrl($param, $type, $is_clear = 'N', $url = null, $default = array())
{
if ($url == null) {
$params = self::parseQuery();
$url = self::$path;
}
//清除现有参数
if ($is_clear == 'Y') {
$params = array();
}
if (!empty($param['num'])) {
unset($params['page']);
}
foreach ($param as $key => $value) {
$is_multi = in_array($key, self::$noSingle) ? 'Y' : 'N';
//增加参数
if ($type == 1) {
if ($is_multi == 'Y') {
//多选
$params[$key] .= empty($params[$key]) ? $value : ',' . $value;
} else {
//单选
$params = array_merge($params, array($key => $value));
}
} else {
//减少参数
//多选
if ($is_multi == 'Y') {
$arr = array_unique(explode(',', $params[$key]));
//只有一个时直接unset
if (count($arr) == 1) {
unset($params[$key]);
} else {
//多于一个时循环处理
foreach ($arr as $k => $v) {
if ($v == $value) {
unset($arr[$k]);
}
}
if (!empty($arr)) {
$params[$key] = implode(',', $arr);
}
}
} else {
//单选
unset($params[$key]);
}
}
}
$query = array();
foreach ($params as $k => $v) {
$query[] = $k . '=' . $v;
}
return $url . (empty($query) ? '' : '?' . implode('&', $query));
}
/**
* 验证参数是否所选
*
* @param unknown_type $key
* @param unknown_type $value
* @return boolean
*/
public static function vail($key, $value)
{
$params = self::parseQuery();
if (empty($params[$key])) {
return false;
}
$is_multi = in_array($key, self::$noSingle) ? 'Y' : 'N';
if ($is_multi == 'Y') {
$val = array_unique(explode(',', $params[$key]));
return in_array($value, $val) ? true : false;
} else {
return $params[$key] != $value ? false : true;
}
}
/**
* 获得url中的参数字符串
*/
public static function parseQuery()
{
if (!empty(self::$_G)) {
return self::$_G;
}
$urlInfo = parse_url($_SERVER['REQUEST_URI']);
self::$path = $urlInfo['path'];
$query = $urlInfo['query'];
if (empty($query)) {
return array();
}
$queryArr = explode('&', $query);
$result = array();
foreach ($queryArr as $v) {
$param = explode('=', $v);
if (empty($param)) {
continue;
}
$result[$param[0]] = $param[1];
}
return self::$_G = $result;
}
public static function params($params)
{
if(empty($params) || !is_array($params)){
return array();
}
$fields = array('gender','brand','specialsale_id','price','style','p_d','parameter','sort','size', 'color');
$result = array();
foreach ($fields as $v){
if(empty($params[$v])){
continue;
}
$is_multi = in_array($v, self::$noSingle) ? 'Y' : 'N';
if($is_multi == 'Y'){
$value = array_unique(explode(',', $params[$v]));
foreach ($value as $id){
$result[] = array(
'key' => $v,
'value' => $id
);
}
}else{
$result[] = array('key' => $v, 'value' => $params[$v]);
}
}
return $result;
}
static function selectGoodsByColor(array $goodsList, $colorID)
{
$_defaultGoods = array();
foreach ($goodsList as $_key => $_goods) {
if ($_goods['color_id'] == $colorID) {
return $_goods;
}
if ($_goods['is_default'] == 'Y') {
$_defaultGoods = $_goods;
}
}
if (empty($_defaultGoods)) {
$_firstGoods = array_slice($goodsList, 0, 1);
return $_firstGoods[0];
}
return $_defaultGoods;
}
public static function getPriceUrlbak($params)
{
$ppam = $params;
if (isset($ppam['q'])) {
unset($ppam['q']);
}
$localurl = http_build_query($ppam, '', '&');
$cssClass = '';
if (empty($ppam['order']) || $ppam['order'] == 's_t_desc') {
$ppam['order'] = 's_p_desc';
} else if ($ppam['order'] == 's_p_desc') {
$cssClass = 'down';
$ppam['order'] = 's_p_asc';
} else if ($ppam['order'] == 's_p_asc') {
$cssClass = 'up';
$ppam['order'] = 's_p_desc';
}
$data = http_build_query($ppam, '', '&');
$priceurl = '?' . $data;
$ppam['order'] = 's_t_desc';
$data = http_build_query($ppam, '', '&');
$newurl = '?' . $data;
return array(
'priceUrl' => $priceurl,
'newUrl' => $newurl,
'localUrl' => $localurl,
'cssClass' => $cssClass
);
}
public static function getPriceUrl($params)
{
$ppam = $params;
if (isset($ppam['q'])) {
unset($ppam['q']);
}
$localurl = http_build_query($ppam, '', '&');
$ppam['order'] = 's_p_desc';
$data = http_build_query($ppam, '', '&');
$down_price_url = '?' . $data;
$ppam['order'] = 's_p_asc';
$data = http_build_query($ppam, '', '&');
$up_price_url = '?' . $data;
$ppam['order'] = 's_t_desc';
$data = http_build_query($ppam, '', '&');
$new_url = '?' . $data;
$ppam['order'] = 's_n_desc';
$data = http_build_query($ppam, '', '&');
$sale_url = '?' . $data;
return array(
'down_price_url' => $down_price_url,
'up_price_url' => $up_price_url,
'new_url' => $new_url,
'sale_url' => $sale_url,
'localurl' => $localurl
);
}
public static function getUrlParams($params)
{
$ppam = $params;
if (isset($ppam['q'])) {
unset($ppam['q']);
}
$localurl = http_build_query($ppam, '', '&');
$cssClass = '';
if (empty($ppam['order'])) {
$ppam['order'] = 's_p_desc';
}
$data = http_build_query($ppam, '', '&');
$priceurl = '?' . $data;
$ppam['order'] = 's_t_desc';
$data = http_build_query($ppam, '', '&');
$newurl = '?' . $data;
return array(
'priceUrl' => $priceurl,
'newUrl' => $newurl,
'localUrl' => $localurl,
'cssClass' => $cssClass
); }
/**
* 获取YOHO币类型
* @param json $params
* @param int $type
* @return string
*/
public static function getYOHOCoin($params, $type)
{
$params = json_decode($params, true);
if (!empty($params['cms_order_id'])) {
$order_code = $params['cms_order_id'];
} else if (!empty($params['order_code'])) {
$order_code = $params['order_code'];
} else {
$order_code = '';
}
if($type == 1) {
return 'YOHO币充值';
} else if($type == 2) {
return '取消订单号为'.$order_code.'的订单返还';
} else if($type == 3) {
return '取消订单号为'.$order_code.'的订单返还';
} else if($type == 4) {
return '使用YOHO币支付订单';
} else if($type ==5) {
return '订单号为' . $order_code .'的订单退货';
} else if($type == 6){
return '老系统导入';
} else if($type == 7) {
return '完善用户信息';
} else if($type == 8) {
return '晒物送YOHO币';
}else if($type == 9){
return '订单' . $order_code . '在线支付,返运费。';
}else if($type == 10){
return '订单' . $order_code . '成功购买返币活动返YOHO币';
}else if ($type == 11){
return 'visible商品降价补差价';
}else if ($type == 12){
return '订单' . $order_code . '退货退运费';
}else if ($type == 13){
return '订单' . $order_code . '发货延迟返50%YOHO币';
}else if ($type == 14){
return '订单' . $order_code . '退货应退金额不退钱退YOHO币';
}else if ($type == 15){
return '先锋人物奖励';
}else if ($type == 16){
return '其他';
}
}
}