审查视图

app/portal/controller/IndexController.php 28.8 KB
anyv authored
1 2 3 4 5 6 7 8 9 10
<?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;
anyv authored
11
use cmf\controller\WeChatBaseController;
王晓刚 authored
12
use EasyWeChat\Foundation\Application;
anyv authored
13
use think\Db;
anyv authored
14
anyv authored
15
class IndexController extends WeChatBaseController
anyv authored
16
{
anyv authored
17 18 19
    /**
     * 显示首页
     */
anyv authored
20
    public function index(){
anyv authored
21
        //显示分类
anyv authored
22 23
        $data_classif= Db::name('classification') -> select();
        $this -> assign('data_classif',$data_classif);
anyv authored
24
        //热门推荐
anyv authored
25
        $data_goods_hot = Db::name('goods') -> alias('a') -> field('a.*,b.name') -> join('classification b','a.classify_id = b.id','LEFT') -> where("a.recommend_hot=1 and a.type = 1 and a.is_out = 1") -> select() -> toArray();
anyv authored
26 27 28 29 30 31
        if(!empty($data_goods_hot)){
            foreach($data_goods_hot as $key => $val){
                $price = explode('.',$data_goods_hot[$key]['price']);
                $data_goods_hot[$key]['price0'] = $price[0];
                $data_goods_hot[$key]['price1'] = $price[1];
            }
anyv authored
32
        }
anyv authored
33 34 35
        //首页轮播图
        $slideshow = Db::name('slide_item') -> select();
        $this -> assign('slideshow',$slideshow);
anyv authored
36 37 38 39 40
        //判断用户是否存在
        $uid = cmf_get_current_user_id();
        $data_my_user = Db::name('my_user') -> where('uid',$uid) -> find();
        if($data_my_user){
            //用户是否为自由人 是自由人则绑定 不是自由人判断是不是老师
anyv authored
41
            if($data_my_user['status'] == 0 || $data_my_user['status'] == 1 || $data_my_user['status'] == 5 || $data_my_user['status'] == 6){
anyv authored
42 43
                $data_id = $this -> request -> param();
                //判断跳转链接是否存在数据 存在则绑定关系
王晓刚 authored
44
                if(!empty($data_id['my_user_id'])){
45 46 47 48 49 50
                    //判断上级权限是否存在
                    $my_user = Db::name('my_user') -> where('id',$data_id['my_user_id']) -> find();
                    if(empty($my_user)){
                        $this->error('查无此人','','','');
                    }
                    if($my_user['status'] != $data_id['status_id']){
王晓刚 authored
51
                        $this->error('链接失效','','','');
52
                    }
anyv authored
53 54 55 56 57 58 59 60 61 62 63
                    //判断数据是老师还是业务员
                    if($data_id['status_id'] == 2){
                        //业务员分享 更改用户身份为老师
                        $my_user_phone = Db::name('my_user') -> where('id',$data_id['my_user_id']) -> find();
                        $data_update['status'] = 3;
                        $data_update['inviter_phone'] = $my_user_phone['phone'];
                        $data_update['is_pro'] = 1;
                        $data_update['pid'] = $my_user_phone['id'];
                        $data_update['bind_time'] = time();
                        $data_update['bind_status'] = 1;
                        Db::name('my_user') -> where('uid',$uid) -> update($data_update);
王晓刚 authored
64
                        $data_goods = Db::name('goods') -> where('uid',$my_user_phone['uid']) -> where('is_out',1) -> order("sort desc") -> limit(6) -> select() -> toArray();
anyv authored
65 66 67 68 69 70 71 72 73 74
                    }elseif ($data_id['status_id'] == 3){
                        //老师分享 更改用户身份为学生
                        $my_user_phone = Db::name('my_user') -> where('id',$data_id['my_user_id']) -> find();
                        $data_update['status'] = 4;
                        $data_update['inviter_phone'] = $my_user_phone['phone'];
                        $data_update['is_pro'] = 0;
                        $data_update['pid'] = $my_user_phone['id'];
                        $data_update['bind_time'] = time();
                        $data_update['bind_status'] = 1;
                        Db::name('my_user') -> where('uid',$uid) -> update($data_update);
anyv authored
75
                        $salesman_id = Db::name('my_user') -> where('id',$my_user_phone['pid']) -> find();
王晓刚 authored
76
                        $data_goods = Db::name('goods') -> where('uid',$salesman_id['uid']) -> where('is_out',1) -> order("sort desc") -> limit(6) -> select() -> toArray();
anyv authored
77 78 79 80 81
                    }
                }
            }else{
                $data_id = $this -> request -> param();
                //判断跳转链接是否存在数据
7  
anyv authored
82
                if(!empty($data_id['status_id'])){
王晓刚 authored
83 84 85 86 87 88
                    //判断上级权限是否存在
                    $my_user = Db::name('my_user') -> where('id',$data_id['my_user_id']) -> find();
                    if(empty($my_user)){
                        $this->error('查无此人','','','');
                    }
                    if($my_user['status'] != $data_id['status_id']){
王晓刚 authored
89
                        $this->error('链接失效','','','');
王晓刚 authored
90
                    }
anyv authored
91 92 93 94 95 96 97 98 99
                    //判断用户是不是老师
                    if($data_my_user['status'] == 3){
                        //是老师则判断老师绑定状态
                        if($data_my_user['bind_status'] = 2){
                            //判断是否为业务员分享的链接
                            if($data_id['status_id'] == 2){
                                //是业务员分享则更新老师的pid
                                $my_user_phone = Db::name('my_user') -> where('id',$data_id['my_user_id']) -> find();
                                $data_update['pid'] = $my_user_phone['id'];
anyv authored
100 101
                                $data_update['bind_time'] = time();
                                $data_update['bind_status'] = 1;
anyv authored
102
                                Db::name('my_user') -> where('uid',$uid) -> update($data_update);
王晓刚 authored
103
                                $data_goods = Db::name('goods') -> where('uid',$my_user_phone['uid']) -> where('is_out',1) -> order("sort desc") -> limit(6) -> select() -> toArray();
anyv authored
104 105
                            }else{
                                $salesman_id = Db::name('my_user') -> where('id',$data_my_user['pid']) -> find();
王晓刚 authored
106
                                $data_goods = Db::name('goods') -> where('uid',$salesman_id['uid']) -> where('is_out',1) -> order("sort desc") -> limit(6) -> select() -> toArray();
anyv authored
107 108 109
                            }
                        }else{
                            $salesman_id = Db::name('my_user') -> where('id',$data_my_user['pid']) -> find();
王晓刚 authored
110
                            $data_goods = Db::name('goods') -> where('uid',$salesman_id['uid']) -> where('is_out',1) -> order("sort desc") -> limit(6) -> select() -> toArray();
anyv authored
111 112 113 114
                        }
                    }else{
                        //当为业务员时显示的数据
                        if($data_my_user['status'] == 2){
王晓刚 authored
115
                            $data_goods = Db::name('goods') -> where('uid',$data_my_user['uid']) -> where('is_out',1) -> order("sort desc") -> limit(6) -> select() -> toArray();
anyv authored
116 117 118 119 120
                        }
                        //当为学生时显示的数据
                        if($data_my_user['status'] == 4){
                            $teacher_id = Db::name('my_user') -> where('id',$data_my_user['pid']) -> find();
                            $salesman_id = Db::name('my_user') -> where('id',$teacher_id['pid']) -> find();
王晓刚 authored
121
                            $data_goods = Db::name('goods') -> where('uid',$salesman_id['uid']) -> where('is_out',1) -> order("sort desc") -> limit(6) -> select() -> toArray();
anyv authored
122 123 124 125 126
                        }
                    }
                }else{
                    //当为业务员时显示的数据
                    if($data_my_user['status'] == 2){
王晓刚 authored
127
                        $data_goods = Db::name('goods') -> where('uid',$data_my_user['uid']) -> where('is_out',1) -> order("sort desc") -> limit(6) -> select() -> toArray();
anyv authored
128 129 130 131
                    }
                    //当为老师时显示的数据
                    if($data_my_user['status'] == 3){
                        $salesman_id = Db::name('my_user') -> where('id',$data_my_user['pid']) -> find();
王晓刚 authored
132
                        $data_goods = Db::name('goods') -> where('uid',$salesman_id['uid']) -> where('is_out',1) -> order("sort desc") -> limit(6) -> select() -> toArray();
anyv authored
133 134 135 136 137
                    }
                    //当为学生时显示的数据
                    if($data_my_user['status'] == 4){
                        $teacher_id = Db::name('my_user') -> where('id',$data_my_user['pid']) -> find();
                        $salesman_id = Db::name('my_user') -> where('id',$teacher_id['pid']) -> find();
王晓刚 authored
138
                        $data_goods = Db::name('goods') -> where('uid',$salesman_id['uid']) -> where('is_out',1) -> order("sort desc") -> limit(6) -> select() -> toArray();
anyv authored
139 140 141 142 143 144
                    }
                }
            }
        }else{
            $data_id = $this -> request -> param();
            //判断跳转链接是否存在数据 如果不存在添加一条自由人用户
王晓刚 authored
145
            if(!empty($data_id['my_user_id'])){
王晓刚 authored
146 147 148 149 150 151
                //判断上级权限是否存在
                $my_user = Db::name('my_user') -> where('id',$data_id['my_user_id']) -> find();
                if(empty($my_user)){
                    $this->error('查无此人','','','');
                }
                if($my_user['status'] != $data_id['status_id']){
王晓刚 authored
152
                    $this->error('链接失效','','','');
王晓刚 authored
153
                }
anyv authored
154 155 156 157 158 159 160 161 162 163 164 165 166
                //判断数据是老师还是业务员
                if($data_id['status_id'] == 2){
                    //业务员分享 添加老师
                    $my_user_phone = Db::name('my_user') -> where('id',$data_id['my_user_id']) -> find();
                    $data_inser['status'] = 3;
                    $data_inser['uid'] = $uid;
                    $data_inser['inviter_phone'] = $my_user_phone['phone'];
                    $data_inser['create_time'] = time();
                    $data_inser['is_pro'] = 1;
                    $data_inser['pid'] = $my_user_phone['id'];
                    $data_inser['bind_time'] = time();
                    $data_inser['bind_status'] = 1;
                    Db::name('my_user') -> insert($data_inser);
王晓刚 authored
167
                    $data_goods = Db::name('goods') -> where('uid',$my_user_phone['uid']) -> where('is_out',1) -> order("sort desc") -> limit(6) -> select() -> toArray();
anyv authored
168 169 170 171 172 173 174 175 176 177 178 179
                }elseif ($data_id['status_id'] == 3){
                    //老师分享 添加学生
                    $my_user_phone = Db::name('my_user') -> where('id',$data_id['my_user_id']) -> find();
                    $data_inser['status'] = 4;
                    $data_inser['uid'] = $uid;
                    $data_inser['inviter_phone'] = $my_user_phone['phone'];
                    $data_inser['create_time'] = time();
                    $data_inser['is_pro'] = 0;
                    $data_inser['pid'] = $my_user_phone['id'];
                    $data_inser['bind_time'] = time();
                    $data_inser['bind_status'] = 1;
                    Db::name('my_user') -> insert($data_inser);
anyv authored
180
                    $salesman_id = Db::name('my_user') -> where('id',$my_user_phone['pid']) -> find();
王晓刚 authored
181
                    $data_goods = Db::name('goods') -> where('uid',$salesman_id['uid']) -> where('is_out',1) -> order("sort desc") -> limit(6) -> select() -> toArray();
anyv authored
182 183 184 185 186 187 188 189 190
                }
            }else{
                $data_inser['status'] = 0;
                $data_inser['uid'] = $uid;
                $data_inser['create_time'] = time();
                $data_inser['is_pro'] = 0;
                Db::name('my_user') -> insert($data_inser);
            }
        }
anyv authored
191 192
        if(empty($data_goods)) {
            $data_goods = null;
王晓刚 authored
193
            $limit_num = 6;
5  
anyv authored
194
        }else{
王晓刚 authored
195
            $limit_num = 6-count($data_goods);
anyv authored
196
        }
anyv authored
197
        $this -> assign('data_goods',$data_goods);
anyv authored
198
        //推荐新品
8  
anyv authored
199
        if($limit_num != 0){
王晓刚 authored
200
            $data_goods_recommend_new = Db::name('goods') -> alias('a') -> field('a.*,b.name') -> join('classification b','a.classify_id = b.id','LEFT') -> where("recommend_new=1 and is_out = 1 and type = 1") -> limit(0) -> select() -> toArray();
5  
anyv authored
201 202
        }else{
            $data_goods_recommend_new = null;
8  
anyv authored
203
        }
王晓刚 authored
204 205 206 207 208 209 210 211
        //分享
        $options=config('wechat_config');
        $app = new Application($options);
        $js = $app->js;
        $jssdk=$js->config(array('onMenuShareAppMessage', 'onMenuShareTimeline'), false,false,true);
        $this->assign('jssdk',$jssdk);
        $arr = [];
        if($data_my_user['status'] == 3){
王晓刚 authored
212
            $arr['status_id'] = 3;
王晓刚 authored
213 214
            $arr['my_user_id'] = $data_my_user['id'];
        }else if($data_my_user['status'] == 4) {
王晓刚 authored
215 216
            $arr['status_id'] = 3;
            $arr['my_user_id'] = $data_my_user['pid'];
王晓刚 authored
217
        }
王晓刚 authored
218
        $url = url('',$arr,true,true);
王晓刚 authored
219
        $this->assign('url',$url);
anyv authored
220
        $this -> assign('data_goods_recommend_new',$data_goods_recommend_new);
anyv authored
221
        $this -> assign('data_goods_hot',$data_goods_hot);
anyv authored
222 223
        return $this -> fetch();
anyv authored
224
    }
anyv authored
225
anyv authored
226 227 228 229 230
    /**
     * 首页搜索
     */
    public function search_salesman_goods(){
anyv authored
231
        $book_name = $this -> request -> param();
anyv authored
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
        $uid = cmf_get_current_user_id();
        $data_status = Db::name('my_user') -> where("uid",$uid) -> find();
        $where = ['type'=>1];
        if($data_status['status'] == 2){
            $where = "type = 1 or uid = ".$uid;
        }
        if($data_status['status'] == 3){
           $salesman_uid = Db::name('my_user') -> where('id',$data_status['pid']) -> find();
            $where = "type = 1 or uid =".$salesman_uid['uid'];
        }
        if($data_status['status'] == 4){
            $teacher_id = Db::name('my_user') -> where('id',$data_status['pid']) -> find();
            $salesman_id = Db::name('my_user') -> where('id',$teacher_id['pid']) -> find();
            $where = "type = 1 or uid =".$salesman_id['uid'];
        }
anyv authored
248
        if(empty($book_name['book_name'])){
anyv authored
249
            $book_name = '';
anyv authored
250
            $data_salesman_goods = Db::name('goods') -> alias('a') -> field("a.*,b.name") -> join('classification b','a.classify_id = b.id','LEFT') -> where($where) -> where('is_out',1) -> select() -> toArray();
9  
anyv authored
251
        }else{
anyv authored
252
            $book_name = $book_name['book_name'];
5  
anyv authored
253
            $data_salesman_goods = Db::name('goods') -> alias('a') -> field("a.*,b.name") -> join('classification b','a.classify_id = b.id','LEFT') -> where($where) -> where('is_out',1) -> where('book_name','like',"%".$book_name."%") -> select() -> toArray();
9  
anyv authored
254
        }
anyv authored
255 256 257 258 259 260 261
        if(!empty($data_salesman_goods)){
            foreach ($data_salesman_goods as $key => $val){
                $price = explode('.',$data_salesman_goods[$key]['price']);
                $data_salesman_goods[$key]['price0'] = $price[0];
                $data_salesman_goods[$key]['price1'] = $price[1];
            }
        }
anyv authored
262
        $this -> assign('search_content',$book_name);
anyv authored
263
        $this -> assign('data_salesman_goods',$data_salesman_goods);
anyv authored
264
        return $this -> fetch();
anyv authored
265
anyv authored
266
    }
anyv authored
267
anyv authored
268 269 270 271 272
    /**
     * 首页搜索结果页 销量排序
     */
    public function search_sales_order(){
anyv authored
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
        $uid = cmf_get_current_user_id();
        $data_status = Db::name('my_user') -> where("uid",$uid) -> find();
        $where = ['type'=>1];
        if($data_status['status'] == 2){
            $where = "type = 1 or uid = ".$uid;
        }
        if($data_status['status'] == 3){
            $salesman_uid = Db::name('my_user') -> where('id',$data_status['pid']) -> find();
            $where = "type = 1 or uid =".$salesman_uid['uid'];
        }
        if($data_status['status'] == 4){
            $teacher_id = Db::name('my_user') -> where('id',$data_status['pid']) -> find();
            $salesman_id = Db::name('my_user') -> where('id',$teacher_id['pid']) -> find();
            $where = "type = 1 or uid =".$salesman_id['uid'];
        }
anyv authored
289
        $search_content = $_POST['search_content'];
anyv authored
290
        $search_content_data = Db::name('goods') -> alias('a') -> field("a.*,b.name") -> join('classification b','a.classify_id = b.id','LEFT') -> where($where) -> where('book_name','like',"%".$search_content."%") -> order('sales desc') -> select() -> toArray();
6  
anyv authored
291 292 293 294 295
        if(!empty($search_content_data)){
            foreach ($search_content_data as $key => $val){
                $price = explode('.',$search_content_data[$key]['price']);
                $search_content_data[$key]['price0'] = $price[0];
                $search_content_data[$key]['price1'] = $price[1];
6  
anyv authored
296
                $search_content_data[$key]['show_img'] = cmf_get_image_url($search_content_data[$key]['show_img']);
6  
anyv authored
297 298 299
            }
        }
        return json_encode($search_content_data);
anyv authored
300 301

    }
anyv authored
302
5  
anyv authored
303 304 305 306 307
    /**
     * 首页搜索结果页 价格排序
     */
    public function search_price_order(){
anyv authored
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
        $uid = cmf_get_current_user_id();
        $data_status = Db::name('my_user') -> where("uid",$uid) -> find();
        $where = ['type'=>1];
        if($data_status['status'] == 2){
            $where = "type = 1 or uid = ".$uid;
        }
        if($data_status['status'] == 3){
            $salesman_uid = Db::name('my_user') -> where('id',$data_status['pid']) -> find();
            $where = "type = 1 or uid =".$salesman_uid['uid'];
        }
        if($data_status['status'] == 4){
            $teacher_id = Db::name('my_user') -> where('id',$data_status['pid']) -> find();
            $salesman_id = Db::name('my_user') -> where('id',$teacher_id['pid']) -> find();
            $where = "type = 1 or uid =".$salesman_id['uid'];
        }
5  
anyv authored
324
        $search_content = $_POST['search_content'];
anyv authored
325
        $search_content_data = Db::name('goods') -> alias('a') -> field("a.*,b.name") -> join('classification b','a.classify_id = b.id','LEFT') -> where($where) -> where('book_name','like',"%".$search_content."%") -> order('price desc') -> select() -> toArray();
5  
anyv authored
326 327 328 329 330 331 332 333 334 335 336
        if(!empty($search_content_data)){
            foreach ($search_content_data as $key => $val){
                $price = explode('.',$search_content_data[$key]['price']);
                $search_content_data[$key]['price0'] = $price[0];
                $search_content_data[$key]['price1'] = $price[1];
                $search_content_data[$key]['show_img'] = cmf_get_image_url($search_content_data[$key]['show_img']);
            }
        }
        return json_encode($search_content_data);

    }
anyv authored
337
5  
anyv authored
338 339 340 341
    /**
     * 首页搜索结果页 综合
     */
    public function search_synthesis_order(){
anyv authored
342
anyv authored
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
        $uid = cmf_get_current_user_id();
        $data_status = Db::name('my_user') -> where("uid",$uid) -> find();
        $where = ['type'=>1];
        if($data_status['status'] == 2){
            $where = "type = 1 or uid = ".$uid;
        }
        if($data_status['status'] == 3){
            $salesman_uid = Db::name('my_user') -> where('id',$data_status['pid']) -> find();
            $where = "type = 1 or uid =".$salesman_uid['uid'];
        }
        if($data_status['status'] == 4){
            $teacher_id = Db::name('my_user') -> where('id',$data_status['pid']) -> find();
            $salesman_id = Db::name('my_user') -> where('id',$teacher_id['pid']) -> find();
            $where = "type = 1 or uid =".$salesman_id['uid'];
        }
5  
anyv authored
359
        $book_name = $_POST['search_content'];
anyv authored
360
        $data_salesman_goods = Db::name('goods') -> alias('a') -> field("a.*,b.name") -> join('classification b','a.classify_id = b.id','LEFT') -> where($where) -> where('book_name','like',"%".$book_name."%") -> select() -> toArray();
5  
anyv authored
361 362 363 364 365 366 367 368 369 370
        if(!empty($data_salesman_goods)){
            foreach ($data_salesman_goods as $key => $val){
                $price = explode('.',$data_salesman_goods[$key]['price']);
                $data_salesman_goods[$key]['price0'] = $price[0];
                $data_salesman_goods[$key]['price1'] = $price[1];
                $data_salesman_goods[$key]['show_img'] = cmf_get_image_url($data_salesman_goods[$key]['show_img']);
            }
        }
        return json_encode($data_salesman_goods);
    }
anyv authored
371
anyv authored
372 373 374 375 376 377
    /**
     * 搜索跳转详情页
     */
    public function search_goods_details(){

        $goods_id =  $this -> request -> param();
7  
anyv authored
378
        $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
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
        $price = explode('.',$data['price']);
        $pricing = explode('.',$data['pricing']);
        $data['price0'] = $price[0];
        $data['price1'] = $price[1];
        $data['pricing0'] = $pricing[0];
        $data['pricing1'] = $pricing[1];
        $data['det_img'] = json_decode($data['det_img'],true);
        $this -> assign('det_img',$data['det_img']);
        $this -> assign('data',$data);
        $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();
        $this -> assign('data_label',$data_label);
        if($data['type'] == 1){
            //相关推荐
            $data_recomm = Db::name('goods') -> where("classify_id =".$data['classify_id']." and type = 1") -> limit(3) -> select();
            $this -> assign('data_recomm',$data_recomm);
            $this -> assign('is_recomm',1);
        }else{
            $this -> assign('is_recomm',2);
        }
anyv authored
398 399 400 401 402 403 404 405
        //添加浏览记录
        $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
406 407 408
        return $this -> fetch();

    }
anyv authored
409
5  
anyv authored
410 411 412 413 414
    /**
     * 显示业务员商城页
     */
    public function salesman_goods(){
4  
anyv authored
415 416 417 418 419
        $uid = cmf_get_current_user_id();
        $user = Db::name('my_user') -> where('uid',$uid) -> find();
        if($user['status'] == 0 || $user['status'] == 1 || $user['status'] == 5 || $user['status'] == 6){
            $salesman_goods = null;
        }elseif ($user['status'] == 2){
5  
anyv authored
420
            $salesman_goods = Db::name('goods') -> where('uid',$uid) -> where('is_out',1) -> order("sort desc") -> select() -> toArray();
4  
anyv authored
421 422
        }elseif ($user['status'] == 3){
            $salesman_id = Db::name('my_user') -> where('id',$user['pid']) -> find();
5  
anyv authored
423
            $salesman_goods = Db::name('goods') -> where('uid',$salesman_id['uid']) -> where('is_out',1) -> order("sort desc") -> select() -> toArray();
4  
anyv authored
424 425 426
        }elseif ($user['status'] == 4){
            $teacher_id = Db::name('my_user') -> where('id',$user['pid']) -> find();
            $salesman_id = Db::name('my_user') -> where('id',$teacher_id['pid']) -> find();
5  
anyv authored
427
            $salesman_goods = Db::name('goods') -> where('uid',$salesman_id['uid']) -> where('is_out',1) -> order("sort desc") -> select() -> toArray();
4  
anyv authored
428
        }
王晓刚 authored
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
        $param = $this->request->param();
        if(!empty($param['status_id']) && !empty($param['my_user_id'])){
            //判断上级权限是否存在
            $my_user = Db::name('my_user') -> where('id',$param['my_user_id']) -> find();
            if(empty($my_user)){
                $this->error('查无此人','','','');
            }
            if($my_user['status'] != $param['status_id']){
                $this->error('分享失效','','','');
            }
            if($user['status'] == 0){
                //判断数据是老师还是业务员
                if($param['status_id'] == 2){
                    //业务员分享 更改用户身份为老师
                    $my_user_phone = Db::name('my_user') -> where('id',$param['my_user_id']) -> find();
                    $data_update['status'] = 3;
                    $data_update['inviter_phone'] = $my_user_phone['phone'];
                    $data_update['is_pro'] = 1;
                    $data_update['pid'] = $my_user_phone['id'];
                    $data_update['bind_time'] = time();
                    $data_update['bind_status'] = 1;
                    Db::name('my_user') -> where('uid',$uid) -> update($data_update);
                }elseif ($param['status_id'] == 3){
                    //老师分享 更改用户身份为学生
                    $my_user_phone = Db::name('my_user') -> where('id',$param['my_user_id']) -> find();
                    $data_update['status'] = 4;
                    $data_update['inviter_phone'] = $my_user_phone['phone'];
                    $data_update['is_pro'] = 0;
                    $data_update['pid'] = $my_user_phone['id'];
                    $data_update['bind_time'] = time();
                    $data_update['bind_status'] = 1;
                    Db::name('my_user') -> where('uid',$uid) -> update($data_update);
                    $salesman_id = Db::name('my_user') -> where('id',$my_user_phone['pid']) -> find();
                }
            }
        }
4  
anyv authored
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
        if(!empty($salesman_goods)){
            foreach ($salesman_goods as $key => $val){
                $price = explode('.',$salesman_goods[$key]['price']);
                $salesman_goods[$key]['price0'] = $price[0];
                $salesman_goods[$key]['price1'] = $price[1];
            }
        }
        $this -> assign('salesman_goods',$salesman_goods);
        $goods = Db::name('goods') -> where("type = 1 and is_out = 1 and recommend_new = 1") -> select() -> toArray();
        if(!empty($goods)){
            foreach($goods as $key => $val){
                $price = explode('.',$goods[$key]['price']);
                $goods[$key]['price0'] = $price[0];
                $goods[$key]['price1'] = $price[1];
            }
        }
        $this -> assign('goods',$goods);
王晓刚 authored
482 483 484 485 486 487 488 489
        //分享
        $options=config('wechat_config');
        $app = new Application($options);
        $js = $app->js;
        $jssdk=$js->config(array('onMenuShareAppMessage', 'onMenuShareTimeline'), false,false,true);
        $this->assign('jssdk',$jssdk);
        $arr = [];
        if($user['status'] == 3){
王晓刚 authored
490 491
            $arr['status_id'] = 3;
            $arr['my_user_id'] = $user['id'];
王晓刚 authored
492 493 494 495 496 497
        }else if($user['status'] == 4) {
            $arr['status_id'] = 3;
            $arr['my_user_id'] = $user['pid'];
        }
        $url = url('portal/index/salesman_goods',$arr,true,true);
        $this->assign('url',$url);
5  
anyv authored
498 499 500 501
        return $this -> fetch();

    }
5  
anyv authored
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
    /**
     * 显示热门推荐页
     */
    public function hot_goods(){

        $hot_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 recommend_hot = 1") -> select() -> toArray();
        if(!empty($hot_goods)){
            foreach ($hot_goods as $key => $val){
                $price = explode('.',$hot_goods[$key]['price']);
                $hot_goods[$key]['price0'] = $price[0];
                $hot_goods[$key]['price1'] = $price[1];
            }
        }
        $this -> assign('hot_goods',$hot_goods);
        return $this -> fetch();

    }
5  
anyv authored
519
anyv authored
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
    /**
     *搜索页点击搜索
     */
    public function my_search(){

        $uid = cmf_get_current_user_id();
        $data_status = Db::name('my_user') -> where("uid",$uid) -> find();
        $where = ['type'=>1];
        if($data_status['status'] == 2){
            $where = "type = 1 or uid = ".$uid;
        }
        if($data_status['status'] == 3){
            $salesman_uid = Db::name('my_user') -> where('id',$data_status['pid']) -> find();
            $where = "type = 1 or uid =".$salesman_uid['uid'];
        }
        if($data_status['status'] == 4){
            $teacher_id = Db::name('my_user') -> where('id',$data_status['pid']) -> find();
            $salesman_id = Db::name('my_user') -> where('id',$teacher_id['pid']) -> find();
            $where = "type = 1 or uid =".$salesman_id['uid'];
        }
        if(empty($_POST['book_name'])){
            $book_name = '';
anyv authored
542
            $data_salesman_goods = Db::name('goods') -> alias('a') -> field("a.*,b.name") -> join('classification b','a.classify_id = b.id','LEFT') -> where($where) -> where('is_out',1) -> select() -> toArray();
anyv authored
543 544
        }else{
            $book_name = $_POST['book_name'];
anyv authored
545
            $data_salesman_goods = Db::name('goods') -> alias('a') -> field("a.*,b.name") -> join('classification b','a.classify_id = b.id','LEFT') -> where($where) -> where('is_out',1) -> where('book_name','like',"%".$book_name."%") -> select() -> toArray();
anyv authored
546 547 548 549 550 551
        }
        if(!empty($data_salesman_goods)){
            foreach ($data_salesman_goods as $key => $val){
                $price = explode('.',$data_salesman_goods[$key]['price']);
                $data_salesman_goods[$key]['price0'] = $price[0];
                $data_salesman_goods[$key]['price1'] = $price[1];
5  
anyv authored
552
                $data_salesman_goods[$key]['show_img'] = cmf_get_image_url($data_salesman_goods[$key]['show_img']);
anyv authored
553 554 555 556 557
            }
        }
        return json_encode($data_salesman_goods);

    }
anyv authored
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584


























anyv authored
585
}