| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901 |
- <?php
- namespace bizGhs\book\classes;
- use bizGhs\base\classes\BaseClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\notify\classes\NotifyClass;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\shop\classes\ShopClass;
- use common\components\dict;
- use common\components\noticeUtil;
- use common\components\util;
- use Yii;
- class BookItemClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\book\models\BookItem';
- public static function delBathItem($batchData, $order, $params = [])
- {
- $orderId = $order->id ?? 0;
- $shopId = $order->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- util::fail('没有门店相关信息');
- }
- $bookSn = $shop->bookSn ?? '';
- $pfLevel = $shop->pfLevel ?? 0;
- if (empty($bookSn)) {
- if ($pfLevel == 1) {
- $sjName = $shop->merchantName ?? '';
- $shopName = $shop->shopName ?? '';
- $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- noticeUtil::push($currentName . ' 没有开启预订', '15280215347');
- util::fail('请先开启预订');
- }
- }
- $mainId = $order->mainId ?? 0;
- $customId = $order->customId ?? 0;
- $customName = $order->customName ?? '';
- $customNamePy = $order->customNamePy ?? '';
- $ids = array_column($batchData, 'productId');
- $infoList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
- foreach ($batchData as $data) {
- $itemId = $data['productId'] ?? 0;
- $product = $infoList[$itemId] ?? null;
- if (empty($product)) {
- util::fail('没有找到产品,ID:' . $itemId);
- }
- $ptItemId = $product->itemId ?? 0;
- $num = $data['num'] ?? 0;
- $name = $product->name ?? '';
- $py = $product->py ?? '';
- $cgStaffName = $product->cgStaffName ?? '';
- $cgStaffId = $product->cgStaffId ?? 0;
- if (empty($cgStaffId)) {
- if ($pfLevel == 1) {
- util::fail($name . '没有设置采购人');
- }
- }
- $cacheKey = 'change_book_item_num_' . $itemId;
- $noLock = util::lock($cacheKey);
- if (!$noLock) {
- util::fail("系统繁忙,1秒后再提交");
- }
- $lastNum = $data['lastNum'] ?? 0;
- $staffName = $params['staffName'] ?? '';
- $staffId = $params['staffId'] ?? 0;
- $ioData = [
- 'mainId' => $mainId,
- 'bookSn' => $bookSn,
- 'itemId' => $itemId,
- 'ptItemId' => $ptItemId,
- 'itemName' => $name,
- 'io' => 0,
- 'changeNum' => $num,
- 'num' => $lastNum,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'orderId' => $orderId,
- ];
- $ioRes = BookIoClass::add($ioData, true);
- $params['ioRes'] = $ioRes;
- $bookItemCustomRes = BookItemCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId, 'itemId' => $itemId], true);
- if (empty($bookItemCustomRes)) {
- $currentData = [
- 'name' => $name,
- 'py' => $py,
- 'mainId' => $mainId,
- 'itemId' => $itemId,
- 'ptItemId' => $ptItemId,
- 'customId' => $customId,
- 'customName' => $customName,
- 'customNamePy' => $customNamePy,
- 'cgStaffId' => $cgStaffId,
- 'cgStaffName' => $cgStaffName,
- 'bookSn' => $bookSn,
- ];
- $bookItemCustomRes = BookItemCustomClass::add($currentData, true);
- }
- $params['cacheKey'] = $cacheKey;
- $bookItemCustomRes = BookItemCustomClass::delBookNum($bookItemCustomRes, $num, $order, $shop, $product, $params);
- $bookItemRes = self::getByCondition(['bookSn' => $bookSn, 'itemId' => $itemId,], true);
- if (empty($bookItemRes)) {
- $statData = [
- 'mainId' => $mainId,
- 'itemId' => $itemId,
- 'ptItemId' => $ptItemId,
- 'name' => $name,
- 'bookSn' => $bookSn,
- 'py' => $py,
- 'cgStaffId' => $cgStaffId,
- 'cgStaffName' => $cgStaffName
- ];
- $bookItemRes = self::add($statData, true);
- }
- $bookItemRes = self::delBookNum($bookItemRes, $num, $order, $shop, $product, $params);
- $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true);
- if (empty($bookCustomRes)) {
- $currentData = [
- 'name' => $customName,
- 'py' => $customNamePy,
- 'mainId' => $mainId,
- 'customId' => $customId,
- 'bookSn' => $bookSn,
- ];
- $bookCustomRes = BookCustomClass::add($currentData, true);
- }
- $bookCustomRes = BookCustomChangeClass::delBookNum($bookCustomRes, $num, $order, $shop, $product, $params);
- //预订变化通知 ssh 20240820
- $noticeText = json_encode(['orderId' => $orderId, 'customName' => $customName, 'customId' => $customId, 'itemId' => $itemId, 'itemName' => $name, 'io' => 0, 'num' => $num, 'shopId' => $shopId]);
- $noticeKey = "bookChangeNoticeStaff";
- Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
- $firstRemainSubNum = 0;
- if ($bookItemCustomRes->needCgNum >= $num) {
- //待采数量足够扣
- $firstNeedSubNum = $num;
- } else {
- $firstNeedSubNum = $bookItemCustomRes->needCgNum;
- //待采数量不够扣
- $firstRemainSubNum = bcsub($num, $firstNeedSubNum);
- }
- $bookItemRes = self::delNeedCgNum($bookItemRes, $firstNeedSubNum, $num, $order, $shop, $product, $params);
- $bookCustomRes = BookCustomClass::delNeedCgNum($bookCustomRes, $firstNeedSubNum, $num, $order, $shop, $product, $params);
- $bookItemCustomRes = BookItemCustomClass::delNeedCgNum($bookItemCustomRes, $firstNeedSubNum, $num, $order, $shop, $product, $params);
- if ($firstRemainSubNum <= 0) {
- util::unlock($cacheKey);
- continue;
- }
- $secondRemainSubNum = 0;
- if ($bookItemCustomRes->roadNum >= $firstRemainSubNum) {
- //路上数量足够扣
- $secondNeedSubNum = $firstRemainSubNum;
- } else {
- //路上数量不够扣
- $secondNeedSubNum = $bookItemCustomRes->roadNum;
- $secondRemainSubNum = bcsub($firstRemainSubNum, $secondNeedSubNum);
- }
- $bookItemRes = self::delRoadNum($bookItemRes, $secondNeedSubNum, $num, $order, $shop, $product, $params);
- $bookItemCustomRes = BookItemCustomClass::delRoadNum($bookItemCustomRes, $secondNeedSubNum, $num, $order, $shop, $product, $params);
- $bookCustomRes = BookCustomClass::delRoadNum($bookCustomRes, $secondNeedSubNum, $num, $order, $shop, $product, $params);
- //删除供货商的路上数量!!!!
- BookItemGhsClass::delRoadNum($bookItemCustomRes, $secondNeedSubNum, $bookSn, $order);
- if ($secondRemainSubNum <= 0) {
- util::unlock($cacheKey);
- continue;
- }
- $thirdRemainSubNum = 0;
- if ($bookItemCustomRes->onNum > $secondRemainSubNum) {
- //上架数量够扣
- $thirdNeedSubNum = $secondRemainSubNum;
- } else {
- //上架数量不够扣
- $thirdNeedSubNum = $bookItemCustomRes->onNum;
- $thirdRemainSubNum = bcsub($secondRemainSubNum, $thirdNeedSubNum);
- }
- $bookItemRes = self::delOnNum($bookItemRes, $thirdNeedSubNum, $num, $order, $shop, $product, $params);
- $bookItemCustomRes = BookItemCustomClass::delOnNum($bookItemCustomRes, $thirdNeedSubNum, $num, $order, $shop, $product, $params);
- $bookCustomRes = BookCustomClass::delOnNum($bookCustomRes, $thirdNeedSubNum, $num, $order, $shop, $product, $params);
- //预订减少造成下架而产生通知
- if($thirdNeedSubNum>0){
- NotifyClass::bookReduceOutItem($bookItemCustomRes, $thirdNeedSubNum, $shop);
- }
- if ($thirdRemainSubNum <= 0) {
- util::unlock($cacheKey);
- continue;
- }
- //还有不够扣在库存里,不用任何处理
- $bookItemCustomRes->save();
- $bookItemRes->save();
- $bookCustomRes->save();
- util::unlock($cacheKey);
- }
- }
- //批量添加预订花材 ssh 20240711
- public static function addBatchItem($batchData, $order, $params = [])
- {
- $action = $params['action'] ?? 'update';
- $orderId = $order->id ?? 0;
- $shopId = $order->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- util::fail('没有门店相关信息');
- }
- $bookSn = $shop->bookSn ?? '';
- $pfLevel = $shop->pfLevel ?? 0;
- if (empty($bookSn)) {
- if ($pfLevel == 1) {
- $sjName = $shop->merchantName ?? '';
- $shopName = $shop->shopName ?? '';
- $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- noticeUtil::push($currentName . ' 没有开启预订', '15280215347');
- util::fail('请开启预订');
- }
- }
- $mainId = $order->mainId ?? 0;
- $customId = $order->customId ?? 0;
- $customName = $order->customName ?? '';
- $customNamePy = $order->customNamePy ?? '';
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- $seatSn = $custom->seatSn ?? '';
- $ids = array_column($batchData, 'productId');
- $infoList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
- foreach ($batchData as $data) {
- $itemId = $data['productId'] ?? 0;
- $product = $infoList[$itemId] ?? null;
- if (empty($product)) {
- util::fail('没有找到产品,ID:' . $itemId);
- }
- $ptItemId = $product->itemId ?? 0;
- $num = $data['num'] ?? 0;
- $name = $product->name ?? '';
- $py = $product->py ?? '';
- $cgStaffName = $product->cgStaffName ?? '';
- $cgStaffId = $product->cgStaffId ?? 0;
- if (empty($cgStaffId)) {
- if ($pfLevel == 1) {
- util::fail($name . '没有设置采购人');
- }
- }
- $cacheKey = 'change_book_item_num_' . $itemId;
- $noLock = util::lock($cacheKey);
- if (!$noLock) {
- util::fail("系统繁忙,1秒后再提交");
- }
- $lastNum = $data['lastNum'] ?? 0;
- $remark = $data['remark'] ?? '';
- $hasRemark = $data['hasRemark'] ?? 0;
- $staffName = $params['staffName'] ?? '';
- $staffId = $params['staffId'] ?? 0;
- $ioData = [
- 'mainId' => $mainId,
- 'bookSn' => $bookSn,
- 'itemId' => $itemId,
- 'ptItemId' => $ptItemId,
- 'itemName' => $name,
- 'io' => 1,
- 'changeNum' => $num,
- 'num' => $lastNum,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'orderId' => $orderId,
- ];
- $ioRes = BookIoClass::add($ioData, true);
- $params['ioRes'] = $ioRes;
- $bookItemRes = self::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'itemId' => $itemId,], true);
- if (empty($bookItemRes)) {
- $statData = [
- 'mainId' => $mainId,
- 'itemId' => $itemId,
- 'ptItemId' => $ptItemId,
- 'name' => $name,
- 'bookSn' => $bookSn,
- 'py' => $py,
- 'cgStaffId' => $cgStaffId,
- 'cgStaffName' => $cgStaffName,
- 'hasRemark' => $hasRemark,
- ];
- $bookItemRes = self::add($statData, true);
- }
- $currentStock = $product->stock;
- $totalHasNum = bcadd($currentStock, $bookItemRes->roadNum);
- $overNum = $bookItemRes->bookNum > $totalHasNum ? 0 : bcsub($totalHasNum, $bookItemRes->bookNum);
- //新增待采数量 = 预订数量 - 超出库存
- $needCgNumValue = bcsub($num, $overNum);
- $addNeedCgNum = $needCgNumValue < 0 ? 0 : $needCgNumValue;
- $bookItemRes = self::addBookNum($bookItemRes, $num, $order, $shop, $product, $params);
- self::addNeedCgNum($bookItemRes, $addNeedCgNum, $num, $order, $shop, $product, $params);
- $bookItemCustomRes = BookItemCustomClass::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'customId' => $customId, 'itemId' => $itemId], true);
- if (empty($bookItemCustomRes)) {
- $currentData = [
- 'name' => $name,
- 'py' => $py,
- 'mainId' => $mainId,
- 'itemId' => $itemId,
- 'ptItemId' => $ptItemId,
- 'customId' => $customId,
- 'customName' => $customName,
- 'customNamePy' => $customNamePy,
- 'seatSn' => $seatSn,
- 'cgStaffId' => $cgStaffId,
- 'cgStaffName' => $cgStaffName,
- 'bookSn' => $bookSn,
- 'hasRemark' => $hasRemark,
- 'remark' => $remark,
- ];
- $bookItemCustomRes = BookItemCustomClass::add($currentData, true);
- }
- $bookItemCustomRes = BookItemCustomClass::addBookNum($bookItemCustomRes, $num, $order, $shop, $product, $params);
- BookItemCustomClass::addNeedCgNum($bookItemCustomRes, $addNeedCgNum, $num, $order, $shop, $product, $params);
- $bookCustomRes = BookCustomClass::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'customId' => $customId], true);
- if (empty($bookCustomRes)) {
- $currentData = [
- 'name' => $customName,
- 'py' => $customNamePy,
- 'seatSn' => $seatSn,
- 'mainId' => $mainId,
- 'customId' => $customId,
- 'bookSn' => $bookSn,
- 'hasRemark' => $hasRemark,
- ];
- $bookCustomRes = BookCustomClass::add($currentData, true);
- }
- $bookCustomRes = BookCustomClass::addBookNum($bookCustomRes, $num, $order, $shop, $product, $params);
- BookCustomClass::addNeedCgNum($bookCustomRes, $addNeedCgNum, $num, $order, $shop, $product, $params);
- util::unlock($cacheKey);
- //添加到缓存,所有待入库采购单重新找货位号
- $cacheKey = 'assign_seat_main_book_sn_list';
- Yii::$app->redis->executeCommand('SADD', [$cacheKey, $bookSn]);
- //预订变化通知
- if($action == 'update'){
- $noticeText = json_encode(['orderId' => $orderId, 'customName' => $customName, 'customId' => $customId, 'itemId' => $itemId, 'itemName' => $name, 'io' => 1, 'num' => $num, 'shopId' => $shopId]);
- $noticeKey = "bookChangeNoticeStaff";
- Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
- }
- }
- }
- public static function addBookNum($bookItemRes, $num, $order, $shop, $product, $params)
- {
- $currentNum = bcadd($bookItemRes->bookNum, $num);
- $bookItemRes->bookNum = $currentNum;
- $bookItemRes->save();
- $bookItemResId = $bookItemRes->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 = $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' => $bookItemResId,
- 'ptStyle' => 2,
- 'capitalType' => $currentCapitalType,
- 'io' => 1,
- 'changeNum' => $num,
- 'num' => $bookItemRes->bookNum,
- 'event' => $event,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'remark' => '',
- ];
- BookChangeGlobalClass::add($changeData, true);
- return $bookItemRes;
- }
- public static function addOnNum($bookItemRes, $addOnNum, $bill, $shop, $product, $params)
- {
- $bookItemRes->onNum = bcadd($bookItemRes->onNum, $addOnNum);
- $bookItemRes->save();
- $bookItemResId = $bookItemRes->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 = $bill->customId ?? 0;
- $customName = $bill->customName ?? '';
- $customNamePy = $bill->customNamePy ?? '';
- $currentCapitalType = dict::getDict('capitalType', 'ghsCheckIn');
- $staffName = $params['staffName'] ?? '';
- $staffId = $params['staffId'] ?? 0;
- $orderSn = $bill->orderSn ?? '';
- $currentChangeType = $params['currentChangeType'] ?? 'putIn';
- if ($currentChangeType == 'stockOn') {
- $currentCapitalType = 0;
- $event = "{$staffName} 手动上架 {$name} " . $addOnNum . $bigUnit;
- } elseif ($currentChangeType == 'putIn') {
- $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' => $bookItemRes->onNum,
- 'event' => $event,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'remark' => '',
- ];
- BookOnChangeGlobalClass::add($changeData, true);
- return $bookItemRes;
- }
- public static function delOnNum($bookItemRes, $delOnNum, $num, $bill, $shop, $product, $params)
- {
- $bookItemRes->onNum = bcsub($bookItemRes->onNum, $delOnNum);
- $bookItemRes->save();
- $bookItemResId = $bookItemRes->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 = 0;
- $customName = '';
- $customNamePy = '';
- $orderSn = $bill->orderSn ?? '';
- $event = $staffName . ' 售后采购单' . $orderSn . ',下架' . $name . $delOnNum . $bigUnit;
- $currentCapitalType = dict::getDict('capitalType', 'ghsCgRefund');
- } elseif ($currentChangeType == 'stockOff') {
- $customId = 0;
- $customName = '';
- $customNamePy = '';
- $currentCapitalType = 0;
- $event = $staffName . '手动下架' . $name . $delOnNum . $bigUnit;
- } elseif ($currentChangeType == 'delBook') {
- $customId = $bill->customId ?? 0;
- $customName = $bill->customName ?? '';
- $customNamePy = $bill->customNamePy ?? '';
- $currentCapitalType = dict::getDict('capitalType', 'delBook');
- $event = $customName . '减少预订' . $name . $num . $bigUnit . ',其中下架' . $delOnNum . $bigUnit;
- } 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' => $bookItemRes->onNum,
- 'event' => $event,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'remark' => '',
- ];
- BookOnChangeGlobalClass::add($changeData, true);
- return $bookItemRes;
- }
- public static function addRoadNum($bookItemRes, $addRoadNum, $bill, $shop, $product, $params)
- {
- $bookItemRes->roadNum = bcadd($bookItemRes->roadNum, $addRoadNum);
- $bookItemRes->save();
- $bookItemResId = $bookItemRes->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;
- $currentCapitalType = dict::getDict('capitalType', 'ghsPurchase');
- $customId = $params['customId'] ?? 0;
- $customName = $params['customName'] ?? '';
- $customNamePy = $params['customNamePy'] ?? '';
- $orderSn = $bill->orderSn ?? '';
- $event = "{$staffName} 新增待入库 {$orderSn}({$customName}),路上增加 {$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' => $bookItemRes->roadNum,
- 'event' => $event,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'remark' => '',
- ];
- BookRoadChangeGlobalClass::add($changeData, true);
- return $bookItemRes;
- }
- public static function delRoadNum($bookItemRes, $delRoadNum, $num, $bill, $shop, $product, $params)
- {
- $bookItemRes->roadNum = bcsub($bookItemRes->roadNum, $delRoadNum);
- $bookItemRes->save();
- $bookItemResId = $bookItemRes->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;
- $currentChangeType = $params['currentChangeType'] ?? 'delBook';
- if ($currentChangeType == 'putIn') {
- //入库
- $currentCapitalType = dict::getDict('capitalType', 'ghsCheckIn');
- $customId = 0;
- $customName = '';
- $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;
- } elseif ($currentChangeType == 'cgCancel') {
- $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
- $customId = 0;
- $customName = '';
- $customNamePy = '';
- $orderSn = $bill->orderSn ?? '';
- $event = "采购单 {$orderSn} 取消,{$name} 路上减少" . $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' => $bookItemRes->roadNum,
- 'event' => $event,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'remark' => '',
- ];
- BookRoadChangeGlobalClass::add($changeData, true);
- return $bookItemRes;
- }
- public static function delNeedCgNum($bookItemRes, $delNeedCgNum, $totalBookNum, $bill, $shop, $product, $params)
- {
- $bookItemRes->needCgNum = bcsub($bookItemRes->needCgNum, $delNeedCgNum);
- $bookItemRes->save();
- $bookItemResId = $bookItemRes->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', 'addBook');
- $staffName = $params['staffName'] ?? '';
- $staffId = $params['staffId'] ?? 0;
- $currentChangeType = $params['currentChangeType'] ?? 'delBook';
- if ($currentChangeType == 'addCg') {
- $currentCapitalType = dict::getDict('capitalType', 'ghsPurchase');
- $customId = $params['customId'] ?? 0;
- $customName = $params['customName'] ?? '';
- $customNamePy = $params['customNamePy'] ?? '';
- $orderSn = $bill->orderSn ?? '';
- $event = $staffName . "新增加待入库 {$orderSn}({$customName}) 减少待采 {$name} " . $delNeedCgNum . $bigUnit;
- } elseif ($currentChangeType == 'pdAddStock') {
- $customId = 0;
- $customName = '';
- $customNamePy = '';
- $currentCapitalType = dict::getDict('capitalType', 'pd');
- $event = $staffName . '盘点增加库存' . $delNeedCgNum . $bigUnit . ',减少待采' . $delNeedCgNum . $bigUnit;
- } elseif ($currentChangeType == 'loanStock') {
- $currentCapitalType = dict::getDict('capitalType', 'loanStock');
- $outName = $params['outName'] ?? '';
- $customId = 0;
- $customName = '';
- $customNamePy = '';
- $event = $staffName . '向' . $outName . '借库存' . $delNeedCgNum . $bigUnit . ',减少待采' . $delNeedCgNum . $bigUnit;
- } elseif ($currentChangeType == 'delBook') {
- $customId = $bill->customId ?? 0;
- $customName = $bill->customName ?? '';
- $customNamePy = $bill->customNamePy ?? '';
- $event = $customName . '减少预订' . $name . $totalBookNum . $bigUnit . ',其中减少待采' . $delNeedCgNum . $bigUnit;
- } else {
- $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' => $delNeedCgNum,
- 'num' => $bookItemRes->needCgNum,
- 'event' => $event,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'remark' => '',
- ];
- BookCgChangeGlobalClass::add($changeData, true);
- return $bookItemRes;
- }
- public static function addNeedCgNum($bookItemRes, $addNeedCgNum, $totalBookNum, $bill, $shop, $product, $params)
- {
- $bookItemRes->needCgNum = bcadd($bookItemRes->needCgNum, $addNeedCgNum);
- $bookItemRes->save();
- $bookItemResId = $bookItemRes->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'] ?? 'addBook';
- if ($currentChangeType == 'cgCancel') {
- $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
- $customId = $bookCustomRes->customId ?? 0;
- $customName = $bookCustomRes->name ?? '';
- $customNamePy = $bookCustomRes->py ?? '';
- $orderSn = $bill->orderSn ?? '';
- $event = "采购单 {$orderSn} 取消,{$name} 增加待采" . $addNeedCgNum . $bigUnit;
- } elseif ($currentChangeType == 'refund') {
- $currentCapitalType = dict::getDict('capitalType', 'ghsCgRefund');
- $customId = $bookCustomRes->customId ?? 0;
- $customName = $bookCustomRes->name ?? '';
- $customNamePy = $bookCustomRes->py ?? '';
- $orderSn = $bill->orderSn ?? '';
- $event = "采购单 {$orderSn} 售后,{$name} 增加待采" . $addNeedCgNum . $bigUnit;
- } elseif ($currentChangeType == 'addBook') {
- $currentCapitalType = dict::getDict('capitalType', 'addBook');
- $customId = $bill->customId ?? 0;
- $customName = $bill->customName ?? '';
- $customNamePy = $bill->customNamePy ?? '';
- $event = $customName . '预订 ' . $name . $totalBookNum . $bigUnit . ',增加待采' . $addNeedCgNum . $bigUnit;
- } else {
- $currentCapitalType = dict::getDict('capitalType', 'addBook');
- $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' => 1,
- 'changeNum' => $addNeedCgNum,
- 'num' => $bookItemRes->needCgNum,
- 'event' => $event,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'remark' => '',
- ];
- BookCgChangeGlobalClass::add($changeData, true);
- return $bookItemRes;
- }
- public static function delBookNum($bookItemRes, $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($bookItemRes->bookNum, $num);
- if ($currentNum < 0) {
- $cacheKey = $params['cacheKey'] ?? '';
- if (!empty($cacheKey)) {
- util::unlock($cacheKey);
- }
- util::fail($customName . '预订的' . $name . '不够减 bookItemCustom');
- }
- $bookItemRes->bookNum = $currentNum;
- $bookItemRes->save();
- $bookItemCustomResId = $bookItemRes->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' => $bookItemRes->bookNum,
- 'event' => $event,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'remark' => '',
- ];
- BookChangeGlobalClass::add($changeData, true);
- return $bookItemRes;
- }
- }
|