diff --git a/app/common/repositories/community/CommunityRepository.php b/app/common/repositories/community/CommunityRepository.php index f25565e1..2c074e33 100644 --- a/app/common/repositories/community/CommunityRepository.php +++ b/app/common/repositories/community/CommunityRepository.php @@ -610,11 +610,13 @@ class CommunityRepository extends BaseRepository // if ($exist) { // throw new ValidateException('已发起转售'); // } - if (empty($purchaseRecord) || ($purchaseRecord['number'] - $purchaseRecord['sales_volume']) <= 0) { + $totalNumber = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('number'); + $totalSalesVolume = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('sales_volume'); + if (empty($purchaseRecord) || ($totalNumber - $totalSalesVolume) <= 0) { throw new ValidateException('进货记录不存在或已售罄'); } - if (($purchaseRecord['number'] - $purchaseRecord['sales_volume']) < $value['number']) { - throw new ValidateException('库存不足123'); + if (($totalNumber - $totalSalesVolume) < $value['number']) { + throw new ValidateException('库存不足'); } if ($value) {