审查视图

app/portal/controller/ClassifyController.php 6.0 KB
anyv authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<?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(){
anyv authored
21
        //所有分类
anyv authored
22
        $data_classify = Db::name('classification') -> select();
anyv authored
23
        //所有标签
anyv authored
24
        $data_label = Db::name('label') -> select();
anyv authored
25 26
        $classify_id = $this -> request -> param();
        if($classify_id){
anyv authored
27
            //获取指定分类商品
9  
anyv authored
28
            $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();
anyv authored
29
            $this -> assign('class',$classify_id['classify_id']);
anyv authored
30
        }else{
anyv authored
31
            //获取默认分类商品
9  
anyv authored
32
            $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();
anyv authored
33
            $this -> assign('class',$data_classify[0]['id']);
anyv authored
34
        }
anyv authored
35
        foreach($data_goods as $key => $val){
anyv authored
36
            $price = explode('.',$data_goods[$key]['price']);
anyv authored
37 38
            $data_goods[$key]['price0'] = $price[0];
            $data_goods[$key]['price01'] = $price[1];
anyv authored
39
        }
anyv authored
40
        $this -> assign('data_goods',$data_goods);
anyv authored
41
        $this -> assign('data_label',$data_label);
anyv authored
42
        $this -> assign('data_classify',$data_classify);
anyv authored
43 44 45 46
        return $this -> fetch();

    }
anyv authored
47 48 49 50 51
    /**
     * 分类下的商品
     */
    public function classify_goods(){
anyv authored
52
            $classify_id = $_POST['classify_id'];
9  
anyv authored
53
            $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();
anyv authored
54 55 56 57
        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];
anyv authored
58
            $data_classify_goods[$key]['show_img'] = cmf_get_image_url($data_classify_goods[$key]['show_img']);
anyv authored
59 60 61 62 63
        }
        return json_encode($data_classify_goods);

    }
anyv authored
64 65 66 67 68 69
    /**
     * 分类标签下的商品
     */
    public function classify_lable_goods(){

        $label_id = $_POST['label_id'];
anyv authored
70
        $classify_id = $_POST['classify_id'];
9  
anyv authored
71
        $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();
anyv authored
72
        $data_classify_name = Db::name('classification') -> where('id',$classify_id) -> find();
anyv authored
73 74 75 76 77
        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']);
anyv authored
78
            $data_classify_lable_goods[$key]['name'] = $data_classify_name['name'];
anyv authored
79 80
        }
        return json_encode($data_classify_lable_goods);
anyv authored
81 82

    }
anyv authored
83
anyv authored
84 85 86 87 88
    /**
     * 销量排序
     */
    public function classify_sales(){
anyv authored
89
        $where = [
9  
anyv authored
90 91
            'a.type' => 1,
            'a.is_out' => 1
anyv authored
92 93
        ];
        if(!empty($_POST['classify_id'])){
anyv authored
94
            $where['a.classify_id'] = $_POST['classify_id'];
anyv authored
95 96
        }
        if(!empty($_POST['lable_id'])){
anyv authored
97
            $where['b.label_id'] = $_POST['lable_id'];
anyv authored
98
        }
anyv authored
99 100
        $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();
anyv authored
101 102 103 104 105
        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']);
anyv authored
106
            $data[$key]['name'] = $data_classify_name['name'];
anyv authored
107 108
        }
        return json_encode($data);
anyv authored
109 110

    }
anyv authored
111
anyv authored
112 113 114 115 116 117
    /**
     * 价格排序
     */
    public function classify_price(){

        $where = [
9  
anyv authored
118 119
            'a.type' => 1,
            'a.is_out' => 1
anyv authored
120 121 122 123 124 125 126
        ];
        if(!empty($_POST['classify_id'])){
            $where['classify_id'] = $_POST['classify_id'];
        }
        if(!empty($_POST['lable_id'])){
            $where['label_id'] = $_POST['lable_id'];
        }
anyv authored
127 128
        $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();
anyv authored
129 130 131 132 133
        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']);
anyv authored
134
            $data[$key]['name'] = $data_classify_name['name'];
anyv authored
135 136 137 138
        }
        return json_encode($data);

    }
anyv authored
139 140 141 142 143 144 145






anyv authored
146
anyv authored
147 148 149 150 151 152 153 154 155








anyv authored
156
}