PairService.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. <?php
  2. namespace App\Http\Services\V1_1;
  3. use App\Generated\V1_1\Messages\Pair\EnrollByFreeMessage;
  4. use App\Generated\V1_1\Messages\Pair\EnrollByPaymentMessage;
  5. use App\Generated\V1_1\Messages\Pair\EnrollBySuperVipMessage;
  6. use App\Generated\V1_1\Messages\Pair\EnrollByEnergyMessage;
  7. use App\Generated\V1_1\Messages\Pair\EnrollByNextMessage;
  8. use App\Generated\V1_1\Messages\Pair\AddScoreBySuperVipMessage;
  9. use App\Generated\V1_1\Messages\Pair\GetRecommendPairApplyContactsMessage;
  10. use App\Generated\Exceptions\ConflictException;
  11. use App\Generated\Exceptions\ForbiddenException;
  12. use App\Generated\Exceptions\NotFoundException;
  13. use App\Generated\Exceptions\UnprocessableEntityException;
  14. use App\Generated\V1_1\Messages\Pair\AddScoreByOrderMessage;
  15. use App\Generated\V1_1\Messages\Pair\AddScoreByEnergyMessage;
  16. use App\Generated\V1_1\Messages\Pair\ActivityInfoMessage;
  17. use App\Generated\V1_1\Messages\Pair\ActivityLastMessage;
  18. use App\Generated\V1_1\Messages\Pair\ActivityRecentMessage;
  19. use App\Generated\V1_1\Messages\Pair\ConfirmBeAloneMessage;
  20. use App\Generated\V1_1\Messages\Pair\ConfirmCpMessage;
  21. use App\Generated\V1_1\Messages\Pair\GetActivityConductStageIdMessage;
  22. use App\Generated\V1_1\Messages\Pair\LastenrollMessage;
  23. use App\Generated\V1_1\Messages\Pair\GetActivityListMessage;
  24. use App\Generated\V1_1\Messages\Pair\GetAloneGroupMessage;
  25. use App\Generated\V1_1\Messages\Pair\RemoveKeepCpMessage;
  26. use App\Generated\V1_1\Messages\Pair\KeepCpMessage;
  27. use App\Generated\V1_1\Messages\Pair\GetKeepRoomMessage;
  28. use App\Generated\V1_1\Messages\Pair\GetAllTagsMessage;
  29. use App\Generated\V1_1\Messages\Pair\RefundMessage;
  30. use App\Generated\V1_1\Messages\Pair\OperationalLogMessage;
  31. use App\Generated\V1_1\Messages\Pair\RegretsMessage;
  32. use App\Generated\V1_1\Messages\Pair\UpdateMessage;
  33. use App\Generated\Exceptions\CustomErrorMessageException;
  34. use App\Http\Controllers\Core\Auth;
  35. use App\Managers\OrderManager;
  36. use App\Managers\PairManager;
  37. use App\Models\OrderModel;
  38. use App\Models\TagModel;
  39. use App\Models\Fpdx\ActivityModel;
  40. use App\Models\Fpdx\RoomModel;
  41. use App\Models\User\UserModel;
  42. use App\Models\Fpdx\GroupModel;
  43. use App\Models\Fpdx\PairModel;
  44. use App\Models\Fpdx\GroupMemberModel;
  45. use App\Models\Fpdx\OperationalLogModel;
  46. use Illuminate\Support\Facades\DB;
  47. use Illuminate\Database\Eloquent\ModelNotFoundException;
  48. use Tymon\JWTAuth\Exceptions\JWTException;
  49. class PairService
  50. {
  51. protected $pairManager;
  52. protected $orderManager;
  53. public function __construct(PairManager $pairManager, OrderManager $orderManager)
  54. {
  55. $this->pairManager = $pairManager;
  56. $this->orderManager = $orderManager;
  57. }
  58. /**
  59. * 付费报名
  60. * @param EnrollByPaymentMessage $message
  61. * @throws ConflictException
  62. * @throws CustomErrorMessageException
  63. * @throws NotFoundException
  64. * @throws UnprocessableEntityException
  65. * @throws \GuzzleHttp\Exception\GuzzleException
  66. */
  67. public function enrollByPayment(EnrollByPaymentMessage $message)
  68. {
  69. $stageId = $message->getStageId();
  70. $couponId = $message->getCouponId();
  71. $mediaId = $message->getMediaId() ?: config('miniprogram.public_id');
  72. $sex = $message->getSex();
  73. $sxo = $message->getSxo();
  74. $minAge = $message->getMinAge();
  75. $maxAge = $message->getMaxAge();
  76. $agent = $message->getRequest()->header('user-agent');
  77. $km = $message->getKm();
  78. $lng = $message->getLng();
  79. $lat = $message->getLat();
  80. $location = $message->getLocation();
  81. $device = 'other';
  82. if (strpos($agent, 'macintosh') || strpos($agent, 'iPod') || strpos($agent, 'iPhone') || strpos($agent, 'iPad')) {
  83. $device = "ios";
  84. }
  85. if (strpos($agent, 'Android')) {
  86. $device = 'android';
  87. }
  88. $uid = Auth::auth();
  89. if (!in_array($sex, [1, 2])) {
  90. throw new UnprocessableEntityException('请选择性别');
  91. }
  92. if (!in_array($sxo, [1, 2])) {
  93. throw new UnprocessableEntityException('请选择性取向');
  94. }
  95. $activity = ActivityModel::enrolling()->first();
  96. if (!$activity) {
  97. throw new NotFoundException("活动不存在");
  98. }
  99. if ($activity->stage_id !== $stageId) {
  100. throw new NotFoundException('活动报名已截止报名');
  101. }
  102. $pair = PairModel::where('uid', $uid)->where('stage_id', $stageId)->first();
  103. if ($pair) {
  104. throw new ConflictException("您已经报名本期活动,请勿重复报名哦");
  105. }
  106. if (isset($pair->order_id) && $pair->order_id > 0) {
  107. throw new CustomErrorMessageException('一次活动只能付费一次');
  108. }
  109. $state = 103;
  110. $score = 90;
  111. $attribute = ['state' => $state, $score => $score, 'uid' => $uid, 'stage_id' => $stageId, 'media_id' => $mediaId, 'sex' => $sex, 'sxo' => $sxo, 'min_age' => $minAge, 'max_age' => $maxAge, 'device' => $device, 'km' => $km, 'lng' => $lng, 'lat' => $lat, 'location' => $location];
  112. $orderId = $this->orderManager->unifyOrderByPair($uid, $attribute, $couponId);
  113. $message->setResponse(['order_id' => $orderId]);
  114. }
  115. /**
  116. * 免费报名
  117. * @param EnrollByFreeMessage $message
  118. * @throws ConflictException
  119. * @throws NotFoundException
  120. * @throws UnprocessableEntityException
  121. */
  122. public function enrollByFree(EnrollByFreeMessage $message)
  123. {
  124. $mediaId = $message->getMediaId() ?: config('miniprogram.public_id');
  125. $stageId = $message->getStageId();
  126. $sex = $message->getSex();
  127. $sxo = $message->getSxo();
  128. $minAge = $message->getMinAge();
  129. $maxAge = $message->getMaxAge();
  130. $km = $message->getKm();
  131. $lng = $message->getLng();
  132. $lat = $message->getLat();
  133. $location = $message->getLocation();
  134. $agent = $message->getRequest()->header('user-agent');
  135. $device = 'other';
  136. if (strpos($agent, 'macintosh') || strpos($agent, 'iPod') || strpos($agent, 'iPhone') || strpos($agent, 'iPad')) {
  137. $device = "ios";
  138. }
  139. if (strpos($agent, 'Android')) {
  140. $device = 'android';
  141. }
  142. $uid = Auth::auth();
  143. if (!in_array($sex, [1, 2])) {
  144. throw new UnprocessableEntityException('请选择性别');
  145. }
  146. if (!in_array($sxo, [1, 2])) {
  147. throw new UnprocessableEntityException('请选择性取向');
  148. }
  149. $activity = ActivityModel::enrolling()->first();
  150. if (!$activity) {
  151. throw new NotFoundException("活动不存在");
  152. }
  153. if ($activity->stage_id !== $stageId) {
  154. throw new NotFoundException('活动报名已截止报名');
  155. }
  156. $pair = PairModel::where('uid', $uid)->where('stage_id', $stageId)->first();
  157. if ($pair) {
  158. throw new ConflictException("您已经报名本期活动,请勿重复报名哦");
  159. }
  160. $state = $sex == 2 ? 103 : 3;
  161. $attribute = ['uid' => $uid, 'stage_id' => $stageId, 'media_id' => $mediaId, 'sex' => $sex, 'sxo' => $sxo, 'min_age' => $minAge, 'max_age' => $maxAge, 'data' => $device, 'device' => $device, 'state' => $state, 'km' => $km, 'lng' => $lng, 'lat' => $lat, 'location' => $location];
  162. $pair = PairModel::create($attribute);
  163. $message->setResponse($pair);
  164. }
  165. /**
  166. * 超级会员报名
  167. * @param EnrollBySuperVipMessage $message
  168. * @throws ConflictException
  169. * @throws CustomErrorMessageException
  170. * @throws NotFoundException
  171. * @throws UnprocessableEntityException
  172. */
  173. public function enrollBySuperVip(EnrollBySuperVipMessage $message)
  174. {
  175. $mediaId = $message->getMediaId() ?: config('miniprogram.public_id');
  176. $stageId = $message->getStageId();
  177. $sex = $message->getSex();
  178. $sxo = $message->getSxo();
  179. $minAge = $message->getMinAge();
  180. $maxAge = $message->getMaxAge();
  181. $km = $message->getKm();
  182. $lng = $message->getLng();
  183. $lat = $message->getLat();
  184. $location = $message->getLocation();
  185. $agent = $message->getRequest()->header('user-agent');
  186. $device = 'other';
  187. if (strpos($agent, 'macintosh') || strpos($agent, 'iPod') || strpos($agent, 'iPhone') || strpos($agent, 'iPad')) {
  188. $device = "ios";
  189. }
  190. if (strpos($agent, 'Android')) {
  191. $device = 'android';
  192. }
  193. $uid = Auth::auth();
  194. $user = UserModel::find($uid);
  195. if (!$user->is_super_vip) {
  196. throw new CustomErrorMessageException("您不是超级会员");
  197. }
  198. if (!in_array($sex, [1, 2])) {
  199. throw new UnprocessableEntityException('请选择性别');
  200. }
  201. if (!in_array($sxo, [1, 2])) {
  202. throw new UnprocessableEntityException('请选择性取向');
  203. }
  204. $activity = ActivityModel::enrolling()->first();
  205. if (!$activity) {
  206. throw new NotFoundException("活动不存在");
  207. }
  208. if ($activity->stage_id !== $stageId) {
  209. throw new NotFoundException('活动报名已截止报名');
  210. }
  211. $pair = PairModel::where('uid', $uid)->where('stage_id', $stageId)->first();
  212. if ($pair) {
  213. throw new ConflictException("您已经报名本期活动,请勿重复报名哦");
  214. }
  215. $state = 103;
  216. $score = 90;
  217. $attribute = ['state' => $state, $score => $score, 'uid' => $uid, 'stage_id' => $stageId, 'media_id' => $mediaId, 'sex' => $sex, 'sxo' => $sxo, 'min_age' => $minAge, 'max_age' => $maxAge, 'data' => $device, 'device' => $device, 'km' => $km, 'lng' => $lng, 'lat' => $lat, 'location' => $location];
  218. $pair = PairModel::create($attribute);
  219. $message->setResponse($pair);
  220. }
  221. /**
  222. * 使用能量报名
  223. * @param EnrollByEnergyMessage $message
  224. * @throws ConflictException
  225. * @throws NotFoundException
  226. * @throws UnprocessableEntityException
  227. */
  228. public function enrollByEnergy(EnrollByEnergyMessage $message)
  229. {
  230. $mediaId = $message->getMediaId() ?: config('miniprogram.public_id');
  231. $stageId = $message->getStageId();
  232. $sex = $message->getSex();
  233. $sxo = $message->getSxo();
  234. $minAge = $message->getMinAge();
  235. $maxAge = $message->getMaxAge();
  236. $km = $message->getKm();
  237. $lng = $message->getLng();
  238. $lat = $message->getLat();
  239. $location = $message->getLocation();
  240. $agent = $message->getRequest()->header('user-agent');
  241. $device = 'other';
  242. if (strpos($agent, 'macintosh') || strpos($agent, 'iPod') || strpos($agent, 'iPhone') || strpos($agent, 'iPad')) {
  243. $device = "ios";
  244. }
  245. if (strpos($agent, 'Android')) {
  246. $device = 'android';
  247. }
  248. $uid = Auth::auth();
  249. if (!in_array($sex, [1, 2])) {
  250. throw new UnprocessableEntityException('请选择性别');
  251. }
  252. if (!in_array($sxo, [1, 2])) {
  253. throw new UnprocessableEntityException('请选择性取向');
  254. }
  255. $activity = ActivityModel::enrolling()->first();
  256. if (!$activity) {
  257. throw new NotFoundException("活动不存在");
  258. }
  259. if ($activity->stage_id !== $stageId) {
  260. throw new NotFoundException('活动报名已截止报名');
  261. }
  262. $pair = PairModel::where('uid', $uid)->where('stage_id', $stageId)->first();
  263. if ($pair) {
  264. throw new ConflictException("您已经报名本期活动,请勿重复报名哦");
  265. }
  266. $user = UserModel::find($uid);
  267. $state = 103;
  268. $score = $user->pair_energy;
  269. $user->pair_energy = 0;
  270. $user->save();
  271. $attribute = ['uid' => $uid, 'stage_id' => $stageId, 'media_id' => $mediaId, 'sex' => $sex, 'sxo' => $sxo, 'min_age' => $minAge, 'max_age' => $maxAge, 'data' => $device, 'device' => $device, 'state' => $state, $score => $score, 'lng' => $lng, 'lat' => $lat, 'location' => $location];
  272. $pair = PairModel::create($attribute);
  273. $message->setResponse($pair);
  274. }
  275. /**
  276. * 报名下一期
  277. * @param EnrollByNextMessage $message
  278. * @throws ConflictException
  279. * @throws CustomErrorMessageException
  280. * @throws ForbiddenException
  281. * @throws NotFoundException
  282. * @throws UnprocessableEntityException
  283. */
  284. public function enrollByNext(EnrollByNextMessage $message)
  285. {
  286. $pairId = $message->getPairId();
  287. $mediaId = $message->getMediaId() ?: config('miniprogram.public_id');
  288. $stageId = $message->getStageId();
  289. $sex = $message->getSex();
  290. $sxo = $message->getSxo();
  291. $minAge = $message->getMinAge();
  292. $maxAge = $message->getMaxAge();
  293. $km = $message->getKm();
  294. $lng = $message->getLng();
  295. $lat = $message->getLat();
  296. $location = $message->getLocation();
  297. $agent = $message->getRequest()->header('user-agent');
  298. $device = 'other';
  299. if (strpos($agent, 'macintosh') || strpos($agent, 'iPod') || strpos($agent, 'iPhone') || strpos($agent, 'iPad')) {
  300. $device = "ios";
  301. }
  302. if (strpos($agent, 'Android')) {
  303. $device = 'android';
  304. }
  305. $uid = Auth::auth();
  306. $pair = PairModel::find($pairId);
  307. if ($pair->uid !== $uid) {
  308. throw new ForbiddenException("无权限");
  309. }
  310. if (!in_array($sex, [1, 2])) {
  311. throw new UnprocessableEntityException('请选择性别');
  312. }
  313. if (!in_array($sxo, [1, 2])) {
  314. throw new UnprocessableEntityException('请选择性取向');
  315. }
  316. $activity = ActivityModel::enrolling()->first();
  317. if (!$activity) {
  318. throw new NotFoundException("活动不存在");
  319. }
  320. if ($activity->stage_id !== $stageId) {
  321. throw new NotFoundException('活动报名已截止报名');
  322. }
  323. $pair = PairModel::where('uid', $uid)->where('stage_id', $stageId)->first();
  324. if ($pair) {
  325. throw new ConflictException("您已经报名本期活动,请勿重复报名哦");
  326. }
  327. $attribute = ['media_id' => $mediaId, 'stage_id' => $stageId, 'sex' => $sex, 'sxo' => $sxo, 'min_age' => $minAge, 'max_age' => $maxAge, 'km' => $km, 'lng' => $lng, 'lat' => $lat, 'location' => $location, 'device' => $device];
  328. $this->pairManager->enrollNext($pair, $attribute);
  329. }
  330. /**
  331. * 超级会员助力领取匹配成功率
  332. * @param AddScoreBySuperVipMessage $message
  333. * @throws CustomErrorMessageException
  334. * @throws ForbiddenException
  335. */
  336. public function addScoreBySuperVip(AddScoreBySuperVipMessage $message)
  337. {
  338. $uid = Auth::auth();
  339. $pairId = $message->getPairId();
  340. $pair = PairModel::find($pairId);
  341. if ($pair->uid !== $uid) {
  342. throw new ForbiddenException("无权限");
  343. }
  344. if ($pair->score >= 90) {
  345. throw new CustomErrorMessageException("当前已达最高匹配成功率,请耐心等待匹配开始吧");
  346. }
  347. $user = UserModel::find($uid);
  348. if (!$user->is_super_vip) {
  349. throw new CustomErrorMessageException("您不是超级会员");
  350. }
  351. $pair->state = 103;
  352. $pair->score = 92;
  353. $pair->save();
  354. }
  355. /**
  356. * 能量助力匹配成功率
  357. * @param AddScoreByEnergyMessage $message
  358. * @throws CustomErrorMessageException
  359. * @throws ForbiddenException
  360. */
  361. public function addScoreByEnergy(AddScoreByEnergyMessage $message)
  362. {
  363. $uid = Auth::auth();
  364. $pairId = $message->getPairId();
  365. $pair = PairModel::find($pairId);
  366. if ($pair->uid !== $uid) {
  367. throw new ForbiddenException("无权限");
  368. }
  369. if ($pair->score >= 90) {
  370. throw new CustomErrorMessageException("当前已达最高匹配成功率,请耐心等待匹配开始吧");
  371. }
  372. $user = UserModel::find($uid);
  373. $score = $user->pair_energy;
  374. $user->pair_energy = 0;
  375. $user->save();
  376. $pair->state = 103;
  377. $pair->score += $score;
  378. $pair->save();
  379. }
  380. /**
  381. * 直缴助力匹配成功率
  382. * @param AddScoreByOrderMessage $message
  383. * @return OrderModel|\Illuminate\Database\Eloquent\Model
  384. * @throws CustomErrorMessageException
  385. * @throws ForbiddenException
  386. * @throws \GuzzleHttp\Exception\GuzzleException
  387. */
  388. public function addScoreByOrder(AddScoreByOrderMessage $message)
  389. {
  390. $uid = Auth::auth();
  391. $pairId = $message->getPairId();
  392. $pair = PairModel::find($pairId);
  393. if ($pair->uid !== $uid) {
  394. throw new ForbiddenException("无权限");
  395. }
  396. if ($pair->score >= 90) {
  397. throw new CustomErrorMessageException("当前已达最高匹配成功率,请耐心等待匹配开始吧");
  398. }
  399. if ($pair->order_id > 0) {
  400. throw new CustomErrorMessageException("每次报名只能补缴一次");
  401. }
  402. $order = $this->orderManager->unifyOrderByScore($pair);
  403. $message->setResponse(['order_id' => $order->id]);
  404. }
  405. /**
  406. * 修改报名信息
  407. * @param UpdateMessage $message
  408. * @throws CustomErrorMessageException
  409. * @throws ForbiddenException
  410. */
  411. public function update(UpdateMessage $message)
  412. {
  413. $uid = Auth::auth();
  414. $pairId = $message->getPairId();
  415. $pair = PairModel::find($pairId);
  416. if ($pair->uid != $uid) {
  417. throw new ForbiddenException('无权限');
  418. }
  419. $activity = ActivityModel::find($pair->stage_id);
  420. if ($activity->getProgress() !== ActivityModel::ENROLLING) {
  421. throw new CustomErrorMessageException('活动已结束报名,信息已不可修改');
  422. }
  423. $pair->sex = $message->getSex();
  424. $pair->sxo = $message->getSxo();
  425. $pair->min_age = $message->getMinAge();
  426. $pair->max_age = $message->getMaxAge();
  427. $pair->km = $message->getKm();
  428. $pair->lng = $message->getLng();
  429. $pair->lat = $message->getLat();
  430. $pair->location = $message->getLocation();
  431. $pair->save();
  432. }
  433. /**
  434. * 退款
  435. * @param RefundMessage $message
  436. * @throws CustomErrorMessageException
  437. * @throws ForbiddenException
  438. */
  439. public function refund(RefundMessage $message)
  440. {
  441. $uid = Auth::auth();
  442. $pairId = $message->getPairId();
  443. $pair = PairModel::findOrFail($pairId);
  444. if ($pair->uid != $uid) {
  445. throw new ForbiddenException('无权限');
  446. }
  447. $this->pairManager->refund($pair);
  448. }
  449. /**
  450. * @param ActivityLastMessage $message
  451. */
  452. public function activityLast(ActivityLastMessage $message)
  453. {
  454. $activity = ActivityModel::orderBy('stage_id', 'desc')->first();
  455. try {
  456. $uid = Auth::auth();
  457. $first_pair = PairModel::where('uid', $uid)->where(function ($query) {
  458. /** @var PairModel $query */
  459. $query->whereNotNull('assoc_id')->orWhere('last_assoc', '>', 0);
  460. })->first();
  461. $activity->first_pair = $first_pair ? false : true;
  462. } catch (JWTException $e) {
  463. }
  464. $message->setResponse($activity);
  465. }
  466. /**
  467. * 获取某人最近一期的活动状态
  468. *
  469. * @param ActivityRecentMessage $message
  470. */
  471. public function activityRecent(ActivityRecentMessage $message)
  472. {
  473. $uid = Auth::auth();
  474. $data = $this->pairManager->getRecentState($uid);
  475. $message->setResponse($data);
  476. }
  477. public function activityInfo(ActivityInfoMessage $message)
  478. {
  479. $stage_id = $message->getStageId();
  480. $uid = Auth::auth();
  481. $data = $this->pairManager->getActivityInfo($uid, $stage_id);
  482. $message->setResponse($data);
  483. }
  484. public function getActivityConductStageId(GetActivityConductStageIdMessage $message)
  485. {
  486. $ings = ActivityModel::getActivitys();
  487. $data = ActivityModel::findOrFail($ings['ing']);
  488. $message->setResponse($data);
  489. }
  490. public function getAllTags(GetAllTagsMessage $message)
  491. {
  492. $datas = TagModel::get()->toArray();
  493. $result = array();
  494. foreach ($datas as $data) {
  495. $tmp = array('id' => (string) $data['id'], 'name' => $data['name'], 'group' => (string) $data['group']);
  496. $result[$data['group']][$data['id']] = $tmp;
  497. }
  498. $message->setResponse($result);
  499. }
  500. public function lastenroll(LastenrollMessage $message)
  501. {
  502. $ings = ActivityModel::getActivitys();
  503. $pairs = PairModel::where([['stage_id', $ings['next']], ['state', '>', 100]])->take(30)->orderBy('id', 'desc')->get(['id', 'sex', 'stage_id', 'create_time', 'uid']);
  504. $users = UserModel::whereIn('uid', $pairs->pluck('uid'))->get(['uid', 'headimgurl', 'nickname', 'sex', 'address', 'home']);
  505. foreach ($pairs as &$pair) {
  506. /** @var UserModel $tmp */
  507. $tmp = $users->where('uid', $pair->uid) ?? [];
  508. foreach ($tmp as $v) {
  509. $pair->user = $v;
  510. }
  511. }
  512. $message->setResponse($pairs);
  513. }
  514. public function getActivityList(GetActivityListMessage $message)
  515. {
  516. $uid = Auth::auth();
  517. $lists = DB::table("kdgx_partner_charge_activity")->join("kdgx_partner_charge_pair", "kdgx_partner_charge_activity.stage_id", "kdgx_partner_charge_pair.stage_id")->where([['kdgx_partner_charge_pair.uid', $uid], ['kdgx_partner_charge_pair.hidden_at', 0]])->orderBy("kdgx_partner_charge_pair.stage_id", "desc")->get();
  518. foreach ($lists as &$list) {
  519. try {
  520. $pair = PairModel::find($list->id);
  521. $progress = $pair->progress();
  522. $list->progress = $progress;
  523. } catch (\Exception $e) {
  524. app('sentry')->captureException($e);
  525. }
  526. $userInfo = DB::table("kdgx_partner_charge_pair")->join("kdgx_partner_charge_user", "kdgx_partner_charge_pair.uid", "kdgx_partner_charge_user.uid")->where([['kdgx_partner_charge_pair.uid', $uid], ['kdgx_partner_charge_pair.stage_id', $list->stage_id]])->first();
  527. if (is_null($userInfo->assoc_id)) {
  528. $list->pair_info = ['user_info' => $userInfo];
  529. } else {
  530. $partnerInfo = DB::table("kdgx_partner_charge_pair")->join("kdgx_partner_charge_user", "kdgx_partner_charge_pair.uid", "kdgx_partner_charge_user.uid")->where('kdgx_partner_charge_pair.id', $userInfo->assoc_id)->first();
  531. try {
  532. $roomInfo = RoomModel::findOrFail($partnerInfo->room_id);
  533. $roomInfo->online = null;
  534. $roomInfo->unread_msg = 0;
  535. } catch (ModelNotFoundException $exception) {
  536. $roomInfo = [];
  537. }
  538. $list->pair_info = ['user_info' => $userInfo, 'partner_info' => $partnerInfo, 'room_info' => $roomInfo];
  539. }
  540. }
  541. $message->setResponse($lists);
  542. }
  543. /**
  544. * @param GetKeepRoomMessage $message
  545. */
  546. public function getKeepRoom(GetKeepRoomMessage $message)
  547. {
  548. $uid = Auth::auth();
  549. $room_id = $this->pairManager->getKeepRoom($uid);
  550. $room = RoomModel::find($room_id);
  551. $message->setResponse($room);
  552. }
  553. /**
  554. * @param KeepCpMessage $message
  555. * @throws \App\Exceptions\AlertException
  556. */
  557. public function keepCp(KeepCpMessage $message)
  558. {
  559. $uid = Auth::auth();
  560. $room_id = $message->getRoomId();
  561. $this->pairManager->keepRoom($uid, $room_id);
  562. }
  563. /**
  564. * @param RemoveKeepCpMessage $message
  565. * @throws CustomErrorMessageException
  566. */
  567. public function removeKeepCp(RemoveKeepCpMessage $message)
  568. {
  569. $uid = Auth::auth();
  570. $room_id = $message->getRoomId();
  571. $this->pairManager->removeKeepRoom($uid, $room_id);
  572. }
  573. /**
  574. * @param GetAloneGroupMessage $message
  575. */
  576. public function getAloneGroup(GetAloneGroupMessage $message)
  577. {
  578. $uid = Auth::auth();
  579. $stageId = $message->getStageId();
  580. $activityType = $message->getActivityType();
  581. $groups = GroupMemberModel::where('uid', $uid)->when($stageId, function ($query) use ($stageId) {
  582. return $query->where('stage_id', $stageId);
  583. })->when($activityType, function ($query) use ($activityType) {
  584. return $query->where('activity_type', $activityType);
  585. })->get();
  586. foreach ($groups as $group) {
  587. $group->group = GroupModel::find($group->group_id);
  588. }
  589. $message->setResponse($groups);
  590. }
  591. /**
  592. * @param ConfirmBeAloneMessage $message
  593. * @throws \App\Exceptions\AlertException
  594. */
  595. public function confirmBeAlone(ConfirmBeAloneMessage $message)
  596. {
  597. $uid = Auth::auth();
  598. $stageId = $message->getStageId();
  599. $groupId = $this->pairManager->getAloneGroup($uid, $stageId);
  600. $group = GroupModel::find($groupId);
  601. $message->setResponse($group);
  602. }
  603. /**
  604. * 操作日志
  605. * @param OperationalLogMessage $message
  606. * @throws JWTException
  607. */
  608. public function operationalLog(OperationalLogMessage $message)
  609. {
  610. $uid = Auth::auth();
  611. $stageId = $message->getStageId();
  612. $type = $message->getType();
  613. $content = $message->getContent();
  614. OperationalLogModel::create(['uid' => $uid, 'stage_id' => $stageId, 'type' => $type, 'content' => $content]);
  615. }
  616. /**
  617. * @param RegretsMessage $message
  618. * @throws \App\Exceptions\AlertException
  619. */
  620. public function regrets(RegretsMessage $message)
  621. {
  622. $pairId = $message->getPairId();
  623. $ps = new \App\Services\Pair\PairService();
  624. $ps->goBackConfirm($pairId);
  625. }
  626. /**
  627. * @param ConfirmCpMessage $message
  628. * @throws \App\Exceptions\AlertException
  629. * @throws \App\Exceptions\DBException
  630. */
  631. public function confirmCp(ConfirmCpMessage $message)
  632. {
  633. $uid = Auth::auth();
  634. $confirm = $message->getConfirm();
  635. $pairId = $message->getPairId();
  636. $pairService = new \App\Services\Pair\PairService();
  637. $pairService->confirmPair($pairId, $confirm);
  638. }
  639. public function getRecommendPairApplyContacts(GetRecommendPairApplyContactsMessage $message)
  640. {
  641. $uid = Auth::auth();
  642. $recommendedContacts = $message->getRecommendedContacts();
  643. $contacts = $this->pairManager->getRecommendPairApplyContacts($uid, $recommendedContacts);
  644. $message->setResponse($contacts);
  645. }
  646. }