PartnerManager.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace App\Managers;
  3. use App\Models\BuyInviteListModel;
  4. use App\Models\BuyInviteModel;
  5. use App\Models\Deed\FriendsModel;
  6. use App\Models\Deed\InvitationCardModel;
  7. use App\Models\PartnerModel;
  8. use App\Models\PraiseModel;
  9. use App\Models\TagModel;
  10. use App\Models\User\FeedType4RemindModel;
  11. use App\Models\User\InviteConfigModel;
  12. use App\Models\User\SuperLikeModel;
  13. use App\Models\User\UserModel;
  14. class PartnerManager
  15. {
  16. public function partnerUser(int $uid, PartnerModel $partner)
  17. {
  18. if ($partner->photo_src && !str_contains($partner->photo_src, 'http')) {
  19. $partner->photo_src = "https://oss.pocketuniversity.cn" . $partner->photo_src;
  20. }
  21. if ($partner->photo_1 && !str_contains($partner->photo_1, 'http')) {
  22. $partner->photo_1 = "https://oss.pocketuniversity.cn" . $partner->photo_1;
  23. }
  24. if ($partner->photo_2 && !str_contains($partner->photo_2, 'http')) {
  25. $partner->photo_2 = "https://oss.pocketuniversity.cn" . $partner->photo_2;
  26. }
  27. if ($partner->photo_3 && !str_contains($partner->photo_3, 'http')) {
  28. $partner->photo_3 = "https://oss.pocketuniversity.cn" . $partner->photo_3;
  29. }
  30. if ($partner->photo_4 && !str_contains($partner->photo_4, 'http')) {
  31. $partner->photo_4 = "https://oss.pocketuniversity.cn" . $partner->photo_4;
  32. }
  33. $partner->black_at = $partner->black_at < time() ? 0 : $partner->black_at;
  34. /** @var UserModel $user */
  35. $user = UserModel::findOrfail($partner->uid, [
  36. 'uid',
  37. 'headimgurl',
  38. 'nickname',
  39. 'age',
  40. 'star',
  41. 'last_life',
  42. 'why',
  43. 'pair_voice',
  44. 'identity_auth',
  45. 'wx_auth',
  46. 'qq',
  47. 'weixin',
  48. 'photo_src',
  49. 'photo_1',
  50. 'photo_2',
  51. 'photo_3',
  52. 'photo_4',
  53. 'introduce',
  54. 'expect',
  55. 'height',
  56. 'sex',
  57. 'school',
  58. 'address',
  59. 'home',
  60. 'tag_1',
  61. 'tag_2',
  62. 'tag_3',
  63. 'tag_4',
  64. 'login_at',
  65. 'claim_tag',
  66. 'work_state',
  67. 'be_vip_at',
  68. 'supvip_endat',
  69. 'logoff_at',
  70. 'bgcolor'
  71. ]);
  72. // 标签处理
  73. $tagModel = new TagModel();
  74. $user->tags = $tagModel->getAllTagByUser($user);
  75. if ($inviteConf = InviteConfigModel::find($partner->uid)) {
  76. $user->task_photo = $inviteConf->task_photo;
  77. $user->task_question = $inviteConf->task_question;
  78. $user->task_sing = $inviteConf->task_sing;
  79. $user->task_question_data = $inviteConf->task_question_data ? true : false;
  80. $user->task_sing_data = $inviteConf->task_sing_data ? true : false;
  81. } else {
  82. $user->task_photo = false;
  83. $user->task_question = false;
  84. $user->task_sing = false;
  85. $user->task_question_data = false;
  86. $user->task_sing_data = false;
  87. }
  88. $user->invite_cnt = InvitationCardModel::where('invite_uid', $user->uid)->count();
  89. $partner->headimgurl = $user->headimgurl;
  90. $partner->nickname = $user->nickname;
  91. if ($uid != $partner->uid) {
  92. if (1 != $partner->check_photo) {
  93. unset($partner->photo_src);
  94. }
  95. if (1 != $partner->photo_1_check) {
  96. unset($partner->photo_1);
  97. }
  98. if (1 != $partner->photo_2_check) {
  99. unset($partner->photo_2);
  100. }
  101. if (1 != $partner->photo_3_check) {
  102. unset($partner->photo_3);
  103. }
  104. if (1 != $partner->photo_4_check) {
  105. unset($partner->photo_4);
  106. }
  107. if (1 != $partner->voice_check) {
  108. unset($partner->voice);
  109. }
  110. unset($partner->check_photo);
  111. unset($partner->photo_1_check);
  112. unset($partner->photo_2_check);
  113. unset($partner->photo_3_check);
  114. unset($partner->photo_4_check);
  115. unset($partner->voice_check);
  116. unset($partner->check_contact);
  117. unset($partner->qq);
  118. unset($partner->weixin);
  119. // 与self的关系处理
  120. $self = array(
  121. 'friend' => false,
  122. 'praise' => false,
  123. 'invite' => [],
  124. 'superlike' => false,
  125. 'is_remind' => FeedType4RemindModel::where([
  126. ['uid', $uid],
  127. ['is_remind_uid', $partner->uid],
  128. ['type', 1]
  129. ])->exists()
  130. );
  131. $friend = FriendsModel::where([['uid', $uid], ['friend_uid', $partner->uid], ['is_friend', 1]])->exists();
  132. if (!$friend) {
  133. !empty($user->weixin) && $user->weixin = substr($user->weixin, 0, 1) . "****" . substr(
  134. $user->weixin,
  135. -1,
  136. 1
  137. );
  138. !empty($user->qq) && $user->qq = substr($user->qq, 0, 1) . "****" . substr($user->qq, -1, 1);
  139. }
  140. $self['friend'] = $friend;
  141. if (PraiseModel::where([['uid', $uid], ['partner_id', $partner->id], ['type', 1]])->exists()) {
  142. $self['praise'] = true;
  143. }
  144. $invite = InvitationCardModel::where([
  145. ['uid', $uid],
  146. ['invite_uid', $partner->uid],
  147. ['expired_at', '>', time()]
  148. ])->groupBy('question_type')->get(['question_type'])->pluck('question_type');
  149. $self['invite'] = $invite->toArray();
  150. if (SuperLikeModel::where([['uid', $uid], ['partner_id', $partner->id]])->exists()) {
  151. $self['superlike'] = true;
  152. }
  153. $partner->self = $self;
  154. } else {
  155. $self = array(
  156. 'friend' => false,
  157. 'praise' => false,
  158. 'invite' => [],
  159. 'superlike' => false,
  160. 'is_remind' => false
  161. );
  162. $partner->self = $self;
  163. }
  164. $partner->setAttribute('user', $user);
  165. $praise = PraiseModel::where([['partner_id', $partner->id], ['uid', $uid]])->first();
  166. $partner->praise = isset($praise->type) ? $praise->type : 0;
  167. $buyInviteListModel = new BuyInviteListModel();
  168. $inviteList = $buyInviteListModel->where([['partner_id', $partner->id], ['uid', $uid]])->first();
  169. if (!collect($inviteList)->isEmpty()) {
  170. $partner->invite_id = $inviteList->id;
  171. $buyInviteModel = new BuyInviteModel();
  172. $partner->invite_percent = $buyInviteModel->effectiveInvite($uid, $partner->id);
  173. }
  174. return $partner;
  175. }
  176. }