StoreServiceReply.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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\service;
  12. use app\common\repositories\store\service\StoreServiceReplyRepository;
  13. use app\validate\merchant\ServiceReplyValidate;
  14. use crmeb\basic\BaseController;
  15. use think\App;
  16. class StoreServiceReply extends BaseController
  17. {
  18. /**
  19. * @var StoreServiceReplyRepository
  20. */
  21. protected $repository;
  22. /**
  23. * StoreService constructor.
  24. * @param App $app
  25. * @param StoreServiceReplyRepository $repository
  26. */
  27. public function __construct(App $app, StoreServiceReplyRepository $repository)
  28. {
  29. parent::__construct($app);
  30. $this->repository = $repository;
  31. }
  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(['keyword', 'status']);
  43. $where['mer_id'] = $this->request->merId();
  44. // 调用 repository 类的 getList 方法获取列表数据并返回 JSON 格式的响应
  45. return app('json')->success($this->repository->getList($where, $page, $limit));
  46. }
  47. /**
  48. * 创建数据
  49. *
  50. * @return \think\response\Json
  51. */
  52. public function create()
  53. {
  54. // 校验参数
  55. $data = $this->checkParams();
  56. // 调用 repository 类的 create 方法创建数据并返回 JSON 格式的响应
  57. $this->repository->create($data);
  58. return app('json')->success('添加成功');
  59. }
  60. /**
  61. * 更新服务回复
  62. *
  63. * @param int $id 服务回复ID
  64. * @return \Psr\Http\Message\ResponseInterface
  65. */
  66. public function update($id)
  67. {
  68. // 检查参数
  69. $data = $this->checkParams();
  70. // 判断数据是否存在
  71. if (!$this->repository->existsWhere(['mer_id' => $data['mer_id'], 'service_reply_id' => $id])) {
  72. return app('json')->fail('数据不存在');
  73. }
  74. // 更新数据
  75. $this->repository->update($id, $data);
  76. // 返回成功信息
  77. return app('json')->success('修改成功');
  78. }
  79. /**
  80. * 删除服务回复
  81. *
  82. * @param int $id 服务回复ID
  83. * @return \Psr\Http\Message\ResponseInterface
  84. */
  85. public function delete($id)
  86. {
  87. if (!$this->repository->existsWhere(['mer_id' => $this->request->merId(), 'service_reply_id' => $id])) {
  88. return app('json')->fail('数据不存在');
  89. }
  90. // 删除数据
  91. $this->repository->delete((int)$id);
  92. return app('json')->success('删除成功');
  93. }
  94. /**
  95. * 修改状态
  96. * @param int $id 服务回复ID
  97. * @return \think\response\Json
  98. */
  99. public function changeStatus($id)
  100. {
  101. // 获取请求参数中的状态值
  102. $data = $this->request->params(['status']);
  103. // 判断服务回复是否存在
  104. if (!$this->repository->existsWhere(['mer_id' => $this->request->merId(), 'service_reply_id' => $id])) {
  105. return app('json')->fail('数据不存在');
  106. }
  107. // 更新服务回复状态
  108. $this->repository->update($id, $data);
  109. return app('json')->success('修改成功');
  110. }
  111. /**
  112. * 检查参数
  113. * @return array
  114. */
  115. public function checkParams()
  116. {
  117. // 获取请求参数中的关键字、状态、内容和类型
  118. $data = $this->request->params(['keyword', 'status', 'content', 'type']);
  119. // 校验参数
  120. app()->make(ServiceReplyValidate::class)->check($data);
  121. // 添加商家ID到参数中
  122. $data['mer_id'] = $this->request->merId();
  123. return $data;
  124. }
  125. }