更新
This commit is contained in:
parent
22c4cb8518
commit
b9298d45c0
@ -2339,7 +2339,12 @@ class ProductRepository extends BaseRepository
|
||||
$stockIn = $params['number'] ?? 0;
|
||||
$price = $params['price'] ?? 0;
|
||||
if ($stockIn == 0) {
|
||||
$stockIn = 1;
|
||||
$number=$model->where('order_id',$params['order_id'])
|
||||
->where('order_product_id',$params['order_product_id'])->where('order_unique',$params['order_unique'])->value('number');
|
||||
if($number<=0){
|
||||
throw new ValidateException('数量不能为空');
|
||||
}
|
||||
$stockIn = $number;
|
||||
}
|
||||
if (empty($params['product_id']) && !empty($params['order_product_id'])) {
|
||||
//有商品无规格或者无商品无规格,导入商品和规格
|
||||
@ -2353,10 +2358,10 @@ class ProductRepository extends BaseRepository
|
||||
if (empty($orderProduct)) {
|
||||
$unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']);
|
||||
if (!$unique) {
|
||||
throw new \Exception('商品规格导入出错', 500);
|
||||
throw new ValidateException('商品规格导入出错');
|
||||
}
|
||||
}
|
||||
if ($orderProduct->is_imported == 1) {
|
||||
if ($orderProduct->is_imported == 0) {
|
||||
|
||||
ProductAttrValue::where('mer_id', $merId)
|
||||
->where('product_id', $product['product_id'])
|
||||
@ -2373,10 +2378,12 @@ class ProductRepository extends BaseRepository
|
||||
'supplier_mer_id' => $orderMerId ?? 0,
|
||||
];
|
||||
if (!$model->save($data)) {
|
||||
throw new \Exception('入库失败', 500);
|
||||
throw new ValidateException('入库失败');
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
}else{
|
||||
throw new ValidateException('该商品已导入过');
|
||||
}
|
||||
$stockIn = $orderProduct['product_num'] ?? 0;
|
||||
$price = $orderProduct['product_price'] ?? 0;
|
||||
@ -2397,7 +2404,7 @@ class ProductRepository extends BaseRepository
|
||||
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $params['product_id'])->where('unique', $params['unique'])->find();
|
||||
}
|
||||
if (!$product || !$attrValue) {
|
||||
throw new DataNotFoundException('商品或规格不存在');
|
||||
throw new ValidateException('商品或规格不存在');
|
||||
}
|
||||
if ($stockIn <= 0) {
|
||||
throw new ValidateException('入库数量不能小于等于0');
|
||||
@ -2406,7 +2413,7 @@ class ProductRepository extends BaseRepository
|
||||
$attrValue->save();
|
||||
$product->stock = $stockIn + $product->stock;
|
||||
if (!$product->save()) {
|
||||
throw new \Exception('商品库存保存失败', 500);
|
||||
throw new ValidateException('商品库存保存失败');
|
||||
}
|
||||
$data = [
|
||||
'order_id' => $params['order_id'] ?? 0,
|
||||
@ -2420,15 +2427,15 @@ class ProductRepository extends BaseRepository
|
||||
'supplier_mer_id' => $supplierMerId,
|
||||
];
|
||||
if (!$model->save($data)) {
|
||||
throw new \Exception('入库失败', 500);
|
||||
throw new ValidateException('入库失败');
|
||||
}
|
||||
if (isset($orderProduct) && !$orderProduct->save(['is_imported' => 1])) {
|
||||
throw new \Exception('订单商品更新出错', 500);
|
||||
throw new ValidateException('订单商品更新出错');
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new \Exception($e->getMessage(), $e->getCode());
|
||||
throw new ValidateException($e->getMessage(), $e->getCode());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -239,8 +239,12 @@ class StoreProduct extends BaseController
|
||||
public function stockIn()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$this->repository->stockIn($this->merId, $params);
|
||||
return app('json')->success('入库成功');
|
||||
$res=$this->repository->stockIn($this->merId, $params);
|
||||
if($res){
|
||||
return app('json')->success('入库成功');
|
||||
}else{
|
||||
return app('json')->success('入库失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user