Goods.php
133 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
<?php
/**
* tpshop
* ============================================================================
* 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* Author: IT宇宙人
* Date: 2015-09-09
*/
namespace app\admin\controller;
use app\admin\logic\GoodsLogic;
use think\AjaxPage;
use think\Page;
use think\Db;
use qcloudcos\Conf;
use qcloudcos\Myqcloudcos;
class Goods extends Base
{
/**
* 商品分类列表
*/
public function categoryList()
{
$GoodsLogic = new GoodsLogic();
$cat_list = $GoodsLogic->goods_cat_list();
$impotr=M('import_active')->where(['store_id'=>getAdmStoId(),'state'=>1,'type'=>101])->find();
$this->assign('import',$impotr);
$this->assign('cat_list', $cat_list);
// upload_ylp_log('商品分类');
return $this->fetch('', getAdmStoId());
}
/**
* 添加修改商品分类
* 手动拷贝分类正则 ([\u4e00-\u9fa5/\w]+) ('393','$1'),
* select * from tp_goods_category where id = 393
* select * from tp_goods_category where parent_id = 393
* update tp_goods_category set parent_id_path = concat_ws('_','0_76_393',id),`level` = 3 where parent_id = 393
* insert into `tp_goods_category` (`parent_id`,`name`) values
* ('393','时尚饰品'),
*/
public function addEditCategory()
{
$stoid=getAdmStoId();
$this->assign('erpid', getERPId());
$this->assign('curid', '0');
$GoodsLogic = new GoodsLogic();
if (IS_GET) {
$goods_category_info = D('goods_category')->where(' store_id=' . getAdmStoId() . ' and id=' . I('GET.id', 0))->find();
// var_dump($goods_category_info);
// die();
$level_cat = $GoodsLogic->find_parent_cat($goods_category_info['id']); // 获取分类默认选中的下拉框
$cat_list = M('goods_category')->where(" store_id=" . getAdmStoId() . " and parent_id = 0")->order('sort_order')->select(); // 已经改成联动菜单
$this->assign('level_cat', $level_cat);
$this->assign('cat_list', $cat_list);
if ($goods_category_info['id'] != "") {
$this->assign('curid', $goods_category_info['id']);
}
$m = Db::query("select max(sort_order)odr from __PREFIX__goods_category where store_id=" . getAdmStoId());
$md = (int)$m[0]["odr"];
$md++;
if (empty($goods_category_info)) {
$goods_category_info["sort_order"] = $md;
$goods_category_info['status']=1;
}
$this->assign('goods_category_info', $goods_category_info);
return $this->fetch('_category', getAdmStoId());
exit;
}
$GoodsCategory = D('GoodsCategory'); //
$type = I('id') > 0 ? 2 : 1; // 标识自动验证时的 场景 1 表示插入 2 表示更新
//ajax提交验证
if (I('is_ajax') == 1) {
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
// 数据验证
$validate = \think\Loader::validate('GoodsCategory');
if (!$validate->batch()->check(input('post.'))) {
$error = $validate->getError();
$error_msg = array_values($error);
$return_arr = array(
'status' => -1,
'msg' => $error_msg[0],
'data' => $error,
);
$this->ajaxReturn($return_arr);
} else {
// 收集数据
$GoodsCategory->data(input('post.'), true);
$GoodsCategory['store_id'] = $stoid;
$GoodsCategory['commission_rate'] = 0;
if ($GoodsCategory['imgtype'] == 0) {
$GoodsCategory['image'] = I('image');
} else {
$GoodsCategory['image'] = I('httimg');
}
$GoodsCategory->parent_id = I('parent_id_1');
input('parent_id_2') && ($GoodsCategory->parent_id = input('parent_id_2'));
//编辑判断
if ($type == 2) {
$children_where = array(
'parent_id_path' => array('like', '%_' . I('id') . "_%")
);
$children = M('goods_category')->where('store_id',getAdmStoId())->where($children_where)->max('level');
if (I('parent_id_1')) {
$parent_level = M('goods_category')->where(array('store_id'=>getAdmStoId(),'id' => I('parent_id_1')))->getField('level', false);
if (($parent_level + $children) > 3) {
$return_arr = array(
'status' => -1,
'msg' => '商品分类最多为三级',
'data' => '',
);
$this->ajaxReturn($return_arr);
}
}
if (I('parent_id_2')) {
$parent_level = M('goods_category')->where(array('store_id'=>getAdmStoId(),'id' => I('parent_id_2')))->getField('level', false);
if (($parent_level + $children) > 3) {
$return_arr = array(
'status' => -1,
'msg' => '商品分类最多为三级',
'data' => '',
);
$this->ajaxReturn($return_arr);
}
}
}
if ($GoodsCategory->id > 0 && $GoodsCategory->parent_id == $GoodsCategory->id) {
// 编辑
$return_arr = array(
'status' => -1,
'msg' => '上级分类不能为自己',
'data' => '',
);
$this->ajaxReturn($return_arr);
}
if ($GoodsCategory->commission_rate > 100) {
// 编辑
$return_arr = array(
'status' => -1,
'msg' => '分佣比例不得超过100%',
'data' => '',
);
$this->ajaxReturn($return_arr);
}
$rt=M("admin")->where('admin_id',getAdminId())->field('ERPUser')->find();
if ($type == 2) {
$GoodsCategory['edit_time'] = time();
$GoodsCategory['edit_ip'] = getIP();
$GoodsCategory['edit_man'] = $rt['ERPUser'];
$GoodsCategory->isUpdate(true)->save(); // 写入数据到数据库
$GoodsLogic->refresh_cat(I('id'),$stoid);
upload_ylp_log('B01商品分类编辑/确认提交');
} else {
//$GoodsCategory['add_time'] = time();
//$GoodsCategory['edit_ip'] = getIP();
//$GoodsCategory['edit_man'] = $rt['ERPUser'];
//$GoodsCategory->save(); // 写入数据到数据库
//$insert_id = $GoodsCategory->getLastInsID(); 读写分离的情况是获取不到ID的
$data=input('post.');
$data['add_time'] = time();
$data['edit_ip'] = getIP();
$data['edit_man'] = $rt['ERPUser'];
$data['store_id'] = $stoid;
$data['commission_rate'] = 0;
if ($data['imgtype'] == 0) { $data['image'] = I('image'); } else {$data['image'] = I('httimg');}
$data['parent_id'] = I('parent_id_1');
input('parent_id_2') && ($data['parent_id'] = input('parent_id_2'));
$insert_id = M("goods_category")->insertGetId($data);
$GoodsLogic->refresh_cat($insert_id,$stoid);
}
$return_arr = array(
'status' => 1,
'msg' => '操作成功',
'data' => array('url' => U('Admin/Goods/categoryList')),
);
$this->ajaxReturn($return_arr);
}
}
}
/**
* 获取商品分类 的帅选规格 复选框
*/
public function ajaxGetSpecList()
{
$GoodsLogic = new GoodsLogic();
$_REQUEST['category_id'] = $_REQUEST['category_id'] ? $_REQUEST['category_id'] : 0;
$filter_spec = M('GoodsCategory')->where("id = " . $_REQUEST['category_id'])->getField('filter_spec');
$filter_spec_arr = explode(',', $filter_spec);
$str = $GoodsLogic->GetSpecCheckboxList($_REQUEST['type_id'], $filter_spec_arr);
$str = $str ? $str : '没有可帅选的商品规格';
exit($str);
}
/**
* 获取商品分类 的帅选属性 复选框
*/
public function ajaxGetAttrList()
{
$GoodsLogic = new GoodsLogic();
$_REQUEST['category_id'] = $_REQUEST['category_id'] ? $_REQUEST['category_id'] : 0;
$filter_attr = M('GoodsCategory')->where("id = " . $_REQUEST['category_id'])->getField('filter_attr');
$filter_attr_arr = explode(',', $filter_attr);
$str = $GoodsLogic->GetAttrCheckboxList($_REQUEST['type_id'], $filter_attr_arr);
$str = $str ? $str : '没有可帅选的商品属性';
exit($str);
}
/**
* 删除分类
*/
public function delGoodsCategory()
{
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
$id = $this->request->param('id');
// 判断子分类
$GoodsCategory = M("goods_category");
$count = $GoodsCategory->where("parent_id = {$id}")
->where('store_id',getAdmStoId())->count("id");
$count > 0 && $this->error('该分类下还有分类不得删除!', U('Admin/Goods/categoryList'));
// 判断是否存在商品
$goods_count = M('Goods')->where(array('store_id'=>getAdmStoId(),'cat_id'=>$id))->count('1');
$goods_count > 0 && $this->error('该分类下有商品不得删除!', U('Admin/Goods/categoryList'));
//删除图片
$goods_search = D('goods_category')->where(array('store_id'=>getAdmStoId(),'id'=>$id))->find();
$delimg = $goods_search['image'];
if ($delimg) {
//删除腾讯云图片
vendor('qcloudcos.myqcloudcos');
//if(!empty($url)){
$rs = Myqcloudcos::delFile('wxd', $delimg);
mdelFile(ROOT_PATH . $delimg);
//}
//mdelFile(ROOT_PATH . $delimg);
}
// 删除分类
DB::name('goods_category')->where(array('store_id'=>getAdmStoId(),'id'=>$id))->delete();
$this->success("操作成功!!!", U('Admin/Goods/categoryList'));
}
/**
* 商品列表
*/
public function goodsList()
{
$key_word = I('key_word') ? trim(I('key_word')) : ''; // 关键词搜索
$intro = I('intro');//新品、推荐
$brand_id = I('brand_id');//品牌
$is_on_sale = I('is_on_sale');//上架、下架
$dis_type = I('dis_type');//分销类型
$iscontent = I('iscontent');//是否完善详情
if ($dis_type=="")
{
$dis_type=-1;
}
if ($is_on_sale=="")
{
$is_on_sale=1;
}
$cat_id = I('cat_id');//分类
$getp = I('p');
$pagenum = 10;//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
}
$order1 = I('order1/s');
$order2 = I('order2/s');
$GoodsLogic = new GoodsLogic();
$brandList = $GoodsLogic->getSortBrands();
$categoryList = $GoodsLogic->getSortCategory();
$oldurl = U('Admin/goods/goodsList', array(
"intro" => $intro,
"brand_id" => $brand_id,
"iscontent" => $iscontent,
"is_on_sale" => $is_on_sale,
"cat_id" => $cat_id,
"key_word" => $key_word,
"pagenum" => $pagenum,
"p" => $getp,
"order1" => $order1,
"order2" => $order2
));
$this->assign('oldurl', urlencode($oldurl));
$this->assign('key_word', $key_word);
$this->assign('iscontent', $iscontent);
$this->assign('intro', $intro);
$this->assign('dis_type', $dis_type);
$this->assign('brand_id', $brand_id);
$this->assign('is_on_sale', $is_on_sale == "" ? 2 : $is_on_sale);
$this->assign('cat_id',$cat_id);
$this->assign('brand_id',$brand_id);
$this->assign('pagenum', $pagenum);
$this->assign('cur_page', $getp);
$this->assign('order1', $order1);
$this->assign('order2', $order2);
$this->assign('categoryList', $categoryList);
$this->assign('brandList', $brandList);
return $this->fetch('', getAdmStoId());
}
/**
* 商品列表
*/
public function ajaxGoodsList()
{
$key_word = I('key_word') ? trim(I('key_word')) : ''; // 关键词搜索
$intro = I('intro');//新品、推荐
$brand_id = I('brand_id');//品牌
$is_on_sale = I('is_on_sale');//上架、下架
$dis_type = I('dis_type');//分销类型
$iscontent = I('iscontent');//是否完善详情
if ($is_on_sale == "") {
$is_on_sale = 1;
}
$exp_sum_type = I('exp_sum_type');//运费设置
$cat_id = I('cat_id');//分类
$cur_page = 1;//当前页数
if ((int)I('p/s') > 0) {
$cur_page = I('p/s');
}
$pagenum = 10;//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
}
$order1 = I('order1/s', "sort");
$order2 = I('order2/s', "asc");
$where = ' 1 = 1 '; // 搜索条件
$where .= " and store_id=" . getAdmStoId();
if ($intro) {
switch ($intro) {
case "is_new":
$where .= " and is_new=1";
break;
case "is_recommend":
$where .= " and is_recommend=1";
break;
case "is_hot":
$where .= " and is_hot=1";
break;
case "promtype1":
$where .= " and prom_type=1";
break;
case "promtype2":
$where .= " and prom_type=2";
break;
case "promtype3":
$where .= " and prom_type=3";
break;
case "promtype4":
$where .= " and prom_type=4";
break;
case "promtype6":
$where .= " and prom_type=6";
break;
default:
break;
}
}
$brand_id && $where = "$where and brand_id = " . $brand_id; //品牌
$time = time();
switch ($dis_type) {
case "0":
$where .= " and dis_type=0";
break;
case "1":
$where .= " and dis_type=1";
break;
default:
break;
}
switch ($iscontent) {
case 1:
$where .= " and goods_content=''";
break;
case 2:
$where .= " and goods_content<>'' ";
break;
default:
break;
}
//上架、下架
switch ($is_on_sale) {
case "0":
$where .= " and (on_time>" . $time . " or down_time<" . $time . " and down_time !='') ";
break;
case "1":
$where .= " and is_on_sale=1 and on_time<" . $time . " and (down_time>" . $time . " or down_time=0 or down_time='' or down_time is null) ";
break;
default:
break;
}
if ($exp_sum_type > 0) {
$where .= " and exp_sum_type=" . $exp_sum_type;
}
if ($key_word) {
$where = "$where and (goods_name like '%$key_word%' or goods_sn like '%$key_word%' or keywords like '%$key_word%' or sku like '%$key_word%')";
}
if ($cat_id > 0) {
$grandson_ids = getCatGrandson($cat_id);
$where .= " and cat_id in(" . implode(',', $grandson_ids) . ") "; // 初始化搜索条件
}
$model = M('Goods');
$count = $model->where($where)->count();
$countstr = $model->where($where)->fetchSql(true)->count();
$Page = new AjaxPage($count, $pagenum);
$show = $Page->show();
$order_str = "`$order1` $order2";
$goodsList = $model->where($where)->order($order_str)->limit($Page->firstRow . ',' . $Page->listRows)->select();
//判断是否上架
$t = time();
foreach ($goodsList as $kr => $vr) {
if ($vr['on_time'] < $t && ($vr['down_time'] > $t || $vr['down_time'] == "") && $vr['is_on_sale'] == 1) {
$goodsList[$kr]['is_on'] = 1;
}
}
$catList = D('goods_category')->where(" store_id=" . getAdmStoId())->select();
$catList = convert_arr_key($catList, 'id');
$this->assign('catList', $catList);
$this->assign('goodsList', $goodsList);
$this->assign('page', $show);// 赋值分页输出
$this->assign('pager', $Page);
$this->assign('pagenum', $pagenum);
// $GoodsLogic = new GoodsLogic();
// $brandList = $GoodsLogic->getSortBrands();
// $categoryList = $GoodsLogic->getSortCategory();
$oldurl = U('Admin/goods/goodsList', array(
"intro" => $intro,
"brand_id" => $brand_id,
"is_on_sale" => $is_on_sale,
"cat_id" => $cat_id,
"key_word" => $key_word,
"pagenum" => $pagenum,
"p" => $cur_page,
"order1" => $order1,
"order2" => $order2
));
$this->assign('oldurl', urlencode($oldurl));
$this->assign('key_word', $key_word);
$this->assign('intro', $intro);
$this->assign('brand_id', $brand_id);
$this->assign('is_on_sale', $is_on_sale);
$this->assign('cat_id', $cat_id);
$this->assign('pagenum', $pagenum);
$this->assign('cur_page', $cur_page);
$this->assign('order1', $order1);
$this->assign('order2', $order2);
// $this->assign('categoryList', $categoryList);
// $this->assign('brandList', $brandList);
$this->assign('store_warning_storage', tpCache('basic.warning_storage', getAdmStoId()));
// upload_ylp_log('商品管理');
return $this->fetch('', getAdmStoId());
}
public function exportreport()
{
$pattern = tpCache('distribut.pattern', getAdmStoId());
$key_word = I('key_word') ? trim(I('key_word')) : ''; // 关键词搜索
$intro = I('intro');//新品、推荐
$brand_id = I('brand_id');//品牌
$is_on_sale = I('is_on_sale');//上架、下架
$cat_id = I('cat_id');//分类
$dis_type = I('dis_type');//分销类型
$exp_sum_type = I('exp_sum_type');//运费设置
$cur_page = 1;//当前页数
if ((int)I('p/s') > 0) {
$cur_page = I('p/s');
}
$pagenum = 10;//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
}
$order1 = I('order1/s', "goods_id");
$order2 = I('order2/s', "desc");
$where = ' 1 = 1 '; // 搜索条件
$where .= " and a.store_id=" . getAdmStoId();
if ($intro) {
switch ($intro) {
case "is_new":
$where .= " and is_new=1";
break;
case "is_recommend":
$where .= " and is_recommend=1";
break;
case "is_hot":
$where .= " and is_hot=1";
break;
case "promtype1":
$where .= " and prom_type=1";
break;
case "promtype2":
$where .= " and prom_type=2";
break;
case "promtype3":
$where .= " and prom_type=3";
break;
case "promtype4":
$where .= " and prom_type=4";
break;
case "promtype6":
$where .= " and prom_type=6";
break;
default:
break;
}
}
$brand_id && $where = "$where and a.brand_id = " . $brand_id; //品牌
$time = time();
switch ($dis_type) {
case "0":
$where .= " and dis_type=0";
break;
case "1":
$where .= " and dis_type=1";
break;
default:
break;
}
//上架、下架
switch ($is_on_sale) {
case "0":
$where .= " and (on_time>" . $time . " or down_time<" . $time . " and down_time !='') ";
break;
case "1":
$where .= " and is_on_sale=1 and on_time<" . $time . " and (down_time>" . $time . " or down_time=0 or down_time='' or down_time is null) ";
break;
default:
break;
}
if ($exp_sum_type > 0) {
$where .= " and exp_sum_type=" . $exp_sum_type;
}
if ($key_word) {
$where = "$where and (a.goods_name like '%$key_word%' or a.goods_sn like '%$key_word%' or a.keywords like '%$key_word%')";
}
if ($cat_id > 0) {
$grandson_ids = getCatGrandson($cat_id);
$where .= " and a.cat_id in(" . implode(',', $grandson_ids) . ") "; // 初始化搜索条件
}
$order_str = "`$order1` $order2";
$goodsList = M('Goods')->alias('a')->join('goods_category b', 'a.cat_id=b.id and a.store_id=b.store_id', 'left')
->join('brand c', 'a.brand_id=c.id', 'left')
->join('nation d', 'a.nation_id=d.id', 'left')
->field('a.*,b.name as cat_name,c.name as brand_name,d.name as nation_name')
->where($where)->order($order_str)->select();
$catList = D('goods_category')->where(" store_id=" . getAdmStoId())->select();
//判断 是否开通等级卡
$is_cardstore = 0;
if (getERPId()) { //有ERP
$tk = M("store_config")->where("store_id", getAdmStoId())
->field("dj_num")->find();
if ($tk['dj_num'] > 0) {
$is_cardstore = 1;
}
}
$strTable = '<table border="1">';
$strTable .= '<tr style="font-weight: bold;">';
$strTable .= '<td style="text-align:center;width:120px;">商品名称</td>';
$strTable .= '<td style="text-align:center;" width="100">商品编号</td>';
$strTable .= '<td style="text-align:center;" width="100">商品条码</td>';
$strTable .= '<td style="text-align:center;" width="50">分类</td>';
$strTable .= '<td style="text-align:center;" width="50">品牌</td>';
$strTable .= '<td style="text-align:center;" width="50">国别</td>';
$strTable .= '<td style="text-align:center;" width="50">分销类型</td>';
$strTable .= '<td style="text-align:center;" width="50">商品重量</td>';
$strTable .= '<td style="text-align:center;" width="50">配送方式</td>';
$strTable .= '<td style="text-align:center;" width="50">佣金</td>';
$strTable .= '<td style="text-align:center;" width="80">市场价</td>';
$strTable .= '<td style="text-align:center;" width="80">手店价</td>';
if ($is_cardstore) {
$strTable .= '<td style="text-align:center;" width="80">售价(一)</td>';
$strTable .= '<td style="text-align:center;" width="80">售价(二)</td>';
$strTable .= '<td style="text-align:center;" width="80">售价(三)</td>';
}
$strTable .= '<td style="text-align:center;" width="50">库存数量</td>';
$strTable .= '<td style="text-align:center;" width="50">已售数量</td>';
$strTable .= '<td style="text-align:center;" width="150">商品标签</td>';
$strTable .= '</tr>';
if (is_array($goodsList)) {
foreach ($goodsList as $k => $val) {
$getpromname = "";
if ($val['prom_type']) {
switch ($val['prom_type']) {
case "1":
$getpromname = "秒杀商品";
break;
case "2":
$getpromname = "团购商品";
break;
case "3":
$getpromname = "促销优惠";
break;
case "4":
$getpromname = "积分购";
break;
case "6":
$getpromname = "天天拼单";
break;
default:
break;
}
}
$strTable .= '<tr>';
$strTable .= '<td style="text-align:left;"> ' . $val['goods_name'] . '</td>';
$strTable .= '<td style="text-align:left;"> ' . $val['goods_sn'] . ' </td>';
$strTable .= '<td style="text-align:left;"> ' . $val['sku'] . ' </td>';
$strTable .= '<td style="text-align:center;">' . $val['cat_name'] . '</td>';
$strTable .= '<td style="text-align:center;">' . $val['brand_name'] . ' </td>';
$strTable .= '<td style="text-align:center;">' . $val['nation_name'] . '</td>';
$strTable .= '<td style="text-align:center;">' . ($val['dis_type'] == '0' ? '主营' : '可选') . '</td>';
$strTable .= '<td style="text-align:center;">' . $val['weight'] . '克</td>';
$strTable .= '<td style="text-align:center;">' . ($val['distr_type'] == '0' ? '用户自选' : $val['distr_type'] == '1' ? '自提' : '物流') . '</td>';
$strTable .= '<td style="text-align:center;">' . ($pattern == '1' ? $val['fir_rate'] + $val['sec_rate'] + $val['thi_rate'] : $val['commission']) . '</td>';
$strTable .= '<td style="text-align:center;">' . $val['market_price'] . '</td>';
$strTable .= '<td style="text-align:center;">' . $val['shop_price'] . '</td>';
if ($is_cardstore) {
$strTable .= '<td style="text-align:center;">' . $val['cardprice1'] . '</td>';
$strTable .= '<td style="text-align:center;">' . $val['cardprice2'] . '</td>';
$strTable .= '<td style="text-align:center;">' . $val['cardprice3'] . '</td>';
}
$strTable .= '<td style="text-align:center;">' . $val['store_count'] . '</td>';
$strTable .= '<td style="text-align:center;">' . $val['sales_sum'] . '</td>';
$strTable .= '<td style="text-align:center;">' . ($val['is_recommend'] == '1' ? '【推荐】' : '') . ($val['is_new'] == '1' ? '【新品】' : '') . ($val['is_hot'] == '1' ? '【热卖】' : '') . '';
$strTable .= ($getpromname != '' ? '【' . $getpromname . '】' : '');
$strTable .= '</td>';
$strTable .= '</tr>';
}
}
$strTable .= '</table>';
echo $strTable;
unset($goodsList);
downloadExcel($strTable, 'goods');
exit();
}
//库存日志
public function stock_list()
{
$model = M('stock_log');
$map = array();
$mtype = I('mtype');
if ($mtype == 1) {
$map['stock'] = array('gt', 0);
}
if ($mtype == -1) {
$map['stock'] = array('lt', 0);
}
$goods_name = I('goods_name');
if ($goods_name) {
$map['goods_name'] = array('like', "%$goods_name%");
}
$stoid = getAdmStoId();
$map['store_id'] = $stoid;
$ctime = I('ctime');
if ($ctime) {
$gap = explode(' - ', $ctime);
$this->assign('start_time', $gap[0]);
$this->assign('end_time', $gap[1]);
$this->assign('ctime', $gap[0] . ' - ' . $gap[1]);
$map['ctime'] = array(array('gt', strtotime($gap[0])), array('lt', strtotime($gap[1])));
}
$count = $model->where($map)->count();
$Page = new Page($count, 20);
$show = $Page->show();
$this->assign('pager', $Page);
$this->assign('page', $show);// 赋值分页输出
$stock_list = $model->where($map)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
$this->assign('stock_list', $stock_list);
// if($stock_list){
// $uids = get_arr_column($stock_list,'store_id');
// $store = M('store')->where("store_id in (". implode(',', $uids).")")->getField('store_id,store_name');
// $this->assign('store',$store);
// }
return $this->fetch('stock_list', getAdmStoId());
}
/**
* 添加修改商品
*/
public function addEditGoods()
{
$oldurl = I('oldurl/s');
$sto_id = getAdmStoId();
if ($oldurl) {
$oldurl = urldecode(urldecode($oldurl));
}
$this->assign('oldurl', $oldurl);
$this->assign('erpid', getERPId());
$GoodsLogic = new GoodsLogic();
$water = tpCache('water', $sto_id);
$storeconfig=M('store_config')->where("store_id",getAdmStoId())->field('switch_list')->find();
$rank=json_decode($storeconfig['switch_list'],true);
$rank_switch = $rank['rank_switch'];//等级开关
$mz_switch = tpCache('shopping.is_beauty',$sto_id);//美妆开关
$this->assign('rank_switch',$rank_switch);
$this->assign('mz_switch',$mz_switch);
if ($water['is_mark'] == 1) {
if ($water['mark_type'] == 'img' ) {
if(!empty($water['mark_img'])) {
$imgpath = $water['mark_img'];
vendor('qcloudcos.myqcloudcos');
$resfolder = Myqcloudcos::stat('wxd', $imgpath);
if ($resfolder && $resfolder['code'] != 0)//不存在
{
$this->assign('isnowater',"1");
}
}else{
$this->assign('isnowater',"1");
}
}
}
$getsku=preg_replace('/\r|\n|\t/', '', I('sku',0));
$goods_list=null;
if($getsku)
$goods_list = M('goods')->where(['sku'=>$getsku,'store_id'=>$sto_id])->order('goods_id desc')->select();
$goodsInfo = array();
$goodsImages =array();
$goodsInfo['is_virtual']=0;
if(!empty($goods_list)){
$goodsInfo=$goods_list[0];
$goodsInfo['sku']=trim($goodsInfo['sku']);
$goodsInfo['goods_list']=$goods_list;
$goodsImages=M('goods_images')->where('goods_id',$goodsInfo['goods_id'])
->order('ismain desc,img_sort asc')->select();
$v_url = M('goods_videos')->where('goods_id', $goodsInfo['goods_id'])->order('video_sort desc')->select();
}
$level_cat = $GoodsLogic->find_parent_cat($goodsInfo['cat_id']); // 获取分类默认选中的下拉框
$level_cat2 = $GoodsLogic->find_parent_cat($goodsInfo['extend_cat_id']); // 获取分类默认选中的下拉框
$cat_list = M('goods_category')->where("parent_id = 0")->where('store_id',$sto_id)->select(); // 已经改成联动菜单
$brandList = $GoodsLogic->getSortBrands();
$nationList = $GoodsLogic->getSortNations();
$this->assign('level_cat', $level_cat);
$this->assign('level_cat2', $level_cat2);
$this->assign('cat_list', $cat_list);
$this->assign('brandList', $brandList);
$this->assign('nationList', $nationList);
$pattern=tpCache('distribut.pattern',getAdmStoId());
$this->assign('pattern', $pattern);
if (empty($goodsInfo)){
$goodsInfo['give_integral'] = 1;
}
if (empty($goodsInfo["exp_sum_type"])) {
$goodsInfo["exp_sum_type"] = 3;
}
if (empty($goodsInfo["on_time"])) {
$goodsInfo['on_time'] = time();
}
$mokun = tpCache('basic.default_storage', $sto_id);
$this->assign('mokun', $mokun); // 默认库存
$this->assign('goodsInfo', $goodsInfo); // 商品详情
$this->assign('goodsImages', $goodsImages); // 商品相册
$this->assign('v_url', $v_url); // 商品视频
$this->initEditor(); // 编辑器
return $this->fetch('_goods', getAdmStoId());
}
public function goods_handle()
{
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
$Goods = I('post.');
$Goods['sku'] = preg_replace('/\r|\n|\t/', '',trim($Goods['sku']));
$old_url = $Goods['oldurl'];
$goods_list = $Goods['data'];
$goods_img = $Goods['goods_images'];
$data_img=[];
array_pop($goods_img); // 弹出最后一个
unset($Goods['data']);
unset($Goods['oldurl']);
unset($Goods['goods_images']);
$sto_id = getAdmStoId();
$goods_video= $Goods['v_url'];
$video_img= $Goods['v_img'];
$up_video_id= $Goods['up_video_id'];
$data_img = []; //从表图片
$video_data=[]; //从表视频
//分类
$cat_id_3=I('cat_id_3');
$cat_id_2=I('cat_id_2');
$cat_id_1=I('cat_id');
$gcat_id=$cat_id_3;
if(empty($cat_id_3)){ $gcat_id=$cat_id_2; }
if(empty($cat_id_2)){$gcat_id=$cat_id_1;}
if(empty($cat_id_1)){
return json(['code' => -1, 'msg' => '请选择分类', 'url' => $old_url]);
}
/*---判断统一运费---*/
$Goods['is_free_shipping'] = 0;
$t = $Goods['exp_sum_type'];
/*--如果是统一运费--*/
if ($t == 1) {
if (empty($Goods['uniform_exp_sum'])) {
$Goods['uniform_exp_sum'] = 0;
}
/*--如果是统一运费等于0就是包邮--*/
if ($Goods['uniform_exp_sum'] <= 0) {
$Goods['is_free_shipping'] = 1;
}
}
$Goods['on_time'] = strtotime($Goods['on_time']);
$Goods['down_time'] = strtotime($Goods['down_time']);
$Goods['store_id'] = $sto_id;
$sort = M('goods')->where('store_id', $sto_id)->Max('sort');
$tk = tpCache('shop_info.api_token', getAdmStoId());
$c = 0;
foreach ($goods_list as $k => $v) {
$id = $v['goods_id'];
$Goods['erpwareid'] = $v['erpwareid'];
$Goods['goods_spec'] = $v['goods_spec'];
$Goods['goods_color'] = $v['goods_color'];
$Goods['goods_sn'] = $v['goods_sn'];
$Goods['market_price'] = $v['market_price'];
$Goods['shop_price'] = $v['shop_price'];
$Goods['mz_price'] = $v['mz_price'];
$Goods['store_count'] = $v['store_count'];
$Goods['sales_sum'] = $v['sales_sum'];
$Goods['viplimited'] = $v['viplimited'];
$Goods['weight'] = $v['weight'];
$Goods['cardprice1'] = $v['cardprice1'];
$Goods['cardprice2'] = $v['cardprice2'];
$Goods['cardprice3'] = $v['cardprice3'];
$Goods['is_mainshow'] = (int)$v['is_mainshow'];
$Goods['spec_img'] = $v['spec_img'];
$pattern=tpCache('distribut.pattern',getAdmStoId());
if($pattern==1) {
$Goods['fir_rate'] = $v['fir_rate'];
$Goods['sec_rate'] = $v['sec_rate'];
$Goods['thi_rate'] = $v['thi_rate'];
}else{
$Goods['commission'] = $v['commission'];
}
$Goods['cat_id'] = $gcat_id;//分类ID
if (empty($id)) {
if (!empty($Goods['goods_content']) && empty($c)) {
$this->mztk($Goods, 1);
$c++;
}
++$sort;
$Goods['sort'] = $sort;
$res = getApiData("wxd.mshop.wares.add", $tk, array(['WareId' => $v['erpwareid']]));
mlog($res, "good/" . getAdmStoId());
if ($res)
{
$res_adderp=json_decode($res,true);
if ($res_adderp['code']==1)
{
$Goods['is_erpwares'] = 1;
}
}
$id = M('goods')->add($Goods);
$img_sort=0;
if (!empty($Goods['original_img'])) {
$data_img[] = ['goods_id' => $id, 'image_url' => $Goods['original_img'], 'store_id' => $sto_id, 'ismain' => 1,"img_sort"=>$img_sort];
}
if($goods_img) {
foreach ($goods_img as $val) {
if ($Goods['original_img'] != $val && $val != "") {
$img_sort++;
$data_img[] = ['goods_id' => $id, 'image_url' => $val, 'store_id' => $sto_id, 'ismain' => 0, "img_sort" => $img_sort];
}
}
}
//---视频从表----
if($goods_video[0]) {
$video_sort = 0;
foreach ($goods_video as $k => $val) {
$video_data[] = ['goods_id' => $id, 'video_url' => $val, 'video_img' => $video_img[$k],
'store_id' => $sto_id, "$video_sort" => $video_sort,'up_video_id'=>$up_video_id[$k]];
$video_sort++;
}
}
} else {
$Goods['edit_time'] = time();
$Goods['edit_ip'] = getIP();
if (!empty($Goods['goods_content']) && empty($c)) {
$this->mztk($Goods, 2);
$c++;
}
M('goods')->where('goods_id', $id)->update($Goods);
//if ($Goods['iseditimg']==1 || !in_array($Goods['original_img'],$goods_img)) {
M('goods_images')->where('goods_id', $id)->where('store_id', getAdmStoId())->delete();
$img_sort=0;
if ($Goods['original_img']) {
$data_img[] = ['goods_id' => $id, 'image_url' => $Goods['original_img'], 'store_id' => $sto_id, 'ismain' => 1,"img_sort"=>$img_sort];
}
if($goods_img) {
foreach ($goods_img as $val) {
if ($Goods['original_img'] != $val && $val != "") {
$img_sort++;
$data_img[] = ['goods_id' => $id, 'image_url' => $val, 'store_id' => $sto_id, 'ismain' => 0,"img_sort"=>$img_sort];
}
}
}
//}
//---视频从表----
if($goods_video[0]) {
M('goods_videos')->where('goods_id', $id)->where('store_id', getAdmStoId())->delete();
$video_sort = 0;
foreach ($goods_video as $k => $val) {
$video_data[] = ['goods_id' => $id, 'video_url' => $val, 'video_img' => $video_img[$k],
'store_id' => $sto_id, "video_sort" => $video_sort,'up_video_id'=>$up_video_id[$k]];
$video_sort++;
}
}
upload_ylp_log('B04商品管理编辑/确认提交');
}
}
if ($data_img) {
M('goods_images')->insertAll($data_img);
}
//---保存视频--
if ($video_data) {
M('goods_videos')->insertAll($video_data);
}else{
M('goods_videos')->where('goods_id',$id)->delete();
}
return json(['code' => 1, 'msg' => '操作成功', 'url' => $old_url]);
}
/**
* 商品类型 用于设置商品的属性
*/
public function goodsTypeList()
{
$model = M("GoodsType");
$count = $model->count();
$Page = $pager = new Page($count, 14);
$show = $Page->show();
$goodsTypeList = $model->order("id desc")->limit($Page->firstRow . ',' . $Page->listRows)->select();
$this->assign('pager', $pager);
$this->assign('show', $show);
$this->assign('goodsTypeList', $goodsTypeList);
return $this->fetch('goodsTypeList', getAdmStoId());
}
/**
* 添加修改编辑 商品属性类型
*/
public function addEditGoodsType()
{
$id = $this->request->param('id', 0);
$model = M("GoodsType");
if (IS_POST) {
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
$data = $this->request->post();
if ($id)
DB::name('GoodsType')->update($data);
else
DB::name('GoodsType')->insert($data);
$this->success("操作成功!!!", U('Admin/Goods/goodsTypeList'));
exit;
}
$goodsType = $model->find($id);
$this->assign('goodsType', $goodsType);
return $this->fetch('_goodsType', getAdmStoId());
}
/**
* 商品属性列表
*/
public function goodsAttributeList()
{
$goodsTypeList = M("GoodsType")->select();
$this->assign('goodsTypeList', $goodsTypeList);
return $this->fetch('', getAdmStoId());
}
/**
* 商品属性列表
*/
public function ajaxGoodsAttributeList()
{
//ob_start('ob_gzhandler'); // 页面压缩输出
$where = ' 1 = 1 '; // 搜索条件
I('type_id') && $where = "$where and type_id = " . I('type_id');
// 关键词搜索
$model = M('GoodsAttribute');
$count = $model->where($where)->count();
$Page = new AjaxPage($count, 13);
$show = $Page->show();
$goodsAttributeList = $model->where($where)->order('`order` desc,attr_id DESC')->limit($Page->firstRow . ',' . $Page->listRows)->select();
$goodsTypeList = M("GoodsType")->getField('id,name');
$attr_input_type = array(0 => '手工录入', 1 => ' 从列表中选择', 2 => ' 多行文本框');
$this->assign('attr_input_type', $attr_input_type);
$this->assign('goodsTypeList', $goodsTypeList);
$this->assign('goodsAttributeList', $goodsAttributeList);
$this->assign('page', $show);// 赋值分页输出
return $this->fetch('', getAdmStoId());
}
/**
* 商品列表导入
*/
public function goodsImport(){
$data = I('data');
$page = I('page');
$sto_id = getAdmStoId();
$import_data = include APP_PATH . 'admin/conf/import_data.php';
$data = json_decode($data, true);
$arrs=0;
foreach ($data as $key => $value) {
$i=0;
$is_set_categ=0;
$is_set_brand=0;
$is_set_nation=0;
$arr = null;
//判断当前时间是不是为null 是的话填写当前时间
if(empty( $value['上架时间'])){
$value['上架时间']= strtotime(date('Y-m-d h:i:s', time()));
}else{
$value['上架时间']= strtotime( $value['上架时间']);
}
$value['下架时间']= strtotime( $value['下架时间']);
foreach ($value as $kl => $vl) {
$is_set= isset($import_data[$kl]);
if(!$is_set&&$i==0) {
$err_arr[] = $kl."查无此列,请核对后重新导入";
$i=1;
break 2;
}
$table_key = $import_data[$kl];
switch ($kl) {
case "品类":
$categ_arr = explode("/",$value['品类']);
foreach ( $categ_arr as $klss => $vlss ){
$rs = M('goods_category')->where('name', $vlss)->where('store_id', $sto_id)->find();
if( $is_set_categ==0){
if (!$rs||rs==null) {
$cat_arr[] = $arr['goods_sn']."商品编号" . "查无品类";
$is_set_categ=1;
break ;
}
}
}
$categ_arr = explode("/", $vl);
$len = count($categ_arr) - 1;
$name = $categ_arr[$len];
$rs = M('goods_category')->where('name', $name)->where('store_id', $sto_id)->find();
$arr[$table_key] = $rs["id"];
break;
case '品牌':
if($vl) {
$rs = M('brand')->where('name', $vl)->where('store_id', $sto_id)->find();
$arr[$table_key] = $rs["id"];
if($rs==null){
$is_set_brand=1;
}
}
break;
case '国别':
if($vl) {
$rs = M('nation')->where('name', $vl)->where('store_id', $sto_id)->find();
$arr[$table_key] = $rs["id"];
if($rs==null) {
$is_set_nation = 1;
}
}
break;
default:
$arr[$table_key] = $vl;
break;
}
}
if(empty($arr['goods_sn'])||$arr['goods_sn']=="\n") {
if(empty($arr['goods_name'])){
$err_arr[] = $arr['sku']."商品条码"."未填写商品编号";
continue;
}else{
$err_arr[] = $arr['goods_name']."商品"."未填写商品编号";
}
continue;
}
if(empty($arr['sku'])||$arr['sku']=="\n") {
$nation_arr[] = $arr['goods_sn']."商品编号"."未填写条码";
continue;
}
if(empty($arr['shop_price'])||$arr['shop_price']=="\n") {
$err_arr[] = $arr['goods_sn']."商品编号"."未填写手店价";
continue;
}
if(empty($arr['cat_id'])&& $is_set_categ==0) {
$err_arr[] = $arr['goods_sn']."商品编号"."未填写品类";
continue;
}
if(empty($arr['nation_id']) && $is_set_nation) {
$nation_arr[] = $arr['goods_sn']."商品编号"."查无国别";
continue;
}
if(empty($arr['brand_id']) && $is_set_brand) {
$brand_arr[] =$arr['goods_sn']."商品编号"."查无品牌";
continue;
}
if( empty($arr['give_integral'])){
$arr['give_integral']=0;
} else if($arr['give_integral']!="1" && $arr['give_integral']!="0"){
$err_arr[] = $arr['goods_sn']."该商品"."积分填写错误";
continue;
}
if( empty($arr['distr_type'])){
$arr['distr_type']=0;
} else if($arr['distr_type']!="0"&&$arr['distr_type']!="1"&&$arr['distr_type']!="2"){
$err_arr[] = $arr['goods_sn']."该商品"."配送方式填写错误";
continue;
}
if( empty($arr['dis_type'])){
$arr['dis_type']=0;
}else if($arr['dis_type']!="0"&&$arr['dis_type']!="1"){
$err_arr[] = $arr['goods_sn']."该商品"."分销类型填写错误";
continue;
}
if( empty($arr['exp_sum_type'])){
$arr['exp_sum_type']=3;
}if($arr['exp_sum_type']!="1"&&$arr['exp_sum_type']!="2"&&$arr['exp_sum_type']!="3"){
$err_arr[] = $arr['goods_sn']."该商品"."运费设置填写错误";
continue;
}
//调接口,有没有该商品
$where['WareNo'] = array('=', $arr['goods_sn']);
$getapi_token = tpCache('shop_info.api_token', getAdmStoId());
/* $rs = getApiData('wxd.mshop.wares.list.get', $getapi_token, null, $where, 1, 10, null);*/
$sn=$arr['goods_sn'];
$accdb=tpCache("shop_info.ERPId",getAdmStoId());
$wdata['State']=1;
$wdata['KeyWord']=urlencode($sn);
$wdata['page']=1;
$wdata['pageSize']=10;
$rs = getApiData_java_p('/api/erp/msg/mshop/wares/page', $accdb, $wdata);
$good_sn = M('goods')->where('goods_sn', $sn)->where('store_id',$sto_id)->find();
//把字符串转换成数组
$datas = json_decode($rs, true);
$goods_data=$datas['data']['pageData'];
if($good_sn) {
// if ($datas['data']) {
$err_arr[] = $arr['goods_sn'] . "该商品已存在";
continue;
// }
}
if ($goods_data!=null&&count($goods_data)!=0) {
//市场价
foreach ($goods_data as $k => $v) {
//市场价
if (empty($arr['market_price'])) {
$arr['market_price'] = $v['PosPrice'];
}
//商品名称
if (empty($arr['goods_name'])) {
$arr['goods_name'] = $v['WareName'];
}
//商品条码
if (empty($arr['sku'])) {
$arr['sku'] = $v['BarCode'];
}
}
} else{
//判断在线下有没有存在
$err_arr[] = $arr['goods_sn']."商品编号" . "线下查无此商品编号";
continue;
}
$arr['erpwareid'] = $datas['data'][0]['Id'];
if(empty($arr['cat_id'])){
$arr['cat_id']=0;
}
if(empty($arr['brand_id'])){
$arr['brand_id']=0;
}
if(empty($arr['nation_id'])){
$arr['nation_id']=0;
}
//插入数据
$arr['store_id'] = getAdmStoId();
//判断积分给是不是null,是给默认值
if(empty($arr['give_integral'])) $arr['give_integral']=0;
//判断库存数是不是null,获取数据库中的默认库存数量
if(empty($arr['store_count']))
$arr['store_count']=tpCache('basic.default_storage', getAdmStoId());
$arr['is_mainshow']=1;
$rs_save_goods=null;
if( $is_set_categ==0) {
$rs_save_goods = M('goods')->save($arr);
$arrs++;
}
if (!$rs_save_goods) {
/*插入失败的日志*/
$fail_err=M('goods')->fetchSql(ture)->save($arr);
mlog($fail_err,"goodsImport/". $arr['store_id']);
$err_arr[] = $arr['goods_sn']."商品编号". "此商品插入失败";
continue;
// Cache::rm("name");
}
/* 设置成功插入的日志*/
$res = getApiData("wxd.mshop.wares.add", $getapi_token, array(['WareId' => $arr['erpwareid']]));
mlog($res, "good/" .getAdmStoId());
}
return json(['code' => 0, 'msg' => '成功', 'err_data' => $err_arr,'nation_data' => $nation_arr,'cat_data' => $cat_arr,'brand_data' => $brand_arr,"arrs"=>$arrs]);
}
/**
* 添加修改编辑 商品属性
*/
public function addEditGoodsAttribute()
{
$model = D("GoodsAttribute");
$type = I('attr_id') > 0 ? 2 : 1; // 标识自动验证时的 场景 1 表示插入 2 表示更新
$attr_values = str_replace('_', '', I('attr_values')); // 替换特殊字符
$attr_values = str_replace('@', '', $attr_values); // 替换特殊字符
$attr_values = trim($attr_values);
$post_data = input('post.');
$post_data['attr_values'] = $attr_values;
if ((I('is_ajax') == 1) && IS_POST)//ajax提交验证
{
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
// 数据验证
$validate = \think\Loader::validate('GoodsAttribute');
if (!$validate->batch()->check($post_data)) {
$error = $validate->getError();
$error_msg = array_values($error);
$return_arr = array(
'status' => -1,
'msg' => $error_msg[0],
'data' => $error,
);
$this->ajaxReturn($return_arr);
} else {
$model->data($post_data, true); // 收集数据
if ($type == 2) {
$model->isUpdate(true)->save(); // 写入数据到数据库
} else {
$model->save(); // 写入数据到数据库
$insert_id = $model->getLastInsID();
}
$return_arr = array(
'status' => 1,
'msg' => '操作成功',
'data' => array('url' => U('Admin/Goods/goodsAttributeList')),
);
$this->ajaxReturn($return_arr);
}
}
// 点击过来编辑时
$attr_id = I('attr_id/d', 0);
$goodsTypeList = M("GoodsType")->select();
$goodsAttribute = $model->find($attr_id);
$this->assign('goodsTypeList', $goodsTypeList);
$this->assign('goodsAttribute', $goodsAttribute);
return $this->fetch('_goodsAttribute', getAdmStoId());
}
/**
* 更改指定表的指定字段
*/
public function updateField()
{
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
$primary = array(
'goods' => 'goods_id',
'goods_category' => 'id',
'brand' => 'id',
'goods_attribute' => 'attr_id',
'ad' => 'ad_id',
);
$model = D($_POST['table']);
$model->$primary[$_POST['table']] = $_POST['id'];
$model->$_POST['field'] = $_POST['value'];
$model->save();
$return_arr = array(
'status' => 1,
'msg' => '操作成功',
'data' => array('url' => U('Admin/Goods/goodsAttributeList')),
);
$this->ajaxReturn($return_arr);
}
/**
* 动态获取商品属性输入框 根据不同的数据返回不同的输入框类型
*/
public function ajaxGetAttrInput()
{
$GoodsLogic = new GoodsLogic();
$str = $GoodsLogic->getAttrInput($_REQUEST['goods_id'], $_REQUEST['type_id']);
exit($str);
}
/**
* 删除商品
*/
public function delGoods()
{
$goods_id = I('id/d');
$error = '';
// 商品团购
// $c1 = M('group_buy')->where("goods_id = $goods_id")->count('1');
// $c1 && $error .= '此商品有团购,不得删除! <br/>';
//
// // 商品退货记录
// $c1 = M('return_goods')->where("goods_id = $goods_id")->count('1');
// $c1 && $error .= '此商品有退货记录,不得删除! <br/>';
//编辑器图片删除
$gos = M("goods")->where('goods_id =' . $goods_id)->find();
if ($gos) {
if ($gos['prom_type'] != 0) {
$error = '此商品有活动,不得删除! <br/>';
} else { // 判断此商品是否有订单
$c1 = M('OrderGoods')->where("goods_id = $goods_id")->count('1');
$c1 && $error .= '此商品有订单,不得删除! <br/>';
}
}
if ($error) {
$return_arr = array('status' => -1, 'msg' => $error, 'data' => '',); //$return_arr = array('status' => -1,'msg' => '删除失败','data' =>'',);
$this->ajaxReturn($return_arr);
}
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
//如果美妆图库有记录就不删除图片
// $num = M('barcodegoods')->where(['store_id'=>getAdmStoId(),'sku'=>$gos['sku']])->count(1);//查找同条码商品个数
// if (empty($num)){
// vendor('qcloudcos.myqcloudcos');
// if ($gos['editorimg']) {
// $editorimg = explode(',', $gos['editorimg']);
// foreach ($editorimg as $kl => $vl) {
// if (!empty($vl)) {
// $rs = Myqcloudcos::delFile('wxd', $vl);
// mdelFile(ROOT_PATH . $vl);
//
// }
// }
// }
// //商品主图删除
// if ($gos['original_img']) {
// $orimg = $gos['original_img'];
// if (!empty($orimg)) {
// $rs = Myqcloudcos::delFile('wxd', $orimg);
// mdelFile(ROOT_PATH . $orimg);
//
// $slocalpath = ROOT_PATH . '/' . UPLOAD_PATH . dirname($orimg) . '/s_' . basename($orimg);
// $sypath = '/' . UPLOAD_PATH . dirname($orimg) . '/s_' . basename($orimg);
// $rs = Myqcloudcos::delFile('wxd', $sypath);
// mdelFile(ROOT_PATH . $slocalpath);
// }
// }
// //商品图片列表
// $goimglist = M("goods_images")->where('goods_id =' . $goods_id)->select();
// if ($goimglist) {
// foreach ($goimglist as $kimg => $vimg) {
// if (!empty($vimg['image_url'])) {
// $rs = Myqcloudcos::delFile('wxd', $vimg['image_url']);
// mdelFile(ROOT_PATH . $vimg['image_url']);
// }
// }
// }
// }
//
$getapi_token=tpCache('shop_info.api_token',getAdmStoId());
//下架商品
$res = getApiData("wxd.mshop.wares.del", $getapi_token,null, array(['WareId'=>$gos['erpwareid']]));
// 删除此商品
M("Goods")->where('store_id',getAdmStoId())->where('goods_id =' . $goods_id)->delete(); //商品表
M("cart")->where('store_id',getAdmStoId())->where('goods_id =' . $goods_id)->delete(); // 购物车
M("comment")->where('store_id',getAdmStoId())->where('goods_id =' . $goods_id)->delete(); //商品评论
M("goods_images")->where('store_id',getAdmStoId())->where('goods_id =' . $goods_id)->delete(); //商品相册
M("goods_collect")->where('store_id',getAdmStoId())->where('goods_id =' . $goods_id)->delete(); //商品收藏
$return_arr = array('status' => 1, 'msg' => '操作成功', 'data' => '',); //$return_arr = array('status' => -1,'msg' => '删除失败','data' =>'',);
$this->ajaxReturn($return_arr);
}
/**
* 异常商品修复
*/
public function updateerpgoods()
{
$key = I('key');
$gos = M('goods')->where('goods_sn',$key)->where('store_id', getAdmStoId())->field('erpwareid')->find();
if ($gos) {
$return_arr = array('status' => -1, 'msg' => '商品编号已存在商品列表', 'data' => '',);
}
else {
$getapi_token = tpCache('shop_info.api_token', getAdmStoId());
$where['WareNo'] = $key;
$res = getApiData('wxd.base.wares.list.get', $getapi_token, null, $where, 1, 10, null);
if ($res) {
$res = json_decode($res, true);
if ($res['code'] == 1 && $res['data']) {
if ($res['count']==1) {
//下架商品
$res = getApiData("wxd.mshop.wares.del", $getapi_token, null, array(['WareId' => $res['data'][0]['Id']]));
$return_arr = array('status' => 1, 'msg' => '修复成功', 'data' => '',);
}else
{
$return_arr = array('status' => -1, 'msg' => '修复失败,您所输入的关键字查询出来数量大于1', 'data' => '',);
}
}
else
{
$return_arr = array('status' => -1, 'msg' => '修复失败', 'data' => '',);
}
}
else
{
$return_arr = array('status' => -1, 'msg' => '修复失败,接口获取失败', 'data' => '',);
}
}
$this->ajaxReturn($return_arr);
}
/**
* 更新商品
*/
public function updatesku()
{
$geterpwareid = I('erpwareid');
$getapi_token=tpCache('shop_info.api_token',getAdmStoId());
$where['Id'] = $geterpwareid;
$res = getApiData('wxd.base.wares.list.get',$getapi_token, null, $where, 1, 10, null);
if ($res)
{
$res=json_decode($res,true);
if ($res['code']==1 && $res['data']) {
$postdata['goods_sn'] = $res['data'][0]['WareNo'];
$postdata['sku'] = $res['data'][0]['BarCode'];
$postdata['market_price'] = $res['data'][0]['PosPrice'];
$row = M('goods')->where(array('store_id' => getAdmStoId(), 'erpwareid' => $geterpwareid))->save($postdata);
$return_arr = array('status' => 1, 'msg' => '操作成功', 'data' => '',);
}
else
{
$return_arr = array('status' => -1,'msg' => '获取商品资料失败','data' =>'',);
}
}
else{
$return_arr = array('status' => -1,'msg' => '获取商品资料失败','data' =>'',);
}
$this->ajaxReturn($return_arr);
}
/**
* 删除商品类型
*/
public function delGoodsType()
{
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
// 判断 商品规格
$id = $this->request->param('id');
$count = M("Spec")->where("type_id = {$id}")->count("1");
$count > 0 && $this->error('该类型下有商品规格不得删除!', U('Admin/Goods/goodsTypeList'));
// 判断 商品属性
$count = M("GoodsAttribute")->where("type_id = {$id}")->count("1");
$count > 0 && $this->error('该类型下有商品属性不得删除!', U('Admin/Goods/goodsTypeList'));
// 删除分类
M('GoodsType')->where("id = {$id}")->delete();
$this->success("操作成功!!!", U('Admin/Goods/goodsTypeList'));
}
/**
* 删除商品属性
*/
public function delGoodsAttribute()
{
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
$id = input('id');
// 判断 有无商品使用该属性
$count = M("GoodsAttr")->where("attr_id = {$id}")->count("1");
$count > 0 && $this->error('有商品使用该属性,不得删除!', U('Admin/Goods/goodsAttributeList'));
// 删除 属性
M('GoodsAttribute')->where("attr_id = {$id}")->delete();
$this->success("操作成功!!!", U('Admin/Goods/goodsAttributeList'));
}
/**
* 删除商品规格
*/
public function delGoodsSpec()
{
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
$id = input('id');
// 判断 商品规格项
$count = M("SpecItem")->where("spec_id = {$id}")->count("1");
$count > 0 && $this->error('清空规格项后才可以删除!', U('Admin/Goods/specList'));
// 删除分类
M('Spec')->where("id = {$id}")->delete();
$this->success("操作成功!!!", U('Admin/Goods/specList'));
}
/**
* 品牌列表
*/
public function brandList()
{
$pagenum = 10;//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
}
$model = M("Brand");
$where = " 1=1 ";
$keyword = urldecode(urldecode(I('keyword')));
$getAdmStoId = getAdmStoId();
$where .= $keyword ? " and name like '%$keyword%' " : "";
$where .= " and store_id='" . $getAdmStoId . "'";
$count = $model->where($where)->count();
$Page = $pager = new Page($count, $pagenum);
$brandList = $model->where($where)->order("`sort` asc")->limit($Page->firstRow . ',' . $Page->listRows)->select();
$show = $Page->show();
$cat_list = M('goods_category')->where("parent_id = 0")->getField('id,name'); // 已经改成联动菜单
$impotr=M('import_active')->where(['store_id'=>$getAdmStoId,'state'=>1,'type'=>102])->find();
$this->assign('import',$impotr);
$this->assign('cat_list', $cat_list);
$this->assign('pager', $pager);
$this->assign('show', $show);
$this->assign('brandList', $brandList);
$this->assign('keyword',$keyword);
$this->assign('stoid', $getAdmStoId);
$this->assign('pagenum', $pagenum);
$this->assign('oldurl', urlencode(curPageURL()));
// upload_ylp_log('品牌列表');
return $this->fetch('brandList', getAdmStoId());
}
/**
* 添加修改编辑 商品品牌
*/
public function addEditBrand()
{
$id = I('id');
$this->assign('erpid', getERPId());
$this->assign('curid', '0');
$oldurl = I('oldurl/s');
if ($oldurl) {
$oldurl = urldecode(urldecode($oldurl));
}
if (!empty($id)) {
$this->assign('curid', $id);
}
if (IS_POST) {
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
$data = input('post.');
$getAdmStoId = getAdmStoId();
$data['store_id'] = $getAdmStoId;
$data['zm'] = substr($data['zm'],0,1);
if ($data['imgtype'] == 0) {
$data['logo'] = I('logo');
} else {
$data['logo'] = I('httimg');
}
$rt=M("admin")->where('store_id',$getAdmStoId)->where('admin_id',getAdminId())->field('ERPUser')->find();
if ($id){
$data['edit_time'] = time();
$data['edit_ip'] = getIP();
$data['edit_man'] = $rt['ERPUser'];
upload_ylp_log('B03品牌详情编辑/确认提交');
M("Brand")->update($data);
}
else{
$data['add_time'] = time();
$data['edit_ip'] = getIP();
$data['edit_man'] = $rt['ERPUser'];
M("Brand")->insert($data);
}
if ($oldurl) {
$this->success("操作成功!!!", U('Admin/Goods/brandList', $oldurl));
} else {
$this->success("操作成功!!!", U('Admin/Goods/brandList', array('p' => input('p'))));
}
exit;
}
$cat_list = M('goods_category')->where(" store_id=" . getAdmStoId() . " and parent_id = 0")->select(); // 已经改成联动菜单
$this->assign('cat_list', $cat_list);
$brand = M("Brand")->find($id);
if (empty($brand)) {
$m = Db::query("select max(sort)so from wxd_brand where store_id=" . getAdmStoId());
$md = (int)$m[0]["so"];
$md++;
$brand["sort"] = $md;
$brand["is_hot"]=1;
}
$this->assign('brand', $brand);
return $this->fetch('_brand', getAdmStoId());
}
/**
* 删除品牌
*/
public function delBrand()
{
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
// 判断此品牌是否有商品在使用
$goods_count = M('Goods')
->where("brand_id = {$_GET['id']}")->where('store_id',getAdmStoId())->count('1');
if ($goods_count) {
$return_arr = array('status' => -1, 'msg' => '此品牌有商品在用不得删除!', 'data' => '',); //$return_arr = array('status' => -1,'msg' => '删除失败','data' =>'',);
$this->ajaxReturn($return_arr);
}
$model = M("Brand");
$brandlist = $model->where('store_id',getAdmStoId())->where('id=' . $_GET['id'])->find();
$dellogo = ltrim($brandlist['logo'], '/');
vendor('qcloudcos.myqcloudcos');
if (!empty($dellogo)) {
$rs = Myqcloudcos::delFile('wxd', $dellogo);
mdelFile(ROOT_PATH . $dellogo);
}
//delFile($dellogo);
$model->where('store_id',getAdmStoId())->where('id =' . $_GET['id'])->delete();
$return_arr = array('status' => 1, 'msg' => '操作成功', 'data' => '',); //$return_arr = array('status' => -1,'msg' => '删除失败','data' =>'',);
$this->ajaxReturn($return_arr);
}
/**
* 国别列表
*/
public function nationList()
{
$pagenum = 10;//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
}
$model = M("nation");
$where = " 1=1 ";
$keyword = urldecode(urldecode(I('keyword')));
$getAdmStoId = getAdmStoId();
$where .= $keyword ? " and name like '%$keyword%' " : "";
$where .= " and store_id=" . $getAdmStoId . "";
$count = $model->where($where)->count();
$Page = $pager = new Page($count, $pagenum);
$nationList = $model->where($where)->order("`sort` asc")->limit($Page->firstRow . ',' . $Page->listRows)->select();
$show = $Page->show();
$this->assign('pager', $pager);
$this->assign('show', $show);
$this->assign('nationList', $nationList);
$this->assign('keyword',$keyword);
$this->assign('pagenum', $pagenum);
$this->assign('oldurl', urlencode(curPageURL()));
// upload_ylp_log('国别列表');
return $this->fetch('nationList', getAdmStoId());
}
/**
* 添加修改编辑 商品国别
*/
public function addEditNation()
{
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
$oldurl = I('oldurl/s');
if ($oldurl) {
$oldurl = urldecode(urldecode($oldurl));
}
$id = I('id');
$this->assign('erpid', getERPId());
$this->assign('curid', '0');
if (!empty($id)) {
$this->assign('curid', $id);
}
$getAdmStoId = getAdmStoId();
$brand = M("nation")->where('store_id',$getAdmStoId)->find($id);
if (IS_POST) {
$data = input('post.');
$data['store_id'] = $getAdmStoId;
if ($data['imgtype'] == 0) {
$data['logo'] = I('logo');
} else {
$data['logo'] = I('httimg');
}
$rt=M("admin")->where(array('store_id'=>$getAdmStoId,'admin_id'=>getAdminId()))->field('ERPUser')->find();
if ($id){
$data['edit_time'] = time();
$data['edit_ip'] = getIP();
$data['edit_man'] = $rt['ERPUser'];
upload_ylp_log('B02国家分类编辑/确认提交');
M("nation")->update($data);
}
else{
$data['add_time'] = time();
$data['edit_ip'] = getIP();
$data['edit_man'] = $rt['ERPUser'];
M("nation")->insert($data);
}
if ($oldurl) {
$this->success("操作成功!!!", $oldurl);
} else {
$this->success("操作成功!!!", U('Admin/Goods/nationlist', array('p' => input('p'))));
}
exit;
}
if (empty($brand)) {
$m = Db::query("select max(sort)odr from wxd_nation where store_id=" . getAdmStoId());
$md = (int)$m[0]["odr"];
$md++;
$brand["sort"] = $md;
$brand["is_hot"]=1;
}
$this->assign('nation', $brand);
return $this->fetch('_nation', getAdmStoId());
}
/**
* 删除国别
*/
public function delNation()
{
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
// 判断此品牌是否有商品在使用
$goods_count = M('Goods')->where('store_id',getAdmStoId())->where("nation_id = {$_GET['id']}")->count('1');
if ($goods_count) {
$return_arr = array('status' => -1, 'msg' => '此国别有商品在用不得删除!', 'data' => '',); //$return_arr = array('status' => -1,'msg' => '删除失败','data' =>'',);
$this->ajaxReturn($return_arr);
}
$model = M("Nation");
$nationlist = $model->where('store_id',getAdmStoId())->where('id =' . $_GET['id'])->find();
$dellogo = ltrim($nationlist['logo'], '/');
if ($dellogo) {
vendor('qcloudcos.myqcloudcos');
$rs = Myqcloudcos::delFile('wxd', $dellogo);
mdelFile(ROOT_PATH . $dellogo);
}
//delFile($dellogo); // 删除缩略图
$model->where('store_id',getAdmStoId())->where('id =' . $_GET['id'])->delete();
$return_arr = array('status' => 1, 'msg' => '操作成功', 'data' => '',); //$return_arr = array('status' => -1,'msg' => '删除失败','data' =>'',);
$this->ajaxReturn($return_arr);
}
/**
* 初始化编辑器链接
* 本编辑器参考 地址 http://fex.baidu.com/ueditor/
*/
private function initEditor()
{
$this->assign("URL_upload", U('admin/Ueditor/imageUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 图片上传目录
$this->assign("URL_imageUp", U('admin/Ueditor/imageUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 不知道啥图片
$this->assign("URL_fileUp", U('admin/Ueditor/fileUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 文件上传s
$this->assign("URL_scrawlUp", U('admin/Ueditor/scrawlUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 图片流
$this->assign("URL_getRemoteImage", U('admin/Ueditor/getRemoteImage', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 远程图片管理
$this->assign("URL_imageManager", U('admin/Ueditor/imageManager', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 图片管理
$this->assign("URL_getMovie", U('admin/Ueditor/getMovie', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 视频上传
$this->assign("URL_Home", "");
}
/**
* 商品规格列表
*/
public function specList()
{
$goodsTypeList = M("GoodsType")->select();
$this->assign('goodsTypeList', $goodsTypeList);
return $this->fetch('', getAdmStoId());
}
/**
* 商品规格列表
*/
public function ajaxSpecList()
{
//ob_start('ob_gzhandler'); // 页面压缩输出
$where = ' 1 = 1 '; // 搜索条件
I('type_id') && $where = "$where and type_id = " . I('type_id');
// 关键词搜索
$model = D('spec');
$count = $model->where($where)->count();
$Page = new AjaxPage($count, 13);
$show = $Page->show();
$specList = $model->where($where)->order('`type_id` desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
$GoodsLogic = new GoodsLogic();
foreach ($specList as $k => $v) { // 获取规格项
$arr = $GoodsLogic->getSpecItem($v['id']);
$specList[$k]['spec_item'] = implode(' , ', $arr);
}
$this->assign('specList', $specList);
$this->assign('page', $show);// 赋值分页输出
$goodsTypeList = M("GoodsType")->select(); // 规格分类
$goodsTypeList = convert_arr_key($goodsTypeList, 'id');
$this->assign('goodsTypeList', $goodsTypeList);
return $this->fetch('', getAdmStoId());
}
/**
* 添加image修改编辑 商品规格
*/
public function addEditSpec()
{
$model = D("spec");
$type = I('id') > 0 ? 2 : 1; // 标识自动验证时的 场景 1 表示插入 2 表示更新
if ((I('is_ajax') == 1) && IS_POST)//ajax提交验证
{
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
// 数据验证
$validate = \think\Loader::validate('Spec');
$post_data = input('post.');
if ($type == 2) {
//更新数据
$check = $validate->scene('edit')->batch()->check($post_data);
} else {
//插入数据
$check = $validate->batch()->check($post_data);
}
if (!$check) {
$error = $validate->getError();
$error_msg = array_values($error);
$return_arr = array(
'status' => -1,
'msg' => $error_msg[0],
'data' => $error,
);
$this->ajaxReturn($return_arr);
}
$model->data($post_data, true); // 收集数据
if ($type == 2) {
$model->isUpdate(true)->save(); // 写入数据到数据库
$model->afterSave(I('id'));
} else {
$model->save(); // 写入数据到数据库
$insert_id = $model->getLastInsID();
$model->afterSave($insert_id);
}
$return_arr = array(
'status' => 1,
'msg' => '操作成功',
'data' => array('url' => U('Admin/Goods/specList')),
);
$this->ajaxReturn($return_arr);
}
// 点击过来编辑时
$id = I('id/d', 0);
$spec = $model->find($id);
$GoodsLogic = new GoodsLogic();
$items = $GoodsLogic->getSpecItem($id);
$spec[items] = implode(PHP_EOL, $items);
$this->assign('spec', $spec);
$goodsTypeList = M("GoodsType")->select();
$this->assign('goodsTypeList', $goodsTypeList);
return $this->fetch('_spec', getAdmStoId());
}
/**
* 动态获取商品规格选择框 根据不同的数据返回不同的选择框
*/
public function ajaxGetSpecSelect()
{
$goods_id = I('get.goods_id/d') ? I('get.goods_id/d') : 0;
$GoodsLogic = new GoodsLogic();
//$_GET['spec_type'] = 13;
$specList = M('Spec')->where("type_id = " . I('get.spec_type/d'))->order('`order` desc')->select();
foreach ($specList as $k => $v)
$specList[$k]['spec_item'] = M('SpecItem')->where("spec_id = " . $v['id'])->order('id')->getField('id,item'); // 获取规格项
$items_id = M('SpecGoodsPrice')->where('goods_id = ' . $goods_id)->getField("GROUP_CONCAT(`key` SEPARATOR '_') AS items_id");
$items_ids = explode('_', $items_id);
// 获取商品规格图片
if ($goods_id) {
$specImageList = M('SpecImage')->where("goods_id = $goods_id")->getField('spec_image_id,src');
}
$this->assign('specImageList', $specImageList);
$this->assign('items_ids', $items_ids);
$this->assign('specList', $specList);
return $this->fetch('ajax_spec_select', getAdmStoId());
}
/**
* 动态获取商品规格输入框 根据不同的数据返回不同的输入框
*/
public function ajaxGetSpecInput()
{
$GoodsLogic = new GoodsLogic();
$goods_id = I('goods_id/d') ? I('goods_id/d') : 0;
$str = $GoodsLogic->getSpecInput($goods_id, I('post.spec_arr/a', [[]]));
exit($str);
}
/**
* 删除商品相册图
*/
public function del_goods_images()
{
ClearALLCache();
delFile(TEMP_PATH . "/" . getAdmStoId());
$path = I('filename', '');
$sku = I('sku');
if ($sku) {
$rs = M('goods')->where(array('store_id'=>getAdmStoId(),'sku'=>$sku))->select();
if ($rs) {
foreach ($rs as $k=>$v) {
if ($v['ismain'] == 1) {
M('goods')->where('goods_id', $v['goods_id'])->save(['original_img' => ""]);
}
M('goods_images')->where("image_url = '$path'")->where('goods_id', $v['goods_id'])->delete();
}
}
}
}
/**
* 更新商品相册图
*/
public function updateimgmain()
{
$path = I('filename', '');
$img_id = I('img_id');
$sku = I('sku');
//判断是否有小图
$smallfilename=basename($path);
$spath=str_replace($smallfilename,'',$path)."s_".$smallfilename;
vendor('qcloudcos.myqcloudcos');
$resfolder=Myqcloudcos::stat('wxd',$spath);
if ($resfolder && $resfolder['code']!=0)//不存在创建
{
$resfolder_new=Myqcloudcos::copyFile('wxd',$path,$spath);
}
//
$imgres=M('goods')->where('store_id',getAdmStoId())->where('sku', $sku)->order('goods_id desc')->find();
if ($imgres) {
M('goods_images')->where('store_id',getAdmStoId())->where('goods_id', $imgres['goods_id'])->save(['ismain' => 0]);
M('goods_images')->where('store_id',getAdmStoId())->where('img_id', $img_id)->save(['ismain' => 1]);
M('goods')->where('store_id',getAdmStoId())->where('sku', $sku)->save(['original_img' =>$path]);
exit(1);
}
else{
exit(0);
}
}
/*--访问接口选择商品--*/
public function SelectGood()
{
$p = I('p/d', 1);
$key = trim(urldecode(I('key/s')));
$accdb=tpCache("shop_info.ERPId",getAdmStoId());
$wdata['State']=1;
$wdata['KeyWord']=urlencode($key);
$wdata['page']=$p;
$wdata['pageSize']=10;
$rs = getApiData_java_p('/api/erp/msg/mshop/wares/page', $accdb, $wdata);
if (empty($rs))
{
return json(["code" => -1, "msg" => "获取接口数据错误"]);
}
$wdata=null;
if ($rs) {
$data = json_decode($rs, true);
if ($data['data']) {
$wdata['data']=$data['data']['pageData'];
if ($wdata['data']) {
foreach ($wdata['data'] as $k => $v) {
$wdata['data'][$k]['PurPrice'] = number_format(empty($v['PurPrice']) ? 0 : $v['PurPrice'], 2, ".", "");
$wdata['data'][$k]['PosPrice'] = number_format(empty($v['PosPrice']) ? 0 : $v['PosPrice'], 2, ".", "");
$wdata['data'][$k]['VipPrice'] = number_format(empty($v['VipPrice']) ? 0 : $v['VipPrice'], 2, ".", "");
$wdata['data'][$k]['TradePrice'] = number_format(empty($v['TradePrice']) ? 0 : $v['TradePrice'], 2, ".", "");
}
$wdata['code'] = 1;
$wdata['count'] = $data['data']['total'];
return json($wdata);
}
else
{
$check = M('goods')->where('goods_sn= "'.$key.'" or goods_name="'.$key.'" or sku="'.$key.'" ')->where('store_id',getAdmStoId())->find();
if ($check){
return json(['code' => -1 ,'msg'=>'该商品已添加']);
}else{
return json(["code" => -1, "msg" => "未找到您要搜索的商品"]);
}
}
} else {
$check = M('goods')->where('goods_sn= "'.$key.'" or goods_name="'.$key.'" or sku="'.$key.'" ')->where('store_id',getAdmStoId())->find();
if ($check){
return json(['code' => -1 ,'msg'=>'该商品已添加']);
}else{
return json(["code" => -1, "msg" => "未找到您要搜索的商品"]);
}
}
}
}
public function select_all()
{
$sku = I('sku/s');
$where['BarCode'] = array('=', $sku);
$where['State'] = array('=', 1);
$tk = M("store")->where("store_id", getAdmStoId())->field("api_token")->find();
$rs = getApiData('wxd.mshop.wares.list.get', $tk['api_token'],
null, $where, 1, 100, null);
if ($rs) {
$data = json_decode($rs, true);
if (!empty($data['data'])) {
foreach ($data['data'] as $k => $v) {
$data['data'][$k]['PurPrice'] = number_format(empty($v['PurPrice']) ? 0 : $v['PurPrice'], 2, ".", "");
$data['data'][$k]['PosPrice'] = number_format(empty($v['PosPrice']) ? 0 : $v['PosPrice'], 2, ".", "");
$data['data'][$k]['VipPrice'] = number_format(empty($v['VipPrice']) ? 0 : $v['VipPrice'], 2, ".", "");
$data['data'][$k]['TradePrice'] = number_format(empty($v['TradePrice']) ? 0 : $v['TradePrice'], 2, ".", "");
}
return json($data);
} else {
return json(["code" => -1, "msg" => "未找到您要搜索的商品"]);
}
}else {
return json(["code" => -1, "msg" => "获取接口数据错误"]);
}
}
/*--渲染商品--*/
function getGoods()
{
return $this->fetch('search', getAdmStoId());
}
/**
* 判断选择的商品条形码是否重复
*/
public function checkisok()
{
$sku = I('sku');
$rk = M('goods')->where(['sku' => $sku, 'store_id' => getAdmStoId()])->field('goods_id,sku')->find();
if (!empty($rk)) {
return json(['code' => 0, 'msg' => '该商品的条码【'.$rk['sku'].'】已添加,是否继续']);
} else {
return json(['code' => 1, 'msg' => '操作成功']);
}
}
function getfile()
{
$f = ROOT_PATH . "/application/json.txt";
$myfile = fopen($f, "r") or die("Unable to open file!");
$str = fread($myfile, filesize($f));
fclose($myfile);
return $str;
}
function getbrandzm()
{
$getname = I('brandname');
$getzm = getFirstCharter($getname);
if ($getzm) {
return $getzm;
} else {
return "";
}
}
/**************************************************商品分组 小张 17-05-22******************************************************************/
//商品分组
function goodsGroup()
{
$list = array();
$where['store_id'] = getAdmStoId();
$res = D('goods_group')->where($where)->order("gp_ordid")->select();
if ($res) {
foreach ($res as $val) {
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
$list[] = $val;
}
}
$this->assign('grouplist', $list);
$this->assign('store_id', getAdmStoId());
// upload_ylp_log('商品分组');
return $this->fetch('', getAdmStoId());
}
//删除商品分组
public function delGoodsGroup()
{
$id = $this->request->param('gpid');
DB::name('goods_group')->where(array('store_id'=>getAdmStoId(),'gpid'=>$id))->delete();
$this->success("操作成功!!!", U('Admin/Goods/goodsGroup'));
}
//编辑新增分组
public function goodsGroupInfo()
{
$gpid = I('gpid');
if ($gpid > 0) {
$group = M('goods_group')->where('store_id',getAdmStoId())->where(" gpid =" . $gpid . " ")->find();
$this->assign('group', $group);
if ($group['gp_goodslist'] != "") {
$where = 'goods_id in (' . $group['gp_goodslist'] . ')';
$group_goods = M('goods')->where('store_id',getAdmStoId())->where($where)->order('sort asc')->select();
$this->assign('group_goods', $group_goods);
}
} else {
$m = Db::query("select max(gp_ordid)odr from __PREFIX__goods_group where store_id=" . getAdmStoId());
$md = (int)$m[0]["odr"];
$md++;
$group["gp_ordid"] = $md;
$group["status"] = 1;
}
$this->assign('group', $group);
return $this->fetch('', getAdmStoId());
}
//选择商品
public function search_goods()
{
$GoodsLogic = new GoodsLogic;
$brandList = $GoodsLogic->getSortBrands();
$this->assign('brandList', $brandList);
$categoryList = $GoodsLogic->getSortCategory();
$this->assign('categoryList', $categoryList);
$pagenum = I('pagenum/d',10);//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
}
$this->assign('pagenum', $pagenum);
$goods_id = I('goods_id');
if ($goods_id)
{
$goods_id=$goods_id.",";
$this->assign('idlist', $goods_id);
}
$tpl = I('get.tpl', 'search_goods');
return $this->fetch($tpl, getAdmStoId());
}
public function ajax_search_goods()
{
$goods_id = I('sel_list');
$formid = I('formid');
$pagenum = I('pagenum/d',10);//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
}
if ($formid == "Group") {
$where = ' is_on_sale = 1 ';//搜索条件
} else {
$where = ' is_on_sale = 1 and store_count>0 ';//搜索条件
}
if ($goods_id) {
$goods_id=$goods_id."0";
$where .= " and goods_id not in ($goods_id) ";
}
I('intro') && $where = "$where and " . I('intro') . " = 1";
//分类
if (I('cat_id')) {
$this->assign('cat_id', I('cat_id'));
$grandson_ids = getCatGrandson(I('cat_id'));
$where = " $where and cat_id in(" . implode(',', $grandson_ids) . ") "; // 初始化搜索条件
}
//品牌
if (I('brand_id')) {
$this->assign('brand_id', I('brand_id'));
$where = "$where and brand_id = " . I('brand_id');
}
if (!empty($_REQUEST['keywords'])) {
$kw = I('keywords');
$kw = urldecode(urldecode($kw));
$this->assign('keywords', $kw);
$where = "$where and (goods_sn like '%" . $kw . "%' or goods_name like '%" . $kw . "%' or keywords like '%" . $kw . "%' or sku = '" . $kw . "')";
}
$t = time();
$getAdmStoId = getAdmStoId();
$where .= " and store_id=" . $getAdmStoId;
$where .= " and on_time<" . $t . " and (down_time>" . $t . " or down_time=0 or down_time='' or down_time is null)";
$count = M('goods')->where($where)->count();
$Page = new AjaxPage($count, $pagenum);
$goodsList = M('goods')->where($where)->order('goods_id DESC')->limit($Page->firstRow . ',' . $Page->listRows)->select();
$show = $Page->show();//分页显示输出
$this->assign('page', $show);//赋值分页输出
$this->assign('formid', $formid);
$this->assign('goodsList', $goodsList);
$this->assign('pager', $Page);//赋值分页输出
return $this->fetch("", getAdmStoId());
}
//保存分组
public function goodsgroup_save()
{
$data = I('post.');
$gpid = $data["gpid"];
if ($gpid) {
$r = D('goods_group')->where('store_id',getAdmStoId())->where('gpid', $data['gpid'])->save($data);
} else {
unset($data['gpid']);
$data['add_time'] = time();
$data["store_id"] = getAdmStoId();
$r = D('goods_group')->add($data);
}
upload_ylp_log('B05商品分组编辑/确认提交');
$this->success('编辑分组成功', U('Goods/goodsGroup'));
}
/**
* 判断是否参与活动
*/
public function isinactive()
{
$gid = I('gid');
$good = M('goods')->where('store_id',getAdmStoId())->where('goods_id', $gid)->find();
if ($good['prom_type'] > 0) {
$title = "";
switch ($good['prom_type']) {
case 1:
$title = "参与秒杀活动";
break;
case 2:
$title = "参与团购活动";
break;
case 3:
$title = "参与优惠促销活动";
break;
case 4:
$title = "参与积分购活动";
break;
}
return json(['code' => 1, 'msg' => $title]);
} else {
return json(['code' => -1, 'msg' => "未参与活动"]);
}
}
/*--判断库存是否OK--*/
public function isstorage()
{
$goods_id = I('gid');
$storecount1 = I('count/d', 0);
$ggg = M('goods')->where('store_id',getAdmStoId())->where('goods_id', $goods_id)->find();
$now0 = time();
switch ($ggg['prom_type']) {
case 2:
$where0 = [
'end_time' => ['>=', $now0],
'start_time' => ['<=', $now0],
'goods_id' => $goods_id,
'is_end' => 0
];
/*--->where('goods_num>buy_num')--*/
$rs0 = M('group_buy')->where($where0)->find();
if (!empty($rs0)) {
$onlybuy = $rs0["goods_num"] - $rs0["buy_num"];
if ($storecount1 < $onlybuy) {
$this->ajaxReturn(['code' => -1,
'msg' => '该商品有参加团购活动,库存数量不能小于团购允许购买的数量',
'count' => $ggg['store_count']]);
}
}
break;
case 1:
$where1 = [
'end_time' => ['>=', $now0],
'show_time' => ['<=', $now0],
'goods_id' => $goods_id,
'is_end' => 0
];
$rs1 = M('flash_sale')->where($where1)->find();
if (!empty($rs1)) {
$onlybuy = $rs1["goods_num"] - $rs1["buy_num"];
if ($storecount1 < $onlybuy) {
$this->ajaxReturn(['code' => -1,
'msg' => '该商品有参加秒杀活动,库存数量不能小于活动允许购买的数量', 'count' => $ggg['store_count']]);
}
}
break;
case 4:
$where2 = [
'end_time' => ['>=', $now0],
'start_time' => ['<=', $now0],
'goods_id' => $goods_id,
'is_end' => 0,
'is_show' => 1,
];
$rs2 = M('integral_buy')->where($where2)->find();
if (!empty($rs2)) {
$onlybuy = $rs2["limitqty"] - $rs2["buy_num"];
if ($storecount1 < $onlybuy) {
$this->ajaxReturn(['code' => -1,
'msg' => '该商品有参加积分购,库存数量不能小于活动允许购买的数量', 'count' => $ggg['store_count']]);
}
}
break;
}
/*ok*/
$this->ajaxReturn(['code' => 1]);
}
// 商品搬家
public function goods_move()
{
set_time_limit(0);//剪切图片避免30秒超时,0表示不限时
$name = I('name');//网址关键字(1688、taobao、tmall)
$UserAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; .NET CLR 3.5.21022; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, I('url'));
curl_setopt($curl, CURLOPT_HEADER, 0); //0表示不输出Header,1表示输出
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_ENCODING, '');
curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$text = curl_exec($curl);
$text = mb_convert_encoding($text, 'utf-8','GB2312');
// echo curl_errno($curl); //返回0时表示程序执行成功 如何从curl_errno返回值获取错误信息
// $text = file_get_contents(I('url'));
// 获取网页主图
if ($name == '1688') {
// 阿里巴巴
preg_match('/<ul[^>]*class=\"nav nav-tabs fd-clr\"[^>]*>(.*?)<\/ul>/is', $text, $ul);
preg_match_all('/<img[^>][^r]*rc=\"([^"]*)\"[^>]*>/', $ul[1], $m_img);
foreach ($m_img[0] as $k => $v) {
if (stripos($v, 'data-lazy-src')) {
preg_match('/data-lazy-src=\"(.*?)\"/', $v, $src);
$m_img[1][$k] = $src[1];
}
}
} else {
// 天猫、淘宝
preg_match('/<ul[^>]*id=\"J_UlThumb\"[^>]*>(.*?)<\/ul>/is', $text, $ul);
preg_match_all('/<img[^>][^r]*rc=\"([^"]*)\"[^>]*>/', $ul[1], $m_img);
}
// 本地存储路径
$path = 'goods/' . cookie('newshop_admin_erpid') . '/' . date('Y') . '/' . date('m-d') . '/';
// 保存在腾讯云
vendor('qcloudcos.myqcloudcos');
$resfolder = Myqcloudcos::statFolder('wxd', UPLOAD_PATH . $path);
// 判断腾讯云是否存在路径
if ($resfolder && $resfolder['code'] != 0) {
Myqcloudcos::createFolder('wxd', UPLOAD_PATH . $path);//创建目录
}
// 判断本地是否存在路径
if (!file_exists(UPLOAD_PATH . $path)) {
mkdir(UPLOAD_PATH . $path,0777,true);//创建目录
}
foreach ($m_img[1] as $k => $v) {
// $src = 'http:' . strstr($v, '.jpg', true) . 'jpg';//主图淘宝天猫网上地址
preg_match('/(.*?)(_50x50.jpg|_60x60q90.jpg|60x60.jpg)/', $v, $src);
if ($name == '1688') {
$I_src = trim(str_replace('.60x60', '', $src[0]));//主图阿里巴巴网上地址
} else {
$I_src = 'https:' . $src[1];//主图淘宝天猫网上地址
}
$img_f = file_get_contents($I_src);
$ImgName = 'WXD_' . md5(microtime(true)) . '.jpg';
$saveFileName = $path . $ImgName;//保存路径加文件名
file_put_contents(UPLOAD_PATH . $saveFileName, $img_f);
// 剪切图片
m_cut_img($ImgName, ROOT_PATH . '/' . UPLOAD_PATH . $path);
// 图片水印处理
// $water = tpCache('water', getAdmStoId());
// $original_img = "./public/upload/" . $saveFileName;
// $image = \think\Image::open($original_img);
// if ($water['is_mark'] == 1) {
// if ($water['mark_type'] == 'img' && !empty($water['mark_img'])) {
// try {
// if (file_exists(ROOT_PATH . $water['mark_img'])) {
// $image->open($original_img)->water("." . $water['mark_img'], $water['mark_position'], $water['mark_degree'])->save($original_img);
// }
// } catch (Exception $e) {
// return NOIMG;
// }
// } else {
// //检查字体文件是否存在
// if (file_exists('./zhjt.ttf')) {
//
// $image->open($original_img)->text($water['mark_text'], './zhjt.ttf', 20, '#000000', $water['mark_position'])->save($original_img);
// }
// }
//
// }
//商品表的主表生成小图
//生成小图
m_cut_img($ImgName, ROOT_PATH . '/public/upload/' . $path, 400, 1);
$slocalpath = ROOT_PATH . '/' . UPLOAD_PATH . $path . 's_' . $ImgName;
$sypath = '/' . UPLOAD_PATH . $path . 's_' . $ImgName;
Myqcloudcos::upload('wxd', $slocalpath, $sypath);
//上传到腾讯云
$localpath = ROOT_PATH . '/' . UPLOAD_PATH . $saveFileName;
$ypath = '/' . UPLOAD_PATH . $saveFileName;
$res = Myqcloudcos::upload('wxd', $localpath, $ypath);
mlog(json_encode($res), "imageUp");
$img_src[] = '/public/upload/' . $saveFileName;//图片路径名
}
delFile(ROOT_PATH . '/' . UPLOAD_PATH . "/" . $path);//删除本地图片
switch ($name) {
case '1688':
preg_match('/<div[^>]*id=\"desc-lazyload-container\"[^>]*data-tfs-url=\"(.*?)\"/', $text, $url0);
$url = $url0[1];
$text0 = file_get_contents($url);
preg_match_all('/<img[^>][^r].*?rc=\\\"([^"]*)\\\"[^>]*>/', $text0, $img0);
break;
case 'taobao':
preg_match('/<script[^>]*>[^<]*<\/script>/is', $text, $content);//页面js脚本
preg_match('/descUrl(.*),/', $content[0], $desc);
preg_match('/\?(.*):/', $desc[0], $url0);
$url = 'http:' . trim(str_replace('\'', '', $url0[1]));
$text0 = file_get_contents($url);
preg_match_all('/<img[^>][^r].*?rc=\"([^"]*)\"[^>]*>/', $text0, $img0);
break;
case 'liangxinyao':
case 'tmall':
preg_match_all('/<script[^>]*>[^<]*<\/script>/is', $text, $content);//页面js脚本
foreach ($content[0] as $v) {
preg_match('/descUrl(.*)fetchDcUrl/', $v, $desc);
if (!empty($desc)) {
preg_match('/:(.*),/', $desc[0], $url0);
$url = 'http:' . trim(str_replace('"', '', $url0[1]));
$text0 = file_get_contents($url);
preg_match_all('/<img[^>][^r].*?rc=\"([^"]*)\"[^>]*>/', $text0, $img0);
break;
}
}
}
$html = '';
mlog("m:".$text0,"goods_move/".getAdmStoId());
mlog("g:".json_encode($img0),"goods_move/".getAdmStoId());
foreach ($img0[1] as $src) {
$html .= '<img src="' . $src . '">';
}
// dump($img1);die;
return json(['html' => $html, 'img' => $img_src]);
}
// 美妆图库
public function goods_snap()
{
$sku = I('sku');
// 过滤掉ppt、tpty、cdzy
//$store = M('store')->where('ERPId in ("ppt","tpty","cdzy")')->field('store_id')->select();
//$store = M('store')->where('ERPId in ("ppt")')->field('store_id')->select();
//foreach ($store as $v) {
//$store_list .= $v['store_id'] . ',';
//}
//$store_list = substr($store_list, 0, strlen($store_list) - 1);//去除最后一个字符,
$res = M('barcodegoods')->where("sku='" . $sku ."' and store_id not in(1,23,39) and goods_content is not null")->find();
if (empty($res)) {
return json(['code' => -1, 'msg' => '美妆图库还没有记录']);
}
$img = M('barcodegoods_images')->where(['goods_id' => $res['goods_id'], 'ismain' => 0])->select();
return json(['code' => 1, 'msg' => '获取成功', 'des' => $res, 'img' => $img]);
}
// 添加到美妆图库
public function mztk($data, $num)
{
$stoid = getAdmStoId();
$erp = getERPId();
if ($erp != 'ppt' && $erp != 'tpty' && $erp != 'cdzy') {
$barcode = M('barcodegoods')->where('sku', $data['sku'])->find();
if (empty($barcode)) {
$bar_data['sku'] = $data['sku'];
$bar_data['goods_sn'] = $data['goods_sn'];
$bar_data['goods_name'] = $data['goods_name'];
$bar_data['store_id'] = $stoid;
$bar_data['goods_content'] = $data['goods_content'];
$bar_data['original_img'] = $data['original_img'];
$bar_data['sort'] = M('barcodegoods')->where('')->Max('sort') + 1;
$bar_id = M('barcodegoods')->add($bar_data);
$bar_img[] = array('goods_id' => $bar_id, 'image_url' => $data['original_img'], 'ismain' => 1);
$bar_imgs = I('goods_images/a');
if (count($bar_imgs) > $num) {
if ($num == 2) {
array_shift($bar_imgs);
}
array_pop($bar_imgs); // 弹出最后一个
foreach ($bar_imgs as $v) {
$bar_img[] = array('goods_id' => $bar_id, 'image_url' => $v, 'ismain' => 0);
}
}
M('barcodegoods_images')->insertAll($bar_img);
$Goods['is_enable'] = 1;
} else {
// 查找美妆图库那条记录归属哪个商家
$erp = M('store')->where('store_id', $barcode['store_id'])->field('ERPId')->find()['ERPId'];
if ($erp == 'ppt' || $erp == 'tpty' || $erp == 'cdzy' || empty($erp)) {
$bar_data['goods_sn'] = $data['goods_sn'];
$bar_data['goods_name'] = $data['goods_name'];
$bar_data['store_id'] = $stoid;
$bar_data['goods_content'] = $data['goods_content'];
$bar_data['original_img'] = $data['original_img'];
M('barcodegoods')->where('goods_id', $barcode['goods_id'])->update($bar_data);
M('barcodegoods_images')->where('goods_id', $barcode['goods_id'])->delete();
$bar_img[] = array('goods_id' => $barcode['goods_id'], 'image_url' => $data['original_img'], 'ismain' => 1);
$bar_imgs = I('goods_images/a');
if (count($bar_imgs) > $num) {
if ($num == 2) {
array_shift($bar_imgs);
}
array_pop($bar_imgs); // 弹出最后一个
foreach ($bar_imgs as $v) {
$bar_img[] = array('goods_id' => $barcode['goods_id'], 'image_url' => $v, 'ismain' => 0);
}
}
M('barcodegoods_images')->insertAll($bar_img);
if (!empty($erp)) {
$goods_edit = M('goods')->where('store_id=' . $barcode['store_id'] . ' and sku=' . $data['sku'])->find()['goods_id'];
M('goods')->where('goods_id', $goods_edit)->update(['is_enable' => 0]);
}
$Goods['is_enable'] = 1;
}
}
}
}
// 导入数据
public function import_data()
{
$type = I('type/d');
$page = I('p/d', 1);
$stoid = getAdmStoId();
$erpid = getERPId();
$tk = tpCache('shop_info.api_token', $stoid);
if ($type == 1) {
$res = getApiData_java('/api/erp/msg/class/page', $erpid, null, $page, 50);
$data = json_decode($res, true);
$all = ceil($data['data']['total'] / 50);//总页数
if ($data['data']['pageData']) {
if ($page == $all) {
/*---插入活动记录表---*/
$imactdata["store_id"] = $stoid;
$imactdata["type"] = 101;
$imactdata["time"] = time();
$imactdata["state"] = 1;
M("import_active")->save($imactdata);
}
foreach ($data['data']['pageData'] as $k => $v) {
$parent_id = 0;
$lev = 1;
if ($v['ParentClassNo'] != -1) {
$rr = M("goods_category")->where(array('store_id'=>$stoid,'class_no'=>$v['ParentClassNo']))->field('id,level,parent_id')->find();
if ($rr) {
$parent_id = $rr['id'];
$lev = $rr['level'] + 1;
} else {
preg_match_all('/\((.*?)\)/', $v['ClassName'], $class);
$lev = count($class[1]);
$parent_id = $class[1][1];
$rr['parent_id'] = $class[1][0];
mlog($v['CName'] . '暂时没有上级分类:'.$v['ParentClassNo'], 'import/'.$stoid);
// continue;
}
}
//season 小级4级才导入
if ($lev < 4) {
$check = M('goods_category')->where(['store_id' => $stoid, 'class_no' => $v['ClassNo']])->count();
if (empty($check)) {
$import['name'] = $v['CName'];
$import['mobile_name'] = $v['CName'];
if($parent_id) {
$import['parent_id'] = $parent_id;
}
$import['level'] = $lev;
$import['sort_order'] = $k;
$import['version'] = 'mshop_category_' . $stoid . '';
$import['is_show'] = 1;
$import['is_hot'] = 0;
$import['cat_group'] = 0;
$import['commission_rate'] = 0;
$import['store_id'] = $stoid;
$import['move_classid'] = $v['Id'];
$import['class_no'] = $v['ClassNo'];
$insert_id = M('goods_category')->save($import);
if ($insert_id) {
/*--分类最多3级--*/
if ($lev == 1) {
$path = '0_' . $insert_id;
}
if ($lev == 2) {
$path = '0_' . $parent_id . '_' . $insert_id;
}
if ($lev == 3) {
$path = '0_' . $rr['parent_id'] . '_' . $parent_id . '_' . $insert_id;
}
$upd['parent_id_path'] = $path;
$updataeinfo=M('goods_category')->where('id', $insert_id)->save($upd);
}
}
}
}
return json(['code' => 1, 'msg' => '导入成功', 'all' => $all]);
} else {
return json(['code' => 0, 'msg' => '未找到数据']);
}
} else {
$res = getApiData_java('/api/erp/msg/brand/page', $erpid, null, $page, 50);
$data = json_decode($res, true);
$all = ceil($data['data']['total'] / 50);//总页数
if ($data['data']['pageData']) {
if ($page == $all) {
/*---插入活动记录表---*/
$imactdata["store_id"] = $stoid;
$imactdata["type"] = 102;
$imactdata["time"] = time();
$imactdata["state"] = 1;
M("import_active")->save($imactdata);
}
/*---开始导入数据---*/
foreach ($data['data']['pageData'] as $k => $v) {
$check = M('brand')->where(['name' => $v['CName'], 'store_id' => $stoid])->count();
if (empty($check)) {
$import['name'] = $v['CName'];
$zm = getFirstCharter($v['CName']);
if (empty($zm)) $zm = "";
$import['zm'] = $zm;
$import['desc'] = "";
// $import['sort']=$k;
$import['version'] = 'mshop_brand_' . $stoid . '';
$import['is_hot'] = 1;
$import['store_id'] = $stoid;
$import['move_classid'] = $v['Id'];
M('brand')->save($import); // 写入数据到数据库
}
}
return json(['code' => 1, 'msg' => '导入成功', 'all' => $all]);
} else {
return json(['code' => 0, 'msg' => '未找到数据']);
}
}
}
public function batchedit()
{
$ispost = I('ispost');
if ($ispost == 1) {
$key_word = I('key_word') ? trim(I('key_word')) : ''; // 关键词搜索
$intro = I('intro');//新品、推荐
$brand_id = I('brand_id');//品牌
$is_on_sale = I('is_on_sale');//上架、下架
$cat_id = I('cat_id');//分类
$cur_page = 1;//当前页数
if ((int)I('p/s') > 0) {
$cur_page = I('p/s');
}
$pagenum = 20;//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
}
$order1 = I('order1/s');
$order2 = I('order2/s');
//
$pricetype = I('pricetype/d');
$newpricetype = I('newpricetype/d');
$numtype = I('numtype/d');
$newnum = I('newnum');
$dotnum = I('dotnum/d');
$getids = I('ids');
$where = ' 1 = 1 '; // 搜索条件
$where .= " and store_id=" . getAdmStoId();
$model = M('Goods');
$goodsList = $model->where($where)->where('goods_id', array('in', $getids))->select();
$getupdatefile = $this->getprice_field($pricetype);
$getupdatefile1 = $this->getprice_field($newpricetype);
$rt = M("admin")->where('admin_id', getAdminId())->field('ERPUser')->find();
mlog("getupdatefile:".$getupdatefile,"batchedit/".getAdmStoId());
mlog("getupdatefile1:".$getupdatefile1,"batchedit/".getAdmStoId());
mlog("numtype:".$numtype,"batchedit/".getAdmStoId());
foreach ($goodsList as $kr => $vr) {
switch ($numtype) {
case "1":
$getupdatevalue = round($vr[$getupdatefile1] + $newnum, $dotnum);
break;
case "2":
$getupdatevalue = round($vr[$getupdatefile1] - $newnum, $dotnum);
break;
case "3":
if ($vr[$getupdatefile1]) {
$getupdatevalue = round($vr[$getupdatefile1] * $newnum, $dotnum);
}
break;
case "4":
if ($vr[$getupdatefile1]) {
$getupdatevalue = round($vr[$getupdatefile1] / $newnum, $dotnum);
}
break;
}
if ($getupdatevalue < 0) {
$getupdatevalue = 0;
}
$updatedata[$getupdatefile] = $getupdatevalue;
$updatedata['edit_time'] = time();
$updatedata['edit_ip'] = getIP();
$updatedata['edit_man'] = $rt['ERPUser'];
M('goods')->where(array('store_id' => getAdmStoId(), 'goods_id' => $vr['goods_id']))->save($updatedata);
}
return json(['code' => 0, 'msg' => '修改成功']);
}
$this->assign("urlparam", $_SERVER['REQUEST_URI']);
$sto_id=getAdmStoId();
$rank = tpCache('shopping.switch_list', $sto_id);//等级开关
$rank=json_decode($rank,true);
$rank_switch = $rank['rank_switch'];
$mz_switch = tpCache('shopping.is_beauty', $sto_id);//美妆开关
$switch = tpCache('distribut.switch', $sto_id);//分销开头
$this->assign('rank_switch', $rank_switch);
$this->assign('mz_switch', $mz_switch);
$this->assign('distribut_switch', $switch);
$pattern = tpCache('distribut.pattern', getAdmStoId());
$this->assign('pattern', $pattern);
return $this->fetch('', getAdmStoId());
}
public function batchedit1()
{
$ispost = I('ispost');
$batchtype = I('batchtype');
$getids = I('ids');
if ($ispost == 1) {
switch ($batchtype) {
case "1":
$exp_sum_type = I('exp_sum_type');
$uniform_exp_sum = I('uniform_exp_sum');
$updatedata['exp_sum_type'] = $exp_sum_type;
$updatedata['uniform_exp_sum'] = $uniform_exp_sum;
break;
case "2":
$updatedata['brand_id'] = I('brand_id');
break;
case "3":
$updatedata['nation_id'] = I('nation_id');
break;
case "4":
$cat_id_3=I('cat_id_3');
$cat_id_2=I('cat_id_2');
$cat_id_1=I('cat_id');
$gcat_id=$cat_id_3;
if(empty($cat_id_3)){ $gcat_id=$cat_id_2; }
if(empty($cat_id_2)){$gcat_id=$cat_id_1;}
$updatedata['cat_id'] = $gcat_id;
break;
case "5":
$isshow=I('isshow');
if ($isshow==1) {
$updatedata['on_time']=time()-7200;
$updatedata['down_time'] = "";
}else
{
$updatedata['down_time'] = time()-7200;
}
break;
case "6":
$distr_type=I('distr_type');
$updatedata['distr_type'] = $distr_type;
break;
case "7":
case "7":
$distr_type = I('give_integral');
$updatedata['give_integral'] = $distr_type;
break;
default:
break;
}
if ($updatedata) {
$rt=M("admin")->where('admin_id',getAdminId())->field('ERPUser')->find();
$updatedata['edit_time'] = time();
$updatedata['edit_ip'] = getIP();
$updatedata['edit_man'] = $rt['ERPUser'];
M('goods')->where(array('store_id' => getAdmStoId(), 'goods_id' => array('in', $getids)))->save($updatedata);
}
return json(['code' => 0, 'msg' => '修改成功']);
}
$GoodsLogic = new GoodsLogic();
switch ($batchtype) {
case "2":
$brandList = $GoodsLogic->getSortBrands();
$this->assign('brandList', $brandList);
break;
case "3":
$nationList = $GoodsLogic->getSortNations();
$this->assign('nationList', $nationList);
break;
case "4":
$cat_list = M('goods_category')->where(" store_id=" . getAdmStoId() . " and parent_id = 0")->order('sort_order')->select(); // 已经改成联动菜单
$this->assign('cat_list', $cat_list);
break;
}
$this->assign("urlparam", $_SERVER['REQUEST_URI']);
$this->assign("batchtype", $batchtype);
return $this->fetch('', getAdmStoId());
}
/*---
public function getprice_field($num)
{
switch ($num)
{
case "1"://市场价
return "market_price";
break;
case "2"://手店
return "shop_price";
break;
case "3"://库存
return "store_count";
break;
case "4"://已售
return "sales_sum";
break;
case "5"://限购
return "viplimited";
break;
case "6"://美妆价
return "mz_price";
break;
case "7"://等级售价1
return "cardprice1";
break;
case "8"://等级售价2
return "cardprice2";
break;
case "9"://等级售价3
return "cardprice3";
break;
}
}
--*/
public function getprice_field($num)
{
switch ($num) {
case "1"://市场价
return "market_price";
break;
case "2"://手店
return "shop_price";
break;
case "3"://库存
return "store_count";
break;
case "4"://已售
return "sales_sum";
break;
case "5"://限购
return "viplimited";
break;
case "6"://佣金
return "commission";
break;
case "7"://一级分成
return "fir_rate";
break;
case "8"://二级分成
return "sec_rate";
break;
case "9"://三级分成
return "thi_rate";
break;
case "10"://等级售价1
return "cardprice1";
break;
case "11"://等级售价2
return "cardprice2";
break;
case "12"://等级售价3
return "cardprice3";
break;
case "13"://美妆价
return "mz_price";
break;
}
}
//season 20181008 选择性导入
public function search_brand()
{
$pagenum = 10;
$this->assign('pagenum', $pagenum);
return $this->fetch('', getAdmStoId());
}
public function ajax_search_brand()
{
$pagenum = I('pagenum/d', 10);
$page = I('p/d', 1);
$stoid = getAdmStoId();
$erpid = getERPId();
$tk = tpCache('shop_info.api_token', $stoid);
$brand_res=M('brand')->where(array('store_id'=>$stoid))->field('name')->select();
$newbrand_res=array();
foreach ($brand_res as $v=>$k)
{
$newbrand_res[$v]=$k['name'];
}
$keywords = I('keywords');
if ($keywords) {
$where=" cname like '%$keywords%'";
}
$res = getApiData('wxd.base.brand.list.get', $tk, null, $where, $page, $pagenum);
$data = json_decode($res, true);
$brandlist=$data['data'];
$newsbrandlist=array();
foreach ($brandlist as $v=>$k)
{
$newsbrandlist[$v]['id']=$k['id'];
$newsbrandlist[$v]['cname']=$k['cname'];
$newsbrandlist[$v]['classno']=$k['classno'];
if (in_array($k['cname'],$newbrand_res))
{
$newsbrandlist[$v]['isexsit']=1;
}
else{
$newsbrandlist[$v]['isexsit']=0;
}
}
$count = $data['count'];
$Page = new AjaxPage($count, $pagenum);
$show = $Page->show();//分页显示输出
$this->assign('page', $show);//赋值分页输出
$this->assign('brandlist', $newsbrandlist);
$this->assign('pager', $Page);//赋值分页输出
$this->assign('brand_res', $brand_res);//当前已有的品牌列表
return $this->fetch('', getAdmStoId());
}
//选择导入单个品牌
function addBrand()
{
$getstoid = getAdmStoId();
$getcname = urldecode(urldecode(I('cname')));
if (empty($getcname)) {
return json(array('status' => -1, 'msg' => '名称为空'));
}
$res = M('brand')->where(array('store_id' => $getstoid, 'name' => $getcname))->find();
if ($res) {
return json(array('status' => -1, 'msg' => '品牌【' . $getcname . '】已存在!'));
}
$getzm = getFirstCharter($getcname);
$data['store_id'] = $getstoid;
$data['zm'] = substr($getzm, 0, 1);
$data['name'] = $getcname;
$rt = M("admin")->where('store_id', $getstoid)->where('admin_id', getAdminId())->field('ERPUser')->find();
$data['add_time'] = time();
$data['edit_ip'] = getIP();
$data['edit_man'] = $rt['ERPUser'];
$m = Db::query("select max(sort)so from wxd_brand where store_id=" . getAdmStoId());
$md = (int)$m[0]["so"];
$md++;
$data["sort"] = $md;
M("Brand")->insert($data);
return json(array('status' => 1, 'msg' => '导入成功!'));
}
//批量导入
function addbatchBrand()
{
$getstoid = getAdmStoId();
$getcname = urldecode(urldecode(I('cname')));
if (empty($getcname)) {
return json(array('status' => -1, 'msg' => '名称为空'));
}
$getcname1 = explode(',', $getcname);
$rt = M("admin")->where('store_id', $getstoid)->where('admin_id', getAdminId())->field('ERPUser')->find();
foreach ($getcname1 as $v => $k) {
if ($k) {
$res = M('brand')->where(array('store_id' => $getstoid, 'name' => $k))->find();
if (empty($res)) {
$getzm = getFirstCharter($k);
$data['store_id'] = $getstoid;
$data['zm'] = substr($getzm, 0, 1);
$data['name'] = $k;
$data['add_time'] = time();
$data['edit_ip'] = getIP();
$data['edit_man'] = $rt['ERPUser'];
$m = Db::query("select max(sort)so from wxd_brand where store_id=" . getAdmStoId());
$md = (int)$m[0]["so"];
$md++;
$data["sort"] = $md;
M("Brand")->insert($data);
}
}
}
return json(array('status' => 1, 'msg' => '导入成功!'));
}
public function search_category()
{
$pagenum = 10;
$this->assign('pagenum', $pagenum);
return $this->fetch('', getAdmStoId());
}
public function ajax_search_category()
{
$pagenum = I('pagenum/d', 10);
$page = I('p/d', 1);
$stoid = getAdmStoId();
$erpid = getERPId();
$tk = tpCache('shop_info.api_token', $stoid);
$class_res=M('goods_category')->where(array('store_id'=>$stoid,'parent_id'=>0))->field('name')->select();
$newclass_res=array();
foreach ($class_res as $v=>$k)
{
$newclass_res[$v]=$k['name'];
}
$where = array('ParentClassNo' => -1);
$keywords = I('keywords');
if ($keywords) {
$where .= array('cname' => $keywords);
}
$res = getApiData('wxd.base.class.list.get', $tk, null, $where, $page, $pagenum);
$data = json_decode($res, true);
$count = $data['count'];
$classlist=$data['data'];
$newclasslist=array();
foreach ($classlist as $v=>$k)
{
$newclasslist[$v]['id']=$k['id'];
$newclasslist[$v]['cname']=$k['cname'];
$newclasslist[$v]['classno']=$k['classno'];
if (in_array($k['cname'],$newclass_res))
{
$newclasslist[$v]['isexsit']=1;
}
else{
$newclasslist[$v]['isexsit']=0;
}
}
$Page = new AjaxPage($count, $pagenum);
$show = $Page->show();//分页显示输出
$this->assign('page', $show);//赋值分页输出
$this->assign('brandlist', $newclasslist);
$this->assign('pager', $Page);//赋值分页输出
return $this->fetch('', getAdmStoId());
}
//单个导入
public function addcategory()
{
$page = I('p/d', 1);
$stoid = getAdmStoId();
$erpid = getERPId();
$getclassno=urldecode(urldecode(I('classno')));
if (empty($getclassno))
{
return json(['code' => -1, 'msg' => '导入失败,请选择要导入的分类']);
}
$getclassno1 = explode(',', $getclassno);
foreach ($getclassno1 as $v => $k) {
if ($k) {
$where=" classname like '%($k)%'";
$tk = tpCache('shop_info.api_token', $stoid);
$res = getApiData('wxd.base.class.list.get', $tk, null, $where, $page, 50);
$data = json_decode($res, true);
$all = ceil($data['count'] / 50);//总页数
if (!empty($data['data'])) {
foreach ($data['data'] as $k => $v) {
$parent_id = 0;
$lev = 1;
if ($v['ParentClassNo'] != -1) {
$rr = M("goods_category")->where(['class_no' => $v['ParentClassNo'], 'store_id' => $stoid])->field('id,level,parent_id')->find();
if ($rr) {
$parent_id = $rr['id'];
$lev = $rr['level'] + 1;
} else {
preg_match_all('/\((.*?)\)/', $v['classname'], $class);
$lev = count($class[1]);
$parent_id = $class[1][1];
$rr['parent_id'] = $class[1][0];
// continue;
}
}
//season 小级4级才导入
if ($lev < 4) {
$check = M('goods_category')->where(['store_id' => $stoid, 'class_no' => $v['classno']])->count();
if (empty($check)) {
$import['name'] = $v['cname'];
$import['mobile_name'] = $v['cname'];
$import['parent_id'] = $parent_id;
$import['level'] = $lev;
$import['version'] = 'mshop_category_' . $stoid . '';
$import['is_show'] = 1;
$import['is_hot'] = 0;
$import['cat_group'] = 0;
$import['commission_rate'] = 0;
$import['store_id'] = $stoid;
$import['move_classid'] = $v['id'];
$import['class_no'] = $v['classno'];
$insert_id = M('goods_category')->add($import);
/*--分类最多3级--*/
if ($lev == 1) {
$path = '0_' . $insert_id;
}
if ($lev == 2) {
$path = '0_' . $parent_id . '_' . $insert_id;
}
if ($lev == 3) {
$path = '0_' . $rr['parent_id'] . '_' . $parent_id . '_' . $insert_id;
}
$upd['parent_id_path'] = $path;
M('goods_category')->where('id', $insert_id)->save($upd);
}
}
}
}
}
}
return json(['code' => 1, 'msg' => '导入成功']);
}
//线下未核销订单(占用数量列表)
public function goods_erplist()
{
$getAdmStoId = getAdmStoId();
$pagenum = 10;//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
}
$goods_id=I('goods_id');
$model = M("erp_yqty");
$where = " 1=1 ";
$keyword = urldecode(urldecode(I('keyword')));
if ($goods_id)
{
$where .= " and a.goods_id=".$goods_id;
}
if ($keyword) {
$where.=" and (b.pickup_name like '%$keyword%' or b.pickup_no like '%$keyword%')";
}
$where .= " and a.store_id=".$getAdmStoId;
$where.=" and a.out_qty>0 ";
$count = $model->alias('a')
->join('pick_up b','a.pickup_id=b.pickup_id','left')
->where($where)->count();
$sumout_qty = $model->alias('a')
->join('pick_up b','a.pickup_id=b.pickup_id','left')
->where($where)->sum('out_qty');
$Page = $pager = new Page($count, $pagenum);
$list = $model->alias('a')
->join('pick_up b','a.pickup_id=b.pickup_id','left')
->where($where)
->order("a.id desc")
->field('a.*,b.pickup_name,b.pickup_no')
->limit($Page->firstRow . ',' . $Page->listRows)
->select();
$show = $Page->show();
$this->assign('pager', $pager);
$this->assign('show', $show);
$this->assign('sumout_qty', $sumout_qty);
$this->assign('goods_id', $goods_id);
$this->assign('list', $list);
$this->assign('keyword', $keyword);
$this->assign('stoid', $getAdmStoId);
$this->assign('pagenum', $pagenum);
$this->assign('oldurl', urlencode(curPageURL()));
return $this->fetch('', getAdmStoId());
}
//清除三级分成
function goodsThirRemove()
{
$savedata['thi_rate']=0;
$updategoods=M('goods')->where(array('store_id'=>getAdmStoId(),'thi_rate'=>array('neq',0)))->save($savedata);
return json(['code' => 1, 'msg' => '操作成功']);
}
}