ComplaintController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace App\Http\Controllers\Miniprogram;
  3. use App\Models\Deed\DeedModel;
  4. use App\Models\Deed\InvitationCardModel;
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\Controller;
  7. use App\Models\User\UserModel;
  8. use App\Models\ComplaintModel;
  9. class ComplaintController extends Controller
  10. {
  11. public function create(Request $request)
  12. {
  13. $this->validate($request, [
  14. 'title' => 'required|max:16',
  15. 'content' => 'required|max:200',
  16. 'images' => 'array',
  17. 'phone' => 'required|integer',
  18. 'type' => 'required|in:partner,user,pair,contract,game,goodnight,contact,question',
  19. 'value' => 'required',
  20. ]);
  21. $uid = Auth::auth();
  22. $data = $request->all();
  23. $search = [];
  24. $user = UserModel::find($uid);
  25. $be_uid = 0;
  26. try {
  27. switch ($request->type) {
  28. case 'partner':
  29. $partner = \App\Models\PartnerModel::find($request->value);
  30. $be_uid = $partner->uid;
  31. break;
  32. case "contract":
  33. $deed = DeedModel::find($request->value);
  34. $be_uid = $deed->uid;
  35. switch ($deed->type) {
  36. case "0":
  37. $data['type'] = "contact";
  38. break;
  39. case "1":
  40. $data['type'] = "pair";
  41. break;
  42. case "2":
  43. case "3":
  44. $data['type'] = "game";
  45. break;
  46. case "4":
  47. $data['type'] = "goodnight";
  48. break;
  49. }
  50. break;
  51. case "contact":
  52. $contact = InvitationCardModel::findOrFail($request->value);
  53. if ($contact->uid == $uid) {
  54. $be_uid = $contact->invite_uid;
  55. } else {
  56. $be_uid = $contact->uid;
  57. }
  58. break;
  59. case "pair":
  60. $pair = \App\Models\Fpdx\PairModel::findOrFail($request->value);
  61. $be_uid = $pair->uid;
  62. $data['value'] = $pair->id;
  63. break;
  64. case "game":
  65. $game = \App\Models\Gteam\EnterModel::findOrFail($request->value);
  66. $be_uid = $game->uid;
  67. $data['value'] = $game->id;
  68. break;
  69. case "goodnight":
  70. $goodnight = \App\Models\Goodnight\EnterModel::findOrFail($request->value);
  71. ;
  72. $be_uid = $goodnight->uid;
  73. $data['value'] = $goodnight->id;
  74. break;
  75. case "question":
  76. $question = \App\Models\User\LikeInviteQuestionModel::find($request->value);
  77. $be_uid = $question->uid;
  78. $data['value'] = $question->id;
  79. break;
  80. }
  81. $be_user = UserModel::findOrFail($be_uid);
  82. // 添加搜索关键字
  83. array_push($search, $request->phone);
  84. array_push($search, $user->nickname);
  85. array_push($search, $user->uid);
  86. array_push($search, $user->phone);
  87. if ($be_user) {
  88. array_push($search, $be_user->nickname);
  89. array_push($search, $be_user->uid);
  90. array_push($search, $be_user->phone);
  91. }
  92. $data['uid'] = $uid;
  93. $data['be_uid'] = $be_uid;
  94. $data['search'] = $search;
  95. ComplaintModel::create($data);
  96. } catch (\Exception $e) {
  97. app('sentry')->captureException($e);
  98. }
  99. return ['code' => 200, 'message' => 'OK'];
  100. }
  101. public function show(Request $request)
  102. {
  103. $this->validate($request, [
  104. 'type' => 'in:partner,user,pair,contract,question',
  105. 'value' => 'required',
  106. ]);
  107. $uid = Auth::auth();
  108. $type = $request->input('type', 'contract');
  109. $value = $request->value;
  110. $builder = ComplaintModel::select('id', 'content', 'images', 'reply_content', 'reply_at', 'title')
  111. ->where(['uid' => $uid, 'value' => $value]);
  112. switch ($type) {
  113. case "contract":
  114. $complaint = $builder->whereIn(
  115. 'type',
  116. ['deed_contact', 'deed_goodnight', 'deed_fpdx', 'deed_gteam']
  117. )->first();
  118. break;
  119. case "partner":
  120. $complaint = $builder->where('type', $type)->first();
  121. break;
  122. default:
  123. $complaint = $builder->where('type', $type)->first();
  124. }
  125. return response()->json([
  126. 'code' => 200,
  127. 'message' => 'OK',
  128. 'data' => $complaint
  129. ]);
  130. }
  131. }