Payment.php
61.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
<?php
/**
* tpshop
* ============================================================================
* * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: IT宇宙人 2015-08-10 $
*/
namespace app\mobile\controller;
use think\Request;
use think\db;
class Payment extends MobileBase
{
public $payment; // 具体的支付类
public $pay_code; // 具体的支付code
public $user;//用户具体信息
/**
* 析构流函数
*/
public function __construct()
{
parent::__construct();
// tpshop 订单支付提交
$pay_radio = $_REQUEST['pay_radio'];
if (!empty($pay_radio)) {
$pay_radio = parse_url_param($pay_radio);
$this->pay_code = $pay_radio['pay_code']; // 支付 code
} else // 第三方 支付商返回
{
//$_GET = I('get.');
//file_put_contents('./a.html',$_GET,FILE_APPEND);
$this->pay_code = I('get.pay_code');
unset($_GET['pay_code']); // 用完之后删除, 以免进入签名判断里面去 导致错误
}
$this->pay_code = 'weixin';
//获取通知的数据
$xml = $GLOBALS['HTTP_RAW_POST_DATA'];
if (empty($this->pay_code))
exit('pay_code 不能为空');
// 导入具体的支付类文件
include_once "plugins/payment/{$this->pay_code}/{$this->pay_code}.class.php"; // D:\wamp\www\svn_tpshop\www\plugins\payment\alipay\alipayPayment.class.php
$code = '\\' . $this->pay_code; // \alipay
$this->payment = new $code();
$this->user = session('user');
}
/**
* tpshop 提交支付方式
*/
public function getCode()
{
$stoid = getMobileStoId();
//C('TOKEN_ON',false); // 关闭 TOKEN_ON
header("Content-type:text/html;charset=utf-8");
$orderno = I('orderno'); // 订单id
// 修改订单的支付方式
$payment_arr = M('Plugin')->where("`type` = 'payment'")->getField("code,name");
$isgift=I('is_gift/d');
//当是送礼情况下的支付
if($isgift==1){
M('giftuser_order')->where("parent_sn", $orderno)
->save(array('pay_code' => $this->pay_code, 'pay_name' => $payment_arr[$this->pay_code]));
$order = M('giftuser_order')->where("parent_sn", $orderno)->select();
if ($order[0]['pay_status'] == 1) { $this->error2('此订单,已完成支付!');}
if ($order[0]['pay_status'] == 1) { $this->error2('此订单,已完成支付!');}
/*--如果订单中有用积分,判断积分是否足够--*/
if ($order[0]['integral'] > 0) {
//$tk = M("store")->where("store_id", getMobileStoId())->field("api_token")->find();
$tk = tpCache("shop_info",getMobileStoId());
$userd = M("users")->where('user_id', $order[0]['user_id'])->find();
//$map['Id'] = array('=', $userd['erpvipid']);
//$rs = getApiData('wxd.vip.vipinfo.list.get', $tk['api_token'], null, $map);
//$d = json_decode($rs, true);
//$integ = $d['data'][0]['Integral'];
if(empty($userd['erpvipid'])) $this->gopayerr2("您非线下会员", $stoid);
$d=get_erpvipinfo($userd['erpvipid'],$tk['ERPId']);
if(!$d) $this->gopayerr2("您的积分不足【01】", $stoid);
$integ=$d['Integral'];
if ($order[0]['integral'] > $integ) { $this->gopayerr2("您的积分不足【02】", $stoid);}
}
$garr = ord_goods_he($orderno);
if (empty($garr)) { $this->gopayerr2("订单获取异常", $stoid);}
//$srule = M('store_config')->where('store_id', $stoid)->find();
//销售规则
$sales_rules = tpCache('basic.sales_rules', $stoid);
/*----如果是线下库存,获取线下库存,预出库库存----*/
$ddd = [];
if ($sales_rules == 2) {
$count_arr = getcountarr($garr, $stoid);
/*--预出库库存--*/
$gidarr=get_arr_column($garr,'goods_id');
$fgid0=implode(',',$gidarr);
$strq = 'select pickup_id,goods_id,sum(out_qty) as sum0 from __PREFIX__erp_yqty where goods_id in(' . $fgid0 . ') and store_id='.$stoid.' GROUP BY pickup_id,goods_id';
$dd = Db::query($strq);
//---组装数组---
if ($dd){
foreach ($dd as $ku => $vu) {
$ypkid=$vu['pickup_id'];
$ypgid=$vu['goods_id'];
$ddd[$ypkid.$ypgid]=$vu['sum0'];
}
}
}
$now=time();
$obj = M('activitylist')->where(['is_end' => 0, 'good_object' => 0, 'prom_type'=>3,
'store_id' => getMobileStoId()])
->where('s_time<'.$now.' and e_time>'.$now)
->field('act_id as id,goods_listid,prom_type')->find();
$user = $this->user;
$mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆开关
$rank_switch = tpCache('shopping.rank_switch',$stoid);//等级开关
/*--库存判断和活动判断--*/
foreach ($garr as $k => $value) {
/*--商品的库存和活动不能过期--*/
$ginfo = M("goods")->where("goods_id", $value['goods_id'])->find();
if ($value['prom_type']==3){
$pro = M("prom_goods")->where("id", $value['prom_id'])
->where('store_id',$stoid)->where('is_end',0)
->field("good_object")
->find();
if(empty($pro)) {
$this->gopayerr("{$ginfo['goods_name']} 此商品活动已经变化", $stoid);
}
if($pro['good_object']>0){
//如果不是普通购买
if($value['is_integral_normal']!=1 && $value['is_pd_normal']!=1){
if($value['prom_type']!=$ginfo['prom_type'] && $value['prom_id']!=$ginfo['prom_id'] && $value['is_gift']==0 )
{
$this->gopayerr("{$ginfo['goods_name']} 此商品活动已经变化", $stoid);
}
}
}
}else{
//如果不是普通购买
if($value['is_integral_normal']!=1 && $value['is_pd_normal']!=1) {
if ($value['prom_type'] != 5 && $value['prom_type'] != $ginfo['prom_type'] && $value['prom_id'] != $ginfo['prom_id'] && $value['is_gift']==0) {
$this->gopayerr("{$ginfo['goods_name']} 此商品活动已经变化", $stoid);
}
}
}
if ($ginfo['prom_type'] == 0 && empty($obj)){
if (!empty($mz_switch) && $user['is_mzvip'] == 1 && $ginfo['mz_price'] > 0){
$ginfo['shop_price'] = $ginfo['mz_price'];
}
if (!empty($rank_switch)){
if (!empty($user['card_field']) && $ginfo[$user['card_field']] > 0
&& strtotime($user['card_expiredate'])>time()){
$ginfo['shop_price'] = $ginfo[$user['card_field']];
}
}
}
/*--线下库存的序列key--*/
$bkey = $value['pick_id'] . $value['goods_id'];
//商品参与活动查看
if ($value['prom_type'] > 0 && $value['member_goods_price'] > 0 && $value['is_collocation'] == 0 && $value['is_integral_normal']!=1 && $value['is_pd_normal']!=1 && $value['is_gift']==0) {
if (!empty($obj) && empty($ginfo['prom_type'])){
$ginfo['prom_type']=3;
$ginfo['prom_id']=$obj['id'];
}
$ginfo['prom_type']=$value['prom_type'];
$ginfo['prom_id']=$value['prom_id'];
$prom = get_goods_promotion1($ginfo, null, $this->user_id);
if ($prom['is_end'] == 1) {
//return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品活动已经结束", 'result' => '');
$this->gopayerr2("{$ginfo['goods_name']} 此商品活动已经结束", $stoid);
}
if ($prom['is_end'] == 2) {
//return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品已经售完", 'result' => '');
$this->gopayerr2("{$ginfo['goods_name']} 此商品已经售完", $stoid);
}
if ($prom['is_end'] == 3) {
//return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量", 'result' => '');
$this->gopayerr2("{$ginfo['goods_name']} 此活动商品超出限购数量", $stoid);
}
if ($value['prom_type'] == 1) {
if ($value['goods_num'] > $prom['buy_limit']) {
//return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量",'result' => '');
$this->gopayerr2("{$ginfo['goods_name']} 此活动商品超出限购数量", $stoid);
}
}
if ($value['member_goods_price'] != $prom['price'] && $value['prom_type'] != 3 && $value['prom_type'] != 5) {
//return array('status' => -4, 'msg' => "商品价格已经变化", 'result' => '');
$this->gopayerr2("{$ginfo['goods_name']} 商品价格已经变化1", $stoid);
}
if ($value['prom_type'] == 1 || $value['prom_type'] == 2 || $value['prom_type'] == 4 || $value['prom_type'] == 6) {
if ($value['goods_num'] > $ginfo['store_count']) {
//return array('status' => -4, 'msg' => "库存不足", 'result' => '');
$this->gopayerr2("{$ginfo['goods_name']} 库存不足", $stoid);
}
} else {
if ($sales_rules == 1) {
if ($value['goods_num'] > $ginfo['store_count']) {
//return array('status' => -4, 'msg' => "库存不足", 'result' => '');
$this->gopayerr2("{$ginfo['goods_name']} 库存不足", $stoid);
}
} else if ($sales_rules == 2) {
if ($value['goods_num']+$ddd[$bkey]> $count_arr[$bkey]) {
//return array('status' => -4, 'msg' => "线下库存不足", 'result' => '');
$this->gopayerr2("{$ginfo['goods_name']} 库存不足", $stoid);
}
}
}
} else {
if ($value['member_goods_price'] > 0) {
if ($sales_rules == 1) {
if ($value['goods_num'] > $ginfo['store_count']) {
//return array('status' => -4, 'msg' => "库存不足", 'result' => '');
$this->gopayerr2("{$ginfo['goods_name']} 库存不足", $stoid);
}
} else if ($sales_rules == 2) {
if ($value['goods_num']+$ddd[$bkey] > $count_arr[$bkey]) {
//return array('status' => -4, 'msg' => "线下库存不足", 'result' => '');
$this->gopayerr2("{$ginfo['goods_name']} 库存不足", $stoid);
}
}
/*--判断价格是否发生变化---*/
if ($value['member_goods_price'] != $ginfo['shop_price'] && $value['is_collocation'] == 0 && $value['is_gift']==0) {
$curprice=$ginfo['shop_price'];
//如果有美妆价和启用,大于0
if ($ginfo['mz_price'] > 0 && !empty($user['is_mzvip']) && !empty($mz_switch)) {
$curprice = $ginfo['mz_price'];
}
//如果有等级价和启用,大于0
if ($rank_switch) {
if ($user['card_field'] && strtotime($user['card_expiredate']) > time() && $ginfo[$user['card_field']] > 0) {
$curprice = $ginfo[$user['card_field']];
}
}
if($curprice!=$value['member_goods_price'] && $value['is_integral_normal']!=1 && $value['is_pd_normal']!=1) {
//return array('status' => -4, 'msg' => "商品价格已经变化", 'result' => '');
$this->gopayerr2("{$ginfo['goods_name']} 商品价格已经变化2", $stoid);
}
}
}
}
}
//tpshop 订单支付提交
$pay_radio = $_REQUEST['pay_radio'];
$config_value = parse_url_param($pay_radio); // 类似于 pay_code=alipay&bank_code=CCB-DEBIT 参数
//微信JS支付
if ($this->pay_code == 'weixin' && $_SESSION['openid'] && strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) {
$code_str = $this->payment->getJSAPI2($orderno);
if (!empty($code_str['code'])) {
$text = $code_str['msg'];
$url = U("mobile/payment/pay_error2", array("stoid" => getMobileStoId(), 'err' => $text, 'ordno' => $orderno));
$this->redirect($url);
} else {
exit($code_str);
}
} else {
//$code_str = $this->payment->get_code($order,$config_value);
$this->error('暂时只支持微信支付!', U("Mobile/index/index", array('stoid' => getMobileStoId())));
}
}else{
M('order')->where("parent_sn", $orderno)
->save(array('pay_code' => $this->pay_code, 'pay_name' => $payment_arr[$this->pay_code]));
$order = M('order')->where("parent_sn", $orderno)->select();
if ($order[0]['pay_status'] == 1) {
$this->error('此订单,已完成支付!');
}
if ($order[0]['order_status'] == 3) {
$this->error('此订单已经取消!');
}
/*--如果订单中有用积分,判断积分是否足够--*/
if ($order[0]['integral'] > 0) {
//$tk = M("store")->where("store_id", getMobileStoId())->field("api_token")->find();
$tk = tpCache("shop_info",getMobileStoId());
$userd = M("users")->where('user_id', $order[0]['user_id'])->find();
//$map['Id'] = array('=', $userd['erpvipid']);
//$rs = getApiData('wxd.vip.vipinfo.list.get', $tk['api_token'], null, $map);
//$d = json_decode($rs, true);
//$integ = $d['data'][0]['Integral'];
if(empty($userd['erpvipid'])) $this->gopayerr2("您非线下会员", $stoid);
$d=get_erpvipinfo($userd['erpvipid'],$tk['ERPId']);
if(!$d) $this->gopayerr2("您的积分不足【01】", $stoid);
$integ=$d['Integral'];
if ($order[0]['integral'] > $integ) {
$this->gopayerr("您的积分不足", $stoid);
}
}
$garr = ord_goods_he($orderno);
if (empty($garr)) {
$this->gopayerr("订单获取异常", $stoid);
}
//$srule = M('store_config')->where('store_id', $stoid)->find();
//销售规则
$sales_rules = tpCache('basic.sales_rules', $stoid);
/*----如果是线下库存,获取线下库存,预出库库存----*/
$ddd = [];
if ($sales_rules == 2) {
$count_arr = getcountarr($garr, $stoid);
/*--预出库库存--*/
$gidarr=get_arr_column($garr,'goods_id');
$fgid0=implode(',',$gidarr);
$strq = 'select pickup_id,goods_id,sum(out_qty) as sum0 from __PREFIX__erp_yqty where goods_id in(' . $fgid0 . ') and store_id='.$stoid.' GROUP BY pickup_id,goods_id';
$dd = Db::query($strq);
//---组装数组---
if ($dd){
foreach ($dd as $ku => $vu) {
$ypkid=$vu['pickup_id'];
$ypgid=$vu['goods_id'];
$ddd[$ypkid.$ypgid]=$vu['sum0'];
}
}
}
$obj = M('prom_goods')->where(['is_end' => 0, 'good_object' => 0, 'store_id' => $stoid])->field('id')->find();
$user = $this->user;
$mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆开关
$rank_switch = tpCache('shopping.rank_switch',$stoid);//等级开关
/*--库存判断和活动判断--*/
foreach ($garr as $k => $value) {
/*--商品的库存和活动不能过期--*/
$ginfo = M("goods")->where("goods_id", $value['goods_id'])->find();
if ($ginfo['prom_type'] == 0 && empty($obj)){
if (!empty($mz_switch) && $user['is_mzvip'] == 1 && $ginfo['mz_price'] > 0){
$ginfo['shop_price'] = $ginfo['mz_price'];
}
if (!empty($rank_switch)){
if (!empty($user['card_field']) && $ginfo[$user['card_field']] > 0 && strtotime($user['card_expiredate']) > time()){
$ginfo['shop_price'] = $ginfo[$user['card_field']];
}
}
}
/*--线下库存的序列key--*/
$bkey = $value['pick_id'] . $value['goods_id'];
//商品参与活动查看
if ($value['prom_type'] > 0 && $value['member_goods_price'] > 0 && $value['is_collocation'] == 0) {
if (!empty($obj) && empty($ginfo['prom_type'])){
$ginfo['prom_type']=3;
$ginfo['prom_id']=$obj['id'];
}
$ginfo['prom_type']=$value['prom_type'];
$ginfo['prom_id']=$value['prom_id'];
$prom=null;
if($order[0]['is_pt_tz']=0 && $order[0]['pt_prom_id']>0)
$prom = get_pt_promotion1($ginfo, null, $user['user_id'],$order[0]['pt_listno']);
else
$prom = get_goods_promotion1($ginfo, null, $user['user_id']);
mlog(json_encode($prom),"getCode/".$stoid);
mlog(json_encode($ginfo),"getCode/".$stoid);
if ($prom['is_end'] == 1) {
//return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品活动已经结束", 'result' => '');
$this->gopayerr("{$ginfo['goods_name']} 此商品活动已经结束", $stoid);
}
if ($prom['is_end'] == 2) {
//return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品已经售完", 'result' => '');
$this->gopayerr("{$ginfo['goods_name']} 此商品已经售完", $stoid);
}
if ($prom['is_end'] == 3) {
//return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量", 'result' => '');
$this->gopayerr("{$ginfo['goods_name']} 此活动商品超出限购数量", $stoid);
}
if ($value['prom_type'] == 1) {
if ($value['goods_num'] > $prom['buy_limit'] && $prom['buy_limit0']>0) {
//return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量",'result' => '');
$this->gopayerr("{$ginfo['goods_name']} 此活动商品超出限购数量", $stoid);
}
}
if ($value['member_goods_price'] != $prom['price'] && $value['prom_type'] != 3) {
//return array('status' => -4, 'msg' => "商品价格已经变化", 'result' => '');
$this->gopayerr("{$ginfo['goods_name']} 商品价格已经变化", $stoid);
}
if ($value['prom_type'] == 1 || $value['prom_type'] == 2 || $value['prom_type'] == 4 || $value['prom_type'] == 6) {
if ($value['goods_num'] > $ginfo['store_count']) {
//return array('status' => -4, 'msg' => "库存不足", 'result' => '');
$this->gopayerr("{$ginfo['goods_name']} 库存不足", $stoid);
}
} else {
if ($sales_rules == 1) {
if ($value['goods_num'] > $ginfo['store_count']) {
//return array('status' => -4, 'msg' => "库存不足", 'result' => '');
$this->gopayerr("{$ginfo['goods_name']} 库存不足", $stoid);
}
} else if ($sales_rules == 2) {
if ($value['goods_num']+$ddd[$bkey]> $count_arr[$bkey]) {
//return array('status' => -4, 'msg' => "线下库存不足", 'result' => '');
$this->gopayerr("{$ginfo['goods_name']} 库存不足", $stoid);
}
}
}
} else {
if ($value['member_goods_price'] > 0) {
if ($sales_rules == 1) {
if ($value['goods_num'] > $ginfo['store_count']) {
//return array('status' => -4, 'msg' => "库存不足", 'result' => '');
$this->gopayerr("{$ginfo['goods_name']} 库存不足", $stoid);
}
} else if ($sales_rules == 2) {
if ($value['goods_num']+$ddd[$bkey] > $count_arr[$bkey]) {
//return array('status' => -4, 'msg' => "线下库存不足", 'result' => '');
$this->gopayerr("{$ginfo['goods_name']} 库存不足", $stoid);
}
}
/*--判断价格是否发生变化---*/
if ($value['member_goods_price'] != $ginfo['shop_price'] && $value['is_collocation'] == 0) {
$curprice=$ginfo['shop_price'];
//如果有美妆价和启用,大于0
if ($ginfo['mz_price'] > 0 && !empty($user['is_mzvip']) && !empty($mz_switch)) {
$curprice = $ginfo['mz_price'];
}
//如果有等级价和启用,大于0
if ($rank_switch) {
if ($user['card_field'] && strtotime($user['card_expiredate']) > time() && $ginfo[$user['card_field']] > 0) {
$curprice = $ginfo[$user['card_field']];
}
}
if($curprice!=$value['member_goods_price']) {
//return array('status' => -4, 'msg' => "商品价格已经变化", 'result' => '');
$this->gopayerr("{$ginfo['goods_name']} 商品价格已经变化", $stoid);
}
}
}
}
}
//tpshop 订单支付提交
$pay_radio = $_REQUEST['pay_radio'];
$config_value = parse_url_param($pay_radio); // 类似于 pay_code=alipay&bank_code=CCB-DEBIT 参数
//微信JS支付
if ($this->pay_code == 'weixin' && $_SESSION['openid'] && strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) {
//如果是拼单的订单
if ($order[0]['pt_prom_id']) {
mlog('pt_1','getCode',$order[0]['store_id']);
$code_str = $this->payment->getJSAPI3($orderno);
mlog('pt_2','getCode',$order[0]['store_id']);
if (!empty($code_str['code'])) {
mlog('pt_3','getCode',$order[0]['store_id']);
$text = $code_str['msg'];
mlog('pt_4'.$text,'getCode',$order[0]['store_id']);
$url = U("mobile/team/team_success/payfail/1",
array("stoid" => getMobileStoId(),'orderno' => $orderno));
$this->redirect($url);
} else {
exit($code_str);
}
}else{
$code_str = $this->payment->getJSAPI($orderno);
if (!empty($code_str['code'])) {
$text = $code_str['msg'];
$url = U("mobile/payment/pay_error", array("stoid" => getMobileStoId(), 'err' => $text, 'ordno' => $orderno));
$this->redirect($url);
} else {
exit($code_str);
}
}
} else {
//$code_str = $this->payment->get_code($order,$config_value);
$this->error('暂时只支持微信支付!', U("Mobile/index/index", array('stoid' => getMobileStoId())));
}
}
$this->assign('code_str', $code_str);
$this->assign('order_id', $orderno);
return $this->fetch('payment', getMobileStoId()); // 分跳转 和不 跳转
}
/**
* tpshop 提交支付方式
*/
public function getCode_pt()
{
$stoid = getMobileStoId();
//C('TOKEN_ON',false); // 关闭 TOKEN_ON
header("Content-type:text/html;charset=utf-8");
$orderno = I('orderno'); // 订单id
// 修改订单的支付方式
$order = M('order')->where("order_sn", $orderno)->select();
if ($order[0]['pay_status'] == 1) {
$this->error('此订单,已完成支付!');
}
if($order[0]['pt_tail_money']<=0) {
update_pt_wk($orderno, $stoid, $order[0], 1);
$go_url = U('Mobile/team/team_success',array('stoid'=>$order[0]['store_id'],'orderno'=>$order[0]['order_sn']));
$this->redirect($go_url);
}
$user = $this->user;
//主要是要判断付尾款的时间是否到期
$wda['team_id']=$order[0]['pt_prom_id'];
$wda['listno']=$order[0]['pt_listno'];
$uu = M("teamgroup")->where($wda)->where('store_id',$stoid)->find();
if($uu){
$v=$order[0];
/*------
//如果付尾款的时间也过期了
$stoid=$stoid;
$refund_type=tpCache('basic.refund_type',$stoid);
//退到余额
if($refund_type==0){
$user_money=$v['order_amount']+$v['user_money']+$v['pt_tail_money'];
$sql = "update wxd_users set user_money=user_money+" . $user_money . " where user_id=" . $v['user_id'];
$rs1 = Db::execute($sql);
if($rs1) {
if ($user_money > 0) {
$odata['user_id'] = $v['user_id'];
$odata['create_time'] = time();
$odata['money'] = $user_money;
$odata['remark'] = "退款";
$odata['store_id'] = $v['store_id'];
$odata['order_sn'] = $v['order_sn'];
$odata['status'] = 1;
$odata['type'] = 1;
M('withdrawals')->save($odata);
}
}else{
mlog("退款到余额失败,",'refund/'.$stoid);
}
}
//原路返回
else if($refund_type==1) {
$wxmoney=0;
$usrmoney=0;
if($v['tail_pay_type']){
$wxmoney=$v['order_amount'];
$usrmoney=$v['order_amount']+$v['pt_tail_money'];
}else{
$wxmoney=$v['order_amount']+$v['pt_tail_money'];
$usrmoney=$v['order_amount'];
}
if($v['order_amount']) {
include_once "plugins/payment/weixin/weixin.class.php";
$wx=new \weixin();
$ordno = $v['order_sn'];
$total_fee = $wxmoney;
$refund_fee = $total_fee;
//$erpid = tpCache('shop_info.ERPId', $stoid);
$path = BASE_PATH . 'public/cert/' . $stoid . '/';
try {
$wx->setCong($v['store_id']);
$rs = $wx->refund($ordno, $total_fee, $refund_fee, $path);
if ($rs['return_code'] == 'FAIL') {
mlog("退款失败," . $rs['return_msg'], 'refund/' . $stoid);
}
} catch (\Exception $e) {
mlog("退款签名失败," . $rs['return_msg'], 'refund/' . $stoid);
}
}
//退到余额
if($v['user_money']){
$user_money=$usrmoney;
$sql = "update wxd_users set user_money=user_money+" . $user_money . " where user_id=" . $v['user_id'];
$rs1 = Db::execute($sql);
if($rs1) {
if ($user_money > 0) {
$odata['user_id'] = $v['user_id'];
$odata['create_time'] = time();
$odata['money'] = $user_money;
$odata['remark'] = "退款";
$odata['store_id'] = $v['store_id'];
$odata['order_sn'] = $v['order_sn'];
$odata['status'] = 1;
$odata['type'] = 1;
M('withdrawals')->save($odata);
}
}else{
mlog("退款到余额失败,",'refund/'.$stoid);
}
}
}
----*/
if($uu['wk_end_time']<time()){
$url = U("mobile/user/order_list",
array("stoid" => getMobileStoId()));
$this->error('尾款时间已到期',$url);
}
}else{
$url = U("mobile/user/order_list",
array("stoid" => getMobileStoId()));
$this->error('未找到拼团',$url);
}
//tpshop 订单支付提交
$pay_radio = $_REQUEST['pay_radio'];
$config_value = parse_url_param($pay_radio); // 类似于 pay_code=alipay&bank_code=CCB-DEBIT 参数
//微信JS支付
if ($this->pay_code == 'weixin' && $_SESSION['openid'] && strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) {
//如果是拼单的订单
if ($order[0]['pt_prom_id']) {
mlog('1','getCode_pt/'.$stoid);
$code_str = $this->payment->getJSAPI_pt_wk($orderno);
if (!empty($code_str['code'])) {
$text = $code_str['msg'];
mlog('2'.$text,'getCode_pt/'.$stoid);
$url = U("mobile/user/order_list",
array("stoid" => getMobileStoId()));
$this->redirect($url);
} else {
exit($code_str);
}
}
} else {
//$code_str = $this->payment->get_code($order,$config_value);
$this->error('暂时只支持微信支付!', U("Mobile/index/index", array('stoid' => getMobileStoId())));
}
$this->assign('code_str', $code_str);
$this->assign('order_id', $orderno);
return $this->fetch('payment', getMobileStoId()); // 分跳转 和不 跳转
}
public function getPay()
{
//手机端在线充值
//C('TOKEN_ON',false); // 关闭 TOKEN_ON
header("Content-type:text/html;charset=utf-8");
$order_id = I('order_id'); //订单id
$recharge_type = I('recharge_type/d'); //充值类型,0余额充值 1积分充值
$jid = I('seleid'); //购买的积分充值id
$num = I('buynum/d'); //购买的积分充值数量
$user = session('user');
$getaccdb=strtoupper($this->pm_erpid);//账套
switch ($recharge_type)
{
//余额充值
case 0:
$data['recharge_type'] = $recharge_type;
if ($order_id > 0) {
M('recharge')->where(array('order_id' => $order_id, 'user_id' => $user['user_id']))->save($data);
} else {
$where['Id'] = array('=', $jid);
$tk['api_token']=tpCache('shop_info.api_token',getMobileStoId());
$aa = getApiData("wxd.vip.addactlist", $tk['api_token'], null, $where);
mlog($aa . ':' . $jid . ':' . getMobileStoId() . ':' . $tk['api_token'], "777ttt");
$aa = json_decode($aa, true);
if ($aa["data"][0]["sQty"])
{
$getbuy_num = $aa["data"][0]["sQty"];
}
else {
$getbuy_num =$aa["data"][0]["Qty"];
}
if ($getbuy_num && $getbuy_num>0) {
$user_buy_count = M('recharge')->where(array('store_id' => getMobileStoId(), 'user_id' => $user['user_id'], 'yucun_id' => $aa["data"][0]['Id'], 'pay_status' => 1))->count();
if ($user_buy_count >= $getbuy_num) {
$this->error('提交失败,已超过限制充值次数!', U("Mobile/User/pre_deposit", array('stoid' => getMobileStoId())));
exit;
}
}
$str=number_format($aa["data"][0]["BeginSum"], 2);//保留俩位小数
$str0=str_replace(',','',$str);
$data["price"] =$str0;
$data["integral_remark"] = "线上会员充值ERP预存款";
$data["yucun_id"] = $aa["data"][0]["Id"];
$data["yucun_Advance_Id"] = $aa["data"][0]["AdvanceItemId"];
$data["account"] = $aa["data"][0]["BeginSum"] * $num;
$data["order_sn"] = $getaccdb.'_vop' . date("YmdHis") . rand(1000, 9999);//"vop" . date("YmdHis") . rand(1000, 9999); . get_rand_str(10, 0, 1)
$this->pay_code = 'weixin';
$data['user_id'] = $user['user_id'];
$data['nickname'] = $user['nickname'];
$data['ctime'] = time();
$data['store_id'] = getMobileStoId();
$data['num'] = $num;
$order_id = M('recharge')->add($data);
}
break;
//积分充值
case 1:
$mon = I("selemon");
$integ = I("seleinteg");
$num = I("buynum/d", 1);
$integ=str_replace(",","",$integ);
$mon=str_replace(",","",$mon);
$integ = number_format($integ,2,".","");
$mon =number_format($mon,2,".","");
/*--规则检验--*/
$istrue = 0;
if ($this->pm_erpid)//账套
{
$tk['api_token'] = tpCache("shop_info.api_token", getMobileStoId());
$rs = getApiData("wxd.vip.intertosum", $tk['api_token']);
if ($rs) {
$d = json_decode($rs, true);
foreach ($d['data'] as $k => $v) {
if ($mon == number_format($v['ToSum'], 2, ".", "") && $integ == number_format($v['Integral'], 2, ".", "")) {
$istrue = 1;
break;
}
}
}
}
else
{
$point_rate=json_decode(tpCache('shopping.point_rate',getMobileStoId()),true);
$getIntegral=0;
$getToSum=0;
if ($point_rate['money'])
{
$getToSum=$point_rate['money'];
}
if ($point_rate['integral'])
{
$getIntegral=$point_rate['integral'];
}
if ($mon == number_format($getToSum, 2, ".", "") && $integ == number_format($getIntegral, 2, ".", "")) {
$istrue = 1;
}
}
if ($istrue == 0) {
$this->error('提交失败,参数有误!', U("Mobile/User/points", array('stoid' => getMobileStoId())));
exit;
}
$ramark = '积分充值';
$account = $mon * $num;
$data['account'] = $account;
$this->pay_code = 'weixin';
if ($order_id > 0) {
M('recharge')->where(array('order_id' => $order_id, 'user_id' => $user['user_id']))->save($data);
} else {
$data['user_id'] = $user['user_id'];
$data['nickname'] = $user['nickname'];
$data['order_sn'] = $getaccdb.'_voi' . date("YmdHis") . rand(1000, 9999);
$data['ctime'] = time();
$data['recharge_type'] = $recharge_type;
$data['store_id'] = getMobileStoId();
$data['price'] = $mon;
$data['integral_remark'] = $ramark;
$data['integral'] = $integ;
$data['num'] = $num;
$order_id = M('recharge')->add($data);
}
break;
//购买服务卡
case 2:
$data['recharge_type'] = $recharge_type;
if ($order_id > 0) {
M('recharge')->where(array('order_id' => $order_id, 'user_id' => $user['user_id']))->save($data);
} else {
$where['SM_ItemManage.Id'] = array('=', $jid);
$tk['api_token']=tpCache('shop_info.api_token',getMobileStoId());
$aa = getApiData("wxd.pos.smitemanage.list.get", $tk['api_token'], null, $where);
mlog($aa . ':' . $jid . ':' . getMobileStoId() . ':' . $tk['api_token'], "777ttt");
$aa = json_decode($aa, true);
if ($aa && $aa["code"] == 1) {
$data["price"] = number_format($aa["data"][0]["Price"], 2); //金额
$data["integral_remark"] = "线上会员购买服务卡";
$data["yucun_id"] = $aa["data"][0]["Id"];
$data["account"] = $aa["data"][0]["Price"] * 1;
$data["num"] = $aa["data"][0]["EndDate"];
$data['integral'] = $aa["data"][0]["Qty"];
$data["order_sn"] = $getaccdb.'_ser' . date("YmdHis") . rand(1000, 9999);//"vop" . date("YmdHis") . rand(1000, 9999);
$this->pay_code = 'weixin';
$data['user_id'] = $user['user_id'];
$data['nickname'] = $user['nickname'];
$data['ctime'] = time();
$data['store_id'] = getMobileStoId();
$order_id = M('recharge')->add($data);
}
}
break;
//等级卡 3:购买
case 3:
$data['recharge_type'] = $recharge_type;
if ($order_id > 0) {
M('recharge')->where(array('order_id' => $order_id, 'user_id' => $user['user_id']))->save($data);
} else {
$param=I('post.');
$tt=strtotime("-10 minute");
/*--- 判断是不是有购买一次,十分钟前---*/
$is_buy=M("recharge")
->where("cardid",$param["cardid"])
->where("user_id",$user['user_id'])
->where("recharge_type",3)
->where("ctime>".$tt)
->where("pay_status",1)
->find();
if($is_buy){
$this->error('为避免您重复购买,请稍后再买!', U("Mobile/index/index", array('stoid' => getMobileStoId())));
}
$fileds_key = md5($param["cardid"] . $param['fee'] . $param["ex_days"] . getErpKey());
if ($param['keys'] != $fileds_key)
$this->error('参数错误', U("Mobile/index/index", array('stoid' => getMobileStoId())));
if($param['code']) {
//检验邀请人
$recommon = M("users")->where("mobile", $param['code'])->where('store_id', getMobileStoId())->find();
if (empty($recommon)) $this->error('邀请人没有绑定会员', U("Mobile/index/index", array('stoid' => getMobileStoId())));
if (empty($recommon['card_field'])) $this->error('邀请人不是plus会员', U("Mobile/index/index", array('stoid' => getMobileStoId())));
$end = strtotime($recommon['card_expiredate']);
if ($end < time()) {
$this->error('邀请人plus会员已经过期', U("Mobile/index/index", array('stoid' => getMobileStoId())));
}
}
//填充有效期
$data["days"] = $param["ex_days"];
//填充有效期
$data["days"] = $param["ex_days"];
$data["integral_remark"] = strtolower($param["newcorrprice"]);
$data["cardid"] = $param["cardid"];
$data["account"] = $param['fee'];
$data["recommon"]=$param['code'];
$data['serviceman']=$param['staff'];
$data["order_sn"] = $getaccdb.'_vlc' . date("YmdHis") . rand(1000, 9999);//"vop" . date("YmdHis") . rand(1000, 9999); . get_rand_str(10, 0, 1)
$this->pay_code = 'weixin';
$data['user_id'] = $user['user_id'];
$data['nickname'] = $user['nickname'];
$data['ctime'] = time();
$data['store_id'] = getMobileStoId();
$order_id = M('recharge')->add($data);
}
break;
//等级卡 4:续费
case 4:
$data['recharge_type'] = $recharge_type;
if ($order_id > 0) {
M('recharge')->where(array('order_id' => $order_id, 'user_id' => $user['user_id']))->save($data);
} else {
$param = I('post.');
$fileds_key = md5($param["cardid"] . $param['fee'] . getErpKey());
if ($param['keys'] != $fileds_key)
$this->error('参数错误', U("Mobile/index/index", array('stoid' => getMobileStoId())));
$data["integral_remark"] = strtolower($param["newcorrprice"]);
$data["cardid"] = $param["cardid"];
$data["account"] = $param['fee'];
$data["recommon"] = $param['code'];
$data['serviceman'] = $param['staff'];
$data["order_sn"] = $getaccdb.'_vlc' . date("YmdHis") . rand(1000, 9999);//"vop" . date("YmdHis") . rand(1000, 9999); . get_rand_str(10, 0, 1)
$this->pay_code = 'weixin';
$data['user_id'] = $user['user_id'];
$data['nickname'] = $user['nickname'];
$data['ctime'] = time();
$data['store_id'] = getMobileStoId();
$order_id = M('recharge')->add($data);
}
break;
//购买礼包
case 5:
$lbid=I('lbid');
$storeid=getMobileStoId();
$libao=M('libao_form')->where('store_id='.$storeid.' and startime<='.time().' and endtime>='.time().' and id='.$lbid)->select();
$lbnumber=$getaccdb.'_lb'. date("YmdHis") . rand(1000, 9999);
$data['user_id']= $user['user_id'];
$data['store_id']=getMobileStoId();
$data['lbid']=$lbid;
$data['expdate']=strtotime('+'.$libao[0]['expday'].' day',time());
$data['number']=$lbnumber;
$data['paytype']=2;
$data['fbillstate']=0;
$data['add_time']=time();
$order_id=M('libao_formvip')->add($data);
$list=M('libao_list')->where(array('store_id'=>$storeid,'lbid'=>$lbid))->select();
if($list)
{
for ($i=0;$i<count($list);$i++)
{
unset($data);
$data['user_id']=$user['user_id'];
$data['store_id']=$storeid;
$data['lbvipid']=$order_id;
$data['goods_num']=$list[$i]['goods_num'];
$data['goods_name']=$libao[0]['lbtype']==1?$list[$i]['goods_name']:$list[$i]['cpid'];
$data['goods_sn']=$list[$i]['goods_sn'];
$data['lb_state']=$list[$i]['state'];
M('libao_listvip')->add($data);
}
}
break;
case 6:
$order_sn=I("order_sn");
$ord=M('marketing_user_buyreceive_form')->where("order_sn", $order_sn)->find();
if(empty($ord)){ $this->error('未找到订单!'); }
if($ord['pay_state']==1){ $this->error('订单已经支付!'); }
if($ord['pay_state']==-1){ $this->error('订单已经取消!');}
$code_str = $this->payment->getJSAPI_new_lb($ord);
exit($code_str);
break;
default:
break;
}
if ($order_id) {
if($recharge_type==5)
{
$order=M('libao_formvip')->alias('a')->where('a.id',$order_id)->field('a.*,a.fbillstate as pay_status,number as order_sn')->find();
}
else
{
$order = M('recharge')->where("order_id", $order_id)->find();
}
if (is_array($order) && $order['pay_status'] == 0) {
$order['order_amount'] = $order['account'];
$pay_radio = $_REQUEST['pay_radio'];
$config_value = parse_url_param($pay_radio); // 类似于 pay_code=alipay&bank_code=CCB-DEBIT 参数
if($recharge_type!=5)
{
$payment_arr = M('Plugin')->where("`type` = 'payment'")->getField("code,name");
M('recharge')->where("order_id", $order_id)->save(array('pay_code' => $this->pay_code, 'pay_name' => $payment_arr[$this->pay_code]));
}
//微信JS支付
if ($this->pay_code == 'weixin' && $_SESSION['openid'] && strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) {
switch ($recharge_type)
{
//余额充值
case 0:
$code_str = $this->payment->getJSAPI_VOP($order['order_sn']);
exit($code_str);
break;
//积分充值
case 1:
$code_str = $this->payment->getJSAPI_VOI($order['order_sn']);
exit($code_str);
break;
//购买服务卡
case 2:
$code_str = $this->payment->getJSAPI_SER($order['order_sn']);
exit($code_str);
break;
//等级卡 3:购买
case 3:
$code_str = $this->payment->getJSAPI_VLC($order['order_sn']);
exit($code_str);
break;
//等级卡 4:续费
case 4:
$code_str = $this->payment->getJSAPI_VLC($order['order_sn']);
exit($code_str);
break;
//购买礼包
case 5:
$code_str = $this->payment->getJSAPI_LB($order['order_sn']);
exit($code_str);
break;
default:
$code_str = $this->payment->getJSAPI($order['order_sn']);
exit($code_str);
break;
}
} else {
if ($recharge_type == 2) {
$this->error('暂时只支持微信支付!', U("Mobile/User/shopping_card", array('stoid' => getMobileStoId())));
}
else if($recharge_type==5)
{
$this->error('暂时只支持微信支付!', U("Mobile/Libao/index", array('stoid' => getMobileStoId())));
}
else {
$this->error('暂时只支持微信支付!', U("Mobile/User/points", array('stoid' => getMobileStoId())));
}
}
} else {
// mlog('订单ID:'.json_encode($order).' 支付状态:'.$order['pay_status'].' ID:'.$order_id,'libaolog');
$this->error('此充值订单,已完成支付!', U("Mobile/index/index", array('stoid' => getMobileStoId())));
}
} else {
$this->error('提交失败,参数有误!', U("Mobile/index/index", array('stoid' => getMobileStoId())));
}
//$this->assign('code_str', $code_str);
$this->assign('order_id', $order_id);
return $this->fetch('recharge', getMobileStoId()); //分跳转 和不 跳转
}
// 服务器点对点 // http://www.tp-shop.cn/index.php/Home/Payment/notifyUrl
public function notifyUrl()
{
$this->payment->response();
exit();
}
// 页面跳转 // http://www.tp-shop.cn/index.php/Home/Payment/returnUrl
public function returnUrl()
{
$result = $this->payment->respond2(); // $result['order_sn'] = '201512241425288593';
if (stripos($result['order_sn'], 'recharge') !== false || stripos($result['order_sn'], 'vop') !== false || stripos($result['order_sn'], 'vlc') !== false) {
$order = M('recharge')->where("order_sn", $result['order_sn'])->find();
$this->assign('order', $order);
if ($result['status'] == 1)
return $this->fetch('recharge_success', getMobileStoId());
else
return $this->fetch('recharge_error', getMobileStoId());
exit();
}
$order = M('order')->where("order_sn", $result['order_sn'])->find();
$this->assign('order', $order);
if ($result['status'] == 1)
return $this->fetch('success', getMobileStoId());
else
return $this->fetch('error', getMobileStoId());
}
//支付成功
public function payment_success()
{
//判断会员是否有绑定线下,没有的话进行线下
$getopenid = $_SESSION['openid'];
$stoid = I('stoid');
$paytype=I('ptype');
//循环更新订单状态,以及库存
$pno=I('orderno');
$odr_arr=M('order')->where('parent_sn',$pno)->where('store_id',$stoid)
->where('pay_status',0)
->where('order_status=0 or order_status=1')
->field('order_amount,order_sn,pickup_id')->select();
foreach ($odr_arr as $k=>$v) {
if ($v['order_amount'] <= 0) {
mlog("payment_success:".$pno,"update_pay_status2/".getMobileStoId());
update_pay_status2($v['order_sn'], 1);
}
}
//结算的数据
$order=M('order')->where('order_sn',$pno)->where('store_id',$stoid)->select();
$order_amount=0;
$user_money=0;
//判断是不是单个商品的订单
if(!empty($order)) {
//单个的商品结算的
$order = $order[0];
//获取余额及微信的价格 计算总价
$total_price=$order["order_amount"]+$order["user_money"];
$this->assign('order', $order);
$this->assign('total_price', $total_price);
if ($order['exp_type'] == 1) {
$pick_up = M('pick_up')->where('pickup_id', $order['pickup_id'])->where('store_id', $stoid)->select();
$pick_up = $pick_up[0];
$this->assign('pick_up', $pick_up);
}
}else{
//多个商品的时候
$order_parent=M('order')->where('parent_sn',$pno)->where('store_id',$stoid)->select();
//php创建数组
$pick_arr=array();
//获取余额及微信的价格
foreach ($order_parent as $kl => $vl) {
$order_amount+=$vl['order_amount'];
$user_money+=$vl['user_money'];
if ( $vl['exp_type'] == 1) {
$pick_up = M('pick_up')->where('pickup_id', $vl['pickup_id'])->where('store_id', $stoid)->select();
$pick_up = $pick_up[0];
$pick_arr['pickup_name']=$pick_up['pickup_name'];
$pick_arr['fulladdress']=$pick_up['fulladdress'];
//添加数组参数
$order_parent[$kl]['pick_arr']=$pick_arr;
}
}
//获取余额及微信的价格 计算总价
$total_price=$order_amount+$user_money;
$this->assign('order_parent',$order_parent);
$this->assign('total_price', $total_price);
}
if($paytype)
{
$this->assign('type', $paytype);
}
else{
if ($stoid && $getopenid) {
$user_info = M('users')->alias('a')
->join(' store b', 'a.store_id=b.store_id', 'left')
->field("a.user_id,a.openid,a.mobile,a.erpvipid,a.erpvipno,b.api_token")
->where(array('a.openid' => $getopenid, 'a.store_id' => $stoid))->find();
if ($user_info && $user_info['mobile'] && empty($user_info['erpvipid'])) {
$user_data = array();
$user_data['MobileTel'] = $user_info['mobile'];
$getpickup_id=0;
if ($odr_arr && $odr_arr[0]['pickup_id']) {
$getpickup_id=$odr_arr[0]['pickup_id'];
$pick = M("pick_up")->where("pickup_id", $odr_arr[0]['pickup_id'])->find();
if ($pick) {
$user_data['StoragesId'] = $pick['keyid'];
}
}
$rs = getApiData("wxd.vip.mshop.register", $user_info['api_token'], array($user_data));
if ($rs) {
$rs = json_decode($rs, true);
if ($rs['code'] && $rs['data']) {
$new_user_info = $rs['data'];
$map['erpvipid'] = $new_user_info['Id'];
$map['erpvipno'] = $new_user_info['VIPNo'];
if ($getpickup_id) {
$map['pickup_id'] = $getpickup_id;
}
$falg = M('users')->where('user_id', $user_info['user_id'])->save($map);
}
}
}
}
}
return $this->fetch("", getMobileStoId());
}
//支付成功
public function recharge_success()
{
$ordid = I('order_id');
$order = $ord = M('recharge')->where("order_id", $ordid)->find();
$this->assign('order', $order);
$this->assign('type', $ord['recharge_type']);
return $this->fetch("", getMobileStoId());
}
//支付失败
public function pay_error()
{
//判断会员是否有绑定线下,没有的话进行线下
$getopenid = $_SESSION['openid'];
$stoid = I('stoid');
if ($stoid && $getopenid) {
$ord = I("ordno");
if ($ord)
{
$odr_arr=M('order')->where('parent_sn',$ord)->where('store_id',getMobileStoId())
->field('order_amount,order_sn,pickup_id')->select();
}
$user_info = M('users')->alias('a')
->join(' store b', 'a.store_id=b.store_id', 'left')
->field("a.user_id,a.openid,a.mobile,a.erpvipid,a.erpvipno,b.api_token")
->where(array('a.openid' => $getopenid, 'a.store_id' => $stoid))->find();
if ($user_info && $user_info['mobile'] && empty($user_info['erpvipid'])) {
$getpickup_id=0;
$user_data = array();
$user_data['MobileTel'] = $user_info['mobile'];
if ($odr_arr && $odr_arr[0]['pickup_id']) {
$getpickup_id=$odr_arr[0]['pickup_id'];
$pick = M("pick_up")->where("pickup_id", $odr_arr[0]['pickup_id'])->find();
if ($pick) {
$user_data['StoragesId'] = $pick['keyid'];
}
}
$rs = getApiData("wxd.vip.mshop.register", $user_info['api_token'], array($user_data));
if ($rs) {
$rs = json_decode($rs, true);
if ($rs['code'] && $rs['data']) {
$new_user_info = $rs['data'];
$map['erpvipid'] = $new_user_info['Id'];
$map['erpvipno'] = $new_user_info['VIPNo'];
if ($getpickup_id) {
$map['pickup_id'] = $getpickup_id;
}
$falg = M('users')->where('user_id', $user_info['user_id'])->save($map);
}
}
}
}
$err = urldecode(urldecode(I('err')));
$this->assign('err', $err);
$this->assign('ordno', $ord);
return $this->fetch("payment_error", getMobileStoId());
}
/*--跳转支付失败页--*/
public function gopayerr($msg, $stoid)
{
$url = U("mobile/payment/pay_error",
array("stoid" => $stoid, 'err' => $msg, 'ordno' =>''));
$this->redirect($url);
}
/*--跳转支付失败页--*/
public function gopayerr2($msg, $stoid)
{
$url = U("mobile/payment/pay_error2",
array("stoid" => $stoid, 'err' => $msg, 'ordno' =>''));
$this->redirect($url);
}
public function pay_lb_success(){
$stoid=I("stoid");
$orderno=I("orderno");
$ord=M("marketing_user_buyreceive_form")->where("order_sn",$orderno)->find();
$this->assign("order",$ord);
$user=session("user");
$back_url=WXD_LB_URL.'MyGiftPack/MyGiftPack?stoid='.$stoid.'&userid='.$user['user_id'];
$this->assign("back_url",$back_url);
return $this->fetch("",$stoid);
}
public function pay_lb_error(){
$stoid=I("stoid");
$orderno=I("orderno");
$this->assign("orderno",$orderno);
$user=session("user");
$back_url=WXD_LB_URL.'MyGiftPack/MyGiftPack?stoid='.$stoid.'&userid='.$user['user_id'];
$this->assign("back_url",$back_url);
return $this->fetch("",$stoid);
}
}