From 7fc4d872496d8de63889eebdb79127e9ee71e7e2 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Mon, 17 Mar 2025 18:47:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81=E6=BA=AF?= =?UTF-8?q?=E6=BA=90=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProductSourceLinkController.php | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/admin/controller/product_source_link/ProductSourceLinkController.php b/app/admin/controller/product_source_link/ProductSourceLinkController.php index 9b4cd00c..ae18746c 100644 --- a/app/admin/controller/product_source_link/ProductSourceLinkController.php +++ b/app/admin/controller/product_source_link/ProductSourceLinkController.php @@ -10,7 +10,7 @@ use app\admin\validate\product_source_link\ProductSourceLinkValidate; use app\common\model\product_source_link\ProductSourceLink; use app\common\model\product_source_link_info\ProductSourceLinkInfo; use app\common\model\store_product\StoreProduct; -use app\common\model\warehouse_order\WarehouseOrder; +use app\common\model\warehouse_product\WarehouseProduct; use app\common\service\xlsx\ProductSourceLinkXsl; @@ -105,17 +105,14 @@ class ProductSourceLinkController extends BaseAdminController if (!empty($params['warehouse_id'])) { $query->where('warehouse_id', $params['warehouse_id']); } - $list = $query->with(['product', 'warehouse', 'purchase']) - ->field(['id', 'purchase_uid', 'product_id', 'warehouse_id',]) + $list = $query->with(['product', 'purchase']) + ->field(['id', 'purchase_uid', 'product_id']) ->order(['id' => 'desc']) + ->group('purchase_uid,product_id') ->select() - ->each(function ($item) { - $item->total_nums = ProductSourceLinkInfo::where('product_id', $item->product_id)->where('oid', $item->id)->where('types', 1)->sum('nums'); - $item->warehouse_outbound_nums = ProductSourceLinkInfo::where('product_id', $item->product_id)->where('oid', $item->id)->where('types', 2)->sum('nums'); - }) ->toArray(); $linkInfos = ProductSourceLinkInfo::whereIn('oid', array_column($list, 'id'))->select()->toArray(); - $orderSnList = WarehouseOrder::field('id,code')->whereIn('id', array_unique(array_column($linkInfos, 'link_id')))->select()->toArray(); + $orderSnList = WarehouseProduct::field('id,code')->whereIn('id', array_unique(array_column($linkInfos, 'link_id')))->select()->toArray(); $orderSnList = reset_index($orderSnList, 'id'); foreach ($list as &$item) { $item['in_order_no'] = []; @@ -129,17 +126,17 @@ class ProductSourceLinkController extends BaseAdminController if (!empty($orderSnItem)) { $item['in_order_no'][] = $orderSnItem['code']; } - $item['in_num'] = bcmul($item['in_num'], $linkInfo['nums'], 2); + $item['in_num'] = bcadd($item['in_num'], $linkInfo['nums'], 2); } else { if (!empty($orderSnItem)) { $item['out_order_no'][] = $orderSnItem['code']; } - $item['out_num'] = bcmul($item['out_num'], $linkInfo['nums'], 2); + $item['out_num'] = bcadd($item['out_num'], $linkInfo['nums'], 2); } } } - $item['in_order_no'] = !empty($item['in_order_no']) ? implode(',', $item['in_order_no']) : ''; - $item['out_order_no'] =!empty($item['out_order_no']) ? implode(',', $item['out_order_no']) : ''; + $item['in_order_no'] = !empty($item['in_order_no']) ? implode(',', $item['in_order_no']) : ''; + $item['out_order_no'] =!empty($item['out_order_no']) ? implode(',', $item['out_order_no']) : ''; } $file_path = (new ProductSourceLinkXsl())->export($list); return $this->success('导出成功', ['url' => $file_path]);