Files
liche/market/controllers/api/system/DictionaryData.php
T
2022-09-29 14:30:16 +08:00

169 lines
5.7 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
/**
* Notes:机构管理
* Created on: 2022/9/16 17:15
* Created by: dengbw
*/
class DictionaryData extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('market/Market_sys_dictionary_data_model', 'mdSysDictionaryData');
}
/**
* Notes:字典项列表
* Created on: 2022/9/16 11:11
* Created by: dengbw
*/
public function page_get()
{
$dictId = $this->input_param('dictId');
$page = $this->input_param('page');
$limit = $this->input_param('limit');
$sort = $this->input_param('sort');
$order = $this->input_param('order');
$keywords = $this->input_param('keywords');
!$page && $page = 1;
!$limit && $limit = 10;
if (!$dictId) {
$this->return_json('参数错误');
}
$res = [];
$sort_order = 'sortNumber asc,dictDataId desc';
$where = ['status>=' => 0, 'dictId' => $dictId];
if ($keywords) {
$where["dictDataName = '{$keywords}' OR dictDataCode = '{$keywords}'"] = null;
}
if ($sort && $order) {
$sort_order = $sort . ' ' . $order;
}
$count = $this->mdSysDictionaryData->count($where);
if ($count) {
$res = $this->mdSysDictionaryData->select($where, $sort_order, $page, $limit);
foreach ($res as $k => $v) {
$res[$k]['dictDataId'] = intval($v['dictDataId']);
$res[$k]['dictId'] = intval($v['dictId']);
$res[$k]['sortNumber'] = intval($v['sortNumber']);
}
}
$date = ['list' => $res, 'count' => $count];
$this->return_response_list($date);
}
public function index_get()
{
$dictCode = $this->input_param('dictCode');
if (!$dictCode) {
$this->return_json('参数错误');
}
$this->load->model('market/Market_sys_dictionary_model', 'mdSysDictionary');
$re = $this->mdSysDictionary->get(['status>=' => 0, 'dictCode' => $dictCode]);
$res = [];
if ($re) {
$dictId = $re['dictId'];
$sort_order = 'sortNumber asc,dictDataId desc';
$where = ['status>=' => 0, 'dictId' => $dictId];
$res = $this->mdSysDictionaryData->select($where, $sort_order, 0, 0);
foreach ($res as $k => $v) {
$res[$k]['dictDataId'] = intval($v['dictDataId']);
$res[$k]['dictId'] = intval($v['dictId']);
$res[$k]['dictCode'] = $re['dictCode'];
$res[$k]['dictName'] = $re['dictName'];
}
}
$this->return_response_list($res);
}
/**
* Notes:添加字典项
* Created on: 2022/9/19 11:01
* Created by: dengbw
*/
public function index_post()
{
$dictId = intval($this->input_param('dictId'));
$dictDataName = $this->input_param('dictDataName');
$dictDataCode = $this->input_param('dictDataCode');
$sortNumber = intval($this->input_param('sortNumber'));
$comments = $this->input_param('comments');
if (!$dictDataName) {
$this->return_json('请输入字典项名称');
}
if (!$dictDataCode) {
$this->return_json('请输入字典项值');
}
!$comments && $comments = '';
$addDate = ['dictId' => $dictId, 'dictDataName' => $dictDataName, 'dictDataCode' => $dictDataCode,
'sortNumber' => $sortNumber, 'comments' => $comments, 'createTime' => date('Y-m-d H:i:s')];
$id = $this->mdSysDictionaryData->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()
{
$dictDataId = intval($this->input_param('dictDataId'));
$dictDataName = $this->input_param('dictDataName');
$dictDataCode = $this->input_param('dictDataCode');
$sortNumber = intval($this->input_param('sortNumber'));
$comments = $this->input_param('comments');
if (!$dictDataName) {
$this->return_json('请输入字典项名称');
}
if (!$dictDataCode) {
$this->return_json('请输入字典项值');
}
!$comments && $comments = '';
$upDate = ['dictDataName' => $dictDataName, 'dictDataCode' => $dictDataCode, 'sortNumber' => $sortNumber, 'comments' => $comments];
$this->mdSysDictionaryData->update($upDate, ['dictDataId' => $dictDataId]);
$this->return_response();
}
/**
* Notes:删除字典项
* Created on: 2022/9/19 11:08
* Created by: dengbw
* @param null $dictDataId
*/
public function index_delete($dictDataId = null)
{
$dictDataId = intval($dictDataId);
if (!$dictDataId) {
$this->return_json('参数错误');
}
$this->mdSysDictionaryData->update(['status' => -1], ['dictDataId' => $dictDataId]);
$this->return_response();
}
/**
* Notes:批量删除字典项
* Created on: 2022/9/19 15:35
* Created by: dengbw
*/
public function batch_delete()
{
$ids = $this->inputs;
if (!$ids) {
$this->return_json('参数错误');
}
$str_ids = implode(',', $ids);
if ($str_ids) {
$this->mdSysDictionaryData->update(['status' => -1], ["dictDataId in($str_ids)" => null]);
}
$this->return_response();
}
}