-
Notifications
You must be signed in to change notification settings - Fork 27
/
exchange.php
760 lines (651 loc) · 30.7 KB
/
exchange.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
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
<?php
/**
* 鸿宇多用户商城 积分商城
* ============================================================================
* 版权所有 2015-2016 鸿宇多用户商城科技有限公司,并保留所有权利。
* 网站地址: http://bbs.hongyuvip.com;
* ----------------------------------------------------------------------------
* 仅供学习交流使用,如需商用请购买正版版权。鸿宇不承担任何法律责任。
* 踏踏实实做事,堂堂正正做人。
* ============================================================================
* $Author: Shadow & 鸿宇
* $Id: exchange.php 17217 2016-01-19 06:29:08Z Shadow & 鸿宇
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
if ((DEBUG_MODE & 2) != 2)
{
$smarty->caching = true;
}
/*------------------------------------------------------ */
//-- act 操作项的初始化
/*------------------------------------------------------ */
if (empty($_REQUEST['act']))
{
$_REQUEST['act'] = 'list';
}
/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */
/*------------------------------------------------------ */
//-- 积分兑换商品列表
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'list')
{
/* 初始化分页信息 */
$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
$size = isset($_CFG['page_size']) && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 10;
$cat_id = isset($_REQUEST['cat_id']) && intval($_REQUEST['cat_id']) > 0 ? intval($_REQUEST['cat_id']) : 0;
$integral_max = isset($_REQUEST['integral_max']) && intval($_REQUEST['integral_max']) > 0 ? intval($_REQUEST['integral_max']) : 0;
$integral_min = isset($_REQUEST['integral_min']) && intval($_REQUEST['integral_min']) > 0 ? intval($_REQUEST['integral_min']) : 0;
/* 排序、显示方式以及类型 */
$default_display_type = $_CFG['show_order_type'] == '0' ? 'list' : ($_CFG['show_order_type'] == '1' ? 'grid' : 'text');
$default_sort_order_method = $_CFG['sort_order_method'] == '0' ? 'DESC' : 'ASC';
$default_sort_order_type = $_CFG['sort_order_type'] == '0' ? 'goods_id' : ($_CFG['sort_order_type'] == '1' ? 'exchange_integral' : 'last_update');
$sort = (isset($_REQUEST['sort']) && in_array(trim(strtolower($_REQUEST['sort'])), array('goods_id', 'exchange_integral', 'last_update','click_count'))) ? trim($_REQUEST['sort']) : $default_sort_order_type;
$order = (isset($_REQUEST['order']) && in_array(trim(strtoupper($_REQUEST['order'])), array('ASC', 'DESC'))) ? trim($_REQUEST['order']) : $default_sort_order_method;
$display = (isset($_REQUEST['display']) && in_array(trim(strtolower($_REQUEST['display'])), array('list', 'grid', 'text'))) ? trim($_REQUEST['display']) : (isset($_COOKIE['ECS']['display']) ? $_COOKIE['ECS']['display'] : $default_display_type);
$display = in_array($display, array('list', 'grid', 'text')) ? $display : 'text';
setcookie('ECS[display]', $display, gmtime() + 86400 * 7);
/* 页面的缓存ID */
$cache_id = sprintf('%X', crc32($cat_id . '-' . $display . '-' . $sort .'-' . $order .'-' . $page . '-' . $size . '-' . $_SESSION['user_rank'] . '-' .
$_CFG['lang'] . '-' . $integral_max . '-' .$integral_min));
if (!$smarty->is_cached('exchange_list.dwt', $cache_id))
{
/* 如果页面没有被缓存则重新获取页面的内容 */
$children = get_children($cat_id);
$cat = get_cat_info($cat_id); // 获得分类的相关信息
if (!empty($cat))
{
$smarty->assign('keywords', htmlspecialchars($cat['keywords']));
$smarty->assign('description', htmlspecialchars($cat['cat_desc']));
}
assign_template();
$position = assign_ur_here('exchange');
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
$smarty->assign('categories', get_categories_tree()); // 分类树
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('top_goods', get_top10()); // 销售排行
$smarty->assign('promotion_info', get_promotion_info()); // 促销活动信息
/* 调查 */
$vote = get_vote();
if (!empty($vote))
{
$smarty->assign('vote_id', $vote['id']);
$smarty->assign('vote', $vote['content']);
}
$ext = ''; //商品查询条件扩展
//$smarty->assign('best_goods', get_exchange_recommend_goods('best', $children, $integral_min, $integral_max));
//$smarty->assign('new_goods', get_exchange_recommend_goods('new', $children, $integral_min, $integral_max));
$smarty->assign('hot_goods', get_exchange_recommend_goods('hot', $children, $integral_min, $integral_max));
$count = get_exchange_goods_count($children, $integral_min, $integral_max);
$max_page = ($count> 0) ? ceil($count / $size) : 1;
if ($page > $max_page)
{
$page = $max_page;
}
$goodslist = exchange_get_goods($children, $integral_min, $integral_max, $ext, $size, $page, $sort, $order);
if($display == 'grid')
{
if(count($goodslist) % 2 != 0)
{
$goodslist[] = array();
}
}
$smarty->assign('goods_list', $goodslist);
$smarty->assign('category', $cat_id);
$smarty->assign('integral_max', $integral_max);
$smarty->assign('integral_min', $integral_min);
assign_pager('exchange', $cat_id, $count, $size, $sort, $order, $page, '', '', $integral_min, $integral_max, $display); // 分页
assign_dynamic('exchange_list'); // 动态内容
}
$smarty->assign('feed_url', ($_CFG['rewrite'] == 1) ? "feed-typeexchange.xml" : 'feed.php?type=exchange'); // RSS URL
$smarty->display('exchange_list.dwt', $cache_id);
}
/*------------------------------------------------------ */
//-- 积分兑换商品详情
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'view')
{
$goods_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
$cache_id = $goods_id . '-' . $_SESSION['user_rank'] . '-' . $_CFG['lang'] . '-exchange';
$cache_id = sprintf('%X', crc32($cache_id));
if (!$smarty->is_cached('exchange_goods.dwt', $cache_id))
{
$smarty->assign('image_width', $_CFG['image_width']);
$smarty->assign('image_height', $_CFG['image_height']);
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('id', $goods_id);
$smarty->assign('type', 0);
$smarty->assign('cfg', $_CFG);
$sql_attr_www_ecshop68_com="SELECT a.attr_id, ga.goods_attr_id FROM ". $GLOBALS['ecs']->table('attribute') . " AS a left join ". $GLOBALS['ecs']->table('goods_attr') . " AS ga on a.attr_id=ga.attr_id WHERE a.is_attr_gallery=1 and ga.goods_id='" . $goods_id. "' order by ga.goods_attr_id ";
$goods_attr=$GLOBALS['db']->getRow($sql_attr_www_ecshop68_com);
$goods_attr_id=$goods_attr['goods_attr_id'];
$smarty->assign('attr_id', $goods_attr['attr_id']);
if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'get_gallery_attr')
{
include('includes/cls_json.php');
$json = new JSON;
$goods_attr_id=$_REQUEST['goods_attr_id'];
$gallery_list_www_ecshop68_com=get_goods_gallery_attr_www_ecshop68_com($goods_id, $goods_attr_id);
$gallery_content=array();
$gallery_content['thumblist'] ='<ul>';
foreach($gallery_list_www_ecshop68_com as $gkey=>$gval)
{
$gallery_content['thumblist'] .= '<li>';
$gallery_content['thumblist'] .= '<a href="'. $gval['img_original'] . '" rel="zoom-id: zoom; zoom-height: 360px;zoom-width:400px;" rev="'.$gval['img_url'].'" name="'.$gval['img_url'].'" rev="'. $gval['img_original'] . '" ';
$gallery_content['thumblist'] .= '><img src="'. ($gval['thumb_url'] ? $gval['thumb_url'] : $gval['img_url']) . '" class="B_blue" ';
$gallery_content['thumblist'] .= ' /></a></li>';
if ($gkey==0)
{
$gallery_content['bigimg'] = $gval['img_original'] ;
$gallery_content['middimg'] .= $gval['img_url'] ;
}
}
$gallery_content['thumblist'] .='</ul>';
die ($json->encode($gallery_content));
}
if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'get_products_info')
{
include('includes/cls_json.php');
$json = new JSON;
// $res = array('err_msg' => '', 'result' => '', 'qty' => 1);
$spce_id = $_GET['id'];
$goods_id = $_GET['goods_id'];
$row = get_products_info($goods_id,explode(",",$spce_id));
//$res = array('err_msg'=>$goods_id,'id'=>$spce_id);
die($json->encode($row));
}
/* 获得商品的信息 */
$goods = get_exchange_goods_info($goods_id);
if ($goods === false)
{
/* 如果没有找到任何记录则跳回到首页 */
ecs_header("Location: ./\n");
exit;
}
else
{
if ($goods['brand_id'] > 0)
{
$goods['goods_brand_url'] = build_uri('brand', array('bid'=>$goods['brand_id']), $goods['goods_brand']);
}
$goods['goods_style_name'] = add_style($goods['goods_name'], $goods['goods_name_style']);
$smarty->assign('goods', $goods);
$smarty->assign('goods_id', $goods['goods_id']);
$smarty->assign('categories', get_categories_tree()); // 分类树
/* meta */
$smarty->assign('keywords', htmlspecialchars($goods['keywords']));
$smarty->assign('description', htmlspecialchars($goods['goods_brief']));
$count1 = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('comment') . " where comment_type=0 and id_value ='$goods_id' and status=1");
$smarty->assign('review_count', $count1);
//评价晒单 增加 by bbs.hongyuvip.com
$rank_num['rank_a'] = $db->getOne("SELECT COUNT(*) AS num FROM ".$ecs->table('comment')." WHERE id_value = '$goods_id' AND status = 1 AND comment_rank in (5,4)");
$rank_num['rank_b'] = $db->getOne("SELECT COUNT(*) AS num FROM ".$ecs->table('comment')." WHERE id_value = '$goods_id' AND status = 1 AND comment_rank in (3,2)");
$rank_num['rank_c'] = $db->getOne("SELECT COUNT(*) AS num FROM ".$ecs->table('comment')." WHERE id_value = '$goods_id' AND status = 1 AND comment_rank = 1");
$rank_num['rank_total'] = $rank_num['rank_a'] + $rank_num['rank_b'] + $rank_num['rank_c'];
$rank_num['rank_pa'] = ($rank_num['rank_a'] > 0) ? round(($rank_num['rank_a'] / $rank_num['rank_total']) * 100,1) : 0;
$rank_num['rank_pb'] = ($rank_num['rank_b'] > 0) ? round(($rank_num['rank_b'] / $rank_num['rank_total']) * 100,1) : 0;
$rank_num['rank_pc'] = ($rank_num['rank_c'] > 0) ? round(($rank_num['rank_c'] / $rank_num['rank_total']) * 100,1) : 0;
$rank_num['shaidan_num'] = $db->getOne("SELECT COUNT(*) AS num FROM ".$ecs->table('shaidan')." WHERE goods_id = '$goods_id' AND status = 1");
$smarty->assign('rank_num',$rank_num);
assign_template();
/* 上一个商品下一个商品 */
$sql = "SELECT eg.goods_id FROM " .$ecs->table('exchange_goods'). " AS eg," . $GLOBALS['ecs']->table('goods') . " AS g WHERE eg.goods_id = g.goods_id AND eg.goods_id > " . $goods['goods_id'] . " AND eg.is_exchange = 1 AND g.is_delete = 0 LIMIT 1";
$prev_gid = $db->getOne($sql);
if (!empty($prev_gid))
{
$prev_good['url'] = build_uri('exchange_goods', array('gid' => $prev_gid), $goods['goods_name']);
$smarty->assign('prev_good', $prev_good);//上一个商品
}
$sql = "SELECT max(eg.goods_id) FROM " . $ecs->table('exchange_goods') . " AS eg," . $GLOBALS['ecs']->table('goods') . " AS g WHERE eg.goods_id = g.goods_id AND eg.goods_id < ".$goods['goods_id'] . " AND eg.is_exchange = 1 AND g.is_delete = 0";
$next_gid = $db->getOne($sql);
if (!empty($next_gid))
{
$next_good['url'] = build_uri('exchange_goods', array('gid' => $next_gid), $goods['goods_name']);
$smarty->assign('next_good', $next_good);//下一个商品
}
/* current position */
$position = assign_ur_here('exchange', $goods['goods_name']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
$properties = get_goods_properties($goods_id); // 获得商品的规格和属性
$smarty->assign('properties', $properties['pro']); // 商品属性
$goodstype = "select goods_type from ".$ecs->table('goods')." where goods_id='". $goods_id ."'";
$goodstype_one = $db->getOne($goodstype);
/* 代码增加_start By bbs.hongyuvip.com */
$sql_zhyh_qq2211707 = "select attr_id from ".$ecs->table('attribute')." where cat_id='". $goodstype_one ."' and is_attr_gallery='1' ";
$attr_id_gallery = $db->getOne($sql_zhyh_qq2211707);
$sql = "SELECT goods_attr_id, attr_value FROM " . $GLOBALS['ecs']->table('goods_attr') . " WHERE goods_id = '$goods_id'";
$results_www_ecshop68_com = $GLOBALS['db']->getAll($sql);
$return_arr = array();
foreach ($results_www_ecshop68_com as $value_ecshop68)
{
$return_arr[$value_ecshop68['goods_attr_id']] = $value_ecshop68['attr_value'];
}
$prod_options_arr=array();
$prod_exist_arr = array();
$sql_prod = "select goods_attr from ". $GLOBALS['ecs']->table('products') ." where product_number>0 and goods_id='$goods_id' order by goods_attr";
$res_prod = $db->query($sql_prod);
while ($row_prod = $GLOBALS['db']->fetchRow($res_prod))
{
$prod_exist_arr[] = "|". $row_prod['goods_attr'] ."|";
}
$GLOBALS['smarty']->assign('prod_exist_arr', $prod_exist_arr);
$selected_first = array();
foreach ($properties['spe'] AS $skey_ecshop68=>$sval_ecshop68)
{
$hahaha_zhyh = 0;
$sskey_www_ecshop68_com = '-1';
foreach ($sval_ecshop68['values'] AS $sskey_ecshop68=>$ssval_ecshop68)
{
if ( is_exist_prod($selected_first, $ssval_ecshop68['id'], $prod_exist_arr))
{
$hahaha_zhyh = $hahaha_zhyh ? $hahaha_zhyh : $ssval_ecshop68['id'];
$sskey_www_ecshop68_com = ($sskey_www_ecshop68_com != '-1') ? $sskey_www_ecshop68_com : $sskey_ecshop68;
}
else
{
$properties['spe'][$skey_ecshop68]['values'][$sskey_ecshop68]['disabled'] = "disabled";
}
if ($skey_ecshop68==$attr_id_gallery)
{
$goods_attr_id_qq2211707 = $ssval_ecshop68['id'] ;
$sql_qq2211707_qq87139667 = "select thumb_url from ". $ecs->table('goods_gallery'). " where goods_id='$goods_id' and goods_attr_id='$goods_attr_id_qq2211707' and is_attr_image='1' ";
$properties['spe'][$skey_ecshop68]['values'][$sskey_ecshop68]['goods_attr_thumb'] = $db->getOne($sql_qq2211707_qq87139667);
}
}
if ($hahaha_zhyh)
{
$selected_first[$skey_ecshop68] = $hahaha_zhyh;
}
if ($sskey_www_ecshop68_com!='-1')
{
$properties['spe'][$skey_ecshop68]['values'][$sskey_www_ecshop68_com]['selected_key_ecshop68'] = "1";
}
}
$smarty->assign('is_goods_page', 1);
//echo '<pre>';
//print_r($properties['spe']);
//echo '</pre>';
/* 代码增加_end By bbs.hongyuvip.com */
$smarty->assign('specification', $properties['spe']); // 商品规格
$smarty->assign('pictures', get_goods_gallery_attr_www_ecshop68_com($goods_id, $goods_attr_id)); // 商品相册_修改 By bbs.hongyuvip.com
$smarty->assign('new_goods', get_recommend_goods('new')); // 最新商品 改 By bbs.hongyuvip.com
$smarty->assign('url', $_SERVER["REQUEST_URI"]);
assign_dynamic('exchange_goods');
}
}
$smarty->display('exchange_goods.dwt', $cache_id);
}
/*------------------------------------------------------ */
//-- 兑换
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'buy')
{
/* 查询:判断是否登录 */
if (!isset($back_act) && isset($GLOBALS['_SERVER']['HTTP_REFERER']))
{
$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'exchange') ? $GLOBALS['_SERVER']['HTTP_REFERER'] : './index.php';
}
/* 查询:判断是否登录 */
if ($_SESSION['user_id'] <= 0)
{
show_message($_LANG['eg_error_login'], array($_LANG['back_up_page']), array($back_act), 'error');
}
/* 查询:取得参数:商品id */
$goods_id = isset($_POST['goods_id']) ? intval($_POST['goods_id']) : 0;
if ($goods_id <= 0)
{
ecs_header("Location: ./\n");
exit;
}
/* 查询:取得兑换商品信息 */
$goods = get_exchange_goods_info($goods_id);
if (empty($goods))
{
ecs_header("Location: ./\n");
exit;
}
/* 查询:检查兑换商品是否有库存 */
if($goods['goods_number'] == 0 && $_CFG['use_storage'] == 1)
{
show_message($_LANG['eg_error_number'], array($_LANG['back_up_page']), array($back_act), 'error');
}
/* 查询:检查兑换商品是否是取消 */
if ($goods['is_exchange'] == 0)
{
show_message($_LANG['eg_error_status'], array($_LANG['back_up_page']), array($back_act), 'error');
}
$user_info = get_user_info($_SESSION['user_id']);
$user_points = $user_info['pay_points']; // 用户的积分总数
if ($goods['exchange_integral'] > $user_points)
{
show_message($_LANG['eg_error_integral'], array($_LANG['back_up_page']), array($back_act), 'error');
}
/* 查询:取得规格 */
$specs = '';
foreach ($_POST as $key => $value)
{
if (strpos($key, 'value_spec_') !== false)
{
$specs .= ',' . intval($value);
}
}
$specs = trim($specs, ',');
/* 查询:如果商品有规格则取规格商品信息 配件除外 */
if (!empty($specs))
{
$_specs = explode(',', $specs);
$product_info = get_products_info($goods_id, $_specs);
}
if (empty($product_info))
{
$product_info = array('product_number' => '', 'product_id' => 0);
}
//查询:商品存在规格 是货品 检查该货品库存
if((!empty($specs)) && ($product_info['product_number'] == 0) && ($_CFG['use_storage'] == 1))
{
show_message($_LANG['eg_error_number'], array($_LANG['back_up_page']), array($back_act), 'error');
}
/* 查询:查询规格名称和值,不考虑价格 */
$attr_list = array();
$sql = "SELECT a.attr_name, g.attr_value " .
"FROM " . $ecs->table('goods_attr') . " AS g, " .
$ecs->table('attribute') . " AS a " .
"WHERE g.attr_id = a.attr_id " .
"AND g.goods_attr_id " . db_create_in($specs);
$res = $db->query($sql);
while ($row = $db->fetchRow($res))
{
$attr_list[] = $row['attr_name'] . ': ' . $row['attr_value'];
}
$goods_attr = join(chr(13) . chr(10), $attr_list);
/* 更新:清空购物车中所有团购商品 */
include_once(ROOT_PATH . 'includes/lib_order.php');
clear_cart(CART_EXCHANGE_GOODS);
/* 更新:加入购物车 */
$number = 1;
$cart = array(
'user_id' => $_SESSION['user_id'],
'session_id' => SESS_ID,
'goods_id' => $goods['goods_id'],
'product_id' => $product_info['product_id'],
'goods_sn' => addslashes($goods['goods_sn']),
'goods_name' => addslashes($goods['goods_name']),
'market_price' => $goods['market_price'],
'goods_price' => 0,//$goods['exchange_integral']
'goods_number' => $number,
'goods_attr' => addslashes($goods_attr),
'goods_attr_id' => $specs,
'is_real' => $goods['is_real'],
'extension_code' => addslashes($goods['extension_code']),
'parent_id' => 0,
'rec_type' => CART_EXCHANGE_GOODS,
'is_gift' => 0
);
$db->autoExecute($ecs->table('cart'), $cart, 'INSERT');
$_SESSION['sel_cartgoods'] = $db->insert_id();
/* 记录购物流程类型:团购 */
$_SESSION['flow_type'] = CART_EXCHANGE_GOODS;
$_SESSION['extension_code'] = 'exchange_goods';
$_SESSION['extension_id'] = $goods_id;
/* 进入收货人页面 */
ecs_header("Location: ./flow.php?step=checkout\n");
exit;
}
/*------------------------------------------------------ */
//-- PRIVATE FUNCTION
/*------------------------------------------------------ */
/**
* 获得分类的信息
*
* @param integer $cat_id
*
* @return void
*/
function get_cat_info($cat_id)
{
return $GLOBALS['db']->getRow('SELECT keywords, cat_desc, style, grade, filter_attr, parent_id FROM ' . $GLOBALS['ecs']->table('category') .
" WHERE cat_id = '$cat_id'");
}
/**
* 获得分类下的商品
*
* @access public
* @param string $children
* @return array
*/
function exchange_get_goods($children, $min, $max, $ext, $size, $page, $sort, $order)
{
$display = $GLOBALS['display'];
$where = "eg.is_exchange = 1 AND g.is_delete = 0 AND ".
"($children OR " . get_extension_goods($children) . ')';
if ($min > 0)
{
$where .= " AND eg.exchange_integral >= $min ";
}
if ($max > 0)
{
$where .= " AND eg.exchange_integral <= $max ";
}
/* 获得商品列表 */
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, eg.exchange_integral, ' .
'g.goods_type, g.goods_brief, g.goods_thumb , g.goods_img, eg.is_hot ' .
'FROM ' . $GLOBALS['ecs']->table('exchange_goods') . ' AS eg, ' .$GLOBALS['ecs']->table('goods') . ' AS g ' .
"WHERE eg.goods_id = g.goods_id AND $where $ext ORDER BY $sort $order";
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);
$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
/* 处理商品水印图片 */
$watermark_img = '';
// if ($row['is_new'] != 0)
// {
// $watermark_img = "watermark_new_small";
// }
// elseif ($row['is_best'] != 0)
// {
// $watermark_img = "watermark_best_small";
// }
// else
if ($row['is_hot'] != 0)
{
$watermark_img = 'watermark_hot_small';
}
if ($watermark_img != '')
{
$arr[$row['goods_id']]['watermark_img'] = $watermark_img;
}
$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
if($display == 'grid')
{
$arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
}
else
{
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
}
$arr[$row['goods_id']]['name'] = $row['goods_name'];
$arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
$arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
$arr[$row['goods_id']]['exchange_integral'] = $row['exchange_integral'];
$arr[$row['goods_id']]['type'] = $row['goods_type'];
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$arr[$row['goods_id']]['url'] = build_uri('exchange_goods', array('gid'=>$row['goods_id']), $row['goods_name']);
}
return $arr;
}
/**
* 获得分类下的商品总数
*
* @access public
* @param string $cat_id
* @return integer
*/
function get_exchange_goods_count($children, $min = 0, $max = 0, $ext='')
{
$where = "eg.is_exchange = 1 AND g.is_delete = 0 AND ($children OR " . get_extension_goods($children) . ')';
if ($min > 0)
{
$where .= " AND eg.exchange_integral >= $min ";
}
if ($max > 0)
{
$where .= " AND eg.exchange_integral <= $max ";
}
$sql = 'SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('exchange_goods') . ' AS eg, ' .
$GLOBALS['ecs']->table('goods') . " AS g WHERE eg.goods_id = g.goods_id AND $where $ext";
/* 返回商品总数 */
return $GLOBALS['db']->getOne($sql);
}
/**
* 获得指定分类下的推荐商品
*
* @access public
* @param string $type 推荐类型,可以是 best, new, hot, promote
* @param string $cats 分类的ID
* @param integer $min 商品积分下限
* @param integer $max 商品积分上限
* @param string $ext 商品扩展查询
* @return array
*/
function get_exchange_recommend_goods($type = '', $cats = '', $min =0, $max = 0, $ext='')
{
$price_where = ($min > 0) ? " AND g.shop_price >= $min " : '';
$price_where .= ($max > 0) ? " AND g.shop_price <= $max " : '';
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, eg.exchange_integral, ' .
'g.goods_brief, g.goods_thumb, goods_img, b.brand_name ' .
'FROM ' . $GLOBALS['ecs']->table('exchange_goods') . ' AS eg ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = eg.goods_id ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' .
'WHERE eg.is_exchange = 1 AND g.is_delete = 0 ' . $price_where . $ext;
$num = 0;
$type2lib = array('best'=>'exchange_best', 'new'=>'exchange_new', 'hot'=>'exchange_hot');
$num = get_library_number($type2lib[$type], 'exchange_list');
switch ($type)
{
case 'best':
$sql .= ' AND eg.is_best = 1';
break;
case 'new':
$sql .= ' AND eg.is_new = 1';
break;
case 'hot':
$sql .= ' AND eg.is_hot = 1';
break;
}
if (!empty($cats))
{
$sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) .")";
}
$order_type = $GLOBALS['_CFG']['recommend_order'];
$sql .= ($order_type == 0) ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()';
$res = $GLOBALS['db']->selectLimit($sql, $num);
$idx = 0;
$goods = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$goods[$idx]['id'] = $row['goods_id'];
$goods[$idx]['name'] = $row['goods_name'];
$goods[$idx]['brief'] = $row['goods_brief'];
$goods[$idx]['brand_name'] = $row['brand_name'];
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods[$idx]['exchange_integral'] = $row['exchange_integral'];
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$goods[$idx]['url'] = build_uri('exchange_goods', array('gid' => $row['goods_id']), $row['goods_name']);
$goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']);
$idx++;
}
return $goods;
}
/**
* 获得积分兑换商品的详细信息
*
* @access public
* @param integer $goods_id
* @return void
*/
function get_exchange_goods_info($goods_id)
{
$time = gmtime();
$sql = 'SELECT g.*, c.measure_unit, b.brand_id, b.brand_name AS goods_brand, eg.exchange_integral, eg.is_exchange ' .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('exchange_goods') . ' AS eg ON g.goods_id = eg.goods_id ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON g.cat_id = c.cat_id ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON g.brand_id = b.brand_id ' .
"WHERE g.goods_id = '$goods_id' AND g.is_delete = 0 " .
'GROUP BY g.goods_id';
$row = $GLOBALS['db']->getRow($sql);
if ($row !== false)
{
/* 处理商品水印图片 */
$watermark_img = '';
if ($row['is_new'] != 0)
{
$watermark_img = "watermark_new";
}
elseif ($row['is_best'] != 0)
{
$watermark_img = "watermark_best";
}
elseif ($row['is_hot'] != 0)
{
$watermark_img = 'watermark_hot';
}
if ($watermark_img != '')
{
$row['watermark_img'] = $watermark_img;
}
/* 修正重量显示 */
$row['goods_weight'] = (intval($row['goods_weight']) > 0) ?
$row['goods_weight'] . $GLOBALS['_LANG']['kilogram'] :
($row['goods_weight'] * 1000) . $GLOBALS['_LANG']['gram'];
/* 修正上架时间显示 */
$row['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);
/* 修正商品图片 */
$row['goods_img'] = get_image_path($goods_id, $row['goods_img']);
$row['goods_thumb'] = get_image_path($goods_id, $row['goods_thumb'], true);
return $row;
}
else
{
return false;
}
}
/* 代码增加_start By bbs.hongyuvip.com */
/**
* 获得指定商品的相册
*
* @access public
* @param integer $goods_id
* @return array
*/
function get_goods_gallery_attr_www_ecshop68_com($goods_id, $goods_attr_id)
{
$sql = 'SELECT img_id, img_original, img_url, thumb_url, img_desc' .
' FROM ' . $GLOBALS['ecs']->table('goods_gallery') .
" WHERE goods_id = '$goods_id' and goods_attr_id='$goods_attr_id' LIMIT " . $GLOBALS['_CFG']['goods_gallery_number'];
$row = $GLOBALS['db']->getAll($sql);
if (count($row)==0)
{
$sql = 'SELECT img_id, img_original, img_url, thumb_url, img_desc' .
' FROM ' . $GLOBALS['ecs']->table('goods_gallery') .
" WHERE goods_id = '$goods_id' and goods_attr_id='0' LIMIT " . $GLOBALS['_CFG']['goods_gallery_number'];
$row = $GLOBALS['db']->getAll($sql);
}
/* 格式化相册图片路径 */
foreach($row as $key => $gallery_img)
{
$row[$key]['img_url'] = get_image_path($goods_id, $gallery_img['img_url'], false, 'gallery');
$row[$key]['thumb_url'] = get_image_path($goods_id, $gallery_img['thumb_url'], true, 'gallery');
$row[$key]['img_original'] = get_image_path($goods_id, $gallery_img['img_original'], true, 'gallery');
}
return $row;
}
/* 代码增加_end By bbs.hongyuvip.com */
?>