GroupData.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-03-27
  7. *
  8. *
  9. */
  10. namespace app\controller\merchant\system\groupData;
  11. use crmeb\basic\BaseController;
  12. use app\common\repositories\system\groupData\GroupDataRepository;
  13. use app\common\repositories\system\groupData\GroupRepository;
  14. use app\validate\admin\GroupDataValidate;
  15. use FormBuilder\Exception\FormBuilderException;
  16. use think\App;
  17. use think\db\exception\DataNotFoundException;
  18. use think\db\exception\DbException;
  19. use think\db\exception\ModelNotFoundException;
  20. /**
  21. * Class GroupData
  22. * @package app\controller\admin\system\groupData
  23. * @author xaboy
  24. * @day 2020-03-27
  25. */
  26. class GroupData extends BaseController
  27. {
  28. /**
  29. * @var GroupDataRepository
  30. */
  31. protected $repository;
  32. /**
  33. * GroupData constructor.
  34. * @param App $app
  35. * @param GroupDataRepository $repository
  36. */
  37. public function __construct(App $app, GroupDataRepository $repository)
  38. {
  39. parent::__construct($app);
  40. $this->repository = $repository;
  41. }
  42. /**
  43. * @param int $groupId
  44. * @return mixed
  45. * @throws DataNotFoundException
  46. * @throws DbException
  47. * @throws ModelNotFoundException
  48. * @author xaboy
  49. * @day 2020-03-30
  50. */
  51. public function lst($groupId)
  52. {
  53. [$page, $limit] = $this->getPage();
  54. $lst = $this->repository->getGroupDataLst($this->request->merId(), $groupId, $page, $limit);
  55. return app('json')->success($lst);
  56. }
  57. /**
  58. * @param int $groupId
  59. * @return mixed
  60. * @throws FormBuilderException
  61. * @author xaboy
  62. * @day 2020-04-02
  63. */
  64. public function createTable($groupId)
  65. {
  66. if (!app()->make(GroupRepository::class)->exists($groupId))
  67. return app('json')->fail('组合数据不存在!');
  68. // return app('json')->success(formToData($this->repository->form($groupId)));
  69. return app('json')->success(formToData($this->repository->form_mer($groupId)));
  70. }
  71. /**
  72. * @param $id
  73. * @return mixed
  74. * @throws DbException
  75. * @author xaboy
  76. * @day 2020-05-13
  77. */
  78. public function changeStatus($id)
  79. {
  80. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  81. if (!$this->repository->merExists($this->request->merId(), $id))
  82. return app('json')->fail('数据不存在');
  83. $this->repository->update($id, compact('status'));
  84. return app('json')->success('修改成功');
  85. }
  86. /**
  87. * @param int $groupId
  88. * @param int $id
  89. * @return mixed
  90. * @throws DataNotFoundException
  91. * @throws DbException
  92. * @throws ModelNotFoundException
  93. * @throws FormBuilderException
  94. * @author xaboy
  95. * @day 2020-04-02
  96. */
  97. public function updateTable($groupId, $id)
  98. {
  99. if (!app()->make(GroupRepository::class)->exists($groupId))
  100. return app('json')->fail('组合数据不存在!');
  101. if (!$this->repository->merExists($this->request->merId(), $id))
  102. return app('json')->fail('数据不存在!');
  103. // return app('json')->success(formToData($this->repository->updateForm($groupId, $this->request->merId(), $id)));
  104. return app('json')->success(formToData($this->repository->updateForm_mer($groupId, $this->request->merId(), $id)));
  105. }
  106. /**
  107. * @param int $groupId
  108. * @param GroupDataValidate $validate
  109. * @param GroupRepository $groupRepository
  110. * @return mixed
  111. * @author xaboy
  112. * @day 2020-04-02
  113. */
  114. public function create($groupId, GroupDataValidate $validate, GroupRepository $groupRepository)
  115. {
  116. $data = $this->request->params([['sort', 0], ['status', 0]]);
  117. $validate->check($data);
  118. if (!$groupRepository->exists($groupId))
  119. return app('json')->fail('数据组不存在');
  120. $data['value'] = $this->request->params($groupRepository->keys($groupId));
  121. $data['group_id'] = $groupId;
  122. $this->repository->create($this->request->merId(), $data);
  123. return app('json')->success('添加成功');
  124. }
  125. /**
  126. * @param int $groupId
  127. * @param int $id
  128. * @param GroupDataValidate $validate
  129. * @param GroupRepository $groupRepository
  130. * @return mixed
  131. * @throws DbException
  132. * @author xaboy
  133. * @day 2020-04-02
  134. */
  135. public function update($groupId,$id, GroupDataValidate $validate, GroupRepository $groupRepository)
  136. {
  137. $data = $this->request->params([['sort', 0], ['status', 0]]);
  138. $validate->check($data);
  139. if (!$groupRepository->exists($groupId))
  140. return app('json')->fail('数据组不存在');
  141. if (!$this->repository->merExists($this->request->merId(), $id))
  142. return app('json')->fail('数据不存在!');
  143. $data['value'] = $this->request->params($groupRepository->keys($groupId));
  144. $this->repository->merUpdate($this->request->merId(), $id, $data);
  145. return app('json')->success('修改成功');
  146. }
  147. /**
  148. * @param int $id
  149. * @return mixed
  150. * @throws DbException
  151. * @author xaboy
  152. * @day 2020-03-30
  153. */
  154. public function delete($id)
  155. {
  156. $this->repository->merDelete($this->request->merId(), $id);
  157. return app('json')->success('删除成功');
  158. }
  159. }