Cart.php
196 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
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
<?php
/**
* tpshop
* ============================================================================
* * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: IT宇宙人 2015-08-10 $
*/
namespace app\mobile\controller;
use think\Db;
use think\Cookie;
use app\home\logic\UsersLogic;
class Cart extends MobileBase
{
public $cartLogic; // 购物车逻辑操作类
public $user_id = 0;
public $user = array();
public $redis =null;
/**
* 析构流函数
*/
public function __construct()
{
parent::__construct();
$this->cartLogic = new \app\home\logic\CartLogic();
if (session('?user')) {
$nuser=array(
'cart3', 'cart3_nosub','cart6_nosub','cart6'
);
if (!in_array(ACTION_NAME, $nuser)) {
$user = session('user');
$user = M('users')->where("user_id", $user['user_id'])->find();
session('user', $user); //覆盖session 中的 user
$this->user = $user;
$this->user_id = $user['user_id'];
$this->assign('user', $user); //存储用户信息
}else{
$user = session('user');
$this->user = $user;
$this->user_id = $user['user_id'];
$this->assign('user', $user); //存储用户信息
}
$nologin = array(
'getNum', 'addskill', 'cart2skill', 'del_address','cart2','ajaxAddCart',
'get_area', 'edit_address', 'add_address', 'cart3', 'reg_user','cart3_nosub','cart6_nosub',
'cart5','cart6','addwx_address'
);
if ($this->user_id == 0 && ACTION_NAME!='getNum') {
$stoid=getMobileStoId();
if($stoid==1){
$this->user=['user_id'=>982127];
$this->user_id=982127;
}
else
$this->error('请先登录', U('Mobile/User/login', array('stoid' => getMobileStoId(), 'oldurl' => urlencode(curHostURL() . $_SERVER['']))));
}
if (!in_array(ACTION_NAME, $nologin)) {
if (($this->pm_erpid && (!$user || !$user['erpvipid'])) || (empty($this->pm_erpid) && !$user || !$user['mobile'])) {
$this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId())));
exit;
}
}
} else {
$uid = Cookie::get('user_id');
if ($uid) {
$user = M('users')->where("user_id", $uid)->where("store_id", getMobileStoId())->find();
session('user', $user); //覆盖session 中的 user
$this->user = $user;
$this->user_id = $user['user_id'];
$this->assign('user', $user); //存储用户信息
} else {
$stoid = getMobileStoId();
if ($stoid == 1) {
$this->user = ['user_id' => 982127];
$this->user_id = 982127;
}
}
}
$this->assign('pstore_id', getMobileStoId());
/*----
$getylpres=getylapp_res(getMobileStoId(),'2');
if ($getylpres)
{
$this->assign('ylpres',$getylpres);
}-----*/
}
public function cart()
{
$stoid=getMobileStoId();
//判断一下有没有秒杀
$t=time();
$f_list=M("flash_sale")->where("store_id",$stoid)->where("is_end",0)
->where('show_time<='.$t." and end_time>=".$t)->select();
if($f_list)
$this->assign('f_list', $f_list);
$t=time();
//获取热卖商品
$hot_goods = M('Goods')
->where("on_time<".$t." and (down_time>".$t." or down_time=0 or down_time='' or down_time is null)")
->where('is_hot=1 and is_on_sale=1 ' . getMobileStoWhere())->limit(20)->select();
$this->assign('hot_goods', $hot_goods);
return $this->fetch('cart', getMobileStoId());
}
/**
* 将商品加入购物车
*/
function addCart()
{
$goods_id = I("goods_id/d"); // 商品id
$goods_num = I("goods_num/d");// 商品数量
$goods_spec = I("goods_spec"); // 商品规格
$goods_spec = json_decode($goods_spec, true); //app 端 json 形式传输过来
$unique_id = I("unique_id"); // 唯一id 类似于 pc 端的session id
$user_id = I('user_id/d', 0); // 用户id
if (empty($this->user['erpvipid']))
return array('status' => -101, 'msg' => '购买商品必须先绑定线下会员', 'result' => '');
$result = $this->cartLogic->addCart($goods_id, $goods_num, $goods_spec, $unique_id, $user_id); // 将商品加入购物车
upload_ylp_log('商品加入购物车');
exit(json_encode($result));
}
/**
* ajax 将商品加入购物车
*/
function ajaxAddCart()
{
$goods_id = I("goods_id/d"); // 商品id
$goods_num = I("goods_num/d");// 商品数量
$goods_spec = I("goods_spec/a", array()); // 商品规格
$pick_up = I("pickup_id/d"); //获取门店id
$to_catr = I("to_catr/d");//1:立即购买
if($to_catr==3) $to_catr=1;
$goods_list = I('goods_list/s');//搭配有值,其他的值是underfined
$isinte=I('isinte/d',0);//积分商品普通购买
$ispd=I('ispd/d',0);//拼团商品普通购买
if ($this->user_id == 0) {
return array('status' => -101, 'msg' => '非法操作', 'result' => '');
}
$result = $this->cartLogic
->addCart($goods_id, $goods_num, $goods_spec, $this->session_id, $this->user, $pick_up, $to_catr, $goods_list,$isinte,$ispd); // 将商品加入购物车
upload_ylp_log('商品加入购物车');
exit(json_encode($result));
}
/**
* 秒杀ajax将商品加入购物车
*/
public function addskill()
{
$goods_id = I("goods_id/d"); // 商品id
$goods_num = I("goods_num/d");// 商品数量
$goods_spec = I("goods_spec/a", array()); // 商品规格
$pick_up = I("pickup_id/d"); //获取门店id
$to_catr = I("to_catr/d");//1:立即购买
if ($this->user_id == 0) {
return array('status' => -101, 'msg' => '非法操作', 'result' => '');
}
$result = $this->cartLogic
->addCart($goods_id, $goods_num, $goods_spec, $this->session_id, $this->user, $pick_up, $to_catr); // 将商品加入购物车
upload_ylp_log('商品加入购物车');
exit(json_encode($result));
}
/*
* 请求获取购物车列表
*/
public function cartList()
{
$cart_form_data = input('cart_form_data'); // goods_num 购物车商品数量
$cart_form_data = json_decode($cart_form_data, true); //app 端 json 形式传输过来
$unique_id = I("unique_id"); // 唯一id 类似于 pc 端的session id
$user_id = I("user_id/d"); // 用户id
$where['session_id'] = $unique_id; // 默认按照 $unique_id 查询
if ($user_id) {
$where['user_id'] = $user_id;
}
$cartList = M('Cart')->where($where)->getField("id,goods_num,selected,goods_id");
/*--要剔除下架商品,活动有过期的商品--*/
foreach ($cartList as $k => $v) {
$good = M('goods')
->where('goods_id', $v['goods_id'])
->where('is_on_sale=1')->find();
if ($good) {
if ($v['prom_type'] != 0) {
$prom = get_goods_promotion($v["goods_id"], $user_id);
if ($prom['is_end'] == 2 || $prom['is_end'] == 3 || $prom['is_end'] == 1) {
M('Cart')->where('goods_id', $v['goods_id'])->where('user_id', $user_id)->delete();
unset($cartList[$k]);
}
}
} else {
M('Cart')->where('goods_id', $v['goods_id'])->where('user_id', $user_id)->delete();
unset($cartList[$k]);
}
}
if ($cart_form_data) {
// 修改购物车数量 和勾选状态
foreach ($cart_form_data as $key => $val) {
$data['goods_num'] = $val['goodsNum'];
$data['selected'] = $val['selected'];
$cartID = $val['cartID'];
if (($cartList[$cartID]['goods_num'] != $data['goods_num']) || ($cartList[$cartID]['selected'] != $data['selected']))
M('Cart')->where("id", $cartID)->save($data);
}
//$this->assign('select_all', $_POST['select_all']); // 全选框
}
$result = $this->cartLogic->cartList($this->user, $unique_id, 0);
upload_ylp_log('购物车列表');
exit(json_encode($result));
}
/**
* 购物车第二步确定页面
*/
public function cart2()
{
$killarr = null;
if ($this->user_id == 0)
$this->error('请先登录', U('Mobile/User/login', array('stoid' => getMobileStoId())));
/*--不能重复的一张表--*/
//$userd=M("users")->where('user_id',$this->user_id)->find();
$userd = $this->user;
$locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
$this->assign('u_money', number_format($userd['user_money'] - $userd['frozen_money'] - $locking_money, 2));
//20180717 season(增加短信随机码校验)
$storeconfig = M('store_config')->where('store_id', getMobileStoId())
->field('reg_type,reg_info,reg_default,sms_send_type,switch_list')->find();
$sms_send_type = json_decode($storeconfig['sms_send_type'], true);
$this->assign('s_type', $sms_send_type['type'] ? $sms_send_type['type'] : 0);
$this->assign('s_time_out', $sms_send_type['time_out'] ? $sms_send_type['time_out'] : 60);
$this->assign('is_verifycode', $sms_send_type['is_verifycode'] ? $sms_send_type['is_verifycode'] : 0);
$user_openid = $this->user['openid'];
//$user_openid="ou608v4s8TmwUsGLtJKDvdPKat5w"; //测试用
$this->assign("user_openid", $user_openid);
$user_openidkey = md5($user_openid . "&" . getErpKey());
$this->assign("user_openid", $user_openid);
$this->assign("user_openidkey", $user_openidkey);
$is_pt=I("is_pt");
$this->assign("is_pt", $is_pt);
//---先查询是不是阶梯团----
if($is_pt!=3) {
/*---获取地区---*/
$region_list = get_region_list();
$addlist = M('user_address')->where(['user_id' => $this->user_id])->select();
foreach ($addlist as $kk => $vv) {
$vv['provicename'] = $region_list[$vv['province']]['name'];
$vv['cityname'] = $region_list[$vv['city']]['name'];
$vv['districtname'] = $region_list[$vv['district']]['name'];
$vv['twonname'] = $region_list[$vv['twon']]['name'];
//$address = M('user_address')->where(['user_id'=>$this->user_id,'is_default'=>1])->find();
$addrstr = $vv['provicename'] . "-" . $vv['cityname'];
if (!empty($vv['district']))
$addrstr .= "-" . $vv['districtname'];
if (!empty($vv['twon']))
$addrstr = $addrstr . "-" . $vv['twonname'];
$vv['addrstr'] = $addrstr;
$addlist[$kk] = $vv;
}
$this->assign("addlist", $addlist);
$address_id = I('address_id/d');
if ($address_id) {
foreach ($addlist as $kk => $vv) {
if ($vv['address_id'] == $address_id) {
$address = $vv;
}
}
} else {
foreach ($addlist as $kk => $vv) {
if ($vv['is_default'] == 1) {
$address = $vv;
}
}
}
$p = M('region')->where(array('parent_id' => 0, 'level' => 1))->select();
$this->assign('province', $p);
if (empty($address)) {
//header("Location: ".U('Mobile/User/add_address',array('stoid'=>getMobileStoId(),'source'=>'cart2')));
$this->assign('setadd', 1);
} else {
$this->assign('address', $address);
$this->assign('setadd', 0);
}
}
/*--是否是购物车--*/
$tocart = I("tocart/d", 0);
$result = null;
if ($tocart == 0) {
if ($this->cartLogic->cart_count($this->user_id, 1) == 0)
$this->error('你的购物车没有选中商品', 'Index/index', array('stoid' => getMobileStoId()));
$result = $this->cartLogic->cartList_cart2($this->user, $this->session_id, 1, 1); //获取购物车商品
} else {
$count = M('Cart')->where(['user_id' => $this->user_id, 'state' => 1])->count();
if ($count == 0)
$this->redirect('Index/index', array('stoid' => getMobileStoId()));
$result = $this->cartLogic->gobuyList_cart2($this->user, $this->session_id); //获取购物车商品
}
/*--购物车商品分组--*/
$cart_goods = $result['cartList'];
$expty = 0;
$prom_goods_arr=$this->com_prom_goods($cart_goods);
foreach ($cart_goods as $kp => $vp) {
$exp2 = 0;
if ($vp['distr_type'] != $vp['bdistr_type']) {
$exp2 = $vp['distr_type'] == 0 ? $vp['bdistr_type'] : $vp['distr_type'];
} else {
$exp2 = $vp['distr_type'];
}
$cart_goods[$kp]['expty'] = $exp2;
if ($vp['is_gift'] == 0) {
//判断最后的物流方式
if ($expty != 0) {
if ($expty != $exp2) {
if ($exp2 == 2 || $expty == 2) {
$expty = 2;
} else {
$expty = 0;
}
}
} else {
$expty = $exp2;
}
}
}
$this->assign("expty", $expty);
$shippingList = M('store_shipping')->alias('a')->join("shipping b", "a.shipping_id=b.shipping_id")
->field('b.shipping_id,b.shipping_code,b.shipping_name,b.shipping_desc,b.shipping_logo')
->where("a.status=1 and a.store_id=" . getMobileStoId())->cache("shippingList_" . getMobileStoId(), TPSHOP_CACHE_TIME)
->select();//物流公司
/*--
if(I('cid') != ''){
$cid = I('cid');
$checkconpon = M('coupon')->field('id,name,money')->where("id = $cid")->find(); //要使用的优惠券
$checkconpon['lid'] = I('lid');
}--*/
/*----------购物车商品分组---------*/
$sql = null;
if ($tocart == 0) {
$sql = "select pickup_id,pickup_name from __PREFIX__pick_up where pickup_id in(select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and selected=1 and state=0 GROUP BY pick_id)";
} else if ($tocart == 1) {
$sql = "select pickup_id,pickup_name from __PREFIX__pick_up where pickup_id in(select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and state=1 GROUP BY pick_id)";
} else {
$sql = "select pickup_id,pickup_name from __PREFIX__pick_up where pickup_id in(select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and state=2 GROUP BY pick_id)";
}
$plist_cart = Db::query($sql);
foreach ($plist_cart as $k => $v) {
$isallskill = 1;
$expty00 = 0;
$geterpwareidlist="";//当前各个门店购买线下商品Id
$check_quan_price=0;
foreach ($cart_goods as $kk => $vv) {
if ($vv['pick_id'] == $v['pickup_id']) {
mlog("获取cart信息:".json_encode($vv),"cart2/".getMobileStoId());
$list[] = $vv;
$expty11 = $vv['expty'];
if ($expty00 == 0) {
$expty00 = $expty11;
}
$fect_price=$vv['goods_price'];
$cut_price=0;
$goods_num=$vv['goods_num'];
//---优惠活动----
if($vv['prom_type']==3){
if($prom_goods_arr[$vv['pick_id']][$vv['prom_id']]['is_xz_yh']) continue;
if($prom_goods_arr[$vv['pick_id']][$vv['prom_id']]['prom_price']<=0) continue;
}
//----------团购是否可以使用优惠券-----
else if($vv['prom_type']==2){
$t = time();
$gb = M('group_buy')->where('store_id', getMobileStoId())
->where('id', $vv['prom_id'])
->where('start_time<' . $t)
->where('end_time>' . $t)->where('is_end', 0)
->field('is_quan')
->find();
if ($gb) {
if ($gb['is_quan'] ==0 ) continue;
}
}
//----秒杀商品----
else if($vv['prom_type']==1) {
$t = time();
$fl = M('flash_sale')->where('store_id', getMobileStoId())
->where('id', $vv['prom_id'])
->where('start_time<' . $t)->where('end_time>' . $t)->where('is_end', 0)
->field("id")
->find();
if ($fl) {
$killarr[] = ['goods_id' => $vv['goods_id'], 'fid' => $fl['id'], 'num' => $vv['goods_num']];
continue;
}
}
//season 2018-10-29 start
if ($geterpwareidlist)
{
$geterpwareidlist .= "," . $vv['erpwareid'];
}
else {
$geterpwareidlist .= $vv['erpwareid'];
}
//season 2018-10-29 end
//season 2018-10-29 end
//$member_goods_price = $vv["goods_price"];
//$check_quan_price += $vv['goods_num'] * $member_goods_price;
$cut_price=$prom_goods_arr[$vv['pick_id']][$vv['prom_id']]['goods'][$vv['goods_id']]['fect_price'];
if($cut_price)
$check_quan_price += $cut_price;
else
$check_quan_price += $vv['goods_num'] * $fect_price;
}
if ($vv['prom_type'] != 1) {
if ($vv['prom_type'] == 6) {
$isallskill = 1;
}
/*-------
else if($vv['prom_type'] == 2 && $isallskill==1){
$t = time();
$gb = M('group_buy')->where('store_id', getMobileStoId())
->where('goods_id', $vv['goods_id'])
->where('start_time<' . $t)
->where('end_time>' . $t)->where('is_end', 0)
->field('is_quan')
->find();
if ($gb) {
if ($gb['is_quan'] ==1 ) $isallskill = 0;
}
}---*/
else{
$isallskill = 0;
}
}
/*-----
else {
$t = time();
$fl = M('flash_sale')->where('store_id', getMobileStoId())->where('goods_id', $vv['goods_id'])
->where('start_time<' . $t)->where('end_time>' . $t)->where('is_end', 0)
->find();
if ($fl) {
$killarr[] = ['goods_id' => $vv['goods_id'], 'fid' => $fl['id'], 'num' => $vv['goods_num']];
}
}---*/
}
if ($killarr) {
$this->assign("killarr", json_encode($killarr));
}
$plist_cart[$k]["goods"] = $list;
$plist_cart[$k]["expty"] = $expty00;
// 获取订单商品总价,$tocart=0为购物车 1为立即购买
//$r = $this->cartLogic->my_calculate_cart2($list, $this->user_id);
unset($list);
// 找出这个用户的优惠券没过期的 并且订单金额达到condition 优惠券指定标准的
$fzquan = M('frozen_quan')->where('user_id', $this->user_id)->field('CashRepNo')->select();
$snow = date("Y-m-d", time());
//是否关闭使用优惠券
$is_close_quan=tpCache("basic.is_close_quan",getMobileStoId());
$is_pt = I("is_pt");
//--如果所有商品不全是秒杀且没有优惠商品--
if ($isallskill == 0 && !$is_pt && !$is_close_quan) {
//要拿出包邮券的这一部分
//如果是注册的会员
$qlistall = "";
if ($this->user['erpvipid']) {
// $tk = tpCache('shop_info.api_token', getMobileStoId());
// $where = "VIPId='" . $this->user['erpvipid'] . "'";
// $where .= " and isnull(useObjectID,'')='' and IsUse=0 and (ValidDate is null or ValidDate='' or ValidDate>='" . $snow . "')";
// $where .= " and (BuySum<=" . $r." or BuySum=0 or BuySum is null)";
// $where .= " and Sum<=" . $r;
// $where .= " and (BeginDate='' or BeginDate is null or BeginDate<='" . $snow . "')";
// $order['Sum'] = 'desc';
// $rs = getApiData("wxderp.cashreplace.list.get", $tk, null, $where, 1, 1000, $order);
$accdb = tpCache('shop_info.ERPId', getMobileStoId());
//$data['BuySum']=$r;
$data['BuySum']=$check_quan_price;
$data['VIPId']=urlencode($this->user['erpvipid']);
$data['IsUse']=0;//0=未使用,1=已使用,2=过期
$data['isBeginDate']=1;
$data['WareIds']=urlencode($geterpwareidlist);
mlog("抵用券条件:".json_encode($data),"cart2/".getMobileStoId());
//$rs=getApiData_java("api/erp/vip/cash/list",$accdb,$data,1,1000);
$rs=getApiData_java("api/erp/vip/cash/page",$accdb,$data,1,1000);
mlog("抵用券0:" . json_encode($rs), "cart2/" . getMobileStoId());
if ($rs) {
mlog("抵用券:" . $geterpwareidlist . $rs, "cart2/" . getMobileStoId());
$qlistall = json_decode($rs, true);
if ($qlistall && $qlistall['code']==0) {
if(isset($qlistall['data']['pageData'])) {
$qlistall['data'] = $qlistall['data']['pageData'];
if ($qlistall['data']) {
foreach ($qlistall['data'] as $k1 => $v1) {
$qlistall['data'][$k1]['Sum'] = number_format(empty($v1['Sum']) ? 0 : $v1['Sum'], 2);
$qlistall['data'][$k1]['BuySum'] = number_format(empty($v1['BuySum']) ? 0 : $v1['BuySum'], 2);
$qlistall['data'][$k1]['BillDate'] = date('Y-m-d', strtotime($v1['BeginDate']));
if (empty($v1['ValidDate'])) {
$qlistall['data'][$k1]['ValidDate'] = "不限";
} else {
$qlistall['data'][$k1]['ValidDate'] = date('Y-m-d', strtotime($v1['ValidDate']));
}
//冻结的券不能使用
foreach ($fzquan as $ku => $vu) {
if ($qlistall['data'][$k1]['CashRepNo'] == $vu['CashRepNo']) {
unset($qlistall['data'][$k1]);
break;
}
}
}
}
}else{
$qlistall['data']=null;
}
}else{
$qlistall['data']=null;
}
$plist_cart[$k]["couponList"] = $qlistall['data'];
mlog("抵用券2:" .json_encode($plist_cart[$k]["couponList"]), "cart2/" . getMobileStoId());
unset($qlistall);
}
}
//通过缓存拿tk
$ERPId = $this->pm_erpid;
//如果是erp用户
if (empty($ERPId)) {
//非erp用户
$ti = time();
$r=$check_quan_price; //需要使用到券的商品
$qlistall = M('coupon_list')->where('store_id', getMobileStoId())
->where('uid', $this->user_id)->where('is_user', 0)
->where('begintime<' . $ti . ' and validtime>' . $ti)
->where('buysum<=' . $r . ' and sum<=' . $r)
->select();
if (!empty($qlistall)) {
foreach ($qlistall as $k1 => $v1) {
$qlistall[$k1]['CashRepNo']=$qlistall[$k1]['code'];
$qlistall[$k1]['Sum'] = number_format(empty($v1['sum']) ? 0 : $v1['sum'], 2);
$qlistall[$k1]['BuySum'] = number_format(empty($v1['buysum']) ? 0 : $v1['buysum'], 2);
$qlistall[$k1]['BillDate'] = date('Y-m-d', $v1['begintime']);
if (empty($v1['validtime'])) {
$qlistall[$k1]['ValidDate'] = "不限";
} else {
$qlistall[$k1]['ValidDate'] = date('Y-m-d', $v1['validtime']);
}
//冻结的券不能使用
foreach ($fzquan as $ku => $vu) {
if ($qlistall[$k1]['code'] == $vu['CashRepNo']) {
unset($qlistall[$k1]);
break;
}
}
}
}
$plist_cart[$k]["couponList"] = $qlistall;
unset($qlistall);
}
}
}
$this->assign('slist', $plist_cart);
$this->assign('shippingList', $shippingList); // 物流公司
//$this->assign('cartList', $result['cartList']); // 购物车的商品
$this->assign('total_price', $result['total_price']); // 总计
upload_ylp_log('购物车已选商品显示');
return $this->fetch('', getMobileStoId());
}
/*---------------------------------秒杀购物详情-------------------------------------------*/
public function cart2skill()
{
$this->assign("skill", 1);
if ($this->user_id == 0)
$this->error('请先登录', U('Mobile/User/login', array('stoid' => getMobileStoId())));
/*--不能重复的一张表--*/
//$userd=M("users")->where('user_id',$this->user_id)->find();
$userd = $this->user;
/*--清理未支付订单--*/
clear_flash_Order(getMobileStoId());
$storeconfig = M('store_config')->where('store_id', getMobileStoId())->field('reg_type,reg_info,reg_default,sms_send_type,switch_list')->find();
$sms_send_type = json_decode($storeconfig['sms_send_type'], true);
$this->assign('s_type', $sms_send_type['type'] ? $sms_send_type['type'] : 0);
$this->assign('s_time_out', $sms_send_type['time_out'] ? $sms_send_type['time_out'] : 60);
$this->assign('is_verifycode', $sms_send_type['is_verifycode'] ? $sms_send_type['is_verifycode'] : 0);
$locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
$this->assign('u_money', number_format($userd['user_money'] - $userd['frozen_money'] - $locking_money, 2));
$user_openid = $this->user['openid'];
//$user_openid="ou608v4s8TmwUsGLtJKDvdPKat5w"; //测试用
$this->assign("user_openid", $user_openid);
$user_openidkey = md5($user_openid . "&" . getErpKey());
$this->assign("user_openid", $user_openid);
$this->assign("user_openidkey", $user_openidkey);
mlog($user_openid."|".$user_openidkey,"cart2skill/".getMobileStoId());
/*---获取地区---*/
$region_list = get_region_list();
$addlist = M('user_address')->where(['user_id' => $this->user_id])->select();
foreach ($addlist as $kk => $vv) {
$vv['provicename'] = $region_list[$vv['province']]['name'];
$vv['cityname'] = $region_list[$vv['city']]['name'];
$vv['districtname'] = $region_list[$vv['district']]['name'];
$vv['twonname'] = $region_list[$vv['twon']]['name'];
//$address = M('user_address')->where(['user_id'=>$this->user_id,'is_default'=>1])->find();
$addrstr = $vv['provicename'] . "-" . $vv['cityname'];
if (!empty($vv['district']))
$addrstr .= "-" . $vv['districtname'];
if (!empty($vv['twon']))
$addrstr = $addrstr . "-" . $vv['twonname'];
$vv['addrstr'] = $addrstr;
$addlist[$kk] = $vv;
}
$this->assign("addlist", $addlist);
$address_id = I('address_id/d');
if ($address_id) {
foreach ($addlist as $kk => $vv) {
if ($vv['address_id'] == $address_id) {
$address = $vv;
}
}
} else {
foreach ($addlist as $kk => $vv) {
if ($vv['is_default'] == 1) {
$address = $vv;
}
}
}
$p = M('region')->where(array('parent_id' => 0, 'level' => 1))->select();
$this->assign('province', $p);
if (empty($address)) {
//header("Location: ".U('Mobile/User/add_address',array('stoid'=>getMobileStoId(),'source'=>'cart2')));
$this->assign('setadd', 1);
} else {
$this->assign('address', $address);
$this->assign('setadd', 0);
}
/*--是否是购物车--*/
$tocart = I("tocart/d", 0);
$result = null;
$count = M('Cart')->where(['user_id' => $this->user_id, 'state' => 1])->count();
if ($count == 0)
$this->redirect('Index/index', array('stoid' => getMobileStoId()));
$result = $this->cartLogic->gobuyList_cart2($this->user, $this->session_id); //获取购物车商品
/*--购物车商品分组--*/
$cart_goods = $result['cartList'];
$expty = 0;
$killarr=null;
foreach ($cart_goods as $kp => $vp) {
$exp2=0;
if($vp['distr_type']!=$vp['bdistr_type']){
$exp2=$vp['distr_type']==0?$vp['bdistr_type']:$vp['distr_type'];
}else{
$exp2=$vp['distr_type'];
}
$cart_goods[$kp]['expty']=$exp2;
if ($vp['is_gift'] == 0) {
//判断最后的物流方式
if ($expty != 0) {
if ($expty != $exp2) {
if($exp2==2 || $expty==2 ){
$expty=2;
}else{
$expty=0;
}
}
} else {
$expty =$exp2;
}
}
$t=time();
$fl=M('flash_sale')->where('store_id',getMobileStoId())->where('goods_id',$vp['goods_id'])
->where('start_time<'.$t)->where('end_time>'.$t)->where('is_end',0)
->find();
if($fl) {
$killarr[] = ['goods_id' => $vp['goods_id'], 'fid' =>$fl['id'],'num'=>$vp['goods_num']];
}
}
$this->assign("expty", $expty);
if($killarr)
$this->assign("killarr", json_encode($killarr));
$shippingList = M('store_shipping')->alias('a')->join("shipping b", "a.shipping_id=b.shipping_id")
->field('b.shipping_id,b.shipping_code,b.shipping_name,b.shipping_desc,b.shipping_logo')
->where("a.status=1 and a.store_id=" . getMobileStoId())->cache("shippingList_" . getMobileStoId(), TPSHOP_CACHE_TIME)
->select();//物流公司
/*----------购物车商品分组---------*/
$sql = null;
$sql = "select pickup_id,pickup_name from __PREFIX__pick_up where pickup_id in(select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and state=1 GROUP BY pick_id)";
//mlog('$tocart:'.$sql,'cart');
$plist_cart = Db::query($sql);
foreach ($plist_cart as $k => $v) {
$expty00 = 0;
foreach ($cart_goods as $kk => $vv) {
if ($vv['pick_id'] == $v['pickup_id']) {
$list[] = $vv;
$expty11=$vv['expty'];
if($expty00==0){
$expty00=$expty11;
}
}
}
$plist_cart[$k]["goods"] = $list;
$plist_cart[$k]["expty"]=$expty00;
unset($list);
}
$this->assign('slist', $plist_cart);
$this->assign('shippingList', $shippingList); // 物流公司
$this->assign('total_price', $result['total_price']); // 总计
upload_ylp_log('购物车已选商品显示');
return $this->fetch('cart2', getMobileStoId());
}
/**
* ajax 获取订单商品价格或者提交订单
*/
public function cart3()
{
if(empty($this->redis)){
//$this->redis=new \Redis();
//$this->redis->connect(redisip, 6379);
$this->redis=get_redis_handle();
}
$popvalue=null;
$popvalue2=null;
$stoid = I("stoid");
//拼单有关
$ispt=I('is_pt');
$pdid=I('pdid');
$team_qh=I('team_qh');
$pdgoodsnum=I('pdgoodsnum/d',0);
$g_promid=I('g_promid/a');
$no="";
$notime=microtime_float();
$rank_switch = tpCache('shopping.rank_switch', $stoid);//等级价格
$mz_switch = tpCache('shopping.is_beauty', $stoid);//美妆价格
$isinte=I("isinte",0);
//记录秒杀
$sd=null;
if ($_REQUEST['act'] == 'submit_order') {
$sd=I('da');
$no='r'.microtime_float().rand(10000, 99990);
if(!empty($sd)){
$skillarray=json_decode($sd,true);
foreach ($skillarray as $lk=>$lv){
//判断秒杀数量是否超限
//$name='ms'.$lv['fid'].'-'.$stoid;
$name=get_redis_name($lv['fid'],1,$stoid);
$num0=$lv['num'];
if($this->redis->lLen($name)<$num0){
return json(array('status' => -4, 'msg' => "秒杀商品已经抢光", 'result' => ''));
}
//秒杀队列控制
for($i=0;$i<$num0;$i++) {
$value = $this->redis->lPop($name);
$popvalue[]=$value;
}
//redis要加入set中,编号,类型,活动id,数量,时间,stoid
$key=$no.'-1-'.$lv['fid'].'-'.$num0.'-'.$notime;
$f_name=get_redis_set_name($stoid);
$this->redis->sAdd($f_name,$key);
}
}
//如果是拼单
if($ispt){
//$no='r'.microtime_float().rand(10000, 99990);
//$name='pind'.$pdid.'-'.$stoid;
$name=get_redis_name($pdid,6,$stoid);
if($this->redis->lLen($name)<$pdgoodsnum){
return json(array('status' => -4, 'msg' => "您晚了一步,商品已被抢光!", 'result' => ''));
}
//拼单队列控制
for($i=0;$i<$pdgoodsnum;$i++) {
$value = $this->redis->lPop($name);
$popvalue[]=$value;
}
//如果,$ispt是会员团的时候,要判断团的缓存
if($team_qh && $ispt=='2'){
//$name2='pind'.$pdid.'-'.$team_qh.$stoid;
$name2=get_redis_name($pdid,6,$stoid).":". $team_qh;
$value = $this->redis->lPop($name2);
if (empty($value)) {
foreach ($popvalue as $k=>$v)
$this->redis->lPush($name,$v);
return array('status' => -4, 'msg' => "手慢了,您参与的团已满团!", 'result' => '');
}
$popvalue2[]=$value;
}
//redis要加入set中,编号,类型,活动id,数量,时间,stoid
$key=$no.'-6-'.$pdid.'-'.$pdgoodsnum.'-'.$notime.'-'.$team_qh;
$p_name=get_redis_set_name($stoid);
$this->redis->sAdd($p_name,$key);
}
//如果是团购的话,要进行组合
if($g_promid){
$arr=null;
foreach ($g_promid as $key=>$val){
$promid=explode("-",$key)[1];
$arr[$promid]+=$val;
}
foreach ($arr as $ky=>$ve){
//判断秒杀数量是否超限
//$name='grb'.$ky.'-'.$stoid;
$name=get_redis_name($ky,2,$stoid);
$num0=$ve;
if($this->redis->lLen($name)<$num0){
return json(array('status' => -4, 'msg' => "团购商品已经抢光", 'result' => ''));
}
//秒杀队列控制
for($i=0;$i<$num0;$i++) {
$value = $this->redis->lPop($name);
}
//redis要加入set中,编号,类型,活动id,数量,时间,stoid
//$key=$no.'-2-'.$ky.'-'.$num0.'-'.$notime;
$g_name=get_redis_set_name($stoid);
$this->redis->sAdd($g_name,$key);
}
}
}
//return;
/*--物流方式--*/
$exptype = I("exptype/d");
$state = I("state/d");
if ($this->user_id == 0) {
$this->backredis($no,$notime);
exit(json_encode(array('status' => -100, 'msg' => "登录超时请重新登录!", 'result' => null))); // 返回结果状态
}
$address_id = I("address_id/d"); // 收货地址id
$setadd = I("setadd/d");
$is_skill = I("skill"); //是否是秒杀
/*--是否是编辑地址--*/
if ($setadd == 1 && $exptype == 2 && empty($address_id)) {
$consignee = I("consignee");
$mobile = I("mobile");
$province = I("province");
$city = I("city");
$district = I("district");
$twon = I("twon");
$address = I("address");
$data = ['consignee' => $consignee,
'mobile' => $mobile,
'province' => $province,
'city' => $city,
'district' => $district,
'twon' => $twon,
'address' => $address,
];
$logic = new UsersLogic();
$data = $logic->add_address($this->user_id, 0, $data);
$address_id = $data['result'];
}
$shipping_code = I("shipping_code/a"); // 物流编号
$invoice_title = I('invoice_title/a'); // 发票
$exparr= I('exparr/a');//获取物流配送数组
$couponTypeSelect = I("couponTypeSelect"); // 优惠券类型 1 下拉框选择优惠券 2 输入框输入优惠券代码
$coupon_id = I("coupon_id/a"); // 优惠券id
$couponCode = I("couponCode"); // 优惠券代码
$user_note = I('user_note/a'); //买家留言
$pay_points = I("pay_points", 0); // 使用积分
$user_money = I("user_money", 0); // 使用余额
$user_money = str_replace(',', '', $user_money);
$user_money = doubleval($user_money);
$exptype=0;
if($exparr) {
foreach ($exparr as $ko => $vo) {
if ($vo == 1) {
$exptype = 1;
break;
}
}
}
if($user_money<0) {
$this->backredis($no,$notime);
exit(json_encode(array('status' => -2, 'msg' => '你的余额不足', 'result' => null))); //返回结果状态
}
//if(!empty($user_money))
//$user_money=number_format(empty($user_money)?0:$user_money,2); //使用俩位
/*--购物车商品提取--*/
/*--
$cart_goods = M('Cart')->alias('a')
->join("pick_up b","a.pick_id=b.pickup_id",'left')
->where(['a.user_id'=>$this->user_id,'a.selected'=>1])
->where($where)->getField("a.*,b.pickup_name,b.pickup_id");--*/
/*---购物车和立即购买的区分---*/
$result = null;
if ($state == 0) {
$result = $this->cartLogic->cartList($this->user, $this->session_id, 1, 1); //获取购物车商品
} else {
$result = $this->cartLogic->gobuyList($this->user, $this->session_id); //获取购物车商品
}
$cart_goods = $result['cartList'];
mlog("购物车出来的数量:".json_encode($cart_goods),"cart3/".$stoid);
if (empty($cart_goods)) {
$this->backredis($no,$notime);
exit(json_encode(array('status' => -2, 'msg' => '你的购物车没有选中商品', 'result' => null))); //返回结果状态
}
/*------
$wlist="";$sumlist="";
//----计算商品组,用于优惠券----
foreach ($cart_goods as $k=>$v){
if($v['is_gift']!=1) {
$wlist .= $v['erpwareid'] .",";
$sumlist .= ($v['goods_price'] * $v['goods_num']) . ",";
}
}
$wlist = substr($wlist,0,strlen($wlist)-1);
$sumlist = substr($sumlist,0,strlen($sumlist)-1);--*/
$address = M('UserAddress')->where("address_id", $address_id)->find();
$allusrnum = $user_money;
$locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
$userd = $this->user;
$salerule = tpCache('basic.sales_rules', $stoid);
$erpid = tpCache('shop_info.ERPId', $stoid);
$userd['sales_rules'] = $salerule;
$userd['ERPId'] = $erpid;
// M("users")->alias('a')
// ->join('store_config b',' a.store_id=b.store_id','left')
// ->join('store c',' a.store_id=c.store_id','left')
// ->field('a.user_money,a.frozen_money,b.sales_rules,c.ERPId')
// ->where('a.user_id',$this->user_id)->find();
//订单余额判断
if (!empty($allusrnum)) {
$ye = $userd['user_money'] - $userd['frozen_money'] - $locking_money;
if ($ye . '' < $allusrnum) {
$this->backredis($no,$notime);
return array('status' => -4,
'msg' => "您的可用余额不足", 'result' => '');
}
}
// $srule=M('store_config')->where('store_id',$stoid)->find();
// $uerp=M('store')->where('store_id',$stoid)->find();
$count_arr = null;
/*----如果是线下库存,获取线下库存----*/
if ($userd['sales_rules'] == 2) {
if ($is_skill != 1) {
$count_arr = getcountarr($cart_goods, $stoid);
}
}
$err_txt = "";
$prom_goods = array();
//建立优惠促销数组
foreach ($cart_goods as $k => $value) {
if ($value['prom_type'] == 3 && $value['is_gift'] == 0 && $value['is_collocation'] == 0) {
//要重新计算等级美妆价
$prom_goods[$value['pick_id']][$value['prom_id']]['num'] += $value['goods_num'];
$prom_goods[$value['pick_id']][$value['prom_id']]['price'] += $value['goods_num'] * $value['goods_price'];
}
if ($value['is_gift'] == 1) {
$prom_goods[$value['pick_id']][$value['prom_id']]['key'] = $k;
}
}
if (!empty($prom_goods)) {
$prom_info = M('prom_goods')->where(['start_time' => ['lt', time()], 'end_time' => ['gt', time()], 'is_end' => 0])
->where('store_id',$stoid)
->getfield('id,name,is_bz');
foreach ($prom_goods as $kk => $vv) {
foreach ($vv as $key => $val) {
if (!empty($prom_info[$key])) {
$prom = discount($val['price'], $key, $val['num'], $this->user_id,$prom_info[$key]['is_bz']);
if (empty($prom['goods_id']) && !empty($val['key'])) {
//不是赠品的才删除,赠品要留着
if($cart_goods[$val['key']['is_gift']]!=1)
unset($cart_goods[$val['key']]);
}
$prom_goods[$kk][$key]['int'] = $prom['int'];
$prom_goods[$kk][$key]['coupon'] = $prom['coupon_id'];
$prom_goods[$kk][$key]['libao'] = $prom['libao'];
$prom_goods[$kk][$key]['is_past'] = $prom['is_past'];
$prom_goods[$kk][$key]['gift_id'] = $prom['gift_id'];
$prom_goods[$kk][$key]['price'] = $prom['price'];
$prom_goods[$kk][$key]['all_price'] = $val['price'];
$prom_goods[$kk][$key]['is_bz'] = $prom['is_bz'];
$prom_goods[$kk][$key]['coupon_num'] = $prom['coupon_num'];
$prom_goods[$kk][$key]['lb_num'] = $prom['lb_num'];
} else {
//return array('status' => -4, 'msg' => "优惠活动已经结束", 'result' => '');
unset($prom_goods[$kk][$key]);
}
}
}
}
$prom_goods_arr=$this->com_prom_goods($cart_goods);
/*--预出库库存--*/
$gidarr=get_arr_column($cart_goods,'goods_id');
$fgid0=implode(',',$gidarr);
$strq = 'select pickup_id,goods_id,sum(out_qty) as sum0 from wxd_erp_yqty where goods_id in(' . $fgid0 . ') and store_id='.$stoid.' GROUP BY pickup_id,goods_id';
$dd = Db::query($strq);
$ddd = [];
//---组装数组---
if ($dd){
foreach ($dd as $ku => $vu) {
$ypkid=$vu['pickup_id'];
$ypgid=$vu['goods_id'];
$ddd[$ypkid."".$ypgid]=$vu['sum0'];
}
}
mlog("预出数量0:".json_encode($ddd),"cart3/".$stoid);
mlog("购物车出来的数量001:".json_encode($cart_goods),"cart3/".$stoid);
/*--库存判断和活动判断,商品的库存和活动不能过期--*/
foreach ($cart_goods as $k => $value) {
//活动不一样就是发生了变化
if($value['prom_type1']!=$value['prom_type'] && $value['prom_id1']!=$value['prom_id'] && $value['is_collocation'] == 0 ) {
$this->backredis($no,$notime);
return array('status' => -3, 'msg' => "{$value['goods_name']}商品价格已经变化", 'result' => '');
}
$ginfo = $value;
/*--线下库存的序列key--*/
$bkey = $value['pick_id'] . $value['goods_id'];
//商品参与活动查看
if ($value['prom_type1'] > 0 && $value['prom_type1'] != 3 && $value['prom_type1'] != 5 && $value['is_collocation'] == 0 && $value['is_integral_normal']!=1 && $value['is_pd_normal']!=1 ) {
/*--修改获取活动的函数--*/
$prom = get_goods_promotion2($ginfo, null, $this->user_id,0,'',$this->user);
if ($prom['is_end'] == 1) {
$this->backredis($no,$notime);
return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品活动已经结束", 'result' => '');
}
if ($prom['is_end'] == 2) {
$this->backredis($no,$notime);
return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品已经售完", 'result' => '');
}
if ($prom['is_end'] == 3) {
$this->backredis($no,$notime);
return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量", 'result' => '');
}
if ($value['prom_type'] == 1 || $value['prom_type'] == 2 || $value['prom_type'] == 4) {
if ($prom['buy_limit']) {
if ($value['goods_num'] > $prom['buy_limit']) {
$this->backredis($no, $notime);
return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量", 'result' => '');
}
}
}
if ($value['member_goods_price'] != $prom['price']) {
$err_txt .= "{$ginfo['goods_name']}商品价格已经变化,是否继续购买!<br>";
}
if ($value['prom_type'] == 1 || $value['prom_type'] == 2 || $value['prom_type'] == 4 || $value['prom_type'] == 6) {
if ($value['goods_num'] > $ginfo['store_count']) {
$this->backredis($no,$notime);
return array('status' => -4, 'msg' => "库存不足", 'result' => '');
}
} else {
if ($userd['sales_rules'] == 1) {
if ($value['goods_num'] > $ginfo['store_count']) {
$this->backredis($no,$notime);
return array('status' => -4, 'msg' => "库存不足", 'result' => '');
}
} else if ($userd['sales_rules'] == 2) {
if (empty($count_arr)) {
$this->backredis($no,$notime);
return array('status' => -4, 'msg' => "库存获取失败", 'result' => '');
}
/*--预出库判断--*/
$ynum=$ddd[$bkey];
mlog("预出数量:".$ynum,"cart3/".$stoid);
if($ynum) {
if ($value['goods_num']+$ynum > $count_arr[$bkey]) {
$this->backredis($no,$notime);
return array('status' => -4, 'msg' => "库存不足", 'result' => '');
}
}else{
if ($value['goods_num'] > $count_arr[$bkey]) {
$this->backredis($no,$notime);
return array('status' => -4, 'msg' => "库存不足", 'result' => '');
}
}
}
}
}else{
//判断商品超出限购
if($ginfo['viplimited']>0) {
$limit = M('order')->alias('a')->join('order_goods b', 'a.order_id=b.order_id')
->where([ 'a.user_id' => $this->user_id, 'b.goods_id' => $ginfo['goods_id'],'a.order_status' => [['=', 4], ['<', 3], 'or']])
->sum('b.goods_num');
if ($value['goods_num'] + $limit > $ginfo['viplimited']) {
$this->backredis($no,$notime);
return array('status' => -3, 'msg' => '购买商品超出限购', 'result' => '');
}
}
if ($value['is_gift']== 0) {
if ($userd['sales_rules'] == 1) {
if ($value['goods_num'] > $ginfo['store_count']) {
$this->backredis($no,$notime);
return array('status' => -4, 'msg' => "库存不足", 'result' => '');
}
} else if ($userd['sales_rules'] == 2) {
if (empty($count_arr)) {
$this->backredis($no,$notime);
return array('status' => -4, 'msg' => "库存获取失败", 'result' => '');
}
/*--预出库判断--*/
$ynum=$ddd[$bkey];
$this_gd_count=$count_arr[$bkey];
if($ynum) {
$this_gd_count=$this_gd_count-$ynum;
}
mlog("预出数量55:".$this_gd_count,"cart3/".$stoid);
if ($value['goods_num'] > $this_gd_count) {
$this->backredis($no,$notime);
return array('status' => -4, 'msg' => "库存不足", 'result' => '');
}
}
$mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆开关
$rank_switch = tpCache('shopping.rank_switch',$stoid);//等级开关
$curprice=$ginfo['shop_price'];
//如果有美妆价和启用,大于0
if ($ginfo['mz_price'] > 0 && !empty($userd['is_mzvip']) && !empty($mz_switch)) {
$curprice = $ginfo['mz_price'];
}
//如果有等级价和启用,大于0
if ($rank_switch) {
if ($userd['card_field'] && strtotime($userd['card_expiredate']) > time() && $ginfo[$userd['card_field']] > 0) {
$curprice = $ginfo[$userd['card_field']];
}
}
/*--判断价格是否发生变化 并且不是搭配商品--*/
if ($value['member_goods_price'] != $curprice && $value['is_collocation'] == 0
//&& $value['prom_type1'] != 3
//&& $value['is_integral_normal']!=1 && $value['is_pd_normal']!=1)
){
$err_txt .= "{$ginfo['goods_name']} 商品价格已经变化<br>";
}
}
}
}
//$err_txt="跳出";
if ($err_txt != "") {
$this->backredis($no,$notime);
return array('status' => -1004, 'msg' => $err_txt, 'result' => '');
}
mlog("购物车出来的数量002:".json_encode($cart_goods),"cart3/".$stoid);
/*--购物车商品分组,生成不同订单--*/
$plist = null;
if ($state == 0) {
$sql = "select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and selected=1 and state=0 GROUP BY pick_id";
$plist = Db::query($sql);
foreach ($plist as $k => $v) {
$count = array();
$wlist="";$sumlist="";
$list=[];
foreach ($cart_goods as $kk => $vv) {
//组装分配券的商品ID 和 金钱
$t_arr= $this->com_package($vv,$v,$wlist,$sumlist,$prom_goods_arr);
if($t_arr['list']) $list[]=$t_arr['list'];
$wlist=$t_arr['wlist'];
$sumlist=$t_arr['sumlist'];
mlog("cart3计算优惠的内容0:".json_encode($t_arr),"cart3/".$stoid);
if (!empty($prom_goods[$v['pick_id']]) && $vv['prom_type'] == 3 && $count[$vv['prom_id']] == 0) {
$plist[$k]['order']['int'] += $prom_goods[$v['pick_id']][$vv['prom_id']]['int'];
$plist[$k]['order']['coupon'][] = $prom_goods[$v['pick_id']][$vv['prom_id']]['coupon'];
$plist[$k]['order']['libao'][] = $prom_goods[$v['pick_id']][$vv['prom_id']]['libao'];
//如果有券对应的数量
if($prom_goods[$v['pick_id']][$vv['prom_id']]['coupon_num']) {
$c_dd['num'] = $prom_goods[$v['pick_id']][$vv['prom_id']]['coupon_num'];
$c_dd['c_id'] = $prom_goods[$v['pick_id']][$vv['prom_id']]['coupon'];
$plist[$k]['order']['coupon_num'][] = $c_dd;
}
//如果有券对应的数量
if($prom_goods[$v['pick_id']][$vv['prom_id']]['coupon_num']) {
$l_dd['num']=$prom_goods[$v['pick_id']][$vv['prom_id']]['lb_num'];
$l_dd['l_id']=$prom_goods[$v['pick_id']][$vv['prom_id']]['libao'];
$plist[$k]['order']['lb_num'][] =$l_dd ;
}
$plist[$k]['order'][$vv['prom_id']]['gift_id'] = $prom_goods[$vv['pick_id']][$vv['prom_id']]['gift_id'];
$plist[$k]['discount'] = $prom_goods[$v['pick_id']];
$count[$vv['prom_id']] += 1;
}
}
$plist[$k]["goods"] = $list;
//组装商品ID和金额
$wlist = substr($wlist,0,strlen($wlist)-1);
$sumlist = substr($sumlist,0,strlen($sumlist)-1);
$plist[$k]["wlist"]=$wlist;
$plist[$k]["sumlist"]=$sumlist;
unset($list);
}
} else {
$sql1 = "select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and state=1 GROUP BY pick_id";
$plist = Db::query($sql1);
foreach ($plist as $k => $v) {
$count = array();
$wlist="";$sumlist="";$list=[];
foreach ($cart_goods as $kk => $vv) {
//组装分配券的商品ID 和 金钱
$t_arr= $this->com_package($vv,$v,$wlist,$sumlist,$prom_goods_arr);
if($t_arr['list']) $list[]=$t_arr['list'];
$wlist=$t_arr['wlist'];
$sumlist=$t_arr['sumlist'];
if (!empty($prom_goods[$v['pick_id']]) && $vv['prom_type'] == 3 && $count[$vv['prom_id']] == 0) {
$plist[$k]['order']['int'] += $prom_goods[$v['pick_id']][$vv['prom_id']]['int'];
$plist[$k]['order']['coupon'][] = $prom_goods[$v['pick_id']][$vv['prom_id']]['coupon'];
$plist[$k]['order']['libao'][] = $prom_goods[$v['pick_id']][$vv['prom_id']]['libao'];
//如果有券对应的数量
if($prom_goods[$v['pick_id']][$vv['prom_id']]['coupon_num']) {
$c_dd['num'] = $prom_goods[$v['pick_id']][$vv['prom_id']]['coupon_num'];
$c_dd['c_id'] = $prom_goods[$v['pick_id']][$vv['prom_id']]['coupon'];
$plist[$k]['order']['coupon_num'][] = $c_dd;
}
//如果有券对应的数量
if($prom_goods[$v['pick_id']][$vv['prom_id']]['lb_num']) {
$l_dd['num']=$prom_goods[$v['pick_id']][$vv['prom_id']]['lb_num'];
$l_dd['l_id']=$prom_goods[$v['pick_id']][$vv['prom_id']]['libao'];
$plist[$k]['order']['lb_num'][] =$l_dd ;
}
$plist[$k]['order'][$vv['prom_id']]['gift_id'] = $prom_goods[$vv['pick_id']][$vv['prom_id']]['gift_id'];
$plist[$k]['discount'] = $prom_goods[$v['pick_id']];
$count[$vv['prom_id']] += 1;
}
if($plist[$k]['order']) mlog(json_encode($plist[$k]['order']).$k,"cart3_yhui/".$stoid);
mlog("cart3计算优惠的内容:".json_encode($t_arr),"cart3/".$stoid);
}
$plist[$k]["goods"] = $list;
//组装商品ID和金额
$wlist = substr($wlist,0,strlen($wlist)-1);
$sumlist = substr($sumlist,0,strlen($sumlist)-1);
$plist[$k]["wlist"]=$wlist;
$plist[$k]["sumlist"]=$sumlist;
unset($list);
}
}
/*--开始生成多单--*/
//$uerp=M('store')->where('store_id',$stoid)->find();
$pno = "";
if (count($plist) > 1) $pno = $userd['ERPId'] . date('ymdHis') . get_total_millisecond() . rand(1000, 9999);
$postFee = 0;$couponFee = 0;$balance = 0;$pointsFee = 0;$payables = 0;
$payables1 = 0;$goodsFee = 0;$order_prom_id = 0;$order_prom_amount = 0;
$youhui_arr=null;
//---拼单只有一个商品---
if($ispt==3) {
$exptype = 1;$exparr[$plist[0]['pick_id']]=1;
}
mlog("plist".json_encode($plist),"cart3/".$stoid);
//启动事务
Db::startTrans();
try {
foreach ($plist as $k => $v) {
/*--计算订单相关--*/
$result = calculate_price2($this->user, $v["goods"], $shipping_code[$v['pick_id']], 0, $address['province'], $address['city'], $address['district'], $pay_points, $user_money, $coupon_id[$v['pick_id']], $couponCode, $stoid, $exparr[$v['pick_id']], $v['discount'],$v['wlist'],$v['sumlist']);
if ($result['status'] < 0) {
$this->backredis($no,$notime);
exit(json_encode($result));
}
/*---余额使用---*/
$user_money = round($user_money - $result['result']['user_money'], 2);
/*----
$order_prom = get_order_promotion($result['result']['order_amount'],$stoid);
$result['result']['order_amount'] = $order_prom['order_amount'];
$result['result']['order_prom_id'] = $order_prom['order_prom_id'];
$result['result']['order_prom_amount'] = $order_prom['order_prom_amount'];
---*/
$postFee += $result['result']['shipping_price']; // 物流费
$couponFee += $result['result']['coupon_price'];// 优惠券
$balance += $result['result']['user_money']; // 使用用户余额
$pointsFee += $result['result']['integral_money']; // 积分支付
$payables += $result['result']['order_amount'];// 应付金额
$payables1 += $result['result']['order_amount1'];// 应付金额,不包含余额的那部分
$goodsFee += $result['result']['goods_price'];// 商品价格
$order_prom_id .= $result['result']['order_prom_id'] . ",";// 订单优惠活动id
$order_prom_amount += $result['result']['order_prom_amount'] + $result['result']['discount'];// 订单优惠活动优惠了多少钱
$youhui_arr = $result['result']['youhui'];
mlog("使用优惠券:".$coupon_id[$v['pick_id']].json_encode($youhui_arr),
"cart3/".$stoid);
// 提交订单
if ($_REQUEST['act'] == 'submit_order') {
$address_id = $_REQUEST['address_id'];
mlog("日志" . $address_id . "是否编辑地址" . $setadd, "cart");
if (!$address_id && $exptype == 0) {
$this->backredis($no,$notime);
exit(json_encode(array('status' => -3, 'msg' => '请先填写收货人信息', 'result' => null)));
} // 返回结果状态
if (!$shipping_code && $exptype == 0){
$this->backredis($no,$notime);
exit(json_encode(array('status' => -4, 'msg' => '请选择物流信息', 'result' => null)));
} // 返回结果状态
if (empty($coupon_id) && !empty($couponCode)) {
$coupon_id = M('CouponList')->where("code", $couponCode)->getField('id');
}
//$iii=$result['result']['user_money'];
$car_price0 = array(
'postFee' => $result['result']['shipping_price'], // 物流费
'couponFee' => $result['result']['coupon_price'], // 优惠券
'balance' => $result['result']['user_money'], // 使用用户余额
'pointsFee' => $result['result']['integral_money'], // 积分支付
'payables' => $result['result']['order_amount'], // 应付金额
'payables1' => $result['result']['order_amount1'], // 应付金额
'goodsFee' => $result['result']['goods_price'],// 商品价格
'order_prom_id' => $result['result']['order_prom_id'], // 订单优惠活动id
'order_prom_amount' => $result['result']['order_prom_amount'], // 订单优惠活动优惠了多少钱
'discount_amount' => $result['result']['discount'],//优惠、搭配促销优惠的金额
'good_prom'=>$result['result']['good_prom'],//优惠活动
);
mlog("addOrder".json_encode($v["goods"]),"cart3/".$stoid);
/*--调用生成订单的函数--*/
$result = $this->cartLogic->addOrder($this->user_id, $address_id,
$shipping_code[$v['pick_id']], $invoice_title[$v['pick_id']], $car_price0,
$v["goods"], $coupon_id[$v['pick_id']], $user_note[$v['pick_id']], $stoid, $exparr[$v['pick_id']], $pno, $v['pick_id'], $v['order'], $this->user,$no,$ispt,$pdid,$team_qh,$youhui_arr); // 添加订单
if($result["status"] != 1) {
//如果失败就补回队列
if(!empty($sd)){
$skillarray=json_decode($sd,true);
foreach ($skillarray as $lk=>$lv){
//$name='ms'.$lv['fid'].'-'.$stoid;
$name=get_redis_name($lv['fid'],1,$stoid);
$num0=$lv['num'];
//秒杀队列控制
for($i=0;$i<$num0;$i++) {
$this->redis->lPush($name,time().'_'.$i);
}
$key=$no.'-1-'.$lv['fid'].'-'.$num0.'-'.$notime;
$p_name=get_redis_set_name($stoid);
$this->redis->sRem($p_name,$key);
}
}
//如果是拼单
if($ispt){
//$name='pind'.$pdid.'-'.$stoid;
$name=get_redis_name($pdid,6,$stoid);
//拼单队列控制
for($i=0;$i<$pdgoodsnum;$i++) {
$this->redis->lPush($name,time().'_'.$i);
}
if($team_qh && $ispt=='2') {
//$name2 = 'pind' . $pdid . '-' . $team_qh . $stoid;
$name2 =get_redis_name($pdid,6,$stoid) . ':' . $team_qh;
$this->redis->lPush($name2,time().'_0');
}
//$key=$no.'-6-'.$pdid.'-'.$pdgoodsnum.'-'.$notime.'-'.$team_qh;
$p_name=get_redis_set_name($stoid);
$this->redis->sRem($p_name,$key);
}
if($g_promid){
$arr=null;
foreach ($g_promid as $key=>$val){
$promid=explode("-",$key)[1];
$arr[$promid]+=$val;
}
foreach ($arr as $ky=>$ve){
//判断秒杀数量是否超限
//$name='grb'.$ky.'-'.$stoid;
$name=get_redis_name($ky,2,$stoid);
$num0=$ve;
//秒杀队列控制
for($i=0;$i<$num0;$i++) {
$this->redis->lPush($name,time() . '_' . $i);
}
//redis要加入set中,编号,类型,活动id,数量,时间,stoid
$key=$no.'-2-'.$ky.'-'.$num0.'-'.$notime;
$p_name=get_redis_set_name($stoid);
$this->redis->sRem($p_name,$key);
}
}
//如果订单失败要还原数量
exit(json_encode($result));
}
if (empty($pno) && count($plist) == 1) {
$pno = $result["result"];
}
}
}
//提交订单
if ($_REQUEST['act'] == 'submit_order') {
upload_ylp_log('提交订单');
if ($state == 0) {
// 删除购物车中已提交订单商品
M('Cart')->where(['user_id' => $this->user_id, 'selected' => 1])->delete();
//删除购物车的cookie
Cookie::delete("cn");
Db::commit();
//正确提交订单记录redis数量
if(!empty($sd)) {
$skillarray = json_decode($sd, true);
foreach ($skillarray as $lk => $lv) {
//判断秒杀数量是否超限
$num0 = $lv['num'];
//$name='ms'.$lv['fid'].'-'.$stoid;
$name=get_redis_name($lv['fid'],1,$stoid);
$jsda['len']=$this->redis->lLen($name);
$jsda['num']=-$num0;
$jsda['order_sn']=$pno;
$jsda['type']=0; //0是买单 1是5分钟自动补回 2是手动补回
mlog(json_encode($jsda),'flash_log/' . $stoid . '/' . $lv['fid']."_1");
$key=$no.'-1-'.$lv['fid'].'-'.$num0.'-'.$notime;
$p_name=get_redis_set_name($stoid);
$this->redis->sRem($p_name,$key);
}
}
if($g_promid){
$arr=null;
foreach ($g_promid as $key=>$val){
$promid=explode("-",$key)[1];
$arr[$promid]+=$val;
}
foreach ($arr as $ky=>$ve){
//redis要加入set中,编号,类型,活动id,数量,时间,stoid
$key=$no.'-2-'.$ky.'-'.$num0.'-'.$notime;
$p_name=get_redis_set_name($stoid);
$this->redis->sRem($p_name,$key);
}
}
exit(json_encode(array('status' => 1, 'msg' => '提交订单成功', 'result' => $pno, 'payables' => $payables)));
}else {
// 删除cart表中立即购买的商品
M('Cart')->where(['user_id' => $this->user_id, 'state' => 1])->delete();
Db::commit();
//正确提交订单记录redis数量
if(!empty($sd)) {
$skillarray = json_decode($sd, true);
foreach ($skillarray as $lk => $lv) {
//判断秒杀数量是否超限
$num0 = $lv['num'];
//$name='ms'.$lv['fid'].'-'.$stoid;
$name=get_redis_name($lv['fid'],1,$stoid);
$jsda['len']=$this->redis->lLen($name);
$jsda['num']=-$num0;
$jsda['order_sn']=$pno;
$jsda['type']=0; //0是买单 1是5分钟自动补回 2是手动补回
mlog(json_encode($jsda),'flash_log/' . $stoid . '/' . $lv['fid']."_1");
$key=$no.'-1-'.$lv['fid'].'-'.$num0.'-'.$notime;
$p_name=get_redis_set_name($stoid);
$this->redis->sRem($p_name,$key);
}
}
if($ispt){
$key=$no.'-6-'.$pdid.'-'.$pdgoodsnum.'-'.$notime.'-'.$team_qh;
$p_name=get_redis_set_name($stoid);
$this->redis->sRem($p_name,$key);
//$name='pind'.$pdid.'-'.$stoid;
$name=get_redis_name($pdid,6,$stoid);
$jsdaa['len']=$this->redis->lLen($name);
$jsdaa['num']=-$pdgoodsnum;
$jsdaa['order_sn']=$pno;
$jsdaa['type']=0; //0是买单 1是5分钟自动补回 2是手动补回
mlog(json_encode($jsdaa),'pt_log/' . $stoid . '/' . $pdid."_1");
}
if($g_promid){
$arr=null;
foreach ($g_promid as $key=>$val){
$promid=explode("-",$key)[1];
$arr[$promid]+=$val;
}
foreach ($arr as $ky=>$ve){
//redis要加入set中,编号,类型,活动id,数量,时间,stoid
$key=$no.'-2-'.$ky.'-'.$num0.'-'.$notime;
$p_name=get_redis_set_name($stoid);
$this->redis->sRem($p_name,$key);
}
}
exit(json_encode(array('status' => 1, 'msg' => '提交订单成功', 'result' => $pno, 'payables' => $payables)));
}
}
}catch (\Exception $e) {
// 回滚事务
Db::rollback();
if ($_REQUEST['act'] == 'submit_order') {
//如果失败就补回队列
if(!empty($sd)){
$skillarray=json_decode($sd,true);
foreach ($skillarray as $lk=>$lv){
//$name='ms'.$lv['fid'].'-'.$stoid;
$name=get_redis_name($lv['fid'],1,$stoid);
$num0=$lv['num'];
//秒杀队列控制
for($i=0;$i<$num0;$i++) {
$this->redis->lPush($name,time().'_'.$i);
}
$key=$no.'-1-'.$lv['fid'].'-'.$num0.'-'.$notime;
$p_name=get_redis_set_name($stoid);
$this->redis->sRem($p_name,$key);
}
}
//如果是拼单
if($ispt){
//$name='pind'.$pdid.'-'.$stoid;
$name=get_redis_name($pdid,6,$stoid);
//拼单队列控制
for($i=0;$i<$pdgoodsnum;$i++) {
$this->redis->lPush($name,time().'_'.$i);
}
if($team_qh && $ispt=='2') {
//$name2 = 'pind' . $pdid . '-' . $team_qh . $stoid;
$name2 = get_redis_name($pdid,6, $stoid). ':' . $team_qh;
$this->redis->lPush($name2,time().'_0');
}
$key=$no.'-6-'.$pdid.'-'.$pdgoodsnum.'-'.$notime.'-'.$team_qh;
$p_name=get_redis_set_name($stoid);
$this->redis->sRem($p_name,$key);
}
if($g_promid){
$arr=null;
foreach ($g_promid as $key=>$val){
$promid=explode("-",$key)[1];
$arr[$promid]+=$val;
}
foreach ($arr as $ky=>$ve){
//判断秒杀数量是否超限
//$name='grb'.$ky.'-'.$stoid;
$name=get_redis_name($ky,2,$stoid);
$num0=$ve;
//秒杀队列控制
for($i=0;$i<$num0;$i++) {
$this->redis->lPush($name,time() . '_' . $i);
}
//redis要加入set中,编号,类型,活动id,数量,时间,stoid
$key=$no.'-2-'.$ky.'-'.$num0.'-'.$notime;
$p_name=get_redis_set_name($stoid);
$this->redis->sRem($p_name,$key);
}
}
}
exit(json_encode(array('status' => -1, 'msg' => '提交订单失败')));
}
$car_price = array(
'postFee' => round($postFee, 2), // 物流费
'couponFee' => round($couponFee, 2), // 优惠券
'balance' => round($allusrnum - $user_money, 2), // 使用用户余额
'pointsFee' => round($pointsFee, 2), // 积分支付
'payables' => round($payables, 2), // 应付金额
'payables1' => round($payables1, 2), // 应付金额,不包含使用余额的那一部分
'goodsFee' => round($goodsFee, 2),// 商品价格
'order_prom_id' => $order_prom_id, // 订单优惠活动id
'order_prom_amount' => round($order_prom_amount, 2), // 订单优惠活动优惠了多少钱
);
$return_arr = array('status' => 1, 'msg' => '计算成功', 'result' => $car_price); // 返回结果状态
exit(json_encode($return_arr));
}
/**
* ajax 获取订单商品价格
*/
public function cart3_nosub()
{
/*--物流方式--*/
$exptype = I("exptype/d");
$stoid = I("stoid");
$state = I("state/d");
if ($this->user_id == 0)
exit(json_encode(array('status' => -100, 'msg' => "登录超时请重新登录!", 'result' => null))); // 返回结果状态
$address_id = I("address_id/d"); //收货地址id
$setadd = I("setadd/d");
$is_skill = I("skill"); //是否是秒杀
$exparr= I('exparr/a');//获取物流配送数组
/*--是否是编辑地址--*/
if ($setadd == 1 && $exptype == 0 && empty($address_id)) {
$consignee = I("consignee");
$mobile = I("mobile");
$province = I("province");
$city = I("city");
$district = I("district");
$twon = I("twon");
$address = I("address");
$data = ['consignee' => $consignee,
'mobile' => $mobile,
'province' => $province,
'city' => $city,
'district' => $district,
'twon' => $twon,
'address' => $address,
];
$logic = new UsersLogic();
$data = $logic->add_address($this->user_id, 0, $data);
$address_id = $data['result'];
}
$shipping_code = I("shipping_code/a"); // 物流编号
$invoice_title = I('invoice_title/a'); // 发票
$couponTypeSelect = I("couponTypeSelect"); // 优惠券类型 1 下拉框选择优惠券 2 输入框输入优惠券代码
$coupon_id = I("coupon_id/a"); // 优惠券id
$couponCode = I("couponCode"); // 优惠券代码
$user_note = I('user_note/a'); //买家留言
$pay_points = I("pay_points", 0); // 使用积分
$user_money = I("user_money", 0); // 使用余额
$user_money = str_replace(',', '', $user_money);
$user_money = doubleval($user_money);
//if(!empty($user_money))
//$user_money=number_format($user_money,2); //使用俩位
$result = null;
if ($state == 0) {
$result = $this->cartLogic->cartList_cart2($this->user, $this->session_id, 1, 1); //获取购物车商品
} else {
$result = $this->cartLogic->gobuyList_cart2($this->user, $this->session_id); //获取购物车商品
}
$cart_goods = $result['cartList'];
if (empty($cart_goods))
exit(json_encode(array('status' => -2, 'msg' => '你的购物车没有选中商品', 'result' => null))); //返回结果状态
$prom_goods_arr=$this->com_prom_goods($cart_goods);
/*----
$wlist=""; $sumlist="";
//----计算商品组,用于优惠券----
foreach ($cart_goods as $k=>$v){
if($v['is_gift']!=1) {
$wlist .= $v['erpwareid'] .",";
$sumlist .= ($v['goods_price'] * $v['goods_num']) . ",";
}
}
$wlist = substr($wlist,0,strlen($wlist)-1);
$sumlist = substr($sumlist,0,strlen($sumlist)-1);--*/
$address = M('UserAddress')->where("address_id", $address_id)->find();
$allusrnum = $user_money;
$locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
$userd = $this->user;
$salerule = tpCache('basic.sales_rules', $stoid);
$erpid = tpCache('shop_info.ERPId', $stoid);
$userd['sales_rules'] = $salerule;
$userd['ERPId'] = $erpid;
//订单余额判断
if (!empty($allusrnum)) {
$ye = $userd['user_money'] - $userd['frozen_money'] - $locking_money;
if ($ye . '' < $allusrnum) {
return array('status' => -4,
'msg' => "您的可用余额不足", 'result' => '');
}
}
/*----如果是线下库存,获取线下库存----*/
$count_arr = null;
if ($userd['sales_rules'] == 2) {
if ($is_skill != 1)
$count_arr = getcountarr($cart_goods, $stoid);
}
/*--购物车商品分组,生成不同订单--*/
$plist = null;
$quan = null;
// 找出是不是冻结的券
$fzquan = M('frozen_quan')->where('user_id', $this->user_id)->field('CashRepNo')->select();
if ($state == 0) {
$sql = "select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and selected=1 and state=0 GROUP BY pick_id";
$plist = Db::query($sql);
foreach ($plist as $k => $v) {
$wlist="";$sumlist="";$list=[];
foreach ($cart_goods as $kk => $vv) {
$t_arr= $this->com_package($vv,$v,$wlist,$sumlist,$prom_goods_arr);
if($t_arr['list']) $list[]=$t_arr['list'];
$wlist=$t_arr['wlist'];
$sumlist=$t_arr['sumlist'];
}
$plist[$k]["goods"] = $list;
//组装商品ID和金额
$wlist = substr($wlist,0,strlen($wlist)-1);
$sumlist = substr($sumlist,0,strlen($sumlist)-1);
$plist[$k]["wlist"]=$wlist;
$plist[$k]["sumlist"]=$sumlist;
//如果有地址,选择物流时,就要查询包邮券
if ($address_id && $exparr[$v['pick_id']]==0) {
//计算总价
$r = $this->cartLogic->my_calculate_cart2($list, $this->user_id);
//获取会员地址
$address = M('UserAddress')->where("address_id", $address_id)->find();
$now=time();
//拿出未使用未过期的优惠券
$wh['a.isuse']=0;
$wh['a.use_start_time']=['<',$now];
$wh['a.store_id']=getMobileStoId();
$wh['a.condition']=['<=',$r];
$wh['a.user_id']=$this->user['user_id'];
$wh2="a.use_end_time>".$now." or a.use_end_time=0 or a.use_end_time='' ";
$bylist=M("user_feemail")->alias('a')
->where($wh)
->field("a.no,a.condition,a.use_start_time,a.use_end_time,a.exparea as free_id")
->select();
$t_key=$v['pick_id'];
if($bylist){
foreach ($bylist as $kt=>$vt){
$isby=$this->cartLogic->isby($address,$vt['free_id']);
if($isby){
if($vt['use_start_time'])
$vt['start_v']=date('Y-m-d',$vt['use_start_time']);
else
$vt['start_v']="";
if($vt['use_end_time'])
$vt['end_v']=date('Y-m-d',$vt['use_end_time']);
else
$vt['end_v']='不限';
//是否冻结
$isdj=0;
//冻结的券不能使用
foreach ($fzquan as $ku => $vu) {
if ($vt['data']['no'] == $vu['CashRepNo']) {
$isdj=1;
break;
}
}
if($isdj==0) $quan[$t_key][]=$vt;
}
}
}
}
unset($list);
}
} else {
$sql1 = "select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and state=1 GROUP BY pick_id";
$plist = Db::query($sql1);
foreach ($plist as $k => $v) {
$wlist="";$sumlist="";$list=[];
foreach ($cart_goods as $kk => $vv) {
$t_arr= $this->com_package($vv,$v,$wlist,$sumlist,$prom_goods_arr);
mlog(json_encode($t_arr),"quan_ji_suan/".getMobileStoId());
if($t_arr['list']) $list[]=$t_arr['list'];
$wlist=$t_arr['wlist'];
$sumlist=$t_arr['sumlist'];
}
$plist[$k]["goods"] = $list;
//组装商品ID和金额
$wlist = substr($wlist,0,strlen($wlist)-1);
$sumlist = substr($sumlist,0,strlen($sumlist)-1);
$plist[$k]["wlist"]=$wlist;
$plist[$k]["sumlist"]=$sumlist;
//如果有地址,选择物流时,就要查询包邮券
if ($address_id && $exparr[$v['pick_id']]==0) {
//计算总价
$r = $this->cartLogic->my_calculate_cart2($list, $this->user_id);
//获取会员地址
$address = M('UserAddress')->where("address_id", $address_id)->find();
$now=time();
//拿出未使用未过期的优惠券
$wh['a.isuse']=0;
$wh['a.use_start_time']=['<',$now];
$wh['a.store_id']=getMobileStoId();
$wh['a.condition']=['<=',$r];
$wh['a.user_id']=$this->user['user_id'];
$wh2="a.use_end_time>".$now." or a.use_end_time=0 or a.use_end_time='' ";
$bylist=M("user_feemail")->alias('a')
->where($wh)
->where($wh2)
->field("a.no,a.condition,a.use_start_time,a.use_end_time,a.exparea as free_id")
->select();
$t_key=$v['pick_id'];
if($bylist){
foreach ($bylist as $kt=>$vt){
$isby=$this->cartLogic->isby($address,$vt['free_id']);
if($isby){
$vt['start_v']=date('Y-m-d',$vt['use_start_time']);
$vt['end_v']=date('Y-m-d',$vt['use_end_time']);
if($vt['use_start_time'])
$vt['start_v']=date('Y-m-d',$vt['use_start_time']);
else
$vt['start_v']="";
if($vt['use_end_time'])
$vt['end_v']=date('Y-m-d',$vt['use_end_time']);
else
$vt['end_v']='不限';
//是否冻结
$isdj=0;
//冻结的券不能使用
foreach ($fzquan as $ku => $vu) {
if ($vt['data']['no'] == $vu['CashRepNo']) {
$isdj=1;
break;
}
}
if($isdj==0) $quan[$t_key][]=$vt;
}
}
}
}
unset($list);
}
}
/*--开始生成多单--*/
//$uerp=M('store')->where('store_id',$stoid)->find();
$pno = "";
if (count($plist) > 1) $pno = $userd['ERPId'] . date('ymdHis') . get_total_millisecond() . rand(1000, 9999);
$postFee = 0;$couponFee = 0;$balance = 0;$pointsFee = 0;$payables = 0;$payables1 = 0;$goodsFee = 0;$order_prom_id = 0;$order_prom_amount = 0;$goods_prom_amount = 0;
foreach ($plist as $k => $v) {
/*--计算订单相关--*/
$result = calculate_price2($this->user, $v["goods"], $shipping_code[$v['pick_id']], 0, $address['province'], $address['city'], $address['district'], $pay_points, $user_money, $coupon_id[$v['pick_id']],
$couponCode, $stoid, $exparr[$v['pick_id']],$v['discount'],$v['wlist'],$v['sumlist']);
if ($result['status'] < 0)
exit(json_encode($result));
/*---余额使用---*/
$user_money = round($user_money - $result['result']['user_money'], 2);
$postFee += $result['result']['shipping_price']; // 物流费
$couponFee += $result['result']['coupon_price'];// 优惠券
$balance += $result['result']['user_money']; // 使用用户余额
$pointsFee += $result['result']['integral_money']; // 积分支付
$payables += $result['result']['order_amount'];// 应付金额
$payables1 += $result['result']['order_amount1'];// 应付金额,不包含余额的那部分
$goodsFee += $result['result']['goods_price'];// 商品价格
$order_prom_id .= $result['result']['order_prom_id'] . ",";// 订单优惠活动id
$order_prom_amount += $result['result']['order_prom_amount'];//订单优惠
$goods_prom_amount+= $result['result']['discount'];//优惠促销活动
}
$car_price = array(
'postFee' => round($postFee, 2), // 物流费
'couponFee' => round($couponFee, 2), // 优惠券
'balance' => round($allusrnum - $user_money, 2), // 使用用户余额
'pointsFee' => round($pointsFee, 2), // 积分支付
'payables' => round($payables, 2), // 应付金额
'payables1' => round($payables1, 2), // 应付金额,不包含使用余额的那一部分
'goodsFee' => round($goodsFee, 2),// 商品价格
'order_prom_id' => $order_prom_id, // 订单优惠活动id
'order_prom_amount' => round($order_prom_amount, 2), // 订单优惠优惠了多少钱
'goods_prom_amount' => round($goods_prom_amount, 2), // 优惠活动优惠了多少钱
);
$return_arr = array('status' => 1, 'msg' => '计算成功', 'result' => $car_price,'quan'=>$quan); // 返回结果状态
exit(json_encode($return_arr));
}
/*
* 订单支付页面
*/
public function cart4()
{
$orderno = I('order_id');
$order_amount = M('Order')->where("parent_sn", $orderno)->sum('order_amount');
$order = M('Order')->where("parent_sn", $orderno)->select();
// 如果已经支付过的订单直接到订单详情页面. 不再进入支付页面
if ($order[0]['pay_status'] == 1) {
$order_detail_url = U("Mobile/User/order_detail", array('stoid' => getMobileStoId(), 'id' => $order["order_id"]));
header("Location: $order_detail_url");
exit;
}
$paymentList = M('Plugin')->where("`type`='payment' and status = 1 and scene in(0,1)")->select();
//微信浏览器
if (strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) {
//$paymentList = M('Plugin')->where("`type`='payment' and status = 1 and code in('weixin','cod')")->select();
$paymentList = M('Plugin')->where("`type`='payment' and status = 1 and code in('weixin')")->select();
}
$paymentList = convert_arr_key($paymentList, 'code');
foreach ($paymentList as $key => $val) {
$val['config_value'] = unserialize($val['config_value']);
if ($val['config_value']['is_bank'] == 2) {
$bankCodeList[$val['code']] = unserialize($val['bank_code']);
}
//判断当前浏览器显示支付方式
if (($key == 'weixin' && !is_weixin()) || ($key == 'alipayMobile' && is_weixin())) {
unset($paymentList[$key]);
}
}
$bank_img = include APP_PATH . 'home/bank.php'; // 银行对应图片
$payment = M('Plugin')->where("`type`='payment' and status = 1")->select();
$this->assign('paymentList', $paymentList);
$this->assign('bank_img', $bank_img);
$this->assign('order_amount', $order_amount);
$this->assign('bankCodeList', $bankCodeList);
$this->assign('pay_date', date('Y-m-d', strtotime("+1 day")));
upload_ylp_log('订单支付');
return $this->fetch('', getMobileStoId());
}
public function cart5()
{
if ($this->user_id == 0)
$this->error('请先登录', U('Mobile/User/login', array('stoid' => getMobileStoId())));
$userd=$this->user;
//获取积分
$integ=get_userpoints($userd,getMobileStoId(),$this->pm_erpid);
//20180717 season(增加短信随机码校验)
$storeconfig = M('store_config')->where('store_id', getMobileStoId())->field('reg_type,reg_info,reg_default,sms_send_type,switch_list')->find();
$sms_send_type = json_decode($storeconfig['sms_send_type'], true);
$this->assign('s_type', $sms_send_type['type'] ? $sms_send_type['type'] : 0);
$this->assign('s_time_out', $sms_send_type['time_out'] ? $sms_send_type['time_out'] : 60);
$this->assign('is_verifycode', $sms_send_type['is_verifycode'] ? $sms_send_type['is_verifycode'] : 0);
$user_openid = $this->user['openid'];
//$user_openid="ou608v4s8TmwUsGLtJKDvdPKat5w"; //测试用
$this->assign("user_openid", $user_openid);
$user_openidkey = md5($user_openid . "&" . getErpKey());
$this->assign("user_openid", $user_openid);
$this->assign("user_openidkey", $user_openidkey);
//
$locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
$this->assign('u_money', number_format($userd['user_money'] - $userd['frozen_money'] - $locking_money, 2));
$this->assign('u_integral', $integ);
/*---获取地区---*/
$region_list = get_region_list();
$addlist = M('user_address')->where(['user_id' => $this->user_id])->select();
foreach ($addlist as $kk => $vv) {
$vv['provicename'] = $region_list[$vv['province']]['name'];
$vv['cityname'] = $region_list[$vv['city']]['name'];
$vv['districtname'] = $region_list[$vv['district']]['name'];
$vv['twonname'] = $region_list[$vv['twon']]['name'];
//$address = M('user_address')->where(['user_id'=>$this->user_id,'is_default'=>1])->find();
$addrstr = $vv['provicename'] . "-" . $vv['cityname'];
if (!empty($vv['district']))
$addrstr .= "-" . $vv['districtname'];
if (!empty($vv['twon']))
$addrstr = $addrstr . "-" . $vv['twonname'];
$vv['addrstr'] = $addrstr;
$addlist[$kk] = $vv;
}
$this->assign("addlist", $addlist);
$address_id = I('address_id/d');
if ($address_id) {
foreach ($addlist as $kk => $vv) {
if ($vv['address_id'] == $address_id) {
$address = $vv;
}
}
} else {
foreach ($addlist as $kk => $vv) {
if ($vv['is_default'] == 1) {
$address = $vv;
}
}
}
$p = M('region')->where(array('parent_id' => 0, 'level' => 1))->select();
$this->assign('province', $p);
if (empty($address)) {
//header("Location: ".U('Mobile/User/add_address',array('stoid'=>getMobileStoId(),'source'=>'cart2')));
$this->assign('setadd', 1);
} else {
$this->assign('address', $address);
$this->assign('setadd', 0);
}
/*--是否是购物车--*/
$tocart = I("tocart/d", 0);
$result = null;
$count = M('Cart')->where(['user_id' => $this->user_id, 'state' => 2])->count();
if ($count == 0)
$this->redirect('Index/index', array('stoid' => getMobileStoId()));
$result = $this->cartLogic->gointeList($this->user, $this->session_id); //获取购物车商品
$cartinfo = M('cart')->where(array('state' => 2, 'user_id' => $this->user_id))->select(); //购物车积分购
$proinfo = M('goods')->where(array('goods_id' => $cartinfo[0]['goods_id']))->select();
$inteinfo = M('integral_buy')->where(array('goods_id' => $proinfo[0]['goods_id'], 'is_end' => 0))->select();
mlog(json_encode($result), "cart");
$shippingList = M('store_shipping')->alias('a')->join("shipping b", "a.shipping_id=b.shipping_id")
->field('b.shipping_id,b.shipping_code,b.shipping_name,b.shipping_desc,b.shipping_logo')
->where("a.status=1 and a.store_id=" . getMobileStoId())
->select();//物流公司
/*--购物车商品分组--*/
$cart_goods = $result['cartList'];
$expty = 0;
foreach ($cart_goods as $kp => $vp) {
$exp2=0;
if($vp['distr_type']!=$vp['bdistr_type']){
$exp2=$vp['distr_type']==0?$vp['bdistr_type']:$vp['distr_type'];
}else{
$exp2=$vp['distr_type'];
}
$cart_goods[$kp]['expty']=$exp2;
if ($vp['is_gift'] == 0) {
//判断最后的物流方式
if ($expty != 0) {
if ($expty != $exp2) {
if($exp2==2 || $expty==2 ){
$expty=2;
}else{
$expty=0;
}
}
} else {
$expty =$exp2;
}
}
}
$this->assign("expty", $expty);
/*----
foreach ($cart_goods as $kp => $vp) {
if ($vp['distr_type'] != 0) {
if ($expty != 0) {
if ($expty != $vp['distr_type']) {
$this->error('您不能同时选择自提和物流商品', 'cart/cart', array('stoid' => getMobileStoId()));
}
} else {
$expty = $vp['distr_type'];
}
}
}
$this->assign("expty", $expty);---*/
$sql = null;
//mlog('$tocart:'.$sql,'cart');
$plist_cart = Db::query("select pickup_id,pickup_name from __PREFIX__pick_up where pickup_id in(select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and state=2 GROUP BY pick_id)");
foreach ($plist_cart as $k => $v) {
$expty00 = 0;
foreach ($cart_goods as $kk => $vv) {
if ($vv['pick_id'] == $v['pickup_id']) {
$list[] = $vv;
$expty11=$vv['expty'];
if($expty00==0){
$expty00=$expty11;
}
}
}
$plist_cart[$k]["goods"] = $list;
$plist_cart[$k]["expty"]=$expty00;
// 获取订单商品总价,$tocart=0为购物车 1为立即购买
//$r = $this->cartLogic->my_calculate($list,$this->user_id,$tocart);
// 找出这个用户的优惠券没过期的 并且订单金额达到condition 优惠券指定标准的
// $fzquan=M('frozen_quan')->where('user_id',$this->user_id)->field('CashRepNo')->select();
// $snow=date("Y-m-d H:i:s",time());
// $tk = M("store")->where("store_id", getMobileStoId())->field("api_token")->find();
// $user = M("users")->where("user_id",$this->user_id)->field("erpvipid")->find();
// $where = "VIPId='" . $user['erpvipid'] . "'";
// $where .= " and IsUse=0 and ValidDate>='" . $snow . "'";
//// $where .= " and BuySum<=".$r;
//// $where .= " and Sum<=".$r;
// $order['Sum']='desc';
//
// $rs=getApiData("wxderp.cashreplace.list.get",$tk["api_token"],null,$where,1,1000,$order);
// $qlistall = json_decode($rs, true);
// if(!empty($qlistall)){
// if($qlistall['data']) {
// foreach ($qlistall['data'] as $k1 => $v1) {
// foreach ($fzquan as $ku=>$vu){
// $qlistall['data'][$k1]['CashRepNo']=$vu['CashRepNo'];
// unset($qlistall['data'][$k1]);
// break;
// }
// $qlistall['data'][$k1]['Sum'] = number_format(empty($v1['Sum']) ? 0 : $v1['Sum'], 2);
// $qlistall['data'][$k1]['BuySum'] = number_format(empty($v1['BuySum']) ? 0 : $v1['BuySum'], 2);
// $qlistall['data'][$k1]['ValidDate']=date('Y-m-d H:i:s', strtotime($v1['ValidDate']));
// }
//
// }
// }
// //$couponList = DB::query($sql);
// $plist_cart[$k]["couponList"]=$qlistall['data'];
unset($list);
//unset($qlistall);
}
$this->assign('slist', $plist_cart);
$this->assign('shippingList', $shippingList); // 物流公司
$this->assign('total_price', $result['total_price']); // 总计
upload_ylp_log('购买积分购商品订单页面');
return $this->fetch('', getMobileStoId());
}
/**
* ajax 获取积分购订单商品价格或者积分购提交订单
*/
public function cart6()
{
/*--物流方式--*/
$exptype = I("exptype/d");
$stoid = I("stoid");
$state = I("state/d");
if ($this->user_id == 0)
exit(json_encode(array('status' => -100, 'msg' => "登录超时请重新登录!", 'result' => null))); // 返回结果状态
$address_id = I("address_id/d"); // 收货地址id
$setadd = I("setadd/d");
/*--积分购传到前台的值--*/
$arystr = I("goodsstr");
$ary0 = explode("-", $arystr);
/*--是否是编辑地址--*/
if ($setadd == 1 && $exptype == 0 && empty($address_id)) {
$consignee = I("consignee");
$mobile = I("mobile");
$province = I("province");
$city = I("city");
$district = I("district");
$twon = I("twon");
$address = I("address");
$data = ['consignee' => $consignee,
'mobile' => $mobile,
'province' => $province,
'city' => $city,
'district' => $district,
'twon' => $twon,
'address' => $address,
];
$logic = new UsersLogic();
$data = $logic->add_address($this->user_id, 0, $data);
$address_id = $data['result'];
}
$shipping_code = I("shipping_code/a"); // 物流编号
$invoice_title = I('invoice_title/a'); // 发票
$exparr= I('exparr/a');//获取物流配送数组
$couponTypeSelect = I("couponTypeSelect"); // 优惠券类型 1 下拉框选择优惠券 2 输入框输入优惠券代码
$coupon_id = I("coupon_id/a"); // 优惠券id
$couponCode = I("couponCode"); // 优惠券代码
$user_note = I('user_note/a'); //买家留言
$pay_points = I("pay_points", 0); // 使用积分
$user_money = I("user_money", 0); // 使用余额
$user_money = str_replace(',', '', $user_money);
$user_money = doubleval($user_money);
$exptype=0;
foreach ($exparr as $ko=>$vo){
if($vo==1){ $exptype=1; break;}
}
/*--购物车商品提取--*/
/*--
$cart_goods = M('Cart')->alias('a')
->join("pick_up b","a.pick_id=b.pickup_id",'left')
->where(['a.user_id'=>$this->user_id,'a.selected'=>1])
->where($where)->getField("a.*,b.pickup_name,b.pickup_id");--*/
/*---购物车和立即购买的区分---*/
$result = null;
$result = $this->cartLogic->gointeList($this->user, $this->session_id); //获取购物车商品
$cart_goods = $result['cartList'];
if (empty($cart_goods))
exit(json_encode(array('status' => -2, 'msg' => '你的购物车没有选中商品', 'result' => null))); //返回结果状态
$address = M('UserAddress')->where("address_id", $address_id)->find();
$allusrnum = $user_money;
$userd = $this->user;
mlog('获取列表值:'.json_encode($cart_goods),'cart6/'.$stoid);
if ($state == 2) {
$pay_points = $cart_goods[0]['prom']['integral'] * $cart_goods[0]["goods_num"];
}
mlog('状态:'.$state,'cart6/'.$stoid);
mlog('支付积分值:'.$pay_points,'cart6/'.$stoid);
$locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
//订单余额判断
if (!empty($allusrnum)) {
$ye = $userd['user_money'] - $userd['frozen_money'] - $locking_money;
if ($ye . '' < $allusrnum) {
return array('status' => -4,
'msg' => "您的可用余额不足", 'result' => '');
}
}
$err_txt = "";
/*--库存判断和活动判断,商品的库存和活动不能过期--*/
foreach ($cart_goods as $k => $value) {
//活动不一样就是发生了变化
if($value['prom_type1']!=$value['prom_type'] && $value['prom_id1']!=$value['prom_id'] ) {
return array('status' => -3, 'msg' => "{$value['goods_name']}商品价格已经变化", 'result' => '');
}
$ginfo = $value;
/*--线下库存的序列key--*/
$bkey = $value['pick_id'] . $value['goods_id'];
//商品参与活动查看
if ($value['prom_type'] > 0) {
$prom = get_goods_promotion1($value, null, $this->user_id);
if ($prom['is_end'] == 1) {
return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品活动已经结束", 'result' => '');
}
if ($prom['is_end'] == 2) {
return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品已经售完", 'result' => '');
}
if ($prom['is_end'] == 3) {
return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量", 'result' => '');
}
if ($value['prom_type'] == 1 || $value['prom_type'] == 2 || $value['prom_type'] == 4) {
if ($value['goods_num'] > $prom['buy_limit']) {
return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量",
'result' => '');
}
}
if ($ary0[0] != $prom['integral'] && $ary0[0] != "" && $ary0[1] != "") {
$err_txt .= "商品购买积分已经变化";
}
if ($ary0[1] != $prom['addmoney'] && $ary0[0] != "" && $ary0[1] != "") {
$err_txt .= "商品价格已经变化 <br>";
}
if ($value['prom_type'] == 1 || $value['prom_type'] == 2 || $value['prom_type'] == 4) {
if ($value['goods_num'] > $ginfo['store_count']) {
return array('status' => -4, 'msg' => "库存不足", 'result' => '');
}
} else {
return array('status' => -4, 'msg' => "库存不足", 'result' => '');
}
} else {
return array('status' => -4, 'msg' => "库存不足", 'result' => '');
}
}
if ($err_txt != "") {
return array('status' => -1004, 'msg' => $err_txt, 'result' => '');
}
/*--购物车商品分组,生成不同订单--*/
$plist = null;
if ($state == 0) {
$sql = "select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and selected=1 and state=0 GROUP BY pick_id";
$plist = Db::query($sql);
foreach ($plist as $k => $v) {
foreach ($cart_goods as $kk => $vv) {
if ($v['pick_id'] == $vv['pickup_id']) {
$list[] = $vv;
}
}
$plist[$k]["goods"] = $list;
unset($list);
}
} else {
$sql1 = "select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and state=" . $state . " GROUP BY pick_id";
$plist = Db::query($sql1);
foreach ($plist as $k => $v) {
foreach ($cart_goods as $kk => $vv) {
if ($v['pick_id'] == $vv['pickup_id']) {
$list[] = $vv;
}
}
$plist[$k]["goods"] = $list;
unset($list);
}
}
/*--开始生成多单--*/
//$uerp = M('store')->where('store_id', $stoid)->find();
$uerp =tpCache('shop_info',$stoid);
$pno = "";
if (count($plist) > 1) $pno = $uerp['ERPId'] . date('YmdHis') . get_total_millisecond() . rand(1000, 9999);
$postFee = 0;
$couponFee = 0;
$balance = 0;$pointsFee = 0;$payables = 0;$payables1 = 0;$goodsFee = 0;$order_prom_id = 0;$order_prom_id = 0;$order_prom_amount = 0;
// 启动事务
// Db::startTrans();
// try {
foreach ($plist as $k => $v) {
/*--计算订单相关--*/
$scode = $shipping_code[$v['pick_id']];
// if (!empty($shipping_code)){
// if ($scode == 'mdzz'){
// $exptype = 1;
// }else{
// $exptype = 0;
// }
// }
$result = calculate_price3($this->user, $v["goods"], $scode, 0, $address['province'], $address['city'], $address['district'], $pay_points, $user_money, 0, "", $stoid, $exparr[$v['pick_id']]);
if ($result['status'] < 0)
exit(json_encode($result));
/*---余额使用---*/
$user_money = $user_money - $result['result']['user_money'];
$postFee += $result['result']['shipping_price']; // 物流费
$couponFee += $result['result']['coupon_price'];// 优惠券
$balance += $result['result']['user_money']; // 使用用户余额
$pointsFee += $result['result']['integral_money']; // 积分支付
$payables += $result['result']['order_amount'];// 应付金额
$payables1 += $result['result']['order_amount1'];// 应付金额,不包含余额的那部分
$goodsFee += $result['result']['goods_price'];// 商品价格
// 提交订单
if ($_REQUEST['act'] == 'submit_order') {
$address_id = $_REQUEST['address_id'];
mlog("日志" . $address_id . "是否编辑地址" . $setadd, "cart");
if (!$address_id && $exptype == 0) exit(json_encode(array('status' => -3, 'msg' => '请先填写收货人信息', 'result' => null))); // 返回结果状态
if (!$shipping_code && $exptype == 0) exit(json_encode(array('status' => -4, 'msg' => '请选择物流信息', 'result' => null))); // 返回结果状态
if (empty($coupon_id) && !empty($couponCode)) {
$coupon_id = M('CouponList')->where("code", $couponCode)->getField('id');
}
//$iii=$result['result']['user_money'];
$car_price0 = array(
'postFee' => $result['result']['shipping_price'], // 物流费
'couponFee' => $result['result']['coupon_price'], // 优惠券
'balance' => $result['result']['user_money'], // 使用用户余额
'pointsFee' => $result['result']['integral_money'], // 积分支付
'payables' => $result['result']['order_amount'], // 应付金额
'payables1' => $result['result']['order_amount1'], // 应付金额,不包含余额那一部分
'goodsFee' => $result['result']['goods_price'],// 商品价格
'order_prom_id' => 0, // 订单优惠活动id
'order_prom_amount' => 0, // 订单优惠活动优惠了多少钱
);
/*--调用生成订单的函数--*/
$result = $this->cartLogic->addOrder($this->user_id, $address_id,
$shipping_code[$v['pick_id']], $invoice_title[$v['pick_id']], $car_price0,
$v["goods"], $coupon_id[$v['pick_id']], $user_note[$v['pick_id']], $stoid, $exparr[$v['pick_id']], $pno, $v['pick_id'], null, $this->user); // 添加订单
if ($result["status"] != 1)
exit(json_encode($result));
if (empty($pno) && count($plist) == 1) {
$pno = $result["result"];
}
}
}
// 提交订单
if ($_REQUEST['act'] == 'submit_order') {
upload_ylp_log('积分购商品提交订单');
if ($state == 0) {
// 删除购物车中已提交订单商品
M('Cart')->where(['user_id' => $this->user_id, 'selected' => 1])->delete();
//删除购物车的cookie
Cookie::delete("cn");
//Db::commit();
$odr_arr=M('order')->where('parent_sn',$pno)->where('store_id',$stoid)
->field('order_amount,order_sn,order_id,user_id')->select();
foreach ($odr_arr as $k=>$v) {
//不是拼单的订单,才进行分成
if($data['pt_prom_id']>0){
}else{
$order=$v;
//分销开关全局
$distribut_switch = tpCache('distribut.switch', getMobileStoId());
mlog("分成开关-" . $order['order_id'] . $order['order_sn'] . ":" . $distribut_switch, 'rebate_log/' . getAdmStoId());
if ($distribut_switch == 1 && file_exists(APP_PATH . 'common/logic/DistributLogic.php')) {
$distributLogic = new \app\common\logic\DistributLogic();
$distributLogic->rebate_log($order, getMobileStoId()); // 生成分成记录
}
}
if ($v['order_amount'] == 0) {
update_pay_status2($v['order_sn'], 1);
}
}
exit(json_encode(array('status' => 1, 'msg' => '提交订单成功', 'result' => $pno, 'payables' => $payables)));
} else {
// 删除cart表中立即购买的商品
M('Cart')->where(['user_id' => $this->user_id, 'state' => 1])->delete();
//Db::commit();
$odr_arr=M('order')->where('parent_sn',$pno)->where('store_id',$stoid)
->field('order_amount,order_sn,order_id,user_id')->select();
foreach ($odr_arr as $k=>$v) {
if ($v['order_amount'] == 0) {
update_pay_status2($v['order_sn'], 1);
}
}
exit(json_encode(array('status' => 1, 'msg' => '提交订单成功', 'result' => $pno, 'payables' => $payables)));
}
}
// }
// catch (\Exception $e) {
// // 回滚事务
// Db::rollback();
// exit(json_encode(array('status' => -1, 'msg' => '提交订单失败')));
// }
$car_price = array(
'postFee' => round($postFee, 2), // 物流费
'couponFee' => round($couponFee, 2), // 优惠券
'balance' => round($allusrnum - $user_money, 2), // 使用用户余额
'pointsFee' => round($pointsFee, 2), // 积分支付
'payables' => round($payables, 2), // 应付金额
'payables1' => round($payables1, 2), // 应付金额,不包含使用余额的那一部分
'goodsFee' => round($goodsFee, 2)// 商品价格
);
$return_arr = array('status' => 1, 'msg' => '计算成功', 'result' => $car_price); // 返回结果状态
exit(json_encode($return_arr));
}
/**
* ajax 获取积分购订单商品价格
*/
public function cart6_nosub()
{
/*--物流方式--*/
$exptype = I("exptype/d");
$stoid = I("stoid");
$state = I("state/d",0);
if ($this->user_id == 0)
exit(json_encode(array('status' => -100, 'msg' => "登录超时请重新登录!", 'result' => null))); // 返回结果状态
$address_id = I("address_id/d"); // 收货地址id
$setadd = I("setadd/d");
/*--是否是编辑地址--*/
if ($setadd == 1 && $exptype == 0 && empty($address_id)) {
$consignee = I("consignee");
$mobile = I("mobile");
$province = I("province");
$city = I("city");
$district = I("district");
$twon = I("twon");
$address = I("address");
$data = ['consignee' => $consignee,
'mobile' => $mobile,
'province' => $province,
'city' => $city,
'district' => $district,
'twon' => $twon,
'address' => $address,
];
$logic = new UsersLogic();
$data = $logic->add_address($this->user_id, 0, $data);
$address_id = $data['result'];
}
$shipping_code = I("shipping_code/a"); // 物流编号
$invoice_title = I('invoice_title/a'); // 发票
$exparr= I('exparr/a');//获取物流配送数组
$couponTypeSelect = I("couponTypeSelect"); // 优惠券类型 1 下拉框选择优惠券 2 输入框输入优惠券代码
$coupon_id = I("coupon_id/a"); // 优惠券id
$couponCode = I("couponCode"); // 优惠券代码
$user_note = I('user_note/a'); //买家留言
$pay_points = I("pay_points", 0); // 使用积分
$user_money = I("user_money", 0); // 使用余额
$user_money = str_replace(',', '', $user_money);
$user_money = doubleval($user_money);
/*--购物车商品提取--*/
/*--
$cart_goods = M('Cart')->alias('a')
->join("pick_up b","a.pick_id=b.pickup_id",'left')
->where(['a.user_id'=>$this->user_id,'a.selected'=>1])
->where($where)->getField("a.*,b.pickup_name,b.pickup_id");--*/
/*---购物车和立即购买的区分---*/
$result = null;
$result = $this->cartLogic->gointeList($this->user, $this->session_id); //获取购物车商品
$cart_goods = $result['cartList'];
if (empty($cart_goods))
exit(json_encode(array('status' => -2, 'msg' => '你的购物车没有选中商品', 'result' => null))); //返回结果状态
$address = M('UserAddress')->where("address_id", $address_id)->find();
$allusrnum = $user_money;
$userd = $this->user;
$pay_points = $cart_goods[0]['prom']['integral'] * $cart_goods[0]["goods_num"];
$locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
//订单余额判断
if (!empty($allusrnum)) {
$ye = $userd['user_money'] - $userd['frozen_money'] - $locking_money;
if ($ye . '' < $allusrnum) {
return array('status' => -4,
'msg' => "您的可用余额不足", 'result' => '');
}
}
/*--购物车商品分组,生成不同订单--*/
$plist = null;
$sql1 = "select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and state=" . $state . " GROUP BY pick_id";
$plist = Db::query($sql1);
foreach ($plist as $k => $v) {
foreach ($cart_goods as $kk => $vv) {
if ($v['pick_id'] == $vv['pickup_id']) {
$list[] = $vv;
}
}
$plist[$k]["goods"] = $list;
unset($list);
}
/*--开始生成多单--*/
//$uerp = M('store')->where('store_id', $stoid)->find();
$uerp = tpCache('shop_info',$stoid);
$pno = "";
if (count($plist) > 1) $pno = $uerp['ERPId'] . date('YmdHis') . get_total_millisecond() . rand(1000, 9999);
$postFee = 0;
$couponFee = 0;
$balance = 0;
$pointsFee = 0;
$payables = 0;
$payables1 = 0;
$goodsFee = 0;
$order_prom_id = 0;
$order_prom_id = 0;
$order_prom_amount = 0;
foreach ($plist as $k => $v) {
/*--计算订单相关--*/
$scode = $shipping_code[$v['pick_id']];
$result = calculate_price3($this->user, $v["goods"], $scode, 0, $address['province'], $address['city'], $address['district'], $pay_points, $user_money, 0, "", $stoid, $exparr[$v['pick_id']]);
if ($result['status'] < 0)
exit(json_encode($result));
/*---余额使用---*/
$user_money = $user_money - $result['result']['user_money'];
$postFee += $result['result']['shipping_price']; // 物流费
$couponFee += $result['result']['coupon_price'];// 优惠券
$balance += $result['result']['user_money']; // 使用用户余额
$pointsFee += $result['result']['integral_money']; // 积分支付
$payables += $result['result']['order_amount'];// 应付金额
$payables1 += $result['result']['order_amount1'];// 应付金额,不包含余额的那部分
$goodsFee += $result['result']['goods_price'];// 商品价格
}
$car_price = array(
'postFee' => round($postFee, 2), // 物流费
'couponFee' => round($couponFee, 2), // 优惠券
'balance' => round($allusrnum - $user_money, 2), // 使用用户余额
'pointsFee' => round($pointsFee, 2), // 积分支付
'payables' => round($payables, 2), // 应付金额
'payables1' => round($payables1, 2), // 应付金额,不包含使用余额的那一部分
'goodsFee' => round($goodsFee, 2)// 商品价格
);
$return_arr = array('status' => 1, 'msg' => '计算成功', 'result' => $car_price); // 返回结果状态
exit(json_encode($return_arr));
}
/*
* ajax 请求获取购物车列表
*/
public function ajaxCartList()
{
$post_goods_num = I("goods_num/a"); // goods_num 购物车商品数量
$post_cart_select = I("cart_select/a"); // 购物车选中状态
$where['session_id'] = $this->session_id; // 默认按照 session_id 查询
// 如果这个用户已经等了则按照用户id查询
$user_id = $this->user_id;
$stoid = getMobileStoId();
if ($user_id) {
unset($where);
$where['user_id'] = $user_id;
}
$where['state'] = 0;
$where['store_id'] = $stoid;
$where['is_gift'] = 0;
M('Cart')->where($where)->save(['selected' => 0]);
$cartList = M('Cart')->alias('a')->join('goods b', 'a.goods_id=b.goods_id')->where(['a.user_id' => $user_id, 'a.store_id' => $stoid, 'a.state' => 0])
->getfield('a.id,a.prom_type,a.selected,a.pick_id,a.goods_id,a.goods_num,a.prom_id,b.shop_price,b.store_count,b.is_on_sale,a.is_gift,b.prom_type as prom_type1,b.viplimited,b.prom_id as prom_id1,a.goods_price');
$now0 = time();
/*---如果是线下销售规则,获取所有购物车商品和门店的组合库存数组---*/
$sale_r = tpCache("basic.sales_rules", $stoid);
if ($sale_r == 2) {
$dlinearr = getcountarr($cartList, $stoid);
}
/*-----------------页面一开始加载的时候更新数量,剔除下架和活动结束的商品-------------*/
if (!empty($cartList)) {
/*--要剔除下架商品,活动有过期的商品,或者商品在参加活动之前被添加到购物车--*/
foreach ($cartList as $k => $v) {
if ($v['is_on_sale'] == 1 && $v['on_time']< $now0 && ($v['down_time']> $now0 || empty($v['down_time']))) {
//--当是优惠促销,搭配促销,普通商品的时候,要直接剔除商品--
if($v['prom_type']==3 || $v['prom_type']==5 || $v['prom_type']==0 ){
$rank_switch = tpCache('shopping.rank_switch', $stoid);//等级价格
$mz_switch = tpCache('shopping.is_beauty', $stoid);//美妆价格
//--判断等级价--
$card_field=$this->user['card_field'];
if($card_field && strtotime($this->user['card_expiredate'])>time()) $is_dengji=1;
$Special_price=0;
$goodsinfo=M('goods')->where("store_id",$stoid)->where('goods_id',$v['goods_id'])
->field("mz_price,cardprice1,cardprice2,cardprice3")
->find();
//--如果商家有开通等级价,或者美妆价的功能--
if($rank_switch && $is_dengji && $goodsinfo[$card_field]>0 ){
$Special_price=$goodsinfo[$card_field];
}else if( $mz_switch && $this->user['is_mzvip'] && $goodsinfo["mz_price"]>0 ) {
$Special_price = $goodsinfo["mz_price"];
}
//如果有特殊的价格,等级价和美妆价不为0
if($Special_price){
if($Special_price!=$v['goods_price']){
M('Cart')->where('id', $v['id'])->where('user_id', $this->user_id)->delete();
unset($cartList[$k]);
continue;
}
}else{
//如果价格有发生变化就要
if($v['shop_price']!=$v['goods_price']){
M('Cart')->where('id', $v['id'])->where('user_id', $this->user_id)->delete();
unset($cartList[$k]);
continue;
}
}
}
if ($v['prom_type'] != 0 && $v['is_gift'] == 0) {
$is_del_ok=1;
//--要判断优惠全场的情况---
if($v['prom_type']==3){
//---不同优惠活动的话---
if($v['prom_type1']==3 && $v['prom_id1']!=$v['prom_id'] ){
M('Cart')->where('id', $v['id'])->where('user_id', $this->user_id)->delete();
unset($cartList[$k]);
continue;
}
$rs=M("prom_goods")->where("store_id",$stoid)
->where('id',$v['prom_id'])->field("good_object")->find();
if($rs && $rs['good_object']==0){
$is_del_ok=0;
}
}
//参加活动又删除的情况
if($v['prom_type1']==0 && $v['prom_id1']==0 && $is_del_ok==1){
M('Cart')->where('id', $v['id'])->where('user_id', $this->user_id)->delete();
unset($cartList[$k]);
continue;
}
mlog("zhengq-0:".json_encode($v),"ajaxCartList/".$stoid);
//不是普通购买,且活动id不一样
if($v['is_integral_normal']!=1 && $v['is_pd_normal']!=1 && $v['prom_type']!=3){
if($v['prom_type1']!=$v['prom_type'] && $v['prom_id1']!=$v['prom_id'] ){
M('Cart')->where('id', $v['id'])->where('user_id', $this->user_id)->delete();
unset($cartList[$k]);
continue;
}
}
mlog("zhengq:".json_encode($v),"ajaxCartList/".$stoid);
$prom = get_goods_promotion1($v, null, $user_id);
if ($prom['is_end'] == 2 || $prom['is_end'] == 3 || $prom['is_end'] == 1) {
M('Cart')->where('goods_id', $v['goods_id'])->where('user_id', $this->user_id)->delete();
unset($cartList[$k]);
}
} else {
$where = [
'end_time' => ['>=', $now0],
'start_time' => ['<=', $now0],
'goods_id' => $v['goods_id'],
'is_end' => 0
];
if ($v['prom_type1'] == 1) {//秒杀
$jj = M('flash_sale')->where($where)->find();
if ($jj) {
M('Cart')->where('goods_id', $v['goods_id'])->where('user_id', $this->user_id)->delete();
unset($cartList[$k]);
}
}
if ($v['prom_type1'] == 2) {//团购
$jj = M('group_buy')->where($where)->find();
if ($jj) {
M('Cart')->where('goods_id', $v['goods_id'])->where('user_id', $this->user_id)->delete();
unset($cartList[$k]);
}
}
if ($v['prom_type1'] == 4) {//积分购
$jj = M('flash_sale')->where($where)->find();
if ($jj) {
M('Cart')->where('goods_id', $v['goods_id'])->where('user_id', $this->user_id)->delete();
unset($cartList[$k]);
}
}
if ($v['is_gift'] == 1) {
M('cart')->where(['id' => $v['id'], 'user_id' => $user_id])->delete();
unset($cartList[$k]);
}
}
} else {
M('Cart')->where('id', $v['id'])->where('user_id', $user_id)->delete();
unset($cartList[$k]);
}
}
}
//统计赠品
// $count=array();
// foreach ($cartList as $val){
// if ($val['is_gift']==1){
// $count[$val['prom_id']]+=1;
// $count[$val['pick_id']][$val['prom_id']]+=1;
// }
// }
/*--------------改变数量和选择商品--------------*/
if (!empty($post_goods_num)) {
// 修改购物车数量,和勾选状态
foreach ($post_goods_num as $key => $val) {
if(empty($cartList[$key])) continue;
/*--线下库存的序列key--*/
$bkey = $cartList[$key]['pick_id'] . $cartList[$key]['goods_id'];
$data['goods_num'] = $val < 1 ? 1 : $val;
$cnum=M("cart")->where('pick_id<>'.$cartList[$key]['pick_id'])
->where('user_id',$this->user_id)
->where('goods_id',$cartList[$key]['goods_id'])->sum('goods_num');
if ($cartList[$key]['prom_type'] > 0 && $cartList[$key]['prom_type'] != 3 && $cartList[$key]['prom_type'] != 5) {
$prom = get_goods_promotion1($cartList[$key], null, $user_id);
$ou=$prom['store_count']-$cnum>0?$prom['store_count']-$cnum:0;
/*---如果大于线上库存--*/
$data['goods_num'] = $data['goods_num']+$cnum > $prom['store_count'] ?$ou : $data['goods_num'];
if ($cartList[$key]['prom_type'] == 1 || $cartList[$key]['prom_type'] == 2 ) {
$ou=$prom['onlybuy']-$cnum>0?$prom['onlybuy']-$cnum:0;
$data['goods_num'] = $data['goods_num']+$cnum>$prom['onlybuy'] ? $ou: $data['goods_num'];
}
/*---如果是秒杀和积分购---*/
if ($cartList[$key]['prom_type'] == 1 || $cartList[$key]['prom_type'] == 2 ) {
$ou=$prom['buy_limit']-$cnum>0?$prom['buy_limit']-$cnum:0;
$data['goods_num'] = $data['goods_num']+$cnum > $prom['buy_limit'] ? $ou: $data['goods_num'];
}
} else {
/*--如果是线下规则--*/
if ($sale_r == 2) {
$dlcount = $dlinearr[$bkey];
if (!empty($dlcount) && $dlcount > 0) {
$gid=$cartList[$key]['goods_id'];
$pid=$cartList[$key]['pick_id'];
//---获取预出库数---
//线下库存判断预存是多少
$strq = 'select sum(out_qty) as sum0 from __PREFIX__erp_yqty where goods_id='
. $gid . ' and store_id='.$stoid.' and pickup_id='.$pid;
$dd = Db::query($strq);
$dlcount=$dlcount-$dd[0]['sum0'];
$data['goods_num'] = $data['goods_num'] > $dlcount ? $dlcount : $data['goods_num'];
}
else{
$data['goods_num']=0;
}
} else if ($sale_r == 1) {
$data['goods_num'] = $data['goods_num'] > $cartList[$key]['store_count'] ? $cartList[$key]['store_count'] : $data['goods_num'];
}
}
$data['selected'] = $post_cart_select[$key] ? 1 : 0;
if ($cartList[$key]['goods_num'] != $data['goods_num'] || $cartList[$key]['selected'] != $data['selected']) {
M('Cart')->where("id", $key)->save($data);
}
}
$this->assign('select_all', input('post.select_all')); // 全选框
}
$prom_goods = array();
if (!empty($post_cart_select)) {
foreach ($post_cart_select as $kk => $vv) {
if ($cartList[$kk]['prom_type'] == 3) {
$prom_goods[$cartList[$kk]['pick_id']][$cartList[$kk]['prom_id']]['num'] += $post_goods_num[$kk];
$prom_goods[$cartList[$kk]['pick_id']][$cartList[$kk]['prom_id']]['price'] += $cartList[$kk]['goods_price'] * $post_goods_num[$kk];
$prom_goods['pick'][] = $cartList[$kk]['pick_id'];//收集选中的门店
}
}
}
if (!empty($prom_goods)) {
M('cart')->where(['is_gift' => 1, 'user_id' => $user_id, 'pick_id' => ['not in', $prom_goods['pick']]])->delete();
unset($prom_goods['pick']);
$prominfo = M('prom_goods')->where(['start_time' => ['lt', time()], 'end_time' => ['gt', time()], 'is_end' => 0])->getfield('id,good_object,name,is_bz');
foreach ($prom_goods as $k => $v) {
foreach ($v as $kk => $vv) {
$prom_id_list[] = $kk;//收集选中门店选中优惠活动id
if (!empty($prominfo[$kk])) {
mlog('1-'.$vv['price'],'ajaxCartList/'.$stoid);
$prom = discount($vv['price'], $kk, $vv['num'], $user_id,$prominfo[$kk]['is_bz']);
if (!empty($prom['goods_id'])) {
$count = M('cart')->where(['user_id' => $user_id, 'prom_id' => $kk, 'is_gift' => 1])->count();
$pick = M('cart')->where(['user_id' => $user_id, 'prom_id' => $kk, 'is_gift' => 1, 'pick_id' => $k])->find();
//要判断倍增,所以赠品是数量也要倍增
$num=1;
if($prom['is_bz']==1){
//按件的判断
$num=$prom['bs'];
//if($num>$prom['limit_num']) $num=$prom['limit_num']; //礼品有最大输出限制
if($num>$prom['limit_num']) $num=0; //礼品有最大输出限制
}
//如果赠品的总送的数量大于礼包的库存,则不送
if($num+$count>$prom['gift_storecount']) $num=0;
if ($count < $prom['limit_num'] && empty($pick) && $num>0) {
M('cart')->add(['user_id' => $user_id, 'session_id' => $this->session_id, 'goods_id' => $prom['goods_id'], 'goods_sn' => '',
'goods_name' => $prom['goods_name'], 'market_price' => 0, 'goods_price' => 0, 'member_goods_price' => 0, 'goods_num' => $num, 'sku' => '',
'add_time' => time(), 'prom_type' => 3, 'prom_id' => $kk, 'pick_id' => $k, 'store_id' => $stoid, 'state' => 0, 'main_cart_id' => 1,
'is_gift' => 1, 'selected' => 1,'gift_id'=>$prom['gift_id']]);
}
else{
M('cart')->where(['id' =>$pick['id']])
->save(['goods_num'=>$num]);
}
} else {
M('cart')->where(['user_id' => $user_id, 'is_gift' => 1, 'prom_id' => $kk, 'pick_id' => $k])->delete();
}
if ($prom['type'] == 0) {
if ($vv['price'] < $prom['condition']) {
$prom_goods[$k][$kk]['condition'] = ($prom['condition'] - $vv['price']) . '元';
}
} else {
if ($vv['num'] < $prom['condition']) {
$prom_goods[$k][$kk]['condition'] = ($prom['condition'] - $vv['num']) . '件';
}
}
if (!empty($prom['rule'])){
$prom_goods[$k][$kk]['next_mon'] = $prom['rule']['money'];
$prom_goods[$k][$kk]['next_sal'] = $prom['rule']['sale'];
$prom_goods[$k][$kk]['next_pas'] = $prom['rule']['is_past'];
$prom_goods[$k][$kk]['next_int'] = $prom['rule']['int'];
$prom_goods[$k][$kk]['next_cou'] = $prom['rule']['coupon'];
$prom_goods[$k][$kk]['next_gif'] = $prom['rule']['gift'];
}
$prom_goods[$k][$kk]['all'] = $prominfo[$kk]['good_object'];
}
}
M('cart')->where(['is_gift' => 1, 'user_id' => $user_id, 'pick_id' => $k, 'prom_id' => ['not in', $prom_id_list]])->delete();
}
// $pick = substr($pick, 0, strlen($pick) - 1);//去除最后一个字符
} else {
M('cart')->where(['user_id' => $user_id, 'is_gift' => 1])->delete();
}
/*------购物车中商品库存要判断线下库存------*/
$result = $this->cartLogic->cartList($this->user, $this->session_id, 0, 1);
$cart_goods = $result['cartList'];
foreach ($cart_goods as $k=>$v){
if (empty($v['viplimited'])){
$cart_goods[$k]['viplimited'] = 10000;
}else{
$limit=M('order')->alias('a')->join('order_goods b','a.order_id=b.order_id')->where(['b.goods_id'=>$v['goods_id'],'a.user_id'=>$user_id,'a.order_status'=>[['=',4],['<',3],'or']])->sum('b.goods_num');
$cart_goods[$k]['viplimited']-= $limit;
}
}
$allprice = 0;
$selectnum = 0;
if ($sale_r == 2) {
/*---循环变更购物车商品的库存---*/
foreach ($cart_goods as $km => $vm) {
/*--线下库存的序列key--*/
$bkey = $vm['pick_id'] . $vm['goods_id'];
if (($vm['prom_type'] == 0 || $vm['prom_type'] == 3 || $vm['prom_type'] == 5) && $vm['is_gift']==0) {
$dlcount = $dlinearr[$bkey];
$gid=$vm['goods_id'];
//---获取预出库数---
//线下库存判断预存是多少
$strq = 'select sum(out_qty) as sum0 from __PREFIX__erp_yqty where goods_id='
. $gid . ' and store_id='.$stoid.' and pickup_id='.$vm['pick_id'];
mlog($strq,"ajaxCartList/".$stoid);
$dd = Db::query($strq);
mlog("num1:".$dd[0]['sum0'],"ajaxCartList/".$stoid);
$dlcount=$dlcount-$dd[0]['sum0'];
mlog("num1:".$dlcount,"ajaxCartList/".$stoid);
if ($dlcount == null) $dlcount = 0;
$cart_goods[$km]['store_count'] = $dlcount;
if ($cart_goods[$km]['goods_num'] > $dlcount) {
$cart_goods[$km]['selected'] = 0;
$cart_goods[$km]['goods_num'] = $dlcount;
$rss = M('Cart')->where("id", $vm['id'])->save(['selected' => 0, 'goods_num' => $dlcount]);
} else {
if ($vm['selected']) {
$allprice += $vm['goods_num'] * $vm['member_goods_price'];
$selectnum += $vm['goods_num'];
}
}
} else {
if ($cart_goods[$km]['goods_num'] > $vm['store_count']) {
$cart_goods[$km]['selected'] = 0;
M('Cart')->where("id", $vm['id'])->save(['selected' => 0, 'goods_num' => $vm['store_count']]);
} else {
if ($vm['selected']) {
$allprice += $vm['goods_num'] * $vm['member_goods_price'];
$selectnum += $vm['goods_num'];
}
}
}
}
} else {
/*---循环变更购物车商品的库存---*/
foreach ($cart_goods as $km => $vm) {
if ($cart_goods[$km]['goods_num'] > $vm['store_count']) {
$cart_goods[$km]['selected'] = 0;
M('Cart')->where("id", $vm['id'])->save(['selected' => 0, 'goods_num' => $vm['store_count']]);
} else {
if ($vm['selected']) {
$allprice += $vm['goods_num'] * $vm['member_goods_price'];
$selectnum += $vm['goods_num'];
}
}
}
}
$this->assign("allprice", $allprice);
$this->assign("selectnum", $selectnum);
$countC = M('Cart')->where('user_id', $this->user_id)->where('store_id', getMobileStoId())->where('state', '0')->where('is_gift', 0)->sum('goods_num');
$this->assign("cart_num", $countC);
/*---计算价格---*/
// if (empty($result['total_price']))
// $result['total_price'] = Array('total_fee' => 0, 'cut_fee' => 0, 'num' => 0, 'atotal_fee' => 0, 'acut_fee' => 0, 'anum' => 0);
$cartsql = "select pickup_id,pickup_name from wxd_pick_up where pickup_id in(select pick_id from wxd_cart where user_id=" . $this->user_id . " and state=0 and store_id=" . getMobileStoId() . " GROUP BY pick_id)";
$plist_cart = Db::query($cartsql);
foreach ($plist_cart as $k => $v) {
$isallsele = 1;
foreach ($cart_goods as $kk => $vv) {
if ($vv['pick_id'] == $v['pickup_id']) {
$plist_cart[$k]['goods'][] = $vv;
if ($vv["selected"] != 1) {
$isallsele = 0;
}
// else {
// $good_jg = 0;
// if ($vv['prom_type'] != 0 && $vv['prom_type'] != 3) {
// $prom = get_goods_promotion1($vv,null, $user_id);
// $good_jg = $prom['price'];
// } else {
// $good_jg = $vv['member_goods_price'];
// }
// }
}
}
$plist_cart[$k]['selected'] = $isallsele;
if (!empty($prom_goods)) {
foreach ($prom_goods as $key => $val) {
if ($key == $v['pickup_id']) {
$plist_cart[$k]['condition'] = $val;
}
}
}
// $freight_free = tpCache('shopping.freight_free', getMobileStoId()); // 全场满多少免运费
// if ($selenum >= $freight_free || $selenum == 0) {
// $plist_cart[$k]["moremoney"] = 0;
// } else if ($selenum > 0) {
// $plist_cart[$k]["moremoney"] = $freight_free - $selenum;
// }
}
//$this->assign('cartList', $result['cartList']); // 购物车的商品
$this->assign('cartList', $plist_cart); // 购物车的商品
// $this->assign('total_price', $result['total_price']); // 总计
upload_ylp_log('购物车列表');
return $this->fetch('ajax_cart_list', getMobileStoId());
}
/*
* ajax 获取用户收货地址 用于购物车确认订单页面
*/
public function ajaxAddress()
{
$regionList = M('Region')->getField('id,name');
$address_list = M('UserAddress')->where("user_id", $this->user_id)->select();
$c = M('UserAddress')->where("user_id = {$this->user_id} and is_default = 1")->count(); // 看看有没默认收货地址
if ((count($address_list) > 0) && ($c == 0)) // 如果没有设置默认收货地址, 则第一条设置为默认收货地址
$address_list[0]['is_default'] = 1;
$this->assign('regionList', $regionList);
$this->assign('address_list', $address_list);
return $this->fetch('ajax_address', getMobileStoId());
}
/**
* ajax 删除购物车的商品
*/
public function ajaxDelCart()
{
$ids = I("ids"); // 购物车ids
M("Cart")->where("id", "in", $ids)->delete(); // 删除id为5的用户数据
$return_arr = array('status' => 1, 'msg' => '删除成功', 'result' => ''); // 返回结果状态
exit(json_encode($return_arr));
}
public function getNum()
{
$user_id = $this->user_id;
$now0 = time();
if (session('?user')) {
/*--要剔除下架商品,活动有过期的商品,或者商品在参加活动之前被添加到购物车--*/
$cartList = M('Cart')->alias('a')->join('goods b', 'a.goods_id=b.goods_id')->where(['a.user_id' => $user_id, 'a.store_id' => getMobileStoId(), 'a.state' => 0])
->field('a.id,a.prom_type,a.goods_id,a.prom_id,b.shop_price,b.store_count,b.is_on_sale,a.is_gift,b.prom_type as prom_type1')->select();
if (!empty($cartList)) {
foreach ($cartList as $k => $v) {
if ($v['is_on_sale'] == 1 && $v['on_time']< $now0 && ($v['down_time']> $now0 || empty($v['down_time'])) ) {
if ($v['prom_type'] != 0 && $v['is_gift'] == 0) {
$prom = get_goods_promotion1($v, null, $user_id);
if ($prom['is_end'] == 2 || $prom['is_end'] == 3 || $prom['is_end'] == 1) {
M('Cart')->where('id', $v['id'])->where('user_id', $user_id)->delete();
}
} else {
$where = [
'end_time' => ['>=', $now0],
'start_time' => ['<=', $now0],
'goods_id' => $v['goods_id'],
'is_end' => 0
];
if ($v['prom_type1'] == 1) {//秒杀
$jj = M('flash_sale')->where($where)->find();
if ($jj) {
M('Cart')->where('id', $v['id'])->where('user_id', $user_id)->delete();
}
}
if ($v['prom_type1'] == 2) {//团购
$jj = M('group_buy')->where($where)->find();
if ($jj) {
M('Cart')->where('id', $v['id'])->where('user_id', $user_id)->delete();
}
}
if ($v['prom_type1'] == 4) {//积分购
$jj = M('flash_sale')->where($where)->find();
if ($jj) {
M('Cart')->where('id', $v['id'])->where('user_id', $user_id)->delete();
}
}
}
} else {
M('Cart')->where('id', $v['id'])->where('user_id', $user_id)->delete();
}
}
}
$num = M("Cart")->where('user_id', $user_id)->where('store_id', getMobileStoId())->where('state', 0)->where('is_gift', 0)->sum('goods_num');
if (empty($num)) {
return 0;
} else {
return $num;
}
} else {
return 0;
}
}
/*----------------------------------地址管理------------------------------------*/
/*
* 添加地址
*/
public function add_address()
{
upload_ylp_log('添加地址');
$logic = new UsersLogic();
$id = I('address_id', 0);
$seleid = I("seleid");
$this->assign("seleid", $seleid);
$data = $logic->add_address($this->user_id, $id, I('get.'));
if ($data['status'] != 1)
return json(['code' => -1, 'fir' => $data['fir'],]);
else {
/*---获取地区---*/
$region_list = get_region_list();
$addlist = M('user_address')->where(['user_id' => $this->user_id])->select();
foreach ($addlist as $kk => $vv) {
$vv['provicename'] = $region_list[$vv['province']]['name'];
$vv['cityname'] = $region_list[$vv['city']]['name'];
$vv['districtname'] = $region_list[$vv['district']]['name'];
$vv['twonname'] = $region_list[$vv['twon']]['name'];
//$address = M('user_address')->where(['user_id'=>$this->user_id,'is_default'=>1])->find();
$addrstr = $vv['provicename'] . "-" . $vv['cityname'];
if (!empty($vv['district']))
$addrstr .= "-" . $vv['districtname'];
if (!empty($vv['twon']))
$addrstr = $addrstr . "-" . $vv['twonname'];
$vv['addrstr'] = $addrstr;
$addlist[$kk] = $vv;
}
$this->assign("addlist", $addlist);
return json(['code' => 1, 'fir' => $data['fir'], 'id' => $data['result'],
'data' => $this->fetch('ajax_addrlist', getMobileStoId())]);
}
}
/*
* 添加地址
*/
public function addwx_address()
{
upload_ylp_log('添加微信地址');
$data= I('post.');
// $data="{\"userName\":\"\u5c0f\u82cf\",\"postalCode\":\"362000\",\"provinceName\":\"\u798f\u5efa\u7701\",\"cityName\":\"\u6cc9\u5dde\u5e02\",\"countryName\":\"\u4e30\u6cfd\u533a\",\"detailInfo\":\" \u6cc9\u5dde\u8f6f\u4ef6\u56ed4\u53f7\u697c4\u5c42\",\"telNumber\":\"13599727122\"}";
// $data=json_decode($data,true);
if (empty($data))
{
return json(array('code' =>-1,'msg' => '操作失败'));
}
$userName=$data['userName'];
$postalCode=$data['postalCode'];
$provinceName=$data['provinceName'];
$cityName=$data['cityName'];
$countryName=$data['countryName'];
$detailInfo=$data['detailInfo'];
$telNumber=$data['telNumber'];
$moreAddress=$provinceName."-".$cityName."-".$countryName."-".$detailInfo;
$provinceId=0;
$cityId=0;
$districtId=0;
$res_province=M('region')->where(array('name'=>$provinceName,'level'=>1))->find();
if ($res_province)
{
$provinceId=$res_province['id'];
}
$res_city=M('region')->where(array('name'=>$cityName,'parent_id'=>$provinceId))->find();
if ($res_city)
{
$cityId=$res_city['id'];
}
$res_district=M('region')->where(array('name'=>$countryName,'parent_id'=>$cityId))->find();
if ($res_district)
{
$districtId=$res_district['id'];
}
//判断是否已经添加过了
$resinfo=M('user_address')->where(array('user_id'=>$this->user_id,'consignee'=>$userName,'province'=>$provinceId,'district'=>$districtId,'address'=>$detailInfo,'mobile'=>$telNumber))->find();
if ($resinfo)
{
return json(array('code' => -1, 'msg' => '操作成功,已存在'));
}
$postdata['store_id']=getMobileStoId();
$postdata['user_id']=$this->user_id;
$postdata['consignee']=$userName;
$postdata['province']=$provinceId;
$postdata['city']=$cityId;
$postdata['district']=$districtId;
$postdata['address']=$detailInfo;
$postdata['more_address']=$moreAddress;
$postdata['zipcode']=$postalCode;
$postdata['mobile']=$telNumber;
$logic = new UsersLogic();
$data = $logic->add_address($this->user_id, 0,$postdata);
if ($data['status'] != 1)
return json(['code' => -1, 'fir' => $data['fir']]);
else {
/*---获取地区---*/
$region_list = get_region_list();
$addlist = M('user_address')->where(['user_id' => $this->user_id])->select();
foreach ($addlist as $kk => $vv) {
$vv['provicename'] = $region_list[$vv['province']]['name'];
$vv['cityname'] = $region_list[$vv['city']]['name'];
$vv['districtname'] = $region_list[$vv['district']]['name'];
$vv['twonname'] = $region_list[$vv['twon']]['name'];
//$address = M('user_address')->where(['user_id'=>$this->user_id,'is_default'=>1])->find();
$addrstr = $vv['provicename'] . "-" . $vv['cityname'];
if (!empty($vv['district']))
$addrstr .= "-" . $vv['districtname'];
if (!empty($vv['twon']))
$addrstr = $addrstr . "-" . $vv['twonname'];
$vv['addrstr'] = $addrstr;
$addlist[$kk] = $vv;
}
$this->assign("addlist", $addlist);
return json(['code' => 1, 'fir' => $data['fir'], 'id' => $data['result'],
'data' => $this->fetch('ajax_addrlist', getMobileStoId())]);
}
}
/*
* 地址编辑
*/
public function edit_address()
{
upload_ylp_log('编辑地址');
$logic = new UsersLogic();
$data = $logic->add_address($this->user_id, 0, I('get.'));
if ($data['status'] != 1)
return json(['code' => -1]);
else {
return json(['code' => 1]);
}
}
/*
* 获取省市区
*/
public function get_area()
{
$id = I('aid');
$address = M("user_address")->where('address_id', $id)->find();
//获取省份
$p = M('region')->where(array('parent_id' => 0, 'level' => 1))->select();
$c = M('region')->where(array('parent_id' => $address['province'], 'level' => 2))->select();
$d = M('region')->where(array('parent_id' => $address['city'], 'level' => 3))->select();
$data['province'] = $p;
$data['city'] = $c;
$data['district'] = $d;
$region_list = get_region_list();
$addrstr = $region_list[$address['province']]['name'] . "-" . $region_list[$address['city']]['name'];
if (!empty($address['district']))
$addrstr .= "-" . $region_list[$address['district']]['name'];
if (!empty($address['twon']))
$addrstr = $addrstr . "-" . $region_list[$address['twon']]['name'];
$address['addname'] = $addrstr;
if (empty($data['district'])) {
$e = M('region')->where(array('parent_id' => $address['city'], 'level' => 4))->select();
$data['twon'] = $e;
} else {
$e = M('region')->where(array('parent_id' => $address['district'], 'level' => 4))->select();
$data['twon'] = $e;
}
$jsond = ['code' => 1, 'data' => $data, 'data2' => $address];
return json($jsond);
}
/*
* 地址删除
*/
public function del_address()
{
upload_ylp_log('删除地址');
$backaddr = null;
$id = I('get.id');
$seleid = I("seleid");
$region_list = get_region_list();
$address = M('user_address')->where("address_id", $id)->find();
$row = M('user_address')->where(array('user_id' => $this->user_id, 'address_id' => $id))->delete();
// 如果删除的是默认收货地址 则要把第一个地址设置为默认收货地址
if ($address['is_default'] == 1) {
$address2 = M('user_address')->where("user_id", $this->user_id)->find();
$address2 && M('user_address')->where("address_id", $address2['address_id'])->save(array('is_default' => 1));
if ($address2) {
$provinename = M('region')->where("id", $address2['province'])->field('name')->find();
$cityname = M('region')->where("id", $address2['city'])->field('name')->find();
$distname = M('region')->where("id", $address2['district'])->field('name')->find();
$twonname = M('region')->where("id", $address2['twon'])->field('name')->find();
$addrstr = $provinename['name'] . "-" . $cityname['name'] . "-" . $distname['name'];
if ($twonname) {
$addrstr = $addrstr . "-" . $twonname['name'];
}
$address2['addrstr'] = $addrstr . " " . $address2['address'];
$backaddr = $address2;
$seleid = $address2['address_id'];
}
} else {
$provinename = $region_list[$address['province']]['name'];
$cityname = $region_list[$address['city']]['name'];
$distname = $region_list[$address['district']]['name'];
$twonname = $region_list[$address['twon']]['name'];
$addrstr = $provinename . "-" . $cityname;
if ($distname) {
$addrstr = $addrstr . "-" . $distname;
}
if ($twonname) {
$addrstr = $addrstr . "-" . $twonname;
}
$address['addrstr'] = $addrstr . " " . $address['address'];
$backaddr = $address;
}
$this->assign("seleid", $seleid);
if (!$row)
return json(['code' => -1]);
else {
/*---获取地区---*/
$addlist = M('user_address')->where(['user_id' => $this->user_id])->select();
foreach ($addlist as $kk => $vv) {
$vv['provicename'] = $region_list[$vv['province']]['name'];
$vv['cityname'] = $region_list[$vv['city']]['name'];
$vv['districtname'] = $region_list[$vv['district']]['name'];
$vv['twonname'] = $region_list[$vv['twon']]['name'];
//$address = M('user_address')->where(['user_id'=>$this->user_id,'is_default'=>1])->find();
$addrstr = $vv['provicename'] . "-" . $vv['cityname'];
if (!empty($vv['district']))
$addrstr .= "-" . $vv['districtname'];
if (!empty($vv['twon']))
$addrstr = $addrstr . "-" . $vv['twonname'];
$vv['addrstr'] = $addrstr;
$addlist[$kk] = $vv;
}
$this->assign("addlist", $addlist);
return json(['code' => 1, 'address2' => $backaddr,
'data' => $this->fetch('ajax_addrlist', getMobileStoId())]);
}
}
/*--绑定手机号--*/
public function reg_user()
{
$code = I('co');
$mobile = I('mob');
$session_id = session_id();
$logic = new UsersLogic();
$stoid = getMobileStoId();
mlog("0", 'reg_user/' . $stoid);
$user9 = M('users')
->where('mobile', $mobile)
->where('store_id', getMobileStoId())->find();
if ($user9) {
//如果openid为空
if (empty($user9['openid'])) {
//手机本来有记录,直接更新openid
$update_replace['openid'] = $this->user['openid'];
$update_replace['nickname'] = $this->user['nickname'];
if ($this->user['head_pic']) {
$update_replace['head_pic'] = $this->user['head_pic'];
}
M('users')->where('user_id', $user9['user_id'])->save($update_replace);
M('users')->where('user_id', $this->user['user_id'])->delete();
$user9['openid'] = $this->user['openid'];
session('user', $user9); //覆盖session 中的 user
$this->user = $user9;
$this->user_id = $user9['user_id'];
Cookie::set('user_id', $this->user_id);
return array('status' => 1, 'msg' => "绑定成功");
} else {
if ($user9['erpvipid']) {
return array('status' => -1, 'msg' => "该手机号已经绑定");
exit;
}
}
}
if (getMobileStoId() != "1") {
$check_code = $logic->check_validate_code($code, $mobile, $session_id);
if ($check_code['status'] != 1) {
return array('status' => -1, 'msg' => $check_code['msg']);
exit;
}
}
mlog("1", 'reg_user/' . $stoid);
$map = null;
// 成为分销商条件
$distribut_condition = tpCache('distribut.condition', $stoid);
$distribut_switch = tpCache('distribut.switch', $stoid);
if ($distribut_switch === 1 && $distribut_condition === 0 && $this->user['is_distribut'] == 0) // 本来要购买成为分销,后来商家改为直接注册就可以成为分销商进行更改
{
//判断分销可以注册的人数
$distr_num = M('store_distribut')->where('store_id', $stoid)->field('distribut_num')->find();
$count1 = M("users")->where('store_id', getMobileStoId())->where('is_distribut', 1)->count();
if ($distr_num['distribut_num'] > $count1) {
$map['is_distribut'] = 1;
$map['be_distribut_time'] = time();
$map['be_dis_condition'] = "直接购买成为分销商";
} else {
$is_out = M("store_module_endtime")
->where('store_id', getMobileStoId())
->where('type', 2)->find();
if (empty($is_out)) {
$yy = M('distri_price')->where('type', 0)->where('money', 0)->find();
$allnum = $yy['user_num'];
if ($allnum > $count1) {
$map['is_distribut'] = 1;
$map['be_distribut_time'] = time();
$map['be_dis_condition'] = "直接购买成为分销商";
}
}
}
}
$map = ['mobile' => $mobile];
$is_distri_rate = tpCache('distribut.is_distri_rate', $stoid); //分销商奖励
$is_invitation_rate = tpCache('distribut.is_invitation_rate', $stoid); //是否参与邀请送积分或代金券
//启动事务
Db::startTrans();
try {
$first_leader = Cookie::get('first_leader');//上级会员ID
if ($first_leader != "") {
$first_info = M('users')->where(array('user_id' => $first_leader, 'store_id' => $stoid))->find();
if ($first_info && $first_info['is_distribut'] == "1" ) {
$map['first_leader'] = $first_leader;
} else {
//往上找会员是否的分销商,
//如果是分销商则注册会员的 first_leader 就是此分销商
$first_info0 = M('users')->where(array('user_id' => $first_info['first_leader'], 'store_id' => $stoid))->find();
if ($first_info0 && $first_info0['is_distribut'] == "1" ) {
$map['first_leader'] = $first_info0['user_id'];
}
}
if ($map['first_leader']) {
$first_leader = M('users')->where("user_id", $map['first_leader'])->field("first_leader,second_leader")->find();
$map['second_leader'] = $first_leader['first_leader']; // 第一级推荐人
$map['third_leader'] = $first_leader['second_leader']; // 第二级推荐人
//他上线分销的下线人数要加1
M('users')->where(array('user_id' => $map['first_leader']))->setInc('underling_number');
M('users')->where(array('user_id' => $map['second_leader']))->setInc('underling_number');
M('users')->where(array('user_id' => $map['third_leader']))->setInc('underling_number');
} else {
$map['first_leader'] = 0;
}
}
mlog("6", 'reg_user/' . $stoid);
$rs = M("users")->where("user_id", $this->user_id)->save($map);
$user_info['api_token'] = tpCache('shop_info.api_token', $stoid);
$map['user_id']=$this->user_id;
$news_info = $map;
$is_distri_rate = tpCache('distribut.is_distri_rate', $stoid); //分销商奖励
$is_invitation_rate = tpCache('distribut.is_invitation_rate', $stoid); //是否参与邀请送积分或代金券
mlog("7", 'reg_user/' . $stoid);
//邀请赠送积分
if (!empty($first_info) &&
!empty($first_info['mobile']) &&
!empty($first_info['erpvipid'])
) { //如果上级会员是绑定,说明是通过链接进来,给发链接的用户赠送积分、优惠券
/*---当上级不是分销商 或者 开启分销商奖励,参与邀请送积分或代金券---*/
if ($first_info['is_distribut'] == 0 || $is_distri_rate == 0 || ($is_invitation_rate == 1 && $is_distri_rate == 1)) {
mlog("701", 'reg_user/' . $stoid);
$inv_type = tpCache('basic.inv_type', $stoid);
$inv_info = tpCache('basic.invitation_rate', $stoid);
mlog("703" . $inv_info, 'reg_user/' . $stoid);
$invitation_rate = json_decode($inv_info, true);
/*--当上级的会员是绑定了的--*/
if ($inv_type == 0) { //邀请送积分
if ($invitation_rate['inv_jf'] != "") {
/*---
$data = array(
'Id' => $first_info["erpvipid"],//会员id
'Integral' => $invitation_rate['inv_jf'],//金额
'Remark' => '邀请送积分',
);
$add_rs = getApiData("wxd.vip.addreduce", $user_info['api_token'], array($data));
mlog("711邀请送积分:" . json_encode($data) . "返回:" . $add_rs, 'smslog/' . $stoid);
$add_rs = json_decode($add_rs, true);
if ($add_rs['code'] != 1) {
// return json(array('status' => -1, 'msg' => '服务器繁忙, 请联系管理员!'));
}--*/
$accdb=tpCache("shop_info.ERPId",$stoid);
com_update_integral($accdb,$first_info,$invitation_rate['inv_jf'],"邀请送积分",$module="mobile/cart");
}
} else {
if ($invitation_rate['inv_coupon'] != "") {
mlog("72", 'reg_user/' . $stoid);
$coupon = M("coupon")->where("id", $invitation_rate['inv_coupon'])->find();
if ($coupon["send_end_time"] > time()) {
$CashRepNo = "1005" . date("ymdHis") . get_total_millisecond();
$data = array(
'CashRepNo' => $CashRepNo,//券号
'VIPId' => $first_info["erpvipid"],//会员id
'Sum' => $coupon["money"],//金额
'SendMan' => '邀请发放',//发放类型
'Operator' => '微信商城',//来源
'BuySum' => $coupon["condition"],//满多少才能使用
'Remark' => '邀请送微券【消费满' . $coupon["condition"] . '元可用】',
);
if ($coupon['useobjecttype'])
{
$data['UseObjectType']=$coupon['useobjecttype'];
$data['UseObjectID']=$coupon['useobjectid'];
$data['UseObjectNo']=$coupon['useobjectno'];
$data['UseObjectName']=$coupon['useobjectname'];
}
if ($coupon["use_start_time"] != "") {
$data['BeginDate'] = date('Y-m-d', $coupon["use_start_time"]);//使用开始日期
}
if ($coupon["use_end_time"] != "") {
$data['ValidDate'] = date('Y-m-d', $coupon["use_end_time"]);//截止期限
}
$erp=tpCache("shop_info.ERPId",$stoid);
$add_rs = getApiData_java_p("/api/erp/vip/cash/insert", $erp, array($data),null, null, null, "POST");
$add_rs = json_decode($add_rs, true);
if ($add_rs['code'] != 1) {
// return json(array('status' => -1, 'msg' => '服务器繁忙, 请联系管理员!'));
}
$colorlist = urlencode("#FF0000|#173177|#173177|#173177|#173177|#173177|#FF0000|#ca003a");
$pd['typeid'] = "1006";
$pd['backurl'] = curHostURL() . '/index.php/Mobile/User/coupon/stoid/' . $stoid;
$pd['colorlist'] = $colorlist;
$pd['title'] = "您好,恭喜您成功领取" . $coupon["money"] . "元优惠券";
$pd['key1'] = $first_info['vipname'];
$pd['key2'] = $coupon["money"] . "元优惠券";
$pd['key3'] = date("Y-m-d");
$pd['remark'] = "点击详情查看优惠券详情信息";
$Event = \think\Loader::controller('home/Api');
$Event->web_poswxcode($pd, $stoid, $first_info);
}
}
}
}
}
$wx_user = M('wx_user')->where('store_id', $stoid)->find();
$jssdk = new \app\mobile\logic\Jssdk($wx_user['appid'], $wx_user['appsecret']);
mlog("7.1", 'reg_user/' . $stoid);
/*---当是分销商 且 开启分销商奖励---*/
if ($is_distri_rate == 1) {
mlog("7.1.1", 'reg_user/' . $stoid);
$ydd_str = tpCache('distribut.invitation_ratelist', $stoid);
$ydd = json_decode($ydd_str, true);
// 一级 分销商赚 的钱
if ($ydd['first_money'] > 0 && $first_info['is_distribut'] == 1) {
// 微信推送消息
$tmp_user = $first_info;
$rrs1 = $this->add_user_money($ydd['first_money'], $first_info['user_id']);
if ($rrs1) {
$odata['user_id'] = $first_info['user_id'];
$odata['create_time'] = time();
$odata['money'] = $ydd['first_money'];
$odata['remark'] = "线下一级注册";
$odata['store_id'] = $stoid;
$odata['order_sn'] = "zc" . date("YmdHis") . rand(1000, 9999);
$odata['status'] = 1;
$odata['type'] = 4;
M('withdrawals')->save($odata);
if ($tmp_user['oauth'] == 'weixin') {
$wx_content = "你的一级下线刚刚绑定,你获得 ¥" . $ydd['first_money'] . "奖励 !";
$first_res = $jssdk->push_msg($tmp_user['openid'], $wx_content);
mlog($news_info['mobile'] . "的一级[" . $first_res['mobile'] . "]推送返回:" . json_encode($first_res), 'reg_user/' . $stoid);
}
}
}
mlog("7.1.2", 'reg_user/' . $stoid);
// 二级 分销商赚 的钱
if ($news_info['second_leader'] > 0 && $ydd['second_money'] > 0) {
$fuid2 = M('users')->where('store_id=' . $stoid . ' and user_id=' . $news_info['second_leader'])->find();
if ($fuid2 && $fuid2['is_distribut'] == 1) {
$rrs2 = $this->add_user_money($ydd['second_money'], $fuid2['user_id']);
if ($rrs2) {
$odata['user_id'] = $fuid2['user_id'];
$odata['create_time'] = time();
$odata['money'] = $ydd['second_money'];
$odata['remark'] = "线下二级注册";
$odata['store_id'] = $stoid;
$odata['order_sn'] = "zc" . date("YmdHis") . rand(1000, 9999);
$odata['status'] = 1;
$odata['type'] = 4;
M('withdrawals')->save($odata);
// 微信推送消息
$tmp_user = $fuid2;
if ($tmp_user['oauth'] == 'weixin') {
$wx_content = "你的二级下线刚刚绑定,你获得 ¥" . $ydd['second_money'] . "奖励 !";
$second_res = $jssdk->push_msg($tmp_user['openid'], $wx_content);
mlog($news_info['mobile'] . "的二级[" . $tmp_user['mobile'] . "]推送返回:" . json_encode($second_res), 'reg_user/' . $stoid);
}
}
}
}
mlog("7.1.3", 'reg_user/' . $stoid);
// 三级 分销商赚 的钱
if ($news_info['third_leader'] > 0 && $ydd['third_money'] > 0) {
$fuid3 = M('users')->where('store_id=' . $stoid . ' and user_id=' . $news_info['third_leader'])->find();
if ($fuid3 && $fuid3['is_distribut'] == 1) {
$rrs3 = $this->add_user_money($ydd['third_money'], $fuid3['user_id']);
if ($rrs3) {
$odata['user_id'] = $fuid3['user_id'];
$odata['create_time'] = time();
$odata['money'] = $ydd['third_money'];
$odata['remark'] = "线下三级注册";
$odata['store_id'] = $stoid;
$odata['order_sn'] = "zc" . date("YmdHis") . rand(1000, 9999);
$odata['status'] = 1;
$odata['type'] = 4;
M('withdrawals')->save($odata);
// 微信推送消息
$tmp_user = $fuid3;
if ($tmp_user['oauth'] == 'weixin') {
$wx_content = "你的三级下线刚刚绑定,你获得 ¥" . $ydd['third_money'] . "奖励 !";
$third_res = $jssdk->push_msg($tmp_user['openid'], $wx_content);
mlog($news_info['mobile'] . "的三级[" . $tmp_user['mobile'] . "]推送返回:" . json_encode($third_res), 'reg_user/' . $stoid);
}
}
}
}
mlog("7.1.4", 'reg_user/' . $stoid);
}
mlog("7.3", 'reg_user/' . $stoid);
Db::commit();
return array('status' => 1, 'msg' => "绑定成功");
}catch (\Exception $e){
Db::rollback();
mlog("err-".json_encode($e), 'reg_user/' . $stoid);
return array('status' => -1, 'msg' => "绑定失败");
}
}
/*---循环更新订单的状态---*/
public function updatecart2()
{
$tocart = I("state");
if ($tocart == 0) {
$result = $this->cartLogic->cartList($this->user, $this->session_id, 1, 1); //获取购物车商品
} else if ($tocart == 1) {
$result = $this->cartLogic->gobuyList($this->user, $this->session_id); //获取立即购买的商品
} else if ($tocart == 2) {
$result = $this->cartLogic->gointeList($this->user, $this->session_id); //获取积分购的商品
}
return "1";
}
/*----增加会员的余额----*/
public function add_user_money($addmoney,$user_id){
$rs=M('users')->where('user_id',$user_id)->setInc('user_money',$addmoney);
return $rs;
}
/*----相应的返回redis----*/
public function backredis($no,$notime)
{
if ($_REQUEST['act'] == 'submit_order') {
$popvalue = null;
$popvalue2 = null;
$stoid = I("stoid");
//拼单有关
$ispt = I('is_pt');
$pdid = I('pdid');
$team_qh = I('team_qh');
$pdgoodsnum = I('pdgoodsnum/d', 0);
$sd = I('da');
if (!empty($sd)) {
$skillarray = json_decode($sd, true);
foreach ($skillarray as $lk => $lv) {
//$name = 'ms' . $lv['fid'] . '-' . $stoid;
$name =get_redis_name($lv['fid'],1, $stoid);
$num0 = $lv['num'];
//秒杀队列控制
for ($i = 0; $i < $num0; $i++) {
$this->redis->lPush($name, time() . '_' . $i);
}
$key=$no.'-1-'.$lv['fid'].'-'.$num0.'-'.$notime;
$p_name=get_redis_set_name($stoid);
$this->redis->sRem($p_name,$key);
}
}
//如果是拼单
if ($ispt) {
//$name = 'pind' . $pdid . '-' . $stoid;
$name = get_redis_name($pdid,6,$stoid);
//拼单队列控制
for ($i = 0; $i < $pdgoodsnum; $i++) {
$this->redis->lPush($name, time() . '_' . $i);
}
if ($team_qh && $ispt == '2') {
//$name2 = 'pind' . $pdid . '-' . $team_qh . $stoid;
$name2 = get_redis_name($pdid,6,$stoid). ':' . $team_qh ;
$this->redis->lPush($name2, time() . '_0' );
}
$key=$no.'-6-'.$pdid.'-'.$pdgoodsnum.'-'.$notime.'-'.$team_qh;
$p_name=get_redis_set_name($stoid);
$this->redis->sRem($p_name,$key);
}
}
}
/**
* 支付尾款的确认订单页面
*/
public function cart2_wk()
{
$ord=I("ordsn");
if ($this->user_id == 0)
$this->error('请先登录', U('Mobile/User/login', array('stoid' => getMobileStoId())));
$order=M('order')->where('order_sn',$ord)->find();
if(empty($order))
$this->error('未找到订单', U('Mobile/User/order_list', array('stoid' => getMobileStoId())));
/*--不能重复的一张表--*/
//$userd=M("users")->where('user_id',$this->user_id)->find();
$userd = $this->user;
$locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
$this->assign('u_money', number_format($userd['user_money'] - $userd['frozen_money'] - $locking_money, 2));
/*---获取地区---*/
$region_list = get_region_list();
$addlist = M('user_address')->where(['user_id' => $this->user_id])->select();
foreach ($addlist as $kk => $vv) {
$vv['provicename'] = $region_list[$vv['province']]['name'];
$vv['cityname'] = $region_list[$vv['city']]['name'];
$vv['districtname'] = $region_list[$vv['district']]['name'];
$vv['twonname'] = $region_list[$vv['twon']]['name'];
//$address = M('user_address')->where(['user_id'=>$this->user_id,'is_default'=>1])->find();
$addrstr = $vv['provicename'] . "-" . $vv['cityname'];
if (!empty($vv['district']))
$addrstr .= "-" . $vv['districtname'];
if (!empty($vv['twon']))
$addrstr = $addrstr . "-" . $vv['twonname'];
$vv['addrstr'] = $addrstr;
$addlist[$kk] = $vv;
}
$this->assign("addlist", $addlist);
$address_id = I('address_id/d');
if ($address_id) {
foreach ($addlist as $kk => $vv) {
if ($vv['address_id'] == $address_id) {
$address = $vv;
}
}
} else {
foreach ($addlist as $kk => $vv) {
if ($vv['is_default'] == 1) {
$address = $vv;
}
}
}
$p = M('region')->where(array('parent_id' => 0, 'level' => 1))->select();
$this->assign('province', $p);
if (empty($address)) {
//header("Location: ".U('Mobile/User/add_address',array('stoid'=>getMobileStoId(),'source'=>'cart2')));
$this->assign('setadd', 1);
} else {
$this->assign('address', $address);
$this->assign('setadd', 0);
}
/*--判断物流方式--*/
$listno=$order["pt_listno"];
$prom_id=$order['pt_prom_id'];
$pick_id=$order['pickup_id'];
$ord_goods=M('order_goods')->alias('a')->join('goods b','a.goods_id=b.goods_id')
->field('a.*,b.distr_type,b.original_img')
->where("a.order_id",$order["order_id"])
->find();
$pick=M('pick_up')->where('pickup_id',$pick_id)->field('pickup_name,distr_type')->find();
$exp2 = 0;
if($ord_goods['distr_type']==0){
$exp2=$pick['distr_type'];
}else{
$exp2= $ord_goods['distr_type'];
}
$this->assign("expty", $exp2);
$shippingList = M('store_shipping')->alias('a')->join("shipping b", "a.shipping_id=b.shipping_id")
->field('b.shipping_id,b.shipping_code,b.shipping_name,b.shipping_desc,b.shipping_logo')
->where("a.status=1 and a.store_id=" . getMobileStoId())->cache("shippingList_" . getMobileStoId(), TPSHOP_CACHE_TIME)
->select();//物流公司
$this->assign('goods', $ord_goods);
$this->assign('listno', $listno);
$this->assign('prom_id', $prom_id);
$this->assign('pick', $pick);
$this->assign('ordsn', $ord);
$this->assign('order', $order);
$this->assign('shippingList', $shippingList); // 物流公司
//$this->assign('cartList', $result['cartList']); // 购物车的商品
upload_ylp_log('购物车已选商品显示');
return $this->fetch('', getMobileStoId());
}
//------计算尾款金额--------
public function cart3_wk(){
/*--物流方式--*/
$stoid = I("stoid");
$ord=I("ordsn");
$listno=I("listno");
$prom_id=I('prom_id');
$is_ajax=I('is_ajax');
$shipping_code = I("shipping_code"); // 物流编号
if ($this->user_id == 0)
exit(json_encode(array('status' => -100, 'msg' => "登录超时请重新登录!", 'result' => null))); // 返回结果状态
$address_id = I("address_id"); //收货地址id
$setadd = I("setadd");
$exparr= I('exparr');//获取物流配送数组
$user_money = I("user_money", 0); // 使用余额
$user_money = str_replace(',', '', $user_money);
$user_money = doubleval($user_money);
$v=M('teamgroup')
->where('team_id',$prom_id)->where("listno",$listno)
->where('team_type',3)->where('store_id',$stoid)
->find();
$jsarr=json_decode($v['jt_json'],true);
$count=$v['jt_ct_num'];
//---要进行计算物流的钱---
$shipping_price=0;
$order=M("order")->where('order_sn',$ord)
->where('store_id',$stoid)
->field('order_amount,user_money,order_id')->find();
//要计算尾款的价钱
$price=0;
foreach ($jsarr as $ko=>$vo){ if($count>=$vo['rynum']) $price=$vo['price'];}
$num= M('order_goods')->where('order_sn',$ord)->sum('goods_num');
$tail_money=$price*$num-$order['order_amount']-$order['user_money'];
$ord_goods=M('order_goods')->alias('a')->join('goods b','a.goods_id=b.goods_id')
->field('a.goods_num,b.weight,b.is_free_shipping,b.exp_sum_type,b.uniform_exp_sum')
->where("a.order_sn",$ord)
->find();
//如果商品不是包邮的,且不是自提
$isfeelexp = $ord_goods['is_free_shipping'];$goods_weight=-1;$goods_piece=-1;
if($isfeelexp==0) {
switch ($ord_goods['exp_sum_type']) {
case 1:
//统一运费
if (!empty($shipping_code))
$shipping_price = $ord_goods['uniform_exp_sum'];
break;
case 2:
if ($goods_weight < 0) $goods_weight = 0;
//累积商品重量 每种商品的重量 * 数量
$goods_weight += $ord_goods['weight'] * $ord_goods['goods_num'];
break;
case 3:
if ($goods_piece < 0) $goods_piece = 0;
//累积商品数量
$goods_piece += $ord_goods['goods_num'];
break;
}
}
$freight_free = tpCache('shopping.freight_free',$stoid); // 全场满多少免运费
$cartLogic = new \app\home\logic\CartLogic();
$province=$city=$district=$twon=0;
if($address_id){
$address = M('UserAddress')->where("address_id", $address_id)->find();
$province=$address['province'];
$city=$address['city'];
$district=$address['district'];
$twon=$address['twon'];
}
//---自提和全场包邮---
if ($exparr == 1){
$shipping_price = 0;
}else if (!empty($shipping_code[0]) && !empty($province)) {
if ($goods_weight > -1)
$shipping_price += $cartLogic->cart_freight2($shipping_code, $province, $city, $district, $goods_weight, $stoid);
if ($goods_piece > -1)
$shipping_price += $cartLogic->cart_piece2($shipping_code, $province, $city, $district, $goods_piece, $stoid);
}
//---还有一个包邮模板---
$wuliu = $tail_money;
if($freight_free > 0 && $wuliu >= $freight_free &&$shipping_price>0 ){
$no_ex_id=tpCache('shopping.no_ex_id',$stoid);
if($no_ex_id) {
//判断是否包邮
$is_by = $cartLogic->isby2($province, $city, $district, $no_ex_id);
if($is_by==1) $shipping_price=0;
}else{
$shipping_price=0;
}
}
$all_money=$price*$num+$shipping_price-$order['order_amount']-$order['user_money'];
if($is_ajax){
if($exparr==0 && empty($address_id))
return json(['code' => -1, 'msg' => "请选择收货地址"]);
$save_data=['pt_tail_money'=>$all_money,
'province'=>$province,
'city'=>$city,
'district'=>$district,
'twon'=>$twon,
];
if($exparr==0){
$save_data['consignee']=$address["consignee"];
$save_data['address']=$address["address"];
$save_data['more_address']=$address["more_address"];
$save_data['exp_type']=0;
$save_data['shipping_price']=$shipping_price;
$save_data['shipping_code']=$shipping_code;
$rs=M('shipping')->where('shipping_code',$shipping_code)->field("shipping_name")->find();
$save_data['shipping_name']=$rs['shipping_name'];
}else{
$save_data['exp_type']=1;
$save_data['address']="";
$save_data['more_address']="";
$save_data['shipping_price']=0;
}
M('order')->where('order_id',$order['order_id'])
->save($save_data);
}
return json(['code'=>0,'tmoney'=>$tail_money,'tprice'=>$price,"cnum"=>$count,
'shipping_price'=>$shipping_price,'all_money'=>$all_money]);
}
public function com_prom_goods($cart_goods){
$prom_goods=null;
//--建立优惠促销数组--
foreach ($cart_goods as $k => $value) {
if ($value['prom_type'] == 3 && $value['is_gift'] == 0 && $value['is_collocation'] == 0) {
$pro=M("prom_goods")->where("id",$value['prom_id'])->field('is_bz,is_xz_yh')->find();
//要重新计算等级美妆价
$prom_goods[$value['pick_id']][$value['prom_id']]['num'] += $value['goods_num'];
$prom_goods[$value['pick_id']][$value['prom_id']]['price'] += $value['goods_num'] * $value['goods_price'];
$prom_goods[$value['pick_id']][$value['prom_id']]['goods'][$value['goods_id']] =['goods_id'=> $value['goods_id'], 'all_price'=> $value['goods_num'] * $value['goods_price']];
$prom_goods[$value['pick_id']][$value['prom_id']]['is_bz']=$pro['is_bz'];
$prom_goods[$value['pick_id']][$value['prom_id']]['is_xz_yh']=$pro['is_xz_yh'];
}
}
if(empty($prom_goods)) return null;
//--平摊实际优惠金额--
foreach ($prom_goods as $kk => $vv) {
foreach ($vv as $key => $val) {
$prom = discount($val['price'], $key, $val['num'], $this->user_id,$val['is_bz']);
$prom_goods[$kk][$key]['prom_price']=$prom['price'];
if($val['is_xz_yh']) continue;
if($prom['price']<=0) continue;
//--平摊金额到商品---
$per=$prom['price']/$val['price'];
$goods=$val['goods'];
$prom_all=0;
foreach ($goods as $kl0=>$vl0){
$fect= floor($vl0['all_price']*$per*100)/100;
$prom_goods[$kk][$key]['goods'][$kl0]['fect_price']=$fect;
$prom_all+=$fect;
}
//有余数
$yushu=$prom['price']-$prom_all;
$prom_goods[$kk][$key]['goods'][0]['fect_price']+=$yushu;
}
}
return $prom_goods;
}
//组装list 商品ID和金额计算代金券
public function com_package($vv,$v,$wlist,$sumlist,$prom_goods){
$list_item=null;
if ($v['pick_id'] == $vv['pickup_id']) {
$list_item = $vv;
//---是否连接判断商品参与优惠券优惠---
$is_conect=1;
$fect_price=$vv['goods_price'];
$goods_num=$vv['goods_num'];
//---优惠活动----
if($vv['prom_type']==3){
if($prom_goods[$vv['pick_id']][$vv['prom_id']]['is_xz_yh']) $is_conect=0;
if($prom_goods[$vv['pick_id']][$vv['prom_id']]['prom_price']<=0) $is_conect=0;
}
//----------团购是否可以使用优惠券-----
else if($vv['prom_type']==2){
$t = time();
$gb = M('group_buy')->where('store_id', getMobileStoId())
->where('id', $vv['prom_id'])
->where('start_time<' . $t)
->where('end_time>' . $t)->where('is_end', 0)
->field('is_quan')
->find();
if ($gb) {
if ($gb['is_quan'] ==0 ) $is_conect=0;
}
}
//----秒杀商品----
else if($vv['prom_type']==1) {$is_conect=0;}
//循环组装商品ID,金额
if($vv['is_gift']!=1 && $is_conect==1) {
$wlist .= $vv['erpwareid'] .",";
//$sumlist .= ($vv['goods_price'] * $vv['goods_num']) . ",";
//去除实际价格
$cut_price=$prom_goods[$vv['pick_id']][$vv['prom_id']]['goods'][$vv['goods_id']]['fect_price'];
if($cut_price)
$sumlist .= ($cut_price) . ",";
else
$sumlist .= ($fect_price* $vv['goods_num']) . ",";
}
}
return ['list'=>$list_item,'wlist'=>$wlist,'sumlist'=>$sumlist];
}
}