login_white = array();//登录白名单 $this->check_status = array();//用户状态校验 $this->check_mobile = array();//需要手机号 $this->check_headimg =array();//授权微信信息 $this->load->model('auto/auto_brand_model'); $this->load->model('auto/auto_series_model'); $this->load->model("biz/biz_model"); } //获取车系 protected function get(){ $page = $this->input_param('page'); $size = $this->input_param('size'); $brand_id = $this->input_param('brand_id'); !$page && $page = 1; !$size && $size = 20; $where = [ 'status' => 1 ]; $brand_id && $where['brand_id']=$brand_id; $count = $this->auto_series_model->count($where); $list = $this->auto_series_model->select($where,'id desc',$page,$size,'id,name'); $data = [ 'list' => $list, 'total' => $count ]; return $data; } //获取品牌 protected function get_brands(){ $page = $this->input_param('page'); $size = $this->input_param('size'); !$page && $page = 1; !$size && $size = 20; $where = [ 'status' => 1 ]; $biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); if($biz_id){ $biz = $this->biz_model->get(['id'=>$biz_id],'jsondata'); $jsondata = json_decode($biz['jsondata'],true); $auto_brands = $jsondata['auto_brands'] ? $jsondata['auto_brands'] : [0]; $str_brands = implode(',',$auto_brands); $where["id in ($str_brands)"] = null; } $count = $this->auto_brand_model->count($where); $list = $this->auto_brand_model->select($where,'id desc',$page,$size,'id,name'); $data = [ 'list' => $list, 'total' => $count ]; return $data; } //获取车型列表 protected function get_cars(){ $uid = $this->session['uid']; $id = $this->input_param('id'); //车系id $where = [ 'status' => 1 ]; $user = $this->app_user_model->get(array('id' => $uid)); if(isset($user['biz_id'])){ $biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); $biz = $this->biz_model->get(['id'=>$biz_id],'jsondata'); $jsondata = json_decode($biz['jsondata'],true); $auto_brands = $jsondata['auto_brands'] ? $jsondata['auto_brands'] : [0]; $str_brands = implode(',',$auto_brands); $where["brand_id in ($str_brands)"] = null; } if($id){ //只显示相同品牌 $series = $this->auto_series_model->get(['id'=>$id],'brand_id'); $series['brand_id'] && $where['brand_id'] = $series['brand_id']; } $rows = $this->auto_series_model-> select($where,'',1,20,'id,brand_id,name'); $list = []; if($rows){ $first = []; $brand_arr = array_unique(array_column($rows,'brand_id')); $brands = []; $brand_ids = implode(',',$brand_arr); if($brand_ids){ $where = [ "id in ({$brand_ids})" => null, ]; $brand_rows = $this->auto_brand_model->map('id','',$where,'','','','id,name'); } foreach($rows as $key=>$val){ $brand_name = isset($brand_rows[$val['brand_id']]) ? $brand_rows[$val['brand_id']][0]['name'] : ''; $temp = [ 'id' => $val['id'], 'title' => $brand_name.$val['name'], ]; if($val['id']==$id){ $first[] = $temp; }else{ $list[] = $temp; } } $list = array_merge($first,$list); } return $list; } //获取车系属性 protected function get_attrs(){ $s_id = $this->input_param('id'); $type = $this->input_param('type'); $page = $this->input_param('page'); $size = $this->input_param('size'); $v_id = $this->input_param('v_id'); $cor_id = $this->input_param('color_id'); !$page && $page = 1; !$size && $size = 20; $this->load->model('auto/auto_cars_model'); $this->load->model('auto/auto_attr_model'); $where = [ 's_id' => $s_id, 'status' => 1 ]; if($type==2){ //内饰颜色 $where['v_id'] = $v_id; $where['cor_id'] = $cor_id; $groupby = "incor_id"; }elseif($type==1){ //颜色 $where['v_id'] = $v_id; $groupby = "cor_id"; }else{ //车辆级别 $groupby = "v_id"; } $lists = []; $rows = $this->auto_cars_model->select_groupby($groupby,$where,'',$page,$size,'id,s_id,v_id,cor_id,incor_id'); if($rows){ $target_arr = array_column($rows,$groupby); $attrs = $this->auto_attr_model->get_map_by_ids($target_arr,'id,title'); foreach($rows as $key => $val){ $attr_id = $val[$groupby]; if($attrs[$attr_id]){ $lists[] = [ 'id' => $attr_id, 'title' => $attrs[$attr_id][0]['title'] ]; } } } $data = [ 'list' => $lists, 'total' => count($lists) ]; return $data; } //获取车型信息信息 protected function get_info(){ $s_id = $this->input_param('car_id'); $v_id = $this->input_param('v_id'); $color_id = $this->input_param('color_id'); $incolor_id = $this->input_param('incolor_id'); $this->load->model('auto/auto_cars_model'); if(!$s_id || !$v_id || !$color_id || !$incolor_id){ throw new Exception('参数错误', ERR_PARAMS_ERROR); } $where_car = array( 's_id'=>$s_id, 'v_id' => $v_id, 'cor_id' => $color_id, 'incor_id' => $incolor_id, 'status' => 1 ); $car = $this->auto_cars_model->get($where_car); if(!$car){ throw new Exception('当前车型暂无库存', ERR_PARAMS_ERROR); } $data = [ 'price' => $car['price_car'] ? $car['price_car'] : 0, 'deposit' => $car['price_book'] ? $car['price_book'] : 0 ]; return $data; } }