ShareService.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace App\Http\Services\V1_1;
  3. use App\Exceptions\AlertException;
  4. use App\Generated\V1_1\Messages\Share\PairApplyListShareHelpMessage;
  5. use App\Generated\V1_1\Messages\Share\PairVipCheckMessage;
  6. use App\Generated\V1_1\Messages\Share\PairGetMessage;
  7. use App\Managers\LikeManager;
  8. use App\Managers\SharePairManager;
  9. use App\Http\Controllers\Core\Auth;
  10. use App\Generated\V1_1\Messages\Share\LikeMeMessage;
  11. use App\Generated\V1_1\Messages\Share\LikeMeCheckMessage;
  12. use App\Generated\V1_1\Messages\Share\LikeMeHistoryMessage;
  13. use App\Models\Fpdx\ActivityModel;
  14. use App\Models\Fpdx\PairModel;
  15. use App\Models\Share\PairApplyListShareHelpLog;
  16. class ShareService
  17. {
  18. protected $sharePairManager;
  19. protected $likeManager;
  20. public function __construct(SharePairManager $sharePairManager, LikeManager $likeManager)
  21. {
  22. $this->sharePairManager = $sharePairManager;
  23. $this->likeManager = $likeManager;
  24. }
  25. public function pairVipCheck(PairVipCheckMessage $message)
  26. {
  27. $inviteId = $message->getInviteId();
  28. $uid = Auth::auth();
  29. $data = $this->sharePairManager->vipCheck($uid, $inviteId);
  30. $message->setResponse($data);
  31. }
  32. public function pairGet(PairGetMessage $message)
  33. {
  34. $listId = $message->getListId();
  35. $data = $this->sharePairManager->get($listId);
  36. $message->setResponse($data);
  37. }
  38. public function likeMe(LikeMeMessage $message)
  39. {
  40. $praiseId = $message->getPraiseId();
  41. $data = $this->likeManager->get($praiseId);
  42. $message->setResponse($data);
  43. }
  44. public function likeMeCheck(LikeMeCheckMessage $message)
  45. {
  46. $praiseId = $message->getPraiseId();
  47. $uid = Auth::auth();
  48. $data = $this->likeManager->check($uid, $praiseId);
  49. $message->setResponse($data);
  50. }
  51. public function likeMeHistory(LikeMeHistoryMessage $message)
  52. {
  53. $praiseId = $message->getPraiseId();
  54. $data = $this->likeManager->history($praiseId);
  55. $message->setResponse($data);
  56. }
  57. public function pairApplyListShareHelp(PairApplyListShareHelpMessage $message)
  58. {
  59. $uid = Auth::auth();
  60. $stageId = $message->getStageId();
  61. $shareUid = $message->getShareUid();
  62. $lockUid = $message->getLockUid();
  63. $activity = ActivityModel::enrolling()->first();
  64. if (
  65. !$activity || $activity->stage_id != $stageId
  66. ) {
  67. throw new AlertException("活动报名已结束,分享已过期");
  68. }
  69. if (
  70. !$sharePair = PairModel::where([
  71. array('stage_id', $stageId), array('uid', $shareUid)
  72. ])->first()
  73. ) {
  74. throw new AlertException("分享者取消报名,分享失效");
  75. }
  76. if (
  77. !$sharePair = PairModel::where([
  78. array('stage_id', $stageId), array('uid', $lockUid)
  79. ])->first()
  80. ) {
  81. throw new AlertException("解锁者取消报名,分享失效");
  82. }
  83. if (
  84. PairApplyListShareHelpLog::where([
  85. array('help_uid', $uid), array('share_uid', $shareUid), array('created_at', '>', mkdir(0, 0, 0))
  86. ])->exists()
  87. ) {
  88. throw new AlertException("一天只可帮一个人助力一次");
  89. }
  90. if (
  91. PairApplyListShareHelpLog::where([
  92. array('help_uid', $uid), array('share_uid', $shareUid), array('lock_uid', $lockUid), array('stage_id', $stageId)
  93. ])->exists()
  94. ) {
  95. throw new AlertException("你已经帮他助力了");
  96. }
  97. PairApplyListShareHelpLog::create([
  98. 'created_at' => time(),
  99. 'share_uid' => $shareUid,
  100. 'lock_uid' => $lockUid,
  101. 'stage_id' => $stageId,
  102. 'help_uid' => $uid
  103. ]);
  104. }
  105. }