审查视图

app/portal/controller/GoodsdetailsController.php 6.6 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 GoodsdetailsController extends WeChatBaseController{

    /**
     * 商品详情页
     */
    public function Goods_details(){
anyv authored
21
        $goods_id =  $this -> request -> param();
8  
anyv authored
22
        $data = Db::name('goods') -> alias('a') -> field("a.*,b.name") -> join('classification b','a.classify_id = b.id','LEFT') -> where('a.id',$goods_id['goods_id']) -> find();
anyv authored
23
        $this -> assign('price',$data['price']);
anyv authored
24
        $price = explode('.',$data['price']);
anyv authored
25
        $pricing = explode('.',$data['pricing']);
anyv authored
26 27
        $data['price0'] = $price[0];
        $data['price1'] = $price[1];
anyv authored
28 29
        $data['pricing0'] = $pricing[0];
        $data['pricing1'] = $pricing[1];
anyv authored
30 31
        $data['det_img'] = json_decode($data['det_img'],true);
      /*  $data['det_img'] = explode(',',$data['det_img']);*/
anyv authored
32
        $this -> assign('det_img',$data['det_img']);
anyv authored
33
        $this -> assign('data',$data);
anyv authored
34
        $data_label = Db::name('label') -> alias('a') -> field("a.*,b.goods_id,b.label_id") -> join('goods_label b','a.id=b.label_id','LEFT') -> where("b.goods_id = ".$goods_id['goods_id']) -> select();
anyv authored
35
        $this -> assign('data_label',$data_label);
anyv authored
36 37
        if($data['type'] == 1){
            //相关推荐
anyv authored
38
            $data_recomm = Db::name('goods') -> where("classify_id =".$data['classify_id']." and is_out = 1 and type = 1") -> limit(3) -> select();
anyv authored
39 40 41 42 43
            $this -> assign('data_recomm',$data_recomm);
            $this -> assign('is_recomm',1);
        }else{
            $this -> assign('is_recomm',2);
        }
anyv authored
44 45 46 47 48 49 50 51
        //添加浏览记录
        $uid = cmf_get_current_user_id();
        $data_browsing_history = Db::name('browsing_history') -> where("uid = ".$uid." and goods_id =".$goods_id['goods_id']) -> find();
        if(empty($data_browsing_history)){
            $browsing_history['uid'] = $uid;
            $browsing_history['goods_id'] = $goods_id['goods_id'];
            Db::name('browsing_history') -> insert($browsing_history);
        }
anyv authored
52 53 54 55 56 57 58 59 60
        //判断订单收藏
        $collect = Db::name('collect') -> where('goods_id',$goods_id['goods_id']) -> find();
        if($collect){
            //存在显示2
           $this -> assign('is_collect',2);
        }else{
            //不存在显示1
            $this -> assign('is_collect',1);
        }
anyv authored
61 62 63 64
        return $this -> fetch();

    }
anyv authored
65 66 67 68 69 70 71 72 73
    /**
     * 点击收藏
     */
    public function goods_collection(){

        $goods_id = $_POST['goods_id'];
        $uid = cmf_get_current_user_id();
        $arr['goods_id'] = $goods_id;
        $arr['uid'] = $uid;
anyv authored
74 75 76
        $collect = Db::name('collect') -> where('goods_id',$arr['goods_id']) -> find();
        if($collect){
         return 3;
anyv authored
77
        }else{
anyv authored
78 79 80 81 82 83
            $data = Db::name('collect') -> insert($arr);
            if($data){
                return true;
            }else{
                return false;
            }
anyv authored
84 85 86
        }

    }
anyv authored
87
anyv authored
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
    /**
     * 立即支付判断
     */
    public function goodsdetails_go_pay(){

        $uid = cmf_get_current_user_id();
        $goods_id = $_POST['id'];
        $data[] = Db::name('goods') -> where('id',$goods_id) -> find();
        $data[0]['book_num'] = 1;

        foreach ($data as $key => $val){
            if($data[0]['type'] == $data[$key]['type']){
            }else{
                $ret['type'] = 3;
                return json_encode($ret);
            }
        }
        if($data[0]['type'] == 1){

            $indent['uid'] = $uid;
            $indent['state'] = 4;
            $indent['order_number'] = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
            $indent['money'] = $_POST['myprice'];
            $indent['create_time'] = time();
            $indent['indent_type'] = 1;
            $indent['logistic_name'] = 'YTO';
            $book_num = 0;
            foreach ($data as $key => $val){
                $book_num += $val['book_num'];
            }
            $indent['book_num'] = $book_num;
            $indet_id = Db::name('indent') -> insertGetId($indent);
            foreach ($data as $key => $val){
                $indent_goods['book_name'] = $val['book_name'];
                $indent_goods['pricing'] = $val['pricing'];
                $indent_goods['price'] = $val['price'];
                $indent_goods['number'] = $val['book_num'];
                $indent_goods['thumbnail'] = $val['show_img'];
                $indent_goods['indent_id'] = $indet_id;
                $indent_goods['commission'] = $val['money'];
                $indent_goods['goods_id'] = $val['id'];
                Db::name('indent_goods ') -> insert($indent_goods);
            }
            $ret['type'] = 1;
            $ret['indet_id'] = $indet_id;
            $res = json_encode($ret);
            return $res;
        }elseif ($data[0]['type'] == 2){
            $indent['uid'] = $uid;
            $indent['state'] = 4;
            $indent['order_number'] = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
            $indent['money'] = $_POST['myprice'];
            $indent['indent_type'] = 2;
            $indent['create_time'] = time();
            $book_num = 0;
            foreach ($data as $key => $val){
                $book_num += $val['book_num'];
            }
            $indent['book_num'] = $book_num;
            $indent['salesman_uid'] = $data[0]['uid'];
            $indet_id = Db::name('indent') -> insertGetId($indent);
            foreach ($data as $key => $val){
                $indent_goods['book_name'] = $val['book_name'];
                $indent_goods['pricing'] = $val['pricing'];
                $indent_goods['price'] = $val['price'];
                $indent_goods['number'] = $val['book_num'];
                $indent_goods['thumbnail'] = $val['show_img'];
                $indent_goods['indent_id'] = $indet_id;
                $indent_goods['commission'] = $val['money'];
                $indent_goods['goods_id'] = $val['id'];
                Db::name('indent_goods ') -> insert($indent_goods);
            }
            $ret['type'] = 2;
            $ret['indet_id'] = $indet_id;
            $res = json_encode($ret);
            return $res;
        }







    }
anyv authored
173 174 175 176 177 178 179 180 181 182 183 184 185 186













anyv authored
187
}