PairNoticeCommand.php 2.7 KB

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