Browse Source

打印

master
Lemon 5 years ago
parent
commit
6c5978eaff
  1. 71
      app/Service/v3/Implementations/FeiePrintService.php

71
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 = '<CB>懒族生活</CB><BR>';
$orderInfo .= '数量 名称 单价 金额<BR>';
$orderInfo .= '--------------------------------<BR>';
@ -113,23 +112,62 @@ class FeiePrintService implements FeiePrintServiceInterface
$orderInfo .= "<C>(" . $shopnum . ")" .$order->store->name . '</C><BR>';
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 .= '<BR> ';
$length = $A;
}
$orderInfo .= $name;
}
if($nameLength > ($B+$C+$D)){
$orderInfo .= '<BR>';
$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 .='<BR>';
$orderInfo .='<BR>';
$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).'<BR>';
// }
$orderInfo .= $note.'<BR>';
}
}
$orderInfo .= '--------------------------------<BR>';
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 .= '<BR>';
$orderInfo .= '送货地点:' . $arr->address . '<BR>';
$tel = substr_replace( $arr->tel, '****', 3, 4);
$orderInfo .= '联系电话:' . $tel . '<BR>';
$orderInfo .= '配送时间:' . $arr->delivery_time_note . '<BR>';
// $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;
}
}
Loading…
Cancel
Save