SystemCrudListServices.php 3.7 KB

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