<?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_tokenprivate 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> <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>