ProcessDataJob.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Jobs;
  3. use App\Model\RevenueCostMain;
  4. use App\Service\TPlusServerService;
  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 Illuminate\Support\Facades\DB;
  11. use Illuminate\Support\Facades\Redis;
  12. use MongoDB\Driver\Exception\Exception;
  13. use Symfony\Component\Console\Output\ConsoleOutput;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. class ProcessDataJob implements ShouldQueue
  16. {
  17. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  18. protected $data;
  19. protected $user;
  20. protected $type;
  21. public $timeout = 1800;
  22. public function __construct($data, $user, $type = 1)
  23. {
  24. $this->data = $data;
  25. $this->user = $user;
  26. $this->type = $type;
  27. }
  28. public function handle()
  29. {
  30. try {
  31. $data = $this->data;
  32. $user = $this->user;
  33. $type = $this->type;
  34. // $this->finalDo($msg, $service);
  35. } catch (\Throwable $e) {
  36. $this->finalDo("异常:" . $e->getMessage(), $service);
  37. $this->delete();
  38. }
  39. }
  40. private function finalDo($msg, $service){
  41. $type = $this->type;
  42. $service->delTableKey($type);
  43. if($type == 1) $service->clearTmpTable();
  44. $user = $this->user;
  45. $data = $this->data;
  46. RevenueCostMain::insert([
  47. 'result' => $msg,
  48. 'crt_id' => $user['id'],
  49. 'crt_time' => $data['operation_time'],
  50. 'order_type' => $data['type'],
  51. ]);
  52. }
  53. protected function echoMessage(OutputInterface $output)
  54. {
  55. //输出消息
  56. $output->writeln(json_encode($this->data));
  57. }
  58. }