更新先货后款
This commit is contained in:
parent
caddda1c41
commit
ba38d4a1c5
@ -623,39 +623,40 @@ class CommunityRepository extends BaseRepository
|
||||
$resale->update($value);
|
||||
continue;
|
||||
}
|
||||
$purchaseRecord = PurchaseRecord::where('unique', $value['product_attr_unique'])->find();
|
||||
// $purchaseRecord = PurchaseRecord::where('unique', $value['product_attr_unique'])->find();
|
||||
// $exist = Resale::where('purchase_record_id', $purchaseRecord['id'])->find();
|
||||
// if ($exist) {
|
||||
// throw new ValidateException('已发起转售');
|
||||
// }
|
||||
$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 (($totalNumber - $totalSalesVolume) < $value['number']) {
|
||||
throw new ValidateException('库存不足');
|
||||
}
|
||||
|
||||
// $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 (($totalNumber - $totalSalesVolume) < $value['number']) {
|
||||
// throw new ValidateException('库存不足');
|
||||
// }
|
||||
if ($value) {
|
||||
$insert[] = [
|
||||
'community_id' => $id,
|
||||
'purchase_record_id' => $purchaseRecord['id'],
|
||||
'product_id' => $purchaseRecord['product_id'],
|
||||
'product_attr_unique' => $purchaseRecord['unique'],
|
||||
'mer_id' => $purchaseRecord['mer_id'],
|
||||
'number' => $value['number'],
|
||||
'price' => $value['price'],
|
||||
'resale_type' => $resaleType,
|
||||
'deliver_method' => $value['deliver_method'] ?? '',
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
$attrValue = ProductAttrValue::where('unique', $value['product_attr_unique'])->find();
|
||||
if($attrValue){
|
||||
$insert[] = [
|
||||
'community_id' => $id,
|
||||
'purchase_record_id' => 0,
|
||||
'product_id' => $attrValue['product_id'],
|
||||
'product_attr_unique' => $attrValue['unique'],
|
||||
'mer_id' => $attrValue['mer_id'],
|
||||
'number' => $value['number'],
|
||||
'price' => $value['price'],
|
||||
'resale_type' => $resaleType,
|
||||
'deliver_method' => $value['deliver_method'] ?? '',
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
$attrValue->stock -= $value['number'];
|
||||
$attrValue->save();
|
||||
}
|
||||
|
||||
}
|
||||
$purchaseRecord->product->stock -= $value['number'];
|
||||
$purchaseRecord->product->save();
|
||||
$attrValue = ProductAttrValue::where('product_id', $purchaseRecord['product_id'])->where('unique', $purchaseRecord['unique'])->find();
|
||||
$attrValue->stock -= $value['number'];
|
||||
$attrValue->save();
|
||||
|
||||
}
|
||||
if ($insert) {
|
||||
Resale::getInstance()->insertAll($insert);
|
||||
|
Loading…
x
Reference in New Issue
Block a user