LikeInviteQuestionController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. namespace App\Http\Controllers\User;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Controllers\Core\Auth;
  5. use App\Models\User\InviteConfigModel;
  6. use App\Services\User\LikeInviteQuestionService;
  7. use Illuminate\Http\Request;
  8. class LikeInviteQuestionController extends Controller
  9. {
  10. /**
  11. * 我的录制->问题列表
  12. * @param Request $request
  13. * @return array
  14. * @throws \App\Exceptions\VersionException
  15. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  16. */
  17. public function createQuestion(Request $request)
  18. {
  19. $low_version = $latest_version = "2.11.10";
  20. version($request->header('version', '0.00.01'), $low_version, $latest_version);
  21. $uid = Auth::auth();
  22. $this->validate($request, [
  23. 'question' => 'required',
  24. 'voice_src' => 'required',
  25. 'template_id' => 'required',
  26. 'question_type' => 'required'
  27. ]);
  28. $liqs = new LikeInviteQuestionService();
  29. $id = $liqs->createQuestion($uid, $request->toArray());
  30. return response([
  31. 'code' => 200,
  32. 'message' => 'success',
  33. 'data' => [
  34. 'id' => $id
  35. ]
  36. ]);
  37. }
  38. /**
  39. * 回答心动考验->换题列表
  40. * @param Request $request
  41. * @return array
  42. * @throws \App\Exceptions\VersionException
  43. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  44. */
  45. public function questionList(Request $request)
  46. {
  47. $low_version = $latest_version = "2.11.10";
  48. version($request->header('version', '0.00.01'), $low_version, $latest_version);
  49. Auth::auth();
  50. $this->validate($request, [
  51. 'user_id' => 'required|integer',
  52. 'question_type' => 'required|in:0,1'
  53. ]);
  54. $user_id = $request->post('user_id');
  55. $question_type = $request->post('question_type', 0);
  56. $liqs = new LikeInviteQuestionService();
  57. $data = $liqs->questionList($user_id, $question_type);
  58. return response([
  59. 'code' => 200,
  60. 'message' => 'success',
  61. 'data' => $data
  62. ]);
  63. }
  64. /**
  65. * 我的录制->问题列表
  66. * @param Request $request
  67. * @return array
  68. * @throws \App\Exceptions\VersionException
  69. */
  70. public function list(Request $request)
  71. {
  72. $low_version = $latest_version = "2.11.10";
  73. version($request->header('version', '0.00.01'), $low_version, $latest_version);
  74. $uid = Auth::auth();
  75. $type = $request->get('type', 0);
  76. $page = $request->get('page', 1);
  77. $pages = array(
  78. 'page' => $request->get('page') ?? 1,
  79. 'limit' => 10
  80. );
  81. $liqs = new LikeInviteQuestionService();
  82. $data = $liqs->list($uid, $type, $pages);
  83. return response([
  84. 'code' => 200,
  85. 'message' => 'success',
  86. 'data' => $data
  87. ]);
  88. }
  89. /**
  90. * 我的录制->删除问题
  91. * @param int $question_id
  92. * @param Request $request
  93. * @return array
  94. * @throws \App\Exceptions\AlertException
  95. * @throws \App\Exceptions\VersionException
  96. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  97. */
  98. public function deleteQuestion(int $question_id, Request $request)
  99. {
  100. $low_version = $latest_version = "2.11.10";
  101. version($request->header('version', '0.00.01'), $low_version, $latest_version);
  102. $uid = Auth::auth();
  103. $liqs = new LikeInviteQuestionService();
  104. $liqs->deleteQuestion($uid, $question_id);
  105. return response([
  106. 'code' => 200,
  107. 'message' => 'success'
  108. ]);
  109. }
  110. /**
  111. * 心动考验开关
  112. * @param Request $request
  113. * @return array
  114. * @throws \App\Exceptions\AlertException
  115. * @throws \App\Exceptions\VersionException
  116. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  117. * @deprecated 2.17.0 以上版本弃用
  118. * @version 2.17.0
  119. */
  120. public function likeInviteQuestionSwitch(Request $request)
  121. {
  122. $low_version = $latest_version = "2.17.0";
  123. version($request->header('version', '0.00.01'), $low_version, $latest_version);
  124. $uid = Auth::auth();
  125. $this->validate($request, [
  126. 'task_type' => "required|in:task_photo,task_question,task_sing",
  127. 'switch' => "required|in:0,1"
  128. ]);
  129. $task_type = $request->post('task_type');
  130. $switch = $request->post('switch');
  131. $liqs = new LikeInviteQuestionService();
  132. $liqs->likeInviteQuestionSwitch($uid, $task_type, $switch);
  133. return response([
  134. 'code' => 200,
  135. 'message' => 'success'
  136. ]);
  137. }
  138. /**
  139. * 心动考验页的取消喜欢|喜欢 某人
  140. * @param int $question_id
  141. * @param Request $request
  142. * @return array
  143. * @throws \App\Exceptions\AlertException
  144. * @throws \App\Exceptions\VersionException
  145. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  146. * @version 2.11.10
  147. */
  148. public function thumbQuestion(int $question_id, Request $request)
  149. {
  150. $low_version = $latest_version = "2.11.10";
  151. version($request->header('version', '0.00.01'), $low_version, $latest_version);
  152. $uid = Auth::auth();
  153. $liqs = new LikeInviteQuestionService();
  154. $data = $liqs->thumb($uid, $question_id);
  155. return response([
  156. 'code' => 200,
  157. 'message' => 'success',
  158. 'data' => $data
  159. ]);
  160. }
  161. /**
  162. * 设置邀请问题
  163. * @param Request $request
  164. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  165. */
  166. public function setInviteQuestion(Request $request)
  167. {
  168. $low_version = $latest_version = "2.17.0";
  169. version($request->header('version', '0.00.01'), $low_version, $latest_version);
  170. $uid = Auth::auth();
  171. $this->validate($request, [
  172. 'task_photo' => '',
  173. 'task_question' => '',
  174. 'task_sing' => '',
  175. 'task_paint' => '',
  176. 'task_question_data' => 'array',
  177. 'task_sing_data' => 'array',
  178. ]);
  179. $invite_config = InviteConfigModel::updateOrCreate(
  180. ['uid' => $uid],
  181. $request->all()
  182. );
  183. return response([
  184. 'code' => 200,
  185. 'message' => 'OK',
  186. 'data' => $invite_config
  187. ]);
  188. }
  189. /**
  190. * 获取邀请的问题
  191. * @param Request $request
  192. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  193. */
  194. public function getInviteQuestion(Request $request)
  195. {
  196. $low_version = $latest_version = "2.17.0";
  197. version($request->header('version', '0.00.01'), $low_version, $latest_version);
  198. $uid = Auth::auth();
  199. $invite_config = InviteConfigModel::firstOrCreate([
  200. 'uid' => $uid
  201. ]);
  202. return response([
  203. 'code' => 200,
  204. 'message' => 'OK',
  205. 'data' => $invite_config
  206. ]);
  207. }
  208. }