This commit is contained in:
shengchanzhe 2023-10-27 19:04:56 +08:00
parent 4d55c6f19f
commit 11dff348e7

View File

@ -682,35 +682,39 @@ class CommunityRepository extends BaseRepository
$entrustInfo->update($value); $entrustInfo->update($value);
continue; continue;
} }
$purchaseRecord = PurchaseRecord::where('unique', $value['product_attr_unique'])->find();
$totalNumber = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('number'); // $purchaseRecord = PurchaseRecord::where('unique', $value['product_attr_unique'])->find();
$totalSalesVolume = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('sales_volume'); // $totalNumber = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('number');
if (empty($purchaseRecord) || ($totalNumber - $totalSalesVolume) <= 0) { // $totalSalesVolume = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('sales_volume');
throw new ValidateException('进货记录不存在或已售罄'); // if (empty($purchaseRecord) || ($totalNumber - $totalSalesVolume) <= 0) {
} // throw new ValidateException('进货记录不存在或已售罄');
if (($totalNumber - $totalSalesVolume) < $value['number']) { // }
throw new ValidateException('库存不足'); // if (($totalNumber - $totalSalesVolume) < $value['number']) {
} // throw new ValidateException('库存不足');
// }
if ($value) { if ($value) {
$insert[] = [ $attrValue = ProductAttrValue::where('unique', $value['product_attr_unique'])->find();
'community_id' => $id, if($attrValue){
'purchase_record_id' => $purchaseRecord['id'], $insert[] = [
'product_id' => $purchaseRecord['product_id'], 'community_id' => $id,
'product_attr_unique' => $purchaseRecord['unique'], 'purchase_record_id' => 0,//$purchaseRecord['id'],
'mer_id' => $purchaseRecord['mer_id'], 'product_id' => $attrValue['product_id'],
'entrust_mer_id' => $entrustMerId, 'product_attr_unique' => $attrValue['unique'],
'entrust_day' => $entrustDay, 'mer_id' => $attrValue['mer_id'],
'number' => $value['number'], 'entrust_mer_id' => $entrustMerId,
'price' => $value['price'], 'entrust_day' => $entrustDay,
'update_time' => date('Y-m-d H:i:s'), 'number' => $value['number'],
]; 'price' => $value['price'],
'update_time' => date('Y-m-d H:i:s'),
];
$attrValue->stock -= $value['number'];
$attrValue->save();
}
} }
$purchaseRecord->product->stock -= $value['number']; // $purchaseRecord->product->stock -= $value['number'];
$purchaseRecord->product->save(); // $purchaseRecord->product->save();
$attrValue = ProductAttrValue::where('product_id', $purchaseRecord['product_id'])->where('unique', $purchaseRecord['unique'])->find();
$attrValue->stock -= $value['number'];
$attrValue->save();
} }
if ($insert) { if ($insert) {
Entrust::getInstance()->insertAll($insert); Entrust::getInstance()->insertAll($insert);