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