Base.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免费声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  13. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  14. // +----------------------------------------------------------------------
  15. namespace app\admin\controller;
  16. use think\admin\Controller;
  17. use think\admin\helper\QueryHelper;
  18. use think\admin\model\SystemBase;
  19. /**
  20. * 数据字典管理
  21. * Class Base
  22. * @package app\admin\controller
  23. */
  24. class Base extends Controller
  25. {
  26. /**
  27. * 数据字典管理
  28. * @auth true
  29. * @menu true
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public function index()
  35. {
  36. SystemBase::mQuery()->layTable(function () {
  37. $this->title = '数据字典管理';
  38. $this->types = SystemBase::types();
  39. $this->type = $this->get['type'] ?? ($this->types[0] ?? '-');
  40. }, function (QueryHelper $query) {
  41. $query->where(['deleted' => 0])->equal('type');
  42. $query->like('code,name,status')->dateBetween('create_at');
  43. });
  44. }
  45. /**
  46. * 添加数据字典
  47. * @auth true
  48. */
  49. public function add()
  50. {
  51. SystemBase::mForm('form');
  52. }
  53. /**
  54. * 编辑数据字典
  55. * @auth true
  56. */
  57. public function edit()
  58. {
  59. SystemBase::mForm('form');
  60. }
  61. /**
  62. * 表单数据处理
  63. * @param array $data
  64. * @throws \think\db\exception\DbException
  65. */
  66. protected function _form_filter(array &$data)
  67. {
  68. if ($this->request->isGet()) {
  69. $this->types = SystemBase::types();
  70. $this->types[] = '--- 新增类型 ---';
  71. $this->type = input('get.type') ?: ($this->types[0] ?? '-');
  72. } else {
  73. $map = [];
  74. $map[] = ['deleted', '=', 0];
  75. $map[] = ['code', '=', $data['code']];
  76. $map[] = ['type', '=', $data['type']];
  77. if (isset($data['id'])) $map[] = ['id', '<>', $data['id']];
  78. if (SystemBase::mk()->where($map)->count() > 0) {
  79. $this->error("同类型的数据编码已经存在!");
  80. }
  81. }
  82. }
  83. /**
  84. * 修改数据状态
  85. * @auth true
  86. */
  87. public function state()
  88. {
  89. SystemBase::mSave($this->_vali([
  90. 'status.in:0,1' => '状态值范围异常!',
  91. 'status.require' => '状态值不能为空!',
  92. ]));
  93. }
  94. /**
  95. * 删除数据记录
  96. * @auth true
  97. */
  98. public function remove()
  99. {
  100. SystemBase::mDelete();
  101. }
  102. }