php
<?php
/**
打印 - 映美云 https://open.jolimark.com/doc/
*/
namespace Home\Controller;
use Admin\Logic\OrderLogic;
class PrintController extends BaseController {
private $appid = "";
private $appkey = "";
//打印机编号
private $deviceIds = "";
//订单打印 - URL地址打印
public function order_print($order_id = 0)
{
$orderLogic = new OrderLogic();
$order = $orderLogic->getOrderInfo($order_id);
if (empty($order)) {
$this->error('订单不存在');
exit;
}
$url = "https://mcp.jolimark.com/mcp/v3/sys/PrintHtmlUrl";
$access_token = $this->get_access_token();
$params = [
'app_id' => $this->appid,
'access_token' => $access_token,
'device_ids' => $this->deviceIds,
'cus_orderid' => $order['order_sn'],
'bill_content' => "http://xxxxx.com/Home/Print/order_print_view/id/".$order_id,
'paper_width' => 98, //打印纸宽度
'paper_height' => 98, //打印纸高度
'paper_type' => 2, //标签纸
];
$res = httpRequest($url, "POST", $params);
$res = json_decode($res, true);
if ($res['return_code'] == 0) {
return true;
}
else {
return false;
}
}
//订单打印页
public function order_print_view()
{
$order_id = I("get.id",'0');
$orderLogic = new OrderLogic();
$order = $orderLogic->getOrderInfo($order_id);
if (empty($order)) {
$this->error('订单不存在');
exit;
}
$orderGoods = $orderLogic->getOrderGoods($order_id);
$this->assign('order', $order);
$this->assign('orderGoods',$orderGoods);
$this->display();
}
//获取access_token
private function get_access_token()
{
$access_token = S('jolimark_access_token');
if (!$access_token)
{
$url = "https://mcp.jolimark.com/mcp/v3/sys/GetAccessToken";
$time_stamp = time();
$param_url = "app_id={$this->appid}&sign_type=MD&time_stamp={$time_stamp}&key={$this->appkey}";
$sign = strtoupper( MD5($param_url) );
$url .= "?".$param_url."&sign=".$sign;
$res = httpRequest($url, "GET");
$res = json_decode($res, true);
if ($res['return_code'] == 0)
{
$access_token = $res['return_data']['access_token'];
S('jolimark_access_token', $access_token, $res['return_data']['expires_in']);
}
}
return $access_token;
}
}
URL订单页面排版代码
html
<html>
<head>
<title>配送小票</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<!--小票基本信息-->
<p><label style="font-size:48px;font-weight:bold;">订单打印</label></p>
<!--配送信息-->
<hr style="print-char:*;">
<p><label style="font-size:34px;font-weight:bold;">{$order.address2} - <if condition="$order.shipping_price eq '0.00'">到店自取<else />{$order.shipping_name}</if></label></p>
<p><label style="font-size:34px;font-weight:bold;">{$order.consignee}</label></p>
<p><label style="font-size:34px;font-weight:bold;">{$order.mobile}</label></p>
<hr style="print-char:*;">
<p><label>订单编号: </label><label>{$order.order_sn}</label></p>
<p><label>下单时间: </label><label>{$order.add_time|date='Y-m-d H:i',###}</label></p>
<p><label>支付方式: </label><label>{$order.pay_name}</label></p>
<p><label>客服电话: </label><label>13245566789</label></p>
<p><label style="font-weight:bold;">到店取件码: </label><label style="font-weight:bold;">{$order.pickup_code}</label></p>
<!--小票明细-->
<hr style="print-char:-;print-text:物品;">
<volist name="orderGoods" id="good">
<p>
<label style="width:71%;font-weight:bold;">{$good.goods_name}</label>
<label style="width:13%;font-weight:bold;text-align:center;">X{$good.goods_num}</label>
<label style="width:16%;font-weight:bold;text-align:right;">{$good[goods_total] - $good[zhekou]}</label>
</p>
</volist>
<p>
<!--费用明细-->
<hr style="print-char:-;print-text:其它费用;">
<p>
<label style="width:85%;font-weight:bold;">运费</label>
<label style="width: 15%;font-weight:bold;text-align:right;">{$order.shipping_price}</label>
</p>
<p>
<label style="width:85%;font-weight:bold;">新人立领</label>
<label style="width: 15%;font-weight:bold;text-align:right;">{$order.fuli_price}</label>
</p>
<p>
<label style="width:85%;font-weight:bold;">活动优惠</label>
<label style="width: 15%;font-weight:bold;text-align:right;">{$order.cut_fee}</label>
</p>
<p><label style="text-align:right;font-weight:bold;font-size:36px;">总计: {$order.order_amount}</label></p>
<!-- <br /> -->
<!-- <h3 style="text-align:center;font-size:48px;font-weight:bold;">=== #1 完 ===</h3> -->
<!-- <br /> -->
</body>
</html>