ProcessDataJob.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Jobs;
  3. use App\Model\RevenueCostMain;
  4. use App\Service\DeviceWorkService;
  5. use App\Service\PersonWorkService;
  6. use App\Service\TPlusServerService;
  7. use Illuminate\Bus\Queueable;
  8. use Illuminate\Contracts\Queue\ShouldQueue;
  9. use Illuminate\Foundation\Bus\Dispatchable;
  10. use Illuminate\Queue\InteractsWithQueue;
  11. use Illuminate\Queue\SerializesModels;
  12. use Illuminate\Support\Facades\DB;
  13. use MongoDB\Driver\Exception\Exception;
  14. use Symfony\Component\Console\Output\ConsoleOutput;
  15. use Symfony\Component\Console\Output\OutputInterface;
  16. class ProcessDataJob implements ShouldQueue
  17. {
  18. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  19. protected $data;
  20. protected $user;
  21. protected $type;
  22. public $timeout = 300;
  23. public function __construct($data, $user)
  24. {
  25. $this->data = $data;
  26. $this->user = $user;
  27. }
  28. public function handle()
  29. {
  30. try {
  31. $data = $this->data;
  32. $user = $this->user;
  33. $type = $data['type'];
  34. if($type == 'p_work'){
  35. $service = new PersonWorkService();
  36. list($status,$msg) = $service->dailyPwOrderCreateMain($data, $user);
  37. }elseif ($type == 'd_work'){
  38. $service = new DeviceWorkService();
  39. list($status,$msg) = $service->dailyDwOrderCreateMain($data, $user);
  40. }
  41. if(isset($status) && isset($msg)) $this->finalDo($msg);
  42. } catch (\Throwable $e) {
  43. $this->finalDo("异常:" . $e->getMessage());
  44. $this->delete();
  45. }
  46. }
  47. private function finalDo($msg){
  48. $user = $this->user;
  49. $data = $this->data;
  50. DB::table('error_record')->insert([
  51. 'result' => $msg,
  52. 'crt_id' => $user['id'],
  53. 'crt_time' => time(),
  54. 'order_type' => $data['type'],
  55. ]);
  56. }
  57. protected function echoMessage(OutputInterface $output)
  58. {
  59. //输出消息
  60. $output->writeln(json_encode($this->data));
  61. }
  62. }