Files
liche/api/controllers/wxapp/app/Series.php
T
2021-08-16 17:33:50 +08:00

129 lines
4.1 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();//授权微信信息
}
//获取车型列表
protected function get_cars(){
$biz_id = $this->session['biz_id'];
$this->load->model('auto/auto_brand_model');
$this->load->model('auto/auto_series_model');
$this->load->model("biz/biz_model");
$id = $this->input_param('id'); //车系id
$where = [
'status' => 1
];
$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;
$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');
!$page && $page = 1;
!$size && $size = 20;
$this->load->model('auto/auto_attr_model');
$where = [
's_id' => $s_id
];
strlen($type) && $where['type'] = $type;
$count = $this->auto_attr_model->count($where);
$rows = $this->auto_attr_model->select($where,'id desc',$page,$size,'id,title,type,jsondata');
$lists = [];
if($rows){
foreach($rows as $key=>$val){
$jsodnata = json_decode($val['jsondata'],true);
$temp = [
'id' => $val['id'],
'title' => $val['title']
];
$lists[] = $temp;
}
}
$data = [
'list' => $lists,
'total' => $count
];
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);
}
$attrs = "{$color_id}_{$v_id}_{$incolor_id}";
$car = $this->auto_cars_model->get(['attrs'=>$attrs,'s_id'=>$s_id]);
$data = [
'price' => $car['price_car'] ? $car['price_car'] : 0,
'deposit' => $car['price_book'] ? $car['price_book'] : 0
];
return $data;
}
}