ClassifyController.php
4.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
<?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();
//获取默认分类商品
$data_goods = Db::name('goods') -> alias('a') -> join('classification b','a.classify_id = b.id','LEFT') -> where("a.type = 1 and a.classify_id =".$data_classify[0]['id']." and a.label_id = 0") -> select() -> toArray();
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') -> join('classification b','a.classify_id = b.id','LEFT') -> where("a.type = 1 and a.classify_id =".$classify_id." and a.label_id = 0") -> 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') -> join('classification b','a.classify_id = b.id','LEFT') -> where("a.type = 1 and a.classify_id =".$classify_id." and a.label_id =".$label_id) -> select() -> toArray();
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']);
}
return json_encode($data_classify_lable_goods);
}
/**
* 销量排序
*/
public function classify_sales(){
$where = [
'a.type' => 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') -> join('classification b','a.classify_id = b.id','LEFT') -> where($where) -> order('a.sales desc') -> select() -> toArray();
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']);
}
return json_encode($data);
}
}