新增补单类型并调整库存逻辑
- 在订单列表中新增"往期补单"类型 - 调整仓库产品逻辑,对不同订单类型进行区分处理 - 优化库存更新流程,修复了一些潜在的问题
This commit is contained in:
parent
316c016b0c
commit
edec1712dc
@ -64,6 +64,8 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
|
||||
$item->order_type_name='线上订单';
|
||||
}elseif($item->order_type==5){
|
||||
$item->order_type_name='仓库补货';
|
||||
}elseif($item->order_type==6){
|
||||
$item->order_type_name='往期补单';
|
||||
}
|
||||
$item->msg='';
|
||||
$count1=PurchaseProductOffer::where('order_id',$item->id)->where('buyer_confirm',0)->count('id');
|
||||
|
@ -39,34 +39,9 @@ class WarehouseProductLogic extends BaseLogic
|
||||
try {
|
||||
$before_nums = 0;
|
||||
$after_nums = 0;
|
||||
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storege) {
|
||||
if ($params['financial_pm'] == 0) {
|
||||
$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 {
|
||||
if ($params['order_type'] != 6) {
|
||||
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storege) {
|
||||
$after_nums = $storege['nums'] + $params['nums'];
|
||||
if ($type == 1) {
|
||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
|
||||
@ -76,25 +51,25 @@ class WarehouseProductLogic extends BaseLogic
|
||||
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
||||
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();
|
||||
$data = [
|
||||
@ -124,20 +99,9 @@ class WarehouseProductLogic extends BaseLogic
|
||||
$data['expiration_date'] = strtotime($params['expiration_date']);
|
||||
}
|
||||
$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;
|
||||
} catch (\Throwable $e) {
|
||||
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();
|
||||
try {
|
||||
$after_nums = 0;
|
||||
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storege) {
|
||||
SystemStoreStorage::create([
|
||||
'store_id' => $params['store_id'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
'order_type' => $params['order_type'],
|
||||
'staff_id' => 0,
|
||||
'type' => 1,
|
||||
'product_id' => $params['product_id'],
|
||||
'nums' => $params['nums'],
|
||||
'status' =>0
|
||||
]);
|
||||
$after_nums = bcsub($storege['nums'], $params['nums']);
|
||||
$total_price = bcmul($after_nums, $params['purchase'], 2);
|
||||
WarehouseProductStorege::update(['nums' =>bcsub($storege['nums'], $params['nums']), 'total_price' => $total_price], ['id' => $storege['id']]);
|
||||
if ($params['order_type'] != 6) {
|
||||
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storege) {
|
||||
SystemStoreStorage::create([
|
||||
'store_id' => $params['store_id'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
'order_type' => $params['order_type'],
|
||||
'staff_id' => 0,
|
||||
'type' => 1,
|
||||
'product_id' => $params['product_id'],
|
||||
'nums' => $params['nums'],
|
||||
'status' => 0
|
||||
]);
|
||||
$after_nums = bcsub($storege['nums'], $params['nums']);
|
||||
$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 {
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user