海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2 KiB

4 years ago
4 years ago
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\Agent;
  4. use App\Models\MiniProgramTemplate;
  5. use App\Service\UploadMiniProgram;
  6. use Exception;
  7. use GuzzleHttp\Exception\GuzzleException;
  8. use Illuminate\Bus\Queueable;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Foundation\Bus\Dispatchable;
  11. use Illuminate\Queue\InteractsWithQueue;
  12. use Illuminate\Queue\SerializesModels;
  13. class UploadMiniProgramQueue implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. private int $template_id; //小程序模板ID
  17. private int $agent_id;
  18. /**
  19. * Create a new job instance.
  20. *
  21. * @param int $template_id 小程序模板ID
  22. * @param int $agent_id 代理商ID
  23. */
  24. public function __construct(int $template_id, int $agent_id)
  25. {
  26. $this->template_id = $template_id;
  27. $this->agent_id = $agent_id;
  28. }
  29. /**
  30. * Execute the job.
  31. *
  32. * @return void
  33. * @throws Exception
  34. */
  35. public function handle()
  36. {
  37. $agent = Agent::find($this->agent_id);
  38. $template = MiniProgramTemplate::find($this->template_id);
  39. if (!$agent || !$template) return;
  40. try {
  41. new UploadMiniProgram($agent, $template);
  42. } catch (GuzzleException | \Exception $e) {
  43. throw new Exception($e->getMessage());
  44. }
  45. }
  46. }