FeedbackRepository.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * 用户反馈仓库
  4. */
  5. declare(strict_types=1);
  6. namespace App\Repositories;
  7. use App\Model\FeedbackModel;
  8. use App\Model\UserModel;
  9. use App\Repositories\Service\CommonService;
  10. use Carbon\Carbon;
  11. use KZ2\Repositories\Model\Repository;
  12. class FeedbackRepository extends Repository
  13. {
  14. public function model()
  15. {
  16. return FeedbackModel::class;
  17. }
  18. /**
  19. * 回复反馈
  20. * @return mixed
  21. * @throws \Psr\SimpleCache\InvalidArgumentException
  22. */
  23. public function feedbackReply($inputData)
  24. {
  25. $rid = strval(data_get($inputData, 'rid'));
  26. $uid = strval(data_get($inputData, 'uid'));
  27. $type = intval(data_get($inputData, 'type'));
  28. $content = strval(data_get($inputData, 'content'));
  29. $create = FeedbackModel::query()->create(
  30. [
  31. 'rid' => $rid,
  32. 'status' => 1,
  33. 'uid' => $uid,
  34. 'type' => $type,
  35. 'content' => $content,
  36. ]
  37. );
  38. // if ($type == 2) {
  39. // $create->content = make(CommonService::class)
  40. // ->getImageUrl($create->content);
  41. // }
  42. Carbon::setLocale('zh');
  43. $create->time = Carbon::parse($create->created_at)->diffForHumans();
  44. unset($create->uid, $create->created_at);
  45. return $create;
  46. }
  47. /**
  48. * 管理后台获取反馈列表
  49. */
  50. public function getAdminList($inputData)
  51. {
  52. $page = intval(data_get($inputData, 'page'));
  53. $page_size = intval(data_get($inputData, 'page_size'));
  54. $name = strval(data_get($inputData, 'name', ''));
  55. $code = strval(data_get($inputData, 'code', ''));
  56. $content = strval(data_get($inputData, 'content', ''));
  57. $status = strval(data_get($inputData, 'status', ''));
  58. // $user_id = strval(data_get($inputData, 'user_id', ''));
  59. $device_type = strval(data_get($inputData, 'device_type', ''));
  60. $query = 'SELECT uid, max(id) id FROM feedback GROUP BY uid';
  61. $model = FeedbackModel::query()
  62. ->with('user')->from('feedback as f1');
  63. if ($name) {
  64. $code = UserModel::query()->where('nick', 'like', $name . '%')
  65. ->value('code');
  66. }
  67. if (is_numeric($status)) {
  68. $model = $model->where('f1.status', $status);
  69. }
  70. if ($code) {
  71. $model = $model->where('f1.uid', $code);
  72. }
  73. if ($device_type) {
  74. $model = $model->where('f1.device_type', $device_type);
  75. }
  76. // if ($user_id) {
  77. // $model = $model->where('f1.user_id', $user_id);
  78. // }
  79. if ($content) {
  80. $model = $model->where('f1.content', 'like', '%' . $content . '%');
  81. }
  82. $list = $model->joinSub($query, 'f2', 'f1.uid', '=', 'f2.uid')
  83. ->whereRaw('f1.id = f2.id')
  84. ->orderByDesc('f1.created_at')
  85. ->paginate($page_size, ['*'], 'page', $page);
  86. // foreach ($list as $item) {
  87. // if ($item['type'] == 2) {
  88. // $item->content = make(CommonService::class)
  89. // ->getImageUrl($item->content, true);
  90. // }
  91. // }
  92. return $list;
  93. }
  94. public function getTalkList($uid, $page, $page_size)
  95. {
  96. $result = FeedbackModel::query()
  97. ->where(['uid' => $uid])
  98. ->paginate(
  99. $page_size,
  100. ['type','content','rid','created_at'],
  101. 'page',
  102. $page
  103. );
  104. foreach ($result as $v) {
  105. // if ($v->type == 2) {
  106. // $v->content = make(CommonService::class)
  107. // ->getImageUrl($v->content, true);
  108. // }
  109. Carbon::setLocale('zh');
  110. $v->time = Carbon::parse($v->created_at)->diffForHumans();
  111. unset($v->created_at);
  112. }
  113. return $result;
  114. }
  115. }