|
|
@@ -3,8 +3,10 @@
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
use App\Model\DDEmployee;
|
|
|
+use App\Model\Inventory;
|
|
|
use App\Model\Record;
|
|
|
use App\Model\U8State;
|
|
|
+use App\Model\Vendor;
|
|
|
use App\Service\U8DatabaseServerService;
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
@@ -89,9 +91,11 @@ class ProcessDataJob implements ShouldQueue
|
|
|
"dVeriDate" => $time1 . ".000",
|
|
|
]);
|
|
|
}elseif($type == Record::type_four){
|
|
|
-
|
|
|
+ list($status, $msg) = $this->inventoryAddToU8($record, $service);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
}elseif($type == Record::type_five){
|
|
|
-
|
|
|
+ list($status, $msg) = $this->vendorAddToU8($record, $service);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
}
|
|
|
|
|
|
// 更新本地数据 通过状态
|
|
|
@@ -112,6 +116,373 @@ class ProcessDataJob implements ShouldQueue
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
+ //U8 存货新增到用友
|
|
|
+ public function inventoryAddToU8($data, $service){
|
|
|
+ $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();
|
|
|
+
|
|
|
+ $title = $inventory['title'];
|
|
|
+ $category_code = $inventory['category_code'];
|
|
|
+ if(! empty($data['code'])){
|
|
|
+ //用户传入
|
|
|
+ $no = $inventory['code'];
|
|
|
+ $flag_title = "重填";
|
|
|
+ }else{
|
|
|
+ //生成编码
|
|
|
+ list($status, $msg) = $this->generate('inventory',$category_code, $service);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+ $no = $msg;
|
|
|
+ $flag_title = "重试";
|
|
|
+ }
|
|
|
+
|
|
|
+ $inventoryData = [
|
|
|
+ 'cInvCode' => $no,
|
|
|
+ 'cInvName' => $title,
|
|
|
+ 'cInvCCode' => $category_code,
|
|
|
+ 'cInvStd' => $inventory['size'] ?? null, // 规格型号
|
|
|
+ 'bSale' => $inventory['bSale'], //内销
|
|
|
+ 'bExpSale' => $inventory['bExpSale'], //外销
|
|
|
+ 'bPurchase' => $inventory['bPurchase'], // 采购
|
|
|
+ 'bSelf' => $inventory['bSelf'], // 自制
|
|
|
+ 'bComsume' => $inventory['bComsume'], // 生产耗材
|
|
|
+ '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' => '1', // 成本累计否
|
|
|
+ 'cPlanMethod' => 'R',
|
|
|
+ 'cSRPolicy' => 'PE',
|
|
|
+ 'bBomMain' => '0', // 允许BOM母件
|
|
|
+ 'bBomSub' => '0', // 允许BOM子件
|
|
|
+ 'bProductBill' => '0', // 允许生产订单
|
|
|
+ 'iPlanDefault' => '1',
|
|
|
+ 'iAllocatePrintDgt' => '4',
|
|
|
+ 'bService' => '0',
|
|
|
+ 'bAccessary' => '0',
|
|
|
+ 'iInvAdvance' => '0.0',
|
|
|
+ 'bInvQuality' => '0',
|
|
|
+ 'bInvBatch' => '0',
|
|
|
+ 'bInvEntrust' => '0',
|
|
|
+ 'bInvOverStock' => '0',
|
|
|
+ 'bFree1' => '0',
|
|
|
+ 'bFree2' => '0',
|
|
|
+ 'bInvType' => '0',
|
|
|
+ 'bFree3' => '0',
|
|
|
+ 'bFree4' => '0',
|
|
|
+ 'bFree5' => '0',
|
|
|
+ 'bFree6' => '0',
|
|
|
+ 'bFree7' => '0',
|
|
|
+ 'bFree8' => '0',
|
|
|
+ 'bFree9' => '0',
|
|
|
+ 'bFree10' => '0',
|
|
|
+ 'cCreatePerson' => 'demo',
|
|
|
+ 'cModifyPerson' => 'demo', // 变更
|
|
|
+ 'dModifyDate' => date("Y-m-d H:i:s.000"),
|
|
|
+ 'bFixExch' => '0',
|
|
|
+ 'bTrack' => '0',
|
|
|
+ 'bSerial' => '0',
|
|
|
+ 'bBarCode' => '0',
|
|
|
+ 'bSolitude' => '0',
|
|
|
+ 'bSpecialties' => '0',
|
|
|
+ 'bPropertyCheck' => '0',
|
|
|
+ 'iRecipeBatch' => '0',
|
|
|
+ 'bPromotSales' => '0',
|
|
|
+ 'bPlanInv' => '0',
|
|
|
+ 'bProxyForeign' => '0',
|
|
|
+ 'bATOModel' => '0',
|
|
|
+ 'bCheckItem' => '0',
|
|
|
+ 'bPTOModel' => '0',
|
|
|
+ 'bEquipment' => '0',
|
|
|
+ 'bMPS' => '0',
|
|
|
+ 'bROP' => '0',
|
|
|
+ 'bRePlan' => '0',
|
|
|
+ 'bBillUnite' => '0',
|
|
|
+ 'bCutMantissa' => '0',
|
|
|
+ 'bConfigFree1' => '0',
|
|
|
+ 'bConfigFree2' => '0',
|
|
|
+ 'bConfigFree3' => '0',
|
|
|
+ 'bConfigFree4' => '0',
|
|
|
+ 'bConfigFree5' => '0',
|
|
|
+ 'bConfigFree6' => '0',
|
|
|
+ 'bConfigFree7' => '0',
|
|
|
+ 'bConfigFree8' => '0',
|
|
|
+ 'bConfigFree9' => '0',
|
|
|
+ 'bConfigFree10' => '0',
|
|
|
+ 'bPeriodDT' => '0',
|
|
|
+ 'bOutInvDT' => '0',
|
|
|
+ 'bBackInvDT' => '0',
|
|
|
+ 'bDTWarnInv' => '0',
|
|
|
+ 'bImportMedicine' => '0',
|
|
|
+ 'bFirstBusiMedicine' => '0',
|
|
|
+ 'bForeExpland' => '0',
|
|
|
+ 'bInvModel' => '0',
|
|
|
+ 'bKCCutMantissa' => '0',
|
|
|
+ 'bReceiptByDT' => '0',
|
|
|
+ 'bCheckBSATP' => '0',
|
|
|
+ 'bCheckFree1' => '0',
|
|
|
+ 'bCheckFree2' => '0',
|
|
|
+ 'bCheckFree3' => '0',
|
|
|
+ 'bCheckFree4' => '0',
|
|
|
+ 'bCheckFree5' => '0',
|
|
|
+ 'bCheckFree6' => '0',
|
|
|
+ 'bCheckFree7' => '0',
|
|
|
+ 'bCheckFree8' => '0',
|
|
|
+ 'bCheckFree9' => '0',
|
|
|
+ 'bCheckFree10' => '0',
|
|
|
+ 'iCheckATP' => '0',
|
|
|
+ 'bPiece' => '0',
|
|
|
+ 'bSrvItem' => '0',
|
|
|
+ 'bSrvFittings' => '0',
|
|
|
+ 'bSpecialOrder' => '0',
|
|
|
+ 'bTrackSaleBill' => '0',
|
|
|
+ 'bCheckBatch' => '0',
|
|
|
+ 'bMngOldpart' => '0',
|
|
|
+ ];
|
|
|
+
|
|
|
+ $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',
|
|
|
+ // 所有的价格自由项默认设为 '0'
|
|
|
+ 'bPurPriceFree1' => '0', 'bPurPriceFree2' => '0', 'bPurPriceFree3' => '0', 'bPurPriceFree4' => '0', 'bPurPriceFree5' => '0',
|
|
|
+ 'bPurPriceFree6' => '0', 'bPurPriceFree7' => '0', 'bPurPriceFree8' => '0', 'bPurPriceFree9' => '0', 'bPurPriceFree10' => '0',
|
|
|
+ 'bOMPriceFree1' => '0', 'bOMPriceFree2' => '0', 'bOMPriceFree3' => '0', 'bOMPriceFree4' => '0', 'bOMPriceFree5' => '0',
|
|
|
+ 'bOMPriceFree6' => '0', 'bOMPriceFree7' => '0', 'bOMPriceFree8' => '0', 'bOMPriceFree9' => '0', 'bOMPriceFree10' => '0',
|
|
|
+ 'bSalePriceFree1' => '0', 'bSalePriceFree2' => '0', 'bSalePriceFree3' => '0', 'bSalePriceFree4' => '0', 'bSalePriceFree5' => '0',
|
|
|
+ 'bSalePriceFree6' => '0', 'bSalePriceFree7' => '0', 'bSalePriceFree8' => '0', 'bSalePriceFree9' => '0', 'bSalePriceFree10' => '0',
|
|
|
+ // 所有的控制自由项默认设为 '0'
|
|
|
+ 'bControlFreeRange1' => '0', 'bControlFreeRange2' => '0', 'bControlFreeRange3' => '0', 'bControlFreeRange4' => '0', 'bControlFreeRange5' => '0',
|
|
|
+ 'bControlFreeRange6' => '0', 'bControlFreeRange7' => '0', 'bControlFreeRange8' => '0', 'bControlFreeRange9' => '0', 'bControlFreeRange10' => '0',
|
|
|
+ // 所有的批次属性默认设为 '0'
|
|
|
+ 'bBatchProperty1' => '0', 'bBatchProperty2' => '0', 'bBatchProperty3' => '0', 'bBatchProperty4' => '0', 'bBatchProperty5' => '0',
|
|
|
+ 'bBatchProperty6' => '0', 'bBatchProperty7' => '0', 'bBatchProperty8' => '0', 'bBatchProperty9' => '0', 'bBatchProperty10' => '0',
|
|
|
+ 'bBondedInv' => '0',
|
|
|
+ 'bBatchCreate' => '0',
|
|
|
+ ];
|
|
|
+
|
|
|
+ try {
|
|
|
+ $service->beginTransaction();
|
|
|
+
|
|
|
+ $exists = $service->table('Inventory')
|
|
|
+ ->where('cInvCode', $inventoryData['cInvCode'])
|
|
|
+ ->lockForUpdate() // 锁定该行,防止并发冲突
|
|
|
+ ->exists();
|
|
|
+
|
|
|
+ if ($exists) return [false, '存货编码已存在,请' . $flag_title];
|
|
|
+
|
|
|
+ $service->table('Inventory')->insert($inventoryData);
|
|
|
+ $service->table('Inventory_sub')->insert($inventorySubData);
|
|
|
+
|
|
|
+ $service->commit();
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
+ $service->rollBack();
|
|
|
+
|
|
|
+ return [false, "创建用友失败: " . $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ //U8 供应商新增
|
|
|
+ public function vendorAddToU8($data, $user,$service){
|
|
|
+ $vendor = Vendor::where('del_time', 0)
|
|
|
+ ->where('order_number', $data['order_number'])
|
|
|
+ ->where('login_type', $data['login_type'])
|
|
|
+ ->first();
|
|
|
+ if(empty($vendor)) return [false, '供应商记录不存在或已被删除'];
|
|
|
+ $vendor = $vendor->toArray();
|
|
|
+
|
|
|
+ if(! empty($vendor['code'])){
|
|
|
+ //用户传入
|
|
|
+ $no = $vendor['code'];
|
|
|
+ $flag_title = "重填";
|
|
|
+ }else{
|
|
|
+ //生成编码
|
|
|
+ list($status, $msg) = $this->generate('vendor','', $service);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+ $no = $msg;
|
|
|
+ $flag_title = "重试";
|
|
|
+ }
|
|
|
+
|
|
|
+ $vendorData = [
|
|
|
+ 'cVenCode' => $no,
|
|
|
+ 'cVenName' => $vendor['title'],
|
|
|
+ 'cVenAbbName' => $vendor['easy_title'],
|
|
|
+ 'cVCCode' => $vendor['category_code'],
|
|
|
+ 'dVenDevDate' => date("Y-m-d 00:00:00.000"),
|
|
|
+ 'iVenDisRate' => '0.0',
|
|
|
+ 'iVenCreLine' => '0.0',
|
|
|
+ 'iVenCreDate' => '0',
|
|
|
+ 'cVenHeadCode' => $no,
|
|
|
+ 'iAPMoney' => '0.0',
|
|
|
+ 'iLastMoney' => '0.0',
|
|
|
+ 'iLRMoney' => '0.0',
|
|
|
+ 'iFrequency' => '0',
|
|
|
+ 'bVenTax' => '1',
|
|
|
+ 'cCreatePerson' => 'demo',
|
|
|
+ 'cModifyPerson' => 'demo',
|
|
|
+ 'dModifyDate' => date("Y-m-d H:i:s.000"),
|
|
|
+ 'iGradeABC' => '-1',
|
|
|
+ 'bLicenceDate' => '0',
|
|
|
+ 'bBusinessDate' => '0',
|
|
|
+ 'bProxyDate' => '0',
|
|
|
+ 'bPassGMP' => '0',
|
|
|
+ 'bVenCargo' => '1', // 采购
|
|
|
+ 'bProxyForeign' => '0', // 委外
|
|
|
+ 'bVenService' => '0', // 服务
|
|
|
+ 'bVenOverseas' => '0', // 国外
|
|
|
+ 'cVenExch_name' => '人民币',
|
|
|
+ 'iVenGSPType' => '0',
|
|
|
+ 'iVenGSPAuth' => '-1',
|
|
|
+ 'bVenAccPeriodMng' => '0',
|
|
|
+ 'bVenHomeBranch' => '0',
|
|
|
+ 'dVenCreateDatetime' => date("Y-m-d H:i:s.000"),
|
|
|
+ 'bIsVenAttachFile' => '0',
|
|
|
+ 'bRetail' => '0',
|
|
|
+ ];
|
|
|
+
|
|
|
+ try {
|
|
|
+ $service->beginTransaction();
|
|
|
+
|
|
|
+ $exists = $service->table('Vendor')
|
|
|
+ ->where('cVenCode', $vendorData['cVenCode'])
|
|
|
+ ->lockForUpdate() // 锁定该行,防止并发冲突
|
|
|
+ ->exists();
|
|
|
+
|
|
|
+ if ($exists) return [false, '供应商编码已存在,请' . $flag_title];
|
|
|
+
|
|
|
+ $service->table('Vendor')->insert($vendorData);
|
|
|
+
|
|
|
+ $service->commit();
|
|
|
+
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
+ $service->rollBack();
|
|
|
+
|
|
|
+ return [false, "创建供应商失败: " . $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成编码
|
|
|
+ public function generate($type, $classCode = "", $service)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ // 1. 确定对象映射
|
|
|
+ $cardNumber = ($type === 'inventory') ? 'inventory' : 'Vendor';
|
|
|
+ $cardNumber_name = ($type === 'inventory') ? '存货' : '供应商';
|
|
|
+ $table = ($type === 'inventory') ? 'Inventory' : 'Vendor';
|
|
|
+ $codeField = ($type === 'inventory') ? 'cInvCode' : 'cVenCode';
|
|
|
+
|
|
|
+ // 2. 获取 U8 规则定义
|
|
|
+ $rule = $service->table('VoucherNumber')
|
|
|
+ ->where('CardNumber', $cardNumber)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if (!$rule) return [false, "未找到 {$cardNumber_name} 的规则定义"];
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 3. 动态解析前缀 (Prefix1, Prefix2, Prefix3)
|
|
|
+ * U8 的规则通常存放在 PrefixRule 或 Prefix 字段中
|
|
|
+ */
|
|
|
+ $prefix = "";
|
|
|
+ for ($i = 1; $i <= 3; $i++) {
|
|
|
+ $ruleField = "Prefix{$i}Rule";
|
|
|
+ $valField = "Prefix{$i}";
|
|
|
+
|
|
|
+ // 检查规则描述
|
|
|
+ $ruleDesc = $rule->$ruleField ?? ''; // 例如 "存货分类编码" 或 "GYS"
|
|
|
+ $staticVal = $rule->$valField ?? '';
|
|
|
+
|
|
|
+ if (str_contains($ruleDesc, '分类') || str_contains($staticVal, '分类')) {
|
|
|
+ // 如果规则提到“分类”,则填入传入的分类编码
|
|
|
+ $prefix .= $classCode;
|
|
|
+ } elseif (!empty($ruleDesc)) {
|
|
|
+ // 如果规则是具体的字符(如 "GYS"),直接拼接
|
|
|
+ $prefix .= $ruleDesc;
|
|
|
+ } elseif (!empty($staticVal) && $staticVal !== '手工输入' && $staticVal !== '存货分类编码') {
|
|
|
+ // 如果静态值不是提示语,则作为前缀
|
|
|
+ $prefix .= $staticVal;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 获取流水号配置 (Glide)
|
|
|
+ $glideLen = $rule->GlideLen > 0 ? $rule->GlideLen : 4;
|
|
|
+ $startNum = $rule->iStartNumber ?? 1;
|
|
|
+
|
|
|
+ // 5. 查找当前最大编码
|
|
|
+ $expectedLen = strlen($prefix) + $glideLen;
|
|
|
+
|
|
|
+ $lastCode = $service->table($table)
|
|
|
+ ->where($codeField, 'like', $prefix . '%')
|
|
|
+ ->whereRaw("LEN($codeField) = $expectedLen")
|
|
|
+ ->orderBy($codeField, 'desc')
|
|
|
+ ->value($codeField);
|
|
|
+
|
|
|
+ // 6. 生成编码
|
|
|
+ if (!$lastCode) {
|
|
|
+ // 初始:前缀 + 起始值补零
|
|
|
+ $finalCode = $prefix . str_pad($startNum, $glideLen, '0', STR_PAD_LEFT);
|
|
|
+ } else {
|
|
|
+ // 截取流水号自增
|
|
|
+ $lastSerial = substr($lastCode, -$glideLen);
|
|
|
+ $nextSerial = ++$lastSerial;
|
|
|
+
|
|
|
+ // 溢出检查
|
|
|
+ if (strlen($nextSerial) > $glideLen) {
|
|
|
+ return [false, "流水号已溢出"];
|
|
|
+ }
|
|
|
+ $finalCode = $prefix . str_pad($nextSerial, $glideLen, '0', STR_PAD_LEFT);
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $finalCode];
|
|
|
+
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ return [false, "生成失败: " . $e->getMessage()];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
protected function echoMessage(OutputInterface $output)
|
|
|
{
|
|
|
//输出消息
|