ClassifyController.php
6.0 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
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\WeChatBaseController;
use think\Db;
class ClassifyController extends WeChatBaseController{
/**
* 显示分类页
*/
public function classify(){
//所有分类
$data_classify = Db::name('classification') -> select();
//所有标签
$data_label = Db::name('label') -> select();
$classify_id = $this -> request -> param();
if($classify_id){
//获取指定分类商品
$data_goods = Db::name('goods') -> alias('a') -> field("a.*,b.name") -> join('classification b','a.classify_id = b.id','LEFT') -> where("a.type = 1 and a.is_out = 1 and a.classify_id =".$classify_id['classify_id']) -> select() -> toArray();
$this -> assign('class',$classify_id['classify_id']);
}else{
//获取默认分类商品
$data_goods = Db::name('goods') -> alias('a') -> field("a.*,b.name") -> join('classification b','a.classify_id = b.id','LEFT') -> where("a.type = 1 and a.is_out = 1 and a.classify_id =".$data_classify[0]['id']) -> select() -> toArray();
$this -> assign('class',$data_classify[0]['id']);
}
foreach($data_goods as $key => $val){
$price = explode('.',$data_goods[$key]['price']);
$data_goods[$key]['price0'] = $price[0];
$data_goods[$key]['price01'] = $price[1];
}
$this -> assign('data_goods',$data_goods);
$this -> assign('data_label',$data_label);
$this -> assign('data_classify',$data_classify);
return $this -> fetch();
}
/**
* 分类下的商品
*/
public function classify_goods(){
$classify_id = $_POST['classify_id'];
$data_classify_goods = Db::name('goods') -> alias('a') -> field("a.*,b.name") -> join('classification b','a.classify_id = b.id','LEFT') -> where("a.type = 1 and a.is_out = 1 and a.classify_id =".$classify_id) -> select() -> toArray();
foreach($data_classify_goods as $key => $val){
$price = explode('.',$data_classify_goods[$key]['price']);
$data_classify_goods[$key]['price0'] = $price[0];
$data_classify_goods[$key]['price01'] = $price[1];
$data_classify_goods[$key]['show_img'] = cmf_get_image_url($data_classify_goods[$key]['show_img']);
}
return json_encode($data_classify_goods);
}
/**
* 分类标签下的商品
*/
public function classify_lable_goods(){
$label_id = $_POST['label_id'];
$classify_id = $_POST['classify_id'];
$data_classify_lable_goods = Db::name('goods') -> alias('a') -> field("a.*") -> join('goods_label b','a.id = b.goods_id','LEFT') -> where("a.type = 1 and a.is_out = 1 and a.classify_id =".$classify_id." and b.label_id =".$label_id) -> select() -> toArray();
$data_classify_name = Db::name('classification') -> where('id',$classify_id) -> find();
foreach($data_classify_lable_goods as $key => $val){
$price = explode('.',$data_classify_lable_goods[$key]['price']);
$data_classify_lable_goods[$key]['price0'] = $price[0];
$data_classify_lable_goods[$key]['price01'] = $price[1];
$data_classify_lable_goods[$key]['show_img'] = cmf_get_image_url($data_classify_lable_goods[$key]['show_img']);
$data_classify_lable_goods[$key]['name'] = $data_classify_name['name'];
}
return json_encode($data_classify_lable_goods);
}
/**
* 销量排序
*/
public function classify_sales(){
$where = [
'a.type' => 1,
'a.is_out' => 1
];
if(!empty($_POST['classify_id'])){
$where['a.classify_id'] = $_POST['classify_id'];
}
if(!empty($_POST['lable_id'])){
$where['b.label_id'] = $_POST['lable_id'];
}
$data = Db::name('goods') -> alias('a') -> field("a.*") -> join('goods_label b','a.id = b.goods_id','LEFT') -> where($where) -> order('a.sales desc') -> select() -> toArray();
$data_classify_name = Db::name('classification') -> where('id',$_POST['classify_id']) -> find();
foreach($data as $key => $val){
$price = explode('.',$data[$key]['price']);
$data[$key]['price0'] = $price[0];
$data[$key]['price01'] = $price[1];
$data[$key]['show_img'] = cmf_get_image_url($data[$key]['show_img']);
$data[$key]['name'] = $data_classify_name['name'];
}
return json_encode($data);
}
/**
* 价格排序
*/
public function classify_price(){
$where = [
'a.type' => 1,
'a.is_out' => 1
];
if(!empty($_POST['classify_id'])){
$where['classify_id'] = $_POST['classify_id'];
}
if(!empty($_POST['lable_id'])){
$where['label_id'] = $_POST['lable_id'];
}
$data = Db::name('goods') -> alias('a') -> field("a.*") -> join('goods_label b','a.id = b.goods_id','LEFT') -> where($where) -> order('a.price desc') -> select() -> toArray();
$data_classify_name = Db::name('classification') -> where('id',$_POST['classify_id']) -> find();
foreach($data as $key => $val){
$price = explode('.',$data[$key]['price']);
$data[$key]['price0'] = $price[0];
$data[$key]['price01'] = $price[1];
$data[$key]['show_img'] = cmf_get_image_url($data[$key]['show_img']);
$data[$key]['name'] = $data_classify_name['name'];
}
return json_encode($data);
}
}