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] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=A2=E5=8D=95=E6=A0=87?= =?UTF-8?q?=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 450daca0..a6515233 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 b520f386..28f3f2b8 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];