FeedbackController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * 用户反馈控制器
  4. */
  5. declare(strict_types=1);
  6. namespace Modules\Manage\Controllers;
  7. use App\Model\FeedbackModel;
  8. use App\Repositories\FeedbackRepository;
  9. use Carbon\Carbon;
  10. use Hyperf\Validation\Contract\ValidatorFactoryInterface;
  11. class FeedbackController extends BaseController
  12. {
  13. /**
  14. * 反馈列表
  15. * @param FeedbackRepository $feedbackRepository
  16. * @return mixed
  17. */
  18. public function list(
  19. ValidatorFactoryInterface $validatorFactory,
  20. FeedbackRepository $feedbackRepository
  21. ) {
  22. $inputData = $this->getJsonData();
  23. $rules = [
  24. 'name' => 'string',
  25. 'code' => 'string',
  26. 'content' => 'string',
  27. 'status' => 'numeric',
  28. 'page' => 'required|numeric',
  29. 'page_size' => 'required|numeric',
  30. 'user_id' => 'string',
  31. ];
  32. $validator = $validatorFactory->make($inputData, $rules);
  33. if ($validator->fails()) {
  34. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  35. return json_fail($validator->errors()->first());
  36. }
  37. return json_success($feedbackRepository->getAdminList($inputData));
  38. }
  39. /**
  40. * 对话列表
  41. * @param FeedbackRepository $feedbackRepository
  42. * @return mixed
  43. */
  44. public function talkList(
  45. ValidatorFactoryInterface $validatorFactory,
  46. FeedbackRepository $feedbackRepository
  47. ) {
  48. $inputData = $this->getJsonData();
  49. $rules = [
  50. 'code' => 'required|string',
  51. 'page' => 'required|numeric',
  52. 'page_size' => 'required|numeric',
  53. ];
  54. $validator = $validatorFactory->make($inputData, $rules);
  55. if ($validator->fails()) {
  56. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  57. return json_fail($validator->errors()->first());
  58. }
  59. $result = $feedbackRepository
  60. ->getTalkList(
  61. $inputData['code'],
  62. (int)$inputData['page'],
  63. (int)$inputData['page_size']
  64. );
  65. return json_success($result);
  66. }
  67. /**
  68. * 回复反馈
  69. */
  70. public function reply(
  71. ValidatorFactoryInterface $validatorFactory,
  72. FeedbackRepository $feedbackRepository
  73. ) {
  74. $inputData = $this->getJsonData();
  75. $rules = [
  76. 'uid' => 'required|string',
  77. 'type' => 'required|numeric',
  78. 'content' => 'required|string',
  79. ];
  80. $validator = $validatorFactory->make($inputData, $rules);
  81. if ($validator->fails()) {
  82. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  83. return json_fail($validator->errors()->first());
  84. }
  85. $item = FeedbackModel::query()->where('uid', $inputData['uid'])->first();
  86. if (empty($item)) {
  87. return json_fail('数据不存在!');
  88. }
  89. $managerInfo = $this->getCurrentManagerInfo();
  90. $inputData['rid'] = $managerInfo['manager_id'];
  91. $create = $feedbackRepository->feedbackReply($inputData);
  92. return json_success($create);
  93. }
  94. /**
  95. * 标记状态
  96. */
  97. public function status(ValidatorFactoryInterface $validatorFactory)
  98. {
  99. $inputData = $this->getJsonData();
  100. $rules = [
  101. 'code' => 'required|string',
  102. ];
  103. $validator = $validatorFactory->make($inputData, $rules);
  104. if ($validator->fails()) {
  105. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  106. return json_fail($validator->errors()->first());
  107. }
  108. $item = FeedbackModel::query()->where('uid', $inputData['code'])
  109. ->update(['status' => 1]);
  110. return json_success($item);
  111. }
  112. }