Files
liche/market/controllers/api/system/Dictionary.php
T
2022-12-07 17:36:12 +08:00

107 lines
3.2 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
/**
* Notes:字典管理
* Created on: 2022/9/19 17:15
* Created by: dengbw
*/
class Dictionary extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('market/Market_sys_dictionary_model', 'mdSysDictionary');
}
/**
* Notes:获取字典
* Created on: 2022/9/19 11:11
* Created by: dengbw
*/
public function index_get()
{
$dictCode = $this->input_param('dictCode');
$where['status>='] = 0;
$dictCode && $where['dictCode like "%' . $dictCode . '%"'] = null;
$sort_order = 'sortNumber asc,dictId desc';
$res = $this->mdSysDictionary->select($where, $sort_order);
foreach ($res as $k => $v) {
$res[$k]['dictId'] = intval($v['dictId']);
}
$this->return_response_list($res);
}
/**
* Notes:添加字典
* Created on: 2022/9/19 11:01
* Created by: dengbw
*/
public function index_post()
{
$dictName = $this->input_param('dictName');
$dictCode = $this->input_param('dictCode');
$sortNumber = intval($this->input_param('sortNumber'));
$comments = $this->input_param('comments');
if (!$dictName) {
$this->return_json('请输入字典名称');
}
if (!$dictCode) {
$this->return_json('请输入字典值');
}
!$comments && $comments = '';
$addDate = ['dictName' => $dictName, 'dictCode' => $dictCode, 'sortNumber' => $sortNumber, 'comments' => $comments
, 'createTime' => date('Y-m-d H:i:s')];
$id = $this->mdSysDictionary->add($addDate);
if (!$id) {
$this->return_json('添加字典失败');
}
$this->return_response();
}
/**
* Notes:修改字典
* Created on: 2022/9/19 11:05
* Created by: dengbw
*/
public function index_put()
{
$dictId = intval($this->input_param('dictId'));
$dictName = $this->input_param('dictName');
$dictCode = $this->input_param('dictCode');
$sortNumber = intval($this->input_param('sortNumber'));
$comments = $this->input_param('comments');
if (!$dictId) {
$this->return_json('参数错误');
}
if (!$dictName) {
$this->return_json('请输入字典名称');
}
if (!$dictCode) {
$this->return_json('请输入字典值');
}
!$comments && $comments = '';
$upDate = ['dictName' => $dictName, 'dictCode' => $dictCode, 'sortNumber' => $sortNumber, 'comments' => $comments];
$this->mdSysDictionary->update($upDate, ['dictId' => $dictId]);
$this->return_response();
}
/**
* Notes:删除字典
* Created on: 2022/9/19 11:08
* Created by: dengbw
* @param null $dictId
*/
public function index_delete($dictId = null)
{
$dictId = intval($dictId);
if (!$dictId) {
$this->return_json('参数错误');
}
$this->mdSysDictionary->update(['status' => -1], ['dictId' => $dictId]);
$this->return_response();
}
}