修复采购入库

This commit is contained in:
shengchanzhe 2023-10-27 21:11:25 +08:00
parent 41b2df4a81
commit 79d4d3adb9

View File

@ -2328,37 +2328,24 @@ class ProductRepository extends BaseRepository
Db::startTrans();
try {
$supplierMerId = 0;
$model = new PurchaseRecord();
if (empty($params['product_id']) && !empty($params['order_product_id'])) {
//有商品无规格或者无商品无规格,导入商品和规格
$product = $this->getWhere(['source_product_id' => $params['order_product_id'], 'mer_id' => $merId]);
if (!empty($product)) {
$unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']);
if (!$unique) {
throw new \Exception('商品规格导入出错', 500);
}
} else {
$productId = $this->import($params['order_product_id'], request()->userInfo());
$product = $this->get($productId);
}
$sku = ProductAttrValue::where('product_id', $params['order_product_id'])->where('unique', $params['order_unique'])->value('sku');
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('sku', $sku)->find();
} else {
//有商品有规格
$product = $this->get($params['product_id']);
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $params['product_id'])->where('unique', $params['unique'])->find();
}
if (!$product || !$attrValue) {
throw new DataNotFoundException('商品或规格不存在');
}
if (!empty($product)) {
$stockIn = $params['number'] ?? 0;
$price = $params['price'] ?? 0;
$model = new PurchaseRecord();
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)) {
throw new ValidateException('订单商品不存在');
$unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']);
if (!$unique) {
throw new \Exception('商品规格导入出错', 500);
}
}
if( $orderProduct->is_imported == 1){
if($stockIn==0){
@ -2391,6 +2378,18 @@ class ProductRepository extends BaseRepository
$product->product_type = 98;
}
}
} else {
$productId = $this->import($params['order_product_id'], request()->userInfo());
$product = $this->get($productId);
}
} else {
//有商品有规格
$product = $this->get($params['product_id']);
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $params['product_id'])->where('unique', $params['unique'])->find();
}
if (!$product || !$attrValue) {
throw new DataNotFoundException('商品或规格不存在');
}
if ($stockIn <= 0) {
throw new ValidateException('入库数量不能小于等于0');
}