refactor(warehouse): 重构仓库订单创建逻辑

- 修改 order_type 字段为 type,提高代码可读性
- 添加 type 字段到 WarehouseOrder 模型,用于区分订单类型
- 更新 WarehouseProductLogic::setOutbound 方法,替代原有的 add 方法
- 优化订单编号生成逻辑,根据订单类型动态生成
This commit is contained in:
mkm 2024-12-19 11:26:41 +08:00
parent 535bd7e47e
commit 18185dab6c

View File

@ -74,10 +74,10 @@ class WarehouseOrderController extends BaseAdminController
$warehouse_id = $this->request->post('warehouse_id');
$delivery_time = $this->request->post('delivery_time');
$mark = $this->request->post('mark');
$order_type = $this->request->post('order_type', 1);
$type = $this->request->post('order_type', 1);
Db::startTrans();
try {
if($order_type==1){
if($type==1){
$code=getNewOrderId('TGY');
}else{
$code=getNewOrderId('BS');
@ -104,7 +104,8 @@ class WarehouseOrderController extends BaseAdminController
'nums' => $arr['stock'],
'status' => 1,
'admin_id' => $this->adminId,
'order_type' => $order_type,
'type' => $type,
'order_type' => 0,
];
$storeProduct = StoreProduct::where('id', $arr['id'])->find();
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
@ -112,7 +113,7 @@ class WarehouseOrderController extends BaseAdminController
$data['oid'] = $res['id'];
$data['financial_pm'] = 0;
$data['price'] = $storeProduct['price'];
WarehouseProductLogic::add($data);
WarehouseProductLogic::setOutbound($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']]);
}