144 lines
4.9 KiB
PHP
144 lines
4.9 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Brand extends HD_Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model("sys/sys_cps_model");
|
|
$this->load->model("auto/auto_brand_model");
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
return $this->lists();
|
|
}
|
|
|
|
public function lists()
|
|
{
|
|
$params = $this->input->get();
|
|
$params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
!strlen($params['status']) && $params['status'] = '';
|
|
!strlen($params['type']) && $params['type'] = '';
|
|
$lists = array();
|
|
$where = [];
|
|
strlen($params['status']) && $where['status'] = intval($params['status']);
|
|
strlen($params['type']) && $where['type'] = intval($params['type']);
|
|
$status_lists = Sys_cps_model::STATUS_LISTS;
|
|
$type_lists = Sys_cps_model::TYPES;
|
|
$count = $this->sys_cps_model->count($where);
|
|
if ($count) {
|
|
$res = $this->sys_cps_model->select($where, "id desc", $params['page'], $params['size']);
|
|
foreach ($res as $key => $value) {
|
|
$brand = $this->auto_brand_model->get(['id' => $value['brand_id']]);
|
|
$value['brand_name'] = $brand['name'];
|
|
$value['type_name'] = Sys_cps_model::TYPES[$value['type']];
|
|
$value['status_name'] = $status_lists[$value['status']];
|
|
$lists[] = $value;
|
|
}
|
|
}
|
|
$this->data['lists'] = $lists;
|
|
$this->data['params'] = $params;
|
|
$this->data['status_lists'] = $status_lists;
|
|
$this->data['type_lists'] = $type_lists;
|
|
$this->data['_title'] = 'cps列表';
|
|
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
|
|
$this->show_view('sys/cps/lists', true);
|
|
}
|
|
|
|
public function get()
|
|
{
|
|
$id = intval($this->input->get('id'));
|
|
$info = ['brand_id' => '', 'type' => Sys_cps_model::TYPE_IMPORTANT];
|
|
if ($id) {
|
|
$info = $this->sys_cps_model->get(['id' => $id]);
|
|
}
|
|
$brand_rows = $this->auto_brand_model->select(['status' => 1], 'initail asc', 0, 0, 'id,name');
|
|
$brands = [];
|
|
if ($brand_rows) {
|
|
foreach ($brand_rows as $v) {
|
|
$brands[] = array(
|
|
'id' => $v['id'],
|
|
'name' => $v['name'],
|
|
);
|
|
}
|
|
}
|
|
$this->data['brands'] = $brands;
|
|
$this->data['info'] = $info;
|
|
$this->data['types'] = Sys_cps_model::TYPES;
|
|
$this->data['_title'] = $id ? '编辑' : '新增';
|
|
return $this->show_view('sys/cps/edit', true);
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
$info = $this->input->post();
|
|
if (!$info['brand_id'] || !$info['type'] || !$info['s_time'] || !$info['e_time']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '参数错误');
|
|
}
|
|
$data = [
|
|
'brand_id' => $info['brand_id'],
|
|
'type' => $info['type'],
|
|
's_time' => $info['s_time'],
|
|
'e_time' => $info['e_time'],
|
|
'c_time' => time()
|
|
];
|
|
$res = $this->sys_cps_model->add($data);
|
|
if (!$res) {
|
|
return $this->show_json(SYS_CODE_FAIL, '保存失败');
|
|
}
|
|
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
$info = $this->input->post();
|
|
$row = $this->sys_cps_model->get(['id' => $info['id']]);
|
|
if (!$row) return $this->show_json(SYS_CODE_FAIL, '数据不存在');
|
|
$up_data = [
|
|
'brand_id' => $info['brand_id'],
|
|
'type' => $info['type'],
|
|
's_time' => $info['s_time'],
|
|
'e_time' => $info['e_time'],
|
|
];
|
|
$res = $this->sys_cps_model->update($up_data, ['id' => $info['id']]);
|
|
if (!$res) {
|
|
return $this->show_json(SYS_CODE_FAIL, '保存失败');
|
|
}
|
|
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
|
|
}
|
|
|
|
public function del()
|
|
{
|
|
|
|
}
|
|
|
|
public function batch()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function export()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function edit_status()
|
|
{
|
|
$id = $this->input->post('id');
|
|
$row = $this->sys_cps_model->get(['id' => $id]);
|
|
if (!$row) return $this->show_json(SYS_CODE_FAIL, '数据不存在');
|
|
$status = $row['status'] ? 0 : 1;
|
|
$up_data = [
|
|
'status' => $status
|
|
];
|
|
$res = $this->sys_cps_model->update($up_data, ['id' => $id]);
|
|
if (!$res) {
|
|
return $this->show_json(SYS_CODE_FAIL, '保存失败');
|
|
}
|
|
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
|
|
}
|
|
}
|