修改商品入库数量的错误

This commit is contained in:
luofei 2023-07-10 16:45:15 +08:00
parent 7806011ad5
commit de148080fd
2 changed files with 28 additions and 26 deletions

View File

@ -2311,31 +2311,32 @@ class ProductRepository extends BaseRepository
$price = $orderProduct['product_price'] ?? 0;
$supplierMerId = $orderMerId ?? 0;
}
if ($stockIn > 0) {
$attrValue->stock = $attrValue->stock + $stockIn;
$attrValue->save();
$product->stock = $stockIn + $product->stock;
if (!$product->save()) {
throw new \Exception('商品库存保存失败');
}
$model = new PurchaseRecord();
$data = [
'order_id' => $params['order_id'] ?? 0,
'order_product_id' => $params['order_product_id'] ?? 0,
'product_id' => $product->product_id,
'number' => $stockIn,
'order_unique' => $params['order_unique'] ?? '',
'unique' => $attrValue['unique'],
'price' => $price,
'mer_id' => $product->mer_id,
'supplier_mer_id' => $supplierMerId,
];
if (!$model->save($data)) {
throw new \Exception('入库失败');
}
if (isset($orderProduct) && !$orderProduct->save(['is_imported' => 1])) {
throw new \Exception('订单商品更新出错');
}
if ($stockIn <= 0) {
throw new \Exception('入库数量不能小于等于0');
}
$attrValue->stock = $attrValue->stock + $stockIn;
$attrValue->save();
$product->stock = $stockIn + $product->stock;
if (!$product->save()) {
throw new \Exception('商品库存保存失败');
}
$model = new PurchaseRecord();
$data = [
'order_id' => $params['order_id'] ?? 0,
'order_product_id' => $params['order_product_id'] ?? 0,
'product_id' => $product->product_id,
'number' => $stockIn,
'order_unique' => $params['order_unique'] ?? '',
'unique' => $attrValue['unique'],
'price' => $price,
'mer_id' => $product->mer_id,
'supplier_mer_id' => $supplierMerId,
];
if (!$model->save($data)) {
throw new \Exception('入库失败');
}
if (isset($orderProduct) && !$orderProduct->save(['is_imported' => 1])) {
throw new \Exception('订单商品更新出错');
}
Db::commit();
} catch (\Exception $e) {

View File

@ -29,7 +29,8 @@ class MerchantUpdateValidate extends Validate
'mer_address|店铺地址' => 'require|max:128',
'long|店铺经度' => 'max:24',
'lat|店铺纬度' => 'max:24',
'interest_rate|利率' => 'max:0.05',
'interest_rate|利率' => 'min:0.01|max:0.1',
'settle_cycle|结算周期' => 'min:15|max:90',
];
protected function isPhone($val)