RentController.php 7.4 KB
<?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\HomeBaseController;
use EasyWeChat\Foundation\Application;
use think\Db;
use think\Session;

//租车商品
class RentController extends CommentController
{
//    session取货日期
    public function insertSession(){
        $data = $this->request->param();
        if(!empty($data['start_time'])){
            Session::set('start_time',$data['start_time']);
//            $_SESSION['start_time'] = $data['start_time'];
        }
        if(!empty($data['end_time'])){
            Session::set('end_time',$data['end_time']);
//            $_SESSION['end_time'] = $data['end_time'];
        }
    }

//    一级分类(over)
    public function index()
    {
        $data = $this->request->param();
        if($data['type'] == 1){
            $where_comm['type'] = array('like','%1%');
        }else{
            $where_comm['type'] = array('like','%2%');
        }
        $where_comm['grade'] = 1;
        $where_comm['parent_id'] = 0;
        $cate = Db::name('CommodityCate')->where($where_comm)->order('score desc,create_time desc')->select()->toArray();
        $this->assign('cate',$cate);
        $this->assign('type',$data['type']);
        return $this->fetch('Rent/index');
    }
//    二级分类
    public function nextGrade()
    {
        $data = $this->request->param();
//        图片
        $where_banner['type'] = $data['type'];
        $where_banner['status'] = array('neq',9);
        $banner = Db::name('Banner')->where($where_banner)->order('score desc,create_time desc')->limit(1)->find();
        $this->assign('banner',$banner);
//        二级分类
        $where_comm['parent_id'] = $data['pid'];
        $where_comm['grade'] = 2;
        if($data['type'] == 1){
            $where_comm['type'] = array('like','%1%');
        }else{
            $where_comm['type'] = array('like','%2%');
        }
        $cate = Db::name('CommodityCate')->where($where_comm)->order('score desc,create_time desc')->select()->toArray();
        $this->assign('cate',$cate);
//        分类下商品
//        $where_vehicle['cate_id'] = $data['cate_id'];
//        $where_vehicle['type'] = $data['type'];
//        $where_vehicle['status'] = array('neq',9);
//        $vehicle = Db::name('Vehicle')->where($where_vehicle)->order('score desc')->select()->toArray();
//        $this->assign('vehicle',$vehicle);
        return $this->fetch('Rent/rent');
    }
//    租商品详情
    public function rentDetail()
    {
        $data = $this->request->param();
        $pic = array();
        $where_vehicle['type'] = $data['type'];
        $where_vehicle['id'] = $data['vehicle_id'];
        $where_vehicle['status'] = array('neq',9);
        $art = Db::name('Vehicle')->where($where_vehicle)->find();
        if($art){
            $art['pic'] = cmf_get_image_url($art['pic']);
            $art['content'] = htmlspecialchars_decode($art['content']);
            $art['pic_banner'] = json_decode($art['pic_banner'],true);
            if($art['pic_banner']){
                foreach ($art['pic_banner'] as $k=>$v){
                    $pic[] = $v['url'];
                }
            }
        }
        $this->assign('pic',$pic);
        $this->assign('art',$art);
        return $this->fetch('Rent/detail');
    }

//    买商品详情
    public function vehicleDetail()
    {
        $data = $this->request->param();
        $pic = array();
        $where_vehicle['type'] = $data['type'];
        $where_vehicle['id'] = $data['vehicle_id'];
        $where_vehicle['status'] = array('neq',9);
        $art = Db::name('Vehicle')->where($where_vehicle)->find();
        if($art){
            $art['pic'] = cmf_get_image_url($art['pic']);
            $art['content'] = htmlspecialchars_decode($art['content']);
            $art['pic_banner'] = json_decode($art['pic_banner'],true);
            if($art['pic_banner']){
                foreach ($art['pic_banner'] as $k=>$v){
                    $pic[] = $v['url'];
                }
            }
        }
        $this->assign('pic',$pic);
        $this->assign('art',$art);
//        购物车
        $where_shopping['user_id'] = Session::get('uid');
        $where_shopping['status'] = array('neq',9);
        $cart = Db::name('Shopping')->where($where_shopping)->count();
        $this->assign('cart',$cart);
        return $this->fetch('Rent/buy_detail');
    }


//    租车确认
    public function rentSure(){
//        时间处理
        $start_time = Session::get('start_time');
        $end_time = Session::get('end_time');
        $middle_start = empty($start_time)?time():strtotime(Session::get('start_time'));
        $middle_end = empty($end_time)?time():strtotime(Session::get('end_time'));
        $time['start_time'] = date('Y-m-d',$middle_start);
        $time['end_time']  = date('Y-m-d',$middle_end);
        $time['time_num'] = ceil((strtotime($time['end_time']) - strtotime($time['start_time']))/86400)+1;
        $this->assign('time',$time);
        return $this->fetch('Rent/rent_sure');
    }

//    我要免押金
    public function free(){
        $where_art['status'] = array('neq',9);
        $where_art['type'] = 3;
        $art = Db::name('Art')->where($where_art)->order('score desc')->find();
        $art['content'] = htmlspecialchars_decode($art['content']);
        $this->assign('art',$art);
        return $this->fetch();
    }

//    搜索页
    public function find(){
        $data  = $this->request->param();
        $where_find['type'] = $data['type'];
        if(empty($data['find'])){
            $type = 1;
            $where_history['user_id'] = $_SESSION['uid'];
            $where_history['status'] = array('neq',9);
            $res_history = Db::name('History')->where($where_history)->select()->toArray();
            $vehicle = array();

        }else{
            $res_history = array();
            $type = 2;
//            查找是否有重复
            $where_history['user_id'] = $_SESSION['uid'];
            $where_history['keyword'] = $data['find'];
            $is_set = Db::name('History')->where($where_history)->find();
            if(!$is_set){
                $history['user_id'] = $_SESSION['uid'];
                $history['keyword'] = $data['find'];
                $history['create_time'] = time();
                $history['update_time'] = time();
                $res = Db::name('History')->insertGetId($history);
            }
            $where_find['name'] = array('like','%'.$data['find'].'%');
            $vehicle = Db::name('Vehicle')->where($where_find)->select()->toArray();
        }
        $this->assign('history',$res_history);
        $this->assign('vehicle',$vehicle);
        $this->assign('type',$type);
        return $this->fetch();

    }
//    清空搜索
    public function clear(){
        $where_history['user_id'] = $_SESSION['uid'];
        $update['status'] = 9;
        $update['update_time'] = time();
        $res_history = Db::name('History')->where($where_history)->update($update);
        if($res_history){
//            成功
        }else{
//            失败
        }
    }
}