Feedback.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy<xaboy2005@qq.com>
  6. * @day 2020/5/28
  7. *
  8. *
  9. */
  10. namespace app\controller\api\user;
  11. use crmeb\basic\BaseController;
  12. use app\common\repositories\user\FeedbackRepository;
  13. use app\validate\api\FeedbackValidate;
  14. use think\App;
  15. class Feedback
  16. {
  17. protected $repository;
  18. public function __construct(App $app, FeedbackRepository $repository)
  19. {
  20. // parent::__construct($app);
  21. $this->repository = $repository;
  22. }
  23. /**
  24. * @param FeedbackValidate $validate
  25. * @param FeedbackRepository $repository
  26. * @return mixed
  27. * @author xaboy
  28. * @day 2020/5/28
  29. */
  30. public function feedback(FeedbackValidate $validate)
  31. {
  32. $data = request()->params(['type', 'content', 'images', 'realname', 'contact']);
  33. if (!is_array($data["images"])) {
  34. $data["images"] = explode(",", $data["images"]);
  35. }
  36. $validate->check($data);
  37. $data['uid'] = request()->uid();
  38. $this->repository->create($data);
  39. return app('json')->success('反馈成功');
  40. }
  41. /**
  42. * @return mixed
  43. * @author xaboy
  44. * @day 2020/5/28
  45. */
  46. public function feedbackList()
  47. {
  48. $data = request()->params(['page', 'limit']);
  49. $list = $this->repository->getList(['uid' => request()->uid(), 'is_del' => 0], $data['page'] ?? 1, $data['limit'] ?? 20);
  50. $reply = $this->repository->getReplyList(request()->uid(), $data['page'] ?? 1, $data['limit'] ?? 20);
  51. return app('json')->success(['list' => $list, 'replyList' => $reply]);
  52. }
  53. public function detail($id)
  54. {
  55. if (!$this->repository->uidExists($id, request()->uid()))
  56. return app('json')->fail('数据不存在');
  57. $feedback = $this->repository->get($id);
  58. return app('json')->success($feedback);
  59. }
  60. /**
  61. * @return void
  62. * @author 史晨
  63. * @date 2026/3/17 14:07
  64. * 用户回复反馈
  65. */
  66. public function reply()
  67. {
  68. $data = request()->params(['feedback_id', 'content']);
  69. if (empty($data['feedback_id']) || empty($data['content'])) {
  70. return app('json')->fail('参数错误');
  71. }
  72. $res = $this->repository->reply($data['feedback_id'], request()->uid(), $data['content']);
  73. if (!$res) {
  74. return app('json')->fail('回复失败');
  75. }
  76. return app('json')->success('回复成功');
  77. }
  78. }