RematchNoticeCommand.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Console\Commands\Pair;
  3. use App\Jobs\GrowingIO\PairSuccessReportJob;
  4. use App\Models\Fpdx\PairModel;
  5. use App\Models\Fpdx\ActivityModel;
  6. use App\Models\User\UserModel;
  7. use Illuminate\Console\Command;
  8. use Illuminate\Http\File;
  9. use Illuminate\Support\Facades\Storage;
  10. use Ixudra\Curl\Facades\Curl;
  11. class RematchNoticeCommand extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'pair:notice:rematch';
  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. */
  39. public function handle()
  40. {
  41. $stageId = ActivityModel::where('signend_time', '<=', time())
  42. ->where('close_time', '>=', time())->value('stage_id');
  43. $pairs = PairModel::select('uid', 'stage_id', 'assoc_id')
  44. ->where('stage_id', $stageId)
  45. ->where('rematch', 1)
  46. ->get();
  47. $maxCount = $pairs->count();
  48. $uuid = uuid();
  49. $path = sprintf("media/%s", date('Y-m-d'));
  50. $local_file = sprintf("storage/app/public/%s.csv", $uuid);
  51. $fp = fopen($local_file, 'w');
  52. fputcsv($fp, [
  53. 'to_user',
  54. 'pair.stage_id'
  55. ]);
  56. foreach ($pairs as $pair) {
  57. $user = UserModel::find($pair->uid);
  58. fputcsv($fp, [
  59. json_encode($user->getAuth()),
  60. $stageId
  61. ]);
  62. if ($pair->assoc_id) {
  63. $other = PairModel::find($pair->assoc_id);
  64. PairSuccessReportJob::dispatch($pair->uid, $other->uid, $stageId, 2);
  65. }
  66. }
  67. fclose($fp);
  68. $file = new File($local_file);
  69. $file = Storage::disk('oss')->putFileAs($path, $file, $uuid . '.' . $file->getExtension());
  70. $fileUrl = Storage::disk('oss')->url($file);
  71. // 导入通知
  72. $url = "https://push.fenpeiduixiang.com/api/v1/marketing/set_up_activity";
  73. $eventId = 10107;
  74. $payload = [
  75. 'memo' => "72小时重配通知-{$stageId}期",
  76. 'queryType' => 1,
  77. 'queryUrl' => $fileUrl,
  78. 'eventId' => $eventId,
  79. 'startAt' => mktime(12, 20, 0),
  80. 'maxEveryDay' => $maxCount,
  81. 'secondSendRate' => 60,
  82. 'delayPiece' => 10,
  83. ];
  84. $response = Curl::to($url)->withData([
  85. 'payload' => $payload
  86. ])->asJson(true)->post();
  87. dd($response);
  88. }
  89. }