This commit is contained in:
mkm 2023-11-16 15:59:53 +08:00
parent 62b5044d33
commit 7f2f1057df

View File

@ -2338,6 +2338,12 @@ class ProductRepository extends BaseRepository
$model = new PurchaseRecord();
$stockIn = $params['number'] ?? 0;
$price = $params['price'] ?? 0;
$orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])
->where('product_sku', $params['order_unique'])->find();
$stockIn=$orderProduct['product_num'];
if ($stockIn <= 0) {
throw new ValidateException('入库数量不能小于等于0');
}
if (empty($params['product_id']) && !empty($params['order_product_id'])) {
//有商品无规格或者无商品无规格,导入商品和规格
$product = $this->getWhere(['source_product_id' => $params['order_product_id'], 'mer_id' => $merId]);
@ -2346,7 +2352,6 @@ class ProductRepository extends BaseRepository
if (!empty($params['order_id'])) {
//采购、委托订单导入
$orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id');
$orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])->where('product_sku', $params['order_unique'])->find();
if (empty($orderProduct)) {
$unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']);
if (!$unique) {
@ -2354,7 +2359,6 @@ class ProductRepository extends BaseRepository
}
}
if ($orderProduct->is_imported == 0) {
$stockIn=$orderProduct['product_num'];
$attrValue->update(['stock' => $attrValue->stock + $stockIn]);
$product->stock = $stockIn + $product->stock;
$data = [
@ -2398,9 +2402,6 @@ class ProductRepository extends BaseRepository
if (!$product || !$attrValue) {
throw new ValidateException('商品或规格不存在');
}
if ($stockIn <= 0) {
throw new ValidateException('入库数量不能小于等于0');
}
$attrValue->stock = $attrValue->stock + $stockIn;
$attrValue->save();
$product->stock = $stockIn + $product->stock;