-
Notifications
You must be signed in to change notification settings - Fork 27
/
flow.php
4501 lines (3927 loc) · 169 KB
/
flow.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
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* 鸿宇多用户商城 购物流程
* ============================================================================
* 版权所有 2005-2010 鸿宇科技有限公司,并保留所有权利。
* 网站地址: http://bbs.hongyuvip.com;
* ----------------------------------------------------------------------------
* 仅供学习交流使用,如需商用请购买正版版权。鸿宇不承担任何法律责任。
* 踏踏实实做事,堂堂正正做人。
* ============================================================================
* $Author: douqinghua $
* $Id: flow.php 17218 2011-01-24 04:10:41Z douqinghua $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
require(ROOT_PATH . 'includes/lib_order.php');
/* 载入语言文件 */
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/user.php');
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/shopping_flow.php');
if($_REQUEST['act'] == 'edit_user_mobile'){
include('includes/cls_json.php');
$json = new JSON;
$sql = "UPDATE ".$GLOBALS['ecs']->table('users')." set mobile_phone = '".$_REQUEST['mobile_phone']."' where user_id =".$_SESSION['user_id'];
$res = $GLOBALS['db'] ->query($sql);
if($res){
die($json->encode(Array('state'=>1,'value'=>$_REQUEST['mobile_phone'])));
}else{
die($json->encode(Array('state'=>0,'value'=>'')));
}
}
/* 代码增加_start BY bbs.hongyuvip.com */
if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'selcart')
{
include('includes/cls_json.php');
$json = new JSON;
$res = array('err_msg' => '', 'result' => '');
if ($_GET['sel_goods'])
{
$id_ext = " AND rec_id in (". $_GET['sel_goods'] .") ";
$_SESSION['sel_cartgoods'] = $_GET['sel_goods'];
$cart_goods = get_cart_goods($id_ext);
$shopping_money = sprintf($_LANG['shopping_money'], $cart_goods['total']['goods_price']);
$market_price_desc= sprintf($_LANG['than_market_price'],
$cart_goods['total']['market_price'], $cart_goods['total']['saving'], $cart_goods['total']['save_rate']);
$res['result'] = $shopping_money;
if ($_CFG['show_marketprice'])
{
$res['result'] .= ",".$market_price_desc ;
}
//折扣活动
$res['suppid'] = intval($_GET['suppid']);
$res['your_discount'] = '';
$discount = compute_discount($res['suppid']);
if(is_array($discount)){
$favour_name = empty($discount['name']) ? '' : join(',', $discount['name']);
$res['your_discount'] = sprintf($_LANG['your_discount'], $favour_name, price_format($discount['discount']));
}
}
else
{
$res['result'] = '您一个商品都没选,这怎么行捏!!真的不行哦!';
}
die($json->encode($res));
}
/* 代码增加_end BY bbs.hongyuvip.com */
/* 代码增加_start By bbs.hongyuvip.com */
$_CFG['anonymous_buy']='0';
$smarty->assign('lang', $_LANG);
if ($_REQUEST['act']=='EditAddress')
{
include_once('includes/cls_json.php');
include_once('includes/lib_transaction.php');
$result = array('error' => 0, 'message' => '', 'content' => '');
$json = new JSON;
$address_id = intval($_GET['address_id']);
if ($address_id)
{
$sql="select * from ". $ecs->table('user_address') ." where address_id='$address_id' ";
$address_info = $db->getRow($sql);
if ($address_info)
{
$address_info['tel_array'] = explode("-", $address_info['tel']);
}
$smarty->assign('address', $address_info);
$province_list = get_regions(1, $address_info['country']);
$city_list = get_regions(2, $address_info['province']);
$district_list = get_regions(3, $address_info['city']);
$smarty->assign('province_list', $province_list);
$smarty->assign('city_list', $city_list);
$smarty->assign('district_list', $district_list);
}
else
{
$smarty->assign('province_list', get_regions(1, $_CFG['shop_country']));
}
$result['content'] = $smarty->fetch("library/address_edit.lbi");
die($json->encode($result));
}
elseif ($_REQUEST['act']=='selAddress')
{
include_once('includes/cls_json.php');
$order = flow_order_info();
$result = array('error' => 0, 'message' => '', 'content' => '');
$json = new JSON;
$address_id = intval($_GET['address_id']);
$sql = "update ". $GLOBALS['ecs']->table('users') ." set address_id='". $_REQUEST['address_id'] ."' where user_id='".$_SESSION['user_id']."' ";
$db->query($sql);
$sql = "SELECT * ".
" FROM " . $GLOBALS['ecs']->table('user_address') .
" WHERE address_id = '".$_REQUEST['address_id']."' ";
$consignee = $GLOBALS['db']->getRow($sql);
$_SESSION['flow_consignee'] = $consignee;
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
$region = array($consignee['country'], $consignee['province'], $consignee['city'], $consignee['district']);
$shipping_list = available_shipping_list($region);
$cart_weight_price = cart_weight_price($flow_type);
$insure_disabled = true;
$cod_disabled = true;
// 查看购物车中是否全为免运费商品,若是则把运费赋为零
$sql = 'SELECT count(*) FROM ' . $ecs->table('cart') . " WHERE `session_id` = '" . SESS_ID. "' AND `extension_code` != 'package_buy' AND `is_shipping` = 0";
$shipping_count = $db->getOne($sql);
foreach ($shipping_list AS $key => $val)
{
$shipping_cfg = unserialize_config($val['configure']);
$shipping_fee = ($shipping_count == 0 AND $cart_weight_price['free_shipping'] == 1) ? 0 : shipping_fee($val['shipping_code'], unserialize($val['configure']),
$cart_weight_price['weight'], $cart_weight_price['amount'], $cart_weight_price['number']);
$shipping_list[$key]['format_shipping_fee'] = price_format($shipping_fee, false);
$shipping_list[$key]['shipping_fee'] = $shipping_fee;
$shipping_list[$key]['free_money'] = price_format($shipping_cfg['free_money'], false);
$shipping_list[$key]['insure_formated'] = strpos($val['insure'], '%') === false ?
price_format($val['insure'], false) : $val['insure'];
/* 当前的配送方式是否支持保价 */
if ($val['shipping_id'] == $order['shipping_id'])
{
$insure_disabled = ($val['insure'] == 0);
$cod_disabled = ($val['support_cod'] == 0);
}
}
$smarty->assign('shipping_list', $shipping_list);
$smarty->assign('insure_disabled', $insure_disabled);
$smarty->assign('cod_disabled', $cod_disabled);
$result['content'] = $smarty->fetch('library/shipping_box.lbi');
die($json->encode($result));
}
elseif ($_REQUEST['act']=='delAddress')
{
include_once('includes/cls_json.php');
include_once('includes/lib_transaction.php');
$order = flow_order_info();
$result = array('error' => 0, 'message' => '', 'content' => '', 'content2'=>'');
$json = new JSON;
$address_id = intval($_GET['address_id']);
drop_consignee($address_id);
$consignee_list = get_consignee_list_ecshop68();
if($_SESSION['flow_consignee']['address_id']==$address_id)
{
if ($consignee_list)
{
$_SESSION['flow_consignee'] = $consignee_list[0];
$region = array($consignee_list[0]['country'], $consignee_list[0]['province'], $consignee_list[0]['city'], $consignee_list[0]['district']);
}
else
{
$_SESSION['flow_consignee']="";
$region = array(1, 0, 0, 0);
}
$shipping_bian=1;
}
else
{
if ($consignee_list)
{
$shipping_bian=0;
}
}
$smarty->assign('consignee_list', $consignee_list);
$smarty->assign('name_of_region', array($_CFG['name_of_region_1'], $_CFG['name_of_region_2'], $_CFG['name_of_region_3'], $_CFG['name_of_region_4']));
$smarty->assign('shop_province_list', get_regions(1, $_CFG['shop_country']));
$result['content'] = $smarty->fetch("library/address_list.lbi");
if($shipping_bian)
{
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
$shipping_list = available_shipping_list($region);
$cart_weight_price = cart_weight_price($flow_type);
$insure_disabled = true;
$cod_disabled = true;
// 查看购物车中是否全为免运费商品,若是则把运费赋为零
$sql = 'SELECT count(*) FROM ' . $ecs->table('cart') . " WHERE `session_id` = '" . SESS_ID. "' AND `extension_code` != 'package_buy' AND `is_shipping` = 0";
$shipping_count = $db->getOne($sql);
foreach ($shipping_list AS $key => $val)
{
$shipping_cfg = unserialize_config($val['configure']);
$shipping_fee = ($shipping_count == 0 AND $cart_weight_price['free_shipping'] == 1) ? 0 : shipping_fee($val['shipping_code'], unserialize($val['configure']),
$cart_weight_price['weight'], $cart_weight_price['amount'], $cart_weight_price['number']);
$shipping_list[$key]['format_shipping_fee'] = price_format($shipping_fee, false);
$shipping_list[$key]['shipping_fee'] = $shipping_fee;
$shipping_list[$key]['free_money'] = price_format($shipping_cfg['free_money'], false);
$shipping_list[$key]['insure_formated'] = strpos($val['insure'], '%') === false ?
price_format($val['insure'], false) : $val['insure'];
/* 当前的配送方式是否支持保价 */
if ($val['shipping_id'] == $order['shipping_id'])
{
$insure_disabled = ($val['insure'] == 0);
$cod_disabled = ($val['support_cod'] == 0);
}
}
$smarty->assign('shipping_list', $shipping_list);
$smarty->assign('insure_disabled', $insure_disabled);
$smarty->assign('cod_disabled', $cod_disabled);
$result['content2'] = $smarty->fetch('library/shipping_box.lbi');
}
if ($consignee_list)
{
$result['have_consignee'] = '1';
}
else
{
$result['have_consignee'] = '0';
}
die($json->encode($result));
}
elseif ($_REQUEST['act']=='saveAddress')
{
include_once('includes/cls_json.php');
include_once('includes/lib_transaction.php');
$json = new JSON;
/* 保存收货地址信息_start */
$_POST['address']=strip_tags(urldecode($_POST['address']));
$_POST['address'] = json_str_iconv($_POST['address']);
$address_ecshop68 = $json->decode($_POST['address']);
$consignee = array(
'address_id' => empty($address_ecshop68->address_id) ? '0' : intval($address_ecshop68->address_id),
'consignee' => empty($address_ecshop68->consignee) ? '' : compile_str(trim($address_ecshop68->consignee)),
'country' => empty($address_ecshop68->country) ? '1' : intval($address_ecshop68->country),
'province' => empty($address_ecshop68->province) ? '' : intval($address_ecshop68->province),
'city' => empty($address_ecshop68->city) ? '' : intval($address_ecshop68->city),
'district' => empty($address_ecshop68->district) ? '' : intval($address_ecshop68->district),
'email' => empty($address_ecshop68->email) ? '' : compile_str($address_ecshop68->email),
'address' => empty($address_ecshop68->address) ? '' : compile_str($address_ecshop68->address),
'zipcode' => empty($address_ecshop68->zipcode) ? '' : compile_str(make_semiangle(trim($address_ecshop68->zipcode))),
'tel' => empty($address_ecshop68->tel) ? '' : compile_str(make_semiangle(trim($address_ecshop68->tel))),
'mobile' => empty($address_ecshop68->mobile) ? '' : compile_str(make_semiangle(trim($address_ecshop68->mobile))),
);
if ($_SESSION['user_id'] > 0)
{
/* 如果用户已经登录,则保存收货人信息 */
$consignee['user_id'] = $_SESSION['user_id'];
save_consignee($consignee, true);
}
/* 保存收货地址信息_end */
$result = array('error' => 0, 'message' => '', 'content' => '', 'closediv'=>$address_ecshop68->closediv);
$consignee_list = get_consignee_list_ecshop68();
$smarty->assign('consignee_list', $consignee_list);
$result['content'] = $smarty->fetch("library/address_list.lbi");
if($consignee_list && count($consignee_list)==1)
{
$_SESSION['flow_consignee'] = $consignee_list[0];
}
if ($address_ecshop68->shipping_bian=='0' && $address_ecshop68->address_id>0 && $address_ecshop68->address_id==$_SESSION['flow_consignee']['address_id'])
{
$sql = "SELECT * ".
" FROM " . $GLOBALS['ecs']->table('user_address') .
" WHERE address_id = '".$address_ecshop68->address_id."' ";
$consignee = $GLOBALS['db']->getRow($sql);
$_SESSION['flow_consignee'] = $consignee;
}
if ($address_ecshop68->shipping_bian=='1' || ($address_ecshop68->shipping_bian=='0' && $address_ecshop68->address_id>0 && $address_ecshop68->address_id==$_SESSION['flow_consignee']['address_id']))
{
$order = flow_order_info();
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
$region = array($consignee['country'], $consignee['province'], $consignee['city'], $consignee['district']);
$shipping_list = available_shipping_list($region);
$cart_weight_price = cart_weight_price($flow_type);
$insure_disabled = true;
$cod_disabled = true;
// 查看购物车中是否全为免运费商品,若是则把运费赋为零
$sql = 'SELECT count(*) FROM ' . $ecs->table('cart') . " WHERE `session_id` = '" . SESS_ID. "' AND `extension_code` != 'package_buy' AND `is_shipping` = 0";
$shipping_count = $db->getOne($sql);
foreach ($shipping_list AS $key => $val)
{
$shipping_cfg = unserialize_config($val['configure']);
$shipping_fee = ($shipping_count == 0 AND $cart_weight_price['free_shipping'] == 1) ? 0 : shipping_fee($val['shipping_code'], unserialize($val['configure']),
$cart_weight_price['weight'], $cart_weight_price['amount'], $cart_weight_price['number']);
$shipping_list[$key]['format_shipping_fee'] = price_format($shipping_fee, false);
$shipping_list[$key]['shipping_fee'] = $shipping_fee;
$shipping_list[$key]['free_money'] = price_format($shipping_cfg['free_money'], false);
$shipping_list[$key]['insure_formated'] = strpos($val['insure'], '%') === false ?
price_format($val['insure'], false) : $val['insure'];
/* 当前的配送方式是否支持保价 */
if ($val['shipping_id'] == $order['shipping_id'])
{
$insure_disabled = ($val['insure'] == 0);
$cod_disabled = ($val['support_cod'] == 0);
}
}
$smarty->assign('shipping_list', $shipping_list);
$smarty->assign('insure_disabled', $insure_disabled);
$smarty->assign('cod_disabled', $cod_disabled);
$result['content2'] = $smarty->fetch('library/shipping_box.lbi');
}
die($json->encode($result));
}
function get_consignee_list_ecshop68()
{
$consignee = get_consignee($_SESSION['user_id']);
$sql="SELECT * FROM " . $GLOBALS['ecs']->table('user_address') .
" WHERE user_id = '". $_SESSION['user_id'] ."' order by address_id ";
$consignee_list_ecshop68 = $GLOBALS['db']->getAll($sql);
foreach ($consignee_list_ecshop68 as $cons_key => $cons_val)
{
$consignee_list_ecshop68[$cons_key]['address_short_name'] = $cons_val['consignee']."<br>";
$consignee_list_ecshop68[$cons_key]['address_short_name'] .= get_region_info($cons_val['province'])."-";
$consignee_list_ecshop68[$cons_key]['address_short_name'] .= get_region_info($cons_val['city'])."-";
$consignee_list_ecshop68[$cons_key]['address_short_name'] .= get_region_info($cons_val['district'])." ";
$consignee_list_ecshop68[$cons_key]['address_short_name'] .= sub_str($cons_val['address'],16);
$consignee_list_ecshop68[$cons_key]['address_short_name'] .= $cons_val['zipcode'] ? (",".$cons_val['zipcode']) : "";
$consignee_list_ecshop68[$cons_key]['address_short_name'] .= "<br>".(empty($cons_val['mobile']) ? $cons_val['tel'] : $cons_val['mobile']);
if ($consignee['address_id'] == $cons_val['address_id'])
{
$consignee_list_ecshop68[$cons_key]['def_addr'] =1;
$have_def_addr=1;
}
}
if ( count($consignee_list_ecshop68) && !$have_def_addr){ $consignee_list_ecshop68[0]['def_addr'] =1; }
return $consignee_list_ecshop68;
}
/* 代码增加_end By bbs.hongyuvip.com */
/*------------------------------------------------------ */
//-- INPUT
/*------------------------------------------------------ */
if (!isset($_REQUEST['step']))
{
$_REQUEST['step'] = "cart";
}
/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */
assign_template();
assign_dynamic('flow');
$position = assign_ur_here(0, $_LANG['shopping_flow']);
$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('lang', $_LANG);
$smarty->assign('show_marketprice', $_CFG['show_marketprice']);
$smarty->assign('data_dir', DATA_DIR); // 数据目录
/*------------------------------------------------------ */
//-- 添加商品到购物车
/*------------------------------------------------------ */
if ($_REQUEST['step'] == 'add_to_cart')
{
include_once('includes/cls_json.php');
$_POST['goods']=strip_tags(urldecode($_POST['goods']));
$_POST['goods'] = json_str_iconv($_POST['goods']);
if (!empty($_REQUEST['goods_id']) && empty($_POST['goods']))
{
if (!is_numeric($_REQUEST['goods_id']) || intval($_REQUEST['goods_id']) <= 0)
{
ecs_header("Location:./\n");
}
$goods_id = intval($_REQUEST['goods_id']);
exit;
}
$result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '');
$json = new JSON;
if (empty($_POST['goods']))
{
$result['error'] = 1;
die($json->encode($result));
}
$goods = $json->decode($_POST['goods']);
/* 判断是否为正在预售的商品 */
if(!isset($goods->extCode) || $goods->extCode != 'pre_sale')
{
$pre_sale_id = is_pre_sale_goods($goods->goods_id);
if($pre_sale_id != null)
{
/* 进入收货人页面 */
$uri = build_uri("pre_sale", array("pre_sale_id" => $pre_sale_id));
$result['error'] = 777;
$result['message'] = "此商品为预售商品,点击确定按钮将跳转到预售商品详情页面!";
$result['uri'] = $uri;
die($json->encode($result));
}
}
//bbs.hongyuvip.com start add 2015-3-26
$time_xg_now=gmtime();
$row_xg= $GLOBALS['db']->getRow("select is_buy,buymax, buymax_start_date, buymax_end_date from ". $GLOBALS['ecs']->table('goods') ." where goods_id='".$goods->goods_id."' " );
if ( $row_xg['is_buy'] == 1 && $row_xg['buymax'] >0 && $row_xg['buymax_start_date'] < $time_xg_now && $row_xg['buymax_end_date'] > $time_xg_now )
{
if ($_SESSION['user_id'] == 0 )
{
$result['error'] = 999;
$result['message'] = "此商品为限购商品,需要登录后才能继续购买!";
die($json->encode($result));
}
else
{
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
$num_cart_old_1=$GLOBALS['db']->getOne("select sum(goods_number) from ". $GLOBALS['ecs']->table('cart') ." where " . $sql_where . " and goods_id= " . $goods->goods_id );
$num_cart_old_2=$GLOBALS['db']->getOne("select sum(og.goods_number) from ". $GLOBALS['ecs']->table('order_goods') ." AS og , ". $GLOBALS['ecs']->table('order_info') ." AS o where o.user_id='$_SESSION[user_id]' and o.order_id = og.order_id and add_time > ". $row_xg['buymax_start_date'] ." and add_time < ". $row_xg['buymax_end_date'] ." and og.goods_id = " . $goods->goods_id );
$num_cart_old = $num_cart_old_1 + $num_cart_old_2 ;
$num_total = $num_cart_old + intval($goods->number);
if ( $num_total > intval($row_xg['buymax']) )
{
$result['error'] = 888;
$num_else=intval($row_xg['buymax'])-$num_cart_old_2;
$result['message'] ="注意:\n\r此商品限购期间每人限购 ". $row_xg['buymax'] . " 件\n\r";
if ($num_cart_old_2 > 0)
{
$result['message'] .="您在限购期间已经成功购买过". $num_cart_old_2 ." 件!\n\r";
}
if ($num_cart_old_1 > 0)
{
$result['message'] .="您的购物车中已经存在". $num_cart_old_1 ."件!\n\r";
}
$result['message'] .= "您只能再买 ". $num_else ." 件";
die($json->encode($result));
}
}
}
//bbs.hongyuvip.com end add 2015-3-26
/* 检查:如果商品有规格,而post的数据没有规格,把商品的规格属性通过JSON传到前台 */
if (empty($goods->spec) AND empty($goods->quick))
{
$sql = "SELECT a.attr_id, a.attr_name, a.attr_type, ".
"g.goods_attr_id, g.attr_value, g.attr_price " .
'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .
"WHERE a.attr_type != 0 AND g.goods_id = '" . $goods->goods_id . "' " .
'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
$res = $GLOBALS['db']->getAll($sql);
if (!empty($res))
{
$spe_arr = array();
foreach ($res AS $row)
{
$spe_arr[$row['attr_id']]['attr_type'] = $row['attr_type'];
$spe_arr[$row['attr_id']]['name'] = $row['attr_name'];
$spe_arr[$row['attr_id']]['attr_id'] = $row['attr_id'];
$spe_arr[$row['attr_id']]['values'][] = array(
'label' => $row['attr_value'],
'price' => $row['attr_price'],
'format_price' => price_format($row['attr_price'], false),
'id' => $row['goods_attr_id']);
}
$i = 0;
$spe_array = array();
foreach ($spe_arr AS $row)
{
$spe_array[]=$row;
}
$result['error'] = ERR_NEED_SELECT_ATTR;
$result['goods_id'] = $goods->goods_id;
$result['parent'] = $goods->parent;
$result['message'] = $spe_array;
die($json->encode($result));
}
}
/* 更新:如果是一步购物,先清空购物车 */
//if ($_CFG['one_step_buy'] == '1')
if ($_COOKIE['one_step_buy'] == 1)
{
//根据预售已改
clear_cart();
}
/* 检查:商品数量是否合法 */
if (!is_numeric($goods->number) || intval($goods->number) <= 0)
{
$result['error'] = 1;
$result['message'] = $_LANG['invalid_number'];
}
/* 更新:购物车 */
else
{
if(!empty($goods->spec))
{
foreach ($goods->spec as $key=>$val )
{
$goods->spec[$key]=intval($val);
}
}
// 更新:添加到购物车
if (addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent))
{
if ($_CFG['cart_confirm'] > 2)
{
$result['message'] = '';
}
else
{
$result['message'] = $_CFG['cart_confirm'] == 1 ? $_LANG['addto_cart_success_1'] : $_LANG['addto_cart_success_2'];
}
$result['content'] = insert_cart_info();
//$result['one_step_buy'] = $_CFG['one_step_buy'];
$result['one_step_buy'] = $_COOKIE['one_step_buy'];
}
else
{
$result['message'] = $err->last_message();
$result['error'] = $err->error_no;
$result['goods_id'] = stripslashes($goods->goods_id);
if (is_array($goods->spec))
{
$result['product_spec'] = implode(',', $goods->spec);
}
else
{
$result['product_spec'] = $goods->spec;
}
}
}
$rows = $GLOBALS['db']->getRow("select goods_brief,shop_price,goods_name,promote_end_date,promote_start_date,promote_price,goods_thumb from ".$GLOBALS['ecs']->table('goods')." where goods_id=".$goods->goods_id);
$time1 = gmtime();
if ($time1 >= $rows['promote_start_date'] && $time1 <= $rows['promote_end_date'] && $rows['promote_price'] > 0)
{
$result['shop_price'] = price_format($rows['promote_price']);
}else{
$result['shop_price'] = price_format($rows['shop_price']);
}
$result['goods_name'] = $rows['goods_name'];
$result['goods_thumb'] = $rows['goods_thumb'];
$result['goods_brief'] = $rows['goods_brief'];
$result['goods_id'] = $goods->goods_id;
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";//添加 bbs.hongyuvip.com
$sql = 'SELECT SUM(goods_number) AS number, SUM(goods_price * goods_number) AS amount' .
' FROM ' . $GLOBALS['ecs']->table('cart') .
" WHERE ".$sql_where." AND rec_type = '" . CART_GENERAL_GOODS . "'";
$rowss = $GLOBALS['db']->GetRow($sql);
$result['goods_price'] = price_format($rowss['amount']);
$result['goods_number'] = $rowss['number'];
$result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2;
die($json->encode($result));
}
elseif ($_REQUEST['step'] == 'link_buy')
{
$goods_id = intval($_GET['goods_id']);
if (!cart_goods_exists($goods_id,array()))
{
addto_cart($goods_id);
}
ecs_header("Location:./flow.php\n");
exit;
}
elseif ($_REQUEST['step'] == 'login')
{
include_once('languages/'. $_CFG['lang']. '/user.php');
/*
* 用户登录注册
*/
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
$smarty->assign('anonymous_buy', $_CFG['anonymous_buy']);
/* 检查是否有赠品,如果有提示登录后重新选择赠品 */
/* 代码增加_start By bbs.hongyuvip.com*/
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
$sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') .
" WHERE $sql_where AND is_gift > 0";
if ($db->getOne($sql) > 0)
{
$smarty->assign('need_rechoose_gift', 1);
}
/* 代码增加_end By bbs.hongyuvip.com */
/* 检查是否需要注册码 */
$captcha = intval($_CFG['captcha']);
if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
{
$smarty->assign('enabled_login_captcha', 1);
$smarty->assign('rand', mt_rand());
}
if ($captcha & CAPTCHA_REGISTER)
{
$smarty->assign('enabled_register_captcha', 1);
$smarty->assign('rand', mt_rand());
}
}
else
{
include_once('includes/lib_passport.php');
if (!empty($_POST['act']) && $_POST['act'] == 'signin')
{
$captcha = intval($_CFG['captcha']);
if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
{
if (empty($_POST['captcha']))
{
show_message($_LANG['invalid_captcha']);
}
/* 检查验证码 */
include_once('includes/cls_captcha.php');
$validator = new captcha();
$validator->session_word = 'captcha_login';
if (!$validator->check_word($_POST['captcha']))
{
show_message($_LANG['invalid_captcha']);
}
}
$_POST['password']=isset($_POST['password']) ? trim($_POST['password']) : '';
if ($user->login($_POST['username'], $_POST['password'],isset($_POST['remember'])))
{
update_user_info(); //更新用户信息
recalculate_price(); // 重新计算购物车中的商品价格
/* 检查购物车中是否有商品 没有商品则跳转到首页 */
/* 代码增加_end By bbs.hongyuvip.com */
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
$sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') . " WHERE $sql_where ";
/* 代码增加_end By bbs.hongyuvip.com */
if ($db->getOne($sql) > 0)
{
ecs_header("Location: flow.php?step=checkout\n");
}
else
{
ecs_header("Location:index.php\n");
}
exit;
}
else
{
$_SESSION['login_fail']++;
show_message($_LANG['signin_failed'], '', 'flow.php?step=login');
}
}
elseif (!empty($_POST['act']) && $_POST['act'] == 'signup')
{
if ((intval($_CFG['captcha']) & CAPTCHA_REGISTER) && gd_version() > 0)
{
if (empty($_POST['captcha']))
{
show_message($_LANG['invalid_captcha']);
}
/* 检查验证码 */
include_once('includes/cls_captcha.php');
$validator = new captcha();
if (!$validator->check_word($_POST['captcha']))
{
show_message($_LANG['invalid_captcha']);
}
}
if (register(trim($_POST['username']), trim($_POST['password']), trim($_POST['email'])))
{
/* 用户注册成功 */
/* 四合一修改 start by bbs.hongyuvip.com */
ecs_header("Location: flow.php?step=checkout\n");
/* 四合一修改 end by bbs.hongyuvip.com */
exit;
}
else
{
$err->show();
}
}
else
{
// TODO: 非法访问的处理
}
}
}
elseif ($_REQUEST['step'] == 'consignee')
{
/*------------------------------------------------------ */
//-- 收货人信息
/*------------------------------------------------------ */
include_once('includes/lib_transaction.php');
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
/* 取得购物类型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/*
* 收货人信息填写界面
*/
if (isset($_REQUEST['direct_shopping']))
{
$_SESSION['direct_shopping'] = 1;
}
/* 取得国家列表、商店所在国家、商店所在国家的省列表 */
$smarty->assign('country_list', get_regions());
$smarty->assign('shop_country', $_CFG['shop_country']);
$smarty->assign('shop_province_list', get_regions(1, $_CFG['shop_country']));
/* 获得用户所有的收货人信息 */
if ($_SESSION['user_id'] > 0)
{
$consignee_list = get_consignee_list($_SESSION['user_id']);
if (count($consignee_list) < 5)
{
/* 如果用户收货人信息的总数小于 5 则增加一个新的收货人信息 */
$consignee_list[] = array('country' => $_CFG['shop_country'], 'email' => isset($_SESSION['email']) ? $_SESSION['email'] : '');
}
}
else
{
if (isset($_SESSION['flow_consignee'])){
$consignee_list = array($_SESSION['flow_consignee']);
}
else
{
$consignee_list[] = array('country' => $_CFG['shop_country']);
}
}
$smarty->assign('name_of_region', array($_CFG['name_of_region_1'], $_CFG['name_of_region_2'], $_CFG['name_of_region_3'], $_CFG['name_of_region_4']));
$smarty->assign('consignee_list', $consignee_list);
/* 取得每个收货地址的省市区列表 */
$province_list = array();
$city_list = array();
$district_list = array();
foreach ($consignee_list as $region_id => $consignee)
{
$consignee['country'] = isset($consignee['country']) ? intval($consignee['country']) : 0;
$consignee['province'] = isset($consignee['province']) ? intval($consignee['province']) : 0;
$consignee['city'] = isset($consignee['city']) ? intval($consignee['city']) : 0;
$province_list[$region_id] = get_regions(1, $consignee['country']);
$city_list[$region_id] = get_regions(2, $consignee['province']);
$district_list[$region_id] = get_regions(3, $consignee['city']);
}
$smarty->assign('province_list', $province_list);
$smarty->assign('city_list', $city_list);
$smarty->assign('district_list', $district_list);
/* 返回收货人页面代码 */
$smarty->assign('real_goods_count', exist_real_goods(0, $flow_type) ? 1 : 0);
}
else
{
/*
* 保存收货人信息
*/
$consignee = array(
'address_id' => empty($_POST['address_id']) ? 0 : intval($_POST['address_id']),
'consignee' => empty($_POST['consignee']) ? '' : compile_str(trim($_POST['consignee'])),
'country' => empty($_POST['country']) ? '' : intval($_POST['country']),
'province' => empty($_POST['province']) ? '' : intval($_POST['province']),
'city' => empty($_POST['city']) ? '' : intval($_POST['city']),
'district' => empty($_POST['district']) ? '' : intval($_POST['district']),
'email' => empty($_POST['email']) ? '' : compile_str($_POST['email']),
'address' => empty($_POST['address']) ? '' : compile_str($_POST['address']),
'zipcode' => empty($_POST['zipcode']) ? '' : compile_str(make_semiangle(trim($_POST['zipcode']))),
'tel' => empty($_POST['tel']) ? '' : compile_str(make_semiangle(trim($_POST['tel']))),
'mobile' => empty($_POST['mobile']) ? '' : compile_str(make_semiangle(trim($_POST['mobile']))),
'sign_building' => empty($_POST['sign_building']) ? '' :compile_str($_POST['sign_building']),
'best_time' => empty($_POST['best_time']) ? '' : compile_str($_POST['best_time']),
);
if ($_SESSION['user_id'] > 0)
{
include_once(ROOT_PATH . 'includes/lib_transaction.php');
/* 如果用户已经登录,则保存收货人信息 */
$consignee['user_id'] = $_SESSION['user_id'];
save_consignee($consignee, true);
}
/* 保存到session */
$_SESSION['flow_consignee'] = stripslashes_deep($consignee);
ecs_header("Location: flow.php?step=checkout\n");
exit;
}
}
elseif ($_REQUEST['step'] == 'drop_consignee')
{
/*------------------------------------------------------ */
//-- 删除收货人信息
/*------------------------------------------------------ */
include_once('includes/lib_transaction.php');
$consignee_id = intval($_GET['id']);
if (drop_consignee($consignee_id))
{
ecs_header("Location: flow.php?step=consignee\n");
exit;
}
else
{
show_message($_LANG['not_fount_consignee']);
}
}
elseif ($_REQUEST['step'] == 'checkout')
{
/*------------------------------------------------------ */
//-- 订单确认
/*------------------------------------------------------ */
/*
* 检查用户是否已经登录
* 如果没有登录则跳转到登录和注册页面
*/
if ($_SESSION['user_id'] == 0)
{
/* 用户没有登录且没有选定匿名购物,转向到登录页面 */
ecs_header("Location: user.php\n");
exit;
}
//$_SESSION['flow_consignee']['mobile']
/* 取得购物类型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/* 团购标志 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$smarty->assign('is_group_buy', 1);
}
/* 积分兑换商品 */
elseif ($flow_type == CART_EXCHANGE_GOODS)
{
$smarty->assign('is_exchange_goods', 1);
}
/* 预售标识 */
else if($flow_type == CART_PRE_SALE_GOODS)
{
$smarty->assign('is_pre_sale', 1);
}
/* 虚拟团购 */
// else if($_SESSION['extension_code'] == 'virtual_good')
else if($flow_type == CART_VIRTUAL_GROUP_GOODS)
{
$smarty -> assign('mobile_phone',$GLOBALS['db']->getOne("select mobile_phone from ".$GLOBALS['ecs']->table('users')." where user_id='$_SESSION[user_id]'"));
$smarty->assign('is_virtual', 1);
}
else
{
//正常购物流程 清空其他购物流程情况
$_SESSION['extension_code'] = '';
}
if($flow_type != CART_EXCHANGE_GOODS ){
//非积分兑换形式的商品
/* 代码增加_start By bbs.hongyuvip.com */
$sel_cartgoods_count = count($_REQUEST['sel_cartgoods']);
$_SESSION['sel_cartgoods'] = $sel_cartgoods_count>0 ? (implode(",", $_REQUEST['sel_cartgoods'])) : $_SESSION['sel_cartgoods'];
/* 代码增加_end By bbs.hongyuvip.com */
//验证购物车中提交过来的商品中参加的活动是否都正常start
$_REQUEST['sel_goods'] = $_SESSION['sel_cartgoods'];
if(empty($_REQUEST['sel_goods'])){
ecs_header("Location: flow.php");
exit;
}
$favourable_list = favourable_list($_SESSION['user_rank'],false);
if($favourable_list){
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
foreach($favourable_list as $fk=>$fv){
if(!$fv['available']){
$sql = "select count(rec_id) as num from ". $ecs->table('cart') .
" WHERE $sql_where " .
"AND is_gift = ".$fv['act_id']." AND rec_id in (".$_REQUEST['sel_goods'].")";
if($db->getOne($sql) > 0){
show_message('购物车中参加['.$fv['act_name'].']活动的商品未满足条件,请重新设置或者将其赠品删除', '', '', 'warning');
}
}
}
unset($sql_where);
}
//验证购物车中提交过来的商品中参加的活动是否都正常end
}
/* 检查购物车中是否有商品 */
/* 代码增加_end By bbs.hongyuvip.com */
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
$sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') .
" WHERE $sql_where " .
"AND parent_id = 0 AND is_gift = 0 AND rec_type = '$flow_type'";
/* 代码增加_end By bbs.hongyuvip.com */
if ($db->getOne($sql) == 0)
{
show_message($_LANG['no_goods_in_cart'], '', '', 'warning');
}
else
{
if($flow_type != CART_EXCHANGE_GOODS)
{
$time_xg_now=gmtime();
$sql="select c.goods_number,g.goods_id, g.goods_name,g.is_buy, g.buymax, g.buymax_start_date, g.buymax_end_date from ".$ecs->table('cart'). " AS c left join ".$ecs->table('goods'). " AS g on c.goods_id=g.goods_id where c.rec_id in (".$_REQUEST['sel_goods'].")";
$goods_list = $db->getAll($sql);
foreach($goods_list as $k => $v)
{
if($v['is_buy'] == 1 && $v['buymax'] >0 && $v['buymax_start_date'] < $time_xg_now && $v['buymax_end_date'] > $time_xg_now )
{
$num_cart_old=$GLOBALS['db']->getOne("select sum(og.goods_number) from ". $GLOBALS['ecs']->table('order_goods') ." AS og , ". $GLOBALS['ecs']->table('order_info') ." AS o where o.user_id='$_SESSION[user_id]' and o.order_id = og.order_id and add_time > ". $v['buymax_start_date'] ." and add_time < ". $v['buymax_end_date'] ." and og.goods_id = " . $v['goods_id'] );
$num_total = $num_cart_old + intval($v['goods_number']);
if ( $num_total > intval($v['buymax']) )
{
$num_else=intval($v['buymax'])-$num_cart_old;
$message .= "商品 <font color=#330099>【".$v['goods_name']."】</font> 限购期间每人限购 <font color=#330099>". $v['buymax'] . "</font> 件<br>";
if ($num_cart_old)
{
$message .="您在限购期间已经成功购买过 <font color=#330099>$num_cart_old</font> 件!<br>";
}
$message .= "您最多只能再买 <font color=#330099>". $num_else ."</font> 件<br>";
}
}
}
if($message != '')
{
show_message($message, $_LANG['back_to_cart'], 'flow.php', 'info', false);
exit;
}
}
}
/*
* 检查用户是否已经登录
* 如果用户已经登录了则检查是否有默认的收货地址
* 如果没有登录则跳转到登录和注册页面
*/
if (empty($_SESSION['direct_shopping']) && $_SESSION['user_id'] == 0)
{