refactor(warehouse): 重构仓库出库逻辑

- 移除了单店和多店的区分逻辑
- 新增了订单类型的判断逻辑
- 优化了订单创建和商品添加的流程
- 删除了一些冗余代码
- 调整了部分变量命名
This commit is contained in:
mkm 2024-12-19 10:55:14 +08:00
parent bdc290c6b1
commit 535bd7e47e
2 changed files with 79 additions and 86 deletions

View File

@ -71,27 +71,22 @@ class WarehouseOrderController extends BaseAdminController
public function outbound()
{
$product_arr = $this->request->post('product_arr');
$store_arr = $this->request->post('store_arr');
$warehouse_id = $this->request->post('warehouse_id');
$delivery_time = $this->request->post('delivery_time');
$mark = $this->request->post('mark');
$count = count($store_arr);
// foreach ($product_arr as $key => $arr) {
// $stock = bcmul($arr['stock'], $count);
// $nums = WarehouseProductStorege::where('warehouse_id', $warehouse_id)->where('product_id', $arr['id'])->value('nums');
// if ($nums < $stock) {
// return $this->fail('商品库存不足');
// }
// }
$order_type = $this->request->post('order_type', 1);
Db::startTrans();
try {
if ($count == 1) {
$store_id = $store_arr[0];
if($order_type==1){
$code=getNewOrderId('TGY');
}else{
$code=getNewOrderId('BS');
}
$arr = [
'warehouse_id' => $warehouse_id,
'store_id' => $store_id,
'store_id' => 0,
'supplier_id' => 0,
'code' => getNewOrderId('PS'),
'code' => $code,
'admin_id' => $this->adminId,
'financial_pm' => 0,
'batch' => 0,
@ -103,33 +98,30 @@ class WarehouseOrderController extends BaseAdminController
$data = [
'warehouse_id' => $warehouse_id,
'product_id' => $arr['id'],
'store_id' => $store_id,
'store_id' => 0,
'financial_pm' => 0,
'batch' => 1,
'nums' => $arr['stock'],
'status' => 1,
'admin_id' => $this->adminId,
'order_type' => $order_type,
];
$storeProduct = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
if ($arr['stock'] == 0) {
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $storeProduct);
} else {
$storeProduct = StoreProduct::where('id', $arr['id'])->find();
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
$data['purchase'] = $storeProduct['purchase'];
$data['oid'] = $res['id'];
$data['financial_pm'] = 0;
$data['price'] = $storeProduct['price'];
WarehouseProductLogic::add($data);
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
}
}
}
Db::commit();
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1);
return $this->success('出库成功', [], 1, 1);
}
@ -155,7 +147,8 @@ class WarehouseOrderController extends BaseAdminController
* @author admin
* @date 2024/08/20 10:50
*/
public function update_edit(){
public function update_edit()
{
$params = $this->request->post();
$result = WarehouseOrderLogic::update_edit($params);
if (true === $result) {

View File

@ -91,7 +91,7 @@ class WarehouseProductLogic extends BaseLogic
'nums' => $params['nums'],
'before_nums' => $before_nums,
'after_nums' => $after_nums,
// 'price' => $params['price'] ?? '',
'price' => $params['price'] ?? '',
'purchase' => $params['purchase'] ?? '',
// 'cost' => $params['cost'] ?? '',
'total_price' => $params['total_price'] ?? '',