From 5e378a3372462da4c0706787c01b76d236536acf Mon Sep 17 00:00:00 2001 From: sjeam <359824901@qq.com> Date: Tue, 8 Apr 2025 14:40:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=8B=A8=E8=AE=A2=E5=8D=95=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=92=8C=E6=8F=92=E5=85=A5=E4=BF=AE=E6=94=B91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InventoryTransferController.php | 14 -------------- .../InventoryTransferOrderController.php | 12 ++++++++++++ .../inventory_transfer/InventoryTransferLogic.php | 13 ++++++------- .../ProductSourceLinkInfoLogic.php | 9 ++++----- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/app/admin/controller/inventory_transfer/InventoryTransferController.php b/app/admin/controller/inventory_transfer/InventoryTransferController.php index 21a556984..49848d287 100644 --- a/app/admin/controller/inventory_transfer/InventoryTransferController.php +++ b/app/admin/controller/inventory_transfer/InventoryTransferController.php @@ -40,7 +40,6 @@ class InventoryTransferController extends BaseAdminController public function add() { $params = $this->request->post(); - // $params = (new InventoryTransferValidate())->post()->goCheck('add'); $result = InventoryTransferLogic::add($params, $this->adminId); if (true === $result) { return $this->success('添加成功', [], 1, 1); @@ -93,17 +92,4 @@ class InventoryTransferController extends BaseAdminController $result = InventoryTransferLogic::detail($params); 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]); - } } diff --git a/app/admin/controller/inventory_transfer_order/InventoryTransferOrderController.php b/app/admin/controller/inventory_transfer_order/InventoryTransferOrderController.php index 7968d1093..f9c9dbcef 100644 --- a/app/admin/controller/inventory_transfer_order/InventoryTransferOrderController.php +++ b/app/admin/controller/inventory_transfer_order/InventoryTransferOrderController.php @@ -104,4 +104,16 @@ class InventoryTransferOrderController extends BaseAdminController InventoryTransferOrderLogic::audit($order); 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]); + } } diff --git a/app/admin/logic/inventory_transfer/InventoryTransferLogic.php b/app/admin/logic/inventory_transfer/InventoryTransferLogic.php index eda3f0609..ba59d138c 100644 --- a/app/admin/logic/inventory_transfer/InventoryTransferLogic.php +++ b/app/admin/logic/inventory_transfer/InventoryTransferLogic.php @@ -30,10 +30,9 @@ class InventoryTransferLogic extends BaseLogic * @author admin * @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(); - $types = $find['types'] ?? 0; if (empty($params['product_arr'])) { throw new BusinessException('请选择商品'); } @@ -54,12 +53,12 @@ class InventoryTransferLogic extends BaseLogic Db::startTrans(); try { $insert = []; - 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("出库商品库存不足 {$outProduct['product_id']} 调拨数量不能大于当前仓库库存"); + continue; } $insert[] = [ 'oid' => $find['id'], @@ -77,14 +76,14 @@ class InventoryTransferLogic extends BaseLogic ]; } InventoryTransfer::insertAll($insert); - if ($types == 0 && $params['two_type'] == 1) { - InventoryTransferOrderLogic::audit($params, $insert, $admin_id); + if ($find['two_type'] == 1) { + InventoryTransferOrderLogic::audit($find, $insert, $admin_id); } Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/product_source_link_info/ProductSourceLinkInfoLogic.php b/app/admin/logic/product_source_link_info/ProductSourceLinkInfoLogic.php index 176fee5fd..2fb9a194b 100644 --- a/app/admin/logic/product_source_link_info/ProductSourceLinkInfoLogic.php +++ b/app/admin/logic/product_source_link_info/ProductSourceLinkInfoLogic.php @@ -300,7 +300,7 @@ class ProductSourceLinkInfoLogic extends BaseLogic 'warehouse_id' => $this->info['warehouse_id'], 'store_id' => $this->info['store_id'], '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'], 'from_id' => $item['id'], 'nums' => $needNum, @@ -474,10 +474,10 @@ class ProductSourceLinkInfoLogic extends BaseLogic foreach ($list as $item) { $currentNum = max(bcsub($item['current_nums'], $needNum, 2), 0); if ($item['current_nums'] > $needNum) { - [$update, $insert] = $this->getInsertAndUpdate2($update, $insert, $currentNum, $item, $needNum); + [$update, $insert] = $this->getInsertAndUpdate($update, $insert, $currentNum, $item, $needNum); break; } 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']; } @@ -542,5 +542,4 @@ class ProductSourceLinkInfoLogic extends BaseLogic (new ProductSourceLinkInfo())->insertAll($insert); return true; } - -} \ No newline at end of file +}