GuaranteeTemplate.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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\merchant\store\guarantee;
  12. use app\common\repositories\store\GuaranteeRepository;
  13. use app\common\repositories\store\GuaranteeTemplateRepository;
  14. use app\validate\admin\GuaranteeTemplateValidate;
  15. use think\App;
  16. use crmeb\basic\BaseController;
  17. class GuaranteeTemplate extends BaseController
  18. {
  19. /**
  20. * @var GuaranteeTemplateRepository
  21. */
  22. protected $repository;
  23. /**
  24. * Product constructor.
  25. * @param App $app
  26. * @param GuaranteeTemplateRepository $repository
  27. */
  28. public function __construct(App $app, GuaranteeTemplateRepository $repository)
  29. {
  30. parent::__construct($app);
  31. $this->repository = $repository;
  32. }
  33. /**
  34. * 获取保障模板列表
  35. * @return \think\response\Json
  36. */
  37. public function lst()
  38. {
  39. // 获取分页参数
  40. [$page, $limit] = $this->getPage();
  41. // 获取查询条件
  42. $where = $this->request->params(['date', 'keyword']);
  43. // 设置查询条件
  44. $where['is_del'] = 0;
  45. $where['mer_id'] = $this->request->merId();
  46. // 获取保障模板列表
  47. $data = $this->repository->getList($where, $page, $limit);
  48. // 返回成功响应
  49. return app('json')->success($data);
  50. }
  51. /**
  52. * 创建保障模板
  53. * @param GuaranteeTemplateValidate $validate 验证器实例
  54. * @return \think\response\Json
  55. */
  56. public function create(GuaranteeTemplateValidate $validate)
  57. {
  58. // 获取保障模板数据
  59. $data = $this->request->params(['template_name', 'template_value', ['status', 1], 'sort']);
  60. // 验证保障模板数据
  61. $validate->check($data);
  62. // 设置商家ID
  63. $data['mer_id'] = $this->request->merId();
  64. // 创建保障模板
  65. $this->repository->create($data);
  66. return app('json')->success('添加成功');
  67. }
  68. /**
  69. * 获取保障模板详情
  70. * @param int $id 保障模板ID
  71. * @return \think\response\Json
  72. */
  73. public function detail($id)
  74. {
  75. // 获取保障模板详情
  76. $ret = $this->repository->detail($id, $this->request->merId());
  77. return app('json')->success($ret);
  78. }
  79. /**
  80. * 修改保障模板
  81. * @param int $id 保障模板ID
  82. * @param GuaranteeTemplateValidate $validate 验证器实例
  83. * @return \think\response\Json
  84. */
  85. public function update($id, GuaranteeTemplateValidate $validate)
  86. {
  87. // 获取保障模板数据
  88. $data = $this->request->params(['template_name', 'template_value', ['status', 1], 'sort']);
  89. // 验证保障模板数据
  90. $validate->check($data);
  91. $this->repository->detail($id, $this->request->merId());
  92. // 设置商家ID
  93. $data['mer_id'] = $this->request->merId();
  94. $this->repository->edit($id, $data);
  95. return app('json')->success('编辑成功');
  96. }
  97. /**
  98. * 根据ID删除记录
  99. *
  100. * @param int $id 记录ID
  101. * @return \Illuminate\Http\JsonResponse 返回JSON格式的成功提示信息
  102. */
  103. public function delete($id)
  104. {
  105. // 获取指定ID的记录详情
  106. $this->repository->detail($id, $this->request->merId());
  107. // 删除指定ID的记录
  108. $this->repository->delete($id);
  109. // 返回JSON格式的成功提示信息
  110. return app('json')->success('删除成功');
  111. }
  112. /**
  113. * 添加模板筛选的条款数据
  114. * @return \think\response\Json
  115. * @author Qinii
  116. * @day 5/25/21
  117. */
  118. public function select()
  119. {
  120. $where['keyword'] = $this->request->param('keyword');
  121. $where['is_del'] = 0;
  122. $where['status'] = 1;
  123. $data = app()->make(GuaranteeRepository::class)->select($where);
  124. return app('json')->success($data);
  125. }
  126. /**
  127. * 对指定ID的数据进行排序操作
  128. *
  129. * @param int $id 数据ID
  130. * @return \think\response\Json 返回JSON格式的响应结果
  131. */
  132. public function sort($id)
  133. {
  134. $ret = $this->repository->detail($id, $this->request->merId());
  135. if (!$ret) return app('json')->fail('数据不存在');
  136. // 构造需要更新的数据
  137. $data = [
  138. 'sort' => $this->request->param('sort'),
  139. ];
  140. $this->repository->update($id, $data);
  141. // 返回成功信息
  142. return app('json')->success('修改成功');
  143. }
  144. /**
  145. * 商品选择模板的下拉数据
  146. * @return \think\response\Json
  147. * @author Qinii
  148. * @day 5/25/21
  149. */
  150. public function list()
  151. {
  152. $data = $this->repository->list($this->request->merId());
  153. return app('json')->success($data);
  154. }
  155. /**
  156. * 切换状态
  157. *
  158. * @param int $id 记录ID
  159. * @return \think\response\Json
  160. */
  161. public function switchStatus($id)
  162. {
  163. $ret = $this->repository->detail($id, $this->request->merId());
  164. if (!$ret) return app('json')->fail('数据不存在');
  165. // 构造更新数据
  166. $data = [
  167. 'status' => $this->request->param('status') == 1 ?: 0,
  168. ];
  169. $this->repository->update($id, $data);
  170. // 返回成功信息
  171. return app('json')->success('修改成功');
  172. }
  173. }