WxProcessDataJob.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Jobs;
  3. use App\Model\EnterpriseRecord;
  4. use App\Service\EnterpriseWechatService;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Bus\Dispatchable;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Queue\SerializesModels;
  10. use Symfony\Component\Console\Output\ConsoleOutput;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12. class WxProcessDataJob implements ShouldQueue
  13. {
  14. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  15. protected $data;
  16. public $timeout = 30;
  17. public function __construct($data)
  18. {
  19. $this->data = $data;
  20. }
  21. public function handle()
  22. {
  23. try {
  24. list($bool, $msg) = $this->settle();
  25. if(! $bool) $this->finalDo($msg);
  26. } catch (\Throwable $e) {
  27. $this->finalDo("异常:" . $e->getMessage());
  28. $this->delete();
  29. }
  30. }
  31. private function finalDo($msg){
  32. $data = $this->data;
  33. EnterpriseRecord::where('sp_no', $data['sp_no'])
  34. ->update(['result' => $msg]);
  35. }
  36. private function settle()
  37. {
  38. $data = $this->data;
  39. try {
  40. $no = $data['sp_no'];
  41. $template_id = $data['template_id'];
  42. $service = new EnterpriseWechatService();
  43. $detail = $service->getOA()->approvalDetail($no);
  44. //todo
  45. } catch (\Throwable $e) {
  46. return [false, $e->getMessage()];
  47. }
  48. return [true, ''];
  49. }
  50. protected function echoMessage(OutputInterface $output)
  51. {
  52. //输出消息
  53. $output->writeln(json_encode($this->data));
  54. }
  55. }