FeedbackNoticeCommand.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Console\Commands\Pair;
  3. use App\Models\Fpdx\ActivityModel;
  4. use App\Models\Fpdx\FormModel;
  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 FeedbackNoticeCommand extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'pair:notice:feedback';
  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('close_time', '<=', time())->orderBy('close_time', 'desc')->value('stage_id');
  42. $pairs = PairModel::select('uid', 'stage_id')
  43. ->where('stage_id', $stageId)
  44. ->whereNotNull('assoc_id')
  45. ->get();
  46. $form = FormModel::where('stage_id', $stageId)->where('activity_type', '72h')->first();
  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. 'stage_id',
  55. 'form_id'
  56. ]);
  57. foreach ($pairs as $pair) {
  58. $user = UserModel::find($pair->uid);
  59. fputcsv($fp, [
  60. json_encode($user->getAuth()),
  61. $stageId,
  62. $form->id,
  63. ]);
  64. }
  65. fclose($fp);
  66. $file = new File($local_file);
  67. $file = Storage::disk('oss')->putFileAs($path, $file, $uuid . '.' . $file->getExtension());
  68. $fileUrl = Storage::disk('oss')->url($file);
  69. // 导入通知
  70. $url = "https://push.fenpeiduixiang.com/api/v1/marketing/set_up_activity";
  71. $eventId = 10108;
  72. $payload = [
  73. 'memo' => "72小时反馈通知-{$stageId}期",
  74. 'queryType' => 1,
  75. 'queryUrl' => $fileUrl,
  76. 'eventId' => $eventId,
  77. 'startAt' => mktime(9, 45, 0),
  78. 'maxEveryDay' => $maxCount,
  79. 'secondSendRate' => 60,
  80. 'delayPiece' => 10,
  81. ];
  82. $response = Curl::to($url)->withData([
  83. 'payload' => $payload
  84. ])->asJson(true)->post();
  85. dd($response);
  86. }
  87. }