ProcessDataJob.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\Log;
  12. use Illuminate\Support\Facades\Redis;
  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, $type = 1)
  24. {
  25. $this->data = $data;
  26. $this->user = $user;
  27. $this->type = $type;
  28. }
  29. public function handle()
  30. {
  31. $service = new TPlusServerService();
  32. try {
  33. $data = $this->data;
  34. $user = $this->user;
  35. $type = $this->type;
  36. if($type == 1){
  37. //收付款单
  38. list($status, $msg) = $service->synRevenueCostFromTPlus($data, $user);
  39. }elseif($type == 2){
  40. list($status, $msg) = $service->synSalaryEmployeeFromMine($data, $user);
  41. }else{
  42. list($status, $msg) = $service->synFreightFeeFromMine($data, $user);
  43. }
  44. $this->finalDo($msg, $service);
  45. } catch (\Throwable $e) {
  46. $this->finalDo("异常:" . $e->getMessage(), $service);
  47. $this->delete();
  48. }
  49. }
  50. private function finalDo($msg, $service){
  51. $type = $this->type;
  52. $service->delTableKey($type);
  53. $service->clearTmpTable($type);
  54. $user = $this->user;
  55. $data = $this->data;
  56. RevenueCostMain::insert([
  57. 'result' => $msg,
  58. 'crt_id' => $user['id'],
  59. 'crt_time' => $data['operation_time'],
  60. 'order_type' => $data['type'],
  61. ]);
  62. }
  63. protected function echoMessage(OutputInterface $output)
  64. {
  65. //输出消息
  66. $output->writeln(json_encode($this->data));
  67. }
  68. }