106 lines
4.0 KiB
PHP
106 lines
4.0 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
/**
|
|
* 车型库
|
|
* Created by PhpStorm.
|
|
* User: xuxb
|
|
* Date: 2021/8/6
|
|
* Time: 11:13
|
|
*/
|
|
class Auto_cars_model extends HD_Model{
|
|
private $table_name = 'lc_auto_cars';
|
|
private $car_config_arr = [
|
|
'350900' => [ //宁德
|
|
//东风EX1
|
|
['brand_id'=>1,'s_id'=>1,'v_id'=>2,'price_car'=>51700,'price_floor'=>51700],
|
|
['brand_id'=>1,'s_id'=>1,'v_id'=>3,'price_car'=>55700,'price_floor'=>55700],
|
|
//雷丁
|
|
['brand_id'=>2,'s_id'=>3,'v_id'=>12,'price_car'=>38900,'price_floor'=>37400],
|
|
['brand_id'=>2,'s_id'=>4,'v_id'=>13,'price_car'=>41900,'price_floor'=>40400],
|
|
['brand_id'=>2,'s_id'=>5,'v_id'=>14,'price_car'=>43900,'price_floor'=>42400],
|
|
],
|
|
];
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct($this->table_name, 'default');
|
|
}
|
|
|
|
/**
|
|
* 获取车型特殊处理
|
|
*/
|
|
public function get($where, $select = '', $city_id = ''){
|
|
if($select){
|
|
$this->db->select($select, false);
|
|
}
|
|
$row = $this->db->get_where($this->table_name, $where)->row_array();
|
|
if($city_id && $this->car_config_arr[$city_id]){ //特殊处理城市
|
|
$car_lists = $this->car_config_arr[$city_id];
|
|
$brand_id_arr = array_column($car_lists,'brand_id');
|
|
$s_id_arr = array_column($car_lists,'s_id');
|
|
$v_id_arr = array_column($car_lists,'v_id');
|
|
if(in_array($row['brand_id'],$brand_id_arr) && in_array($row['s_id'],$s_id_arr) && in_array($row['v_id'],$v_id_arr)){
|
|
foreach($car_lists as $key => $val){
|
|
if($row['brand_id']==$val['brand_id']&&$row['s_id']==$val['s_id']&&$row['v_id']==$val['v_id']){
|
|
$row['price_car'] = $val['price_car'];
|
|
$row['price_floor'] = $val['price_floor'];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$city_id == 350900 && $row['price_book'] = 5000; //宁德定金固定5000
|
|
return $row;
|
|
}
|
|
|
|
//获取完整车辆信息
|
|
public function get_title($id){
|
|
$this->load->model('auto/auto_brand_model');
|
|
$this->load->model('auto/auto_series_model');
|
|
$this->load->model('auto/auto_attr_model');
|
|
$row = $this->get(['id'=>$id],'brand_id,s_id,v_id,cor_id,incor_id');
|
|
$b_row = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name');
|
|
$s_row = $this->auto_series_model->get(['id'=>$row['s_id']],'name');
|
|
if($row){
|
|
$where = [
|
|
"id in ({$row['v_id']},{$row['cor_id']},{$row['incor_id']})" => null
|
|
];
|
|
$attr = $this->auto_attr_model->map('id','',$where,'','','','id,title');
|
|
}
|
|
$title = $b_row['name'].$s_row['name'];
|
|
$attr[$row['v_id']] && $title.= $attr[$row['v_id']][0]['title'];
|
|
$attr[$row['cor_id']] && $title.= "-".$attr[$row['cor_id']][0]['title'];
|
|
$attr[$row['incor_id']] && $title.= "-".$attr[$row['incor_id']][0]['title'];
|
|
return $title;
|
|
}
|
|
|
|
//获取车系品牌完整信息
|
|
public function select_car($where=[],$order,$page,$size,$fileds='',$count=''){
|
|
|
|
!$fileds && $fileds = "{$this->table_name}.*";
|
|
$this->db->select($fileds);
|
|
$this->db->from($this->table_name);
|
|
$this->db->join('lc_auto_brand', "lc_auto_brand.id = {$this->table_name}.brand_id");
|
|
$this->db->join('lc_auto_series', "lc_auto_series.id = {$this->table_name}.s_id");
|
|
|
|
if ($where) {
|
|
$this->db->where($where);
|
|
}
|
|
if ($count) {
|
|
return $this->db->count_all_results();
|
|
}
|
|
if ($order) {
|
|
$this->db->order_by($order);
|
|
}
|
|
if ($page) {
|
|
$offset = ($page - 1) * $size;
|
|
$limit = $size;
|
|
} else {
|
|
$offset = null;
|
|
$limit = null;
|
|
}
|
|
$this->db->limit($limit, $offset);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
}
|