202 lines
6.5 KiB
PHP
202 lines
6.5 KiB
PHP
<?php
|
|
/**
|
|
* Created by Vim
|
|
* User: lcc
|
|
* Date: 2020/08/05
|
|
* Time: 10:19
|
|
*/
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Series extends HD_Controller{
|
|
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->load->model('auto/auto_brand_model');
|
|
$this->load->model('auto/auto_series_model');
|
|
}
|
|
|
|
public function index(){
|
|
$this->lists();
|
|
}
|
|
|
|
public function lists(){
|
|
$params = $this->input->get();
|
|
$page = $this->input->get('page');
|
|
!$page && $page = 1;
|
|
$size = 20;
|
|
$where["status > -1"] = null;
|
|
$params['title'] && $where["name like '%{$params['title']}%'"] = null;
|
|
$where['brand_id in (select id from lc_auto_brand where status > -1)'] = null;
|
|
if($params['brand_id']){
|
|
$where['brand_id'] = $params['brand_id'];
|
|
} else {
|
|
$params['brand_id'] = '';
|
|
}
|
|
if (!strlen($params['status'])){
|
|
$params['status'] = $where['status'] = 1;
|
|
}
|
|
elseif ($params['status'] == -9){
|
|
# pass
|
|
}
|
|
else{
|
|
$where['status'] = $params['status'];
|
|
}
|
|
|
|
$count = $this->auto_series_model->count($where);
|
|
$rows = $this->auto_series_model->select($where, 'id desc', $page, $size);
|
|
$status_arr = $this->auto_series_model->get_status();
|
|
$list = [];
|
|
|
|
//获取品牌map
|
|
$where_brand = array('status > -1' => null);
|
|
$map_brand = $this->auto_brand_model->map_brand($where_brand);
|
|
|
|
if($rows){
|
|
foreach($rows as $key=>$val){
|
|
$brand_name = $map_brand[$val['brand_id']] ? $map_brand[$val['brand_id']] : '';
|
|
$list[] = [
|
|
'id' => $val['id'],
|
|
'brand_name' => $brand_name,
|
|
'name' => $val['name'],
|
|
'status' => $val['status'],
|
|
'status_name' => $status_arr[$val['status']],
|
|
'c_time' => date('Y-m-d H:i:s',$val['c_time'])
|
|
];
|
|
}
|
|
}
|
|
$status_arr_list = $status_arr;
|
|
unset($status_arr_list[-1]);
|
|
$this->data['status_arr'] = $status_arr_list;
|
|
$this->data['lists'] = $list;
|
|
$this->data['params'] = $params;
|
|
$this->data['brandAry'] = $this->auto_brand_model->map_brand_list($map_brand);
|
|
$this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
|
|
$this->data['_title'] = '车系列表';
|
|
$this->show_view('auto/series/lists', true);
|
|
}
|
|
|
|
/**
|
|
* 获取数据列表
|
|
* @return bool
|
|
*/
|
|
public function json_lists(){
|
|
$brand_id = $this->input->get_post('brand_id');
|
|
$page = $this->input->get_post('page');
|
|
$size = $this->input->get_post('size');
|
|
|
|
$where = array('status > -1' => null);
|
|
$brand_id && $where['brand_id'] = $brand_id;
|
|
$orderby = 'id desc';
|
|
|
|
$total = $this->auto_series_model->count($where);
|
|
|
|
$lists = array();
|
|
if($total){
|
|
$select = 'id, name';
|
|
$rows = $this->auto_series_model->select($where, $orderby, $page, $size, $select);
|
|
|
|
foreach($rows as $v){
|
|
$lists[] = array(
|
|
'id' => $v['id'],
|
|
'name' => $v['name'],
|
|
);
|
|
}
|
|
}
|
|
|
|
$this->data = array('total' => $total, 'list' => $lists);
|
|
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
|
|
}
|
|
|
|
public function get(){
|
|
$id = $this->input->get('id');
|
|
|
|
$info = [];
|
|
if ($id) {
|
|
$info = $this->auto_series_model->get(array('id' => $id));
|
|
if (!$info || empty($info)) {
|
|
return $this->show_json(SYS_CODE_FAIL, '数据不存在!');
|
|
}
|
|
}
|
|
$brands = $this->auto_brand_model->select([],'','','','id,name');
|
|
$this->data['brands'] = $brands;
|
|
$this->data['info'] = $info;
|
|
$this->data['_title'] = $id ? '编辑车系' : '新增车系';
|
|
return $this->show_view('auto/series/edit');
|
|
}
|
|
|
|
public function add(){
|
|
if (!$this->if_ajax) {
|
|
return $this->show_json(SYS_CODE_FAIL, '提交出错!');
|
|
}
|
|
$id = $this->input->post('id');
|
|
$name = $this->input->post('name');
|
|
$brand_id = $this->input->post('brand_id');
|
|
if (!$name || empty($name)) {
|
|
return $this->show_json(SYS_CODE_FAIL, '车系名称不能为空');
|
|
}
|
|
$old = $this->auto_series_model->get(['name'=>$name,'status>'=>-1]);
|
|
if ($old) {
|
|
return $this->show_json(SYS_CODE_FAIL, '车系已经存在');
|
|
}
|
|
$add_data = array(
|
|
'name' => $name,
|
|
'brand_id' => $brand_id,
|
|
'c_time' => time()
|
|
);
|
|
$brand_id = $this->auto_series_model->add($add_data);
|
|
if (!$brand_id) {
|
|
return $this->show_json(SYS_CODE_FAIL, '添加失败');
|
|
}
|
|
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
|
|
}
|
|
|
|
public function edit(){
|
|
if (!$this->if_ajax) {
|
|
return $this->show_json(SYS_CODE_FAIL, '提交出错!');
|
|
}
|
|
$id = $this->input->post('id');
|
|
$name = $this->input->post('name');
|
|
$brand_id = $this->input->post('brand_id');
|
|
$row = $this->auto_series_model->get(['id' => $id]);
|
|
if (!$row) {
|
|
return $this->show_json(SYS_CODE_FAIL, '数据不存在!');
|
|
}
|
|
if (!$name) {
|
|
return $this->show_json(SYS_CODE_FAIL, '车系名称不能为空');
|
|
}
|
|
//防止车系名称重复
|
|
$where = array('name' => $name, "status<>-1" => null);
|
|
$id && $where['id <>'] = $id;
|
|
$old = $this->auto_series_model->get($where);
|
|
if ($old) {
|
|
return $this->show_json(SYS_CODE_FAIL, '车系已经存在');
|
|
}
|
|
$up_data = array(
|
|
'brand_id' => $brand_id,
|
|
'name' => $name,
|
|
);
|
|
$this->auto_series_model->update($up_data, array('id' => $id));
|
|
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
|
|
}
|
|
|
|
public function del(){
|
|
$id = $this->input->post('id');
|
|
if (!$id) {
|
|
$this->show_json(SYS_CODE_FAIL, '参数错误');
|
|
}
|
|
$stauts = $this->input->post('status');
|
|
$where = array('id' => $id);
|
|
$this->auto_series_model->update(array('status' => $stauts), $where);
|
|
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
|
|
}
|
|
|
|
public function batch(){
|
|
|
|
}
|
|
|
|
public function export(){
|
|
|
|
}
|
|
|
|
}
|