cqp 1 tydzień temu
rodzic
commit
17edf1f54c

+ 24 - 14
app/Console/Commands/U8Settle.php

@@ -222,10 +222,17 @@ class U8Settle extends Command
             $currentU8Nos = [];
             $lastId = 0;
             $orderDateLimit = $dateMap[$name]; // 当前类型的起始日期限制
+            $isFetchSuccess = true; // 新增:标记本次扫描是否完整
 
             while (true) {
                 list($status, $items) = $service->getPendingBills($config, $lastId);
-                if (!$status || empty($items)) break;
+                if(! $status){
+                    $isFetchSuccess = false;
+                    Log::channel('apiLog')->error("类型 {$name} 扫描中断,跳过删除逻辑");
+                    break;
+                }
+
+                if (empty($items)) break;
 
                 $nos = collect($items)->pluck('no')->toArray();
                 $currentU8Nos = array_merge($currentU8Nos, $nos); // 记录当前存在的单号
@@ -277,21 +284,24 @@ class U8Settle extends Command
 
             $currentU8NosLookup = array_flip($currentU8Nos);
 
-            // 使用 chunk 配合日期过滤,只查快照中大于等于月结日期的单据
-            DB::table('sync_snapshot')
-                ->where('type', $name)
-                ->where('order_date', '>=', $orderDateLimit) // 关键:缩小快照查询范围
-                ->orderBy('u8_id')
-                ->chunk(100, function ($snapshots) use ($currentU8NosLookup, $name, $time) {
-                    foreach ($snapshots as $oldSnapshot) {
-                        // 如果快照里的单号不在本次 U8 扫描结果里
-                        if (!isset($currentU8NosLookup[$oldSnapshot->u8_no])) {
-                            $this->createSyncTask($name, $oldSnapshot->u8_no, $oldSnapshot->u8_id, json_decode($oldSnapshot->payload, true), SyncTempRecord::opt_two, "", $time);
+            //只有这次分页查询完整才启动删除
+            if($isFetchSuccess){
+                // 使用 chunk 配合日期过滤,只查快照中大于等于月结日期的单据
+                DB::table('sync_snapshot')
+                    ->where('type', $name)
+                    ->where('order_date', '>=', $orderDateLimit) // 关键:缩小快照查询范围
+                    ->orderBy('u8_id')
+                    ->chunk(100, function ($snapshots) use ($currentU8NosLookup, $name, $time) {
+                        foreach ($snapshots as $oldSnapshot) {
+                            // 如果快照里的单号不在本次 U8 扫描结果里
+                            if (!isset($currentU8NosLookup[$oldSnapshot->u8_no])) {
+                                $this->createSyncTask($name, $oldSnapshot->u8_no, $oldSnapshot->u8_id, json_decode($oldSnapshot->payload, true), SyncTempRecord::opt_two, "", $time);
+                            }
                         }
-                    }
-                });
+                    });
 
-            unset($currentU8Nos); // 释放内存
+                unset($currentU8Nos); // 释放内存
+            }
         }
     }
 

+ 26 - 737
app/Service/U8ThirdPartyService.php

@@ -101,97 +101,6 @@ class U8ThirdPartyService extends Service
         return [true, ['host' => $host, 'token' => $token]];
     }
 
-   public function purchaseIn1($data){
-       if(empty($data['orderId'])) return [false, '采购到货单ID不能为空'];
-       if(empty($data['orderNo'])) return [false, '采购到货单单号不能为空'];
-       if(empty($data['detail'])) return [false, '表体信息detail不能为空'];
-
-       //获取采购到货单明细
-       $service = new U8ThirtyPartyDatabaseServerService();
-       $details_map = $service->getCGDHDetail1s($data['orderId']);
-       if(empty($details_map)) return [false, '采购到货单明细不存在'];
-
-       $existingLineNums = array_column($data['detail'], 'lineNum');
-       $maxLineNum = empty($existingLineNums) ? 0 : max($existingLineNums);
-       $body = [];
-       $seenLineNums = []; // 用于记录已经处理过的原始行号
-       foreach ($data['detail'] as $key => $value) {
-           if(empty($value['lineNum'])) return [false, '行号不能为空'];
-           if(! is_numeric($value['lineNum'])) return [false, '行号错误'];
-           if(empty($value['materialCode'])) return [false, '存货编码不能为空'];
-           if(empty($value['productDate']) || ! $this->validateProductDate($value['productDate'])) return [false, '生产日期为空或格式错误'];
-           if(empty($value['failureDate']) || ! $this->validateProductDate($value['failureDate'])) return [false, '失效日期为空或格式错误'];
-           if(empty($value['lot'])) return [false, '批号不能为空'];
-           if(empty($value['iQuantity']) || ! is_numeric($value['iQuantity'])) return [false, '存货数量错误'];
-
-           $currentLineNum = $value['lineNum'];
-
-           // 2. 判断行号是否重复
-           if (in_array($currentLineNum, $seenLineNums)) {
-               $maxLineNum++;
-               $currentLineNum = $maxLineNum;
-               $editProp = 'A'; // 或者根据你的需求设为空或其他标志
-
-               $o_tmp = $details_map[$value['materialCode']] ?? [];
-
-           } else {
-               $seenLineNums[] = $currentLineNum;
-               $editProp = 'M';
-           }
-
-           // 3. 组织最终数据
-           $body[] = [
-               'ivouchrowno' =>$currentLineNum,
-               'dPDate'      => $value['productDate'],
-               'dVDate'      => $value['failureDate'],
-               'cBatch'      => $value['lot'],
-               'iQuantity'   => $value['iQuantity'],
-               'editprop'    => $editProp,
-           ];
-       }
-
-       //调用所需
-       $host = $data['u8_data']['host'];
-       $token = $data['u8_data']['token'];
-
-       //采购到货单弃审
-       $header = ["Authorization: {$token}",'Content-Type:application/json'];
-       $url = $host . "/api/PuArrVouch/UnVerify";
-       $json = [
-           "VouchId" => $data['orderId'],
-       ];
-       $json = json_encode($json);
-
-       list($status, $result) = $this->post_helper1($url,$json, $header, 30);
-       if(! $status) return [false, $result];
-
-       if(! isset($result['code'])) return [false, '采购到货单弃审失败'];
-       if($result['code'] != 0) return [false, $result['msg']];
-
-       //采购到货单编辑并审核
-       $url = $host . "/api/PuArrVouch/Update";
-       $json_final[] = [
-            "Inum" => "PuArrVouch",
-            "data" =>[
-                "iHead" => [
-                    "cCode" => $data['orderNo'],
-                    "IsVerify" => true,
-                    "debug" => true,
-                ],
-                "iBody" => $body,
-            ],
-       ];
-
-       $json = json_encode($json_final);
-       list($status, $result) = $this->post_helper1($url,$json, $header, 30);
-       if(! $status) return [false, $result];
-
-       if(! isset($result['code'])) return [false, '采购到货单编辑并审核失败'];
-       if($result['code'] != 0) return [false, $result['msg']];
-
-       return [true, ''];
-   }
-
     /**
      * 采购到货单拆行/更新处理
      */
