feat(inventory): 优化库存转移订单功能
- 添加订单类型切换逻辑,支持不同类型的库存转移 - 完善订单详情页面,展示转出转入门店/仓库名称 - 增加商品列表展示,包含商品名称等信息 - 优化库存扣减逻辑,根据订单类型进行相应处理
This commit is contained in:
parent
daec144ca1
commit
ae40c1940f
@ -8,6 +8,8 @@ use app\common\logic\BaseLogic;
|
||||
use app\common\model\inventory_transfer\InventoryTransfer;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\warehouse\Warehouse;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
@ -31,6 +33,7 @@ class InventoryTransferOrderLogic extends BaseLogic
|
||||
*/
|
||||
public static function add(array $params,$admin_id): bool
|
||||
{
|
||||
$types=$params['types']??0;
|
||||
if (empty($params['product_arr'])) {
|
||||
throw new BusinessException('请选择商品');
|
||||
}
|
||||
@ -78,22 +81,26 @@ class InventoryTransferOrderLogic extends BaseLogic
|
||||
'two_type' => $params['two_type'],
|
||||
'one_id' => $params['one_id'],
|
||||
'two_id' => $params['two_id'],
|
||||
'types' => $params['types']??0,
|
||||
'types' => $types,
|
||||
'mark' => $params['mark']??'',
|
||||
]);
|
||||
foreach ($insert as $k => $v) {
|
||||
$insert[$k]['oid'] = $order['id'];
|
||||
}
|
||||
InventoryTransfer::insertAll($insert);
|
||||
if($types==1){
|
||||
Db::commit();
|
||||
return true;
|
||||
}
|
||||
foreach ($insert as $v) {
|
||||
if($params['one_type']==1){
|
||||
$find=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $params['one_id'])->find();
|
||||
$find->save(['stock' =>bcsub( $find['stock'],$v['nums'],2)]);
|
||||
SqlChannelLog('StoreBranchProduct', $find['id'], $v['nums'], -1, Request()->url(),$admin_id);
|
||||
$find=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $params['one_id'])->find();
|
||||
$find->save(['stock' =>bcsub( $find['stock'],$v['nums'],2)]);
|
||||
SqlChannelLog('StoreBranchProduct', $find['id'], $v['nums'], -1, Request()->url(),$admin_id);
|
||||
} elseif ($params['one_type'] == 2) {
|
||||
$find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id', $params['one_id'])->find();
|
||||
$find->save(['nums' =>bcsub( $find['nums'],$v['nums'],2)]);
|
||||
SqlChannelLog('WarehouseProductStorege', $find['id'], $v['nums'], -1, Request()->url(),$admin_id);
|
||||
$find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id', $params['one_id'])->find();
|
||||
$find->save(['nums' =>bcsub( $find['nums'],$v['nums'],2)]);
|
||||
SqlChannelLog('WarehouseProductStorege', $find['id'], $v['nums'], -1, Request()->url(),$admin_id);
|
||||
}
|
||||
if($params['two_type']==1){
|
||||
$find=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $params['two_id'])->find();
|
||||
@ -185,6 +192,28 @@ class InventoryTransferOrderLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return InventoryTransferOrder::findOrEmpty($params['id'])->toArray();
|
||||
$data= InventoryTransferOrder::findOrEmpty($params['id']);
|
||||
$type_name='';
|
||||
if($data->one_type==1){
|
||||
$data->one_name=SystemStore::where('id',$data->one_id)->value('name');
|
||||
$type_name='门店转';
|
||||
}else{
|
||||
$data->one_name=Warehouse::where('id',$data->one_id)->value('name');
|
||||
$type_name='仓库转';
|
||||
}
|
||||
if($data->two_type==1){
|
||||
$type_name.='门店';
|
||||
$data->two_name=SystemStore::where('id',$data->two_id)->value('name');
|
||||
}else{
|
||||
$type_name.='仓库';
|
||||
$data->two_name=Warehouse::where('id',$data->two_id)->value('name');
|
||||
}
|
||||
$data->type_name=$type_name;
|
||||
$data['product_list']=InventoryTransfer::where('oid',$params['id'])->select()->each(function ($item) {
|
||||
$find= StoreProduct::where('id',$item->product_id)->withTrashed()->field('store_name')->find();
|
||||
$item->store_name=$find['store_name'];
|
||||
})
|
||||
->toArray();
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user