SystemFormDataServices.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\dao\system\form\SystemFormDataDao;
  15. use app\services\BaseServices;
  16. use app\dao\diy\DiyDao;
  17. use think\exception\ValidateException;
  18. /**
  19. * 系统表单
  20. * Class SystemFormDataServices
  21. * @package app\services\system\form
  22. * @mixin DiyDao
  23. */
  24. class SystemFormDataServices extends BaseServices
  25. {
  26. /**
  27. * DiyServices constructor.
  28. * @param SystemFormDataDao $dao
  29. */
  30. public function __construct(SystemFormDataDao $dao)
  31. {
  32. $this->dao = $dao;
  33. }
  34. /**
  35. * 获取表单收集数据列表
  36. * @param int $id
  37. * @param array $where
  38. * @return array
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. */
  43. public function getFormDataList(int $id = 0, array $where = [])
  44. {
  45. $where['is_del'] = 0;
  46. if ($id) $where['system_form_id'] = $id;
  47. [$page, $limit] = $this->getPageValue();
  48. $list = $this->dao->getList($where, ['*'], $page, $limit, ['user', 'systemForm']);
  49. $count = $this->dao->count($where);
  50. return compact('list', 'count');
  51. }
  52. /**
  53. * 保存系统表单收集数据
  54. * @param array $form
  55. * @param int $type
  56. * @return bool
  57. */
  58. public function setFormData(array $form, int $type = 1)
  59. {
  60. if (!$form) {
  61. throw new ValidateException('缺少表单收集数据');
  62. }
  63. /** @var SystemFormServices $systemFormServices */
  64. $systemFormServices = app()->make(SystemFormServices::class);
  65. $form['value'] = $systemFormServices->handleForm($form['value'] ?? []);
  66. $form['value'] = json_encode($form['value']);
  67. $data = ['type' => $type, 'add_time' => time()];
  68. switch ($type) {
  69. case 1://订单
  70. $data = array_merge($data, $form);
  71. break;
  72. }
  73. if ($data) {
  74. $this->dao->save($data);
  75. }
  76. return true;
  77. }
  78. }