CgRefundItemClass.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace bizGhs\cg\classes;
  3. use bizGhs\base\classes\BaseClass;
  4. use common\components\util;
  5. use Yii;
  6. use bizGhs\product\classes\ProductClass;
  7. use bizGhs\stock\classes\StockRecordClass;
  8. class CgRefundItemClass extends BaseClass
  9. {
  10. public static $baseFile = '\bizGhs\cg\models\CgRefundItem';
  11. public static function addData($data, $order)
  12. {
  13. $productId = $data['itemId'] ?? 0;
  14. $smallNum = 0;
  15. $bigNum = $data['num'] ?? 0;
  16. $refundSn = $data['refundSn'] ?? '';
  17. $ptItemId = $data['ptItemId'] ?? 0;
  18. $name = $data['name'] ?? '';
  19. $mainId = $order->mainId ?? 0;
  20. $shopId = $order->shopId ?? 0;
  21. $sjId = $order->sjId ?? 0;
  22. $ghsName = $order->ghsName ?? '';
  23. $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum);
  24. $oldStock = $stockInfo['oldStock'] ?? 0;
  25. $newStock = $stockInfo['newStock'] ?? 0;
  26. if ($newStock < 0) {
  27. util::fail("退货失败,{$name}库存不足" . $bigNum);
  28. }
  29. $recordData = [];
  30. $recordData['itemNum'] = $bigNum;
  31. $recordData['ptStyle'] = 2;
  32. $recordData['sjId'] = $sjId;
  33. $recordData['shopId'] = $shopId;
  34. $recordData['mainId'] = $mainId;
  35. $recordData['orderSn'] = $refundSn;
  36. $recordData['itemId'] = $ptItemId;
  37. $recordData['oldStock'] = $oldStock; //当时库存
  38. $recordData['productId'] = $productId;
  39. $recordData['newStock'] = $newStock;// 最新库存
  40. $recordData['relateName'] = $ghsName;
  41. StockRecordClass::ghsCgApplyRefundAddRecord($recordData);
  42. self::add($data);
  43. }
  44. }