PrintService.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Services;
  3. use App\OracleDocOrderDeliveryInfo;
  4. use App\OracleDOCOrderHeader;
  5. use App\Traits\ModelSearchWay;
  6. use App\Traits\ServiceAppAop;
  7. use Illuminate\Database\Eloquent\Builder;
  8. use Illuminate\Database\Eloquent\Collection;
  9. class PrintService
  10. {
  11. use ModelSearchWay;
  12. use ServiceAppAop;
  13. /**
  14. * 分列 订单号,快递单号,波次号
  15. * @param string $print
  16. * @return array[]
  17. */
  18. public function conversionPrintData(string $print): array
  19. {
  20. preg_match_all('/[\w]+/',$print,$nos);
  21. foreach ($nos[0] as $no){
  22. if(strstr($no,'SO')) $orderCodes[] = $no;
  23. elseif(strstr($no,'W')) $batchesCodes[] = $no;
  24. else $logistic_numbers[] = $no;
  25. }
  26. return [$batchesCodes ?? [],$orderCodes ?? [],$logistic_numbers ?? []];
  27. }
  28. /**
  29. * 返回WMS中对应的快递单号
  30. * @param array $batchCodes
  31. * @param array $orderCodes
  32. * @param array $logistic_numbers
  33. * @return array|mixed
  34. */
  35. public function getLogisticNumber($batchCodes=[],$orderCodes = [],$logistic_numbers = []): array
  36. {
  37. if($batchCodes){
  38. $orderHeaders = OracleDOCOrderHeader::query()->selectRaw('OrderNo')->whereIn('WaveNo',$batchCodes)->get()->map(function($item) {
  39. return $item->orderno;
  40. });
  41. $orderCodes = array_merge($orderHeaders, $orderCodes);
  42. }
  43. if($orderCodes) {
  44. $info = OracleDocOrderDeliveryInfo::query()->where('OrderNo',$orderCodes)->get()->map(function($item){
  45. return $item->tackingno;
  46. });
  47. $logistic_numbers = array_merge($info, $logistic_numbers);
  48. }
  49. return $logistic_numbers ?? [];
  50. }
  51. /**
  52. * 获取打印信息
  53. * @param string $print
  54. * @return Builder[]|Collection
  55. */
  56. public function getPrintData(string $print)
  57. {
  58. list($batchesCodes,$orderCodes,$logistic_numbers) = $this->conversionPrintData($print);
  59. $logistic_numbers = $this->getLogisticNumber($batchesCodes, $orderCodes, $logistic_numbers);
  60. $items = OracleDocOrderDeliveryInfo::query()->select(['TackingNo','OrderNO','UserDefine1'])->whereIn('tackingNo',$logistic_numbers)->get();
  61. return $this->disposesPrintInfo($items);
  62. }
  63. /**
  64. * 处理打印请求参数
  65. * @param $oracleDocOrderDeliveryInfos
  66. * @return array
  67. */
  68. public function disposesPrintInfo($oracleDocOrderDeliveryInfos): array
  69. {
  70. foreach ($oracleDocOrderDeliveryInfos as $key => $info){
  71. $data[] = [
  72. 'documentID' => $info->orderno ?? '',
  73. 'encryptedData' => $info->userDefine4->encryptedData ?? '',
  74. 'signature' => $info->userDefine4->signature ?? '',
  75. 'templateURL' => $info->userDefine4->templateURL ?? '',
  76. 'ver' => $info->userDefine4->ver ?? '',
  77. ];
  78. }
  79. return $data ?? [];
  80. }
  81. }