| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658 |
- <?php
- namespace bizGhs\book\classes;
- use bizGhs\base\classes\BaseClass;
- use bizGhs\product\classes\ProductClass;
- use common\components\dict;
- use common\components\util;
- use Yii;
- class BookItemCustomClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\book\models\BookItemCustom';
- //下架
- public static function goOff($bookItemCustomRes, $shop, $params, $num)
- {
- $itemId = $bookItemCustomRes->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;
- }
- }
|