SystemCrudListServices.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\services\system;
  3. use app\dao\system\SystemCrudListDao;
  4. use app\services\BaseServices;
  5. use crmeb\services\FormBuilder as Form;
  6. use think\facade\Route as Url;
  7. class SystemCrudListServices extends BaseServices
  8. {
  9. /**
  10. * SystemCrudListServices constructor.
  11. * @param SystemCrudListDao $dao
  12. */
  13. public function __construct(SystemCrudListDao $dao)
  14. {
  15. $this->dao = $dao;
  16. }
  17. /**
  18. * 数据字典列表
  19. * @param $where
  20. * @return array
  21. * @throws \ReflectionException
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\DbException
  24. * @throws \think\db\exception\ModelNotFoundException
  25. * @author wuhaotian
  26. * @email 442384644@qq.com
  27. * @date 2024/5/20
  28. */
  29. public function dataDictionaryList($where)
  30. {
  31. [$page, $limit] = $this->getPageValue();
  32. $list = $this->dao->selectList($where, '*', $page, $limit, '', [], true)->toArray();
  33. $count = $this->dao->count($where);
  34. foreach ($list as &$item) {
  35. $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  36. }
  37. return compact('list', 'count');
  38. }
  39. /**
  40. * 数据字典新增/编辑
  41. * @param int $id
  42. * @return array
  43. * @throws \FormBuilder\Exception\FormBuilderException
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. * @author wuhaotian
  48. * @email 442384644@qq.com
  49. * @date 2024/5/20
  50. */
  51. public function dataDictionaryListCreate($id = 0)
  52. {
  53. $info = $this->dao->get($id);
  54. $field = [];
  55. $field[] = Form::input('name', '字典名称', $info['name'] ?? '')->required();
  56. $field[] = Form::input('mark', '字典标识', $info['mark'] ?? '')->required();
  57. $field[] = Form::radio('level', '层级', $info['level'] ?? 0)->options([['value' => 1, 'label' => '多级'], ['value' => 0, 'label' => '一级']]);
  58. $field[] = Form::radio('status', '状态', $info['status'] ?? 1)->options([['value' => 1, 'label' => '显示'], ['value' => 0, 'label' => '隐藏']]);
  59. return create_form($id ? '编辑' : '新增', $field, Url::buildUrl('/system/crud/data_dictionary_list/save/' . $id), 'POST');
  60. }
  61. /**
  62. * 数据字典保存
  63. * @param int $id
  64. * @param array $data
  65. * @return bool
  66. * @author wuhaotian
  67. * @email 442384644@qq.com
  68. * @date 2024/5/20
  69. */
  70. public function dataDictionaryListSave($id = 0, $data = [])
  71. {
  72. if ($id) {
  73. $this->dao->update($id, $data);
  74. } else {
  75. $data['add_time'] = time();
  76. $this->dao->save($data);
  77. }
  78. return true;
  79. }
  80. /**
  81. * 数据字典删除
  82. * @param $id
  83. * @return bool
  84. * @author wuhaotian
  85. * @email 442384644@qq.com
  86. * @date 2024/5/20
  87. */
  88. public function dataDictionaryListDel($id)
  89. {
  90. $res1 = $this->dao->delete($id);
  91. $res2 = app()->make(SystemCrudDataService::class)->delete(['cid' => $id]);
  92. return $res1 && $res2;
  93. }
  94. }