itemId ?? 0; $product = ProductClass::getById($itemId, true); if (empty($product)) { util::fail('没有找到花材'); } $bookSn = $shop->bookSn ?? 0; $bookItemRes = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], true); if (empty($bookItemRes)) { util::fail('预订信息缺失'); } $onNum = $bookItemCustomRes->onNum ?? 0; if ($num > $onNum) { util::fail('下架数量超过已上架数'); } $needOffNum = $num; $params['currentChangeType'] = 'stockOff'; $bookItemRes = BookItemClass::delOnNum($bookItemRes, $needOffNum, 0, null, $shop, $product, $params); $bookItemCustomRes = self::delOnNum($bookItemCustomRes, $needOffNum, 0, null, $shop, $product, $params); $customId = $bookItemCustomRes->customId ?? 0; $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true); if (empty($bookCustomRes)) { util::fail('上架库存没有bookCustom...'); } $bookCustomRes = BookCustomClass::delOnNum($bookCustomRes, $needOffNum, 0, null, $shop, $product, $params); } //上架 $onSkip true 表示上齐的直接跳过 public static function goOn($bookItemCustomRes, $shop, $params, $num, $onSkip=false) { $itemId = $bookItemCustomRes->itemId ?? 0; $product = ProductClass::getById($itemId, true); if (empty($product)) { util::fail('没有找到花材'); } $bookNum = $bookItemCustomRes->bookNum ?? 0; $onNum = $bookItemCustomRes->onNum ?? 0; $itemName =$bookItemCustomRes->name ?? ''; $customName = $bookItemCustomRes->customName??''; if ($onNum >= $bookNum) { if($onSkip){ return true; }else{ util::fail('已经上齐'); } } $bookSn = $shop->bookSn ?? 0; $bookItemRes = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], true); if (empty($bookItemRes)) { util::fail('预订信息缺失'); } $hasOnNum = $bookItemRes->onNum; $stock = $product->stock ?? 0; $couldOnNum = bcsub($stock, $hasOnNum); if ($couldOnNum < 0) { util::fail('上架数量超过库存数量 bookItem'); } if ($num > 0) { //上指定数量 $needOnNum = $num; $maxNum = bcsub($bookNum, $onNum); if ($needOnNum > $maxNum) { util::fail("只需要上" . $maxNum . '份'); } } else { //上齐 $needOnNum = bcsub($bookNum, $onNum); } if ($needOnNum > $couldOnNum) { util::fail($customName.'的'.$itemName.' 可上' . $couldOnNum . '份,需上'.$needOnNum.'份'); } $params['currentChangeType'] = 'stockOn'; $bookItemRes = BookItemClass::addOnNum($bookItemRes, $needOnNum, null, $shop, $product, $params); $bookItemCustomRes = self::addOnNum($bookItemCustomRes, $needOnNum, null, $shop, $product, $params); $customId = $bookItemCustomRes->customId ?? 0; $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true); if (empty($bookCustomRes)) { util::fail('上架库存没有bookCustom...'); } $bookCustomRes = BookCustomClass::addOnNum($bookCustomRes, $needOnNum, null, $shop, $product, $params); } public static function cancelBox($bookItemCustomRes) { $bookItemCustomRes->box = 0; $bookItemCustomRes->save(); $bookSn = $bookItemCustomRes->bookSn ?? 0; $customId = $bookItemCustomRes->customId ?? 0; $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true); if (!empty($bookCustomRes)) { $bookCustomRes->box = 0; $bookCustomRes->save(); } return $bookItemCustomRes; } public static function toBox($bookItemCustomRes) { if ($bookItemCustomRes->box == 1) { util::fail('已装过箱了'); } if ($bookItemCustomRes->bookNum != $bookItemCustomRes->onNum) { util::fail('上架数量不等于预订数量'); } $bookItemCustomRes->box = 1; $bookItemCustomRes->save(); $bookSn = $bookItemCustomRes->bookSn ?? 0; $customId = $bookItemCustomRes->customId ?? 0; $list = BookItemCustomClass::getAllByCondition(['bookSn' => $bookSn, 'customId' => $customId,], null, '*', null, true); $allHasBox = 1; if (!empty($list)) { foreach ($list as $info) { if ($info->box == 0) { $allHasBox = 0; } } } if ($allHasBox == 1) { $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true); if (!empty($bookCustomRes)) { $bookCustomRes->box = 1; $bookCustomRes->save(); } } return $bookItemCustomRes; } public static function delOnNum($bookItemCustomRes, $delOnNum, $num, $bill, $shop, $product, $params) { $bookItemCustomRes->onNum = bcsub($bookItemCustomRes->onNum, $delOnNum); $bookItemCustomRes->save(); $bookItemResId = $bookItemCustomRes->id ?? 0; $ioRes = $params['ioRes'] ?? null; $relatedId = $ioRes->id ?? 0; //变动记录 $itemId = $product->id ?? 0; $ptItemId = $product->itemId ?? 0; $name = $product->name ?? ''; $py = $product->py ?? ''; $bigUnit = $product->bigUnit ?? '扎'; $bookSn = $shop->bookSn ?? ''; $mainId = $shop->mainId ?? 0; $staffName = $params['staffName'] ?? ''; $staffId = $params['staffId'] ?? 0; $currentChangeType = $params['currentChangeType'] ?? 'delBook'; if ($currentChangeType == 'ghsCgRefund') { //供货商采购单售后 $customId = $bookItemCustomRes->customId ?? 0; $customName = $bookItemCustomRes->customName ?? ''; $customNamePy = $bookItemCustomRes->customNamePy ?? ''; $orderSn = $bill->orderSn ?? ''; $event = $staffName . ' 售后采购单' . $orderSn . ',下架' . $name . $delOnNum . $bigUnit; $currentCapitalType = dict::getDict('capitalType', 'ghsCgRefund'); } elseif ($currentChangeType == 'stockOff') { $customId = $bookItemCustomRes->customId ?? 0; $customName = $bookItemCustomRes->customName ?? ''; $customNamePy = $bookItemCustomRes->customNamePy ?? ''; $currentCapitalType = 0; $event = $staffName . '手动下架' . $name . $delOnNum . $bigUnit; } elseif ($currentChangeType == 'delBook') { $customId = $bill->customId ?? 0; $customName = $bill->customName ?? ''; $customNamePy = $bill->customNamePy ?? ''; $event = $customName . '减少预订' . $name . $num . $bigUnit . ',其中下架' . $delOnNum . $bigUnit; $currentCapitalType = dict::getDict('capitalType', 'delBook'); } else { $currentCapitalType = dict::getDict('capitalType', 'delBook'); $customId = 0; $customName = ''; $customNamePy = ''; $event = ''; util::fail('不存在的运作哦!!!'); } $changeData = [ 'mainId' => $mainId, 'bookSn' => $bookSn, 'name' => $name, 'py' => $py, 'itemId' => $itemId, 'ptItemId' => $ptItemId, 'customId' => $customId, 'customName' => $customName, 'customNamePy' => $customNamePy, 'relateId' => $relatedId, 'relateSecondId' => $bookItemResId, 'ptStyle' => 2, 'capitalType' => $currentCapitalType, 'io' => 0, 'changeNum' => $delOnNum, 'num' => $bookItemCustomRes->onNum, 'event' => $event, 'staffId' => $staffId, 'staffName' => $staffName, 'remark' => '', ]; BookOnChangeClass::add($changeData, true); return $bookItemCustomRes; } public static function addOnNum($bookItemCustomRes, $addOnNum, $bill, $shop, $product, $params) { $bookItemCustomRes->onNum = bcadd($bookItemCustomRes->onNum, $addOnNum); $bookItemCustomRes->save(); $bookItemResId = $bookItemCustomRes->id ?? 0; $ioRes = $params['ioRes'] ?? null; $relatedId = $ioRes->id ?? 0; $itemId = $product->id ?? 0; $ptItemId = $product->itemId ?? 0; $name = $product->name ?? ''; $py = $product->py ?? ''; $bigUnit = $product->bigUnit ?? '扎'; $bookSn = $shop->bookSn ?? ''; $mainId = $shop->mainId ?? 0; $customId = $bookItemCustomRes->customId ?? 0; $customName = $bookItemCustomRes->customName ?? ''; $customNamePy = $bookItemCustomRes->customNamePy ?? ''; $currentCapitalType = dict::getDict('capitalType', 'ghsCheckIn'); $staffName = $params['staffName'] ?? ''; $staffId = $params['staffId'] ?? 0; $currentChangeType = $params['currentChangeType'] ?? 'putIn'; if ($currentChangeType == 'stockOn') { $currentCapitalType = 0; $event = "{$staffName} 手动上架 {$name} " . $addOnNum . $bigUnit; } elseif ($currentChangeType == 'putIn') { $orderSn = $bill->orderSn ?? ''; $event = "采购单 {$orderSn} 入库,{$name} 上架 " . $addOnNum . $bigUnit; } else { $event = ''; util::fail('无效动作'); } $changeData = [ 'mainId' => $mainId, 'bookSn' => $bookSn, 'name' => $name, 'py' => $py, 'itemId' => $itemId, 'ptItemId' => $ptItemId, 'customId' => $customId, 'customName' => $customName, 'customNamePy' => $customNamePy, 'relateId' => $relatedId, 'relateSecondId' => $bookItemResId, 'ptStyle' => 2, 'capitalType' => $currentCapitalType, 'io' => 1, 'changeNum' => $addOnNum, 'num' => $bookItemCustomRes->onNum, 'event' => $event, 'staffId' => $staffId, 'staffName' => $staffName, 'remark' => '', ]; BookOnChangeClass::add($changeData, true); return $bookItemCustomRes; } public static function addRoadNum($bookItemCustomRes, $addRoadNum, $bill, $shop, $product, $params) { $bookItemCustomRes->roadNum = bcadd($bookItemCustomRes->roadNum, $addRoadNum); $bookItemCustomRes->save(); $bookItemResId = $bookItemCustomRes->id ?? 0; $ioRes = $params['ioRes'] ?? null; $relatedId = $ioRes->id ?? 0; $bigUnit = $product->bigUnit ?? '扎'; $itemId = $product->id ?? 0; $ptItemId = $product->itemId ?? 0; $name = $product->name ?? ''; $py = $product->py ?? ''; $bookSn = $shop->bookSn ?? ''; $mainId = $shop->mainId ?? 0; $staffName = $params['staffName'] ?? ''; $staffId = $params['staffId'] ?? 0; $currentCapitalType = dict::getDict('capitalType', 'ghsPurchase'); $customId = $bookItemCustomRes->customId ?? 0; $customName = $bookItemCustomRes->customName ?? ''; $customNamePy = $bookItemCustomRes->customNamePy ?? ''; $orderSn = $bill->orderSn ?? ''; $event = "{$staffName} 新增待入库 {$orderSn},路上增加 {$name}" . $addRoadNum . $bigUnit; $changeData = [ 'mainId' => $mainId, 'bookSn' => $bookSn, 'name' => $name, 'py' => $py, 'itemId' => $itemId, 'ptItemId' => $ptItemId, 'customId' => $customId, 'customName' => $customName, 'customNamePy' => $customNamePy, 'relateId' => $relatedId, 'relateSecondId' => $bookItemResId, 'ptStyle' => 2, 'capitalType' => $currentCapitalType, 'io' => 1, 'changeNum' => $addRoadNum, 'num' => $bookItemCustomRes->roadNum, 'event' => $event, 'staffId' => $staffId, 'staffName' => $staffName, 'remark' => '', ]; BookRoadChangeClass::add($changeData, true); return $bookItemCustomRes; } public static function delRoadNum($bookItemCustomRes, $delRoadNum, $num, $bill, $shop, $product, $params) { $bookItemCustomRes->roadNum = bcsub($bookItemCustomRes->roadNum, $delRoadNum); $bookItemCustomRes->save(); $bookItemResId = $bookItemCustomRes->id ?? 0; $ioRes = $params['ioRes'] ?? null; $relatedId = $ioRes->id ?? 0; $bigUnit = $product->bigUnit ?? '扎'; $currentChangeType = $params['currentChangeType'] ?? 'delBook'; $itemId = $product->id ?? 0; $ptItemId = $product->itemId ?? 0; $name = $product->name ?? ''; $py = $product->py ?? ''; $bookSn = $shop->bookSn ?? ''; $mainId = $shop->mainId ?? 0; $currentCapitalType = dict::getDict('capitalType', 'delBook'); $staffName = $params['staffName'] ?? ''; $staffId = $params['staffId'] ?? 0; if ($currentChangeType == 'putIn') { //入库 $currentCapitalType = dict::getDict('capitalType', 'ghsCheckIn'); $customId = $bookItemCustomRes->customId ?? 0; $customName = $bookItemCustomRes->customName ?? ''; $customNamePy = $bookItemCustomRes->customNamePy ?? ''; $orderSn = $bill->orderSn ?? ''; $event = "采购单 {$orderSn} 入库上架,{$name} 路上减少" . $delRoadNum . $bigUnit; } elseif ($currentChangeType == 'cgCancel') { $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel'); $customId = $bookItemCustomRes->customId ?? 0; $customName = $bookItemCustomRes->customName ?? ''; $customNamePy = $bookItemCustomRes->customNamePy ?? ''; $orderSn = $bill->orderSn ?? ''; $event = "采购单 {$orderSn} 取消,{$name} 路上减少" . $delRoadNum . $bigUnit; } elseif ($currentChangeType == 'delBook') { //减少预订 $currentCapitalType = dict::getDict('capitalType', 'delBook'); $customId = $bill->customId ?? 0; $customName = $bill->customName ?? ''; $customNamePy = $bill->customNamePy ?? ''; $event = $customName . '减少预订' . $name . $num . $bigUnit . ',其中减少路上' . $delRoadNum . $bigUnit; } else { $event = ''; $customId = 0; $customName = ''; $customNamePy = ''; util::fail('此变动方式没有找到'); } $changeData = [ 'mainId' => $mainId, 'bookSn' => $bookSn, 'name' => $name, 'py' => $py, 'itemId' => $itemId, 'ptItemId' => $ptItemId, 'customId' => $customId, 'customName' => $customName, 'customNamePy' => $customNamePy, 'relateId' => $relatedId, 'relateSecondId' => $bookItemResId, 'ptStyle' => 2, 'capitalType' => $currentCapitalType, 'io' => 0, 'changeNum' => $delRoadNum, 'num' => $bookItemCustomRes->roadNum, 'event' => $event, 'staffId' => $staffId, 'staffName' => $staffName, 'remark' => '', ]; BookRoadChangeClass::add($changeData, true); return $bookItemCustomRes; } public static function delNeedCgNum($bookItemCustomRes, $delNeedCgNum, $totalBookNum, $bill, $shop, $product, $params) { $bookItemCustomRes->needCgNum = bcsub($bookItemCustomRes->needCgNum, $delNeedCgNum); $bookItemCustomRes->save(); $bookItemCustomResId = $bookItemCustomRes->id ?? 0; $ioRes = $params['ioRes'] ?? null; $relatedId = $ioRes->id ?? 0; $itemId = $product->id ?? 0; $ptItemId = $product->itemId ?? 0; $name = $product->name ?? ''; $py = $product->py ?? ''; $bigUnit = $product->bigUnit ?? '扎'; $bookSn = $shop->bookSn ?? ''; $mainId = $shop->mainId ?? 0; $currentCapitalType = dict::getDict('capitalType', 'delBook'); $staffName = $params['staffName'] ?? ''; $staffId = $params['staffId'] ?? 0; $customId = $bookItemCustomRes->customId ?? 0; $customName = $bookItemCustomRes->customName ?? ''; $customNamePy = $bookItemCustomRes->customNamePy ?? ''; $currentChangeType = $params['currentChangeType'] ?? 'delBook'; $event = ''; if ($currentChangeType == 'addCg') { $currentCapitalType = dict::getDict('capitalType', 'ghsPurchase'); $orderSn = $bill->orderSn ?? ''; $event = $staffName . "新增待入库 {$orderSn} 减少待采 {$name} " . $delNeedCgNum . $bigUnit; } elseif ($currentChangeType == 'pdAddStock') { $currentCapitalType = dict::getDict('capitalType', 'pd'); $event = $staffName . '盘点增加库存' . $delNeedCgNum . $bigUnit . ',减少待采' . $delNeedCgNum . $bigUnit; } elseif ($currentChangeType == 'loanStock') { $currentCapitalType = dict::getDict('capitalType', 'loanStock'); $outName = $params['outName'] ?? ''; $event = $staffName . '向' . $outName . '借库存' . $delNeedCgNum . $bigUnit . ',减少待采' . $delNeedCgNum . $bigUnit; } elseif ($currentChangeType == 'delBook') { $currentCapitalType = dict::getDict('capitalType', 'delBook'); $event = $customName . '减少预订' . $name . $totalBookNum . $bigUnit . ',其中减少待采' . $delNeedCgNum . $bigUnit; } else { util::fail('没有找到的操作'); } $changeData = [ 'mainId' => $mainId, 'bookSn' => $bookSn, 'name' => $name, 'py' => $py, 'itemId' => $itemId, 'ptItemId' => $ptItemId, 'customId' => $customId, 'customName' => $customName, 'customNamePy' => $customNamePy, 'relateId' => $relatedId, 'relateSecondId' => $bookItemCustomResId, 'ptStyle' => 2, 'capitalType' => $currentCapitalType, 'io' => 0, 'changeNum' => $delNeedCgNum, 'num' => $bookItemCustomRes->needCgNum, 'event' => $event, 'staffId' => $staffId, 'staffName' => $staffName, 'remark' => '', ]; BookCgChangeClass::add($changeData, true); return $bookItemCustomRes; } //预订增加待采数量 ssh 20240712 public static function addNeedCgNum($bookItemCustomRes, $addNeedCgNum, $totalBookNum, $bill, $shop, $product, $params) { $bookItemCustomRes->needCgNum = bcadd($bookItemCustomRes->needCgNum, $addNeedCgNum); $bookItemCustomRes->save(); $bookItemCustomResId = $bookItemCustomRes->id ?? 0; $ioRes = $params['ioRes'] ?? 0; $relatedId = $ioRes->id ?? 0; //待采增加变动记录 $itemId = $product->id ?? 0; $ptItemId = $product->itemId ?? 0; $name = $product->name ?? ''; $py = $product->py ?? ''; $bigUnit = $product->bigUnit ?? '扎'; $bookSn = $shop->bookSn ?? ''; $mainId = $shop->mainId ?? 0; $staffName = $params['staffName'] ?? ''; $staffId = $params['staffId'] ?? 0; $currentChangeType = $params['currentChangeType'] ?? 'delBook'; if ($currentChangeType == 'cgCancel') { $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel'); $customId = $bookItemCustomRes->customId ?? 0; $customName = $bookItemCustomRes->customName ?? ''; $customNamePy = $bookItemCustomRes->customNamePy ?? ''; $orderSn = $bill->orderSn ?? ''; $event = "采购单 {$orderSn} 取消,{$name} 增加待采" . $addNeedCgNum . $bigUnit; } elseif ($currentChangeType == 'delBook') { $currentCapitalType = dict::getDict('capitalType', 'addBook'); $customId = $bill->customId ?? 0; $customName = $bill->customName ?? ''; $customNamePy = $bill->customNamePy ?? ''; $event = $customName . '预订 ' . $name . $totalBookNum . $bigUnit . ',增加待采' . $addNeedCgNum . $bigUnit; } else { $customId = 0; $customName = ''; $customNamePy = ''; $currentCapitalType = dict::getDict('capitalType', 'addBook'); util::fail('没有'); } $changeData = [ 'mainId' => $mainId, 'bookSn' => $bookSn, 'name' => $name, 'py' => $py, 'itemId' => $itemId, 'ptItemId' => $ptItemId, 'customId' => $customId, 'customName' => $customName, 'customNamePy' => $customNamePy, 'relateId' => $relatedId, 'relateSecondId' => $bookItemCustomResId, 'ptStyle' => 2, 'capitalType' => $currentCapitalType, 'io' => 1, 'changeNum' => $addNeedCgNum, 'num' => $bookItemCustomRes->needCgNum, 'event' => $event, 'staffId' => $staffId, 'staffName' => $staffName, 'remark' => '', ]; BookCgChangeClass::add($changeData, true); return $bookItemCustomRes; } public static function addBookNum($bookItemCustomRes, $num, $order, $shop, $product, $params) { $currentNum = bcadd($bookItemCustomRes->bookNum, $num); $bookItemCustomRes->bookNum = $currentNum; $bookItemCustomRes->box = 0; $bookItemCustomRes->save(); $bookItemCustomResId = $bookItemCustomRes->id ?? 0; $ioRes = $params['ioRes'] ?? 0; $relatedId = $ioRes->id ?? 0; //预订增加变动记录 $itemId = $product->id ?? 0; $ptItemId = $product->itemId ?? 0; $name = $product->name ?? ''; $py = $product->py ?? ''; $bigUnit = $product->bigUnit ?? '扎'; $bookSn = $shop->bookSn ?? ''; $mainId = $order->mainId ?? 0; $customId = $order->customId ?? 0; $customName = $order->customName ?? ''; $customNamePy = $order->customNamePy ?? ''; $currentCapitalType = dict::getDict('capitalType', 'addBook'); $staffName = $params['staffName'] ?? ''; $staffId = $params['staffId'] ?? 0; $event = $customName . '预订' . $name . $num . $bigUnit; $changeData = [ 'mainId' => $mainId, 'bookSn' => $bookSn, 'name' => $name, 'py' => $py, 'itemId' => $itemId, 'ptItemId' => $ptItemId, 'customId' => $customId, 'customName' => $customName, 'customNamePy' => $customNamePy, 'relateId' => $relatedId, 'relateSecondId' => $bookItemCustomResId, 'ptStyle' => 2, 'capitalType' => $currentCapitalType, 'io' => 1, 'changeNum' => $num, 'num' => $bookItemCustomRes->bookNum, 'event' => $event, 'staffId' => $staffId, 'staffName' => $staffName, 'remark' => '', ]; BookChangeClass::add($changeData, true); return $bookItemCustomRes; } public static function delBookNum($bookItemCustomRes, $num, $order, $shop, $product, $params) { $mainId = $order->mainId ?? 0; $customId = $order->customId ?? 0; $customName = $order->customName ?? ''; $customNamePy = $order->customNamePy ?? ''; $itemId = $product->id ?? 0; $ptItemId = $product->itemId ?? 0; $name = $product->name ?? ''; $py = $product->py ?? ''; $bigUnit = $product->bigUnit ?? '扎'; $bookSn = $shop->bookSn ?? ''; $currentNum = bcsub($bookItemCustomRes->bookNum, $num); if ($currentNum < 0) { $cacheKey = $params['cacheKey'] ?? ''; if (!empty($cacheKey)) { util::unlock($cacheKey); } util::fail($customName . '预订的' . $name . '不够减 bookItemCustom'); } $bookItemCustomRes->bookNum = $currentNum; $bookItemCustomRes->save(); $bookItemCustomResId = $bookItemCustomRes->id ?? 0; $ioRes = $params['ioRes'] ?? null; $relatedId = $ioRes->id ?? 0; //变动记录 $currentCapitalType = dict::getDict('capitalType', 'delBook'); $staffName = $params['staffName'] ?? ''; $staffId = $params['staffId'] ?? 0; $event = $customName . '减少预订' . $name . $num . $bigUnit; $changeData = [ 'mainId' => $mainId, 'bookSn' => $bookSn, 'name' => $name, 'py' => $py, 'itemId' => $itemId, 'ptItemId' => $ptItemId, 'customId' => $customId, 'customName' => $customName, 'customNamePy' => $customNamePy, 'relateId' => $relatedId, 'relateSecondId' => $bookItemCustomResId, 'ptStyle' => 2, 'capitalType' => $currentCapitalType, 'io' => 0, 'changeNum' => $num, 'num' => $bookItemCustomRes->bookNum, 'event' => $event, 'staffId' => $staffId, 'staffName' => $staffName, 'remark' => '', ]; BookChangeClass::add($changeData, true); return $bookItemCustomRes; } }