|
|
@@ -13,7 +13,11 @@ use biz\stat\classes\StatCgGhsClass;
|
|
|
use biz\stat\classes\StatOutClass;
|
|
|
use biz\wx\classes\WxMessageClass;
|
|
|
use bizGhs\base\classes\BaseClass;
|
|
|
+use bizGhs\book\classes\BookCustomClass;
|
|
|
+use bizGhs\book\classes\BookItemClass;
|
|
|
use bizGhs\book\classes\BookItemCustomClass;
|
|
|
+use bizGhs\book\classes\BookItemGhsClass;
|
|
|
+use bizGhs\cg\classes\CgOrderItemSendClass;
|
|
|
use bizGhs\custom\classes\CustomClass;
|
|
|
use bizGhs\item\classes\CostChangeClass;
|
|
|
use bizGhs\order\traits\OrderTrait;
|
|
|
@@ -63,23 +67,146 @@ class PurchaseOrderClass extends BaseClass
|
|
|
const IN_TYPE_LATER = 0;
|
|
|
const IN_TYPE_NOW = 1;
|
|
|
|
|
|
- public static function assign($cg,$bookSn)
|
|
|
+ public static function assign($cg, $bookSn)
|
|
|
{
|
|
|
- $orderSn = $cg->orderSn??'';
|
|
|
- $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn'=>$orderSn],null,'*',null,true);
|
|
|
- if(empty($itemList)){
|
|
|
+ $orderSn = $cg->orderSn ?? '';
|
|
|
+ $cgId = $cg->id ?? 0;
|
|
|
+ $mainId = $cg->mainId ?? 0;
|
|
|
+ $ghsId = $cg->ghsId ?? 0;
|
|
|
+ $ghsName = $cg->ghsName ?? '';
|
|
|
+ $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
|
|
|
+ if (empty($itemList)) {
|
|
|
return [];
|
|
|
}
|
|
|
- foreach($itemList as $item){
|
|
|
- $num = $item->itemNum??0;
|
|
|
- $productId = $item->productId??0;
|
|
|
- if($num<=0){
|
|
|
+
|
|
|
+ $ids = [];
|
|
|
+ foreach ($itemList as $itemMaster) {
|
|
|
+ $ids[] = $itemMaster->productId;
|
|
|
+ }
|
|
|
+ $productInfoList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true)
|
|
|
+
|
|
|
+ foreach ($itemList as $itemMaster) {
|
|
|
+ $itemMasterId = $itemMaster->id ?? 0;
|
|
|
+ $num = $itemMaster->itemNum ?? 0;
|
|
|
+ $productId = $itemMaster->productId ?? 0;
|
|
|
+ $ptItemId = $itemMaster->itemId ?? 0;
|
|
|
+ if ($num <= 0) {
|
|
|
continue;
|
|
|
}
|
|
|
- $bookList = BookItemCustomClass::getAllByCondition(['bookSn'=>$bookSn,'itemId'=>$productId],null,'*',null,true);
|
|
|
- if(!empty($bookList)){
|
|
|
- foreach($bookList as $bookData){
|
|
|
+ $currentItemInfo = $productInfoList[$productId] ?? null;
|
|
|
+ if (empty($currentItemInfo)) {
|
|
|
+ util::fail('花材信息缺失');
|
|
|
+ }
|
|
|
+
|
|
|
+ $itemMain = BookItemClass::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'itemId' => $productId], true);
|
|
|
+ if (empty($itemMain)) {
|
|
|
+ util::fail('信息不完整呢');
|
|
|
+ }
|
|
|
|
|
|
+ $bookList = BookItemCustomClass::getAllByCondition(['bookSn' => $bookSn, 'itemId' => $productId], null, '*', null, true);
|
|
|
+ if (!empty($bookList)) {
|
|
|
+
|
|
|
+ $customIds = [];
|
|
|
+ foreach ($bookList as $bookData) {
|
|
|
+ $customIds[] = $bookData->customId;
|
|
|
+ }
|
|
|
+ $customList = CustomClass::getAllByCondition(['id' => ['in', $customIds]], null, '*', 'id', true);
|
|
|
+
|
|
|
+ foreach ($bookList as $bookData) {
|
|
|
+ $needCgNum = $bookData->needCgNum ?? 0;
|
|
|
+ $customId = $bookData->customId ?? 0;
|
|
|
+ $bookItemCustomId = $bookData->id ?? 0;
|
|
|
+ $currentCustom = $customList[$customId] ?? null;
|
|
|
+ if (empty($currentCustom)) {
|
|
|
+ util::fail('客户信息缺失');
|
|
|
+ }
|
|
|
+
|
|
|
+ $confirmSendNum = $itemMaster->confirmSendNum ?? 0;
|
|
|
+ $remainCouldSendNum = bcsub($num, $confirmSendNum, 2);
|
|
|
+ if ($remainCouldSendNum <= 0) {
|
|
|
+ //剩余可分配数量不足则退出
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $bcInfo = BookCustomClass::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'customId' => $customId]);
|
|
|
+ if (empty($bcInfo)) {
|
|
|
+ util::fail('信息不完整');
|
|
|
+ }
|
|
|
+ if ($needCgNum >= $remainCouldSendNum) {
|
|
|
+ $remainNeedSendNum = $remainCouldSendNum;
|
|
|
+ } else {
|
|
|
+ $remainNeedSendNum = $needCgNum;
|
|
|
+ }
|
|
|
+ //待采数量减少
|
|
|
+ $bookData->needCgNum = bcsub($needCgNum, $remainNeedSendNum);
|
|
|
+ $bcInfo->needCgNum = bcsub($bcInfo->needCgNum, $remainNeedSendNum);
|
|
|
+ $itemMain->needCgNum = bcsub($itemMain->needCgNum, $remainNeedSendNum);
|
|
|
+ //路上数量增加
|
|
|
+ $bookData->roadNum = bcadd($bookData->roadNum, $remainNeedSendNum);
|
|
|
+ $bcInfo->roadNum = bcadd($bcInfo->roadNum, $remainNeedSendNum);
|
|
|
+ $itemMain->roadNum = bcsub($itemMain->roadNum, $remainNeedSendNum);
|
|
|
+ $bookData->save();
|
|
|
+ $bcInfo->save();
|
|
|
+ $itemMain->save();
|
|
|
+ //确认已分配数量增加
|
|
|
+ $itemMaster->confirmSendNum = bcadd($itemMaster->confirmSendNum, $remainNeedSendNum);
|
|
|
+ $itemMaster->save();
|
|
|
+
|
|
|
+ $sendInfo = CgOrderItemSendClass::getByCondition(['parentId' => $itemMasterId, 'customId' => $customId, 'itemId' => $productId], true);
|
|
|
+ if (empty($sendInfo)) {
|
|
|
+ $sendData = [
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'parentOrderId' => $cgId,
|
|
|
+ 'parentId' => $itemMasterId,
|
|
|
+ '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' => $itemMasterId,
|
|
|
+ '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();
|
|
|
}
|
|
|
}
|
|
|
}
|