Files
liche/api/controllers/wxapp/app/Series.php
T
2022-02-16 15:18:10 +08:00

222 lines
7.9 KiB
PHP

<?php
defined('WXAPP_APP') OR exit('No direct script access allowed');
/**
* Created by Vim
* User: lcc
* Desc: 车系信息
* Date: 2021.06.23
* Time: 14:08
*/
require_once APPPATH.'controllers/wxapp/Wxapp.php';
class Series extends Wxapp{
function __construct($inputs, $app_key){
parent::__construct($inputs, $app_key);
$this->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('auto/auto_attr_model');
$this->load->model('auto/auto_cars_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;
$lists = [];
if($type==2 || $type==1){ //1颜色 2内饰颜色
$type = $type==1 ? 0 : $type;
$where = [
's_id' => $s_id,
'type' => $type,
'status' => 1
];
$count = $this->auto_attr_model->count($where);
$lists = $this->auto_attr_model->select($where,'',$page,$size,'id,title');
}else{ //车辆级别
$city_id = '';
$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],'city_id');
$city_id = $biz['city_id'];
}
$where = [
's_id' => $s_id,
];
if($city_id=='350900'){ //宁德市特殊判断
$where['(status=1 or id=30)'] = null;
}else{
$where['status'] = 1;
}
$rows = $this->auto_cars_model->select($where,'id desc',$page,$size,'id,s_id,v_id');
if($rows){
$target_arr = array_unique(array_column($rows,'v_id'));
$attrs = $this->auto_attr_model->get_map_by_ids($target_arr,'id,title');
foreach($attrs as $key => $val){
$lists[] = [
'id' => $key,
'title' => $val[0]['title']
];
}
}
$count = count($lists);
}
$data = [
'list' => $lists,
'total' => $count
];
return $data;
}
//获取车型信息信息
protected function get_info(){
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
$s_id = $this->input_param('car_id');
$v_id = $this->input_param('v_id');
if(!$s_id || !$v_id){
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
$city_id = '';
if($biz_id){
$biz = $this->biz_model->get(['id'=>$biz_id],'city_id');
$city_id = $biz['city_id'];
}
$where_car = array(
's_id'=>$s_id,
'v_id' => $v_id,
);
if($v_id!=113) { //哪吒 U 2021款Pro400巡航版 不判断状态
$where_car['status'] = 1;
}
$car = $this->auto_cars_model->get($where_car,'',$city_id);
$biz_id == 70 && $car['price_book'] = 2000; //蕉城辉科写死定金
if(!$car){
throw new Exception('当前车型暂无库存', ERR_PARAMS_ERROR);
}
$dis_fine_money = $car['price_fine_floor']>0 && $car['price_fine']-$car['price_fine_floor']>0 ? $car['price_fine']-$car['price_fine_floor'] : 0;
$data = [
'price' => $car['price_car'] ? floatval($car['price_car']) : 0,
'deposit' => $car['price_book'] ? floatval($car['price_book']) : 0,
'dis_money' => $car['price_car'] - $car['price_floor'],
'fine_money' => floatval($car['price_fine']),
'dis_fine_money' => $dis_fine_money,
];
return $data;
}
}