| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace bizGhs\book\classes;
- use bizGhs\base\classes\BaseClass;
- use bizGhs\cg\classes\CgOrderItemClass;
- use bizGhs\cg\classes\CgOrderItemSendClass;
- use bizGhs\shop\classes\ShopAdminClass;
- use common\components\util;
- use Yii;
- class BookItemGhsClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\book\models\BookItemGhs';
- public static function delRoadNum($bookItemCustomRes, $totalNum, $bookSn, $order)
- {
- $bookItemCustomResId = $bookItemCustomRes->id ?? 0;
- $ghsList = self::getAllByCondition(['parentId' => $bookItemCustomResId], null, '*', null, true);
- if (empty($ghsList)) {
- //有预订单但还没有采购单时会这样
- return true;
- }
- foreach ($ghsList as $ghsRes) {
- $status = $ghsRes->status ?? 0;
- if ($status != 0) {
- continue;
- }
- if ($totalNum <= 0) {
- break;
- }
- $num = $ghsRes->num ?? 0;
- $cgSendId = $ghsRes->cgSendId ?? 0;
- $send = CgOrderItemSendClass::getById($cgSendId, true);
- if (empty($send)) {
- util::fail('预订减少删路上数时,没找到供货2');
- }
- $cgOrderId = $send->parentOrderId ?? 0;
- $cgOrderItemId = $send->parentId ?? 0;
- $cgOrderItemRes = CgOrderItemClass::getById($cgOrderItemId, true);
- if (empty($cgOrderItemRes)) {
- util::fail('预订减少删路上数时,没找到供货3');
- }
- if ($num >= $totalNum) {
- $delNum = $totalNum;
- } else {
- $delNum = $num;
- }
- $totalNum = bcsub($totalNum, $delNum);
- $ghsRemainNum = bcsub($ghsRes->num, $delNum);
- $ghsRes->num = $ghsRemainNum;
- $ghsRes->save();
- $sendRemainNum = bcsub($send->num, $delNum);
- $send->num = $sendRemainNum;
- $send->save();
- $confirmSendNum = $cgOrderItemRes->confirmSendNum ?? 0;
- $lastConfirm = bcsub($confirmSendNum, $delNum);
- if ($lastConfirm < 0) {
- util::fail('预订减少删路上数时,没找到供货4');
- }
- $cgOrderItemRes->confirmSendNum = $lastConfirm;
- $cgOrderItemRes->save();
- //通知采购单页要刷新货位
- $cacheKey = 'ghs_cg_order_staff_refresh_seat_' . $bookSn;
- $mainId = $order->mainId ?? 0;
- $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
- if (!empty($staffList)) {
- foreach ($staffList as $staff) {
- $staffId = $staff->id ?? 0;
- $ele = $cgOrderId . '-' . $staffId;
- Yii::$app->redis->executeCommand('SADD', [$cacheKey, $ele]);
- }
- }
- $cacheKey = 'ghs_cg_order_guest_refresh_seat_' . $bookSn;
- Yii::$app->redis->executeCommand('SADD', [$cacheKey, $cgOrderId]);
- }
- }
- }
|