ProcessDataJob.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace App\Jobs;
  3. use App\Model\DDEmployee;
  4. use App\Model\Record;
  5. use App\Model\U8State;
  6. use App\Service\U8DatabaseServerService;
  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 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. public $timeout = 30;
  19. public function __construct($data)
  20. {
  21. //record表
  22. $this->data = $data;
  23. }
  24. public function handle()
  25. {
  26. try {
  27. list($bool, $msg) = $this->syncApprovedRecords($this->data);
  28. if(! $bool) $this->finalDo($msg, $this->data);
  29. } catch (\Throwable $e) {
  30. $this->finalDo("异常:" . $e->getMessage());
  31. $this->delete();
  32. }
  33. }
  34. private function finalDo($msg, $record){
  35. Record::where('id', $record['id'])
  36. ->update(['result' => $msg]);
  37. }
  38. private function syncApprovedRecords($record)
  39. {
  40. try {
  41. $LoginType = $record['login_type'];
  42. $database = $record['database'];
  43. $service = new U8DatabaseServerService(['zt_database' => $database]);
  44. if ($service->error) return [false, $service->error];
  45. $time = date("Y-m-d H:i:s");
  46. $time1 = date("Y-m-d 00:00:00");
  47. if($record['del_time'] == 2){
  48. $type = $record['type'];
  49. $order_number = $record['order_number'];
  50. $system_name = "system";
  51. $name = DDEmployee::where('userid', $record['userid'])->where('login_type', $LoginType)->value('name');
  52. if(! empty($name)) $system_name = $name;
  53. if($type == Record::type_one){
  54. $service->db->table("PO_Pomain")
  55. ->where("cPOID", $order_number)
  56. ->update([
  57. "cVerifier" => $system_name,
  58. "iverifystateex" => 1,
  59. "cState" => 1,
  60. "cAuditTime" => $time . ".000",
  61. "cAuditDate" => $time1 . ".000",
  62. ]);
  63. }elseif($type == Record::type_two){
  64. $service->db->table("PU_AppVouch")
  65. ->where("cCode", $order_number)
  66. ->update([
  67. "cVerifier" => $system_name,
  68. "cAuditTime" => $time . ".000",
  69. "cAuditDate" => $time1 . ".000",
  70. ]);
  71. }elseif($type == Record::type_three){
  72. $service->db->table("RdRecord01")
  73. ->where("cCode", $order_number)
  74. ->update([
  75. "cHandler" => $system_name,
  76. "dnverifytime" => $time . ".000",
  77. "dVeriDate" => $time1 . ".000",
  78. ]);
  79. }elseif($type == Record::type_four){
  80. }elseif($type == Record::type_five){
  81. }
  82. // 更新本地数据 通过状态
  83. Record::where("id", $record['id'])->update(['del_time' => 3]);
  84. // 更新状态为 通过状态
  85. U8State::updateOrCreate(
  86. ['order_number' => $record['order_number'], 'login_type' => $record['login_type'], 'type' => $record['type']],
  87. ['state' => U8State::state_one]
  88. );
  89. }
  90. $service->close();
  91. } catch (\Throwable $e) {
  92. return [false, $e->getMessage()];
  93. }
  94. return [true, ''];
  95. }
  96. protected function echoMessage(OutputInterface $output)
  97. {
  98. //输出消息
  99. $output->writeln(json_encode($this->data));
  100. }
  101. }