|
|
@@ -3,6 +3,10 @@
|
|
|
namespace bizGhs\cg\classes;
|
|
|
|
|
|
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 common\components\util;
|
|
|
use Yii;
|
|
|
|
|
|
@@ -11,4 +15,80 @@ class CgOrderItemSendClass extends BaseClass
|
|
|
|
|
|
public static $baseFile = '\bizGhs\cg\models\CgOrderItemSend';
|
|
|
|
|
|
+ //售后产生下架 ssh 20240707
|
|
|
+ public static function afterSaleOut($shop, $order, $currentCgItem, $num)
|
|
|
+ {
|
|
|
+ //如果有预订活动,货位数量也要变化
|
|
|
+ if (isset($shop->pfLevel) && $shop->pfLevel == 1 && isset($shop->bookSn) && !empty($shop->bookSn)) {
|
|
|
+ if (isset($order->bookSn) && $shop->bookSn == $order->bookSn) {
|
|
|
+ $currentCgItemId = $currentCgItem->id ?? 0;
|
|
|
+ $totalNeedOutNum = $num;
|
|
|
+ $sendList = self::getAllByCondition(['parentId' => $currentCgItemId], null, '*', null, true);
|
|
|
+ if (!empty($sendList)) {
|
|
|
+ foreach ($sendList as $send) {
|
|
|
+ if ($totalNeedOutNum > 0) {
|
|
|
+ $sendNum = $send->num ?? 0;
|
|
|
+ $sendOutNum = $send->outNum ?? 0;
|
|
|
+ $couldOutNum = bcsub($sendNum, $sendOutNum);
|
|
|
+ if ($totalNeedOutNum >= $couldOutNum) {
|
|
|
+ $needOutNum = $couldOutNum;
|
|
|
+ } else {
|
|
|
+ $needOutNum = $totalNeedOutNum;
|
|
|
+ }
|
|
|
+ $totalNeedOutNum = bcsub($totalNeedOutNum, $needOutNum);
|
|
|
+ $send->outNum = bcadd($send->outNum, $needOutNum);
|
|
|
+ $send->save();
|
|
|
+
|
|
|
+ $bookGhsGiveId = $send->bookGhsGiveId ?? 0;
|
|
|
+ $give = BookItemGhsClass::getById($bookGhsGiveId, true);
|
|
|
+ if (empty($give)) {
|
|
|
+ util::fail('售后时,货位配送相关信息缺失哦');
|
|
|
+ }
|
|
|
+ $give->outNum = bcadd($give->outNum, $needOutNum);
|
|
|
+ $give->save();
|
|
|
+
|
|
|
+ $bookItemCustomId = $send->bookItemCustomId ?? 0;
|
|
|
+ $bookItemCustomRes = BookItemCustomClass::getById($bookItemCustomId, true);
|
|
|
+ if (empty($bookItemCustomRes)) {
|
|
|
+ util::fail('售后时,bookItemCustom信息缺失');
|
|
|
+ }
|
|
|
+ $onNum = $bookItemCustomRes->onNum ?? 0;
|
|
|
+ if ($needOutNum > $onNum) {
|
|
|
+ util::fail('售后时,bookItemCustom上架数量不够扣');
|
|
|
+ }
|
|
|
+ $bookItemCustomRes->onNum = bcsub($bookItemCustomRes->onNum, $needOutNum);
|
|
|
+ $bookItemCustomRes->save();
|
|
|
+ $customId = $bookItemCustomRes->customId ?? 0;
|
|
|
+ $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $order->bookSn, 'customId' => $customId], true);
|
|
|
+ if (empty($bookCustomRes)) {
|
|
|
+ util::fail('售后时,bookCustom信息缺失');
|
|
|
+ }
|
|
|
+ $onNum2 = $bookCustomRes->onNum ?? 0;
|
|
|
+ if ($needOutNum > $onNum2) {
|
|
|
+ util::fail('售后时,bookCustom上架数量不够扣');
|
|
|
+ }
|
|
|
+ $bookCustomRes->onNum = bcsub($bookCustomRes->onNum, $needOutNum);
|
|
|
+ $bookCustomRes->save();
|
|
|
+
|
|
|
+ $itemId = $bookItemCustomRes->itemId ?? 0;
|
|
|
+ $bookItemRes = BookItemClass::getByCondition(['bookSn' => $order->bookSn, 'itemId' => $itemId], true);
|
|
|
+ if (empty($bookItemRes)) {
|
|
|
+ util::fail('售后时,bookItem信息缺失');
|
|
|
+ }
|
|
|
+ $onNum3 = $bookItemRes->onNum ?? 0;
|
|
|
+ if ($needOutNum > $onNum3) {
|
|
|
+ util::fail('售后时,bookItem上架数量不够扣');
|
|
|
+ }
|
|
|
+ $bookItemRes->onNum = bcsub($bookItemRes->onNum, $needOutNum);
|
|
|
+ $bookItemRes->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($totalNeedOutNum > 0) {
|
|
|
+ util::fail('售后下架数量不足');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|