审查视图

app/portal/controller/GoodsdetailsController.php 12.1 KB
anyv authored
1 2 3 4 5 6 7 8 9 10 11
<?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;
1  
anyv authored
12
use EasyWeChat\Foundation\Application;
anyv authored
13 14 15 16 17 18 19 20 21
use think\Db;

class GoodsdetailsController extends WeChatBaseController{

    /**
     * 商品详情页
     */
    public function Goods_details(){
anyv authored
22
        $goods_id =  $this -> request -> param();
5  
anyv authored
23 24 25
        $uid = cmf_get_current_user_id();
        //判断跳转过来的链接
        if(!empty($goods_id['status']) && !empty($goods_id['id'])){
王晓刚 authored
26 27 28 29 30 31
            //判断上级权限是否存在
            $my_user = Db::name('my_user') -> where('id',$goods_id['id']) -> find();
            if(empty($my_user)){
                $this->error('查无此人','','','');
            }
            if($my_user['status'] != $goods_id['status']){
王晓刚 authored
32
                $this->error('链接失效','','','');
王晓刚 authored
33
            }
5  
anyv authored
34 35 36
            $share_user = Db::name('my_user') -> where('uid',$uid) -> find();
            //判断用户是否存在
            if(!empty($share_user)){
王晓刚 authored
37
//                dump($share_user);
5  
anyv authored
38
                //判断用户是不是自由人
王晓刚 authored
39
                if($share_user['status'] == 0 || $share_user['status'] == 1 || $share_user['status'] == 5 || $share_user['status'] == 6){
5  
anyv authored
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
                    //如果是自由人 那就绑定关系
                    $share_data['status'] = 4;
                    $share_data['pid'] = $goods_id['id'];
                    $share_data['bind_time'] = time();
                    $share_data['bind_status'] = 1;
                    Db::name('my_user') -> where("uid",$uid) -> update($share_data);
                }
            }else{
                //用户不存在的话 如果是老师分享过来的
                if($goods_id['status'] == 3 || $goods_id['status'] == 4){
                    //判断这个用户是否存在
                    if(empty($share_user)){
                        $share_data['status'] = 4;
                        $share_data['uid'] = $uid;
                        $share_data['create_time'] = time();
                        $share_data['is_pro'] = 0;
                        $share_data['pid'] = $goods_id['id'];
                        $share_data['bind_time'] = time();
                        $share_data['bind_status'] = 1;
                        Db::name('my_user') -> insert($share_data);
                    }
                }
            }

        }
8  
anyv authored
65
        $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();
5  
anyv authored
66 67 68 69
        //当商品不存在时跳转到首页
        if(empty($data)){
            $this -> redirect("Index/index");
        }
anyv authored
70
        $this -> assign('price',$data['price']);
anyv authored
71
        $price = explode('.',$data['price']);
anyv authored
72
        $pricing = explode('.',$data['pricing']);
anyv authored
73 74
        $data['price0'] = $price[0];
        $data['price1'] = $price[1];
anyv authored
75 76
        $data['pricing0'] = $pricing[0];
        $data['pricing1'] = $pricing[1];
anyv authored
77
        $data['det_img'] = json_decode($data['det_img'],true);
4  
anyv authored
78
        $data['instr'] = cmf_replace_content_file_url(htmlspecialchars_decode($data['instr']));
刘朕 authored
79
//        $data['instr'] = explode(' ',$data['instr']);
anyv authored
80
      /*  $data['det_img'] = explode(',',$data['det_img']);*/
anyv authored
81
        $this -> assign('det_img',$data['det_img']);
anyv authored
82
        $this -> assign('data',$data);
anyv authored
83
        $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
84
        $this -> assign('data_label',$data_label);
anyv authored
85 86
        if($data['type'] == 1){
            //相关推荐
anyv authored
87
            $data_recomm = Db::name('goods') -> where("classify_id =".$data['classify_id']." and is_out = 1 and type = 1") -> limit(3) -> select();
anyv authored
88 89 90 91 92
            $this -> assign('data_recomm',$data_recomm);
            $this -> assign('is_recomm',1);
        }else{
            $this -> assign('is_recomm',2);
        }
anyv authored
93 94 95 96 97 98 99 100
        //添加浏览记录
        $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
101
        //判断订单收藏
anyv authored
102
        $collect = Db::name('collect') -> where('goods_id',$goods_id['goods_id']) -> where('uid',$uid) -> find();
anyv authored
103 104 105 106 107 108 109
        if($collect){
            //存在显示2
           $this -> assign('is_collect',2);
        }else{
            //不存在显示1
            $this -> assign('is_collect',1);
        }
4  
anyv authored
110
anyv authored
111
1  
anyv authored
112 113 114 115
        //商品详情分享
        $options=config('wechat_config');
        $app = new Application($options);
        $js = $app->js;
5  
anyv authored
116
        $jssdk=$js->config(array('onMenuShareAppMessage', 'onMenuShareTimeline'), false,false,true);
1  
anyv authored
117
        $this->assign('jssdk',$jssdk);
5  
anyv authored
118 119 120 121
        //判断用户身份
        $my_user = Db::name('my_user') -> where('uid',$uid) -> find();
        //如果是业务员身份
        if($my_user['status'] == 2 || $my_user['status'] == 0 || $my_user['status'] == 1 || $my_user['status'] == 5 || $my_user['status'] == 6){
刘朕 authored
122
            $url = request()->domain()."/portal/goodsdetails/goods_details/goods_id/".$goods_id['goods_id'];
5  
anyv authored
123 124 125
        }
        //如果是老师身份
        if($my_user['status'] == 3){
刘朕 authored
126
            $url = request()->domain()."/portal/goodsdetails/goods_details/goods_id/".$goods_id['goods_id']."/status/".$my_user['status']."/id/".$my_user['id'];
5  
anyv authored
127 128 129 130 131
        }
        //学生身份
        if($my_user['status'] == 4){
            $teacher_my_user = Db::name('my_user') -> where('id',$my_user['pid']) -> find();
            if(empty($goods_id['id'])){
刘朕 authored
132
                $url = request()->domain()."/portal/goodsdetails/goods_details/goods_id/".$goods_id['goods_id']."/status/3/id/".$teacher_my_user['id'];
5  
anyv authored
133
            }else{
刘朕 authored
134
                $url = request()->domain()."/portal/goodsdetails/goods_details/goods_id/".$goods_id['goods_id']."/status/".$goods_id['status']."/id/".$goods_id['id'];
5  
anyv authored
135 136
            }
        }
1  
anyv authored
137
        $this -> assign('url',$url);
4  
anyv authored
138
        return $this -> fetch();
anyv authored
139 140
    }
anyv authored
141 142 143 144 145 146 147 148 149
    /**
     * 点击收藏
     */
    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
150
        $collect = Db::name('collect') -> where('goods_id',$arr['goods_id']) -> where('uid',$uid) -> find();
anyv authored
151 152
        if($collect){
         return 3;
anyv authored
153
        }else{
anyv authored
154 155 156 157 158 159
            $data = Db::name('collect') -> insert($arr);
            if($data){
                return true;
            }else{
                return false;
            }
anyv authored
160 161 162
        }

    }
