GnightController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Models\Goodnight\TopicExampleModel;
  4. use App\Models\Goodnight\TopicModel;
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\Controller;
  7. use App\Models\Gnight\UserModel;
  8. class GnightController extends Controller
  9. {
  10. /**
  11. * 获取正在审核的语音
  12. * @param Request $request
  13. * @return array
  14. */
  15. public function getCheckings(Request $request)
  16. {
  17. $page = $request->get('page') ?? 1;
  18. $count = UserModel::where('voice_state', 2)->count();
  19. $boy = UserModel::where('voice_state', 1)->where('sex', 1)->count();
  20. $girl = UserModel::where('voice_state', 1)->where('sex', 2)->count();
  21. $boy_all = UserModel::where('sex', 1)->count();
  22. $girl_all = UserModel::where('sex', 2)->count();
  23. $all = UserModel::where('sex', 0)->count();
  24. $voices = UserModel::where('voice_state', 2)->skip($page - 1)->take(500)->get();
  25. return response([
  26. 'code' => 200,
  27. 'message' => 'success',
  28. 'data' => [
  29. 'count' => $count,
  30. 'boy' => $boy,
  31. 'girl' => $girl,
  32. 'boy_all' => $boy_all,
  33. 'girl_all' => $girl_all,
  34. 'all' => $all,
  35. 'limit' => 500,
  36. 'voice' => $voices
  37. ]
  38. ]);
  39. }
  40. public function changeState(int $uid, Request $request)
  41. {
  42. $user = UserModel::findOrFail($uid);
  43. $user->voice_state = $request->input('voice_state');
  44. $user->save();
  45. return response([
  46. 'code' => 200,
  47. 'message' => 'success'
  48. ]);
  49. }
  50. public function topics(Request $request)
  51. {
  52. $topics = TopicModel::when($request->filled("show"), function ($query) use ($request) {
  53. return $query->where("show", 1);
  54. })->get();
  55. foreach ($topics as $topic) {
  56. $topic->examples = TopicExampleModel::select("id", "content", "show")->where('topic_id', $topic->id)
  57. ->when($request->filled("show"), function ($query) use ($request) {
  58. return $query->where("show", 1);
  59. })->get();
  60. }
  61. return response([
  62. 'code' => 200,
  63. 'message' => 'OK',
  64. 'data' => $topics
  65. ]);
  66. }
  67. public function createTopic(Request $request)
  68. {
  69. $topic = TopicModel::create($request->all());
  70. return response([
  71. "code" => 200,
  72. "message" => "OK",
  73. "data" => $topic
  74. ]);
  75. }
  76. public function updateTopic(Request $request, int $id)
  77. {
  78. $topic = TopicModel::findOrFail($id);
  79. $topic->update($request->all());
  80. return response([
  81. "code" => 200,
  82. "message" => "OK"
  83. ]);
  84. }
  85. public function createTopicExample(Request $request)
  86. {
  87. $topicExample = TopicExampleModel::create($request->all());
  88. return response([
  89. "code" => 200,
  90. "message" => "OK",
  91. "data" => $topicExample
  92. ]);
  93. }
  94. public function updateTopicExample(Request $request, int $id)
  95. {
  96. $topicExample = TopicExampleModel::find($id);
  97. $topicExample->update($request->all());
  98. return response([
  99. "code" => 200,
  100. "message" => "OK"
  101. ]);
  102. }
  103. }