调拨订单导出和插入修改
This commit is contained in:
parent
dd681470d8
commit
d05a8c842d
@ -114,7 +114,7 @@ class InventoryTransferOrderController extends BaseAdminController
|
||||
public function insert()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$result = InventoryTransferOrderLogic::insert($params);
|
||||
$result = InventoryTransferOrderLogic::insert($params, $this->adminId);
|
||||
if (true == $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
|
@ -237,22 +237,56 @@ class InventoryTransferOrderLogic extends BaseLogic
|
||||
/**
|
||||
* 插入调拨订单
|
||||
*/
|
||||
public static function insert($params)
|
||||
public static function insert($params, $admin_id)
|
||||
{
|
||||
$find = InventoryTransferOrder::where('id', $params['oid'])->find()->toArray();
|
||||
$types = $find['types'] ?? 0;
|
||||
if (empty($params['product_arr'])) {
|
||||
throw new BusinessException('请选择商品');
|
||||
}
|
||||
$productIds = array_column($params['product_arr'], 'id');
|
||||
if ($find['one_type'] == 1) {
|
||||
$outProducts = StoreBranchProduct::whereIn('product_id', $productIds)->where('store_id', $find['one_id'])->field('id,product_id,stock')->select()->toArray();
|
||||
} else {
|
||||
$outProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $find['one_id'])->field('id,product_id,nums stock')->select()->toArray();
|
||||
}
|
||||
$outProducts = reset_index($outProducts, 'product_id');
|
||||
if ($find['two_type'] == 1) {
|
||||
$inProducts = StoreBranchProduct::whereIn('product_id', $productIds)->where('store_id', $find['two_id'])->field('id,product_id,stock')->select()->toArray();
|
||||
} else {
|
||||
$inProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $find['two_id'])->field('id,product_id,nums stock')->select()->toArray();
|
||||
}
|
||||
$inProducts = reset_index($inProducts, 'product_id');
|
||||
$insert = [];
|
||||
Db::startTrans();
|
||||
try {
|
||||
$product_arr = $params['product_arr'];
|
||||
$insert = [];
|
||||
foreach ($product_arr as $v) {
|
||||
$find = InventoryTransfer::where('product_id', $v['id'])->where('oid', $params['oid'])->find()->toArray();
|
||||
if ($find) {
|
||||
unset($find['id']);
|
||||
$find['nums'] = $v['nums'];
|
||||
$find['create_time'] = time();
|
||||
$insert[] = $find;
|
||||
|
||||
foreach ($params['product_arr'] as $v) {
|
||||
$outProduct = !empty($outProducts[$v['id']]) ? $outProducts[$v['id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['id']];
|
||||
$inProduct = !empty($inProducts[$v['id']]) ? $inProducts[$v['id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['id']];
|
||||
if ($outProduct['stock'] < $v['nums']) {
|
||||
throw new BusinessException("{$v['nums']}-{$outProduct['stock']}出库商品{$find['one_id']} 库存不足 {$outProduct['product_id']} 调拨数量不能大于当前仓库库存");
|
||||
}
|
||||
$insert[] = [
|
||||
'oid' => $find['id'],
|
||||
'product_id' => $v['id'],
|
||||
'nums' => $v['nums'],
|
||||
'one_before_nums' => $outProduct['stock'],
|
||||
'one_after_nums' => bcsub($outProduct['stock'], $v['nums']),
|
||||
'two_before_nums' => $inProduct['stock'],
|
||||
'two_after_nums' => bcadd($inProduct['stock'], $v['nums']),
|
||||
'one_type' => $find['one_type'],
|
||||
'two_type' => $find['two_type'],
|
||||
'one_id' => $find['one_id'],
|
||||
'two_id' => $find['two_id'],
|
||||
'create_time' => time(),
|
||||
];
|
||||
}
|
||||
InventoryTransfer::insertAll($insert);
|
||||
if ($types == 0 && $params['two_type'] == 1) {
|
||||
self::audit($params, $insert, $admin_id);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -260,25 +294,4 @@ class InventoryTransferOrderLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * 插入调拨订单
|
||||
// */
|
||||
// public static function insert($params)
|
||||
// {
|
||||
// Db::startTrans();
|
||||
// try {
|
||||
// $find = InventoryTransfer::where('product_id', $params['product_id'])->where('oid', $params['id'])->find()->toArray();
|
||||
// if ($find) {
|
||||
// unset($find['id']);
|
||||
// $find['nums'] = $params['nums'];
|
||||
// $find['create_time'] = time();
|
||||
// }
|
||||
// InventoryTransfer::insert($find);
|
||||
// Db::commit();
|
||||
// return true;
|
||||
// } catch (\Throwable $e) {
|
||||
// Db::rollback();
|
||||
// throw new BusinessException($e->getMessage());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user