cqp há 2 dias atrás
pai
commit
5551c045ea
3 ficheiros alterados com 275 adições e 0 exclusões
  1. 11 0
      app/Http/Controllers/Api/TestController.php
  2. 263 0
      app/Service/TestService.php
  3. 1 0
      routes/api.php

+ 11 - 0
app/Http/Controllers/Api/TestController.php

@@ -98,6 +98,17 @@ class TestController extends BaseController
         }
     }
 
+    public function purchaseInAddU8(Request $request){
+        $common_array = $request->common_param;
+        list($bool, $data) = (new TestService())->purchaseInByZj($request->all(), $common_array);
+
+        if($bool){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function dispatchAddU8(Request $request){
         $common_array = $request->common_param;
         list($bool, $data) = (new TestService())->DispatchAddU8($request->all(), $common_array);

+ 263 - 0
app/Service/TestService.php

@@ -587,6 +587,269 @@ class TestService extends Service
         return [$status, $msg];
     }
 
+    //检验单(不是用友的检验单 所以不是参照)生成产成品入库单
+    public function productInByZj($data, $common_array){
+        // u8 token 获取
+        list($status, $msg) = $this->getToken($common_array);
+        if(! $status) return [false, $msg];
+        $title = $common_array['title'];
+
+        // 组织 ProductIn 结构
+        $tmp = [
+            "Inum" => "ProductIn",
+            "Data" => [
+                "iHead" => [
+                    "cWhCode"     => $data['warehouseCode'] ?? "01", // 默认产成品库
+                    "cRdCode"     => "105", // 入库类别
+                    "cDepCode"    => null,
+                    "cMemo"       => "接口生成",
+                    "cSource"     => "库存",
+                    "cBusType"    => "成品入库",
+                    "dDate"       => date("Y-m-d"),
+                    "IsVerify"    => true,
+                ],
+                "iBody" => []
+            ]
+        ];
+
+        //合格数量加让步接收数量
+        $num = $data['quality_receive_num'] ?? 0;
+        $num2 = $data['compromise_receive_num'] ?? 0;
+        $num = bcadd($num, $num2,2);
+
+        //产品编码
+        $product_code = $data['material_code'] ?? "";
+
+        $baseData = [
+            "iRowNo"    => 1,
+            "cInvCode"  => $product_code,
+            "iQuantity" => $num,
+        ];
+
+        if ($common_array['site'] == "LFMY") {
+            // 朗峰结构 (cdefine28 - cdefine33)
+            $extData = [
+                'cdefine28' => $data['brand_name'] ?? null,
+                'cdefine29' => $data['safe'] ?? null,
+                'cdefine30' => $data['decor'] ?? null,
+                'cdefine31' => $data['craft_type_code'] ?? null,
+                'cdefine32' => $data['decor_b'] ?? null,
+                'cdefine33' => $data['craft_type_code_b'] ?? null,
+            ];
+        } elseif ($common_array['site'] == "HCLT") {
+            // 恒昌结构 (cfree + cdefine22/23 + cdefine28-31)
+            $extData = [
+                'cfree1'    => $data['customer_brand'] ?? null,
+                'cfree2'    => $data['color'] ?? null,
+                'cdefine22' => $data['plan_no'] ?? null,
+                'cdefine23' => $data['contract_no'] ?? null,
+                'cdefine28' => $data['technical_require'] ?? null,
+                'cdefine29' => $data['quality_require'] ?? null,
+                'cdefine30' => $data['package_require'] ?? null,
+                'cdefine31' => $data['shipping_mark'] ?? null,
+            ];
+        } else {
+            $extData = [];
+        }
+
+        $inventoryEntry = array_merge($baseData, $extData);
+
+        // 组织表体
+        $tmp["Data"]["iBody"][] = $inventoryEntry;
+
+        $final_data = [$tmp];
+
+        // 调用参数
+        $host = $msg['host'] ?? "";
+        $token = $msg['token'] ?? "";
+        $url = $host . "/api/ProductIn/Add";
+        $header = ["Authorization: {$token}", 'Content-Type:application/json'];
+
+        $json = json_encode($final_data);
+
+        list($status, $result) = $this->post_helper($url, json_encode($json), $header, 60, $title . '生成产成品入库单');
+        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, $common_array)
+    {
+        // u8 token 获取
+        list($status, $msg) = $this->getToken($common_array);
+        if(! $status) return [false, $msg];
+        $title = $common_array['title'];
+
+        //合格数量加让步接收数量
+        $num = $data['quality_receive_num'] ?? 0;
+        $num2 = $data['compromise_receive_num'] ?? 0;
+        $num = bcadd($num, $num2,2);
+        $qty = $num;
+        $taxRate = $data['tax_rate'] ?? 0; // 税率
+        $taxUnitPrice = $data['tax_price'] ?? 0; // 原币含税单价
+
+        // 1. 价税合计 (iSum)
+        $iSum = round($qty * $taxUnitPrice, 2);
+        // 2. 原币无税金额 (imoney) = 价税合计 / (1 + 税率/100)
+        $iMoney = round($iSum / (1 + ($taxRate / 100)), 2);
+        // 3. 税额 (itax)
+        $iTax = round($iSum - $iMoney, 2);
+        // 4. 原币无税单价 (iunitprice)
+        $iUnitPrice = round($taxUnitPrice / (1 + ($taxRate / 100)), 6);
+
+        $baseData = [
+            "iRowNo"    => 1,
+            "cInvCode"      => $data['material_code'],
+            "iQuantity"     => $qty,
+            "iOriTaxCost"   => (float)$taxUnitPrice, // 原币含税单价
+            "iOriCost"      => (float)$iUnitPrice,    // 原币无税单价
+            "iOriMoney"     => (float)$iMoney,       // 原币无税金额
+            "iOriTaxPrice"  => (float)$iTax,         // 原币税额
+            "iOriSum"       => (float)$iSum,         // 原币价税合计
+            "iTaxRate"      => (float)$taxRate,      // 税率
+            "cBatch"        => $data['cBatch'] ?? null,
+            "dMadeDate"     => $data['dMadeDate'] ?? null,
+            "dVDate"        => $data['dVDate'] ?? null,
+        ];
+
+        if ($common_array['site'] == "LFMY") {
+            // 朗峰结构 (cdefine28 - cdefine33)
+            $extData = [
+                'cdefine28' => $data['brand_name'] ?? null,
+                'cdefine29' => $data['safe'] ?? null,
+                'cdefine30' => $data['decor'] ?? null,
+                'cdefine31' => $data['craft_type_code'] ?? null,
+                'cdefine32' => $data['decor_b'] ?? null,
+                'cdefine33' => $data['craft_type_code_b'] ?? null,
+            ];
+        } elseif ($common_array['site'] == "HCLT") {
+            // 恒昌结构 (cfree + cdefine22/23 + cdefine28-31)
+            $extData = [
+                'cfree1'    => $data['customer_brand'] ?? null,
+                'cfree2'    => $data['color'] ?? null,
+                'cdefine22' => $data['plan_no'] ?? null,
+                'cdefine23' => $data['contract_no'] ?? null,
+                'cdefine28' => $data['technical_require'] ?? null,
+                'cdefine29' => $data['quality_require'] ?? null,
+                'cdefine30' => $data['package_require'] ?? null,
+                'cdefine31' => $data['shipping_mark'] ?? null,
+            ];
+        } else {
+            $extData = [];
+        }
+
+        $inventoryEntry = array_merge($baseData, $extData);
+
+        // 3. 组织采购入库单
+        $tmp = [
+            "Inum" => "PurchaseIn",
+            "Data" => [
+                "iHead" => [
+                    "IsVerify"      => true,
+                    "bCalPrice"     => true,          // 开启自动计算
+                    "PriceCalKey"   => "iOriTaxCost", // 以含税单价为准
+                    "cWhCode"       => $data['warehouseCode'] ?? "",
+                    "cVenCode"      => $data['supplierCode'] ?? "",
+                    "cRdCode"       => $data['cRdCode'] ?? "101", //收发类别
+                    "iExchRate"     => $data['iExchRate'] ?? 1.0,
+                    "iTaxRate"      => (float)$taxRate,
+                    "cExch_Name"    => "人民币",
+                    "cSource"       => "库存",
+                    "cBusType"      => "普通采购",
+                    "cMemo"         => "接口生成",
+                    "dDate"         => date("Y-m-d"),
+                ],
+                "iBody" => $inventoryEntry
+            ]
+        ];
+
+        $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_helper($url, json_encode($json), $header, 60, $title . '生成采购入库单');
+
+        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'];
+        $payload = $data['payload'];
+        $id = $record['u8_id'];
+        $num = $payload['hg_not_quantity'];
+
+        //获取单据 检验单
+        $service = new U8ThirtyPartyDatabaseServerService();
+        list($status, $order) = $service->getJyOrder($id);
+        if(! $status) return [false, $order];
+
+        //u8 token
+        list($status, $msg) = $this->getToken();
+        if(! $status) return [false, $msg];
+
+        $tmp = [
+            "Inum" => "OtherIn",
+            "Data" => [
+                "iHead" => [
+                    "IsVerify"    => true,
+                    "cWhCode"     => "53", // 成品不良品库
+                    "cRdCode"     => '0109', // 入库类别 其他入库
+                    "cDepCode"    => '',     // 部门
+                    "cMemo"       => "接口生成",
+                    "dDate"       => date("Y-m-d"),
+                ],
+                "iBody" => []
+            ]
+        ];
+        //一个检验单只有一行
+        $tmp["Data"]["iBody"][] = [
+            "iRowNo"       => 1,
+            "cInvCode"     => $order['CINVCODE'] ?? '',
+            "cAssUnit"     => $order['CUNITID'] ?? '',
+            "cPosition"    => $order['cPosition'] ?? '',
+            "cBatch"       => $order['CBATCH'] ?? '',
+            "iinvexchrate" => $order['FCHANGRATE'] ?? 0,
+            "iQuantity"    => $num,   // 数量
+            "dMadeDate"    => $order['DPRODATE'] ?? '', // 生产日期
+            "dVDate"       => $order['DVDATE'] ?? '',
+            'cFree1' => $order['CFREE1'] ?? null,
+            'cFree2' => $order['CFREE2'] ?? null,
+        ];
+        $final_data = [$tmp];
+
+        //调用所需
+        $host = $msg['host'] ?? "";
+        $token = $msg['token'] ?? "";
+
+        //产成品入库单生成
+        $header = ["Authorization: {$token}",'Content-Type:application/json'];
+        $url = $host . "/api/OtherIn/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, ''];
+    }
+
     //-----------------------------------朗峰u8-----
     public function post_helper($url, $data, $header = [], $timeout = 20, $title = ""){
         Log::channel('apiLog')->info($title . 'POST', ["api" => $url , "param" => json_decode($data,true) ,"header" => $header]);

+ 1 - 0
routes/api.php

@@ -72,6 +72,7 @@ Route::group(['middleware'=> ['CheckU8']],function ($route){
     $route->any('purchaseOrderGet', 'Api\TestController@purchaseOrderGet');
     $route->any('materialAddU8', 'Api\TestController@materialAddU8')->middleware('U8Deal');
     $route->any('productInAddU8', 'Api\TestController@productInAddU8')->middleware('U8Deal');
+    $route->any('purchaseInAddU8', 'Api\TestController@purchaseInAddU8')->middleware('U8Deal');
     $route->any('dispatchAddU8', 'Api\TestController@dispatchAddU8')->middleware('U8Deal');
 });