新增补单类型并调整库存逻辑

- 在订单列表中新增"往期补单"类型
- 调整仓库产品逻辑,对不同订单类型进行区分处理
- 优化库存更新流程,修复了一些潜在的问题
This commit is contained in:
mkm 2024-10-15 15:25:24 +08:00
parent 316c016b0c
commit edec1712dc
2 changed files with 43 additions and 73 deletions

View File

@ -64,6 +64,8 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
$item->order_type_name='线上订单'; $item->order_type_name='线上订单';
}elseif($item->order_type==5){ }elseif($item->order_type==5){
$item->order_type_name='仓库补货'; $item->order_type_name='仓库补货';
}elseif($item->order_type==6){
$item->order_type_name='往期补单';
} }
$item->msg=''; $item->msg='';
$count1=PurchaseProductOffer::where('order_id',$item->id)->where('buyer_confirm',0)->count('id'); $count1=PurchaseProductOffer::where('order_id',$item->id)->where('buyer_confirm',0)->count('id');

View File

@ -39,34 +39,9 @@ class WarehouseProductLogic extends BaseLogic
try { try {
$before_nums = 0; $before_nums = 0;
$after_nums = 0; $after_nums = 0;
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find(); if ($params['order_type'] != 6) {
if ($storege) { $storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
if ($params['financial_pm'] == 0) { if ($storege) {
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
if (!$storeProduct) {
throw new BusinessException('商品不存在');
}
$after_nums = $storege['nums'] - $params['nums'];
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
// if ($after_nums < 0) {
// throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']);
// }
WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price], ['id' => $storege['id']]);
//门店加库存
$storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['store_id'])->find();
if (!$storeBranchProduct) {
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
if (!$storeProduct) {
throw new BusinessException('商品不存在');
}
$storeBranchProduct = StoreProductLogic::ordinary(['id' => $params['product_id']], $params['store_id'], $params['admin_id'], $storeProduct);
}
if ($params['nums'] > 0 && $type == 1) {
StoreBranchProductLogic::stock(['id' => $storeBranchProduct['id'], 'product_id' => $params['product_id'], 'nums' => $params['nums']]);
}
} else {
$after_nums = $storege['nums'] + $params['nums']; $after_nums = $storege['nums'] + $params['nums'];
if ($type == 1) { if ($type == 1) {
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty(); $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
@ -76,25 +51,25 @@ class WarehouseProductLogic extends BaseLogic
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2); $total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price], ['id' => $storege['id']]); WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price], ['id' => $storege['id']]);
} }
$before_nums = $storege['nums'];
} else {
$after_nums = $params['nums'];
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
if (!$storeProduct) {
throw new BusinessException('商品不存在');
}
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
$data = [
'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'total_price' => $total_price
];
if ($params['financial_pm'] == 0) {
$data['nums'] = -$params['nums'];
}
$storege = WarehouseProductStorege::create($data);
} }
$before_nums = $storege['nums'];
} else {
$after_nums = $params['nums'];
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
if (!$storeProduct) {
throw new BusinessException('商品不存在');
}
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
$data = [
'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'total_price' => $total_price
];
if ($params['financial_pm'] == 0) {
$data['nums'] = -$params['nums'];
}
$storege = WarehouseProductStorege::create($data);
} }
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count(); $batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count();
$data = [ $data = [
@ -124,20 +99,9 @@ class WarehouseProductLogic extends BaseLogic
$data['expiration_date'] = strtotime($params['expiration_date']); $data['expiration_date'] = strtotime($params['expiration_date']);
} }
$res = WarehouseProduct::create($data); $res = WarehouseProduct::create($data);
//更改采购订单状态
if (isset($params['purchase_product_offer_id']) && $params['purchase_product_offer_id'] != '') {
PurchaseProductOffer::where('id', $params['purchase_product_offer_id'])->update(['is_storage' => 1, 'supplier_id' => $params['supplier_id'] ?? 0]);
}
// self::enter($res['id'], $params['financial_pm']);
// Db::commit();
return $res; return $res;
} catch (\Throwable $e) { } catch (\Throwable $e) {
throw new BusinessException($e->getMessage()); throw new BusinessException($e->getMessage());
// Db::rollback();
// Log::error($e->getMessage().',file:'.$e->getFile().',line:'.$e->getLine());
// self::setError($e->getMessage());
// return false;
} }
} }
@ -149,23 +113,27 @@ class WarehouseProductLogic extends BaseLogic
Db::startTrans(); Db::startTrans();
try { try {
$after_nums = 0; $after_nums = 0;
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find(); if ($params['order_type'] != 6) {
if ($storege) { $storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
SystemStoreStorage::create([ if ($storege) {
'store_id' => $params['store_id'], SystemStoreStorage::create([
'admin_id' => $params['admin_id'], 'store_id' => $params['store_id'],
'order_type' => $params['order_type'], 'admin_id' => $params['admin_id'],
'staff_id' => 0, 'order_type' => $params['order_type'],
'type' => 1, 'staff_id' => 0,
'product_id' => $params['product_id'], 'type' => 1,
'nums' => $params['nums'], 'product_id' => $params['product_id'],
'status' =>0 'nums' => $params['nums'],
]); 'status' => 0
$after_nums = bcsub($storege['nums'], $params['nums']); ]);
$total_price = bcmul($after_nums, $params['purchase'], 2); $after_nums = bcsub($storege['nums'], $params['nums']);
WarehouseProductStorege::update(['nums' =>bcsub($storege['nums'], $params['nums']), 'total_price' => $total_price], ['id' => $storege['id']]); $total_price = bcmul($after_nums, $params['purchase'], 2);
WarehouseProductStorege::update(['nums' => bcsub($storege['nums'], $params['nums']), 'total_price' => $total_price], ['id' => $storege['id']]);
} else {
throw new BusinessException('仓库商品不存在' . '|' . $params['product_id']);
}
} else { } else {
throw new BusinessException('仓库商品不存在'.'|'.$params['product_id']); $storege['nums'] = 0;
} }
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count(); $batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count();