Dict.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的多应用管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\dict;
  12. use core\base\BaseAdminController;
  13. use app\service\admin\dict\DictService;
  14. use think\Response;
  15. /**
  16. * 数据字典控制器
  17. * Class Dict
  18. * @package app\adminapi\controller\dict
  19. */
  20. class Dict extends BaseAdminController
  21. {
  22. /**
  23. * 获取数据字典列表
  24. * @return \think\Response
  25. */
  26. public function lists(){
  27. $data = $this->request->params([
  28. ["name",""],
  29. ["key",""]
  30. ]);
  31. return success((new DictService())->getPage($data));
  32. }
  33. /**
  34. * 数据字典详情
  35. * @param int $id
  36. * @return \think\Response
  37. */
  38. public function info(int $id){
  39. return success((new DictService())->getInfo($id));
  40. }
  41. /**
  42. * 添加数据字典
  43. * @return \think\Response
  44. */
  45. public function add(){
  46. $data = $this->request->params([
  47. ["name",""],
  48. ["key",""],
  49. ["memo",""],
  50. ["dictionary", ""]
  51. ]);
  52. // $this->validate($data, 'app\validate\dict\Dict.add');
  53. $id = (new DictService())->add($data);
  54. return success('ADD_SUCCESS', ['id' => $id]);
  55. }
  56. /**
  57. * 数据字典编辑
  58. * @param $id 数据字典id
  59. * @return \think\Response
  60. */
  61. public function edit($id){
  62. $data = $this->request->params([
  63. ["name",""],
  64. ["key",""],
  65. ["memo",""],
  66. ]);
  67. // $this->validate($data, 'app\validate\dict\Dict.edit');
  68. (new DictService())->edit($id, $data);
  69. return success('EDIT_SUCCESS');
  70. }
  71. /**
  72. * 数据字典删除
  73. * @param int $id 数据字典id
  74. * @return Response
  75. */
  76. public function del(int $id){
  77. (new DictService())->del($id);
  78. return success('DELETE_SUCCESS');
  79. }
  80. /**
  81. * 添加数据字典内容
  82. */
  83. public function addDictData($id)
  84. {
  85. $data = $this->request->params([
  86. ["dictionary",'[]'],
  87. ]);
  88. // $this->validate($data, 'app\validate\dict\Dict.add');
  89. $data['dictionary'] = json_encode($data['dictionary'], true);
  90. (new DictService())->edit($id,$data);
  91. return success('ADD_SUCCESS');
  92. }
  93. /**
  94. * 获取全部数据字典
  95. * @return \think\Response
  96. */
  97. public function getAll(){
  98. return success((new DictService())->getAll());
  99. }
  100. /**
  101. * 数据字典详情
  102. * @param string $type
  103. * @return Response
  104. */
  105. public function getKeyInfo(string $type){
  106. $res = (new DictService())->getKeyInfo($type);
  107. return success($res);
  108. }
  109. }