@@ -203,8 +112,8 @@ class U8ThirdPartyService extends Service
 
         // 1. 获取到货单明细
         $service = new U8ThirtyPartyDatabaseServerService();
-        $result = $service->getCGDHDetails($data['orderId']);
-        if (empty($result)) return [false, '采购到货单明细不存在'];
+        list($status, $result) = $service->getCGDHDetails($data['orderId']);
+        if (! $status) return [false, $result];
 
         // 取出第一行作为模板,保留 ID, cCode 等主表关联信息
         $templateRow = reset($result);
@@ -261,8 +170,8 @@ class U8ThirdPartyService extends Service
         if (!$status) return [false, $msg];
 
         //查询采购到货单
-        $order = $service->getCgOrder($data['orderId']);
-        if(empty($order)) return [false, '采购到货单不存在'];
+        list($status, $order) = $service->getCgOrder($data['orderId']);
+        if(! $status) return [false, $order];
         //生成来料报检单
         $inspect = [
             "Inum" => "ArrInspect",
@@ -326,8 +235,8 @@ class U8ThirdPartyService extends Service
 
         // 1. 获取领料申请单明细
         $service = new U8ThirtyPartyDatabaseServerService();
-        $result = $service->getLlSQDetails($data['orderId']);
-        if (empty($result)) return [false, '领料申请单明细不存在'];
+        list($status, $result) = $service->getLlSQDetails($data['orderId']);
+        if (! $status) return [false, $result];
 
         // 取出第一行作为模板,获取主表 ID
         $templateRow = reset($result);
@@ -368,8 +277,8 @@ class U8ThirdPartyService extends Service
         if (!$status) return [false, $msg];
 
         //查询领料申请单
-        $order = $service->getLLOrder($data['orderId']);
-        if(empty($order)) return [false, '领料单不存在'];
+        list($status, $order) = $service->getLLOrder($data['orderId']);
+        if(!$status) return [false, '领料单不存在'];
 
         //仓库区分出入库类别
         if($data['warehouseCode'] == "01"){
@@ -438,78 +347,13 @@ class U8ThirdPartyService extends Service
         return [true, ''];
     }
 
-    //采购到货单弃审的版本
-   public function materialOut1($data){
-       if(empty($data['orderId'])) return [false, '领料申请单ID不能为空'];
-       if(empty($data['orderNo'])) return [false, '领料申请单单号不能为空'];
-       if(empty($data['detail'])) return [false, '表体信息detail不能为空'];
-
-       $body = [];
-       foreach ($data['detail'] as $key => $value){
-           if(empty($value['lineNum'])) return [false, '行号不能为空'];
-           if(! is_numeric($value['lineNum'])) return [false, '行号错误'];
-           if(empty($value['materialCode'])) return [false, '存货编码不能为空'];
-           if(empty($value['productDate']) || ! $this->validateProductDate($value['productDate'])) return [false, '生产日期为空或格式错误'];
-           if(empty($value['failureDate']) || ! $this->validateProductDate($value['failureDate'])) return [false, '失效日期为空或格式错误'];
-           if(empty($value['lot'])) return [false, '批号不能为空'];
-           $body[] = [
-               'ivouchrowno' => $value['lineNum'],
-               'dPDate' => $value['productDate'],
-               'dVDate' => $value['failureDate'],
-               'cBatch' => $value['lot'],
-               'editprop' => 'M',
-           ];
-       }
-
-       //调用所需
-       $host = $data['u8_data']['host'];
-       $token = $data['u8_data']['token'];
-
-       //采购到货单弃审
-       $header = ["Authorization: {$token}",'Content-Type:application/json'];
-       $url = $host . "/api/PuArrVouch/UnVerify";
-       $json = [
-           "VouchId" => $data['orderId'],
-       ];
-       $json = json_encode($json);
-
-       list($status, $result) = $this->post_helper1($url,$json, $header, 30);
-       if(! $status) return [false, $result];
-
-       if(! isset($result['code'])) return [false, '采购到货单弃审失败'];
-       if($result['code'] != 0) return [false, $result['msg']];
-
-       //采购到货单编辑并审核
-       $url = $host . "/api/PuArrVouch/Update";
-       $json_final[] = [
-            "Inum" => "PuArrVouch",
-            "data" =>[
-                "iHead" => [
-                    "cCode" => $data['orderNo'],
-                    "IsVerify" => true,
-                    "debug" => true,
-                ],
-                "iBody" => $body,
-            ],
-       ];
-
-       $json = json_encode($json_final);
-       list($status, $result) = $this->post_helper1($url,$json, $header, 30);
-       if(! $status) return [false, $result];
-
-       if(! isset($result['code'])) return [false, '采购到货单编辑并审核失败'];
-       if($result['code'] != 0) return [false, $result['msg']];
-
-       return [true, ''];
-   }
-
    public function purchaseReturn($data){
         if(empty($data['orderId'])) return [false, '采购退货单ID不能为空'];
 
         // 1. 获取到货单(退货单)及明细
         $service = new U8ThirtyPartyDatabaseServerService();
-        $order = $service->getArrivalVouchById($data['orderId']);
-        if(empty($order)) return [false, '采购退货单数据不存在'];
+        list($status, $order) = $service->getArrivalVouchById($data['orderId']);
+        if(! $status) return [false, $order];
 
         // 获取 Token 相关信息
         $host = $data['u8_data']['host'] ?? "";
@@ -583,8 +427,8 @@ class U8ThirdPartyService extends Service
 
        // 1. 获取报检单明细 (建议 getBjOrder 返回以 cInvCode 为 key 的数组)
        $service = new U8ThirtyPartyDatabaseServerService();
-       $result = $service->getBjOrder($data['orderId']);
-       if (empty($result)) return [false, '报检单明细不存在'];
+       list($status,$result) = $service->getBjOrder($data['orderId']);
+       if (! $status) return [false, $result];
 
       // 取出第一行作为模板,获取主表 ID
        $templateRow = reset($result);
@@ -678,8 +522,8 @@ class U8ThirdPartyService extends Service
 
        //获取销售订单信息
        $service = new U8ThirtyPartyDatabaseServerService();
-       $order = $service->getXsOrder($data['orderId']);
-       if(empty($order)) return [false, '销售订单不存在'];
+       list($status,$order) = $service->getXsOrder($data['orderId']);
+       if(! $status) return [false, $order];
 
        $detail_map = [];
        foreach ($data['detail'] as $key => $value) {
@@ -800,8 +644,8 @@ class U8ThirdPartyService extends Service
        $id = $first['VouchId'];
 //       $id = 1000000882;
 
-       $fhOrder = $service->getFhOrder($id);
-       if(empty($fhOrder)) return [false, '销售发货单获取失败'];
+       list($status, $fhOrder) = $service->getFhOrder($id);
+       if(! $status) return [false, $fhOrder];
 
        // 2. 初始化销售出库单结构
        $saleOut = [
@@ -867,190 +711,6 @@ class U8ThirdPartyService extends Service
        return [true, ''];
    }
 
-   public function saleOut1($data){
-       if(empty($data['orderId'])) return [false, '销售订单ID不能为空'];
-       if(empty($data['orderNo'])) return [false, '销售订单号不能为空'];
-       if(empty($data['detail'])) return [false, '表体信息detail不能为空'];
-
-       //获取销售订单信息
-       $service = new U8ThirtyPartyDatabaseServerService();
-       $order = $service->getXsOrder($data['orderId']);
-       if(empty($order)) return [false, '销售订单不存在'];
-
-       $orderItemMap = [];
-       foreach ($order['details'] as $detail) {
-           // 这里的 iTaxUnitPrice 是订单里的含税单价
-           $orderItemMap[$detail['cInvCode']] = [
-               'iTaxUnitPrice' => $detail['iTaxUnitPrice'] ?? 0,
-               'iTaxRate'      => $detail['iTaxRate'] ?? 13,
-               'iUnitPrice'    => $detail['iUnitPrice'] ?? 0,
-           ];
-       }
-
-       $detail_map = [];
-       foreach ($data['detail'] as $key => $value) {
-           if(empty($value['lineNum'])) return [false, '行号不能为空'];
-           if(! is_numeric($value['lineNum'])) return [false, '行号错误'];
-           if(empty($value['materialCode'])) return [false, '存货编码不能为空'];
-           if(empty($value['productDate'])) return [false, '生产日期不能为空'];
-           $return = $this->formatAndValidateDate($value['productDate']);
-           if(! $return) return [false, '生产日期格式错误'];
-           $productDate = $return;
-           if(empty($value['failureDate'])) return [false, '失效日期不能为空'];
-           $return = $this->formatAndValidateDate($value['failureDate']);
-           if(! $return) return [false, '生产日期格式错误'];
-           $failureDate= $return;
-           if(empty($value['lot'])) return [false, '批号不能为空'];
-           if(empty($value['iQuantity']) || ! is_numeric($value['iQuantity'])) return [false, '存货数量错误'];
-           $detail_map[$value['materialCode']][] = [
-               'productDate' => $productDate,
-               'failureDate' => $failureDate,
-               'lot' => $value['lot'],
-               'iQuantity' => $value['iQuantity'],
-           ];
-       }
-
-       // 2. 组织发货单 (DispatchList) 结构
-       $tmp = [
-           "Inum" => "DispatchList",
-           "Data" => [
-               "iHead" => [
-                   "cVouchType"      => "05",
-                   "cSTCode"         => $order['cSTCode'] ?? "01",
-                   "cDepCode"        => $order['cDepCode'] ?? "01",
-                   "IsVerify"        => true,
-                   "cMemo"           => "接口生成",
-                   "dDate"           => date("Y-m-d"),
-                   "bCalPrice"       => false,
-                   "PriceCalKey"     => "iSum",
-                   "iExchRate"       => $order['iExchRate'] ?? 1,
-                   "cexch_name"      => $order['cexch_name'] ?? "人民币",
-                   "cCusCode"        => $order['cCusCode'],
-                   "iTaxRate"        => $order['iTaxRate'] ?? 13,
-                   "cinvoicecompany" => $order['cCusCode'],
-               ],
-               "iBody" => []
-           ]
-       ];
-
-        // 3. 组织表体
-       $rowKey = 0;
-       foreach ($detail_map as $invCode => $items) {
-           // 获取该存货在订单里的价格信息
-           $priceInfo = $orderItemMap[$invCode];
-
-           foreach ($items as $value) {
-               $rowKey++;
-               $quantity = $value['iQuantity'];
-               $unitPrice = $priceInfo['iTaxUnitPrice']; // 直接使用订单里的含税单价
-
-               // 计算价税合计:数量 * 含税单价
-               $sum = round($quantity * $unitPrice, 2);
-
-               $tmp["Data"]["iBody"][] = [
-                   "iRowNo"          => $rowKey,
-                   "cInvCode"        => $invCode,
-                   "iTaxRate"        => $priceInfo['iTaxRate'],
-                   "cWhCode"         => "06",
-                   "iQuantity"       => $quantity,
-                   "iSum"            => $sum,             // 总金额
-                   "iMoney"          => $sum,
-                   "cBatch"          => $value['lot'],
-                   "dMDate"          => $value['productDate'],
-                   "dvDate"          => $value['failureDate'],
-                   "iTaxUnitPrice"   => $unitPrice,       // 含税单价
-                   "iUnitPrice"      => $priceInfo['iUnitPrice'], // 原订单无税单价
-               ];
-           }
-       }
-
-       // 4. 封装成数组返回
-       $final_data = [$tmp];
-
-       //调用所需
-       $host = $data['u8_data']['host'];
-       $token = $data['u8_data']['token'];
-
-       //销售发货单
-       $header = ["Authorization: {$token}",'Content-Type:application/json'];
-       $url = $host . "/api/Dispatch/Add";
-       $json = json_encode($final_data);
-
-       list($status, $result) = $this->post_helper1($url,$json, $header, 30);
-       if(! $status) return [false, $result];
-
-       if(! isset($result['code'])) return [false, '销售发货单生成失败'];
-       if($result['code'] != 0) return [false, $result['msg']];
-
-       $first = $result['data'][0];
-       $id = $first['VouchId'];
-//       $id = 1000000882;
-
-       $fhOrder = $service->getFhOrder($id);
-       if(empty($fhOrder)) return [false, '销售发货单获取失败'];
-
-       // 2. 初始化销售出库单结构
-       $saleOut = [
-           "Inum" => "SaleOut",
-           "Data" => [
-               "iHead" => [
-                   "IsVerify" => true, // 自动审核
-                   "cWhCode"  => "06", // 仓库编码
-                   "cRdCode"  => "0299", // 出入库类别编码
-                   "cVouchType"  => "32", // 单据类型编码
-                   "cMemo"    => "接口生成",
-                   "cSource"  => "发货单",
-                   "cSTCode"  => $fhOrder['cSTCode'], // 销售类型
-                   "DLCode"   => $fhOrder['cDLCode'],  // 关联的发货单号
-                   "cDepCode" => $fhOrder['cDepCode'],  // 部门
-                   "dDate"    => date("Y-m-d"),              // 出库日期
-               ],
-               "iBody" => []
-           ]
-       ];
-
-        // 3. 遍历发货单明细组织表体
-       foreach ($fhOrder['details'] as $index => $item) {
-           // 计算待出库数量 (总发货数 - 已出库数)
-           $qty = (float)($item['iQuantity'] ?? 0);
-           $outQty = (float)($item['fOutQuantity'] ?? 0);
-           $pendingQty = $qty - $outQty;
-
-           // 如果该行已全部出库,则跳过(可选逻辑)
-           if ($pendingQty <= 0) continue;
-
-           $saleOut["Data"]["iBody"][] = [
-               "iRowNo"       => $index + 1,
-               "cInvCode"     => $item['cInvCode'] ?? "",
-               "cPosition"    => $item['cPosition'] ?? "",    // 货位
-               "cBatch"       => $item['cBatch'] ?? "",       // 批号
-               "iinvexchrate" => (float)($item['iExchRate'] ?? 1), // 换算率
-               "iQuantity"    => $pendingQty,                 // 本次出库数量
-               "iNQuantity"   => $pendingQty,                 // 对应实收数量
-               "iDLsID"       => $item['iDLsID'],             // 核心:发货单子表ID
-               "dMadeDate"       => $item['dMDate'], // 生产
-               "dVDate"       => $item['dvDate'], // 失效
-               "iUnitCost"    => (float)($item['iUnitPrice'] ?? 0), // 无税单价
-               "iPrice"       => round((float)($item['iUnitPrice'] ?? 0) * $pendingQty, 2), // 无税金额
-           ];
-       }
-
-        // 4. 封装成数组
-       $final_data = [$saleOut];
-
-       $header = ["Authorization: {$token}",'Content-Type:application/json'];
-       $url = $host . "/api/SaleOut/Add";
-       $json = json_encode($final_data);
-
-       list($status, $result) = $this->post_helper1($url,$json, $header, 30);
-       if(! $status) return [false, $result];
-
-       if(! isset($result['code'])) return [false, '销售出库单生成失败'];
-       if($result['code'] != 0) return [false, $result['msg']];
-
-       return [true, ''];
-   }
-
    public function otherIn($data) {
         // 1. 基础校验
         if (empty($data['warehouseCode'])) return [false, '仓库编码不能为空'];
@@ -1203,84 +863,13 @@ class U8ThirdPartyService extends Service
         return [true, $result];
     }
 
-   public function saleReturn1($data) {
-        if(empty($data['orderId'])) return [false, '销售退货单ID不能为空'];
-
-        // 1. 获取销售退货单/订单信息
-        $service = new U8ThirtyPartyDatabaseServerService();
-        $order = $service->getXsThOrder($data['orderId']);
-        if(empty($order)) return [false, '销售退货单信息不存在'];
-
-        $iBody = [];
-        foreach ($order['details'] as $key => $value) {
-            // 确保数量为负数(红字单据要求)
-            $qty = (float)($value['iQuantity'] ?? 0);
-            $redQty = $qty > 0 ? -$qty : $qty;
-
-            $iBody[] = [
-                "iRowNo"       => $key + 1,
-                "cInvCode"     => $value['cInvCode'],      // 存货编码
-                "cPosition"    => $value['cPosition'] ?? "", // 货位
-                "cBatch"       => $value['cBatch'] ?? "",    // 批号
-                "iinvexchrate" => (float)($value['iinvexchrate'] ?? 1),
-                "iQuantity"    => $redQty,                 // 红字数量
-                "iNQuantity"   => $redQty,                 // 实退数量
-                "iNum"         => (float)($value['iNum'] ?? 0),
-                "iNNum"        => (float)($value['iNum'] ?? 0),
-                // 核心关联:如果是参照发货单退货,需要 iDLsID (发货单子表Autoid)
-                "iDLsID"       => $value['iDLsID'] ?? 0,
-                "dMadeDate"    => $value['dMDate'], // 生产日期
-                "dVDate"       => $value['dvDate'],    // 失效日期
-            ];
-        }
-
-        // 2. 组织表头 (iHead)
-        $iHead = [
-            "IsVerify"     => $data['IsVerify'] ?? false,  // 是否自动审核
-            "bIsRedVouch"  => true,                        // 核心:必须为 true (红字单据)
-            "cWhCode"      => $order['cWhCode'], // 仓库
-            "cRdCode"      => $order['cRdCode'],    // 收发类别(如:销售出库/退货)
-            "cMemo"        => "接口生成",
-            "cSource"      => "发货单",                     // 来源类型
-            "cSTCode"      => $order['cSTCode'],   // 销售类型
-            "DLCode"       => $order['cDLCode'],     // 关联的发货单号
-            "dDate"        => date("Y-m-d"),               // 单据日期
-        ];
-
-        // 3. 封装成 SaleOut 结构
-        $final_data = [
-            [
-                "Inum" => "SaleOut",
-                "Data" => [
-                    "iHead" => $iHead,
-                    "iBody" => $iBody
-                ]
-            ]
-        ];
-
-        // 4. 发送请求
-        $host = $data['u8_data']['host'] ?? "";
-        $token = $data['u8_data']['token'] ?? "";
-        $url = $host . "/api/SaleOut/Add";
-        $header = ["Authorization: {$token}", 'Content-Type:application/json'];
-
-        $json = json_encode($final_data);
-        list($status, $result) = $this->post_helper1($url, $json, $header, 30);
-        if(! $status) return [false, $result];
-
-        if(! isset($result['code'])) return [false, '红字销售出库单生成失败'];
-        if($result['code'] != 0) return [false, $result['msg']];
-
-        return [true, $result];
-    }
-
     public function saleReturn($data) {
         if(empty($data['orderId'])) return [false, '销售退货单ID不能为空'];
 
         // 1. 获取销售退货单信息 (DispatchList & DispatchLists)
         $service = new U8ThirtyPartyDatabaseServerService();
-        $order = $service->getXsThOrder($data['orderId']);
-        if(empty($order)) return [false, '销售退货单信息不存在'];
+        list($status, $order) = $service->getXsThOrder($data['orderId']);
+        if(! $status) return [false, $order];
 
         // --- 核心修改:按仓库分组 ---
         $groupDetails = [];
@@ -1367,12 +956,12 @@ class U8ThirdPartyService extends Service
 
         // 获取单据 产品检验单
         $service = new U8ThirtyPartyDatabaseServerService();
-        $order = $service->getJyOrder($id);
-        if(empty($order)) return [false, '产品检验单不存在'];
+        list($status, $order) = $service->getJyOrder($id);
+        if(! $status) return [false, $order];
 
         // 获取单据 生产订单子表 (用于获取生产订单累计数量 iNQuantity)
-        $product_detail = $service->getScDetails($order['SOURCEID']);
-        if(empty($product_detail)) return [false, '生产订单子表数据不存在'];
+        list($status, $product_detail) = $service->getScDetails($order['SOURCEID']);
+        if(! $status) return [false, $product_detail];
 
         // u8 token 获取
         list($status, $msg) = $this->getToken();
@@ -1434,153 +1023,6 @@ class U8ThirdPartyService extends Service
         return [true, ''];
     }
 
-   public function productInByZj2($data){
-       $record = $data['record'];
-       $payload = $data['payload'];
-       $id = $record['u8_id'];
-       $type = $data['type'];
-       if($type == 1){
-           $num = $payload['hg_quantity'];
-       }else{
-           $num = $payload['rb_quantity'];
-       }
-
-       //获取单据 产品检验单
-       $service = new U8ThirtyPartyDatabaseServerService();
-       $order = $service->getJyOrder($id);
-       if(empty($order)) return [false, '产品检验单不存在'];
-
-       //获取单据 生产订单子表
-       $product_detail = $service->getScDetails($order['SOURCEID']);
-       if(empty($product_detail)) return [false, '生产订单子表数据不存在'];
-
-       //u8 token
-       list($status, $msg) = $this->getToken();
-       if(! $status) return [false, $msg];
-
-       $tmp = [
-           "Inum" => "ProductIn",
-           "Data" => [
-               "iHead" => [
-                   "IsVerify"    => true,
-                   "cWhCode"     => "06", // 产成品库
-                   "cRdCode"     => '0103', // 入库类别 产成品入库
-                   "cDepCode"    => $order['CINSPECTDEPCODE'] ?? '',     // 部门
-                   "cMemo"       => "接口生成",
-                   "cSource"     => "产品检验单",
-                   "cBusType"    => "成品入库",
-                   "cMPoCode"    => $order['SOURCECODE'], // 生产订单号
-                   "cChkCode"    => $order['CCHECKCODE'], // 检验单号
-                   "dDate"       => date("Y-m-d"),
-                   "bIsRedVouch" => false,  // 如果是红字入库请设为true
-                   "bCalPrice"   => true, // 是否由接口计算金额
-               ],
-               "iBody" => []
-           ]
-       ];
-       //一个检验单只有一行
-       $tmp["Data"]["iBody"][] = [
-           "iRowNo"       => 1,
-           "cInvCode"     => $order['cInvCode'] ?? '',
-           "cAssUnit"     => $order['CUNITID'] ?? '',
-           "cPosition"    => $order['cPosition'] ?? '',
-           "cBatch"       => $order['cBatch'] ?? '',
-           "iinvexchrate" => $order['FCHANGRATE'] ?? 0,
-           "iQuantity"    => $num,   // 数量
-           "iNQuantity"   => $product_detail['Qty'], // 生产订单产品数量
-           "iMPoIds"      => $order['SOURCEAUTOID'] ?? 0,  // 生产订单子表ID
-           "dMadeDate"    => $order['DPRODATE'] ?? '',        // 生产日期
-           "iMassDate"    => $order['IMASSDATE'],  // 保质期
-           "cMassUnit"    => $order['CMASSUNIT'], // 保质期单位
-           "dVDate"       => $order['DVDATE'] ?? '', // 失效日期
-       ];
-       $final_data = [$tmp];
-
-       //调用所需
-       $host = $msg['host'] ?? "";
-       $token = $msg['token'] ?? "";
-
-       //产成品入库单生成
-       $header = ["Authorization: {$token}",'Content-Type:application/json'];
-       $url = $host . "/api/ProductIn/Add";
-
-       $json = json_encode($final_data);
-       list($status, $result) = $this->post_helper1($url, $json, $header, 30);
-       if(! $status) return [false, $result];
-
-       if(! isset($result['code'])) return [false, '产成品入库单生成并审核失败'];
-       if($result['code'] != 0) return [false, $result['msg']];
-
-       return [true, ''];
-   }
-
-    public function productInByZj1($data){
-        $record = $data['record'];
-        $payload = $data['payload'];
-        $id = $record['u8_id'];
-        $type = $data['type'];
-
-        // 确定入库数量
-        $num = ($type == 1) ? $payload['hg_quantity'] : $payload['rb_quantity'];
-
-        // 1. 获取检验单数据(用于提取物料、批次、仓库等基本信息,即便不参照也需要这些数据)
-        $service = new U8ThirtyPartyDatabaseServerService();
-        $order = $service->getJyOrder($id);
-        if(empty($order)) return [false, '产品检验单不存在'];
-
-        // 2. 获取 U8 Token
-        list($status, $msg) = $this->getToken();
-        if(! $status) return [false, $msg];
-
-        // 3. 组织产成品入库单 (不参照模式)
-        $tmp = [
-            "Inum" => "ProductIn",
-            "Data" => [
-                "iHead" => [
-                    "IsVerify"    => true,           // 自动审核
-                    "cWhCode"     => $order['CWHCODE'] ?? "06", // 产成品库
-                    "cRdCode"     => '0103',           // 产成品入库类别编码 (根据U8实际修改,通常为12)
-                    "cDepCode"    => $order['CINSPECTDEPCODE'],
-                    "cMemo"       => "接口生成",
-                    "cSource"     => "库存",         // 关键:设为库存即为手动入库
-                    "cBusType"    => "成品入库",
-                    "dDate"       => date("Y-m-d"),
-                    "bIsRedVouch" => false,
-                    "bCalPrice"   => true,
-                ],
-                "iBody" => [
-                    [
-                        "iRowNo"       => 1,
-                        "cInvCode"     => $order['CINVCODE'] ?? '',
-                        "cBatch"       => $order['CBATCH'] ?? '',
-                        "iinvexchrate" => $order['FCHANGRATE'] ?? 0,
-                        "iQuantity"    => $num,       // 入库数量
-                        "iNQuantity"   => $num,       // 保持一致
-                        "dMadeDate"    => $order['DPRODATE'] ?? '', // 生产日期
-                        "dVDate"       => $order['DVDATE'] ?? '',   // 失效日期
-                    ]
-                ]
-            ]
-        ];
-
-        $final_data = [$tmp];
-
-        // 4. 调用接口
-        $host = $msg['host'] ?? "";
-        $token = $msg['token'] ?? "";
-        $header = ["Authorization: {$token}", 'Content-Type:application/json'];
-        $url = $host . "/api/ProductIn/Add";
-
-        $json = json_encode($final_data);
-        list($status, $result) = $this->post_helper1($url, $json, $header, 30);
-
-        if(! $status) return [false, $result];
-        if(! isset($result['code'])) return [false, '产成品入库单生成失败'];
-        if($result['code'] != 0) return [false, $result['msg']];
-
-        return [true, ''];
-    }
-
    //检验单生成其他入库单
    public function otherInByZj($data){
        $record = $data['record'];
@@ -1590,8 +1032,8 @@ class U8ThirdPartyService extends Service
 
        //获取单据 检验单
        $service = new U8ThirtyPartyDatabaseServerService();
-       $order = $service->getJyOrder($id);
-       if(empty($order)) return [false, '检验单不存在'];
+       list($status, $order) = $service->getJyOrder($id);
+       if(! $status) return [false, $order];
 
        //u8 token
        list($status, $msg) = $this->getToken();
@@ -1645,159 +1087,6 @@ class U8ThirdPartyService extends Service
        return [true, ''];
    }
 
-   //检验单生产采购入库单
-   public function purchaseInByZj2($data)
-    {
-        $record = $data['record'];
-        $payload = $data['payload'];
-        $id = $record['u8_id']; // 这里的 ID 应该是检验单主表的 ID
-        $type = $data['type'];
-
-        if($type == 1){
-            $num = $payload['hg_quantity'];
-        }else{
-            $num = $payload['rb_quantity'];
-        }
-
-        // 1. 获取检验单明细 (需要包含来源到货单子表ID: SOURCEAUTOID)
-        $service = new U8ThirtyPartyDatabaseServerService();
-        $order = $service->getJyOrder2($id);
-        if(empty($order)) return [false, '检验单不存在'];
-
-        // 2. 获取 U8 Token
-        list($status, $msg) = $this->getToken();
-        if(! $status) return [false, $msg];
-
-        // 3. 组织采购入库单 (PurchaseIn) 结构
-        $tmp = [
-            "Inum" => "PurchaseIn",
-            "Data" => [
-                "iHead" => [
-                    "IsVerify"    => true,          // 自动审核
-                    "bCalPrice"   => true,          // 自动计算价格
-                    "cWhCode"     => $order['CWHCODE'],  // 仓库编码
-                    "cRdCode"     => "0101",          // 入库类别:原材料采购入库
-                    "cSource"     => "来料检验单",   // 来源
-                    "cBusType"    => "普通采购",
-                    "cChkCode"    => $order['CCHECKCODE'] ?? '', // 关联检验单号
-                    "cMemo"       => "接口生成",
-                    "dDate"       => date("Y-m-d"),
-                ],
-                "iBody" => []
-            ]
-        ];
-
-        // 4. 组织表体
-        $tmp["Data"]["iBody"][] = [
-            "iRowNo"       => 1,
-            "cInvCode"     => $order['CINVCODE'] ?? '',
-            "cPosition"    => $order['cPosition'] ?? '',
-            "cBatch"       => $order['CBATCH'],
-            "iinvexchrate" => (float)($order['FCHANGRATE'] ?? 1),
-            "iQuantity"    => $num,            // 应收数量(入库数量)
-            "iNQuantity"   => $num,            // 实收数量
-            "iArrsId"      => $order['SOURCEAUTOID'], // 子表id
-            "dMadeDate"    => $order['DPRODATE'], // 生产日期
-            "dVDate"       => $order['DVDATE'],   // 失效日期
-            "iUnitCost"    => $order['iCost'] ?? 0,
-            "iPrice"       => round(($order['iCost'] ?? 0) * $num, 2),
-            "iTaxUnitPrice"=> $order['iOriTaxCost'] ?? 0,
-            "iSum"         => round(($order['iOriTaxCost'] ?? 0) * $num, 2),
-            "iTaxRate"     => $order['iTaxRate'] ?? 0,
-        ];
-
-        $final_data = [$tmp];
-
-        // 5. 调用 API
-        $host = $msg['host'] ?? "";
-        $token = $msg['token'] ?? "";
-        $header = ["Authorization: {$token}", 'Content-Type:application/json'];
-        $url = $host . "/api/PurchaseIn/Add";
-
-        $json = json_encode($final_data);
-        list($status, $result) = $this->post_helper1($url, $json, $header, 30);
-
-        if(! $status) return [false, $result];
-        if(! isset($result['code'])) return [false, '采购入库单生成失败'];
-        if($result['code'] != 0) return [false, $result['msg']];
-
-        return [true, ''];
-    }
-
-    public function purchaseInByZj1($data)
-    {
-        $record = $data['record'];
-        $payload = $data['payload'];
-        $type = $data['type'];
-
-        // 确定入库数量
-        $num = ($type == 1) ? $payload['hg_quantity'] : $payload['rb_quantity'];
-
-        // 1. 获取基础数据 (即使不参照,我们也需要从检验单拿到物料、仓库、供应商等基本信息)
-        $service = new U8ThirtyPartyDatabaseServerService();
-        $order = $service->getJyOrder2($record['u8_id']);
-        if(empty($order)) return [false, '检验单不存在'];
-
-        // 2. 获取 U8 Token
-        list($status, $msg) = $this->getToken();
-        if(! $status) return [false, $msg];
-
-        // 3. 组织采购入库单 (不参照模式)
-        $tmp = [
-            "Inum" => "PurchaseIn",
-            "Data" => [
-                "iHead" => [
-                    "IsVerify"      => true,          // 自动审核
-                    "bCalPrice"     => true,          // 自动计算价格
-                    "PriceCalKey"   => "iOriTaxCost", // 以含税单价为准计算
-                    "cWhCode"       => "01", // 仓库
-                    "cVenCode"      => $order['CVENCODE'],  // 供应商(不参照时必填)
-                    "cPTCode"       => "01",          // 采购类型:委外或普通
-                    "cRdCode"       => "0101",          // 入库类别编码
-                    "cDepCode"      => $order['CDEPCODE'] ?? '',  // 部门
-                    "cBusType"      => "普通采购",
-                    "cSource"       => "库存",         // 设为库存即为不参照模式
-                    "cMemo"         => "接口生成",
-                    "dDate"         => date("Y-m-d"),
-                    "cExch_Name"    => "人民币",
-                    "iExchRate"     => 1,
-                ],
-                "iBody" => [
-                    [
-                        "iRowNo"        => 1,
-                        "cInvCode"      => $order['CINVCODE'],
-                        "cPosition"     => $order['CPOSITION'] ?? '',
-                        "cBatch"        => $order['CBATCH'] ?? '',
-                        "iQuantity"     => $num,            // 数量
-                        "iNQuantity"    => $num,            // 实收数量
-                        "iOriTaxCost"   => $order['iOriTaxCost'], // 含税单价
-                        "iTaxRate"      => $order['iTaxRate'],   // 税率
-                        "dMadeDate"    => $order['DPRODATE'], // 生产日期
-                        "dVDate"       => $order['DVDATE'],   // 失效日期
-                        // 注意:不参照时,不要传 iArrsId
-                    ]
-                ]
-            ]
-        ];
-
-        $final_data = [$tmp];
-
-        // 4. 调用 API
-        $host = $msg['host'] ?? "";
-        $token = $msg['token'] ?? "";
-        $header = ["Authorization: {$token}", 'Content-Type:application/json'];
-        $url = $host . "/api/PurchaseIn/Add";
-
-        $json = json_encode($final_data);
-        list($status, $result) = $this->post_helper1($url, $json, $header, 30);
-
-        if(! $status) return [false, $result];
-        if(! isset($result['code'])) return [false, '采购入库单生成失败'];
-        if($result['code'] != 0) return [false, $result['msg']];
-
-        return [true, ''];
-    }
-
     public function purchaseInByZj($data)
     {
         $record = $data['record'];
@@ -1809,8 +1098,8 @@ class U8ThirdPartyService extends Service
 
         // 1. 获取基础数据 (检验单信息)
         $service = new U8ThirtyPartyDatabaseServerService();
-        $order = $service->getJyOrder2($record['u8_id']);
-        if(empty($order)) return [false, '检验单不存在'];
+        list($status, $order) = $service->getJyOrder2($record['u8_id']);
+        if(! $status || empty($order)) return [false, '检验单不存在'];
 
         // 2. 获取 U8 Token
         list($status, $msg) = $this->getToken();

Plik diff jest za duży
+ 376 - 457
app/Service/U8ThirtyPartyDatabaseServerService.php


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików