service = new PrintService(); } /** * 小票打印字体对齐样例,不支持金额播报 * 注意:对齐标签L C R CB 请勿嵌套使用,嵌套使用内层标签有效,外层失效; * 同一行请勿使用多个对齐标签,否则只有最后一个对齐标签有效 */ public function printFontAlign($sn,$order) { $system_store=$order['system_store']; $system_phone=$order['system_phone']; $verify_code=$order['verify_code']; $order_id=$order['order_id']; $create_time=$order['create_time']; $pay_price=$order['pay_price']; $total_price=$order['total_price']; $deduction_price=$order['deduction_price']; $pay_type_name=$order['pay_type_name']; $printContent = <<{$system_store}
============================== 核销码:{$verify_code} 单号:{$order_id} 下单时间:{$create_time} ============================== 单价 数量 小计 EOF; // 使用 for 循环生成商品列表 foreach ($order['product_arr'] as $k=>$v) { $printContent .= <<{$v['name']} {$v['price']} *{$v['quantity']} {$v['subtotal']} EOF; } // 继续生成剩余的 printContent $printContent .= << ============================== 合计:{$total_price}元 优惠:{$deduction_price}元 实付款:{$pay_price}元 支付方式:{$pay_type_name} 店铺电话:{$system_phone} ============================== 欢迎下次光临!
EOF; $request = new PrintRequest(); $request->generateSign(); //*必填*:打印机编号 $request->sn = $sn; //*必填*:打印内容,不能超过12K $request->content = $printContent; //打印份数,默认为1 $request->copies = 1; //声音播放模式,0 为取消订单模式,1 为静音模式,2 为来单播放模式,3为有用户申请退单了。默认为 2 来单播放模式 $request->voice = 2; //打印模式: //值为 0 或不指定则会检查打印机是否在线,如果不在线 则不生成打印订单,直接返回设备不在线状态码;如果在线则生成打印订单,并返回打印订单号。 //值为 1不检查打印机是否在线,直接生成打印订单,并返回打印订单号。如果打印机不在线,订单将缓存在打印队列中,打印机正常在线时会自动打印。 $request->mode = 0; $result = $this->service->xpYunPrint($request); return $result->content; } }