NoticeController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Http\Controllers\Fpdx;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Redis;
  5. use App\Http\Controllers\Controller;
  6. use App\Http\Controllers\Core\Auth;
  7. class NoticeController extends Controller
  8. {
  9. /**
  10. * 获取发送状态
  11. * @param Request $request
  12. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  13. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  14. */
  15. public function getSendState(Request $request)
  16. {
  17. $this->validate($request, [
  18. 'room_id' => 'required',
  19. 'type' => 'required'
  20. ]);
  21. $uid = Auth::auth();
  22. $type = $request->input('type', 'sms');
  23. $bel = Redis::get("send_{$type}_{$uid}_{$request->room_id}");
  24. if (empty($bel)) {
  25. return response([
  26. 'code' => 200,
  27. 'message' => '可发送'
  28. ]);
  29. } else {
  30. return response([
  31. 'code' => 501,
  32. 'message' => '超过限制'
  33. ]);
  34. }
  35. }
  36. /**
  37. * 发送通知消息
  38. * @param Request $request
  39. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  40. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  41. */
  42. public function sendNotive(Request $request)
  43. {
  44. $this->validate($request, [
  45. 'room_id' => 'required',
  46. 'pair_uid' => 'required',
  47. 'type' => 'required'
  48. ]);
  49. $uid = Auth::auth();
  50. $type = $request->input('type', 'sms');
  51. $room_id = $request->input('room_id');
  52. $bel = Redis::get("send_{$type}_{$uid}_{$room_id}");
  53. if (empty($bel)) {
  54. Redis::setex("send_{$type}_{$uid}_{$room_id}", mktime(0, 0, 0) + 86400 - time(), time());
  55. return response(['code' => 200, 'message' => 'success']);
  56. } else {
  57. return response(['code' => 501, 'message' => '超过限制']);
  58. }
  59. }
  60. }