From b51e352305462c8efb1608716f40962f5017dd70 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 18 Nov 2024 14:08:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E4=BC=98=E5=8C=96=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 优化预先订单购物车信息列表的搜索功能,增加按店铺名称搜索 - 优化仓库订单列表的搜索条件,增加按订单ID搜索 - 修复仓库订单逻辑中获取订单类型的问题 - 在 API 控制器中添加 XpsdkPrintApi 服务的引用 --- .../BeforehandOrderCartInfoLists.php | 7 +- .../warehouse_order/WarehouseOrderLists.php | 2 +- .../warehouse_order/WarehouseOrderLogic.php | 3 + app/api/controller/IndexController.php | 1 + app/common/service/xpyun/XpsdkOtherApi.php | 24 +++ app/common/service/xpyun/XpsdkPrintApi.php | 89 ++++++++ extend/Xpyun/Autoloader.php | 28 +++ extend/Xpyun/model/AddPrinterRequest.php | 9 + extend/Xpyun/model/AddPrinterRequestItem.php | 17 ++ extend/Xpyun/model/DelPrinterRequest.php | 13 ++ extend/Xpyun/model/PrintRequest.php | 45 ++++ extend/Xpyun/model/PrinterRequest.php | 13 ++ extend/Xpyun/model/QueryOrderStateRequest.php | 13 ++ .../Xpyun/model/QueryOrderStatisRequest.php | 18 ++ extend/Xpyun/model/RestRequest.php | 44 ++++ extend/Xpyun/model/SetVoiceTypeRequest.php | 18 ++ extend/Xpyun/model/UpdPrinterRequest.php | 17 ++ extend/Xpyun/model/VoiceRequest.php | 27 +++ extend/Xpyun/model/XPYunResp.php | 11 + extend/Xpyun/model/XPYunRespContent.php | 12 ++ extend/Xpyun/service/HttpClient.php | 41 ++++ extend/Xpyun/service/PrintService.php | 197 ++++++++++++++++++ extend/Xpyun/util/Encoding.php | 18 ++ extend/Xpyun/util/NoteFormatter.php | 129 ++++++++++++ extend/Xpyun/util/Xputil.php | 29 +++ 25 files changed, 823 insertions(+), 2 deletions(-) create mode 100644 app/common/service/xpyun/XpsdkOtherApi.php create mode 100644 app/common/service/xpyun/XpsdkPrintApi.php create mode 100644 extend/Xpyun/Autoloader.php create mode 100644 extend/Xpyun/model/AddPrinterRequest.php create mode 100644 extend/Xpyun/model/AddPrinterRequestItem.php create mode 100644 extend/Xpyun/model/DelPrinterRequest.php create mode 100644 extend/Xpyun/model/PrintRequest.php create mode 100644 extend/Xpyun/model/PrinterRequest.php create mode 100644 extend/Xpyun/model/QueryOrderStateRequest.php create mode 100644 extend/Xpyun/model/QueryOrderStatisRequest.php create mode 100644 extend/Xpyun/model/RestRequest.php create mode 100644 extend/Xpyun/model/SetVoiceTypeRequest.php create mode 100644 extend/Xpyun/model/UpdPrinterRequest.php create mode 100644 extend/Xpyun/model/VoiceRequest.php create mode 100644 extend/Xpyun/model/XPYunResp.php create mode 100644 extend/Xpyun/model/XPYunRespContent.php create mode 100644 extend/Xpyun/service/HttpClient.php create mode 100644 extend/Xpyun/service/PrintService.php create mode 100644 extend/Xpyun/util/Encoding.php create mode 100644 extend/Xpyun/util/NoteFormatter.php create mode 100644 extend/Xpyun/util/Xputil.php diff --git a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php index efeb9c9b..7358cadd 100644 --- a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php +++ b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php @@ -70,7 +70,12 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe $this->searchWhere[] = ['product_id', 'in', $ids]; } } - + if ($this->request->get('store_name')) { + $ids = StoreProduct::where('store_name', 'like', '%'.$this->request->get('store_name').'%')->column('id'); + if ($ids) { + $this->searchWhere[] = ['product_id', 'in', $ids]; + } + } $list = BeforehandOrderCartInfo::where($this->searchWhere) ->field(['id', 'bhoid', 'package', 'store_info', 'marques', 'gross_weight', 'net_weight', 'accept_num', 'after_sales', 'loss', 'uid', 'pay_price', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'purchase', 'price', 'total_price', 'cart_num', 'mark','create_time']) ->limit($this->limitOffset, $this->limitLength) diff --git a/app/admin/lists/warehouse_order/WarehouseOrderLists.php b/app/admin/lists/warehouse_order/WarehouseOrderLists.php index a22251ba..9e57f516 100644 --- a/app/admin/lists/warehouse_order/WarehouseOrderLists.php +++ b/app/admin/lists/warehouse_order/WarehouseOrderLists.php @@ -30,7 +30,7 @@ class WarehouseOrderLists extends BaseAdminDataLists implements ListsSearchInter public function setSearch(): array { return [ - '=' => ['financial_pm', 'supplier_id', 'warehouse_id', 'store_id'], + '=' => ['financial_pm', 'supplier_id', 'warehouse_id', 'store_id','id'], '%like'=>['code'], 'between_time' => 'create_time' ]; diff --git a/app/admin/logic/warehouse_order/WarehouseOrderLogic.php b/app/admin/logic/warehouse_order/WarehouseOrderLogic.php index 8c9d262c..91144e11 100644 --- a/app/admin/logic/warehouse_order/WarehouseOrderLogic.php +++ b/app/admin/logic/warehouse_order/WarehouseOrderLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\warehouse_order; use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\common\model\warehouse_order\WarehouseOrder; use app\common\logic\BaseLogic; +use app\common\model\beforehand_order\BeforehandOrder; use app\common\model\warehouse_product\WarehouseProduct; use support\exception\BusinessException; use think\facade\Db; @@ -90,9 +91,11 @@ class WarehouseOrderLogic extends BaseLogic if (!$find) { throw new BusinessException('订单不存在'); } + $order_type=BeforehandOrder::where('warehousing_id|outbound_id',$find['id'])->value('order_type')??0; Db::startTrans(); try { foreach ($params['product_arr'] as $k => $v) { + $data['order_type'] = $order_type; $data['admin_id'] = $params['admin_id']; $data['store_id'] = $find['store_id']; $data['oid'] = $find['id']; diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 4194e98d..ce571667 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -26,6 +26,7 @@ use app\common\service\Curl; use app\common\service\pay\PayService; use app\common\service\PushService; use app\common\service\wechat\WechatTemplate; +use app\common\service\xpyun\XpsdkPrintApi; use app\statistics\logic\OrderLogic; use Exception; use Overtrue\EasySms\EasySms; diff --git a/app/common/service/xpyun/XpsdkOtherApi.php b/app/common/service/xpyun/XpsdkOtherApi.php new file mode 100644 index 00000000..836f628e --- /dev/null +++ b/app/common/service/xpyun/XpsdkOtherApi.php @@ -0,0 +1,24 @@ +<?php +namespace app\common\service\xpyun; + +use Xpyun\service\PrintService; + +/** + * Class XpsdkOtherApi + * 打印机管理 + */ +class XpsdkOtherApi +{ + /** + * 打印服务对象实例化 + */ + private $service; + + public function __construct() + { + + $this->service = new PrintService(); + } + + +} \ No newline at end of file diff --git a/app/common/service/xpyun/XpsdkPrintApi.php b/app/common/service/xpyun/XpsdkPrintApi.php new file mode 100644 index 00000000..e363fec4 --- /dev/null +++ b/app/common/service/xpyun/XpsdkPrintApi.php @@ -0,0 +1,89 @@ +<?php +namespace app\common\service\xpyun; + +use Xpyun\model\PrintRequest; +use Xpyun\service\PrintService; + +/** + * Class XpsdkPrintApi + * 打印示例 + */ +class XpsdkPrintApi +{ + /** + * 打印服务对象实例化 + */ + private $service; + + public function __construct() + { + $this->service = new PrintService(); + } + + /** + * 小票打印字体对齐样例,不支持金额播报 + * 注意:对齐标签L C R CB 请勿嵌套使用,嵌套使用内层标签有效,外层失效; + * 同一行请勿使用多个对齐标签,否则只有最后一个对齐标签有效 + */ + public function printFontAlign($sn) + { + $printContent = <<<EOF +不加标签:默认字体大小<BR> +<BR> +L标签:<L>左对齐<BR></L> +<BR> +R标签:<R>右对齐<BR></R> +<BR> +C标签:<C>居中对齐<BR></C> +<BR> +N标签:<N>字体正常大小<BR></N> +<BR> +HB标签:<HB>字体变高一倍<BR></HB> +<BR> +WB标签:<WB>字体变宽一倍<BR></WB> +<BR> +B标签:<B>字体放大一倍<BR></B> +<BR> +HB2标签:<HB2>字体变高二倍<BR></HB2> +<BR> +WB2标签:<WB2>字体变宽二倍<BR></WB2> +<BR> +B2标签:<B2>字体放大二倍<BR></B2> +<BR> +BOLD标签:<BOLD>字体加粗<BR></BOLD> +EOF; + + $printContent = $printContent . '<BR>'; + // 嵌套使用对齐和字体 + $printContent = $printContent . '<C>嵌套使用:<BOLD>居中加粗</BOLD><BR></C>'; + + // 打印条形码和二维码 + $printContent = $printContent . '<BR>'; + $printContent = $printContent . '<C><BARCODE>9884822189</BARCODE></C>'; + $printContent = $printContent . '<C><QR>https://www.xpyun.net</QR></C>'; + + + $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 = 1; + + $result = $this->service->xpYunPrint($request); + return $result->content; + } +} diff --git a/extend/Xpyun/Autoloader.php b/extend/Xpyun/Autoloader.php new file mode 100644 index 00000000..47d5042b --- /dev/null +++ b/extend/Xpyun/Autoloader.php @@ -0,0 +1,28 @@ +<?php + +namespace Xpyun; +class Autoloader +{ + public static function loadClassByNamespace($name) + { + $class_file = ''; + $class_path = str_replace('\\', DIRECTORY_SEPARATOR, $name); + if (strpos($name, 'Xpyun\\') === 0) { + $class_file = __DIR__ . substr($class_path, strlen('Xpyun')) . '.php'; + } else if (empty($class_file) || !is_file($class_file)) { + $class_file = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $class_path . ".php"; + } + if (is_file($class_file)) { + require_once($class_file); + if (class_exists($name, false)) { + return true; + } + } + return false; + + } + +} + +spl_autoload_register('\Xpyun\Autoloader::loadClassByNamespace'); +?> \ No newline at end of file diff --git a/extend/Xpyun/model/AddPrinterRequest.php b/extend/Xpyun/model/AddPrinterRequest.php new file mode 100644 index 00000000..acf6f2fa --- /dev/null +++ b/extend/Xpyun/model/AddPrinterRequest.php @@ -0,0 +1,9 @@ +<?php + +namespace Xpyun\model; +class AddPrinterRequest extends RestRequest +{ + var $items; +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/model/AddPrinterRequestItem.php b/extend/Xpyun/model/AddPrinterRequestItem.php new file mode 100644 index 00000000..dd8e7b04 --- /dev/null +++ b/extend/Xpyun/model/AddPrinterRequestItem.php @@ -0,0 +1,17 @@ +<?php + +namespace Xpyun\model; +class AddPrinterRequestItem +{ + + /** + * 打印机编号 + */ + var $sn; + /** + * 打印机名称 + */ + var $name; +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/model/DelPrinterRequest.php b/extend/Xpyun/model/DelPrinterRequest.php new file mode 100644 index 00000000..bfc4ea36 --- /dev/null +++ b/extend/Xpyun/model/DelPrinterRequest.php @@ -0,0 +1,13 @@ +<?php + +namespace Xpyun\model; +class DelPrinterRequest extends RestRequest +{ + /** + * 打印机编号集合 + */ + var $snlist; + +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/model/PrintRequest.php b/extend/Xpyun/model/PrintRequest.php new file mode 100644 index 00000000..b264df27 --- /dev/null +++ b/extend/Xpyun/model/PrintRequest.php @@ -0,0 +1,45 @@ +<?php + +namespace Xpyun\model; +class PrintRequest extends RestRequest +{ + + /** + * 打印机编号 + */ + var $sn; + + /** + * 打印内容,不能超过5000字节 + */ + var $content; + + /** + * 打印份数,默认为1 + */ + var $copies = 1; + + /** + * 打印模式,默认为0 + */ + var $mode = 0; + + /** + * 支付方式41~55:支付宝 微信 ... + */ + var $payType; + /** + * 支付与否59~61:退款 到账 消费 + */ + var $payMode; + /** + * 支付金额 + */ + var $money; + /** + * 声音播放模式,0 为取消订单模式,1 为静音模式,2 为来单播放模式,默认为 2 来单播放模式 + */ + var $voice = 2; +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/model/PrinterRequest.php b/extend/Xpyun/model/PrinterRequest.php new file mode 100644 index 00000000..5c30db38 --- /dev/null +++ b/extend/Xpyun/model/PrinterRequest.php @@ -0,0 +1,13 @@ +<?php + +namespace Xpyun\model; +class PrinterRequest extends RestRequest +{ + + /** + * 打印机编号 + */ + var $sn; +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/model/QueryOrderStateRequest.php b/extend/Xpyun/model/QueryOrderStateRequest.php new file mode 100644 index 00000000..15326113 --- /dev/null +++ b/extend/Xpyun/model/QueryOrderStateRequest.php @@ -0,0 +1,13 @@ +<?php + +namespace Xpyun\model; +class QueryOrderStateRequest extends RestRequest +{ + + /** + * 订单编号 + */ + var $orderId; +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/model/QueryOrderStatisRequest.php b/extend/Xpyun/model/QueryOrderStatisRequest.php new file mode 100644 index 00000000..28aa22e5 --- /dev/null +++ b/extend/Xpyun/model/QueryOrderStatisRequest.php @@ -0,0 +1,18 @@ +<?php + +namespace Xpyun\model; +class QueryOrderStatisRequest extends RestRequest +{ + + /** + * 打印机编号 + */ + var $sn; + /** + * 查询日期,格式YY-MM-DD,如:2016-09-20 + */ + var $date; + +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/model/RestRequest.php b/extend/Xpyun/model/RestRequest.php new file mode 100644 index 00000000..3f4abff6 --- /dev/null +++ b/extend/Xpyun/model/RestRequest.php @@ -0,0 +1,44 @@ +<?php + +namespace Xpyun\model; + +use Xpyun\util\Xputil; + +class RestRequest +{ + /** + * 开发者ID(芯烨云后台登录账号) + */ + var $user; + /** + * 芯烨云后台开发者密钥 + */ + var $userKey; + /** + * 当前UNIX时间戳,10位,精确到秒 + */ + var $timestamp; + /** + * 对参数 user + UserKEY + timestamp 拼接后(+号表示连接符)进行SHA1加密得到签名,值为40位小写字符串,其中 UserKEY 为用户开发者密钥 + */ + var $sign; + /** + * debug=1返回非json格式的数据。仅测试时候使用 + */ + var $debug; + + function __construct() + { + $this->user = 'lihaink789@126.com'; + $this->userKey = '2ffcdeb6fa494e9e84902fd15d3ac9af'; + $this->debug = "0"; + $this->timestamp = Xputil::getMillisecond(); + } + + public function generateSign() + { + $this->sign = Xputil::sign($this->user . $this->userKey . $this->timestamp); + } +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/model/SetVoiceTypeRequest.php b/extend/Xpyun/model/SetVoiceTypeRequest.php new file mode 100644 index 00000000..5f71953e --- /dev/null +++ b/extend/Xpyun/model/SetVoiceTypeRequest.php @@ -0,0 +1,18 @@ +<?php + +namespace Xpyun\model; +class SetVoiceTypeRequest extends RestRequest +{ + + /** + * 打印机编号 + */ + var $sn; + + /** + * 声音类型: 0真人语音(大) 1真人语音(中) 2真人语音(小) 3 嘀嘀声 4 静音 + */ + var $voiceType; +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/model/UpdPrinterRequest.php b/extend/Xpyun/model/UpdPrinterRequest.php new file mode 100644 index 00000000..228e5ba9 --- /dev/null +++ b/extend/Xpyun/model/UpdPrinterRequest.php @@ -0,0 +1,17 @@ +<?php + +namespace Xpyun\model; +class UpdPrinterRequest extends RestRequest +{ + + /** + * 打印机编号 + */ + var $sn; + /** + * 打印机名称 + */ + var $name; +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/model/VoiceRequest.php b/extend/Xpyun/model/VoiceRequest.php new file mode 100644 index 00000000..a28c7de6 --- /dev/null +++ b/extend/Xpyun/model/VoiceRequest.php @@ -0,0 +1,27 @@ +<?php + +namespace Xpyun\model; +class VoiceRequest extends RestRequest +{ + + /** + * 打印机编号 + */ + var $sn; + + /** + * 支付方式41~55:支付宝 微信 ... + */ + var $payType; + /** + * 支付与否59~61:退款 到账 消费 + */ + var $payMode; + /** + * 支付金额 + */ + var $money; + +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/model/XPYunResp.php b/extend/Xpyun/model/XPYunResp.php new file mode 100644 index 00000000..fc3b8938 --- /dev/null +++ b/extend/Xpyun/model/XPYunResp.php @@ -0,0 +1,11 @@ +<?php + +namespace Xpyun\model; +class XPYunResp +{ + var $httpStatusCode; + + var $content; +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/model/XPYunRespContent.php b/extend/Xpyun/model/XPYunRespContent.php new file mode 100644 index 00000000..01aabbed --- /dev/null +++ b/extend/Xpyun/model/XPYunRespContent.php @@ -0,0 +1,12 @@ +<?php + +namespace Xpyun\model; +class XPYunRespContent +{ + var $code; + var $msg; + var $data; + var $serverExecutedTime; +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/service/HttpClient.php b/extend/Xpyun/service/HttpClient.php new file mode 100644 index 00000000..7dbdd403 --- /dev/null +++ b/extend/Xpyun/service/HttpClient.php @@ -0,0 +1,41 @@ +<?php +/** + * 发送http的json请求 + * + * @param $url 请求url + * @param $jsonStr 发送的json字符串 + * @return array + */ +namespace Xpyun\service; + +use Exception; + +class HttpClient +{ + public function http_post_json($url, $jsonStr) + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, 1);// 发送一个常规的Post请求 + curl_setopt($ch, CURLOPT_URL, $url);// 要访问的地址 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检测 + curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循 + curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json;charset=UTF-8', + 'Content-Length: ' . strlen($jsonStr) + ) + ); + + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if (curl_errno($ch)) { + throw new Exception(curl_error($ch)); + } + curl_close($ch); + + return array($httpCode, $response); + } +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/service/PrintService.php b/extend/Xpyun/service/PrintService.php new file mode 100644 index 00000000..3ecc1334 --- /dev/null +++ b/extend/Xpyun/service/PrintService.php @@ -0,0 +1,197 @@ +<?php + +namespace Xpyun\service; + +use Xpyun\model\XPYunResp; + +class PrintService +{ + private const BASE_URL = 'https://open.xpyun.net/api/openapi'; + + private function xpyunPostJson($url, $request) + { + $jsonRequest = json_encode($request); +// var_dump($jsonRequest); + $client = new HttpClient(); + + list($returnCode, $returnContent) = $client->http_post_json($url, $jsonRequest); + + $result = new XPYunResp(); + $result->httpStatusCode = $returnCode; + $result->content = json_decode($returnContent); + + return $result; + } + + /** + * 1.批量添加打印机 + * @param restRequest + * @return + */ + public function xpYunAddPrinters($restRequest) + { + $url = self::BASE_URL . "/xprinter/addPrinters"; + return $this->xpyunPostJson($url, $restRequest); + } + + /** + * 2.设置打印机语音类型 + * @param restRequest + * @return + */ + public function xpYunSetVoiceType($restRequest) + { + $url = self::BASE_URL . "/xprinter/setVoiceType"; + return $this->xpyunPostJson($url, $restRequest); + } + + /** + * 3.打印小票订单 + * @param restRequest - 打印订单信息 + * @return + */ + public function xpYunPrint($restRequest) + { + $url = self::BASE_URL . "/xprinter/print"; + + return $this->xpyunPostJson($url, $restRequest); + } + + /** + * 4.打印标签订单 + * @param restRequest - 打印订单信息 + * @return + */ + public function xpYunPrintLabel($restRequest) + { + $url = self::BASE_URL . "/xprinter/printLabel"; + + return $this->xpyunPostJson($url, $restRequest); + } + + /** + * 5.批量删除打印机 + * @param restRequest + * @return + */ + public function xpYunDelPrinters($restRequest) + { + $url = self::BASE_URL . "/xprinter/delPrinters"; + + return $this->xpyunPostJson($url, $restRequest); + } + + + /** + * 6.修改打印机信息 + * @param restRequest + * @return + */ + public function xpYunUpdatePrinter($restRequest) + { + $url = self::BASE_URL . "/xprinter/updPrinter"; + return $this->xpyunPostJson($url, $restRequest); + } + + /** + * 7.清空待打印队列 + * @param restRequest + * @return + */ + public function xpYunDelPrinterQueue($restRequest) + { + $url = self::BASE_URL . "/xprinter/delPrinterQueue"; + return $this->xpyunPostJson($url, $restRequest); + } + + /** + * 8.查询订单是否打印成功 + * @param restRequest + * @return + */ + public function xpYunQueryOrderState($restRequest) + { + $url = self::BASE_URL . "/xprinter/queryOrderState"; + + return $this->xpyunPostJson($url, $restRequest); + } + + /** + * 9.查询打印机某天的订单统计数 + * @param restRequest + * @return + */ + public function xpYunQueryOrderStatis($restRequest) + { + $url = self::BASE_URL . "/xprinter/queryOrderStatis"; + return $this->xpyunPostJson($url, $restRequest); + } + + /** + * 10.查询打印机状态 + * + * 0、离线 1、在线正常 2、在线不正常 + * 备注:异常一般是无纸,离线的判断是打印机与服务器失去联系超过30秒 + * @param restRequest + * @return + */ + public function xpYunQueryPrinterStatus($restRequest) + { + $url = self::BASE_URL . "/xprinter/queryPrinterStatus"; + + return $this->xpyunPostJson($url, $restRequest); + } + + /** + * 10.批量查询打印机状态 + * + * 0、离线 1、在线正常 2、在线不正常 + * 备注:异常一般是无纸,离线的判断是打印机与服务器失去联系超过30秒 + * @param restRequest + * @return + */ + public function xpYunQueryPrintersStatus($restRequest) + { + $url = self::BASE_URL . "/xprinter/queryPrintersStatus"; + + return $this->xpyunPostJson($url, $restRequest); + } + + /** + * 11.云喇叭播放语音 + * @param restRequest - 播放语音信息 + * @return + */ + public function xpYunPlayVoice($restRequest) + { + $url = self::BASE_URL . "/xprinter/playVoice"; + + return $this->xpyunPostJson($url, $restRequest); + } + + /** + * 12.POS指令 + * @param restRequest + * @return + */ + public function xpYunPos($restRequest) + { + $url = self::BASE_URL . "/xprinter/pos"; + + return $this->xpyunPostJson($url, $restRequest); + } + + /** + * 13.钱箱控制 + * @param restRequest + * @return + */ + public function xpYunControlBox($restRequest) + { + $url = self::BASE_URL . "/xprinter/controlBox"; + + return $this->xpyunPostJson($url, $restRequest); + } +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/util/Encoding.php b/extend/Xpyun/util/Encoding.php new file mode 100644 index 00000000..d20e5d53 --- /dev/null +++ b/extend/Xpyun/util/Encoding.php @@ -0,0 +1,18 @@ +<?php + +namespace Xpyun\util; + +class Encoding +{ + public static function CalcGbkLenForPrint($data) + { + return (strlen($data) + mb_strlen($data, "UTF8")) / 2; + } + + public static function CalcAsciiLenForPrint($data) + { + return strlen($data); + } +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/util/NoteFormatter.php b/extend/Xpyun/util/NoteFormatter.php new file mode 100644 index 00000000..91dd3156 --- /dev/null +++ b/extend/Xpyun/util/NoteFormatter.php @@ -0,0 +1,129 @@ +<?php + +namespace Xpyun\util; + +class NoteFormatter +{ + /** + * 58mm 系列打印机模板 + */ + public const ROW_MAX_CHAR_LEN = 32; + public const MAX_HEAD_NAME_CHAR_LEN58 = 116; + private const MAX_NAME_CHAR_LEN = 20; + private const LAST_ROW_MAX_NAME_CHAR_LEN = 16; + private const MAX_QUANTITY_CHAR_LEN = 6; + private const MAX_PRICE_CHAR_LEN = 6; + + /** + * 80mm 系列打印机模板 + */ + public const ROW_MAX_CHAR_LEN80 = 48; + public const MAX_HEAD_NAME_CHAR_LEN80 = 32; + private const MAX_NAME_CHAR_LEN80 = 36; + // 每行打印的字符数,汉字,字母,数字均为1 + private const LAST_ROW_MAX_NAME_CHAR_LEN80 = 17; + private const MAX_QUANTITY_CHAR_LEN80 = 6; + private const MAX_PRICE_CHAR_LEN80 = 6; + + public static function formatPrintOrderItem80($foodName, $quantity, $price) + { + $foodNameLen = Encoding::CalcGbkLenForPrint($foodName); + $mod = $foodNameLen % self::ROW_MAX_CHAR_LEN80; + $result = ""; + if ($foodNameLen <= self::LAST_ROW_MAX_NAME_CHAR_LEN80 * 2) { + $result = $foodName; + $result = $result . str_repeat(" ", self::MAX_NAME_CHAR_LEN80 - $mod); + $quantityStr = '' . $quantity; + $quantityLen = Encoding::CalcAsciiLenForPrint($quantityStr); + + $priceStr = '' . round($price, 2); + $priceLen = Encoding::CalcAsciiLenForPrint($priceStr); + $result = $result . $quantityStr . str_repeat(" ", self::MAX_QUANTITY_CHAR_LEN80 - $quantityLen); + $result = $result . $priceStr . str_repeat(" ", self::MAX_PRICE_CHAR_LEN80 - $priceLen); + } else { + $result = $result . self::getFoodNameSplit80($foodName, $quantity, $price); + $result = mb_convert_encoding($result, "UTF-8"); + } + + return $result . "<BR>"; + } + + private static function getFoodNameSplit80($foodName, $quantity, $price): string + { + print_r($foodName); + $foodNames = str_split($foodName, self::LAST_ROW_MAX_NAME_CHAR_LEN80 * 3); + $resultTemp = ""; + + for ($i = 0; $i < count($foodNames); $i++) { + $foodNameTmp = $foodNames[$i]; + if ($i == 0) { + $foodNameLen = Encoding::CalcGbkLenForPrint($foodNameTmp); + $mod = $foodNameLen % self::ROW_MAX_CHAR_LEN80; + $resultTemp = $resultTemp . $foodNameTmp; + $resultTemp = $resultTemp . str_repeat(" ", self::MAX_NAME_CHAR_LEN80 - $mod); + + $quantityStr = '' . $quantity; + $quantityLen = Encoding::CalcAsciiLenForPrint($quantityStr); + $priceStr = '' . round($price, 2); + $priceLen = Encoding::CalcAsciiLenForPrint($priceStr); + $resultTemp = $resultTemp . $quantityStr . str_repeat(" ", self::MAX_QUANTITY_CHAR_LEN80 - $quantityLen); + $resultTemp = $resultTemp . $priceStr . str_repeat(" ", self::MAX_PRICE_CHAR_LEN80 - $priceLen); + } else { + $resultTemp = $resultTemp . $foodNameTmp . "<BR>"; + } + } + return $resultTemp; + } + + /** + * 格式化菜品列表(用于58mm打印机) + * 注意:默认字体排版,若是字体宽度倍大后不适用 + * 58mm打印机一行可打印32个字符 汉子按照2个字符算 + * 分3列: 名称20字符一般用16字符4空格填充 数量6字符 单价6字符,不足用英文空格填充 名称过长换行 + * + * @param foodName 菜品名称 + * @param quantity 数量 + * @param price 价格 + * @throws Exception + */ + + public static function formatPrintOrderItem($foodName, $quantity, $price) + { + $orderNameEmpty = str_repeat(" ", self::MAX_NAME_CHAR_LEN); + $foodNameLen = Encoding::CalcGbkLenForPrint($foodName); +// print("foodNameLen=".$foodNameLen."\n"); + + $quantityStr = '' . $quantity; + $quantityLen = Encoding::CalcAsciiLenForPrint($quantityStr); + // print("quantityLen=".$quantityLen."\n"); + + $priceStr = '' . round($price, 2); + $priceLen = Encoding::CalcAsciiLenForPrint($priceStr); + // print("priceLen=".$priceLen); + + $result = $foodName; + $mod = $foodNameLen % self::ROW_MAX_CHAR_LEN; + // print("mod=".$mod."\n"); + + if ($mod <= self::LAST_ROW_MAX_NAME_CHAR_LEN) { + // 保证各个列的宽度固定,不足部分,利用空格填充 + //make sure all the column length fixed, fill with space if not enough + $result = $result . str_repeat(" ", self::MAX_NAME_CHAR_LEN - $mod); + + } else { + // 另起新行 + // new line + $result = $result . "<BR>"; + $result = $result . $orderNameEmpty; + } + + $result = $result . $quantityStr . str_repeat(" ", self::MAX_QUANTITY_CHAR_LEN - $quantityLen); + $result = $result . $priceStr . str_repeat(" ", self::MAX_PRICE_CHAR_LEN - $priceLen); + + $result = $result . "<BR>"; + + return $result; + } +} + +?> \ No newline at end of file diff --git a/extend/Xpyun/util/Xputil.php b/extend/Xpyun/util/Xputil.php new file mode 100644 index 00000000..c87f49e9 --- /dev/null +++ b/extend/Xpyun/util/Xputil.php @@ -0,0 +1,29 @@ +<?php + +namespace Xpyun\util; +class Xputil +{ + /** + * 哈稀签名 + * @param signSource - 源字符串 + * @return + */ + public static function sign($signSource) + { + $signature = sha1($signSource); + + return $signature; + } + + /** + * 当前UNIX时间戳,精确到毫秒 + * @return string + */ + public static function getMillisecond() + { + list($s1, $s2) = explode(' ', microtime()); + return sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000); + } +} + +?> \ No newline at end of file