ProcessDataJob.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Jobs;
  3. use App\Model\ErrorTable;
  4. use App\Model\U8Job;
  5. use App\Service\ProductService;
  6. use App\Service\U8ServerService;
  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 Illuminate\Support\Facades\Redis;
  14. use MongoDB\Driver\Exception\Exception;
  15. use Symfony\Component\Console\Output\ConsoleOutput;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. class ProcessDataJob implements ShouldQueue
  18. {
  19. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  20. protected $data;
  21. public $tries = 0;
  22. public $timeout = 60;
  23. //1 采购 2 销售(合同) 3 总社库存
  24. protected $function = [
  25. 1 => 'U8PO_PomainSave',
  26. 2 => 'U8SaleOrderSave',
  27. 3 => 'U8StockToMy',
  28. ];
  29. public function __construct($data)
  30. {
  31. $this->data = $data;
  32. }
  33. public function handle()
  34. {
  35. try {
  36. $function = $this->function[$this->data['type']] ?? '';
  37. if(empty($function)) return;
  38. //调用同步方法
  39. $this->$function();
  40. } catch (\Throwable $e) {
  41. $this->delete();
  42. }
  43. }
  44. //采购
  45. private function U8PO_PomainSave(){
  46. $service = new U8ServerService();
  47. if(! empty($service->error)) {
  48. $service->finalSettle($this->data['id'], U8Job::one, $service->error);
  49. return;
  50. }
  51. $service->U8PO_PomainSave($this->data['id'], $this->data['user_name']);
  52. }
  53. //销售(合同)
  54. private function U8SaleOrderSave(){
  55. $service = new U8ServerService();
  56. if(! empty($service->error)) {
  57. $service->finalSettle($this->data['id'], U8Job::two, $service->error);
  58. return;
  59. }
  60. $service->U8SaleOrderSave($this->data['id'], $this->data['user_name']);
  61. }
  62. // public function failed($exception)
  63. // {
  64. // // 记录失败错误信息到日志或其他媒介
  65. // $errorMessage = $exception->getFile() . $exception->getMessage() . $exception->getLine();
  66. // $this->recordErrorTable($errorMessage);
  67. // }
  68. //总社库存
  69. private function U8StockToMy(){
  70. $service = new ProductService();
  71. list($status, $msg) = $service->writeStock($this->data);
  72. $service = new U8ServerService();
  73. $service->finalSettle(-1, U8Job::three, $msg);
  74. }
  75. private function recordErrorTable($msg){
  76. $data = $this->data;
  77. ErrorTable::insert([
  78. 'msg' => $msg,
  79. 'data' => json_encode($this->data),
  80. 'user_id' => $data['user']['id'],
  81. 'user_operation_time' => $data['user']['operate_time'],
  82. 'type' => $data['type']
  83. ]);
  84. }
  85. protected function echoMessage(OutputInterface $output)
  86. {
  87. //输出消息
  88. $output->writeln(json_encode($this->data));
  89. }
  90. }