|
@@ -686,7 +686,7 @@ class ProcessDataJob implements ShouldQueue
|
|
|
* @param object $service 用友数据库连接实例 (DB Service)
|
|
* @param object $service 用友数据库连接实例 (DB Service)
|
|
|
* @return array [bool, string]
|
|
* @return array [bool, string]
|
|
|
*/
|
|
*/
|
|
|
- public function inventoryAddToU8($data, $username, $service)
|
|
|
|
|
|
|
+ public function inventoryAddToU83($data, $username, $service)
|
|
|
{
|
|
{
|
|
|
// 1. 获取本地存货记录
|
|
// 1. 获取本地存货记录
|
|
|
$inventory = Inventory::where('del_time', 0)
|
|
$inventory = Inventory::where('del_time', 0)
|
|
@@ -860,6 +860,205 @@ class ProcessDataJob implements ShouldQueue
|
|
|
return [true, '同步成功'];
|
|
return [true, '同步成功'];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function inventoryAddToU8($data, $username, $service)
|
|
|
|
|
+ {
|
|
|
|
|
+ // 1. 获取本地存货记录
|
|
|
|
|
+ $inventory = Inventory::where('del_time', 0)
|
|
|
|
|
+ ->where('order_number', $data['order_number'])
|
|
|
|
|
+ ->where('login_type', $data['login_type'])
|
|
|
|
|
+ ->first();
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($inventory)) {
|
|
|
|
|
+ return [false, '本地存货记录不存在或已被删除'];
|
|
|
|
|
+ }
|
|
|
|
|
+ $inventory = $inventory->toArray();
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 提取核心属性变量
|
|
|
|
|
+ $bSale = (int)($inventory['bSale'] ?? 0);
|
|
|
|
|
+ $bExpSale = (int)($inventory['bExpSale'] ?? 0);
|
|
|
|
|
+ $bPurchase = (int)($inventory['bPurchase'] ?? 0);
|
|
|
|
|
+ $bSelf = (int)($inventory['bSelf'] ?? 0);
|
|
|
|
|
+ $bComsume = (int)($inventory['bComsume'] ?? 0);
|
|
|
|
|
+ $bProxy = (int)($inventory['bProxy'] ?? 0);
|
|
|
|
|
+
|
|
|
|
|
+ // --- 用友业务规则动态计算 ---
|
|
|
|
|
+ $iPlanDefault = $bSelf ? 1 : ($bProxy ? 2 : ($bPurchase ? 3 : 0));
|
|
|
|
|
+ $bBomMain = ($bSelf || $bProxy) ? 1 : 0;
|
|
|
|
|
+ $bBomSub = ($bSelf || $bProxy || $bPurchase || $bComsume) ? 1 : 0;
|
|
|
|
|
+ $bProductBill = $bSelf ? 1 : 0;
|
|
|
|
|
+ $cPlanMethod = 'R';
|
|
|
|
|
+ $bInTotalCost = 1;
|
|
|
|
|
+ if (!$bSale && !$bExpSale && !$bComsume && $bBomSub) {
|
|
|
|
|
+ $cPlanMethod = 'N';
|
|
|
|
|
+ $bInTotalCost = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 编码生成逻辑
|
|
|
|
|
+ $category_code = $inventory['category_code'];
|
|
|
|
|
+ $serialInfo = null;
|
|
|
|
|
+ if (!empty($data['code'])) {
|
|
|
|
|
+ $no = $data['code'];
|
|
|
|
|
+ $flag_title = "重填";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ list($status, $res) = $this->generate('inventory', $category_code, $service);
|
|
|
|
|
+ if (!$status) return [false, "生成存货编码失败: " . $res];
|
|
|
|
|
+ $no = $res['finalCode'];
|
|
|
|
|
+ $serialInfo = $res;
|
|
|
|
|
+ $flag_title = "重试";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 构建 Inventory 主表数据
|
|
|
|
|
+ $inventoryData = [
|
|
|
|
|
+ 'cInvCode' => $no,
|
|
|
|
|
+ 'cInvName' => $inventory['title'],
|
|
|
|
|
+ 'cInvCCode' => $category_code,
|
|
|
|
|
+ 'cInvStd' => $inventory['size'] ?? null,
|
|
|
|
|
+ 'bSale' => $bSale,
|
|
|
|
|
+ 'bExpSale' => $bExpSale,
|
|
|
|
|
+ 'bPurchase' => $bPurchase,
|
|
|
|
|
+ 'bSelf' => $bSelf,
|
|
|
|
|
+ 'bComsume' => $bComsume,
|
|
|
|
|
+ 'bProxyForeign' => $bProxy,
|
|
|
|
|
+ 'iGroupType' => $inventory['unit_group_type'],
|
|
|
|
|
+ 'cGroupCode' => $inventory['unit_group_code'],
|
|
|
|
|
+ 'cComUnitCode' => $inventory['unit_code'],
|
|
|
|
|
+ 'cShopUnit' => $inventory['unit_code'],
|
|
|
|
|
+ 'iImpTaxRate' => $inventory['iImpTaxRate'],
|
|
|
|
|
+ 'iTaxRate' => $inventory['iTaxRate'],
|
|
|
|
|
+ 'dSDate' => date("Y-m-d 00:00:00.000"),
|
|
|
|
|
+ 'cEnterprise' => $inventory['vendor_code_title'] ?? null,
|
|
|
|
|
+ 'iSupplyType' => '0',
|
|
|
|
|
+ 'fConvertRate' => '1.0',
|
|
|
|
|
+ 'bInTotalCost' => $bInTotalCost,
|
|
|
|
|
+ 'cPlanMethod' => $cPlanMethod,
|
|
|
|
|
+ 'cSRPolicy' => 'PE',
|
|
|
|
|
+ 'bBomMain' => $bBomMain,
|
|
|
|
|
+ 'bBomSub' => $bBomSub,
|
|
|
|
|
+ 'bProductBill' => $bProductBill,
|
|
|
|
|
+ 'iPlanDefault' => $iPlanDefault,
|
|
|
|
|
+ 'iAllocatePrintDgt' => '4',
|
|
|
|
|
+ 'bService' => '0',
|
|
|
|
|
+ 'bAccessary' => '0',
|
|
|
|
|
+ 'iInvAdvance' => '0.0',
|
|
|
|
|
+ 'bInvQuality' => '0',
|
|
|
|
|
+ 'bInvBatch' => '0',
|
|
|
|
|
+ 'bInvEntrust' => '0',
|
|
|
|
|
+ 'bInvOverStock' => '0',
|
|
|
|
|
+ 'cCreatePerson' => $username,
|
|
|
|
|
+ 'dModifyDate' => date("Y-m-d H:i:s.000"),
|
|
|
|
|
+ 'bPlanInv' => '0',
|
|
|
|
|
+ 'bATOModel' => '0',
|
|
|
|
|
+ 'bPTOModel' => '0',
|
|
|
|
|
+ 'bMPS' => ($iPlanDefault == 1 || $iPlanDefault == 2) ? '1' : '0',
|
|
|
|
|
+ 'bROP' => '0',
|
|
|
|
|
+ 'bRePlan' => '0',
|
|
|
|
|
+ 'bCutMantissa' => '0',
|
|
|
|
|
+ 'bCheckBSATP' => '0',
|
|
|
|
|
+ 'iCheckATP' => '0',
|
|
|
|
|
+ 'bFree1' => '0', 'bFree2' => '0', 'bFree3' => '0', 'bFree4' => '0', 'bFree5' => '0',
|
|
|
|
|
+ 'bFree6' => '0', 'bFree7' => '0', 'bFree8' => '0', 'bFree9' => '0', 'bFree10' => '0',
|
|
|
|
|
+ 'bConfigFree1' => '0', 'bConfigFree2' => '0', 'bConfigFree3' => '0', 'bConfigFree4' => '0',
|
|
|
|
|
+ 'bConfigFree5' => '0', 'bConfigFree6' => '0', 'bConfigFree7' => '0', 'bConfigFree8' => '0',
|
|
|
|
|
+ 'bConfigFree9' => '0', 'bConfigFree10' => '0',
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 构建 Inventory_sub 表数据
|
|
|
|
|
+ $inventorySubData = [
|
|
|
|
|
+ 'cInvSubCode' => $no,
|
|
|
|
|
+ 'iSurenessType' => '1',
|
|
|
|
|
+ 'bIsAttachFile' => '0',
|
|
|
|
|
+ 'bInByProCheck' => '1',
|
|
|
|
|
+ 'iRequireTrackStyle' => '0',
|
|
|
|
|
+ 'iExpiratDateCalcu' => '0',
|
|
|
|
|
+ 'iBOMExpandUnitType' => '1',
|
|
|
|
|
+ 'iDrawType' => $inventory['iDrawType'] ?? 0,
|
|
|
|
|
+ 'fInvCIQExch' => $inventory['customs_change_rate'] ?? 1,
|
|
|
|
|
+ 'bInvKeyPart' => '1',
|
|
|
|
|
+ 'iAcceptEarlyDays' => '999',
|
|
|
|
|
+ 'dInvCreateDatetime' => date("Y-m-d H:i:s.000"),
|
|
|
|
|
+ 'bPUQuota' => '0',
|
|
|
|
|
+ 'bInvROHS' => '0',
|
|
|
|
|
+ 'bPrjMat' => '0',
|
|
|
|
|
+ 'bInvAsset' => '0',
|
|
|
|
|
+ 'bSrvProduct' => '0',
|
|
|
|
|
+ 'iAcceptDelayDays' => '0',
|
|
|
|
|
+ 'bSCkeyProjections' => '0',
|
|
|
|
|
+ 'iSupplyPeriodType' => '1',
|
|
|
|
|
+ 'iAvailabilityDate' => '1',
|
|
|
|
|
+ 'bImport' => '0',
|
|
|
|
|
+ 'bCheckSubitemCost' => '1',
|
|
|
|
|
+ 'fRoundFactor' => '0.0',
|
|
|
|
|
+ 'bConsiderFreeStock' => '1',
|
|
|
|
|
+ 'bSuitRetail' => '0',
|
|
|
|
|
+ 'bFeatureMatch' => '0',
|
|
|
|
|
+ 'bProduceByFeatureAllocate' => '0',
|
|
|
|
|
+ 'bMaintenance' => '0',
|
|
|
|
|
+ 'iMaintenanceCycleUnit' => '0',
|
|
|
|
|
+ 'bCoupon' => '0',
|
|
|
|
|
+ 'bStoreCard' => '0',
|
|
|
|
|
+ 'bProcessProduct' => '0',
|
|
|
|
|
+ 'bProcessMaterial' => '0',
|
|
|
|
|
+ 'bPurPriceFree1' => '0', 'bOMPriceFree1' => '0', 'bSalePriceFree1' => '0',
|
|
|
|
|
+ 'bControlFreeRange1' => '0', 'bBatchProperty1' => '0',
|
|
|
|
|
+ 'bBondedInv' => '0',
|
|
|
|
|
+ 'bBatchCreate' => '0',
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 执行同步
|
|
|
|
|
+ try {
|
|
|
|
|
+ $service->beginTransaction();
|
|
|
|
|
+
|
|
|
|
|
+ $exists = $service->table('Inventory')->where('cInvCode', $no)->lockForUpdate()->exists();
|
|
|
|
|
+ if ($exists) {
|
|
|
|
|
+ $service->rollBack();
|
|
|
|
|
+ return [false, '存货编码 [' . $no . '] 在用友系统中已存在,请' . $flag_title];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // --- 核心插入操作 ---
|
|
|
|
|
+ $service->table('Inventory')->insert($inventoryData);
|
|
|
|
|
+ $service->table('Inventory_sub')->insert($inventorySubData);
|
|
|
|
|
+
|
|
|
|
|
+ // --- 新增:插入 bas_part 表 ---
|
|
|
|
|
+ // 1. 获取 U8 内部最大 PartId (或者从 bas_part_seq 获取,这里采用最大值+1的简易方案)
|
|
|
|
|
+ $maxPartId = $service->table('bas_part')->max('PartId');
|
|
|
|
|
+ $newPartId = (int)$maxPartId + 1;
|
|
|
|
|
+
|
|
|
|
|
+ $basPartData = [
|
|
|
|
|
+ 'PartId' => $newPartId,
|
|
|
|
|
+ 'InvCode' => $no,
|
|
|
|
|
+ 'Free1' => '', 'Free2' => '', 'Free3' => '', 'Free4' => '', 'Free5' => '',
|
|
|
|
|
+ 'Free6' => '', 'Free7' => '', 'Free8' => '', 'Free9' => '', 'Free10' => '',
|
|
|
|
|
+ 'SafeQty' => null,
|
|
|
|
|
+ 'MinQty' => null,
|
|
|
|
|
+ 'MulQty' => null,
|
|
|
|
|
+ 'FixQty' => null,
|
|
|
|
|
+ 'bVirtual' => 1, // 默认非虚仓,如果是虚拟件请改为 1
|
|
|
|
|
+ 'DrawCode' => null,
|
|
|
|
|
+ 'LLC' => 0, // 低层码,新增时默认为 0,U8全检时会更新
|
|
|
|
|
+ 'iSurenessType' => 1, // 对应 Inventory_sub 的设置
|
|
|
|
|
+ 'RoundingFactor' => '0',
|
|
|
|
|
+ 'FreeStockFlag' => '0',
|
|
|
|
|
+ 'bFreeStop' => '0'
|
|
|
|
|
+ ];
|
|
|
|
|
+ $service->table('bas_part')->insert($basPartData);
|
|
|
|
|
+
|
|
|
|
|
+ // 更新流水号表
|
|
|
|
|
+ if ($serialInfo) {
|
|
|
|
|
+ $service->table('VoucherHistory')->updateOrInsert(
|
|
|
|
|
+ ['CardNumber' => 'inventory', 'cContent' => '存货分类编码', 'cSeed' => $category_code],
|
|
|
|
|
+ ['cNumber' => $serialInfo['serial']]
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $service->commit();
|
|
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
|
|
+ $service->rollBack();
|
|
|
|
|
+ return [false, "同步用友数据库失败: " . $exception->getMessage()];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return [true, '同步成功'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* U8 供应商新增 (全量版)
|
|
* U8 供应商新增 (全量版)
|
|
|
*/
|
|
*/
|