HdRefundItemClass.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace bizHd\refund\classes;
  3. use bizGhs\product\classes\ProductClass;
  4. use bizGhs\stock\classes\StockRecordClass;
  5. use Yii;
  6. use bizHd\base\classes\BaseClass;
  7. class HdRefundItemClass extends BaseClass
  8. {
  9. public static $baseFile = '\bizHd\refund\models\HdRefundItem';
  10. public static function getItemListBySn($orderSn)
  11. {
  12. $list = self::getAllByCondition(['refundSn' => $orderSn], null, '*');
  13. return $list;
  14. }
  15. //退款的花材 ssh 20220427
  16. public static function addData($data, $refundSn, $post)
  17. {
  18. $itemId = $data['itemId'] ?? 0;
  19. $num = $data['num'] ?? 0;
  20. $unitType = $data['unitType'] ?? 0;
  21. $ratio = $data['ratio'] ?? 0;
  22. $ptItemId = $data['ptItemId'] ?? 0;
  23. $mainId = $data['mainId'] ?? 0;
  24. $shopId = $data['shopId'] ?? 0;
  25. $sjId = $data['sjId'] ?? 0;
  26. $shopAdminName = $post['shopAdminName'] ?? '';
  27. if ($unitType == 1) {
  28. $bigNum = 0;
  29. $smallNum = $num;
  30. } else {
  31. $bigNum = $num;
  32. $smallNum = 0;
  33. }
  34. $refundType = $post['refundType'] ?? 0;
  35. if ($refundType == 1) {
  36. if ($bigNum > 0 || $smallNum > 0) {
  37. $stockInfo = ProductClass::addStock($itemId, $bigNum, $smallNum);
  38. ProductClass::tryRecoverLimitBuyWhenStockRollbackFromZero($itemId, $stockInfo['oldStock']);
  39. $recordData = [];
  40. $recordData['sjId'] = $sjId;
  41. $recordData['shopId'] = $shopId;
  42. $recordData['mainId'] = $mainId;
  43. $recordData['itemId'] = $ptItemId;
  44. $recordData['itemNum'] = ProductClass::mergeItemNum($bigNum, $smallNum, $ratio);
  45. $recordData['oldStock'] = $stockInfo['oldStock'];
  46. $recordData['newStock'] = $stockInfo['newStock'];
  47. $recordData['productId'] = $itemId;
  48. $recordData['orderSn'] = $refundSn;
  49. $recordData['relateName'] = $shopAdminName;
  50. StockRecordClass::hdRefundAddRecord($recordData);
  51. }
  52. }
  53. return self::add($data);
  54. }
  55. }