FeedbackController.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace app\admin\controller\client;
  3. use app\admin\service\member\MemberService;
  4. use app\controller\Curd;
  5. use app\model\ClientContent;
  6. use app\model\MemberRole;
  7. use support\Request;
  8. use support\Response;
  9. class FeedbackController extends Curd
  10. {
  11. public function __construct()
  12. {
  13. $this->model = new ClientContent();
  14. }
  15. public function select(Request $request): Response
  16. {
  17. $searchTimes = $request->get('client_content_addtimes', []);
  18. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  19. $order = $request->get('order', 'desc');
  20. $field = $field ?? 'client_content_addtimes';
  21. $where['client_content_page'] = 'FEEDBACK';
  22. if (!empty($searchTimes)) {
  23. $searchTimes[0] = !empty($searchTimes[0]) ? strtotime($searchTimes[0]) : time();
  24. $searchTimes[1] = !empty($searchTimes[1]) ? strtotime($searchTimes[1]) : time();
  25. $where['client_content_addtimes'] = $searchTimes;
  26. }
  27. $query = $this->doSelect($where, $field, $order);
  28. return $this->doFormat($query, $format, $limit);
  29. }
  30. protected function doSelect(array $where, string $field = null, string $order = 'desc')
  31. {
  32. $model = $this->model->with([
  33. 'member' => function ($query) {
  34. $query->select('member_id', 'member_mobile');
  35. },
  36. 'cert' => function ($query) {
  37. $query->select('join_cert_member_id', 'member_cert_name');
  38. },
  39. 'info' => function ($query) {
  40. $query->select('join_info_member_id', 'member_info_nickname');
  41. }
  42. ]);
  43. foreach ($where as $column => $value) {
  44. if (is_array($value)) {
  45. if ($value[0] === 'like' || $value[0] === 'not like') {
  46. $model = $model->where($column, $value[0], "%$value[1]%");
  47. } elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
  48. $model = $model->where($column, $value[0], $value[1]);
  49. } elseif ($value[0] == 'in' && !empty($value[1])) {
  50. $valArr = $value[1];
  51. if (is_string($value[1])) {
  52. $valArr = explode(",", trim($value[1]));
  53. }
  54. $model = $model->whereIn($column, $valArr);
  55. } elseif ($value[0] == 'not in' && !empty($value[1])) {
  56. $valArr = $value[1];
  57. if (is_string($value[1])) {
  58. $valArr = explode(",", trim($value[1]));
  59. }
  60. $model = $model->whereNotIn($column, $valArr);
  61. } elseif ($value[0] == 'null') {
  62. $model = $model->whereNull($column);
  63. } elseif ($value[0] == 'not null') {
  64. $model = $model->whereNotNull($column);
  65. } elseif ($value[0] !== '' || $value[1] !== '') {
  66. $model = $model->whereBetween($column, $value);
  67. }
  68. } else {
  69. $model = $model->where($column, $value);
  70. }
  71. }
  72. if ($field) {
  73. $model = $model->orderBy($field, $order);
  74. }
  75. return $model;
  76. }
  77. public function afterQuery($items)
  78. {
  79. foreach ($items as &$item) {
  80. $mobile = !empty($item['member']) && !empty($item['member']['member_mobile']) ? $item['member']['member_mobile'] : '';
  81. $certName = !empty($item['cert']) && !empty($item['cert']['member_cert_name']) ? $item['cert']['member_cert_name'] : '';
  82. $nickname = !empty($item['info']) && !empty($item['info']['member_info_nickname']) ? $item['info']['member_info_nickname'] : '';
  83. $item['member_name'] = MemberService::getMemberName($mobile, $certName, $nickname);
  84. if (!empty($item['client_content_extend_json'])) {
  85. $clientContentExtendJson = json_decode($item['client_content_extend_json'], true);
  86. if (isset($clientContentExtendJson['feedback'])) {
  87. $item['feedback_content'] = mb_strlen($clientContentExtendJson['feedback']) > 30 ? mb_substr($clientContentExtendJson['feedback'], 0, 30) . '...' : $clientContentExtendJson['feedback'];
  88. }
  89. }
  90. unset($item['member'], $item['info'], $item['cert']);
  91. }
  92. return $items;
  93. }
  94. public function info(Request $request): Response
  95. {
  96. $feedbackId = $request->get('feedback_id');
  97. if (!$feedbackId) {
  98. return json_fail('参数异常');
  99. }
  100. $feedback = ClientContent::with([
  101. 'member' => function ($query) {
  102. $query->select('member_id', 'member_mobile', 'join_member_role_id', 'member_is_owner', 'member_is_vip', 'member_is_partner', 'member_is_referrer');
  103. },
  104. 'cert' => function ($query) {
  105. $query->select('join_cert_member_id', 'member_cert_name');
  106. },
  107. 'info' => function ($query) {
  108. $query->select('join_info_member_id', 'member_info_nickname', 'member_info_headimg');
  109. }
  110. ])->where('client_content_id', $feedbackId)
  111. ->first();
  112. if (empty($feedback)) {
  113. return json_success('');
  114. }
  115. $feedback = $feedback->toArray();
  116. $feedback['member']['member_mobile'] = !empty($feedback['member']) && !empty($feedback['member']['member_mobile']) ? $feedback['member']['member_mobile'] : '';
  117. $feedback['cert']['member_cert_name'] = !empty($feedback['cert']) && !empty($feedback['cert']['member_cert_name']) ? $feedback['cert']['member_cert_name'] : '';
  118. $feedback['info']['member_info_nickname'] = MemberService::getNickname(!empty($feedback['info']) ? $feedback['info']['member_info_nickname'] : '', $feedback['member']['member_mobile']);
  119. if (!empty($feedback['client_content_extend_json'])) {
  120. $clientContentExtendJson = json_decode($feedback['client_content_extend_json'], true);
  121. $feedback['feedback_content'] = $clientContentExtendJson['feedback'] ?? '';
  122. }
  123. if (!empty($feedback['member']) && !empty($feedback['member']['join_member_role_id'])) {
  124. $feedback['role_name'] = MemberRole::where('member_role_id', $feedback['member']['join_member_role_id'])->value('member_role_name');
  125. }
  126. return json_success('success', $feedback);
  127. }
  128. }