SystemForm.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. namespace app\controller\store\system\form;
  12. use app\controller\store\AuthController;
  13. use app\services\system\form\SystemFormServices;
  14. use think\facade\App;
  15. /**
  16. *
  17. * Class SystemForm
  18. * @package app\controller\store\system\form
  19. */
  20. class SystemForm extends AuthController
  21. {
  22. /**
  23. * Diy constructor.
  24. * @param App $app
  25. * @param SystemFormServices $services
  26. */
  27. public function __construct(App $app, SystemFormServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /*
  33. * 所有系统表单
  34. */
  35. public function allSystemForm()
  36. {
  37. $data = $this->services->getFormList([], ['id', 'name']);
  38. return $this->success($data['list'] ?? []);
  39. }
  40. /**
  41. * 获取一条数据
  42. * @param int $id
  43. * @return mixed
  44. */
  45. public function getInfo(int $id)
  46. {
  47. if (!$id) return $this->fail('数据不存在');
  48. [$type] = $this->request->postMore([
  49. ['type', 0],
  50. ], true);
  51. $info = $this->services->get($id);
  52. if ($info) {
  53. $info = $info->toArray();
  54. } else {
  55. return $this->fail('数据不存在');
  56. }
  57. $info['value'] = json_decode($info['value'], true);
  58. if ($type == 1) {//处理表单数据
  59. $value = $info['value'] ?? [];
  60. $info = $this->services->handleForm($value);
  61. }
  62. return $this->success(compact('info'));
  63. }
  64. }