Goods.php
93.2 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
<?php
/**
* tpshop
* ============================================================================
* * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: IT宇宙人 2015-08-10 $
*/
namespace app\mobile\controller;
use think\AjaxPage;
use think\Cache;
use think\Cookie;
use think\Page;
use think\Db;
class Goods extends MobileBase
{
public function index()
{
// $this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover,{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>!</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
// $sto=tpCache('shop_info',$stoid);
// if($user['erpvipid']) //已绑定线下会员
// {
// $where['VIPId']=$user['erpvipid'];
//
// $cardinfo =getApiData("wxd.mem.vipinfo.list.get",$sto['api_token'],null,$where);
// $cardinfo=json_decode($cardinfo,true);
// if($cardinfo['code']==1 && $cardinfo['data'][0]['GradeCardID']!='')
// {
// $user['card_field']=$cardinfo['data'][0];
// $expiredate=$cardinfo['ExpiryDate'];
// $expireday=$cardinfo['YExpiryDate'];
// $user['card_expiredate']=date("Y-m-d",strtotime("$expiredate +$expireday day"));
// }
//
// }
return $this->fetch('', getMobileStoId());
}
/**
* 分类列表显示
*/
public function categoryList()
{
//tpCache()配置
$bconf=tpCache("basic",getMobileStoId());
/*--手机端三级分类--*/
$getype = I('type/d', 0);
$bconf= $bconf['switch_list'];
$bconf= json_decode($bconf, true);
$is_newgoodstpey =$bconf["is_newsgoodstype"];
//新旧版本的控制器
$this->assign('is_newgoodstpey', $is_newgoodstpey);
if ($is_newgoodstpey!=1) {
switch ($getype) {
case 0:
$goods_category_tree = get_goods_category_tree_mobile();
$this->cateTrre = $goods_category_tree;
if (empty($goods_category_tree)) {
$this->assign('goods_category_tree', '');//类别
} else {
$this->assign('goods_category_tree', $goods_category_tree);//类别
}
break;
case 2:
$zmsql = "select zm from __PREFIX__brand where is_hot=1 and store_id=" . getMobileStoId() . " group by zm";
$brand_zm = DB::query($zmsql);
foreach ($brand_zm as $val) {
$zmsql1 = "select id,name,logo,imgtype from __PREFIX__brand where is_hot=1 and store_id=" . getMobileStoId() . " and zm='" . $val['zm'] . "' order by sort asc";//
$brand_zm1 = DB::query($zmsql1);
$arr[] = ['zm' => $val['zm'], 'tmenu' => $brand_zm1];
}
if (empty($arr)) {
$this->assign('brand_list', '');//品牌
} else {
$this->assign('brand_list', $arr);//品牌
}
$this->assign('brand_zm', $brand_zm);
break;
case 1:
$nationlist = M('nation')->where(' is_hot=1 and store_id=' . getMobileStoId())->order('sort')->select();
if (empty($nationlist)) {
$this->assign('nation_list', '');//国别
} else {
$this->assign('nation_list', $nationlist);//国别
}
break;
}
} else {
//国别
$nationlist = M('nation')->where(' is_hot=1 and store_id=' . getMobileStoId())->order('sort')->select();
if (empty($nationlist)) {
$this->assign('nation_list', '');//国别
} else {
$this->assign('nation_list', $nationlist);//国别
$is_nationlist = 1;
$this->assign('is_nationlist', $is_nationlist);
}
//品牌
$zmsql = "select zm from __PREFIX__brand where is_hot=1 and store_id=" . getMobileStoId() . " group by zm";
$brand_zm = DB::query($zmsql);
foreach ($brand_zm as $val) {
$zmsql1 = "select id,name,logo,imgtype from __PREFIX__brand where is_hot=1 and store_id=" . getMobileStoId() . " and zm='" . $val['zm'] . "' order by sort asc";//
$brand_zm1 = DB::query($zmsql1);
$brand_img[] = $brand_zm1;
//$arr[] = ['zm' => $val['zm'], 'tmenu' => $brand_zm1];
}
if (empty($brand_img)) {
$this->assign('brand_list', '');//品牌
} else {
$brand = 2;
$this->assign('brand', $brand);
$this->assign('brand_list', $brand_img);//品牌
}
$this->assign('brand_zm', $brand_zm);
}
//一级分类
$goods_category_tree = get_goods_category_tree_mobile();
$this->cateTrre = $goods_category_tree;
if (empty($goods_category_tree)) {
$this->assign('goods_category_tree', '');//类别
} else {
$this->assign('goods_category_tree', $goods_category_tree);//类别
}
upload_ylp_log('分类列表');
return $this->fetch("", getMobileStoId());
}
//商品分类点击一级的ajax
public function ajaxGoodsBrand()
{
// 点击的分类id
$brand_id = I('brand_id');
$goods_category_tree = get_goods_category_tree_mobile();
$this->cateTrre = $goods_category_tree;
if (!empty($goods_category_tree)) {
$arrs=array();
$kz=1;
$arrs["is_three"]=0;
foreach ($goods_category_tree as $key => $value) {
if (!empty($value["tmenu"])) {
$count = count($value["tmenu"]);
foreach ($value["tmenu"] as $ke => $val) {
if ($brand_id == $val['parent_id']) {
if( $kz==1 ) {
$arrs[] = $value["tmenu"];
$kz=2;
}
if(!empty($val["sub_menu"])){
$arrs["is_three"]=1;
}
if ($ke == $count-1)
{
return json(['code' => 0, 'msg' => '成功', 'err_data' => $arrs]);
}
}
}
}else{
$arrs=[];
return json(['code' => 0, 'msg' => '成功', 'err_data' => $arrs]);
}
}
}
}
/**
* 商品列表页
*/
public function goodsList()
{
$uid = Cookie::get('user_id');
$user = session('user');
$this->assign('uid', $uid);
$key = "goodsList";
if ($uid) {
$key .= $uid;
}
$co = Cache::get($key);
/*--如果是本页清理--*/
$clearcache = I('clearcache');
if ($clearcache == 1) {
Cache::rm($key);
Cache::rm($key . '_url');
$co = 0;
} else {
/*--如果返回的地址不一样--*/
$url1 = Cache::get($key . '_url');
$url2 = curHostURL() . $_SERVER['REQUEST_URI'];
if ($url1 != $url2) {
Cache::rm($key);
Cache::rm($key . '_url');
$co = 0;
}
}
$stoid = I('stoid/d');
if (empty($co)) {
$filter_param = array(); // 帅选数组
$id = I('id/d', 0); // 当前分类id
$brand_id = I('brand_id/d', 0); //品牌
$nation_id = I('nation_id/d', 0);//国别
$price = I('price', ''); // 价钱
$gid = I('gid/d', 0); //分组
$sort = I('sort', 'sort'); // 排序
$sort_asc = I('sort_asc', 'asc'); // 排序
if($sort=="") $sort_asc="desc";
$start_price = trim(I('start_price', '0')); // 输入框价钱
$end_price = trim(I('end_price', '0')); // 输入框价钱
if ($start_price && $end_price) $price = $start_price . '-' . $end_price; // 如果输入框有价钱 则使用输入框的价钱
$filter_param['id'] = $id; //加入帅选条件中
$brand_id && ($filter_param['brand_id'] = $brand_id); //加入筛选条件中
$nation_id && ($filter_param['nation_id'] = $nation_id); //加入筛选条件中
$price && ($filter_param['price'] = $price); //加入筛选条件中
$goodsLogic = new \app\home\logic\GoodsLogic(); // 前台商品操作逻辑类
// 分类菜单显示
$goodsCate = M('GoodsCategory')->where("id", $id)->find();// 当前分类
//($goodsCate['level'] == 1) && header('Location:'.U('Home/Channel/index',array('cat_id'=>$id))); //一级分类跳转至大分类馆
$cateArr = $goodsLogic->get_goods_cate($goodsCate);
// 帅选 品牌 规格 属性 价格
$filter_goods_id =$filter_goods_id2= null;
$titlename = '';
$whereall=" ";
if (!empty($id)) {
$rrs = M('goods_category')->where('store_id',getMobileStoId())->where('id', $id)->find();
$titlename = $rrs['name'];
$cat_id_arr = getCatGrandson($id);
/*--商品修改。store_id筛选条件--*/
$filter_goods_id = M('goods')->where('store_id', getMobileStoId())->where("is_on_sale=1")->where("cat_id", "in", implode(',', $cat_id_arr))->getField("goods_id", true);
$whereall.=" and a.cat_id in (".implode(',', $cat_id_arr).")";
} else if (!empty($gid)) {
$rrs = M('goods_group')->where('store_id',getMobileStoId())->where('gpid', $gid)->find();
$titlename = $rrs['gpname'];
$filter_goods_id2=$filter_goods_id = explode(',', $rrs['gp_goodslist']);
} else {
if (!empty($brand_id)) {
$rrs = M('brand')->where('store_id',getMobileStoId())->where('id', $brand_id)->find();
$titlename = $rrs['name'];
}
if (!empty($nation_id)) {
$rrs = M('nation')->where('store_id',getMobileStoId())->where('id', $nation_id)->find();
$titlename = $rrs['name'];
}
$filter_goods_id = M('goods')->where('store_id', $stoid)->where("is_on_sale=1")->getField("goods_id", true);
}
$this->assign('titlename', $titlename);
// 过滤帅选的结果集里面找商品
if ($brand_id || $nation_id)// 品牌或者价格
{
if($brand_id) $whereall.=" and a.brand_id=".$brand_id;
if($nation_id) $whereall.=" and a.nation_id=".$nation_id;
$goods_id_1 = $goodsLogic->getGoodsIdByBrandPrice2($brand_id, $nation_id); // 根据 品牌 或者 价格范围 查找所有商品id
$filter_goods_id = array_intersect($filter_goods_id, $goods_id_1); // 获取多个帅选条件的结果 的交集
}
//筛选网站自营,入驻商家,货到付款,仅看有货,促销商品
//$sel = I('sel');
//if ($sel) {
// $goods_id_4 = $goodsLogic->get_filter_selected($sel, $cat_id_arr);
// $filter_goods_id = array_intersect($filter_goods_id, $goods_id_4);
//}
//$filter_menu = $goodsLogic->get_filter_menu($filter_param, 'goodsList'); // 获取显示的帅选菜单
/*--如果有价格条件--*/
$where = "";
if ($price) {
$pricearr = explode('-', $price);
$where = " having final_price>=" . $pricearr[0] . " and final_price<=" . $pricearr[1];
}
$time = time();
$where11 = "";
if ($filter_goods_id2) {
$filter_goods_id2_array = implode(",", $filter_goods_id2);
if ($filter_goods_id2_array && count($filter_goods_id2) > 0) {
$where11 = " and a.goods_id in(" . implode(',', $filter_goods_id2) . ")";
}
else
{
$where11 = " and a.goods_id=0";
}
}
$str = "select a.market_price,a.goods_name,a.goods_id,a.original_img, a.sales_sum,a.mz_price,a.prom_type,a.prom_id,a.cardprice1,a.cardprice2,a.cardprice3,a.is_mainshow,
CAST(case when (a.prom_type>0 and a.prom_type<3 and b.id<>'') or (a.prom_type=4 and b.is_show=1 and b.id<>'') or (a.prom_type=6 and b.id<>'') then b.prom_price
else a.shop_price end as decimal(9,2)) as final_price,b.prom_integral
from __PREFIX__goods a left join (select id,commission,is_show,prom_price,type,expression,prom_integral,goods_listid,good_object,prom_type from __PREFIX__activitylist where is_end=0 and (s_time<=" . $time . " or (warm_uptime<=" . $time . " and warm_uptime<>0)) and e_time>=" . $time . " and store_id=" . $stoid . ") as b on locate(CONCAT(',',a.goods_id,','),b.goods_listid)>0 and (b.good_object=1 or b.prom_type<>3) where a.store_id=" . $stoid . $where11 .$whereall. " and a.is_on_sale=1 and a.on_time<".$time." and (a.down_time>".$time." or a.down_time=0 ) and a.is_mainshow=1 " . $where . " order by " . $sort . " " . $sort_asc;
$arr = Db::query($str);
$count = count($arr);
$pricearr = get_arr_column($arr, 'final_price');
/*--各种帅选--*/
$filter_price = $goodsLogic->get_filter_price2($pricearr, $filter_param, 'goodsList'); // 帅选的价格期间
$filter_brand = $goodsLogic->get_filter_brand($filter_goods_id, $filter_param, 'goodsList', 1); // 获取指定分类下的帅选品牌
$filter_nation = $goodsLogic->get_filter_nation($filter_goods_id, $filter_param, 'goodsList', 1);// 获取指定分类下的帅选属性
/*--计算分页--*/
$end = I('p/d', 1) * 10;
$mshow = 0;
if ($count > 0) {
$fir = I('p/d', 1) * 10 - 10;
if ($count < $end) $end = $count;
for ($i = $fir; $i < $end; $i++) {
$arr[$i]['final_price'] = number_format($arr[$i]['final_price'], 2);
// if ($arr[$i]['mz_price'] == 0)
// $arr[$i]['mz_price'] =$arr[$i]['final_price'];
if ($arr[$i]['is_mainshow'] == 1)
$goods_list[] = $arr[$i];
}
//$filter_goods_id2 = get_arr_column($goods_list, 'goods_id');
//if ($filter_goods_id2)
// $goods_images = M('goods_images')->where("goods_id", "in", implode(',', $filter_goods_id2))
// ->cache("goods_list_goods_images_" . getMobileStoId())->select();
}
//$goods_category = M('goods_category')->where('is_show=1')
// ->cache("good_list_goods_category_" . getMobileStoId())->getField('id,name,parent_id,level'); // 键值分类数组
//$this->assign('goods_category', $goods_category);
//$this->assign('goods_images', $goods_images); // 相册图片
//$this->assign('filter_menu', $filter_menu); // 帅选菜单
//$this->assign('filter_spec', $filter_spec); // 帅选规格
//$this->assign('filter_attr', $filter_attr); // 帅选属性
$this->assign('goods_list', $goods_list);
$this->assign('filter_brand', $filter_brand);// 列表页帅选属性 - 商品品牌
$this->assign('filter_nation', $filter_nation);// 列表页帅选属性 - 国别
$this->assign('filter_price', $filter_price);// 帅选的价格期间
$this->assign('goodsCate', $goodsCate);
$this->assign('cateArr', $cateArr);
$rank_switch = tpCache('shopping.rank_switch',$stoid);//等级价格
$mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆价格
$this->assign('rank_switch', $rank_switch);
$this->assign('mz_switch', $mz_switch);
if (!empty($rank_switch)){
//$this->assign('rank_field',$user['card_field']);
$rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']);
$card_field=$rand_end>time()?$user['card_field']:0;
$this->assign('rank_field',$card_field);
//----读取等级卡标签---
$all_card=get_plus_price_arr($stoid);
if($all_card) {
$this->assign('all_card', $all_card);
//--读取卡的分类---
$new_card_dd = null;
foreach ($all_card as $kl => $vl) {
if ($vl) {
switch ($vl['CorrPrice']) {
case "Price1":
$new_card_dd['cardprice1'] = $vl['CardName'];
break;
case "Price2":
$new_card_dd['cardprice2'] = $vl['CardName'];
break;
case "Price3":
$new_card_dd['cardprice3'] = $vl['CardName'];
break;
}
}
}
$card_label = $new_card_dd[$card_field];
$len = mb_strlen($card_label, "utf-8");
if ($len > 4)
$card_label = mb_substr($card_label, 0, 4, "utf-8");
$this->assign('card_label', $card_label);
}
}
if (!empty($mz_switch)){
$this->assign('mz_vip',$user['is_mzvip']);
}
if ($count > $end) {
$mshow = 1;
}
$this->assign('mshow', $mshow);
$this->assign('filter_param', $filter_param); // 帅选条件
$this->assign('cat_id', $id);
//$this->assign('page', $page);// 赋值分页输出
$this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc');
C('TOKEN_ON', false);
upload_ylp_log('商品列表');
if (input('is_ajax'))
return $this->fetch('ajaxGoodsList', $stoid);
//return $this->fetch();
else
return $this->fetch('', $stoid);
//return $this->fetch();
} else {
Cache::rm($key);
Cache::rm($key . '_url');
$id = I('id/d', 0); // 当前分类id
$brand_id = I('brand_id/d', 0); //品牌
$nation_id = I('nation_id/d', 0);//国别
$price = I('price', ''); // 价钱
$filter_param['id'] = $id; //加入帅选条件中
$brand_id && ($filter_param['brand_id'] = $brand_id); //加入筛选条件中
$nation_id && ($filter_param['nation_id'] = $nation_id); //加入筛选条件中
$price && ($filter_param['price'] = $price); //加入筛选条件中
$this->assign('filter_param', $filter_param); // 帅选条件
return $this->fetch('goodsList_b', $stoid);
}
}
/**
* 商品列表页 ajax 翻页请求 搜索
*/
public function ajaxGoodsList()
{
$where = '';
$cat_id = I("id", 0); // 所选择的商品分类id
if ($cat_id > 0) {
$grandson_ids = getCatGrandson($cat_id);
$where .= " WHERE cat_id in(" . implode(',', $grandson_ids) . ") "; // 初始化搜索条件
}
/*--商品修改,store_id筛选条件--*/
$where .= ' and store_id=' . getMobileStoId();
$result = DB::query("select count(1) as count from __PREFIX__goods $where ");
$count = $result[0]['count'];
$page = new AjaxPage($count, 10);
$order = " order by goods_id desc"; // 排序
$limit = " limit " . $page->firstRow . ',' . $page->listRows;
$list = DB::query("select * from __PREFIX__goods $where $order $limit");
$this->assign('lists', $list);
$html = $this->fetch('ajaxGoodsList', getMobileStoId()); //return $this->fetch('ajax_goods_list');
upload_ylp_log('商品列表页');
exit($html);
}
/**
* 商品详情页
*/
public function goodsInfo()
{
C('TOKEN_ON', true);
$stoid = getMobileStoId();
//$user = session('user');
$user_id = cookie('user_id');
$user = M("users")->where("user_id",$user_id)->find();
$goodsLogic = new \app\home\logic\GoodsLogic();
$goods_id = I("get.id");
$is_inte_normal=I("is_inte_normal/d",0);
$now0 = time();
/*--活动判断--*/
$goods = M('Goods')->where("goods_id", $goods_id)->where('is_on_sale', 1)
//->where('is_mainshow', 1)
->where("on_time<" . $now0 . " and (down_time>" . $now0 . " or down_time=0)")
->field('goods_id,goods_name,brand_id,nation_id,cat_id,market_price,store_count,shop_price,sku,original_img,goods_sn,goods_spec,goods_color,
sales_sum,on_time,prom_id,prom_type,REPLACE(REPLACE(goods_remark,
CHAR(10),""), CHAR(13),"") as goods_remark,viplimited,distr_type,mz_price,cardprice1,cardprice2,cardprice3,spec_img')->find();
// $ylpapp_list=M('store_config')->where('store_id='.getMobileStoId())->find();//app使用
// $ylpapp_list=$ylpapp_list['ylpapp_list'];
if (empty($goods)) {
$this->error("此商品已经下架",
U('Mobile/index/index', array('stoid' => $stoid)));
}
if($is_inte_normal==1){ $goods['prom_type']=0;}
if (empty($goods['spec_img']))
$goods['spec_img'] = $goods['original_img'];
//有礼派APP
$getylpres=getylapp_res($stoid,'3');
if ($getylpres)
{
$this->assign('ylpres',$getylpres);
}
$this->buy_page_assign();
$rank_switch = tpCache('shopping.rank_switch', $stoid);//等级价格
$mz_switch = tpCache('shopping.is_beauty', $stoid);//美妆价格
$this->assign('mz_switch',$mz_switch);
$this->assign('rank_switch',$rank_switch);
//---关于销售规则---
$switch_list=tpCache('basic.switch_list', $stoid);
$switch_list=json_decode($switch_list,true);
$is_newsales_rules=$switch_list['is_newsales_rules'];
$this->assign('is_newsales_rules',$is_newsales_rules);
$mstore=tpCache('basic.sales_rules',$stoid);
$this->assign('sales_rules',$mstore);
$fid = "," . $goods_id . ',';
$where0 = "((warm_uptime<=" . $now0 . " and warm_uptime>0) or s_time<=" . $now0 . ") and " . $now0 . "<=e_time and goods_listid='" . $fid . "' and is_end=0";
$rrs = M('activitylist')->where($where0)->field('is_show')->find();
$rrs_str = M('activitylist')->where($where0)->field('is_show')->fetchSql(true)->find();
mlog("活动不行".$rrs_str,"activitylist/".$stoid);
if ($rrs) {
mlog("活动不行,类型".$goods['prom_type'],"activitylist/".$stoid);
switch ($goods['prom_type']) {
case "1"://限时抢购
//$this->redirect(U('Mobile/Activity/seckill_info', array('id' => $goods_id, 'stoid' => $stoid)));
$Event = \think\Loader::controller('mobile/Activity');
$Event->seckill_fun();
return $this->fetch('activity/seckill_info', getMobileStoId());
break;
case "2"://团购
//$this->redirect(U('Mobile/Activity/group', array('id' => $goods_id, 'stoid' => $stoid)));
$Event = \think\Loader::controller('mobile/Activity');
$Event->group_fun();
return $this->fetch('activity/group', getMobileStoId());
break;
case "4"://积分购
if ($rrs['is_show'] == 1 && $is_inte_normal!=1) {
//$this->redirect(U('Mobile/integral/integral_info', array('id' => $goods_id, 'stoid' => $stoid)));
$Event = \think\Loader::controller('mobile/Integral');
$Event->integral_fun();
return $this->fetch('integral/integral_info', getMobileStoId());
}
break;
case "6"://拼团
//$this->redirect(U('Mobile/Activity/group', array('id' => $goods_id, 'stoid' => $stoid)));
mlog("活动不行,类型".$rrs['is_show'],"activitylist/".$stoid);
if ($rrs['is_show'] == 1) {
mlog("活动不行,类型1212121","activitylist/".$stoid);
$Event = \think\Loader::controller('mobile/Team');
$Event->team_fun();
return $this->fetch('team/team_info', getMobileStoId());
break;
}
}
}
if (empty($goods)) {
$this->error('此商品不存在或者已下架');
return;
}
$this->assign('stoid', $stoid);
//如果商品有活动,要判断改活动是不是结束了
if($goods['prom_id']){
//如果是搭配促销的话
if($goods['prom_type']==5){
$act=M("collocation")->where("store_id",getMobileStoId())
->where("id",$goods['prom_id'])->find();
//如果是已经结束或者当前时间大于结束时间
if ($act['is_end'] == 1 || $now0 > $act['end_time']) {
M('Goods')->where("goods_id", $goods_id)->save(["prom_type" => 0, "prom_id" => 0]);
}
}else{
//---查找活动---
$wherea=" store_id=".getMobileStoId()." and act_id=".$goods['prom_id']." and prom_type=".$goods['prom_type']." and locate(',$fid,', goods_listid)>0";
$act = M('activitylist')
->where($wherea)
->field('is_end,e_time')->find();
if($act){
//如果是已经结束或者当前时间大于结束时间
if($act['is_end']==1 || $now0>$act['e_time']){
M('Goods')->where("goods_id",$goods_id)->save(["prom_type"=>0,"prom_id"=>0]);
}
}
}
}
$gconfig=M("giftuser_config")->where('store_id',getMobileStoId())->field('state')->find();
$this->assign('gconfig', $gconfig);
// $goods['prom_type']=0;
$is_chat = tpCache("basic.is_chat", $stoid);
$rs_server = M('storage_recharge_detail')
->where('store_id', $stoid)->where('admin_id<>0')
->where('end_time>' . $now0)
->find();
$this->assign('is_chat', $is_chat && $rs_server);
if ($goods['brand_id']) {
$brnad = M('brand')->where("id", $goods['brand_id'])->find();
$goods['brand_name'] = $brnad['name'];
}
if ($goods['nation_id']) {
$nation = M('nation')->where("id", $goods['nation_id'])->find();
$goods['nation_name'] = $nation['name'];
}
if ($goods['cat_id']) {
$cat = M('goods_category')->where("id", $goods['cat_id'])->find();
$goods['cat_name'] = $cat['name'];
}
$goods_images_list = M('GoodsImages')->where("goods_id", $goods_id)->order('ismain desc')->select(); // 商品 图册
$goods_videos = M('goods_videos')->where("goods_id", $goods_id)
->order('video_sort asc')->select(); // 商品 图册
if($goods_videos[0])
$this->assign("goods_videos", $goods_videos);
/*---规格筛选---*/
$filter_spec = M('goods')->where('sku', $goods['sku'])->where('store_id', $stoid)->where("is_on_sale", 1)
->where("on_time<" . $now0 . " and (down_time>" . $now0 . " or down_time=0 or down_time='' )")
->field('goods_id,erpwareid,goods_name,brand_id,nation_id,cat_id,goods_spec,goods_color,goods_unitname,goods_sn,sku,shop_price,
market_price,sales_sum,store_count,original_img,prom_type,REPLACE(REPLACE(goods_remark,
CHAR(10),""), CHAR(13),"") as goods_remark,mz_price,distr_type,cardprice1,cardprice2,cardprice3,spec_img,viplimited')
->order("sort")
->select();
foreach ($filter_spec as $k4 => $v4) {
$gidarr4[$v4['erpwareid']] = $v4['goods_id'];
}
/*-----查看销售规则,采用线下规则要计算所有规格的商品在线下的库存
$mstore=tpCache('basic.sales_rules',$stoid);
if($mstore==2){
$this->assign('is_bline',1);
mlog('获取线下库存','blinestore0');
$blinesto=getblinesto($gidarr4,getMobileStoId());
mlog('获取线下库存','blinestore0');
if($blinesto==-1){
$this->assign('err', 1);
mlog('系统获取线下库存失败','getdownkun/'.$stoid.'/'.$goods_id);
}else if($blinesto==-2){
$this->assign('err', 1);
mlog('系统未设置线下库存','getdownkun/'.$stoid.'/'.$goods_id);
}else {
$this->assign('sto_data', $blinesto);
}
}else{
$this->assign('is_bline',0);
}
----*/
//查看销售规则,采用线下规则要计算所有规格的商品在线下的库存
$mstore = tpCache('basic.sales_rules', $stoid);
if ($mstore == 2) {
$this->assign('is_bline', 1);
} else {
$this->assign('is_bline', 0);
}
$guige = "规格";
$gorder = 1;
$ary = null;
foreach ($filter_spec as $k => $v) {
/*-----过滤掉活动的商品-----*/
$now = time();
$wh0 = [
'end_time' => ['>=', $now],
'start_time' => ['<=', $now],
'id' => $v['prom_id'],
'goods_id' => $v['goods_id'],
'is_end' => 0,
];
$rs = M('group_buy')->where($wh0)->find();
if ($rs) {
unset($filter_spec[$k]);
continue;
}
$rs = M('integral_buy')->where($wh0)->where('is_show', 1)->find();
if ($rs) {
unset($filter_spec[$k]);
continue;
}
$rs = M('flash_sale')->where($wh0)->find();
if ($rs) {
unset($filter_spec[$k]);
continue;
}
$sp = trim($v["goods_spec"]);
$cn = trim($$v["goods_color"]);
if ($sp == "" && $cn == "") {
$tgg = $guige . $gorder;
$gorder++;
} else if ($sp != "" && $cn == "") {
$tgg = $sp;
} else if ($sp == "" && $cn != "") {
$tgg = $cn;
} else {
$tgg = $sp . "/" . $cn;
}
if (empty($v['spec_img']))
$filter_spec[$k]['spec_img'] = $v['original_img'];
/*--该商品此卖了多少件--*/
$filter_spec[$k]['guige'] = $tgg;
$filter_spec[$k]['curprice'] = $v['shop_price'];
if($v['goods_id']==$goods_id && $is_inte_normal==1){
$filter_spec[$k]['prom_type'] = 0;
}else {
if ($v['prom_type'] > 0) {
//找出活动的细节
$prom = $filter_spec[$k]['flash_sale'] = get_goods_promotion($v['goods_id']);
if ($prom['is_end'] != 1 && $prom['is_end'] != 4 && $prom['is_end'] != 2) {
$filter_spec[$k]['curprice'] = $filter_spec[$k]['flash_sale']['price'];
} else {
$filter_spec[$k]['prom_type'] = 0;
}
}
}
//---判断价格,等级价,美妆价----
if ($v['prom_type'] == 0 || $v['prom_type'] == 3 || $v['prom_type'] == 5) {
if ($user['is_mzvip'] && $v['mz_price'] > 0 && $mz_switch) {
$filter_spec[$k]['curprice'] = $v['mz_price'];
}
if ($rank_switch) {
if ($user['card_field'] && $v[$user['card_field']] > 0 && strtotime($user['card_expiredate']) > time()) {
$filter_spec[$k]['curprice'] = $v[$user['card_field']];
}
}
}
/*--规格排序--*/
if ($v["goods_id"] == $goods_id) {
//$filter_spec[$k]['viplimited'] = $goods['viplimited'];
$ary = $filter_spec[$k];
unset($filter_spec[$k]);
}
}
/*--规格排序--*/
array_unshift($filter_spec, $ary);
M('Goods')->where("goods_id=$goods_id")->save(array('click_count' => $goods['click_count'] + 1)); //统计点击数
$commentStatistics = $goodsLogic->commentStatistics($goods_id);// 获取某个商品的评论统计
$goods['guige'] = $ary['guige'];
/*-----当前价格-----*/
$curprice = $ary['curprice'];
$now = time();
$where = [
'end_time' => ['gt', $now], 'start_time' => ['lt', $now],
'id' => $goods['prom_id'], 'is_end' => 0,
];
$goods['discount'] = round($curprice / $goods['market_price'], 2) * 10;
if ($goods['prom_type'] == 3) {
$prom_active = M('prom_goods')
->where('store_id', $stoid)
->where($where)->find();
} else if ($goods['prom_type'] == 5) {
$collocation_active = M('collocation')
->where('store_id', $stoid)
->where($where)->field('id,title,img_url,end_time')->find();
if (!empty($collocation_active)) {
$collocation_active['max'] = $goods['shop_price'] + M('collocation_list')->where('prom_id', $goods['prom_id'])->order('price desc')->limit(0, 1)->field('price')->find()['price'];
$collocation_active['min'] = $goods['shop_price'] + M('collocation_list')->where('prom_id', $goods['prom_id'])->order('price asc')->limit(0, 1)->field('price')->find()['price'];
}
$this->assign('collocation', $collocation_active);
} else {
/*----
$prom_active = M('prom_goods')
->where('store_id', $stoid)
->where(['end_time' => ['gt', $now], 'start_time' => ['lt', $now], 'is_end' => 0, 'good_object' => 0])->find();
}---*/
$now=time();
$w1="(b.goods_listid='' or b.goods_listid is null or locate(',".$goods['goods_id'].",',b.goods_listid)=0)";
$prom_active = M('prom_goods')->alias('a')->join('activitylist b','b.act_id=a.id and b.prom_type=3')
->where('a.store_id', $stoid)->where($w1)
->where(['a.end_time' => ['gt', $now], 'a.start_time' => ['lt', $now], 'a.is_end' => 0, 'a.good_object' => 0])
->field('a.*')
->find();
}
if (!empty($prom_active)) {
$prom_lists = M('prom_goods_list')->where('prom_id', $prom_active['id'])->order('condition', 'asc')->select();
foreach ($prom_lists as $k => $v) {
$prom_list = json_decode($v['preferential_type'], true);
$prom_lists[$k]['condition'] = floatval($v['condition']);
$prom_lists[$k]['money'] = floatval(($prom_list['money']));
$prom_lists[$k]['sale'] = $prom_list['sale'];
$prom_lists[$k]['past'] = $prom_list['is_past'];
$prom_lists[$k]['int'] = $prom_list['int'];
$id = $prom_list['coupon'];
if ($id > 0) {
$coupon = M('coupon')->where(['id' => $id, 'send_start_time' => ['lt', $now], 'send_end_time' => ['gt', $now]])->field('id,money')->find();
$prom_lists[$k]['coupon'] = $coupon['money'];
$prom_lists[$k]['coupon_id'] = (int)$coupon['id'];
}
$id = $prom_list['gift'];
if ($id > 0) {
$gift = M('gift')->where(['id' => $id, 'start_time' => ['lt', $now], 'end_time' => ['gt', $now], 'goods_num' => ['>', 0], 'is_end' => 0])->field('id,goods_name,goods_id')->find();
$prom_lists[$k]['goods_name'] = $gift['goods_name'];
$prom_lists[$k]['gift_id'] = (int)$gift['id'];
}
$liid=$prom_list['libao'];
if($liid>0){
$lb = M('libao_form')->where(['id' => $liid, 'startime' => ['lt', $now], 'endtime' => ['gt', $now],'isdel' => 0])->field('id,lbtitle')->find();
$prom_lists[$k]['lbtitle'] = $lb['lbtitle'];
$prom_lists[$k]['lb_id'] = (int)$lb['id'];
}
}
$this->assign('prom_list', $prom_lists);// 商品促销
}
//修改美妆价
if ($goods['prom_type'] == 0 || $goods['prom_type'] == 3) {
//如果有美妆价和启用,大于0
if ($goods['mz_price'] > 0 && $user['is_mzvip'] && $mz_switch) {
$curprice = $goods['mz_price'];
}
//如果有等级价和启用,大于0
if ($rank_switch) {
if ($user['card_field'] && strtotime($user['card_expiredate']) > time() && $goods[$user['card_field']] > 0) {
$curprice = $goods[$user['card_field']];
//--- 如果卡还没有到期,前30天 --
if(strtotime($user['card_expiredate'])-time()>30*24*3600){
$this->assign("is_no_date",1);
}
}
}
}
//当前用户收藏
$user_id = cookie('user_id');
$collect = M('goods_collect')->where(array("goods_id" => $goods_id, "user_id" => $user_id))->count();
$goods_collect_count = M('goods_collect')->where(array("goods_id" => $goods_id))->count(); //商品收藏数
$this->assign('collect', $collect);
$this->assign('commentStatistics', $commentStatistics);//评论概览
$this->assign('filter_spec', $filter_spec);//规格参数
$this->assign('goods_images_list', $goods_images_list);//商品缩略图
$this->assign('goods', $goods);
$this->assign('goods_collect_count', $goods_collect_count); //商品收藏人数
$this->assign('collect', $collect); //是否收藏
$this->assign('curprice', $curprice); //价格
if ($rank_switch) {
//$this->assign('rank_field', $user['card_field']);
$rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']);
$card_field=$rand_end>time()?$user['card_field']:0;
//30天,要显示等级卡续费
if($rand_end>time() && $rand_end-time()<60*60*24*30 ){
$this->assign('is_near',1);
}
$this->assign('rank_field',$card_field);
$this->assign('card_expiredate',$user['card_expiredate']);
$rs_dd=get_plus_price_arr(getMobileStoId());
if($rs_dd) {
$new_card_dd = null;
foreach ($rs_dd as $kl => $vl) {
if ($vl) {
switch ($vl['CorrPrice']) {
case "Price1":
$new_card_dd['cardprice1'] = $vl['CardName'];
break;
case "Price2":
$new_card_dd['cardprice2'] = $vl['CardName'];
break;
case "Price3":
$new_card_dd['cardprice3'] = $vl['CardName'];
break;
}
}
}
$this->assign('card_data', $rs_dd);
$this->assign('new_card_dd', $new_card_dd);
}
}
if ($mz_switch) {
$this->assign('mz_vip', $user['is_mzvip']);
}
$mzprice_list = tpCache('shopping.mzprice_list',$stoid);//美妆条件
$mzprice_list=json_decode($mzprice_list,true);
$this->assign('mz_switch',$mz_switch);
$this->assign('mzprice_list',$mzprice_list);
$this->assign('switch', tpCache('shopping.switch_list', $stoid));
$t = time();
$prom_order = M("prom_order")
->where("store_id", getMobileStoId())
->where("start_time<=" . $t)
->where("end_time>=" . $t)
->where("is_close=0")->where('is_end', 0)
->order(" id desc")->limit(1)->select();
$this->assign('prom_order', $prom_order);
upload_ylp_log('商品详情');
//商品图片
$imgurl = getImg($goods['original_img'],curHostURL().NOIMG);
$msg = $this->img_curl_url($imgurl, 2);
$shareimg = $msg['data'];
$this->assign('shareimg',$shareimg);
//二维码也用64位
$shareurl=curHostURL().'/index.php/mobile/goods/goodsInfo/stoid/'.$stoid.'/id/'.$goods_id."/first_leader/".$user['user_id'];
$this->assign('shareurl',$shareurl);
$qc = new \app\home\controller\Index();
$shareurl=$qc->qr_code_64($shareurl);
$this->assign('shareurlimg',$shareurl);
return $this->fetch('', getMobileStoId());
}
/**
* 商品详情页
*/
public function detail()
{
// form表单提交
C('TOKEN_ON', true);
$goods_id = I("get.id/d");
$goods = M('Goods')->where("goods_id", $goods_id)->find();
$this->assign('goods', $goods);
upload_ylp_log('商品页-商品详情');
return $this->fetch('', getMobileStoId());
}
/*
* 商品评论
*/
public function comment()
{
$goods_id = I("goods_id/d", 0);
$this->assign('goods_id', $goods_id);
return $this->fetch('', getMobileStoId());
}
/*
* ajax获取商品详情
*/
public function ajaxComment()
{
$stoid=getMobileStoId();
$goods_id = I("goods_id/d", 0);
$commentType = I('commentType', '1'); // 1 全部 2好评 3 中评 4差评 5晒图
$where = "1=1";
if ($commentType == 5) {
$where .= " and c.goods_id =" . $goods_id . " and c.parent_id = 0 and c.img !='' and c.img NOT LIKE 'N;%' ";
} else {
$typeArr = array('1' => '0,1,2,3,4,5', '2' => '4,5', '3' => '3', '4' => '0,1,2');
$where .= " and c.goods_id =" . $goods_id . " and c.parent_id = 0 and round((c.deliver_rank + c.goods_rank + c.service_rank) / 3) in($typeArr[$commentType])";
}
$where .= ' and c.store_id=' . getMobileStoId();
$where .= ' and c.is_show=1 ';
$count = M('Comment')
->alias('c')
->where($where)->count("1");
$page_count = 5;
$page = new AjaxPage($count, $page_count);
$list = M('Comment')
->alias('c')
->join('__USERS__ u', 'u.user_id = c.user_id', 'LEFT')
->where($where)
->order("add_time desc")
->field('u.head_pic,u.nickname,c.username,c.add_time,c.content,c.img,c.comment_id,round((c.deliver_rank + c.goods_rank + c.service_rank) / 3)as service_rank,u.card_field')
->limit($page->firstRow . ',' . $page->listRows)
->select();
foreach ($list as $k => $v) {
$list[$k]['img'] = unserialize($v['img']); // 晒单图片
//商家回复
$replyList = M('Comment')->where(array('goods_id'=>$goods_id,'parent_id'=>$v['comment_id']))->field('content,add_time')->order("add_time desc")->select();
$list[$k]['replylist']=$replyList;
//点赞的统计
$zannum=M("comment_zan")->where("store_id",getMobileStoId())->where("comment_id",$v['comment_id'])->select();
if($zannum){
$list[$k]['zannum']= count($zannum);
$user_id= Cookie::get('user_id');
if($user_id){
foreach ($zannum as $kl=>$vl){
if($vl['user_id']==$user_id){ $list[$k]['iszan']=1; break; }
}
}
}
else $list[$k]['zannum']=0;
}
//获取所有的等级卡
$all_card=get_plus_price_arr($stoid);
$rs_dd=$all_card;
$new_card_dd=null;
if($rs_dd) {
foreach ($rs_dd as $kl => $vl) {
if ($vl) {
switch ($vl['CorrPrice']) {
case "Price1":
$new_card_dd['cardprice1'] = $vl['CardName'];
break;
case "Price2":
$new_card_dd['cardprice2'] = $vl['CardName'];
break;
case "Price3":
$new_card_dd['cardprice3'] = $vl['CardName'];
break;
}
}
}
$this->assign('new_card_dd', $new_card_dd);
}
$this->assign('goods_id', $goods_id);//商品id
$this->assign('commentlist', $list);// 商品评论
$this->assign('commentType', $commentType);// 1 全部 2好评 3 中评 4差评 5晒图
// $this->assign('replyList', $replyList); // 管理员回复
$this->assign('count', $count);//总条数
$this->assign('page_count', $page_count);//页数
$this->assign('current_count', $page_count * I('p'));//当前条
$this->assign('p', I('p'));//页数
upload_ylp_log('商品页-商品评论');
return $this->fetch('', getMobileStoId());
}
/*
* ajax获取商品评论
*/
public function ajaxdetail()
{
$goods_id = I("goods_id/d", 0);
$gd = M("goods")->where("goods_id", $goods_id)->field('goods_content')->find();
$this->assign("goods_content", $gd["goods_content"]);
return $this->fetch('', getMobileStoId());
}
/*
* 获取商品规格
*/
public function goodsAttr()
{
$goods_id = I("get.goods_id/d", 0);
$goods_attribute = M('GoodsAttribute')->getField('attr_id,attr_name'); // 查询属性
$goods_attr_list = M('GoodsAttr')->where("goods_id", $goods_id)->select(); // 查询商品属性表
$this->assign('goods_attr_list', $goods_attr_list);
$this->assign('goods_attribute', $goods_attribute);
upload_ylp_log('商品页-商品规格');
return $this->fetch('', getMobileStoId());
}
/**
* 积分商城
*/
public function integralMall()
{
$rank = I('get.rank');
//以兑换量(购买量)排序
if ($rank == 'num') {
$ranktype = 'sales_sum';
$order = 'desc';
}
//以需要积分排序
if ($rank == 'integral') {
$ranktype = 'exchange_integral';
$order = 'desc';
}
$point_rate = tpCache('shopping.point_rate', getMobileStoId());
$goods_where = array(
'is_on_sale' => 1, //是否上架
);
//积分兑换筛选
$exchange_integral_where_array = array(array('gt', 0));
// 分类id
if (!empty($cat_id)) {
$goods_where['cat_id'] = array('in', getCatGrandson($cat_id));
}
//我能兑换
$user_id = cookie('user_id');
if (!empty($user_id)) {
//获取用户积分
$user_pay_points = intval(M('users')->where(array('user_id' => $user_id))->getField('pay_points'));
if ($user_pay_points !== false) {
array_push($exchange_integral_where_array, array('lt', $user_pay_points));
}
}
$goods_where['exchange_integral'] = $exchange_integral_where_array; //拼装条件
$goods_list_count = M('goods')->where($goods_where)->count(); //总页数
$page = new Page($goods_list_count, 15);
$goods_list = M('goods')->where($goods_where)->order($ranktype, $order)->limit($page->firstRow . ',' . $page->listRows)->select();
$goods_category = M('goods_category')->where(array('level' => 1))->select();
$this->assign('goods_list', $goods_list);
$this->assign('page', $page->show());
$this->assign('goods_list_count', $goods_list_count);
$this->assign('goods_category', $goods_category);//商品1级分类
$this->assign('point_rate', $point_rate);//兑换率
$this->assign('totalPages', $page->totalPages);//总页数
if (IS_AJAX) {
return $this->fetch('ajaxIntegralMall', getMobileStoId()); //获取更多
}
upload_ylp_log('积分商城');
return $this->fetch('', getMobileStoId());
}
/**
* 商品搜索列表页
*/
public function search()
{
$uid = Cookie::get('user_id');
$this->assign('uid', $uid);
$stoid = I('stoid/d');
$filter_param = array(); // 帅选数组
$id = I('get.id/d', 0); // 当前分类id
$brand_id = I('brand_id', 0);
$nation_id = I('nation_id', 0);
$sort = I('sort', 'sort'); // 排序
$sort_asc = I('sort_asc', 'asc'); // 排序
$price = I('price', ''); // 价钱
if($sort=="") $sort_asc="desc";
$id && ($filter_param['id'] = $id); //加入帅选条件中
$price && ($filter_param['price'] = $price); //加入帅选条件中
$brand_id && ($filter_param['brand_id'] = $brand_id); //加入筛选条件中
$nation_id && ($filter_param['nation_id'] = $nation_id); //加入筛选条件中
$start_price = trim(I('start_price', '0')); // 输入框价钱
$end_price = trim(I('end_price', '0')); // 输入框价钱
if ($start_price && $end_price) $price = $start_price . '-' . $end_price; // 如果输入框有价钱 则使用输入框的价钱
$q = urldecode(trim(I('q', ''))); // 关键字搜索
$q && ($_GET['q'] = $filter_param['q'] = $q); //加入帅选条件中
$qtype = I('qtype', '');
$where2="1=1";
$where22=" and 1=1";
if ($qtype) {
$filter_param['qtype'] = $qtype;
//$where2[$qtype] = 1;
$where2.=" and ".$qtype."=1";
$where22.=" and a.".$qtype."=1";
}
if ($q) {
//$where2['keywords|goods_sn|goods_name'] = array('like', '%' . $q . '%');
$where2.=" and (keywords like '%".$q."%' or goods_sn like '%".$q."%' or sku like '%".$q."%' or goods_name like '%".$q."%')";
$where22.=" and (a.keywords like '%".$q."%' or a.goods_sn like '%".$q."%' or sku like '%".$q."%' or a.goods_name like '%".$q."%')";
}
//$where2['is_on_sale'] = 1;
//$where2['store_id'] = getMobileStoId();
$goodsLogic = new \app\home\logic\GoodsLogic(); // 前台商品操作逻辑类
$filter_goods_id = M('goods')->where($where2)->where('is_on_sale',1)
->where('store_id',getMobileStoId())->getField("goods_id", true);
$whereall="";
// 过滤帅选的结果集里面找商品
if ($brand_id || $nation_id)// 品牌或者价格
{
if($brand_id) $whereall.=" and a.brand_id=".$brand_id;
if($nation_id) $whereall.=" and a.nation_id=".$nation_id;
$goods_id_1 = $goodsLogic->getGoodsIdByBrandPrice2($brand_id, $nation_id); // 根据 品牌 或者 价格范围 查找所有商品id
$filter_goods_id = array_intersect($filter_goods_id, $goods_id_1); // 获取多个帅选条件的结果 的交集
}
//筛选网站自营,入驻商家,货到付款,仅看有货,促销商品
//$sel = I('sel');
//if ($sel) {
// $goods_id_4 = $goodsLogic->get_filter_selected($sel);
// $filter_goods_id = array_intersect($filter_goods_id, $goods_id_4);
//}
/*--如果有价格条件--*/
$where = "";
if ($price) {
$pricearr = explode('-', $price);
$where = " having final_price>=" . $pricearr[0] . " and final_price<=" . $pricearr[1];
}
$filter_brand = $goodsLogic->get_filter_brand($filter_goods_id, $filter_param, 'search', 1); // 获取指定分类下的帅选品牌
$filter_nation = $goodsLogic->get_filter_nation($filter_goods_id, $filter_param, 'search', 1); // 获取指定分类下的帅选品牌
$this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc');
$this->assign('filter_param', $filter_param); // 帅选条件
$this->assign('filter_brand', $filter_brand);// 列表页帅选属性 - 商品品牌
$this->assign('filter_nation', $filter_nation);// 列表页帅选属性 -国别
if (input('is_ajax')) {
$user = session('user');
$time = time();
$where11 = "";
//if (count($filter_goods_id) > 0)
// $where11 = " and a.goods_id in(" . implode(',', $filter_goods_id) . ")";
//else
// $where11 = " and a.goods_id=0";
$str = "select a.market_price,a.goods_name,a.goods_id,a.original_img, a.sales_sum,a.is_new,a.is_hot,a.mz_price,a.prom_type,a.prom_id,a.cardprice1,a.cardprice2,a.cardprice3,a.is_mainshow,
CAST(case when (a.prom_type>0 and a.prom_type<3 and b.id<>'') or (a.prom_type=4 and b.is_show=1 and b.id<>'' ) or (a.prom_type=6 and b.id<>'')
then b.prom_price else a.shop_price
end as decimal(9,2)) as final_price,b.prom_integral from __PREFIX__goods a left join
(select id,commission,is_show,prom_price,type,expression,prom_integral,goods_listid,good_object,prom_type from __PREFIX__activitylist
where is_end=0 and (s_time<=" . $time . " or (warm_uptime<=" . $time . " and warm_uptime<>0)) and e_time>=" . $time . " and store_id=" . $stoid . ") as b
on locate(CONCAT(',',a.goods_id,','),b.goods_listid)>0 and (b.good_object=1 or b.prom_type<>3) where a.store_id=" . $stoid .$where22. $where11.$whereall. " and a.is_on_sale=1 and
a.on_time<".$time." and (a.down_time>".$time." or a.down_time=0) and a.is_mainshow=1 " . $where . " order by " . $sort . " " . $sort_asc;
$arr = Db::query($str);
$count = count($arr);
$pricearr = get_arr_column($arr, 'final_price');
//$filter_menu = $goodsLogic->get_filter_menu($filter_param, 'search'); // 获取显示的帅选菜单
$filter_price = $goodsLogic->get_filter_price2($pricearr, $filter_param, 'search'); // 帅选的价格期间
$this->assign('filter_price', $filter_price);// 帅选的价格期间
$this->assign('filter_price1', json_encode($filter_price));// 帅选的价格期间
$end = I('p/d', 1) * 10;
$mshow = 0;
if ($count > 0) {
//$goods_list = M('goods')->where("goods_id", "in", implode(',', $filter_goods_id))->order("$sort $sort_asc")->limit($page->firstRow . ',' . $page->listRows)->select();
$fir = I('p/d', 1) * 10 - 10;
if ($count < $end) $end = $count;
for ($i = $fir; $i < $end; $i++) {
$arr[$i]['final_price'] = number_format($arr[$i]['final_price'], 2);
if ($arr[$i]['is_mainshow'] == 1)
$goods_list[] = $arr[$i];
}
/*----
$filter_goods_id2 = get_arr_column($goods_list, 'goods_id');
if ($filter_goods_id2)
$goods_images = M('goods_images')
->where("goods_id", "in", implode(',', $filter_goods_id2))->select();--*/
}
//$goods_category = M('goods_category')->where('is_show=1')->getField('id,name,parent_id,level'); // 键值分类数组
if ($count > I('p/d', 1) * 10) {
$this->assign('mshow', 1);
} else {
$this->assign('mshow', 0);
}
$rank_switch = tpCache('shopping.rank_switch',$stoid);//等级价格
$mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆价格
$this->assign('rank_switch', $rank_switch);
$this->assign('mz_switch', $mz_switch);
if (!empty($rank_switch)){
//$this->assign('rank_field',$user['card_field']);
$rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']);
$card_field=$rand_end>time()?$user['card_field']:0;
$this->assign('rank_field',$card_field);
//----读取等级卡标签---
$all_card=get_plus_price_arr($stoid);
if($all_card) {
$this->assign('all_card', $all_card);
//--读取卡的分类---
$new_card_dd = null;
foreach ($all_card as $kl => $vl) {
if ($vl) {
switch ($vl['CorrPrice']) {
case "Price1":
$new_card_dd['cardprice1'] = $vl['CardName'];
break;
case "Price2":
$new_card_dd['cardprice2'] = $vl['CardName'];
break;
case "Price3":
$new_card_dd['cardprice3'] = $vl['CardName'];
break;
}
}
}
mlog("1:".json_encode($all_card),"/".getMobileStoId());
mlog("2:".json_encode($new_card_dd),"/".getMobileStoId());
$card_label = $new_card_dd[$card_field];
mlog("3:".json_encode($new_card_dd),"/".getMobileStoId());
$len = mb_strlen($card_label, "utf-8");
if ($len > 4)
$card_label = mb_substr($card_label, 0, 4, "utf-8");
$this->assign('card_label', $card_label);
}
}
if (!empty($mz_switch)){
$this->assign('mz_vip',$user['is_mzvip']);
}
$this->assign('stoid', getMobileStoId());
$this->assign('goods_list', $goods_list);
//$this->assign('goods_category', $goods_category);
//$this->assign('goods_images', $goods_images); // 相册图片
//$this->assign('filter_menu', $filter_menu); // 帅选菜单
//$this->assign('page', $page);// 赋值分页输出
$this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc');
C('TOKEN_ON', false);
upload_ylp_log('商品搜索列表');
return $this->fetch('ajaxGoodsList', $stoid);
}
return $this->fetch('', $stoid);
}
/**
* 分销商品搜索列表页
*/
public function searchdistribution()
{
$filter_param = array(); // 帅选数组
$id = I('get.id/d', 0); // 当前分类id
$brand_id = I('brand_id', 0);
$sort = I('sort', 'goods_id'); // 排序
$sort_asc = I('sort_asc', 'desc'); // 排序
$price = I('price', ''); // 价钱
$start_price = trim(I('start_price', '0')); // 输入框价钱
$end_price = trim(I('end_price', '0')); // 输入框价钱
if ($start_price && $end_price) $price = $start_price . '-' . $end_price; // 如果输入框有价钱 则使用输入框的价钱
$filter_param['id'] = $id; //加入帅选条件中
$brand_id && ($filter_param['brand_id'] = $brand_id); //加入帅选条件中
$price && ($filter_param['price'] = $price); //加入帅选条件中
$q = urldecode(trim(I('q', ''))); // 关键字搜索
$q && ($_GET['q'] = $filter_param['q'] = $q); //加入帅选条件中
$qtype = I('qtype', '');
if ($qtype) {
$where = array('is_on_sale' => 1);
$filter_param['qtype'] = $qtype;
$where[$qtype] = 1;
}
if ($q) $where['goods_name'] = array('like', '%' . $q . '%');
$where['store_id'] = getMobileStoId();
$goodsLogic = new \app\home\logic\GoodsLogic(); // 前台商品操作逻辑类
$filter_goods_id = M('goods')->where($where)->getField("goods_id", true);
// 过滤帅选的结果集里面找商品
if ($brand_id || $price)// 品牌或者价格
{
$goods_id_1 = $goodsLogic->getGoodsIdByBrandPrice($brand_id, $price); // 根据 品牌 或者 价格范围 查找所有商品id
$filter_goods_id = array_intersect($filter_goods_id, $goods_id_1); // 获取多个帅选条件的结果 的交集
}
//筛选网站自营,入驻商家,货到付款,仅看有货,促销商品
$sel = I('sel');
if ($sel) {
$goods_id_4 = $goodsLogic->get_filter_selected($sel);
$filter_goods_id = array_intersect($filter_goods_id, $goods_id_4);
}
$filter_menu = $goodsLogic->get_filter_menu($filter_param, 'searchdistribution'); // 获取显示的帅选菜单
$filter_price = $goodsLogic->get_filter_price($filter_goods_id, $filter_param, 'searchdistribution'); // 帅选的价格期间
$filter_brand = $goodsLogic->get_filter_brand($filter_goods_id, $filter_param, 'searchdistribution', 1); // 获取指定分类下的帅选品牌
$count = count($filter_goods_id);
$page = new Page($count, 2);
if ($count > 0) {
$goods_list = M('goods')->where("goods_id", "in", implode(',', $filter_goods_id))
->order("$sort $sort_asc")->limit($page->firstRow . ',' . $page->listRows)->select();
$filter_goods_id2 = get_arr_column($goods_list, 'goods_id');
if ($filter_goods_id2)
$goods_images = M('goods_images')
->where("goods_id", "in", implode(',', $filter_goods_id2))->select();
}
$goods_category = M('goods_category')->where('is_show=1')->getField('id,name,parent_id,level'); // 键值分类数组
$this->assign('stoid', getMobileStoId());
$this->assign('goods_list', $goods_list);
$this->assign('goods_category', $goods_category);
$this->assign('goods_images', $goods_images); // 相册图片
$this->assign('filter_menu', $filter_menu); // 帅选菜单
$this->assign('filter_brand', $filter_brand);// 列表页帅选属性 - 商品品牌
$this->assign('filter_price', $filter_price);// 帅选的价格期间
$this->assign('filter_param', $filter_param); // 帅选条件
$this->assign('page', $page);// 赋值分页输出
$this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc');
C('TOKEN_ON', false);
upload_ylp_log('分销商品搜索列表');
if (input('is_ajax'))
return $this->fetch('ajaxdistribution', getMobileStoId());
else
return $this->fetch('', getMobileStoId());
}
/**
* 商品搜索列表页
*/
public function ajaxSearch()
{
return $this->fetch('', getMobileStoId());
}
/**
* 品牌街
*/
public function brandstreet()
{
$getnum = 9; //取出数量
$goods = M('goods')->where(array('is_recommend' => 1, 'is_on_sale' => 1))
->page(1, $getnum)->cache("brandstreet_" . getMobileStoId(), TPSHOP_CACHE_TIME)->select(); //推荐商品
for ($i = 0; $i < ($getnum / 3); $i++) {
//3条记录为一组
$recommend_goods[] = array_slice($goods, $i * 3, 3);
}
$where = array(
'is_hot' => 1, //1为推荐品牌
);
$count = M('brand')->where($where)->count(); // 查询满足要求的总记录数
$Page = new Page($count, 20);
$show = $Page->show();// 分页显示输出
$brand_list = M('brand')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('sort desc')->select();
$this->assign('Page', $show); //赋值分页输出
$this->assign('recommend_goods', $recommend_goods); //品牌列表
$this->assign('brand_list', $brand_list); //推荐商品
if (I('is_ajax')) {
return $this->fetch('ajaxBrandstreet', getMobileStoId());
}
return $this->fetch('', getMobileStoId());
}
/**
* 商品列表—分销商上下架 增加 20170321
*/
public function goodsList_distribution()
{
$filter_param = array(); // 帅选数组
$id = I('id/d', 0); // 当前分类id
$brand_id = I('brand_id/d', 0);
$spec = I('spec', 0); // 规格
$attr = I('attr', ''); // 属性
$sort = I('sort', 'goods_id'); // 排序
$sort_asc = I('sort_asc', 'desc'); // 排序
$price = I('price', ''); // 价钱
$start_price = trim(I('start_price', '0')); // 输入框价钱
$end_price = trim(I('end_price', '0')); // 输入框价钱
if ($start_price && $end_price) $price = $start_price . '-' . $end_price; // 如果输入框有价钱 则使用输入框的价钱
$filter_param['id'] = $id; //加入帅选条件中
$brand_id && ($filter_param['brand_id'] = $brand_id); //加入帅选条件中
$spec && ($filter_param['spec'] = $spec); //加入帅选条件中
$attr && ($filter_param['attr'] = $attr); //加入帅选条件中
$price && ($filter_param['price'] = $price); //加入帅选条件中
$goodsLogic = new \app\home\logic\GoodsLogic(); // 前台商品操作逻辑类
// 分类菜单显示
$goodsCate = M('GoodsCategory')->where("id", $id)->find();// 当前分类
//($goodsCate['level'] == 1) && header('Location:'.U('Home/Channel/index',array('cat_id'=>$id))); //一级分类跳转至大分类馆
$cateArr = $goodsLogic->get_goods_cate($goodsCate);
// 帅选 品牌 规格 属性 价格
$cat_id_arr = getCatGrandson($id);
$filter_goods_id = M('goods')->where("is_on_sale=1")->where("cat_id", "in", implode(',', $cat_id_arr))->getField("goods_id", true);
// 过滤帅选的结果集里面找商品
if ($brand_id || $price)// 品牌或者价格
{
$goods_id_1 = $goodsLogic->getGoodsIdByBrandPrice($brand_id, $price); // 根据 品牌 或者 价格范围 查找所有商品id
$filter_goods_id = array_intersect($filter_goods_id, $goods_id_1); // 获取多个帅选条件的结果 的交集
}
if ($spec)// 规格
{
$goods_id_2 = $goodsLogic->getGoodsIdBySpec($spec); // 根据 规格 查找当所有商品id
$filter_goods_id = array_intersect($filter_goods_id, $goods_id_2); // 获取多个帅选条件的结果 的交集
}
if ($attr)// 属性
{
$goods_id_3 = $goodsLogic->getGoodsIdByAttr($attr); // 根据 规格 查找当所有商品id
$filter_goods_id = array_intersect($filter_goods_id, $goods_id_3); // 获取多个帅选条件的结果 的交集
}
//筛选网站自营,入驻商家,货到付款,仅看有货,促销商品
$sel = I('sel');
if ($sel) {
$goods_id_4 = $goodsLogic->get_filter_selected($sel, $cat_id_arr);
$filter_goods_id = array_intersect($filter_goods_id, $goods_id_4);
}
$filter_menu = $goodsLogic->get_filter_menu($filter_param, 'goodsList'); // 获取显示的帅选菜单
$filter_price = $goodsLogic->get_filter_price($filter_goods_id, $filter_param, 'goodsList'); // 帅选的价格期间
$filter_brand = $goodsLogic->get_filter_brand($filter_goods_id, $filter_param, 'goodsList', 1); // 获取指定分类下的帅选品牌
$filter_spec = $goodsLogic->get_filter_spec($filter_goods_id, $filter_param, 'goodsList', 1); // 获取指定分类下的帅选规格
$filter_attr = $goodsLogic->get_filter_attr($filter_goods_id, $filter_param, 'goodsList', 1); // 获取指定分类下的帅选属性
$count = count($filter_goods_id);
$page = new Page($count, 2);
if ($count > 0) {
$goods_list = M('goods')->where("goods_id", "in", implode(',', $filter_goods_id))->order("$sort $sort_asc")->limit($page->firstRow . ',' . $page->listRows)->select();
$filter_goods_id2 = get_arr_column($goods_list, 'goods_id');
if ($filter_goods_id2)
$goods_images = M('goods_images')->where("goods_id", "in", implode(',', $filter_goods_id2))->select();
}
$goods_category = M('goods_category')->where('is_show=1')->getField('id,name,parent_id,level'); // 键值分类数组
$this->assign('goods_list', $goods_list);
$this->assign('goods_category', $goods_category);
$this->assign('goods_images', $goods_images); // 相册图片
$this->assign('filter_menu', $filter_menu); // 帅选菜单
$this->assign('filter_spec', $filter_spec); // 帅选规格
$this->assign('filter_attr', $filter_attr); // 帅选属性
$this->assign('filter_brand', $filter_brand);// 列表页帅选属性 - 商品品牌
$this->assign('filter_price', $filter_price);// 帅选的价格期间
$this->assign('goodsCate', $goodsCate);
$this->assign('cateArr', $cateArr);
$this->assign('filter_param', $filter_param); // 帅选条件
$this->assign('cat_id', $id);
$this->assign('page', $page);// 赋值分页输出
$this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc');
C('TOKEN_ON', false);
if (input('is_ajax'))
return $this->fetch('ajaxGoodsList');
else
return $this->fetch();
}
/**
* 看相似
* $author lxl
* $time 2017-1
*/
// public function similar(){
// $good_id = I('id','');
// $now_good = M('goods')->where("goods_id=$good_id")->find(); //当前商品
// $where_id_list = M('goods')->field('cat_id,spec_type')->where("goods_id=$good_id")->find(); //相似条件,分类id,类型id
// $count = M('goods')->where($where_id_list) ->count(); //符合条件的总数
// $pagesize = C('PAGESIZE'); //每页显示数
// $Page = new Page($count,$pagesize);
// $goods_list = M('goods')->where($where_id_list) ->limit($Page->firstRow.','.$Page->listRows)->select(); //获取相似商品
// $this->assign('goods_list',$goods_list);
// $this->assign('now_good',$now_good);
// if(I('is_ajax')){
// return $this->fetch('ajax_similar',getMobileStoId());
// }
// return $this->fetch('',getMobileStoId());
// }
public function firstsetCaChe()
{
$key = I("key");
$url = I("url");
Cache::set($key, "1");
Cache::set($key . '_url', $url);
$co = Cache::get($key);
if($co==false) $co=1;
return $co;
}
public function firstgetCaChe()
{
$key = I("key");
$co = Cache::get($key);
return $co;
}
/*-----------获取门店排行20191128------------------*/
public function getStorageList()
{
$lx = I('lx');
$ly = I('ly');
if(empty($lx)) $lx=0;
if(empty($ly)) $ly=0;
$uid = session('user')['user_id'];
$stoid = I('stoid');
$dis=I('distr_type/d');//商品物流方式
$user_def_sto=mb_get_user_sto($dis,$lx,$ly);
/*-----查看销售规则,采用线下规则要计算所有规格的商品在线下的库存----*/
$mstore = tpCache('basic.sales_rules', $stoid);
$switch_list=tpCache('basic.switch_list', $stoid);
$switch_list=json_decode($switch_list,true);
$is_newsales_rules=$switch_list['is_newsales_rules'];
mlog("[".$uid."]is_newsales_rules:".$is_newsales_rules,"getStorageList/".$stoid);
//--当是线下规则的时候,且不是最新的取门店方法--
if ($mstore == 2 ) {
$id = I('goodsid');
$goods = M("goods")->where('store_id', $stoid)
->where('goods_id', $id)->field('erpwareid,goods_id')->find();
$time = time();
$gidarr4[$goods['erpwareid']]=$goods['goods_id'];
$this->assign('is_bline', 1);
$blinesto = [];
if($is_newsales_rules){
$blinesto =get_isnewrules_store($stoid,$id,$dis,$lx,$ly);
}else{
if ($lx == 0 && $ly == 0) {
$blinesto = getblinesto($gidarr4, getMobileStoId(),$dis);
} else {
session('ulx'.$uid, $lx);
session('uly'.$uid, $ly);
$blinesto = getblinesto_sortlocation($gidarr4, getMobileStoId(),$id, $lx, $ly,$dis);
}
}
mlog('获取线下库存'.json_encode($blinesto), 'blinestore0/'.$stoid);
if ($blinesto == -1) {
return json(['code' => -2, 'msg' => '获取库存失败', 'is_bline' => 1]);
mlog('系统获取线下库存失败', 'getdownkun/' . $stoid . '/' . $goods_id);
} else if ($blinesto == -2) {
return json(['code' => -2, 'msg' => '门店库存不足', 'is_bline' => 1]);
mlog('系统未设置线下库存', 'getdownkun/' . $stoid . '/' . $goods_id);
}
else if ($blinesto == -3) {
return json(['code' => -2, 'msg' => '未找到门店', 'is_bline' => 1]);
mlog('未找到门店', 'getdownkun/' . $stoid . '/' . $goods_id);
}
else {
//--运行数量,计算预出库的库存数量要减掉--
if(!$is_newsales_rules) {
//---线下库存判断预存是多少,组装map数组,快速查找---
$strq = 'select pickup_id,sum(out_qty) as sum0 from __PREFIX__erp_yqty where goods_id='
. $id . ' and store_id='.$stoid.' group by pickup_id';
$dd = Db::query($strq);
$ddd=[];
foreach ($dd as $kl=>$vl){
$ypkid=$vl['pickup_id'];
$ddd[$id."-".$ypkid]=$vl['sum0'];
}
$count = 0;
foreach ($blinesto['res'] as $k0 => $v0) {
//--预出库库存计算--
foreach ($v0['list'] as $km => $vm) {
$pkid = $vm['pickup_id'];
$gid0 = $k0;
if ($ddd[$gid0 . '-' . $pkid]) {
$vm['count'] = $blinesto['res'][$k0]['list'][$km]['count'] = $vm['count'] - $ddd[$gid0 . '-' . $pkid];
}
//--如果库存为零--
if ($vm['count'] == 0) {
unset($blinesto['res'][$k0]['list'][$km]);
}
}
}
}
$list=$blinesto['res'][$id]['list']; //本商品的门店列表,不同是商品是由不同的list
$count=count($list);
$res1=M("storage_category")->where('store_id', $stoid)->field("cat_id,cat_name")
->order('sort asc')
->where("is_show",1)->select();
$count0=M("storage_category")->where('store_id', $stoid)->count();
if($count<=5 || $count0<=0){
return json(['code' => 1, 'msg' => 'ok','type'=>1,'is_bline' => 1,'user_def_sto'=>$user_def_sto,
'sto_data' => $list, 'min' =>$list[0] ]);
}else {
foreach ($res1 as $k1 => $v1) {
$result =[];
foreach($list as $k=>$v){
if($v1['cat_id']==$v['cat_id']){ $result[]=$v;}
}
if (empty($result)) {
unset($res1[$k1]);
} else {
$res1[$k1]['list'] = $result;
}
}
return json(['code' => 1, 'msg' => 'ok', 'is_bline' => 1,'user_def_sto'=>$user_def_sto,
'sto_data' => $res1, 'min' => $blinesto['min'],'def_list'=>$blinesto['def_list']]);
}
}
} else {
if ($lx != 0 || $ly != 0) {
session('ulx'.getMobileStoId(), $lx);
session('uly'.getMobileStoId(), $ly);
}
$mindate = [];
/*--剔除不显示门店分类底下的门店--*/
$res0 = M("storage_category")->where('store_id', $stoid)->where('is_show', 0)->field("cat_id")->select();
$count0=M("storage_category")->where('store_id', $stoid)->count();
$res0=get_arr_column($res0,'cat_id');
$wh="1=1";
if(!empty($res0))
$wh="category_id not in(".implode(',',$res0).")";
if($dis==0){
$where1="1=1";
}else {
$where1 = "distr_type=" . $dis . " or distr_type=0";
}
if($lx || $ly){
$result0=M("pick_up")->where('store_id',$stoid)->where('isstop<>1')->where($wh)->where($where1)
->field('*,st_distance (POINT (lat,lon),POINT('.$ly.','.$lx.')) * 111195 AS distance')
->order('distance asc,pickup_id asc')
->select();
}else{
$result0=M("pick_up")->where('store_id',$stoid)->where('isstop<>1')->where($wh)->where($where1)
->field("*,'null' AS distance")
->order('pickup_id asc')
->select();
}
//---计算默认一开始的5个门店---
$def_list=[];
foreach ($result0 as $k5=>$v5){
if($k5>4) break;
$def_list[]=$v5;
}
$count=count($result0);
if ($count == 0){ return json(['code' => -2, 'msg' => '未找到门店', 'is_bline' => 0]); }
/*--当数量小于5--*/
if($count<=5 || $count0<=0){
mlog("[".$uid."]门店数:".$count,"getStorageList/".$stoid);
return json(['code' => 1,'is_bline'=>0,'msg' => 'ok','sto_data' => $result0,'type'=>1,'user_def_sto'=>$user_def_sto,]);
}else {
/*----选择门店-----*/
$res1 = M("storage_category")->where('store_id', $stoid)->where('is_show', 1)
->order('sort asc')->select();
foreach ($res1 as $k1 => $v1) {
$result =[];
foreach($result0 as $k=>$v){
if($v1['cat_id']==$v['category_id']){ $result[]=$v;}
}
if (empty($result)) {
unset($res1[$k1]);
} else {
$res1[$k1]['list'] = $result;
}
}
mlog("[".$uid."]门店数:".$count,"getStorageList/".$stoid);
return json(['code' => 1, 'msg' => 'ok', 'is_bline' => 0, 'sto_data' => $res1,'user_def_sto'=>$user_def_sto,
'min' => $def_list[0],'def_list'=>$def_list]);
}
}
}
/*--搭配促销列表--*/
public function prom_list()
{
$id = I('id/d');
$user_id = cookie('user_id');
$goods_id = I('goods_id/d');
$good = M('goods')->where(['goods_id' => $goods_id])->field('goods_id,goods_name,goods_spec,goods_color,store_count,shop_price,original_img,sales_sum,viplimited,distr_type')->find();
if (empty($good['viplimited'])){
$good['viplimited'] = 10000;
}else{
$limit=M('order')->alias('a')->join('order_goods b','a.order_id=b.order_id')->where(['b.goods_id'=>$goods_id,'a.user_id'=>$user_id,'a.order_status'=>[['=',4],['<',3],'or']])->sum('b.goods_num');
$good['viplimited']-=$limit;
}
if ($good['goods_spec'] == '') {
if ($good['goods_color'] == '') {
$good['spec'] = '规格1';
} else {
$good['spec'] = $good['goods_color'];
}
} else {
$good['spec'] = $good['goods_spec'];
if (!empty($good['goods_color'])) {
$good['spec'] .= '/' . $good['goods_color'];
}
}
$list = M('collocation_list')->where('prom_id', $id)->select();
foreach ($list as $k => $v) {
$goods = M('goods')->where(['goods_id' => $v['goods_id'], 'store_count' => ['>', 0]])->field('shop_price,goods_spec,goods_color,original_img,distr_type')->find();
if (!empty($goods)) {
if ($goods['goods_spec'] == '') {
if ($goods['goods_color'] == '') {
$list[$k]['spec'] = '规格1';
} else {
$list[$k]['spec'] = $goods['goods_color'];
}
} else {
$list[$k]['spec'] = $goods['goods_spec'];
if (!empty($goods['goods_color'])) {
$list[$k]['spec'] .= '/' . $goods['goods_color'];
}
}
$list[$k]['original_img'] = $goods['original_img'];
$list[$k]['shop_price'] = $goods['shop_price'];
$list[$k]['dist_type'] = $goods['distr_type'];
} else {
unset($list[$k]);
}
}
$this->assign([
'list' => $list,
'good' => $good,
]);
return $this->fetch('', getMobileStoId());
}
/*优惠促销商品列表*/
public function prom_goods()
{
$uid = Cookie::get('user_id');
$stoid = I('stoid/d');
$prom_id = I('prom_id/d');
$all = I('all/d');
$key = I('key/s', '');
$where['store_id'] = $stoid;
$where['is_on_sale'] = 1;
$where['store_count'] = ['>', 0];
if ($all == 0) {
$where['prom_type'] = 0;
} else {
$where['prom_type'] = 3;
$where['prom_id'] = $prom_id;
}
if (!empty($key)) {
$where['goods_name'] = ['like', "%$key%"];
}
$time=time();
$arr = M('goods')->where("on_time<".$time." and (down_time>$time or down_time=0 and down_time='' or down_time is null)")
->where($where)->field('goods_name,goods_id,original_img,sales_sum,shop_price as final_price')->select();
$count = M('goods')->where("on_time<".$time." and (down_time>$time or down_time=0 and down_time='' or down_time is null)")
->where($where)->count();
/*--计算分页--*/
$end = I('page/d', 1) * 10;
$mshow = 0;
if ($count > 0) {
$fir = I('page/d', 1) * 10 - 10;
if ($count < $end) $end = $count;
for ($i = $fir; $i < $end; $i++) {
$arr[$i]['final_price'] = number_format($arr[$i]['final_price'], 2);
$goods_list[] = $arr[$i];
}
}
$this->assign('uid', $uid);
$this->assign('prom_id', $prom_id);
$this->assign('all', $all);
$this->assign('goods_list', $goods_list);
if ($count > $end) {
$mshow = 1;
}
$this->assign('mshow', $mshow);
if (input('is_ajax')) {
return $this->fetch('ajaxGoodsList', $stoid);
} else {
$now = time();
if ($prom_id > 0) {
$prom_active = M('prom_goods')->where(['end_time' => ['gt', $now], 'start_time' => ['lt', $now], 'is_end' => 0, 'id' => $prom_id])->find();
} else {
$prom_active = M('prom_goods')->where(['end_time' => ['gt', $now], 'start_time' => ['lt', $now], 'is_end' => 0, 'good_object' => 0])->find();
}
if (!empty($prom_active)) {
$prom_list = M('prom_goods_list')->where('prom_id', $prom_active['id'])->order('condition', 'asc')->select();
foreach ($prom_list as $k => $v) {
$rule = json_decode($v['preferential_type'], true);
$prom_list[$k]['money'] = $rule['money'];
$prom_list[$k]['sale'] = $rule['sale'];
$prom_list[$k]['past'] = $rule['is_past'];
$prom_list[$k]['int'] = $rule['int'];
$id = $rule['coupon'];
if ($id > 0) {
$coupon = M('coupon')->where(['id' => $id, 'send_start_time' => ['lt', $now], 'send_end_time' => ['gt', $now]])->field('id,money')->find();
$prom_list[$k]['coupon'] = (int)$coupon['money'];
$prom_list[$k]['coupon_id'] = (int)$coupon['id'];
}
$id = $rule['gift'];
if ($id > 0) {
$gift = M('gift')->where(['id' => $id, 'start_time' => ['lt', $now], 'end_time' => ['gt', $now], 'goods_num' => ['>', 0], 'is_end' => 0])->field('id,goods_name,goods_id')->find();
$prom_list[$k]['goods_name'] = $gift['goods_name'];
$prom_list[$k]['gift_id'] = (int)$gift['id'];
}
}
$this->assign('prom_list', $prom_list);// 商品促销
}
return $this->fetch('', $stoid);
}
}
//查找商品限购
public function getGoodslimit($id){
$user = session('user');
if(empty($id)) $id=I('id',0);
$t=time();
/*查找商品*/
$goods = M('Goods')
->where("on_time<".$t." and (down_time>".$t." or down_time='')")
->where("goods_id", $id)->where('is_on_sale', 1)
->find(); // 找出这个商品
if(empty($goods)) return ['num'=>0];
if (empty($goods['viplimited'])) {
return ['num'=>100000];
} else {
$limit = M('order')->alias('a')->join('order_goods b', 'a.order_id=b.order_id')
->where(['b.goods_id' => $id, 'a.user_id' => $user['user_id'], 'a.order_status' => [['=', 4], ['<', 3], 'or']])
->sum('b.goods_num');
$limit += M('cart')->where(['goods_id' => $id, 'user_id' => $user['user_id']])
->where('state',0)->sum('goods_num');
if ($limit >= $goods['viplimited']) {
$goods['viplimited'] = 0;
} else {
$goods['viplimited'] -= $limit;
}
return ['num'=>$goods['viplimited']];
}
}
// 网址图片生成BASE64
function img_curl_url($url,$type=0,$timeout=30)
{
$msg = ['code' => 2100, 'status' => 'error', 'msg' => '未知错误!'];
$imgs = ['image/jpeg' => 'jpeg',
'image/jpg' => 'jpg',
'image/gif' => 'gif',
'image/png' => 'png',
'text/html' => 'html',
'text/plain' => 'txt',
'image/pjpeg' => 'jpg',
'image/x-png' => 'png',
'image/x-icon' => 'ico'
];
if (!stristr($url, 'http')) {
$msg['code'] = 2101;
$msg['msg'] = 'url地址不正确!';
return $msg;
}
$dir = pathinfo($url);
//var_dump($dir);
$host = $dir['dirname'];
$refer = $host . '/';
$ch = curl_init($url);
//不验证https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_REFERER, $refer); //伪造来源地址
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//返回变量内容还是直接输出字符串,0输出,1返回内容
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);//在启用CURLOPT_RETURNTRANSFER的时候,返回原生的(Raw)输出
curl_setopt($ch, CURLOPT_HEADER, 0); //是否输出HEADER头信息 0否1是
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); //超时时间
$data = curl_exec($ch);
//$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
//$httpContentType = curl_getinfo($ch,CURLINFO_CONTENT_TYPE);
$info = curl_getinfo($ch);
curl_close($ch);
$httpCode = intval($info['http_code']);
$httpContentType = $info['content_type'];
$httpSizeDownload = intval($info['size_download']);
if ($httpCode != '200') {
$msg['code'] = 2102;
$msg['msg'] = 'url返回内容不正确!';
return $msg;
}
if ($type > 0 && !isset($imgs[$httpContentType])) {
$msg['code'] = 2103;
$msg['msg'] = 'url资源类型未知!';
return $msg;
}
if ($httpSizeDownload < 1) {
$msg['code'] = 2104;
$msg['msg'] = '内容大小不正确!';
return $msg;
}
$msg['code'] = 200;
$msg['status'] = 'success';
$msg['msg'] = '资源获取成功';
if ($type == 0 or $httpContentType == 'text/html') $msg['data'] = $data;
$base_64 = base64_encode($data);
if ($type == 1) $msg['data'] = $base_64;
elseif ($type == 2) $msg['data'] = "data:{$httpContentType};base64,{$base_64}";
elseif ($type == 3) $msg['data'] = "<img src='data:{$httpContentType};base64,{$base_64}' />";
else $msg['msg'] = '未知返回需求!';
unset($info, $data, $base_64);
return $msg;
}
public function get_pj_list(){
$stoid=I('stoid');
$gd_id=I('goods_id');
$pageSize=I('pageSize');
$page=I('page');
//获取所有的等级卡
$tk=tpCache("shop_info.api_token",$stoid);
$rs_dd = getApiData("wxd.mem.bershipcard.list.get", $tk, null,
null, null, null, 'CardCode desc');
$rs_dd=json_decode($rs_dd,true);
$rs_dd=$rs_dd['data'];
if($rs_dd){
$new_card_dd=null;
foreach ($rs_dd as $kl=>$vl){
if($vl){
switch ($vl['CorrPrice']){
case "Price1":
$new_card_dd['cardprice1']=$vl['CardName'];
break;
case "Price2":
$new_card_dd['cardprice2']=$vl['CardName'];
break;
case "Price3":
$new_card_dd['cardprice3']=$vl['CardName'];
break;
}
}
}
$this->assign('new_card_dd', $new_card_dd);
}
$url=Mini_Host()."/api/weshop/comment/pageComment?store_id=".$stoid
."&goods_id=".$gd_id."&pageSize=".$pageSize."&parent_id=0&page=".$page;
$data=httpRequest($url);
$data=json_decode($data,true);
if($data['code']==0){
$data=$data['data']['pageData'];
if($data){
foreach ($data as $kk=>$vv){
$data[$kk]['img']=unserialize($vv['img']);
$user=M('users')->where('user_id',$vv['user_id'])
->field('card_field')->find();
$data[$kk]['card_field']=$user['card_field'];
}
$this->assign("pg_list",$data);
}
}
return $this->fetch("",$stoid);
}
public function get_free_quan()
{
$type = I("get_type");
$stoid = I("stoid");
$user = session('user');
$tt = time();
if ($type == 0) {
$coupon = M('coupon')->where("type = 1 and store_id = " . getMobileStoId() . " and " . $tt . " >= send_start_time and send_end_time >= " . $tt)
->order('add_time desc')->limit(3)->select();
$this->assign("coupon", $coupon);
return $this->fetch('', $stoid);
} else {
$coupon = M('coupon')->where("type = 1 and store_id = " . getMobileStoId() . " and " . $tt . " >= send_start_time and send_end_time >= " . $tt)
->order('add_time desc')->select();
$this->assign("coupon", $coupon);
$this->assign("user", $user);
return $this->fetch('get_free_quan_list', $stoid);
}
}
//---设置默认门店---
public function set_def_store(){
$stoid=I("stoid");
$pickup_id=I("pickup_id");
$uid = Cookie::get('user_id');
$rs= M('users')->where("store_id",$stoid)->where('user_id',$uid)->save(['def_pickup_id'=>$pickup_id]);
if($rs===false){
return json(['code'=>-1,'msg'=>'修改失败']);
}
return json(['code'=>0,'msg'=>'修改成功']);
}
}