RejectedPushJob.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Jobs;
  3. use App\OracleDOCASNDetail;
  4. use App\OracleDOCASNHeader;
  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\Http;
  11. use Illuminate\Support\Facades\Log;
  12. class RejectedPushJob implements ShouldQueue
  13. {
  14. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  15. public $tries = 5;
  16. public $timeout = 120;
  17. /**
  18. * type: 推单,上架
  19. * [
  20. * ['sku' => '75603675975072','taskNum' => 'JI20220316211', 'asnNo' => 'asn002', 'type' => '推单'],
  21. * ['sku' => '75603675975072','taskNum' => 'JI20220316211', 'asnNo' => 'asn002', 'type' => '推单'],
  22. * ]
  23. */
  24. private $asnNos;
  25. /**
  26. * RejectedPushJob constructor.
  27. * @param array $asnNos
  28. */
  29. public function __construct(array $asnNos)
  30. {
  31. $this->asnNos = $asnNos;
  32. }
  33. /**
  34. * Execute the job.
  35. *
  36. * @return void
  37. */
  38. public function handle()
  39. {
  40. $result = array();
  41. $array = array();
  42. if (count($this->asnNos) > 0) {
  43. $asnHerders=OracleDOCASNHeader::query()->whereIn('asnno',$this->asnNos)
  44. ->select('asnno','notes','asntype','asnstatus')
  45. ->get();
  46. foreach ($asnHerders as $asnHerder) {
  47. if ($asnHerder->asntype == 'THRK' && $asnHerder->notes) {
  48. preg_match('/^[A-Z]{2}[0-9]{8}\d{0,8}/', $asnHerder->notes, $result);
  49. if (count($result) < 1) continue;
  50. $details = OracleDOCASNDetail::query()->select('sku', 'linestatus')->where('asnno', $asnHerder->asnno)->get();
  51. if (count($details) < 1) continue;
  52. foreach ($details as $detail) {
  53. $array[] = [
  54. 'sku' => $detail->sku,
  55. 'taskNum' => $result[0],
  56. 'asnNo' => $asnHerder->asnno,
  57. 'type' => $detail->linestatus == '99' ? '上架' : '推单'
  58. ];
  59. }
  60. }
  61. }
  62. }
  63. $url = config('api.java.wms.rejectedPushTask.receivePush');
  64. if (count($array) > 0) {
  65. $response = Http::post($url, $array);
  66. Log::info("推送信息!", ['res' => $response->body(), 'req' => $array]);
  67. }else{
  68. Log::info("推送信息失败!", ['res' => $this->asnNos,'array'=>$array]);
  69. }
  70. }
  71. }