SystemFormServices.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\services\system\form;
  13. use app\dao\system\form\SystemFormDao;
  14. use app\services\BaseServices;
  15. use app\dao\diy\DiyDao;
  16. /**
  17. * 系统表单
  18. * Class SystemFormServices
  19. * @package app\services\diy
  20. * @mixin DiyDao
  21. */
  22. class SystemFormServices extends BaseServices
  23. {
  24. /**
  25. * form类型
  26. * @var string[]
  27. */
  28. protected $formType = [
  29. 'checkboxs' => '多选框',
  30. 'citys' => '城市',
  31. 'dates' => '日期',
  32. 'dateranges' => '日期范围',
  33. 'radios' => '单选框',
  34. 'selects' => '下拉框',
  35. 'texts' => '文本框',
  36. 'times' => '时间',
  37. 'timeranges' => '时间范围',
  38. 'uploadPicture' => '图片'
  39. ];
  40. /**
  41. * DiyServices constructor.
  42. * @param SystemFormDao $dao
  43. */
  44. public function __construct(SystemFormDao $dao)
  45. {
  46. $this->dao = $dao;
  47. }
  48. /**
  49. * 获取系统表单
  50. * @param array $where
  51. * @param array $field
  52. * @return array
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. public function getFormList(array $where = [], array $field = ['*'])
  58. {
  59. [$page, $limit] = $this->getPageValue();
  60. $list = $this->dao->getFormList($where, $field, $page, $limit);
  61. $count = $this->dao->count($where + ['is_del' => 0]);
  62. return compact('list', 'count');
  63. }
  64. /**
  65. * 处理表单数据
  66. * @param array $form
  67. * @return array
  68. */
  69. public function handleForm(array $form)
  70. {
  71. $info = [];
  72. if ($form) {
  73. $infoOne = [];
  74. foreach ($form as $item) {
  75. $infoOne['id'] = $item['id'] ?? '';
  76. $infoOne['type'] = $item['name'] ?? '';
  77. $infoOne['name'] = $this->formType[$infoOne['type']] ?? '';
  78. $infoOne['title'] = $item['titleConfig']['value'] ?? '';
  79. $infoOne['tip'] = $item['tipConfig']['value'] ?? '';
  80. $infoOne['list'] = [];
  81. $infoOne['require'] = $item['titleShow']['val'] ?? false;
  82. switch ($item['name']) {
  83. case 'checkboxs':
  84. case 'radios':
  85. case 'selects':
  86. $infoOne['list'] = $item['wordsConfig']['list'] ?? [];
  87. break;
  88. }
  89. $infoOne['value'] = $item['value'] ?? '';
  90. $info[] = $infoOne;
  91. }
  92. }
  93. return $info;
  94. }
  95. }