调拨订单导出和插入修改1

This commit is contained in:
sjeam 2025-04-08 14:40:56 +08:00
parent 83fe8c4539
commit 5e378a3372
4 changed files with 22 additions and 26 deletions

View File

@ -40,7 +40,6 @@ class InventoryTransferController extends BaseAdminController
public function add() public function add()
{ {
$params = $this->request->post(); $params = $this->request->post();
// $params = (new InventoryTransferValidate())->post()->goCheck('add');
$result = InventoryTransferLogic::add($params, $this->adminId); $result = InventoryTransferLogic::add($params, $this->adminId);
if (true === $result) { if (true === $result) {
return $this->success('添加成功', [], 1, 1); return $this->success('添加成功', [], 1, 1);
@ -93,17 +92,4 @@ class InventoryTransferController extends BaseAdminController
$result = InventoryTransferLogic::detail($params); $result = InventoryTransferLogic::detail($params);
return $this->data($result); return $this->data($result);
} }
/**
* 导出调拨表格
*/
public function export()
{
$params = $this->request->post();
$xlsx = new InventoryTransferXlsx();
$order = InventoryTransferOrderLogic::detail($params);
$file_path = $xlsx->export($order['product_list'], $order);
return $this->success('导出成功', ['url' => $file_path]);
}
} }

View File

@ -104,4 +104,16 @@ class InventoryTransferOrderController extends BaseAdminController
InventoryTransferOrderLogic::audit($order); InventoryTransferOrderLogic::audit($order);
return $this->success('删除成功', [], 1, 1); return $this->success('删除成功', [], 1, 1);
} }
/**
* 导出调拨表格
*/
public function export()
{
$params = $this->request->post();
$xlsx = new InventoryTransferXlsx();
$order = InventoryTransferOrderLogic::detail($params);
$file_path = $xlsx->export($order['product_list'], $order);
return $this->success('导出成功', ['url' => $file_path]);
}
} }

View File

@ -30,10 +30,9 @@ class InventoryTransferLogic extends BaseLogic
* @author admin * @author admin
* @date 2024/08/13 16:18 * @date 2024/08/13 16:18
*/ */
public static function add(array $params, $admin_id = 0): bool public static function add(array $params, $admin_id = 0)
{ {
$find = InventoryTransferOrder::where('id', $params['oid'])->find()->toArray(); $find = InventoryTransferOrder::where('id', $params['oid'])->find()->toArray();
$types = $find['types'] ?? 0;
if (empty($params['product_arr'])) { if (empty($params['product_arr'])) {
throw new BusinessException('请选择商品'); throw new BusinessException('请选择商品');
} }
@ -54,12 +53,12 @@ class InventoryTransferLogic extends BaseLogic
Db::startTrans(); Db::startTrans();
try { try {
$insert = []; $insert = [];
foreach ($params['product_arr'] as $v) { foreach ($params['product_arr'] as $v) {
$outProduct = !empty($outProducts[$v['id']]) ? $outProducts[$v['id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['id']]; $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']]; $inProduct = !empty($inProducts[$v['id']]) ? $inProducts[$v['id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['id']];
if ($outProduct['stock'] < $v['nums']) { if ($outProduct['stock'] < $v['nums']) {
throw new BusinessException("出库商品库存不足 {$outProduct['product_id']} 调拨数量不能大于当前仓库库存"); throw new BusinessException("出库商品库存不足 {$outProduct['product_id']} 调拨数量不能大于当前仓库库存");
continue;
} }
$insert[] = [ $insert[] = [
'oid' => $find['id'], 'oid' => $find['id'],
@ -77,14 +76,14 @@ class InventoryTransferLogic extends BaseLogic
]; ];
} }
InventoryTransfer::insertAll($insert); InventoryTransfer::insertAll($insert);
if ($types == 0 && $params['two_type'] == 1) { if ($find['two_type'] == 1) {
InventoryTransferOrderLogic::audit($params, $insert, $admin_id); InventoryTransferOrderLogic::audit($find, $insert, $admin_id);
} }
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
return false; throw new BusinessException($e->getMessage());
} }
} }

View File

@ -300,7 +300,7 @@ class ProductSourceLinkInfoLogic extends BaseLogic
'warehouse_id' => $this->info['warehouse_id'], 'warehouse_id' => $this->info['warehouse_id'],
'store_id' => $this->info['store_id'], 'store_id' => $this->info['store_id'],
'oid' => $item['oid'], 'oid' => $item['oid'],
'types' => empty($this->info['types']) ? ProductSourceLinkInfo::TypeOut: $this->info['types'], 'types' => empty($this->info['types']) ? ProductSourceLinkInfo::TypeOut : $this->info['types'],
'link_id' => $this->info['link_id'], 'link_id' => $this->info['link_id'],
'from_id' => $item['id'], 'from_id' => $item['id'],
'nums' => $needNum, 'nums' => $needNum,
@ -474,10 +474,10 @@ class ProductSourceLinkInfoLogic extends BaseLogic
foreach ($list as $item) { foreach ($list as $item) {
$currentNum = max(bcsub($item['current_nums'], $needNum, 2), 0); $currentNum = max(bcsub($item['current_nums'], $needNum, 2), 0);
if ($item['current_nums'] > $needNum) { if ($item['current_nums'] > $needNum) {
[$update, $insert] = $this->getInsertAndUpdate2($update, $insert, $currentNum, $item, $needNum); [$update, $insert] = $this->getInsertAndUpdate($update, $insert, $currentNum, $item, $needNum);
break; break;
} else { } else {
[$update, $insert] = $this->getInsertAndUpdate2($update, $insert, 0, $item, $item['current_nums']); [$update, $insert] = $this->getInsertAndUpdate($update, $insert, 0, $item, $item['current_nums']);
} }
$needNum = $needNum - $item['current_nums']; $needNum = $needNum - $item['current_nums'];
} }
@ -542,5 +542,4 @@ class ProductSourceLinkInfoLogic extends BaseLogic
(new ProductSourceLinkInfo())->insertAll($insert); (new ProductSourceLinkInfo())->insertAll($insert);
return true; return true;
} }
}
}