Guarantee.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\admin\store;
  12. use app\common\repositories\store\GuaranteeRepository;
  13. use app\validate\admin\GuaranteeValidate;
  14. use think\App;
  15. use crmeb\basic\BaseController;
  16. /**
  17. * 保障服务
  18. */
  19. class Guarantee extends BaseController
  20. {
  21. /**
  22. * @var GuaranteeRepository
  23. */
  24. protected $repository;
  25. /**
  26. * City constructor.
  27. * @param App $app
  28. * @param GuaranteeRepository $repository
  29. */
  30. public function __construct(App $app, GuaranteeRepository $repository)
  31. {
  32. parent::__construct($app);
  33. $this->repository = $repository;
  34. }
  35. /**
  36. * 列表
  37. * @return \think\response\Json
  38. * @author Qinii
  39. */
  40. public function lst()
  41. {
  42. [$page, $limit] = $this->getPage();
  43. $where = $this->request->params(['date', 'keyword']);
  44. $where['is_del'] = 0;
  45. $data = $this->repository->getList($where, $page, $limit);
  46. return app('json')->success($data);
  47. }
  48. /**
  49. * 添加表单
  50. * @return \think\response\Json
  51. * @author Qinii
  52. */
  53. public function createForm()
  54. {
  55. return app('json')->success(formToData($this->repository->form(null)));
  56. }
  57. /**
  58. * 添加
  59. * @param GuaranteeValidate $validate
  60. * @return \think\response\Json
  61. * @author Qinii
  62. */
  63. public function create(GuaranteeValidate $validate)
  64. {
  65. $data = $this->checkParams($validate);
  66. $this->repository->create($data);
  67. return app('json')->success('添加成功');
  68. }
  69. /**
  70. * 修改表单
  71. * @param $id
  72. * @return \think\response\Json
  73. * @author Qinii
  74. */
  75. public function updateForm($id)
  76. {
  77. return app('json')->success(formToData($this->repository->updateForm($id)));
  78. }
  79. /**
  80. * 修改
  81. * @param $id
  82. * @param GuaranteeValidate $validate
  83. * @return \think\response\Json
  84. * @author Qinii
  85. */
  86. public function update($id, GuaranteeValidate $validate)
  87. {
  88. $ret = $this->repository->get($id);
  89. if (!$ret) return app('json')->fail('数据不存在');
  90. $data = $this->checkParams($validate);
  91. $this->repository->update($id, $data);
  92. return app('json')->success('编辑成功');
  93. }
  94. /**
  95. * 排序
  96. * @param $id
  97. * @return \think\response\Json
  98. * @author Qinii
  99. */
  100. public function sort($id)
  101. {
  102. $ret = $this->repository->get($id);
  103. if (!$ret) return app('json')->fail('数据不存在');
  104. $data = [
  105. 'sort' => $this->request->param('sort'),
  106. ];
  107. $this->repository->update($id, $data);
  108. return app('json')->success('修改成功');
  109. }
  110. /**
  111. * 状态修改
  112. * @param $id
  113. * @return \think\response\Json
  114. * @author Qinii
  115. */
  116. public function switchStatus($id)
  117. {
  118. $ret = $this->repository->get($id);
  119. if (!$ret) return app('json')->fail('数据不存在');
  120. $data = [
  121. 'status' => $this->request->param('status') == 1 ?: 0,
  122. ];
  123. $this->repository->update($id, $data);
  124. return app('json')->success('修改成功');
  125. }
  126. /**
  127. * 详情
  128. * @param $id
  129. * @return \think\response\Json
  130. * @author Qinii
  131. */
  132. public function detail($id)
  133. {
  134. $ret = $this->repository->get($id);
  135. if (!$ret) return app('json')->fail('数据不存在');
  136. return app('json')->success($ret);
  137. }
  138. /**
  139. * 删除
  140. * @param $id
  141. * @return \think\response\Json
  142. * @author Qinii
  143. */
  144. public function delete($id)
  145. {
  146. $ret = $this->repository->get($id);
  147. if (!$ret) return app('json')->fail('数据不存在');
  148. $this->repository->update($id, ['is_del' => 1]);
  149. return app('json')->success('删除成功');
  150. }
  151. /**
  152. * 验证
  153. * @param GuaranteeValidate $validate
  154. * @return array|mixed|string|string[]
  155. * @author Qinii
  156. */
  157. public function checkParams(GuaranteeValidate $validate)
  158. {
  159. $params = [
  160. "guarantee_name", "guarantee_info", "image", "status", "sort",
  161. ];
  162. $data = $this->request->params($params);
  163. $validate->check($data);
  164. return $data;
  165. }
  166. }