-
Notifications
You must be signed in to change notification settings - Fork 5
/
recharge2.php
3063 lines (2648 loc) · 108 KB
/
recharge2.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
/**
* ECSHOP 购物流程
* ============================================================================
* 版权所有 2005-2010 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: liuhui $
* $Id: flow.php 17164 2010-05-24 01:42:50Z liuhui $
*/
define('IN_ECS', true);
require_once(dirname(__FILE__) . '/includes/waf.php');
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');
/*------------------------------------------------------ */
//-- INPUT
/*------------------------------------------------------ */
if (!isset($_REQUEST['step']))
{
$_REQUEST['step'] = "cart";
}
$smarty->assign('nowtime', local_date('Y-m-d'));
/*------------------------------------------------------ */
//-- 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); // 数据目录
/*------------------------------------------------------ */
//-- Added by Jack, 2015.05.25
//-- 判定用户手机是否绑定
/*------------------------------------------------------ */
if ($_REQUEST['step'] == 'cart')
{
require_once(ROOT_PATH . 'includes/lib_sms.php');
/* 获取用户手机号 */
$sql = "SELECT user_id, mobile_phone FROM " . $ecs->table('users') . " WHERE user_name='$_SESSION[user_name]' LIMIT 1";
$row = $db->getRow($sql);
/* 是否开启强制手机绑定 */
if ($_CFG['ihuyi_sms_mobile_cons'] == '1' && (!$row || !ismobile($row['mobile_phone'])))
{
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/sms.php');
show_message($_LANG['ihuyi_sms_mobile_cons_notice'], '绑定手机号', 'user.php?act=bindmobile', 'info');
}
}
/*------------------------------------------------------ */
//-- 添加商品到购物车
/*------------------------------------------------------ */
if ($_REQUEST['step'] == 'add_to_cart')
{
include_once('includes/cls_json.php');
$_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']);
/* 检查:如果商品有规格,而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')
{
clear_cart();
}
/* 检查:商品数量是否合法 */
if (!is_numeric($goods->number) || intval($goods->number) <= 0)
{
$result['error'] = 1;
$result['message'] = $_LANG['invalid_number'];
}
/* 更新:购物车 */
else
{
//判断是否会会员商品
if($_SESSION['user_id']){
$is_bind_card = $db->getOne("select is_bind_card from ".$ecs->table("goods")." where is_bind_card= 2 and goods_id=".$goods->goods_id);
if($is_bind_card){
$todate = $db->getOne("select to_date from ".$ecs->table("users")." where user_id=".$_SESSION['user_id']);
if(empty($todate)){
$result['error'] = 11;
die($json->encode($result));
}
}
}
// 更新:添加到购物车
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'];
}
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;
}
}
}
$result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2;
die($json->encode($result));
}
elseif($_REQUEST['step'] == 'checksendtime'){
include_once('includes/cls_json.php');
$sendtime = $_REQUEST['sendtime'];
$result = array('error' => 0);
$json = new JSON;
if((int)local_date("H")>=12 && local_date('Y-m-d',gmstr2time("1 day"))==$sendtime){
$result['error'] = 1;
}
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']);
/* 检查是否有赠品,如果有提示登录后重新选择赠品 */
$sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') .
" WHERE session_id = '" . SESS_ID . "' AND is_gift > 0";
if ($db->getOne($sql) > 0)
{
$smarty->assign('need_rechoose_gift', 1);
}
/* 检查是否需要注册码 */
$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']);
}
}
if ($user->login($_POST['username'], $_POST['password'],isset($_POST['remember'])))
{
update_user_info(); //更新用户信息
recalculate_price(); // 重新计算购物车中的商品价格
/* 检查购物车中是否有商品 没有商品则跳转到首页 */
$sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') . " WHERE session_id = '" . SESS_ID . "' ";
if ($db->getOne($sql) > 0)
{
ecs_header("Location: flow.php?step=consignee\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'])))
{
/* 用户注册成功 */
ecs_header("Location: flow.php?step=consignee\n");
exit;
}
else
{
$err->show();
}
}
else
{
// TODO: 非法访问的处理
}
}
}
elseif ($_REQUEST['step'] == 'addconsignee')
{
include_once(ROOT_PATH . 'includes/lib_transaction.php');
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
$smarty->assign('real_goods_count', exist_real_goods(0, $flow_type) ? 1 : 0);
if ($_SERVER['REQUEST_METHOD'] == 'GET'){
if(isset($_GET['address_id'])){
$consignee = get_consignee_info($_SESSION['user_id'],$_GET['address_id']);
$smarty->assign('consignee', $consignee);
$province_list = get_regions(1, $consignee['country']);
$city_list = get_regions(2, $consignee['province']);
$district_list = get_regions(3, $consignee['city']);
$smarty->assign('city_list', $city_list);
$smarty->assign('district_list', $district_list);
$smarty->assign('province_list', $province_list);
$smarty->assign('country_list', get_regions());
}else{
$smarty->assign('country_list', get_regions());
$smarty->assign('shop_country', $_CFG['shop_country']);
$smarty->assign('shop_province_list', get_regions(1, $_CFG['shop_country']));
}
}else{
$consignee = array(
'address_id' => empty($_POST['address_id']) ? 0 : intval($_POST['address_id']),
'consignee' => empty($_POST['consignee']) ? '' : trim($_POST['consignee']),
'country' => empty($_POST['country']) ? '' : $_POST['country'],
'province' => empty($_POST['province']) ? '' : $_POST['province'],
'city' => empty($_POST['city']) ? '' : $_POST['city'],
'district' => empty($_POST['district']) ? '' : $_POST['district'],
'email' => empty($_POST['email']) ? '' : $_POST['email'],
'address' => empty($_POST['address']) ? '' : $_POST['address'],
'zipcode' => empty($_POST['zipcode']) ? '' : make_semiangle(trim($_POST['zipcode'])),
'tel' => empty($_POST['tel']) ? '' : make_semiangle(trim($_POST['tel'])),
'mobile' => empty($_POST['mobile']) ? '' : make_semiangle(trim($_POST['mobile'])),
'sign_building' => empty($_POST['sign_building']) ? '' : $_POST['sign_building'],
'best_time' => empty($_POST['best_time']) ? '' : $_POST['best_time'].' '.$_POST['best_time1'],
);
if ($_SESSION['user_id'] > 0)
{
/* 如果用户已经登录,则保存收货人信息 */
$consignee['user_id'] = $_SESSION['user_id'];
save_consignee($consignee, true);
ecs_header("Location: flow.php?step=consignee\n");
exit;
}else{
$_SESSION['flow_consignee'] = stripslashes_deep($consignee);
ecs_header("Location: flow.php?step=checkout\n");
exit;
}
}
}
elseif ($_REQUEST['step'] == 'consignee')
{
/*------------------------------------------------------ */
//-- 收货人信息
/*------------------------------------------------------ */
if ($_SESSION['user_id'] == 0)
{
ecs_header("Location: flow.php?step=login\n");
exit;
}
include_once('includes/lib_transaction.php');
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
/* 取得购物类型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
$sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') .
" WHERE session_id = '" . SESS_ID . "' " .
"AND parent_id = 0 AND is_gift = 0 AND rec_type = '$flow_type' and extension_code!='virtual_card'";
$notvirtual = $db->getOne($sql);
if(!$notvirtual){
ecs_header("Location: flow.php?step=checkout\n");
exit;
}
/*
* 收货人信息填写界面
*/
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) < 1)
{
/* 如果用户收货人信息的总数小于 5 则增加一个新的收货人信息 */
// $consignee_list[] = array('country' => $_CFG['shop_country'], 'email' => isset($_SESSION['email']) ? $_SESSION['email'] : '');
ecs_header("Location: flow.php?step=addconsignee\n");
exit;
}
}
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']));
/* 取得每个收货地址的省市区列表 */
$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('consignee_list', $consignee_list);
$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
{
$db->query("update ".$ecs->table('user_address')." set best_time='".$_POST['best_time'].' '.$_POST['best_time1']."' where address_id=".$_POST['address_id']." and user_id=".$_SESSION['user_id']);
$consignee = get_consignee_info($_SESSION['user_id'],$_POST['address_id']);
$_SESSION['flow_consignee'] = stripslashes_deep($consignee);
ecs_header("Location: flow.php?step=checkout\n");
exit;
/*
* 保存收货人信息
*/
$consignee = array(
'address_id' => empty($_POST['address_id']) ? 0 : intval($_POST['address_id']),
'consignee' => empty($_POST['consignee']) ? '' : trim($_POST['consignee']),
'country' => empty($_POST['country']) ? '' : $_POST['country'],
'province' => empty($_POST['province']) ? '' : $_POST['province'],
'city' => empty($_POST['city']) ? '' : $_POST['city'],
'district' => empty($_POST['district']) ? '' : $_POST['district'],
'email' => empty($_POST['email']) ? '' : $_POST['email'],
'address' => empty($_POST['address']) ? '' : $_POST['address'],
'zipcode' => empty($_POST['zipcode']) ? '' : make_semiangle(trim($_POST['zipcode'])),
'tel' => empty($_POST['tel']) ? '' : make_semiangle(trim($_POST['tel'])),
'mobile' => empty($_POST['mobile']) ? '' : make_semiangle(trim($_POST['mobile'])),
'sign_building' => empty($_POST['sign_building']) ? '' : $_POST['sign_building'],
'best_time' => empty($_POST['best_time']) ? '' : $_POST['best_time'].' '.$_POST['best_time1'],
);
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'] == 'recharge')
{
$money = $_GET["money"];
/* 插入订单表 Start*/
$error_no = 0;
do
{
$order['order_sn'] = get_order_sn(); //获取新订单号
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), $order, 'INSERT');
$error_no = $GLOBALS['db']->errno();
if ($error_no > 0 && $error_no != 1062)
{
die($GLOBALS['db']->errorMsg());
}
}
while ($error_no == 1062); //如果是订单号重复则重新提交数据
$new_order_id = $db->insert_id();
$order['order_id'] = $new_order_id;
/* . */
$goods_name= $money. " " . '元充值卡';
$sql = "INSERT INTO " . $ecs->table('order_goods') . "( " .
"order_id, goods_id, goods_name, goods_sn, product_id, goods_number, market_price, ".
"goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id, package_attr_id) VALUES (".
"'$new_order_id', 0,'$goods_name','',0,1,$money,$money,'',0,'virtual_card',0,0,'','')";
$db->query($sql);
/* 插入订单表 END*/
ecs_header("Location: recharge.php?step=checkout&money=$money\n");
exit;
}
elseif ($_REQUEST['step'] == 'checkout')
{
/*------------------------------------------------------ */
//-- 订单确认
/*------------------------------------------------------ */
/* 取得购物类型 */
$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
{
//正常购物流程 清空其他购物流程情况
$_SESSION['flow_order']['extension_code'] = '';
}
///* 检查购物车中是否有商品 */
//$sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') .
// " WHERE session_id = '" . SESS_ID . "' " .
// "AND parent_id = 0 AND is_gift = 0 AND rec_type = '$flow_type'";
//
//if ($db->getOne($sql) == 0)
//{
// show_message($_LANG['no_goods_in_cart'], '', '', 'warning');
//}
/*
* 检查用户是否已经登录
* 如果用户已经登录了则检查是否有默认的收货地址
* 如果没有登录则跳转到登录和注册页面
*/
//if (empty($_SESSION['direct_shopping']) && $_SESSION['user_id'] == 0)
//{
// /* 用户没有登录且没有选定匿名购物,转向到登录页面 */
// ecs_header("Location: flow.php?step=login\n");
// exit;
//}
if ($_SESSION['user_id'] == 0)
{
/* 用户没有登录,转向到登录页面 */
ecs_header("Location: flow.php?step=login\n");
exit;
}
//$sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') .
// " WHERE session_id = '" . SESS_ID . "' " .
// "AND parent_id = 0 AND is_gift = 0 AND rec_type = '$flow_type' and extension_code!='virtual_card'";
//
//
//$notvirtual = $db->getOne($sql);
//if($notvirtual){
// $smarty->assign('notvirtual', 1);
// $consignee = get_consignee($_SESSION['user_id']);
//
// /* 检查收货人信息是否完整 */
//
// if (!check_consignee_info($consignee, $flow_type))
// {
// /* 如果不完整则转向到收货人信息填写界面 */
// ecs_header("Location: flow.php?step=consignee\n");
// exit;
// }
// $_SESSION['flow_consignee'] = $consignee;
// $smarty->assign('consignee', $consignee);
//}else{
// $smarty->assign('notvirtual', 0);
//}
$u = $db->getRow("select to_date,user_money from ".$ecs->table("users")." where user_id=".$_SESSION['user_id']);
if(!empty($u['to_date']) && $u['to_date']<gmtime()){ //判断合同期限
$smarty->assign('user_invalid', '1');
if( $u['user_money']==0){
$smarty->assign('msg', '您的订单无法提交,您的会员卡已超过合同期。<a href=category.php?id=9&act=clear target=_blank>去充值</a>');
}else{
$smarty->assign('msg', '很抱歉,您的会员资格已过了合约有效期(相关规定请参照网站首页-购物指南-<a
href=article.php?id=23 target=_blank>会员卡协议</a>),您账户内的余额和
等级分仍为您保留,但目前无法继续订购。您现可以选择:1)联系客服400-821-3860,申请享受和您所购会员卡相应的延长期的权利。2)如您已享受完单次的延长期服务,通过客服协助,您仍可以注册会员身份继续用账户内余额购物,但不再享有原会员等级的优惠服务。取消的原等级分仍将被保留一年的记录,以便您一年中再续费时累积计入您的等级分中 。
3)直接购卡<a href=category.php?id=9&act=clear target=_blank>续费</a>,并在用户中心-会员卡栏目绑定操作后
,即可继续享受相应的会员等级优惠服务。
');
}
}
/* 对商品信息赋值 */
$cart_goods = cart_goods($flow_type); // 取得商品列表,计算合计
$smarty->assign('goods_list', $cart_goods);
/* 对是否允许修改购物车赋值 */
if ($flow_type != CART_GENERAL_GOODS || $_CFG['one_step_buy'] == '1')
{
$smarty->assign('allow_edit_cart', 0);
}
else
{
$smarty->assign('allow_edit_cart', 1);
}
$usercard = $db->getOne("select count(*) from " . $ecs->table('user_card') . " where user_id='$_SESSION[user_id]' " );
$smarty->assign('usercard', $usercard);
/*
* 取得购物流程设置
*/
$smarty->assign('config', $_CFG);
/*
* 取得订单信息
*/
$order = flow_order_info();
$smarty->assign('order', $order);
/* 计算折扣 */
if ($flow_type != CART_EXCHANGE_GOODS && $flow_type != CART_GROUP_BUY_GOODS)
{
$discount = compute_discount();
$smarty->assign('discount', $discount['discount']);
$favour_name = empty($discount['name']) ? '' : join(',', $discount['name']);
$smarty->assign('your_discount', sprintf($_LANG['your_discount'], $favour_name, price_format($discount['discount'])));
}
/*
* 计算订单的费用
*/
//$total = order_fee($order, $cart_goods, $consignee);
$money = $_GET["money"];
$total['goods_price_formated']=$money;
$total['amount_formated']=$money;
$smarty->assign('nowtime', local_date('Y-m-d'));
$smarty->assign('total', $total);
$smarty->assign('shopping_money', sprintf($_LANG['shopping_money'], $total['formated_goods_price']));
$smarty->assign('market_price_desc', sprintf($_LANG['than_market_price'], $total['formated_market_price'], $total['formated_saving'], $total['save_rate']));
/* 取得配送列表 */
//$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);
//
///* 取得支付列表 */
//if ($order['shipping_id'] == 0)
//{
// $cod = true;
// $cod_fee = 0;
//}
//else
//{
// $shipping = shipping_info($order['shipping_id']);
// $cod = $shipping['support_cod'];
//
// if ($cod)
// {
// /* 如果是团购,且保证金大于0,不能使用货到付款 */
// if ($flow_type == CART_GROUP_BUY_GOODS)
// {
// $group_buy_id = $_SESSION['extension_id'];
// if ($group_buy_id <= 0)
// {
// show_message('error group_buy_id');
// }
// $group_buy = group_buy_info($group_buy_id);
// if (empty($group_buy))
// {
// show_message('group buy not exists: ' . $group_buy_id);
// }
//
// if ($group_buy['deposit'] > 0)
// {
// $cod = false;
// $cod_fee = 0;
//
// /* 赋值保证金 */
// $smarty->assign('gb_deposit', $group_buy['deposit']);
// }
// }
//
// if ($cod)
// {
// $shipping_area_info = shipping_area_info($order['shipping_id'], $region);
// $cod_fee = $shipping_area_info['pay_fee'];
// }
// }
// else
// {
// $cod_fee = 0;
// }
//}
// 给货到付款的手续费加<span id>,以便改变配送的时候动态显示
$payment_list = available_payment_list(1, $cod_fee);
if(isset($payment_list))
{
foreach ($payment_list as $key => $payment)
{
if ($payment['is_cod'] == '1')
{
$payment_list[$key]['format_pay_fee'] = '<span id="ECS_CODFEE">' . $payment['format_pay_fee'] . '</span>';
}
/* 如果有易宝神州行支付 如果订单金额大于300 则不显示 */
if ($payment['pay_code'] == 'yeepayszx' && $total['amount'] > 300)
{
unset($payment_list[$key]);
}
/* 如果有余额支付 */
if ($payment['pay_code'] == 'balance')
{
/* 如果未登录,不显示 */
if ($_SESSION['user_id'] == 0)
{
unset($payment_list[$key]);
}
else
{
if ($_SESSION['flow_order']['pay_id'] == $payment['pay_id'])
{
$smarty->assign('disable_surplus', 1);
}
}
}
}
}
$smarty->assign('payment_list', $payment_list);
/* 取得包装与贺卡 */
//if ($total['real_goods_count'] > 0)
//{
// /* 只有有实体商品,才要判断包装和贺卡 */
// if (!isset($_CFG['use_package']) || $_CFG['use_package'] == '1')
// {
// /* 如果使用包装,取得包装列表及用户选择的包装 */
// $smarty->assign('pack_list', pack_list());
// }
//
// /* 如果使用贺卡,取得贺卡列表及用户选择的贺卡 */
// if (!isset($_CFG['use_card']) || $_CFG['use_card'] == '1')
// {
// $smarty->assign('card_list', card_list());
// }
//}
$user_info = user_info($_SESSION['user_id']);
/* 如果使用余额,取得用户余额 */
if ((!isset($_CFG['use_surplus']) || $_CFG['use_surplus'] == '1')
&& $_SESSION['user_id'] > 0
&& $user_info['user_money'] > 0)
{
// 能使用余额
$smarty->assign('allow_use_surplus', 1);
$smarty->assign('your_surplus', $user_info['user_money']);
}
/* 如果使用积分,取得用户可用积分及本订单最多可以使用的积分 */
if ((!isset($_CFG['use_integral']) || $_CFG['use_integral'] == '1')
&& $_SESSION['user_id'] > 0
&& $user_info['pay_points'] > 0
&& ($flow_type != CART_GROUP_BUY_GOODS && $flow_type != CART_EXCHANGE_GOODS))
{
// 能使用积分
$smarty->assign('allow_use_integral', 1);
$smarty->assign('order_max_integral', flow_available_points()); // 可用积分
$smarty->assign('your_integral', $user_info['pay_points']); // 用户积分
}
/* 如果使用红包,取得用户可以使用的红包及用户选择的红包 */
if ((!isset($_CFG['use_bonus']) || $_CFG['use_bonus'] == '1')
&& ($flow_type != CART_GROUP_BUY_GOODS && $flow_type != CART_EXCHANGE_GOODS))
{
// 取得用户可用红包
$user_bonus = user_bonus($_SESSION['user_id'], $total['goods_price']);
if (!empty($user_bonus))
{
foreach ($user_bonus AS $key => $val)
{
$user_bonus[$key]['bonus_money_formated'] = price_format($val['type_money'], false);
}
$smarty->assign('bonus_list', $user_bonus);
}
// 能使用红包
$smarty->assign('allow_use_bonus', 1);
}
/* 如果使用缺货处理,取得缺货处理列表 */
if (!isset($_CFG['use_how_oos']) || $_CFG['use_how_oos'] == '1')
{
if (is_array($GLOBALS['_LANG']['oos']) && !empty($GLOBALS['_LANG']['oos']))
{
$smarty->assign('how_oos_list', $GLOBALS['_LANG']['oos']);
}
}
/* 如果能开发票,取得发票内容列表 */
//if ((!isset($_CFG['can_invoice']) || $_CFG['can_invoice'] == '1')
// && isset($_CFG['invoice_content'])
// && trim($_CFG['invoice_content']) != '' && $flow_type != CART_EXCHANGE_GOODS)
//{
// $inv_content_list = explode("\n", str_replace("\r", '', $_CFG['invoice_content']));
// $smarty->assign('inv_content_list', $inv_content_list);
//
// $inv_type_list = array();
// foreach ($_CFG['invoice_type']['type'] as $key => $type)
// {
// if (!empty($type))
// {
// $inv_type_list[$type] = $type . ' [' . floatval($_CFG['invoice_type']['rate'][$key]) . '%]';
// }
// }
// $smarty->assign('inv_type_list', $inv_type_list);
//}
/* 保存 session */
$_SESSION['flow_order'] = $order;
}
elseif ($_REQUEST['step'] == 'select_shipping')
{
/*------------------------------------------------------ */
//-- 改变配送方式
/*------------------------------------------------------ */
include_once('includes/cls_json.php');
$json = new JSON;
$result = array('error' => '', 'content' => '', 'need_insure' => 0);
/* 取得购物类型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/* 获得收货人信息 */
$consignee = get_consignee($_SESSION['user_id']);
/* 对商品信息赋值 */
$cart_goods = cart_goods($flow_type); // 取得商品列表,计算合计
if (empty($cart_goods) || !check_consignee_info($consignee, $flow_type))
{
$result['error'] = $_LANG['no_goods_in_cart'];
}
else
{
/* 取得购物流程设置 */
$smarty->assign('config', $_CFG);
/* 取得订单信息 */
$order = flow_order_info();
$order['shipping_id'] = intval($_REQUEST['shipping']);
$regions = array($consignee['country'], $consignee['province'], $consignee['city'], $consignee['district']);
$shipping_info = shipping_area_info($order['shipping_id'], $regions);
/* 计算订单的费用 */
$total = order_fee($order, $cart_goods, $consignee);
$smarty->assign('total', $total);
/* 取得可以得到的积分和红包 */
$smarty->assign('total_integral', cart_amount(false, $flow_type) - $total['bonus'] - $total['integral_money']);
$smarty->assign('total_bonus', price_format(get_total_bonus(), false));
/* 团购标志 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$smarty->assign('is_group_buy', 1);
}
$result['cod_fee'] = $shipping_info['pay_fee'];
if (strpos($result['cod_fee'], '%') === false)
{
$result['cod_fee'] = price_format($result['cod_fee'], false);
}