ajun 5 лет назад
Родитель
Сommit
5b3881ab7e

+ 12 - 0
app/Http/Controllers/PrintController.php

@@ -2,9 +2,21 @@
 
 namespace App\Http\Controllers;
 
+use App\Components\AsyncResponse;
+use App\Services\PrintService;
 use Illuminate\Http\Request;
 
 class PrintController extends Controller
 {
     //
+    use AsyncResponse;
+
+    public function getPrintDataApi(Request $request,PrintService $service): array
+    {
+        if(!$request->has('printStr')) $this->error('输入条件进行查询');
+        $printData = $service->getPrintData($request->input('printStr'));
+        return ['success' => true,'data' => $printData];
+    }
+
+
 }

+ 7 - 0
app/OracleDocOrderDeliveryInfo.php

@@ -16,10 +16,17 @@ class OracleDocOrderDeliveryInfo extends Model
     protected $table = "DOC_ORDER_DELIVERYINFO";
     public $timestamps = false;
 
+    protected $fillable = ['orderno','trackingno','userdefine1','userdefine3','userdefine4','userdefine5'];
+
+    protected $casts = [
+        'userdefine1' => 'array',
+    ];
+
     /**
      * OrderNo        订单单号
      * TrackingNo     快递单号
      * userDefine1    打印组件参数
+     * userDefine2    打印组件参数
      * userDefine3    解码
      * userDefine4    打印组件解析模板url
      * userDefine5    打印版本

+ 35 - 11
app/Services/PrintService.php

@@ -2,20 +2,23 @@
 
 namespace App\Services;
 
-use App\Batch;
 use App\OracleDocOrderDeliveryInfo;
 use App\OracleDOCOrderHeader;
-use App\Order;
-use App\OrderPackage;
-use App\Owner;
 use App\Traits\ModelSearchWay;
 use App\Traits\ServiceAppAop;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Collection;
 
 class PrintService
 {
     use ModelSearchWay;
     use ServiceAppAop;
 
+    /**
+     * 分列 订单号,快递单号,波次号
+     * @param string $print
+     * @return array[]
+     */
     public function conversionPrintData(string $print): array
     {
         preg_match_all('/[\w]+/',$print,$nos);
@@ -25,6 +28,7 @@ class PrintService
             elseif(strstr($no,'W')) $batchesCodes[] = $no;
             else $logistic_numbers[] = $no;
         }
+
         return [$batchesCodes ?? [],$orderCodes ?? [],$logistic_numbers ?? []];
     }
 
@@ -35,7 +39,7 @@ class PrintService
      * @param array $logistic_numbers
      * @return array|mixed
      */
-    public function getLogisticNumber($batchCodes=[],$orderCodes = [],$logistic_numbers = [])
+    public function getLogisticNumber($batchCodes=[],$orderCodes = [],$logistic_numbers = []): array
     {
         if($batchCodes){
             $orderHeaders = OracleDOCOrderHeader::query()->selectRaw('OrderNo')->whereIn('WaveNo',$batchCodes)->get()->map(function($item) {
@@ -52,15 +56,35 @@ class PrintService
         return $logistic_numbers ?? [];
     }
 
+    /**
+     * 获取打印信息
+     * @param string $print
+     * @return Builder[]|Collection
+     */
     public function getPrintData(string $print)
     {
-        list($batchesCodes,$orderCodes,$logistic_numbers) =  $this->conversionPrintData($print);
+        list($batchesCodes,$orderCodes,$logistic_numbers) = $this->conversionPrintData($print);
         $logistic_numbers = $this->getLogisticNumber($batchesCodes, $orderCodes, $logistic_numbers);
-        $info = OracleDocOrderDeliveryInfo::query()->select(['TackingNo','OrderNO','UserDefine1'])->whereIn('tackingNo',$logistic_numbers)->get();
-        return $info;
+        $items = OracleDocOrderDeliveryInfo::query()->select(['TackingNo','OrderNO','UserDefine1'])->whereIn('tackingNo',$logistic_numbers)->get();
+        return $this->disposesPrintInfo($items);
     }
 
-
-
-
+    /**
+     * 处理打印请求参数
+     * @param $oracleDocOrderDeliveryInfos
+     * @return array
+     */
+    public function disposesPrintInfo($oracleDocOrderDeliveryInfos): array
+    {
+        foreach ($oracleDocOrderDeliveryInfos as $key => $info){
+            $data[] = [
+                'documentID' => $info->orderno ?? '',
+                'encryptedData' => $info->userDefine4->encryptedData ?? '',
+                'signature' => $info->userDefine4->signature ?? '',
+                'templateURL' => $info->userDefine4->templateURL ?? '',
+                'ver' => $info->userDefine4->ver ?? '',
+            ];
+        }
+        return $data ?? [];
+    }
 }