ProcessDataJob.php 1.7 KB

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