anyv authored
163
anyv authored
164
    /**
anyv authored
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
     * 点击取消收藏
     */
    public function cancel_goods_collection(){

        $uid = cmf_get_current_user_id();
        $goods_id = $_POST['goods_id'];
        $data = Db::name('collect') -> where("uid=".$uid." and goods_id=".$goods_id) -> delete();
        if($data){
            return true;
        }else{
            return false;
        }

    }














    /**
anyv authored
194 195 196 197 198
     * 立即支付判断
     */
    public function goodsdetails_go_pay(){

        $uid = cmf_get_current_user_id();
anyv authored
199 200 201 202 203
        $my_user = Db::name('my_user') -> where('uid',$uid) -> find();
        if($my_user['status'] == 2){
            $ret['type'] = 20;
            return json_encode($ret);
        }
王晓刚 authored
204 205 206 207
        if(in_array(intval($my_user['status']),[1,5,6])){
            $ret['type'] = 21;
            return json_encode($ret);
        }
anyv authored
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
        $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;
王晓刚 authored
223
            $indent['order_number'] = cmf_get_order_sn().rand(00000,99999);
anyv authored
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
            $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;
王晓刚 authored
252
            $indent['order_number'] = cmf_get_order_sn().rand(00000,99999);
anyv authored
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
            $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;
        }
5  
anyv authored
280
    }
anyv authored
281
5  
anyv authored
282 283 284 285
    /**
     * 判断购买的商品是不是自己上一级业务员卖的商品
     */
    public function is_salesmang_goods(){
anyv authored
286
5  
anyv authored
287 288 289
        $uid = cmf_get_current_user_id();
        $goods_uid = Db::name('goods') -> where("id",$_POST['goods_id']) -> find();
        $my_user = Db::name('my_user') -> where('uid',$uid) -> find();
4  
anyv authored
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
        if($goods_uid['type'] == 1){
            return true;
        }else{
            if($my_user['status'] == 3){
                $salesman_user = Db::name('my_user') -> where('id',$my_user['pid']) -> find();
            }
            if($my_user['status'] == 4){
                $teacher_user = Db::name('my_user') -> where('id',$my_user['pid']) -> find();
                $salesman_user = Db::name('my_user') -> where('id',$teacher_user['pid']) -> find();
            }
            if(!empty($salesman_user)){
                if($goods_uid['uid'] == $salesman_user['uid']){
                    return true;
                }else{
                    return false;
                }
5  
anyv authored
306
            }else{
4  
anyv authored
307
                return true;
5  
anyv authored
308 309
            }
        }
anyv authored
310 311

    }
anyv authored
312 313 314 315 316 317 318 319 320 321 322 323











anyv authored
324
}