VoiceInvite.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Http\Controllers\Gnight;
  3. use App\Exceptions\AlertException;
  4. use App\Http\Controllers\Controller;
  5. use App\Http\Controllers\Miniprogram\Auth;
  6. use App\Models\Gnight\UserModel;
  7. use App\Models\Gnight\VoiceInviteModel;
  8. class VoiceInvite extends Controller
  9. {
  10. /**
  11. * @param int $share_uid
  12. * @return array
  13. * @throws AlertException
  14. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  15. * @api {get} /api/gnight/voiceinvite/check 分享邀请
  16. * @apiName check
  17. * @apiGroup Gnight
  18. *
  19. * @apiParam {int} $share_uid 分享链接id
  20. *
  21. */
  22. public function check($share_uid)
  23. {
  24. $uid = Auth::auth();
  25. $user = UserModel::findOrFail($share_uid);
  26. if (
  27. VoiceInviteModel::where([
  28. ['uid', $share_uid],
  29. ['invite_uid', $uid]
  30. ])->exists()
  31. ) {
  32. throw new AlertException("你已为TA助力", 102);
  33. }
  34. \DB::beginTransaction();
  35. try {
  36. \DB::table('kdgx_gnight_voice_invite')->insert([
  37. 'created_at' => time(),
  38. 'uid' => $share_uid,
  39. 'invite_uid' => $uid
  40. ]);
  41. $voice_id = Voice::pop($share_uid);
  42. \DB::table('kdgx_gnight_get_voice')->insert([
  43. 'created_at' => time(),
  44. 'uid' => $share_uid,
  45. 'get_uid' => $voice_id
  46. ]);
  47. \DB::commit();
  48. $notive = new Notive();
  49. $notive->getVoice($share_uid);
  50. return array(
  51. 'code' => 200,
  52. 'message' => 'success'
  53. );
  54. } catch (\Exception $e) {
  55. \DB::rollBack();
  56. throw $e;
  57. }
  58. }
  59. }