Merge pull request 'feat(inventory): 优化库存转移订单功能' (#489) from dev into main

Reviewed-on: #489
This commit is contained in:
mkm 2025-01-24 16:17:06 +08:00
commit 72b593bb91

View File

@ -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();
}
}