From 194fbbb2ddf2fac49b6e66a43301995a87153b21 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 9 Oct 2024 14:47:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=87=BA=E5=BA=93=E5=8D=95?= =?UTF-8?q?=E5=92=8C=E9=A2=84=E7=BA=A6=E5=8D=95=E5=AF=BC=E5=87=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改了出库单和预约单导出时的数据处理逻辑,增加了更多订单相关信息 - 优化了导出文档的格式,提高了可读性和信息完整性 - 新增字符串转数字的工具函数 `convertStringToNumber` --- .../BeforehandOrderController.php | 27 ++++++++++----- .../WarehouseOrderController.php | 18 +++++++--- app/common/service/xlsx/Beforehand.php | 12 +++++-- app/functions.php | 33 ++++++++++++++++--- 4 files changed, 70 insertions(+), 20 deletions(-) diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index 099160da1..c3c94a5f1 100644 --- a/app/admin/controller/beforehand_order/BeforehandOrderController.php +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -9,6 +9,7 @@ use app\admin\lists\beforehand_order\BeforehandOrderTwoLists; use app\admin\lists\beforehand_order\BeforehandOrderThreeLists; use app\admin\logic\beforehand_order\BeforehandOrderLogic; use app\common\model\beforehand_order\BeforehandOrder; +use app\common\model\store_order\StoreOrder; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\system_store\SystemStore; @@ -133,19 +134,29 @@ class BeforehandOrderController extends BaseAdminController public function export() { $params = $this->request->post(); - $outbound_id = BeforehandOrder::where('id', $params['id'])->value('outbound_id'); - if(!$outbound_id){ + $order = BeforehandOrder::where('id', $params['id'])->field('outbound_id,order_sn')->find(); + if(!$order){ return $this->fail('未生成出库单'); } - $warehouseOrder = WarehouseOrder::where('id', $outbound_id)->field('store_id,delivery_time')->find(); + $warehouseOrder = WarehouseOrder::where('id', $order['outbound_id'])->field('store_id,delivery_time')->find(); $system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('name'); - $data = WarehouseProduct::where('oid', $outbound_id)->field('product_id,nums')->select() - ->each(function ($item) use ($system_store,$warehouseOrder) { - $item['system_store'] = $system_store; + $data = WarehouseProduct::where('oid', $order['outbound_id'])->field('product_id,nums')->select() + ->each(function ($item) use ($system_store,$warehouseOrder,$order) { $find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->find(); - $item['store_name'] = $find['store_name']; $unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); - $item['unit_name'] = $item['nums'].'/'.$unit_name.' '.date('m-d',$warehouseOrder['delivery_time']); + $item['system_store'] = $system_store; + $item['subtitle'] = $item['oid'].' '.convertStringToNumber($item['nums']).'/'.$unit_name; + $item['store_name'] = $find['store_name']; + if($warehouseOrder['oid']){ + $find=StoreOrder::where('order_id',$order['order_sn'])->field('real_name,user_address')->find(); + if($find){ + $item['address'] = $find['real_name'].' '.$find['user_address']; + }else{ + $item['address'] = '无地址'; + } + }else{ + $item['address'] = '无地址'; + } }) ->toArray(); $file_path=(new Beforehand())->export($data, $system_store); diff --git a/app/admin/controller/warehouse_order/WarehouseOrderController.php b/app/admin/controller/warehouse_order/WarehouseOrderController.php index 435d9df6e..a614eb23a 100644 --- a/app/admin/controller/warehouse_order/WarehouseOrderController.php +++ b/app/admin/controller/warehouse_order/WarehouseOrderController.php @@ -283,15 +283,25 @@ class WarehouseOrderController extends BaseAdminController public function export_tags() { $id = $this->request->post('id'); - $warehouseOrder = WarehouseOrder::where('id', $id)->field('store_id,delivery_time')->find(); + $warehouseOrder = WarehouseOrder::where('id', $id)->field('oid,store_id,delivery_time')->find(); $system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('introduction'); $data = WarehouseProduct::where('oid', $id)->where('financial_pm',0)->field('oid,product_id,nums')->select() ->each(function ($item) use ($system_store,$warehouseOrder) { - $item['system_store'] = $system_store.' '.$item['oid']; $find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->find(); - $item['store_name'] = $find['store_name']; $unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); - $item['unit_name'] = $item['nums'].'/'.$unit_name.' '.date('m-d',$warehouseOrder['delivery_time']); + $item['system_store'] = $system_store; + $item['subtitle'] = $item['oid'].' '.convertStringToNumber($item['nums']).'/'.$unit_name; + $item['store_name'] = $find['store_name']; + if($warehouseOrder['oid']){ + $find=StoreOrder::where('id',$warehouseOrder['oid'])->field('real_name,user_address')->find(); + if($find){ + $item['address'] = $find['real_name'].' '.$find['user_address']; + }else{ + $item['address'] = '无地址'; + } + }else{ + $item['address'] = '无地址'; + } }) ->toArray(); $file_path=(new Beforehand())->export($data, $system_store); diff --git a/app/common/service/xlsx/Beforehand.php b/app/common/service/xlsx/Beforehand.php index 327a9109b..b520f386a 100644 --- a/app/common/service/xlsx/Beforehand.php +++ b/app/common/service/xlsx/Beforehand.php @@ -22,11 +22,17 @@ class Beforehand 'marginBottom' => Converter::cmToTwip(0), )); $fontStyle = ['name' => 'Arial', 'size' => 12, 'bold' => true]; + $fontStyle1 = ['name' => 'Arial', 'size' => 8, 'bold' => true]; + $fontStyle2 = ['name' => 'Arial', 'size' => 8, 'bold' => true]; + $fontStyle3 = ['name' => 'Arial', 'size' => 8, 'bold' => true]; foreach ($data as $k => $v) { - $section->addText(mb_substr($v['system_store'], 0, 8, 'UTF-8'), $fontStyle); - $section->addText(mb_substr( $v['store_name'], 0, 8, 'UTF-8'), $fontStyle); - $section->addText(mb_substr($v['unit_name'], 0, 8, 'UTF-8'), $fontStyle); + $textRun =$section->addTextRun(); + + $textRun->addText($v['system_store'], $fontStyle); + $textRun->addText(' '.mb_substr($v['subtitle'], 0, 8, 'UTF-8'), $fontStyle1); + $section->addText(mb_substr( $v['store_name'], 0, 16, 'UTF-8'), $fontStyle2); + $section->addText($v['address'], $fontStyle3); } $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); diff --git a/app/functions.php b/app/functions.php index d3275a116..2f3150285 100644 --- a/app/functions.php +++ b/app/functions.php @@ -500,6 +500,29 @@ if (!function_exists('convertNumber')) { } } } +if (!function_exists('convertStringToNumber')) { + + /** + * 根据字符串是否包含小数点以及小数点后的值,决定将其转换为浮点数或整数 + * + * @param string $str 需要转换的字符串 + * @return mixed 转换后的浮点数或整数 + */ + function convertStringToNumber($str) + { + $count = explode('.', $str); + if (count($count) > 1) { + // 包含小数点,转换为浮点数 + if ($count[1] > 0) { + return floatval($str); + } + return intval($str); + } else { + // 不包含小数点,转换为整数 + return intval($str); + } + } +} /** * 日志记录 @@ -510,16 +533,16 @@ if (!function_exists('convertNumber')) { function onBeforeUpdate($data, $type) { $log = Log::channel($type); - $log->info('更新前:',$data); + $log->info('更新前:', $data); } function onAfterUpdate($data, $type) { $log = Log::channel($type); - $log->info('更新后:' ,$data); + $log->info('更新后:', $data); } -function channelLog($data, $type,$title='更新前') +function channelLog($data, $type, $title = '更新前') { $log = Log::channel($type); - $log->info($title ,$data); -} \ No newline at end of file + $log->info($title, $data); +}