From 6c5978eaff11d756832cc8a0f0a2a6a52c5e54ba Mon Sep 17 00:00:00 2001
From: Lemon <15040771@qq.com>
Date: Tue, 15 Sep 2020 17:34:04 +0800
Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../v3/Implementations/FeiePrintService.php | 71 +++++++++++++++----
1 file changed, 58 insertions(+), 13 deletions(-)
diff --git a/app/Service/v3/Implementations/FeiePrintService.php b/app/Service/v3/Implementations/FeiePrintService.php
index 08b9cf4..1c261fb 100644
--- a/app/Service/v3/Implementations/FeiePrintService.php
+++ b/app/Service/v3/Implementations/FeiePrintService.php
@@ -102,7 +102,6 @@ class FeiePrintService implements FeiePrintServiceInterface
protected function printFormat($arr, $A, $B, $C, $D)
{
- $length = $A + $B +$C + $D;
$orderInfo = '懒族生活
';
$orderInfo .= '数量 名称 单价 金额
';
$orderInfo .= '--------------------------------
';
@@ -113,23 +112,62 @@ class FeiePrintService implements FeiePrintServiceInterface
$orderInfo .= "(" . $shopnum . ")" .$order->store->name . '
';
foreach ($order['orderGoods'] as $goods){
$orderInfo .= str_pad($goods->number,$A,' ',STR_PAD_RIGHT);
- $nameLength = mb_strwidth($goods->name,'utf-8');
- $orderInfo .= str_pad($goods->name,$B+$nameLength,' ',STR_PAD_RIGHT);
- $orderInfo .= str_pad($goods->price,$C,' ',STR_PAD_LEFT);
- $orderInfo .= str_pad(bcmul($goods->number,$goods->price,2),$D,' ',STR_PAD_LEFT);
+ $nameLength = mb_strwidth($goods->name);
+ $nameArr = mb_str_split($goods->name);
+ $length = $A;
+ foreach ($nameArr as $name){
+ $len = mb_strwidth($name);
+ $length += $len;
+ if($length >= ($A + $B +$C + $D)){
+ $orderInfo .= '
';
+ $length = $A;
+ }
+ $orderInfo .= $name;
+ }
+ if($nameLength > ($B+$C+$D)){
+ $orderInfo .= '
';
+ $orderInfo .= str_pad($goods->price,$A+$B+$C,' ',STR_PAD_LEFT);
+ $orderInfo .= str_pad(bcmul($goods->number,$goods->price,2),$D,' ',STR_PAD_LEFT);
+ }else{
+ $orderInfo .= str_pad($goods->price,$C+$B+$A-$length,' ',STR_PAD_LEFT);
+ $orderInfo .= str_pad(bcmul($goods->number,$goods->price,2),$D,' ',STR_PAD_LEFT);
+ }
}
if(!empty($order->note)){
+ $orderInfo .='
';
+ $orderInfo .='
';
$note = '备注:'.$order->note;
-
- // $noteLength = mb_strwidth($note);
- // $noteTime = ceil($noteLength/32);
- // $noteArr = $this->mb_str_split($note,$length);
- // var_dump($noteArr,$noteTime);
- // for ($i = 0;$i <= count($noteArr);$i++){
- // $orderInfo .= str_pad($noteArr[$i],$length,' ',STR_PAD_RIGHT).'
';
- // }
+ $orderInfo .= $note.'
';
}
}
+ $orderInfo .= '--------------------------------
';
+ if ($arr->services_money > 0) {
+ $orderInfo .= $this->space('服务费:',$arr->services_money);
+ }
+ if($arr->delivery_money > 0){
+ $orderInfo .= $this->space('配送费:',$arr->delivery_money);
+ }
+ if($arr->coupon_money > 0){
+ $orderInfo .= $this->space('红包:',$arr->coupon_money);
+ }
+ $total = '合计:'.$arr->money;
+ $userName = $arr->name;
+ if(strlen($userName)>18){
+ $userName=substr($userName,0,18).'...';
+ }
+ $userLength = preg_replace('/[^\x{4e00}-\x{9fa5}]/u', '', $userName);
+ $totalLength = preg_replace('/[^\x{4e00}-\x{9fa5}]/u', '', $total);
+ var_dump($userLength,$totalLength);
+ $orderInfo .= str_pad($userName,$A+$B+$userLength,' ',STR_PAD_RIGHT);
+ $orderInfo .= str_pad($total,$C+$D+$totalLength,' ',STR_PAD_LEFT);
+ $orderInfo .= '
';
+ $orderInfo .= '送货地点:' . $arr->address . '
';
+ $tel = substr_replace( $arr->tel, '****', 3, 4);
+ $orderInfo .= '联系电话:' . $tel . '
';
+ $orderInfo .= '配送时间:' . $arr->delivery_time_note . '
';
+
+
+
// $name = $v5['name'];
// $name .= "(规格:". $v5['goods_unit'].")";
// $price = $v5['m_money'];
@@ -264,4 +302,11 @@ class FeiePrintService implements FeiePrintServiceInterface
return $orderInfo;
}
+ function space($name,$price,$len = 32)
+ {
+ $length = mb_strwidth($name);
+ $str = $name;
+ $str .= str_pad($price ,$len-$length,' ',STR_PAD_LEFT);
+ return $str;
+ }
}
\ No newline at end of file