IntoRoomCommand.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Console\Commands\Qbj;
  3. use App\Models\Fpdx\ActivityModel;
  4. use App\Models\Fpdx\PairModel;
  5. use App\Models\Fpdx\RoomModel;
  6. use App\Services\Deed\FriendService;
  7. use DB;
  8. use Exception;
  9. use Illuminate\Console\Command;
  10. use Illuminate\Support\Facades\Redis;
  11. class IntoRoomCommand extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'qbj:into:room';
  19. /**
  20. * The console command description.
  21. *
  22. * @var string
  23. */
  24. protected $description = '情报局::匹配成功送入房间';
  25. /**
  26. * Create a new command instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct()
  31. {
  32. parent::__construct();
  33. }
  34. /**
  35. * Execute the console command.
  36. *
  37. * @return mixed
  38. * @throws Exception
  39. */
  40. public function handle()
  41. {
  42. //
  43. $stage_id = ActivityModel::where('qbj_stage_id', '>', 0)
  44. ->where('signend_time', '<=', time())
  45. ->where('close_time', '>=', time())->value('stage_id');
  46. if (!$stage_id) {
  47. dd("当前没有正在进行的情报局活动");
  48. }
  49. $pairs = PairModel::where([
  50. 'stage_id' => $stage_id,
  51. 'room_id' => 0,
  52. 'activity_type' => 'qbj'
  53. ])->whereNotNull('assoc_id')
  54. ->where('partner', 1)->get();
  55. $fs = new FriendService();
  56. foreach ($pairs as $pair) {
  57. DB::beginTransaction();
  58. try {
  59. $other = PairModel::findOrFail($pair->assoc_id);
  60. $room = RoomModel::create([
  61. 'stage_id' => $stage_id,
  62. 'room_name' => "第{$stage_id}期的房间",
  63. 'member' => implode(',', [$pair->uid, $other->uid]),
  64. 'create_time' => time(),
  65. 'type' => 1
  66. ]);
  67. $pair->confirm = 1;
  68. $pair->rematch = -1;
  69. $pair->room_id = $room->room_id;
  70. $pair->save();
  71. $other->confirm = 1;
  72. $other->rematch = -1;
  73. $other->room_id = $room->room_id;
  74. $other->save();
  75. Redis::zadd("session_room_{$pair->uid}", time(), $room->room_id);
  76. Redis::zadd("session_room_{$other->uid}", time(), $room->room_id);
  77. Redis::sadd("fpdx_pairs_{$pair->uid}", $other->uid);
  78. Redis::sadd("fpdx_pairs_{$other->uid}", $pair->uid);
  79. $fs->befriend($pair->uid, $other->uid, 2, $room->room_id);
  80. DB::commit();
  81. } catch (Exception $e) {
  82. DB::rollBack();
  83. app('sentry')->captureException($e);
  84. \Log::warning("创建房间失败:【{$pair->id}】|【{$pair->assoc_id}】");
  85. }
  86. }
  87. // 结束钉钉通知
  88. \Curl::to("http://api.deep.fenpeiduixiang.com/api/ding/roomstate/end/{$stage_id}")->get();
  89. }
  90. }