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 1/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=87=BA=E5=BA=93?= =?UTF-8?q?=E5=8D=95=E5=92=8C=E9=A2=84=E7=BA=A6=E5=8D=95=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=8A=9F=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); +} From c370a96e6035e298ece4fbb2bc6bc9bad6b85efe Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 9 Oct 2024 15:01:05 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 StoreOrderController 中新增 export_tags 方法,用于导出订单标签 - 在 Beforehand 类中调整字体样式大小 --- .../store_order/StoreOrderController.php | 43 ++++++++++++++++--- app/common/service/xlsx/Beforehand.php | 2 +- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/admin/controller/store_order/StoreOrderController.php b/app/admin/controller/store_order/StoreOrderController.php index 450daca0d..a65152336 100644 --- a/app/admin/controller/store_order/StoreOrderController.php +++ b/app/admin/controller/store_order/StoreOrderController.php @@ -18,8 +18,10 @@ use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; +use app\common\model\system_store\SystemStore; use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_product\WarehouseProduct; +use app\common\service\xlsx\Beforehand; use app\common\service\xlsx\OrderDetail; use support\exception\BusinessException; use think\facade\Db; @@ -168,9 +170,9 @@ class StoreOrderController extends BaseAdminController $order['delivery_time'] = date('Y-m-d', $time); $data = StoreOrderCartInfo::where('oid', $id)->select(); foreach ($data as $key => &$value) { - if(in_array($order['store_id'],[17,18])){ - $find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->find(); - }else{ + if (in_array($order['store_id'], [17, 18])) { + $find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id', $order['store_id'])->find(); + } else { $find = StoreProduct::where('id', $value->product_id)->find(); } $value->store_name = $find['store_name'] ?? ''; @@ -198,12 +200,12 @@ class StoreOrderController extends BaseAdminController $warehouse_id = $this->request->post('warehouse_id'); $delivery_time = $this->request->post('delivery_time'); $mark = $this->request->post('mark'); - $find = WarehouseOrder::where('oid',$id)->find(); - if($find){ + $find = WarehouseOrder::where('oid', $id)->find(); + if ($find) { return $this->fail('该订单已创建出库单'); } - $product_arr=StoreOrderCartInfo::where('oid',$id)->field('oid,product_id id,price,total_price,cart_num stock')->select(); - if(!$product_arr){ + $product_arr = StoreOrderCartInfo::where('oid', $id)->field('oid,product_id id,price,total_price,cart_num stock')->select(); + if (!$product_arr) { return $this->fail('无商品'); } Db::startTrans(); @@ -252,4 +254,31 @@ class StoreOrderController extends BaseAdminController } return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1); } + + /** + * 导出标签 + */ + public function export_tags() + { + $id = $this->request->post('id'); + $order = StoreOrder::where('id', $id)->field('store_id,uid,real_name,user_address')->find(); + + $system_store = SystemStore::where('id', $order['store_id'])->value('introduction'); + $data = StoreOrderCartInfo::where('oid', $id)->field('oid,product_id,cart_num')->select() + ->each(function ($item) use ($system_store, $order) { + $find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->find(); + $unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['system_store'] = $system_store; + $item['subtitle'] = $item['oid'] . ' ' . convertStringToNumber($item['cart_num']) . '/' . $unit_name; + $item['store_name'] = $find['store_name']; + if ($order['uid']) { + $item['address'] = $find['real_name'] . ' ' . $find['user_address']; + } else { + $item['address'] = '无地址'; + } + }) + ->toArray(); + $file_path = (new Beforehand())->export($data, $system_store); + return $this->success('导出成功', ['url' => $file_path]); + } } diff --git a/app/common/service/xlsx/Beforehand.php b/app/common/service/xlsx/Beforehand.php index b520f386a..28f3f2b88 100644 --- a/app/common/service/xlsx/Beforehand.php +++ b/app/common/service/xlsx/Beforehand.php @@ -21,7 +21,7 @@ class Beforehand 'marginTop' => Converter::cmToTwip(0.2), 'marginBottom' => Converter::cmToTwip(0), )); - $fontStyle = ['name' => 'Arial', 'size' => 12, 'bold' => true]; + $fontStyle = ['name' => 'Arial', 'size' => 10, 'bold' => true]; $fontStyle1 = ['name' => 'Arial', 'size' => 8, 'bold' => true]; $fontStyle2 = ['name' => 'Arial', 'size' => 8, 'bold' => true]; $fontStyle3 = ['name' => 'Arial', 'size' => 8, 'bold' => true]; From 1f33cb3564fd541295b1708c521b29b9ba9a02b4 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 9 Oct 2024 15:02:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=8F=B7=E7=94=9F=E6=88=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在创建预订单时,新增了订单号(order_sn)的生成逻辑,使用了订单ID(order_id)作为其值。这确保了每个订单都有一个唯一的订单号,有助于订单的跟踪和管理。 --- app/admin/logic/beforehand_order/BeforehandOrderLogic.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 51a1532aa..0aba0a355 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -207,6 +207,7 @@ class BeforehandOrderLogic extends BaseLogic } $order = BeforehandOrder::create([ 'order_id' => getNewOrderId('YG'), + 'order_sn' => $order['order_id'], 'admin_id' => $params['admin_id'] ?? 0, 'uid' => $uid, 'total_num' => $total_num,