FeedBack.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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\user;
  12. use crmeb\basic\BaseController;
  13. use think\App;
  14. use app\common\repositories\user\FeedbackRepository as repository;
  15. /**
  16. * 用户反馈
  17. * app\controller\admin\user
  18. * FeedBack
  19. */
  20. class FeedBack extends BaseController
  21. {
  22. /**
  23. * @var UserRepository
  24. */
  25. protected $repository;
  26. /**
  27. * User constructor.
  28. * @param App $app
  29. * @param $repository
  30. */
  31. public function __construct(App $app, repository $repository)
  32. {
  33. parent::__construct($app);
  34. $this->repository = $repository;
  35. }
  36. /**
  37. * 列表
  38. * @return mixed
  39. * @author Qinii
  40. */
  41. public function lst()
  42. {
  43. $where = $this->request->params(['keyword', 'type', 'status', 'realname', ['is_del', 0]]);
  44. [$page, $limit] = $this->getPage();
  45. return app('json')->success($this->repository->getList($where, $page, $limit));
  46. }
  47. /**
  48. * 详情
  49. * @param $id
  50. * @return mixed
  51. * @author Qinii
  52. */
  53. public function detail($id)
  54. {
  55. if (!$this->repository->fieldExists('feedback_id', $id))
  56. return app('json')->fail('数据不存在');
  57. $feedback = $this->repository->get($id)->toArray();
  58. [$feedback['category'], $feedback['type']] = explode('/', $feedback['type'], 2);
  59. return app('json')->success($feedback);
  60. }
  61. /**
  62. * 回复表单
  63. * @param $id
  64. * @return mixed
  65. * @author Qinii
  66. */
  67. public function replyForm($id)
  68. {
  69. return app('json')->success(formToData($this->repository->replyForm($id)));
  70. }
  71. /**
  72. * 回复提交
  73. * @param $id
  74. * @return mixed
  75. * @throws \think\db\exception\DbException
  76. * @author Qinii
  77. */
  78. public function reply($id)
  79. {
  80. if (!$this->repository->fieldExists('feedback_id', $id))
  81. return app('json')->fail('数据不存在');
  82. $data = $this->request->params(['reply', 'remake']);
  83. if (empty($data['reply'])) {
  84. return app('json')->fail('请填写回复内容');
  85. }
  86. $data['status'] = 1;
  87. $data['update_time'] = date('Y-m-d H:i:s');
  88. $this->repository->update($id, $data);
  89. if (!empty($data['reply'])) event('user.feedbackReply', compact('id', 'data'));
  90. return app('json')->success('回复成功');
  91. }
  92. /**
  93. * 删除
  94. * @param $id
  95. * @return mixed
  96. * @author Qinii
  97. */
  98. public function delete($id)
  99. {
  100. if (!$this->repository->fieldExists('feedback_id', $id))
  101. return app('json')->fail('数据不存在');
  102. $this->repository->update($id, ['is_del' => 1]);
  103. return app('json')->success('删除成功');
  104. }
  105. }