243 lines
7.5 KiB
PHP
243 lines
7.5 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: xuxb
|
|
* Date: 2021/8/25
|
|
* Time: 11:35
|
|
*/
|
|
class Fine extends HD_Controller{
|
|
protected $log_dir;
|
|
|
|
public function __construct(){
|
|
parent::__construct();
|
|
|
|
$this->load->model('auto/auto_fine_model');
|
|
|
|
$this->log_dir = "auto_" . get_class($this);
|
|
}
|
|
|
|
public function index(){
|
|
return $this->lists();
|
|
}
|
|
|
|
public function lists(){
|
|
$params = $this->input->get();
|
|
|
|
$statusAry = array(0 => '关闭', 1 => '开启');
|
|
|
|
$where = array();
|
|
|
|
if($params['title']){
|
|
$where["title like '%{$params['title']}%'"] = null;
|
|
}
|
|
if(strlen($params['status']) > 0){
|
|
$where['status'] = $params['status'];
|
|
} else{
|
|
$where['status>-1'] = null;
|
|
$params['status'] = '';
|
|
}
|
|
|
|
$page = $params['page'];
|
|
$page = !$page ? 1 : $page;
|
|
$size = $params['size'];
|
|
$size = !$size ? 20 : $size;
|
|
|
|
$total = $this->auto_fine_model->count($where);
|
|
$lists = array();
|
|
if($total){
|
|
$orderby = 'id desc';
|
|
$select = 'id, title, status';
|
|
$rows = $this->auto_fine_model->select($where, $orderby, $page, $size, $select);
|
|
foreach($rows as $v){
|
|
$lists[] = array(
|
|
'id' => $v['id'],
|
|
'title' => $v['title'],
|
|
'status' => $v['status'],
|
|
'status_name' => $statusAry[$v['status']],
|
|
);
|
|
}
|
|
}
|
|
|
|
$this->data['params'] = $params;
|
|
$this->data['lists'] = $lists;
|
|
$this->data['statusAry'] = $statusAry;
|
|
$this->data['pager'] = array('count' => ceil($total / $size), 'curr' => $page, 'totle' => $total);
|
|
$this->data['_title'] = '车辆精品管理';
|
|
$this->show_view('auto/fine/lists',true);
|
|
}
|
|
|
|
public function get(){
|
|
$id = $this->input->get('id');
|
|
if($id){
|
|
$row = $this->auto_fine_model->get(array('id' => $id));
|
|
$info = array(
|
|
'id' => $row['id'],
|
|
'title' => $row['title'],
|
|
'status' => $row['status']
|
|
);
|
|
$title = '编辑车辆精品';
|
|
$action = 'auto/fine/edit';
|
|
} else {
|
|
$info = array(
|
|
'title' => '',
|
|
'status' => 1,
|
|
);
|
|
$title = '新增车辆精品';
|
|
$action = 'auto/fine/add';
|
|
}
|
|
|
|
$statusAry = array(0 => '关闭', 1 => '开启');
|
|
|
|
$this->data['info'] = $info;
|
|
$this->data['statusAry'] = $statusAry;
|
|
$this->data['action'] = $action;
|
|
$this->data['_title'] = $title;
|
|
$this->show_view('auto/fine/get');
|
|
}
|
|
|
|
/**
|
|
* 新增精品
|
|
* @return bool
|
|
*/
|
|
public function add(){
|
|
$info = $this->input->post('info');
|
|
if(!$info['title']){
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入精品名称');
|
|
}
|
|
|
|
$where = array("title" => trim($info['title']));
|
|
$old = $this->auto_fine_model->get($where);
|
|
if($old && $old['status'] > -1){
|
|
return $this->show_json(SYS_CODE_FAIL, '精品已经存在');
|
|
} else if(-1 == $old['status']) {
|
|
//旧数据存在,更新
|
|
$upd = array('status' => $info['status']);
|
|
$ret = $this->auto_fine_model->update($upd, array('id' => $old['id']));
|
|
if(!$ret){
|
|
debug_log('[error]# update fail; ' . $this->auto_fine_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
return $this->show_json(SYS_CODE_FAIL, '添加失败');
|
|
}
|
|
} else {
|
|
$add = array(
|
|
'title' => $info['title'],
|
|
'status' => $info['status'],
|
|
'c_time' => time(),
|
|
);
|
|
$ret = $this->auto_fine_model->add($add);
|
|
if(!$ret){
|
|
debug_log('[error]# add fail; ' . $this->auto_fine_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
return $this->show_json(SYS_CODE_FAIL, '添加失败');
|
|
}
|
|
}
|
|
|
|
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
|
|
}
|
|
|
|
/**
|
|
* 编辑
|
|
* @return bool
|
|
*/
|
|
public function edit(){
|
|
$info = $this->input->post('info');
|
|
if(!$info['title']){
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入精品名称');
|
|
}
|
|
|
|
$where = array(
|
|
"title" => trim($info['title']),
|
|
"id<>{$info['id']}" => null,
|
|
"status>-1" => null
|
|
);
|
|
$old = $this->auto_fine_model->get($where);
|
|
if($old){
|
|
return $this->show_json(SYS_CODE_FAIL, '精品已经存在');
|
|
}
|
|
|
|
$upd = array('title' => $info['title'], 'status' => $info['status']);
|
|
$ret = $this->auto_fine_model->update($upd, array('id' => $info['id']));
|
|
if(!$ret){
|
|
debug_log('[error]# update fail; ' . $this->auto_fine_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
return $this->show_json(SYS_CODE_FAIL, '添加失败');
|
|
}
|
|
|
|
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
|
|
}
|
|
|
|
function edit_status(){
|
|
$id = $this->input->post('id');
|
|
$stauts = $this->input->post('status');
|
|
if (!$id) {
|
|
$this->show_json(SYS_CODE_FAIL, '参数错误');
|
|
}
|
|
$where = array('id' => $id);
|
|
$this->auto_fine_model->update(array('status' => $stauts), $where);
|
|
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
|
|
}
|
|
|
|
public function del(){
|
|
$id = $this->input->post('id');
|
|
if (!$id) {
|
|
$this->show_json(SYS_CODE_FAIL, '参数错误');
|
|
}
|
|
$where = array('id' => $id);
|
|
$ret = $this->auto_fine_model->update(array('status' => -1), $where);
|
|
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
|
|
}
|
|
|
|
public function batch(){
|
|
// TODO: Implement batch() method.
|
|
}
|
|
|
|
public function export(){
|
|
// TODO: Implement export() method.
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
function json_lists(){
|
|
$id = $this->input->post('id');
|
|
$title = trim($this->input->post('title'));
|
|
$status = $this->input->post('status');
|
|
$page = $this->input->post('page');
|
|
$size = $this->input->post('size');
|
|
|
|
$where = array();
|
|
if($id){
|
|
if(is_numeric($id)){
|
|
$where['id'] = $id;
|
|
} else {
|
|
if(is_array($id)){
|
|
$id = implode(',', $id);
|
|
}
|
|
$where["id in ({$id})"] = null;
|
|
}
|
|
} else {
|
|
$title && $where["title like '%{$title}%'"] = null;
|
|
if(strlen($status) > 0){
|
|
$where['status'] = $status;
|
|
} else {
|
|
$where['status>-1'] = null;
|
|
}
|
|
}
|
|
|
|
$total = $this->auto_fine_model->count($where);
|
|
$lists = array();
|
|
if($total){
|
|
$orderby = 'id desc';
|
|
$select = 'id, title';
|
|
$rows = $this->auto_fine_model->select($where, $orderby, $page, $size, $select);
|
|
|
|
foreach($rows as $v){
|
|
$lists[] = array(
|
|
'id' => $v['id'],
|
|
'title' => $v['title'],
|
|
);
|
|
}
|
|
}
|
|
|
|
$this->data = array('total' => $total, 'list' => $lists);
|
|
return $this->show_json(SYS_CODE_SUCCESS);
|
|
}
|
|
} |