ProcessDataJob.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. public $timeout = 1800;
  21. public function __construct($data, $user)
  22. {
  23. $this->data = $data;
  24. $this->user = $user;
  25. }
  26. public function handle()
  27. {
  28. $service = new TPlusServerService();
  29. try {
  30. $data = $this->data;
  31. $user = $this->user;
  32. list($status, $msg) = $service->synRevenueCostFromTPlus($data, $user);
  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. $service->delTableKey();
  41. $service->clearTmpTable();
  42. $user = $this->user;
  43. $data = $this->data;
  44. RevenueCostMain::insert([
  45. 'result' => $msg,
  46. 'crt_id' => $user['id'],
  47. 'crt_time' => $data['operation_time'],
  48. 'order_type' => $data['type'],
  49. ]);
  50. }
  51. protected function echoMessage(OutputInterface $output)
  52. {
  53. //输出消息
  54. $output->writeln(json_encode($this->data));
  55. }
  56. }