|
@@ -102,124 +102,125 @@ class PurchaseOrderClass extends BaseClass
|
|
|
if (empty($currentItemInfo)) {
|
|
if (empty($currentItemInfo)) {
|
|
|
util::fail('花材信息缺失');
|
|
util::fail('花材信息缺失');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- $bookItemRes = BookItemClass::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'itemId' => $productId], true);
|
|
|
|
|
|
|
+ $bookItemRes = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $productId], true);
|
|
|
if (empty($bookItemRes)) {
|
|
if (empty($bookItemRes)) {
|
|
|
- //没有预订就无货位号
|
|
|
|
|
|
|
+ //没有预订花材则不需要分配货位
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
$bookItemCustomList = BookItemCustomClass::getAllByCondition(['bookSn' => $bookSn, 'itemId' => $productId], null, '*', null, true);
|
|
$bookItemCustomList = BookItemCustomClass::getAllByCondition(['bookSn' => $bookSn, 'itemId' => $productId], null, '*', null, true);
|
|
|
- if (!empty($bookItemCustomList)) {
|
|
|
|
|
-
|
|
|
|
|
- $customIds = [];
|
|
|
|
|
- foreach ($bookItemCustomList as $bookItemCustomRes) {
|
|
|
|
|
- $customIds[] = $bookItemCustomRes->customId;
|
|
|
|
|
|
|
+ if (empty($bookItemCustomList)) {
|
|
|
|
|
+ //没有预订的花材和客户则不需要分配货位
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $customIds = [];
|
|
|
|
|
+ foreach ($bookItemCustomList as $bookItemCustomRes) {
|
|
|
|
|
+ $customIds[] = $bookItemCustomRes->customId;
|
|
|
|
|
+ }
|
|
|
|
|
+ $customList = CustomClass::getAllByCondition(['id' => ['in', $customIds]], null, '*', 'id', true);
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($bookItemCustomList as $bookItemCustomRes) {
|
|
|
|
|
+ $customId = $bookItemCustomRes->customId ?? 0;
|
|
|
|
|
+ $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true);
|
|
|
|
|
+ if (empty($bookCustomRes)) {
|
|
|
|
|
+ noticeUtil::push("采购单 {$orderSn} 分配货位时,发现 bookCustom 数据有问题", '15280215347');
|
|
|
|
|
+ util::fail("bookCustom 数据有问题");
|
|
|
}
|
|
}
|
|
|
- $customList = CustomClass::getAllByCondition(['id' => ['in', $customIds]], null, '*', 'id', true);
|
|
|
|
|
|
|
|
|
|
- foreach ($bookItemCustomList as $bookItemCustomRes) {
|
|
|
|
|
- $customId = $bookItemCustomRes->customId ?? 0;
|
|
|
|
|
- $bookCustomRes = BookCustomClass::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'customId' => $customId], true);
|
|
|
|
|
- if (empty($bookCustomRes)) {
|
|
|
|
|
- util::fail('信息不完整');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $needCgNum = $bookItemCustomRes->needCgNum ?? 0;
|
|
|
|
|
+ $confirmSendNum = $cgItem->confirmSendNum ?? 0;
|
|
|
|
|
+ $remainCouldSendNum = bcsub($cgItemNum, $confirmSendNum, 2);
|
|
|
|
|
+ if ($remainCouldSendNum <= 0) {
|
|
|
|
|
+ //剩余可分配数量不足则退出
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($needCgNum >= $remainCouldSendNum) {
|
|
|
|
|
+ $remainNeedSendNum = $remainCouldSendNum;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $remainNeedSendNum = $needCgNum;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($remainNeedSendNum <= 0) {
|
|
|
|
|
+ //剩余需要分配数量不足则退出
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ //待采数量减少
|
|
|
|
|
+ $bookItemCustomRes->needCgNum = bcsub($needCgNum, $remainNeedSendNum);
|
|
|
|
|
+ $bookCustomRes->needCgNum = bcsub($bookCustomRes->needCgNum, $remainNeedSendNum);
|
|
|
|
|
+ $bookItemRes->needCgNum = bcsub($bookItemRes->needCgNum, $remainNeedSendNum);
|
|
|
|
|
+ //路上数量增加
|
|
|
|
|
+ $bookItemCustomRes->roadNum = bcadd($bookItemCustomRes->roadNum, $remainNeedSendNum);
|
|
|
|
|
+ $bookCustomRes->roadNum = bcadd($bookCustomRes->roadNum, $remainNeedSendNum);
|
|
|
|
|
+ $bookItemRes->roadNum = bcadd($bookItemRes->roadNum, $remainNeedSendNum);
|
|
|
|
|
+ $bookItemCustomRes->save();
|
|
|
|
|
+ $bookCustomRes->save();
|
|
|
|
|
+ $bookItemRes->save();
|
|
|
|
|
+
|
|
|
|
|
+ //确认已分配数量增加
|
|
|
|
|
+ $cgItem->confirmSendNum = bcadd($cgItem->confirmSendNum, $remainNeedSendNum);
|
|
|
|
|
+ $cgItem->save();
|
|
|
|
|
+
|
|
|
|
|
+ $sendInfo = CgOrderItemSendClass::getByCondition(['parentId' => $cgItemId, 'customId' => $customId, 'itemId' => $productId], true);
|
|
|
|
|
+ $bookItemCustomId = $bookItemCustomRes->id ?? 0;
|
|
|
|
|
+ $currentCustom = $customList[$customId] ?? null;
|
|
|
|
|
+ if (empty($currentCustom)) {
|
|
|
|
|
+ util::fail('客户信息缺失');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (empty($sendInfo)) {
|
|
|
|
|
+ $sendData = [
|
|
|
|
|
+ 'mainId' => $mainId,
|
|
|
|
|
+ 'parentOrderId' => $cgId,
|
|
|
|
|
+ 'parentId' => $cgItemId,
|
|
|
|
|
+ 'bookGhsGiveId' => 0,
|
|
|
|
|
+ 'name' => $currentItemInfo->name ?? '',
|
|
|
|
|
+ 'py' => $currentItemInfo->py ?? '',
|
|
|
|
|
+ 'itemId' => $productId,
|
|
|
|
|
+ 'ptItemId' => $ptItemId,
|
|
|
|
|
+ 'customId' => $customId,
|
|
|
|
|
+ 'customName' => $currentCustom->name ?? '',
|
|
|
|
|
+ 'customPy' => $currentCustom->py ?? '',
|
|
|
|
|
+ 'seatSn' => $currentCustom->seatSn ?? 0,
|
|
|
|
|
+ 'num' => 0,
|
|
|
|
|
+ 'bookItemCustomId' => $bookItemCustomId,
|
|
|
|
|
+ 'status' => 0,
|
|
|
|
|
+ 'staffId' => $currentItemInfo->cgStaffId ?? 0,
|
|
|
|
|
+ 'staffName' => $currentItemInfo->cgStaffName ?? '',
|
|
|
|
|
+ ];
|
|
|
|
|
+ $sendInfo = CgOrderItemSendClass::add($sendData, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ $sendInfo->num = bcadd($sendInfo->num, $remainNeedSendNum);
|
|
|
|
|
+ $sendInfo->save();
|
|
|
|
|
+ $sendInfoId = $sendInfo->id ?? 0;
|
|
|
|
|
|
|
|
- $needCgNum = $bookItemCustomRes->needCgNum ?? 0;
|
|
|
|
|
- $confirmSendNum = $cgItem->confirmSendNum ?? 0;
|
|
|
|
|
- $remainCouldSendNum = bcsub($cgItemNum, $confirmSendNum, 2);
|
|
|
|
|
- if ($remainCouldSendNum <= 0) {
|
|
|
|
|
- //剩余可分配数量不足则退出
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- if ($needCgNum >= $remainCouldSendNum) {
|
|
|
|
|
- $remainNeedSendNum = $remainCouldSendNum;
|
|
|
|
|
- } else {
|
|
|
|
|
- $remainNeedSendNum = $needCgNum;
|
|
|
|
|
- }
|
|
|
|
|
- if ($remainNeedSendNum <= 0) {
|
|
|
|
|
- //剩余需要分配数量不足则退出
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- //待采数量减少
|
|
|
|
|
- $bookItemCustomRes->needCgNum = bcsub($needCgNum, $remainNeedSendNum);
|
|
|
|
|
- $bookCustomRes->needCgNum = bcsub($bookCustomRes->needCgNum, $remainNeedSendNum);
|
|
|
|
|
- $bookItemRes->needCgNum = bcsub($bookItemRes->needCgNum, $remainNeedSendNum);
|
|
|
|
|
- //路上数量增加
|
|
|
|
|
- $bookItemCustomRes->roadNum = bcadd($bookItemCustomRes->roadNum, $remainNeedSendNum);
|
|
|
|
|
- $bookCustomRes->roadNum = bcadd($bookCustomRes->roadNum, $remainNeedSendNum);
|
|
|
|
|
- $bookItemRes->roadNum = bcadd($bookItemRes->roadNum, $remainNeedSendNum);
|
|
|
|
|
- $bookItemCustomRes->save();
|
|
|
|
|
- $bookCustomRes->save();
|
|
|
|
|
- $bookItemRes->save();
|
|
|
|
|
-
|
|
|
|
|
- //确认已分配数量增加
|
|
|
|
|
- $cgItem->confirmSendNum = bcadd($cgItem->confirmSendNum, $remainNeedSendNum);
|
|
|
|
|
- $cgItem->save();
|
|
|
|
|
-
|
|
|
|
|
- $sendInfo = CgOrderItemSendClass::getByCondition(['parentId' => $cgItemId, 'customId' => $customId, 'itemId' => $productId], true);
|
|
|
|
|
- $bookItemCustomId = $bookItemCustomRes->id ?? 0;
|
|
|
|
|
- $currentCustom = $customList[$customId] ?? null;
|
|
|
|
|
- if (empty($currentCustom)) {
|
|
|
|
|
- util::fail('客户信息缺失');
|
|
|
|
|
- }
|
|
|
|
|
- if (empty($sendInfo)) {
|
|
|
|
|
- $sendData = [
|
|
|
|
|
- 'mainId' => $mainId,
|
|
|
|
|
- 'parentOrderId' => $cgId,
|
|
|
|
|
- 'parentId' => $cgItemId,
|
|
|
|
|
- 'bookGhsGiveId' => 0,
|
|
|
|
|
- 'name' => $currentItemInfo->name ?? '',
|
|
|
|
|
- 'py' => $currentItemInfo->py ?? '',
|
|
|
|
|
- 'itemId' => $productId,
|
|
|
|
|
- 'ptItemId' => $ptItemId,
|
|
|
|
|
- 'customId' => $customId,
|
|
|
|
|
- 'customName' => $currentCustom->name ?? '',
|
|
|
|
|
- 'customPy' => $currentCustom->py ?? '',
|
|
|
|
|
- 'seatSn' => $currentCustom->seatSn ?? 0,
|
|
|
|
|
- 'num' => 0,
|
|
|
|
|
- 'bookItemCustomId' => $bookItemCustomId,
|
|
|
|
|
- 'status' => 0,
|
|
|
|
|
- 'staffId' => $currentItemInfo->cgStaffId ?? 0,
|
|
|
|
|
- 'staffName' => $currentItemInfo->cgStaffName ?? '',
|
|
|
|
|
- ];
|
|
|
|
|
- $sendInfo = CgOrderItemSendClass::add($sendData, true);
|
|
|
|
|
- }
|
|
|
|
|
- $sendInfo->num = bcadd($sendInfo->num, $remainNeedSendNum);
|
|
|
|
|
- $sendInfo->save();
|
|
|
|
|
- $sendInfoId = $sendInfo->id ?? 0;
|
|
|
|
|
-
|
|
|
|
|
- $giveGhs = BookItemGhsClass::getByCondition(['parentId' => $bookItemCustomId, 'ghsId' => $ghsId, 'itemId' => $productId,], true);
|
|
|
|
|
- if (empty($giveGhs)) {
|
|
|
|
|
- $giveGhsData = [
|
|
|
|
|
- 'mainId' => $mainId,
|
|
|
|
|
- 'bookSn' => $bookSn,
|
|
|
|
|
- 'parentId' => $bookItemCustomId,
|
|
|
|
|
- 'cgSendId' => $sendInfoId,
|
|
|
|
|
- 'name' => $currentItemInfo->name ?? '',
|
|
|
|
|
- 'py' => $currentItemInfo->py ?? '',
|
|
|
|
|
- 'itemId' => $productId,
|
|
|
|
|
- 'ptItemId' => $ptItemId,
|
|
|
|
|
- 'ghsId' => $ghsId,
|
|
|
|
|
- 'ghsName' => $ghsName,
|
|
|
|
|
- 'cgId' => $cgId,
|
|
|
|
|
- 'cgItemId' => $cgItemId,
|
|
|
|
|
- 'customId' => $customId,
|
|
|
|
|
- 'customName' => $currentCustom->name ?? '',
|
|
|
|
|
- 'staffId' => $currentItemInfo->cgStaffId ?? 0,
|
|
|
|
|
- 'staffName' => $currentItemInfo->cgStaffName ?? '',
|
|
|
|
|
- 'status' => 0,
|
|
|
|
|
- ];
|
|
|
|
|
- $giveGhs = BookItemGhsClass::add($giveGhsData, true);
|
|
|
|
|
- }
|
|
|
|
|
- $giveGhs->num = bcadd($giveGhs->num, $remainNeedSendNum);
|
|
|
|
|
- $giveGhs->save();
|
|
|
|
|
- $giveGhsId = $giveGhs->id ?? 0;
|
|
|
|
|
- $sendInfo->bookGhsGiveId = $giveGhsId;
|
|
|
|
|
- $sendInfo->save();
|
|
|
|
|
- $hasChange = 1;
|
|
|
|
|
|
|
+ $giveGhs = BookItemGhsClass::getByCondition(['parentId' => $bookItemCustomId, 'ghsId' => $ghsId, 'itemId' => $productId,], true);
|
|
|
|
|
+ if (empty($giveGhs)) {
|
|
|
|
|
+ $giveGhsData = [
|
|
|
|
|
+ 'mainId' => $mainId,
|
|
|
|
|
+ 'bookSn' => $bookSn,
|
|
|
|
|
+ 'parentId' => $bookItemCustomId,
|
|
|
|
|
+ 'cgSendId' => $sendInfoId,
|
|
|
|
|
+ 'name' => $currentItemInfo->name ?? '',
|
|
|
|
|
+ 'py' => $currentItemInfo->py ?? '',
|
|
|
|
|
+ 'itemId' => $productId,
|
|
|
|
|
+ 'ptItemId' => $ptItemId,
|
|
|
|
|
+ 'ghsId' => $ghsId,
|
|
|
|
|
+ 'ghsName' => $ghsName,
|
|
|
|
|
+ 'cgId' => $cgId,
|
|
|
|
|
+ 'cgItemId' => $cgItemId,
|
|
|
|
|
+ 'customId' => $customId,
|
|
|
|
|
+ 'customName' => $currentCustom->name ?? '',
|
|
|
|
|
+ 'staffId' => $currentItemInfo->cgStaffId ?? 0,
|
|
|
|
|
+ 'staffName' => $currentItemInfo->cgStaffName ?? '',
|
|
|
|
|
+ 'status' => 0,
|
|
|
|
|
+ ];
|
|
|
|
|
+ $giveGhs = BookItemGhsClass::add($giveGhsData, true);
|
|
|
}
|
|
}
|
|
|
|
|
+ $giveGhs->num = bcadd($giveGhs->num, $remainNeedSendNum);
|
|
|
|
|
+ $giveGhs->save();
|
|
|
|
|
+ $giveGhsId = $giveGhs->id ?? 0;
|
|
|
|
|
+ $sendInfo->bookGhsGiveId = $giveGhsId;
|
|
|
|
|
+ $sendInfo->save();
|
|
|
|
|
+ $hasChange = 1;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
return ['hasChange' => $hasChange];
|
|
return ['hasChange' => $hasChange];
|
|
|
}
|
|
}
|