Contribution.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-03-24
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\system\config;
  11. use crmeb\basic\BaseController;
  12. use app\common\repositories\system\config\ConfigContributionRepository;
  13. use FormBuilder\Exception\FormBuilderException;
  14. use think\App;
  15. use think\db\exception\DataNotFoundException;
  16. use think\db\exception\DbException;
  17. use think\db\exception\ModelNotFoundException;
  18. /**
  19. * Class Contribution
  20. * @package app\controller\admin\system\config
  21. * @author xaboy
  22. * @day 2020-03-27
  23. */
  24. class Contribution extends BaseController
  25. {
  26. /**
  27. * @var ConfigContributionRepository
  28. */
  29. private $repository;
  30. /**
  31. * ConfigClassify constructor.
  32. * @param App $app
  33. * @param ConfigContributionRepository $repository
  34. */
  35. public function __construct(App $app, ConfigContributionRepository $repository)
  36. {
  37. parent::__construct($app);
  38. $this->repository = $repository;
  39. }
  40. /**
  41. * @return mixed 列表
  42. * @throws DataNotFoundException
  43. * @throws DbException
  44. * @throws ModelNotFoundException
  45. * @author xaboy
  46. * @day 2020-03-31
  47. */
  48. public function lst()
  49. {
  50. $lst = $this->repository->lst();
  51. // $lst['list'] = $lst['list']->toArray();
  52. return app('json')->success($lst);
  53. }
  54. /**
  55. * @return mixed 创建表单
  56. * @throws FormBuilderException
  57. * @author xaboy
  58. * @day 2020-03-31
  59. */
  60. public function createTable()
  61. {
  62. $form = $this->repository->createForm();
  63. return app('json')->success(formToData($form));
  64. }
  65. /** 修改表单
  66. * @param int $id
  67. * @return mixed
  68. * @throws DataNotFoundException
  69. * @throws DbException
  70. * @throws ModelNotFoundException
  71. * @throws FormBuilderException
  72. * @author xaboy
  73. * @day 2020-03-31
  74. */
  75. public function updateTable($id)
  76. {
  77. if (!$this->repository->exists($id)) app('json')->fail('数据不存在');
  78. $form = $this->repository->updateForm($id);
  79. return app('json')->success(formToData($form));
  80. }
  81. /** 创建
  82. * @return mixed
  83. * @author xaboy
  84. * @day 2020-03-27
  85. */
  86. public function create()
  87. {
  88. $data = $this->request->params(['title', 'start', 'end', 'type', 'jd', 'value']);
  89. $this->repository->create($data);
  90. return app('json')->success('添加成功');
  91. }
  92. /**修改
  93. * @param int $id
  94. * @return mixed
  95. * @throws DbException
  96. * @author xaboy
  97. * @day 2020-03-27
  98. */
  99. public function update($id)
  100. {
  101. $data = $this->request->params(['title', 'start', 'end', 'type', 'jd', 'value']);
  102. $this->repository->update($id, $data);
  103. return app('json')->success('修改成功');
  104. }
  105. /** 删除
  106. * @param int $id
  107. * @return mixed
  108. * @throws DbException
  109. * @author xaboy
  110. * @day 2020-03-27
  111. */
  112. public function delete($id)
  113. {
  114. $this->repository->delete($id);
  115. return app('json')->success('删除成功');
  116. }
  117. }