getPrintContent($order);
// 执行打印请求
return $PrinterDriver->printTicket($content);
}
/**
* 构建订单打印的内容
* @param \app\common\model\BaseModel $order
* @return string
*/
private function getPrintContent($order)
{
// 商城名称
$storeName = SettingModel::getItem('store', $order['wxapp_id'])['name'];
// 收货地址
/* @var \app\common\model\OrderAddress $address */
$address = $order['address'];
// 拼接模板内容
$content = "{$storeName}
";
$content .= '--------------------------------
';
$content .= "昵称:{$order['user']['nickName']} [{$order['user_id']}]
";
$content .= "订单号:{$order['order_no']}
";
$content .= '付款时间:' . date('Y-m-d H:i:s', $order['pay_time']) . '
';
// 收货人信息
if ($order['delivery_type']['value'] == DeliveryTypeEnum::EXPRESS) {
$content .= "--------------------------------
";
$content .= "收货人:{$address['name']}
";
$content .= "联系电话:{$address['phone']}
";
$content .= '收货地址:' . $address->getFullAddress() . '
';
}
// 自提信息
if ($order['delivery_type']['value'] == DeliveryTypeEnum::EXTRACT && !empty($order['extract'])) {
$content .= "--------------------------------
";
$content .= "联系人:{$order['extract']['linkman']}
";
$content .= "联系电话:{$order['extract']['phone']}
";
$content .= "自提门店:{$order['extract_shop']['shop_name']}
";
}
// 商品信息
$content .= '=========== 商品信息 ===========
';
foreach ($order['goods'] as $key => $goods) {
$content .= ($key + 1) . ".商品名称:{$goods['goods_name']}
";
!empty($goods['goods_attr']) && $content .= " 商品规格:{$goods['goods_attr']}
";
$content .= " 购买数量:{$goods['total_num']}
";
$content .= " 商品总价:{$goods['total_price']}元
";
$content .= '--------------------------------
';
}
// 买家备注
if (!empty($order['buyer_remark'])) {
$content .= '============ 买家备注 ============
';
$content .= "{$order['buyer_remark']}
";
$content .= '--------------------------------
';
}
// 订单金额
if ($order['coupon_money'] > 0) {
$content .= "优惠券:-{$order['coupon_money']}元
";
}
if ($order['points_num'] > 0) {
$content .= "积分抵扣:-{$order['points_money']}元
";
}
if ($order['update_price']['value'] != '0.00') {
$content .= "后台改价:{$order['update_price']['symbol']}{$order['update_price']['value']}元
";
}
// 运费
if ($order['delivery_type']['value'] == DeliveryTypeEnum::EXPRESS) {
$content .= "运费:{$order['express_price']}元
";
$content .= '------------------------------
';
}
// 实付款
$content .= "实付款:{$order['pay_price']}元
";
return $content;
}
}