WxProcessDataJob.php 1.7 KB

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