初始上传
This commit is contained in:
38
addon/printer/config/diy_view.php
Executable file
38
addon/printer/config/diy_view.php
Executable file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
return [
|
||||
|
||||
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
|
||||
'template' => [],
|
||||
|
||||
// 后台自定义组件——装修
|
||||
'util' => [],
|
||||
|
||||
// 自定义页面路径
|
||||
'link' => [],
|
||||
|
||||
// 自定义图标库
|
||||
'icon_library' => [],
|
||||
|
||||
// uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
|
||||
'component' => [],
|
||||
|
||||
// uni-app 页面,多个逗号隔开
|
||||
'pages' => [],
|
||||
|
||||
// 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
|
||||
'info' => [],
|
||||
|
||||
// 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
|
||||
'theme' => [],
|
||||
|
||||
// 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
|
||||
'data' => []
|
||||
];
|
||||
63
addon/printer/config/event.php
Executable file
63
addon/printer/config/event.php
Executable file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// 事件定义文件
|
||||
return [
|
||||
'bind' => [
|
||||
|
||||
],
|
||||
|
||||
'listen' => [
|
||||
//展示活动
|
||||
'ShowPromotion' => [
|
||||
'addon\printer\event\ShowPromotion',
|
||||
],
|
||||
|
||||
'PromotionType' => [
|
||||
'addon\printer\event\PromotionType',
|
||||
],
|
||||
|
||||
//小票打印
|
||||
'PrintOrder' => [
|
||||
'addon\printer\event\PrintOrder',
|
||||
],
|
||||
|
||||
//模板
|
||||
'PrinterTemplate' => [
|
||||
'addon\printer\event\PrinterTemplate',
|
||||
],
|
||||
|
||||
//打印数据
|
||||
'PrinterContent' => [
|
||||
'addon\printer\event\PrinterContent',
|
||||
],
|
||||
|
||||
//订单支付
|
||||
'OrderPay' => [
|
||||
'addon\printer\event\OrderPay',
|
||||
],
|
||||
//支付打印
|
||||
'OrderPayPrinter' => [
|
||||
'addon\printer\event\OrderPayPrinter',
|
||||
],
|
||||
|
||||
//订单收货
|
||||
'OrderTakeDeliveryAfter' => [
|
||||
'addon\printer\event\OrderTakeDeliveryAfter',
|
||||
],
|
||||
//收货打印
|
||||
'OrderTakeDeliveryPrinter' => [
|
||||
'addon\printer\event\OrderTakeDeliveryPrinter',
|
||||
],
|
||||
|
||||
//充值
|
||||
'MemberRechargeOrderPay' => [
|
||||
'addon\printer\event\MemberRechargeOrderPay',
|
||||
],
|
||||
'MemberRechargeOrderPayPrinter' => [
|
||||
'addon\printer\event\MemberRechargeOrderPayPrinter',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'subscribe' => [
|
||||
],
|
||||
];
|
||||
20
addon/printer/config/info.php
Executable file
20
addon/printer/config/info.php
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
return [
|
||||
'name' => 'printer',
|
||||
'title' => '小票打印',
|
||||
'description' => '小票打印',
|
||||
'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
|
||||
'status' => 1,
|
||||
'author' => '',
|
||||
'version' => '5.5.3',
|
||||
'version_no' => '553250709001',
|
||||
'content' => '',
|
||||
];
|
||||
84
addon/printer/config/menu_shop.php
Executable file
84
addon/printer/config/menu_shop.php
Executable file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 店铺端菜单设置
|
||||
// +----------------------------------------------------------------------
|
||||
return [
|
||||
[
|
||||
'name' => 'PROMOTION_PRINTER',
|
||||
'title' => '小票打印',
|
||||
'url' => 'printer://shop/printer/lists',
|
||||
'parent' => 'PROMOTION_TOOL',
|
||||
'picture' => 'addon/printer/shop/view/public/img/distribution_new.png',
|
||||
'picture_selected' => 'addon/printer/shop/view/public/img/distribution_select.png',
|
||||
'is_show' => 1,
|
||||
'sort' => 1,
|
||||
'child_list' => [
|
||||
[
|
||||
'name' => 'PROMOTION_PRINTER_LIST',
|
||||
'title' => '打印机管理',
|
||||
'url' => 'printer://shop/printer/lists',
|
||||
'is_show' => 1,
|
||||
'sort' => 2,
|
||||
'child_list' => [
|
||||
[
|
||||
'name' => 'PROMOTION_PRINTER_ADD',
|
||||
'title' => '添加打印机',
|
||||
'url' => 'printer://shop/printer/add',
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
],
|
||||
[
|
||||
'name' => 'PROMOTION_PRINTER_EDIT',
|
||||
'title' => '编辑打印机',
|
||||
'url' => 'printer://shop/printer/edit',
|
||||
'sort' => 1,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
],
|
||||
[
|
||||
'name' => 'PROMOTION_PRINTER_DELETE',
|
||||
'title' => '删除打印机',
|
||||
'url' => 'printer://shop/printer/delete',
|
||||
'sort' => 1,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'PROMOTION_TEMPLATE_LIST',
|
||||
'title' => '打印模板',
|
||||
'url' => 'printer://shop/template/lists',
|
||||
'is_show' => 1,
|
||||
'sort' => 2,
|
||||
'child_list' => [
|
||||
[
|
||||
'name' => 'PROMOTION_TEMPLATE_ADD',
|
||||
'title' => '添加模板',
|
||||
'url' => 'printer://shop/template/add',
|
||||
'sort' => 1,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
],
|
||||
[
|
||||
'name' => 'PROMOTION_TEMPLATE_EDIT',
|
||||
'title' => '编辑模板',
|
||||
'url' => 'printer://shop/template/edit',
|
||||
'sort' => 2,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
],
|
||||
[
|
||||
'name' => 'PROMOTION_TEMPLATE_DELETE',
|
||||
'title' => '删除模板',
|
||||
'url' => 'printer://shop/template/delete',
|
||||
'sort' => 3,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
|
||||
];
|
||||
1
addon/printer/data/install.sql
Executable file
1
addon/printer/data/install.sql
Executable file
@@ -0,0 +1 @@
|
||||
SET NAMES 'utf8';
|
||||
32
addon/printer/data/sdk/yilianyun/Autoloader.php
Executable file
32
addon/printer/data/sdk/yilianyun/Autoloader.php
Executable file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
class Autoloader{
|
||||
|
||||
public static function loadByNamespace($name)
|
||||
{
|
||||
$class_path = str_replace('\\', DIRECTORY_SEPARATOR, $name);
|
||||
if (strpos($name, 'App\\') === 0) {
|
||||
$class_file = __DIR__ . substr($class_path, strlen('App')) . '.php';
|
||||
}elseif(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('\App\Autoloader::loadByNamespace');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
130
addon/printer/data/sdk/yilianyun/Demo/AuthorizationCodeMode/callback.php
Executable file
130
addon/printer/data/sdk/yilianyun/Demo/AuthorizationCodeMode/callback.php
Executable file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
use App\Oauth\YlyOauthClient;
|
||||
use App\Api\PrintService;
|
||||
|
||||
|
||||
$client = new YlyOauthClient($config);
|
||||
|
||||
$code = ''; //开放型应用商户授权码 获取请看 http://doc2.10ss.net/371769#Code_5
|
||||
if (empty($code)) {echo 'The authorization code cannot be empty';return;}
|
||||
|
||||
try {
|
||||
$token = $client->getToken($code);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
print_r(json_decode($e->getMessage(), true));
|
||||
return;
|
||||
}
|
||||
|
||||
$access_token = $token->access_token; //调用API凭证AccessToken
|
||||
$refresh_token = $token->refresh_token; //刷新AccessToken凭证 失效时间35天
|
||||
$machine_code = $token->machine_code; //商户授权机器码
|
||||
$expires_in = $token->expires_in; //AccessToken失效时间30天
|
||||
$origin_id = ''; //内部订单号(32位以内)
|
||||
|
||||
|
||||
if (empty($machine_code)) {echo 'The machine_code cannot be empty';return;}
|
||||
|
||||
if (empty($origin_id)) {echo 'The origin_id cannot be empty';return;}
|
||||
|
||||
/**文本接口开始**/
|
||||
$print = new PrintService($access_token, $config);
|
||||
//58mm排版 排版指令详情请看 http://doc2.10ss.net/332006
|
||||
$content = "<FS2><center>**#1 美团**</center></FS2>";
|
||||
$content .= str_repeat('.', 32);
|
||||
$content .= "<FS2><center>--在线支付--</center></FS2>";
|
||||
$content .= "<FS><center>张周兄弟烧烤</center></FS>";
|
||||
$content .= "订单时间:". date("Y-m-d H:i") . "\n";
|
||||
$content .= "订单编号:40807050607030\n";
|
||||
$content .= str_repeat('*', 14) . "商品" . str_repeat("*", 14);
|
||||
$content .= "<table>";
|
||||
$content .= "<tr><td>烤土豆(超级辣)</td><td>x3</td><td>5.96</td></tr>";
|
||||
$content .= "<tr><td>烤豆干(超级辣)</td><td>x2</td><td>3.88</td></tr>";
|
||||
$content .= "<tr><td>烤鸡翅(超级辣)</td><td>x3</td><td>17.96</td></tr>";
|
||||
$content .= "<tr><td>烤排骨(香辣)</td><td>x3</td><td>12.44</td></tr>";
|
||||
$content .= "<tr><td>烤韭菜(超级辣)</td><td>x3</td><td>8.96</td></tr>";
|
||||
$content .= "</table>";
|
||||
$content .= str_repeat('.', 32);
|
||||
$content .= "<QR>这是二维码内容</QR>";
|
||||
$content .= "小计:¥82\n";
|
||||
$content .= "折扣:¥4 \n";
|
||||
$content .= str_repeat('*', 32);
|
||||
$content .= "订单总价:¥78 \n";
|
||||
$content .= "<FS2><center>**#1 完**</center></FS2>";
|
||||
|
||||
try{
|
||||
var_dump($print->index($machine_code, $content, $origin_id));
|
||||
}catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
/**文本接口结束**/
|
||||
|
||||
|
||||
///**图形接口开始**/
|
||||
//$picturePrint = new PicturePrintService($access_token, $config);
|
||||
//$content = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1497000905083&di=7c3cffef1dd40edffbd0a37c4eabb277&imgtype=0&src=http://img1.touxiang.cn/uploads/20131114/14-054929_462.jpg";
|
||||
//try{
|
||||
// var_dump($picturePrint->index($machine_code, $content, $origin_id));
|
||||
//}catch (Exception $e) {
|
||||
// echo $e->getMessage();
|
||||
//}
|
||||
///**图形接口结束**/
|
||||
|
||||
|
||||
///**面单接口开始**/ //打印机型必须为k5;
|
||||
//$expressPrint = new ExpressPrintService($access_token, $config);
|
||||
//$content = array(
|
||||
// "OrderCode"=> "0126578665784971",
|
||||
// "ShipperCode"=> "SF", //SF YZPY HTKY YD
|
||||
// "PayType"=> 1,
|
||||
// "ExpType"=> 1,
|
||||
// "Cost"=>6.0,
|
||||
// "OtherCost"=> 7.0,
|
||||
// "CustomerName" => '1264546',
|
||||
// "CustomerPwd" => '4545454',
|
||||
// "MonthCode" => '',
|
||||
// "Sender"=> array(
|
||||
// "Company" => "5645645",
|
||||
// "Name" => "Taylor",
|
||||
// "Mobile" => "15018442396",
|
||||
// "ProvinceName" => "上海",
|
||||
// "CityName" => "上海",
|
||||
// "PostCode" => '61000',
|
||||
// "ExpAreaName" => "青浦区",
|
||||
// "Address" => "明珠路73号"
|
||||
// ),
|
||||
// "Receiver"=> array(
|
||||
// "Company"=> "789789",
|
||||
// "Name"=> "Yann",
|
||||
// "Mobile"=> "15018442396",
|
||||
// "ProvinceName"=> "北京",
|
||||
// "CityName"=> "北京",
|
||||
// "PostCode" => '61000',
|
||||
// "ExpAreaName"=> "朝阳区",
|
||||
// "Address"=> "三里屯街道雅秀大厦"
|
||||
// ),
|
||||
// "Commodity" => array(
|
||||
// array(
|
||||
// "GoodsName"=> "鞋子",
|
||||
// )
|
||||
// ),
|
||||
// "AddService"=> array(
|
||||
// array(
|
||||
// "Name"=> "COD",
|
||||
// "Value"=> "1020",
|
||||
// "CustomerID" => "44564"
|
||||
// )
|
||||
// ),
|
||||
// "StartDate" => date("y-M-d H:i:s",time() + 7200),
|
||||
// "Weight"=> 1.0,
|
||||
// "Quantity"=> 1,
|
||||
// "Volume"=> 0.0,
|
||||
// "Remark"=> "小心轻放",
|
||||
//);
|
||||
//
|
||||
//try{
|
||||
// var_dump($expressPrint->index($machine_code, $content, $origin_id));
|
||||
//}catch (Exception $e) {
|
||||
// echo $e->getMessage();
|
||||
//}
|
||||
///**面单接口结束**/
|
||||
123
addon/printer/data/sdk/yilianyun/Demo/ClientMode/callback.php
Executable file
123
addon/printer/data/sdk/yilianyun/Demo/ClientMode/callback.php
Executable file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
use App\Oauth\YlyOauthClient;
|
||||
use App\Api\PrintService;
|
||||
use App\Api\PicturePrintService;
|
||||
use App\Api\ExpressPrintService;
|
||||
|
||||
$client = new YlyOauthClient($config);
|
||||
try {
|
||||
$token = $client->getToken();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
print_r(json_decode($e->getMessage(), true));
|
||||
return;
|
||||
}
|
||||
|
||||
$access_token = $token->access_token; //调用API凭证AccessToken 永久有效,请妥善保存.
|
||||
$refresh_token = $token->refresh_token; //刷新AccessToken凭证 失效时间35天
|
||||
$expires_in = $token->expires_in; //自有型应用可忽略此回调参数, AccessToken失效时间30天
|
||||
$machine_code = ''; //机器码
|
||||
$origin_id = ''; //内部订单号(32位以内)
|
||||
|
||||
|
||||
/**文本接口开始**/
|
||||
$print = new PrintService($access_token, $config);
|
||||
//58mm排版 排版指令详情请看 http://doc2.10ss.net/332006
|
||||
$content = "<FS2><center>**#1 美团**</center></FS2>";
|
||||
$content .= str_repeat('.', 32);
|
||||
$content .= "<FS2><center>--在线支付--</center></FS2>";
|
||||
$content .= "<FS><center>张周兄弟烧烤</center></FS>";
|
||||
$content .= "订单时间:". date("Y-m-d H:i") . "\n";
|
||||
$content .= "订单编号:40807050607030\n";
|
||||
$content .= str_repeat('*', 14) . "商品" . str_repeat("*", 14);
|
||||
$content .= "<table>";
|
||||
$content .= "<tr><td>烤土豆(超级辣)</td><td>x3</td><td>5.96</td></tr>";
|
||||
$content .= "<tr><td>烤豆干(超级辣)</td><td>x2</td><td>3.88</td></tr>";
|
||||
$content .= "<tr><td>烤鸡翅(超级辣)</td><td>x3</td><td>17.96</td></tr>";
|
||||
$content .= "<tr><td>烤排骨(香辣)</td><td>x3</td><td>12.44</td></tr>";
|
||||
$content .= "<tr><td>烤韭菜(超级辣)</td><td>x3</td><td>8.96</td></tr>";
|
||||
$content .= "</table>";
|
||||
$content .= str_repeat('.', 32);
|
||||
$content .= "<QR>这是二维码内容</QR>";
|
||||
$content .= "小计:¥82\n";
|
||||
$content .= "折扣:¥4 \n";
|
||||
$content .= str_repeat('*', 32);
|
||||
$content .= "订单总价:¥78 \n";
|
||||
$content .= "<FS2><center>**#1 完**</center></FS2>";
|
||||
|
||||
try{
|
||||
var_dump($print->index($machine_code, $content, $origin_id));
|
||||
}catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
/**文本接口结束**/
|
||||
|
||||
|
||||
///**图形接口开始**/
|
||||
//$picturePrint = new PicturePrintService($access_token, $config);
|
||||
//$content = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1497000905083&di=7c3cffef1dd40edffbd0a37c4eabb277&imgtype=0&src=http://img1.touxiang.cn/uploads/20131114/14-054929_462.jpg";
|
||||
//try{
|
||||
// var_dump($picturePrint->index($machine_code, $content, $origin_id));
|
||||
//}catch (Exception $e) {
|
||||
// echo $e->getMessage();
|
||||
//}
|
||||
///**图形接口结束**/
|
||||
|
||||
|
||||
///**面单接口开始**/ //打印机型必须为k5;
|
||||
//$expressPrint = new ExpressPrintService($access_token, $config);
|
||||
//$content = array(
|
||||
// "OrderCode"=> "0126578665784971",
|
||||
// "ShipperCode"=> "SF", //SF YZPY HTKY YD
|
||||
// "PayType"=> 1,
|
||||
// "ExpType"=> 1,
|
||||
// "Cost"=>6.0,
|
||||
// "OtherCost"=> 7.0,
|
||||
// "CustomerName" => '1264546',
|
||||
// "CustomerPwd" => '4545454',
|
||||
// "MonthCode" => '',
|
||||
// "Sender"=> array(
|
||||
// "Company" => "5645645",
|
||||
// "Name" => "Taylor",
|
||||
// "Mobile" => "15018442396",
|
||||
// "ProvinceName" => "上海",
|
||||
// "CityName" => "上海",
|
||||
// "PostCode" => '61000',
|
||||
// "ExpAreaName" => "青浦区",
|
||||
// "Address" => "明珠路73号"
|
||||
// ),
|
||||
// "Receiver"=> array(
|
||||
// "Company"=> "789789",
|
||||
// "Name"=> "Yann",
|
||||
// "Mobile"=> "15018442396",
|
||||
// "ProvinceName"=> "北京",
|
||||
// "CityName"=> "北京",
|
||||
// "PostCode" => '61000',
|
||||
// "ExpAreaName"=> "朝阳区",
|
||||
// "Address"=> "三里屯街道雅秀大厦"
|
||||
// ),
|
||||
// "Commodity" => array(
|
||||
// array(
|
||||
// "GoodsName"=> "鞋子",
|
||||
// )
|
||||
// ),
|
||||
// "AddService"=> array(
|
||||
// array(
|
||||
// "Name"=> "COD",
|
||||
// "Value"=> "1020",
|
||||
// "CustomerID" => "44564"
|
||||
// )
|
||||
// ),
|
||||
// "StartDate" => date("y-M-d H:i:s",time() + 7200),
|
||||
// "Weight"=> 1.0,
|
||||
// "Quantity"=> 1,
|
||||
// "Volume"=> 0.0,
|
||||
// "Remark"=> "小心轻放",
|
||||
//);
|
||||
//
|
||||
//try{
|
||||
// var_dump($expressPrint->index($machine_code, $content, $origin_id));
|
||||
//}catch (Exception $e) {
|
||||
// echo $e->getMessage();
|
||||
//}
|
||||
///**面单接口结束**/
|
||||
11
addon/printer/data/sdk/yilianyun/Demo/index.php
Executable file
11
addon/printer/data/sdk/yilianyun/Demo/index.php
Executable file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
include __DIR__ . '/init.php';
|
||||
|
||||
if (GRANTTYPE == 'client_credentials') {
|
||||
include_once __DIR__ . '/ClientMode/callback.php';
|
||||
}
|
||||
|
||||
if (GRANTTYPE == 'authorization_code') {
|
||||
include_once __DIR__ . '/AuthorizationCodeMode/callback.php';
|
||||
}
|
||||
14
addon/printer/data/sdk/yilianyun/Demo/init.php
Executable file
14
addon/printer/data/sdk/yilianyun/Demo/init.php
Executable file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
include dirname(__DIR__) . '/Lib/Autoloader.php';
|
||||
use App\Config\YlyConfig;
|
||||
|
||||
$grantType = 'client_credentials'; //'client_credentials' 自有型应用; 'authorization_code' 开放型应用
|
||||
define('GRANTTYPE', $grantType);
|
||||
|
||||
|
||||
$clientId = ''; //应用id
|
||||
$clientSecret = ''; //应用密钥
|
||||
|
||||
|
||||
$config = new YlyConfig($clientId, $clientSecret);
|
||||
21
addon/printer/data/sdk/yilianyun/api/ExpressPrintService.php
Executable file
21
addon/printer/data/sdk/yilianyun/api/ExpressPrintService.php
Executable file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api;
|
||||
|
||||
class ExpressPrintService extends RpcService{
|
||||
|
||||
/**
|
||||
* 面单打印接口
|
||||
* 不支持机型: k4-wh, k4-wa, m1 (k4系列机型不建议使用不干胶热敏纸)
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $content array 面单数据
|
||||
* @param $originId string 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母
|
||||
* @return mixed
|
||||
*/
|
||||
public function index($machineCode, $content, $originId)
|
||||
{
|
||||
return $this->client->call('expressprint/index', array('machine_code' => $machineCode, 'content' => $content, 'origin_id' => $originId));
|
||||
}
|
||||
|
||||
}
|
||||
22
addon/printer/data/sdk/yilianyun/api/OauthService.php
Executable file
22
addon/printer/data/sdk/yilianyun/api/OauthService.php
Executable file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api;
|
||||
|
||||
class OauthService extends RpcService{
|
||||
|
||||
|
||||
/**
|
||||
* 设置推送URL接口
|
||||
*
|
||||
* @param $cmd string 推送队列键
|
||||
* @param $url string 推送地址
|
||||
* @param $status string 推送开关
|
||||
* @return mixed
|
||||
*/
|
||||
public function setPushUrl($cmd, $url, $status = 'open')
|
||||
{
|
||||
return $this->client->call('oauth/setpushurl', array('cmd' => $cmd, 'url' => $url, 'status' => $status));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
21
addon/printer/data/sdk/yilianyun/api/PicturePrintService.php
Executable file
21
addon/printer/data/sdk/yilianyun/api/PicturePrintService.php
Executable file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api;
|
||||
|
||||
class PicturePrintService extends RpcService{
|
||||
|
||||
|
||||
/**
|
||||
* 图形打印接口
|
||||
* 不支持机型: k4-wh, k4-wa, m1
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $pictureUrl string 图片链接地址
|
||||
* @param $originId string 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母
|
||||
* @return mixed
|
||||
*/
|
||||
public function index($machineCode, $pictureUrl, $originId)
|
||||
{
|
||||
return $this->client->call('pictureprint/index', array('machine_code' => $machineCode, 'picture_url' => $pictureUrl, 'origin_id' => $originId));
|
||||
}
|
||||
}
|
||||
19
addon/printer/data/sdk/yilianyun/api/PrintMenuService.php
Executable file
19
addon/printer/data/sdk/yilianyun/api/PrintMenuService.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api;
|
||||
|
||||
class PrintMenuService extends RpcService{
|
||||
|
||||
/**
|
||||
* 添加应用菜单接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $content string 菜单详情(json)
|
||||
* @return mixed
|
||||
*/
|
||||
public function addPrintMenu($machineCode, $content)
|
||||
{
|
||||
return $this->client->call('printmenu/addprintmenu', array('machine_code' => $machineCode, 'content' => $content));
|
||||
}
|
||||
|
||||
}
|
||||
43
addon/printer/data/sdk/yilianyun/api/PrintService.php
Executable file
43
addon/printer/data/sdk/yilianyun/api/PrintService.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace addon\printer\data\sdk\yilianyun\api;
|
||||
|
||||
use addon\printer\data\sdk\yilianyun\config\YlyConfig;
|
||||
use addon\printer\model\Printer;
|
||||
use think\Exception;
|
||||
|
||||
class PrintService extends RpcService
|
||||
{
|
||||
|
||||
/**
|
||||
* 打印接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $content string 打印内容
|
||||
* @param $originId string 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母
|
||||
* @return mixed
|
||||
*/
|
||||
public function index($machineCode, $content, $originId, $printer = [])
|
||||
{
|
||||
static $call_num = 0;
|
||||
$call_num ++;
|
||||
$res = $this->client->call('print/index', array ( 'machine_code' => $machineCode, 'content' => $content, 'origin_id' => $originId ));
|
||||
|
||||
if (is_null($res)) {
|
||||
throw new Exception("invalid response.");
|
||||
}
|
||||
//token过期处理
|
||||
if ($res->error == 18 && $printer && $call_num <= 3) {
|
||||
$printer_model = new Printer();
|
||||
$config = new YlyConfig($printer[ 'open_id' ], $printer[ 'apikey' ]);
|
||||
$access_token = $printer_model->getYlyToken($config, $printer[ 'printer_id' ], 1);
|
||||
$res = (new self($access_token, $config))->index($machineCode, $content, $originId, $printer);
|
||||
}
|
||||
if (isset($res->error) && $res->error != 0) {
|
||||
$errorDescription = isset($res->body) ? $res->error_description . $res->body : $res->error_description;
|
||||
throw new Exception('Call method print/index error code is ' . $res->error . ' error message is ' . $errorDescription);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
247
addon/printer/data/sdk/yilianyun/api/PrinterService.php
Executable file
247
addon/printer/data/sdk/yilianyun/api/PrinterService.php
Executable file
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
|
||||
namespace addon\printer\data\sdk\yilianyun\api;
|
||||
|
||||
class PrinterService extends RpcService{
|
||||
|
||||
/**
|
||||
* 自有型应用授权终端
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $mSign string 机器密钥
|
||||
* @param string $printName 打印机昵称
|
||||
* @param string $phone gprs卡号
|
||||
* @return mixed
|
||||
*/
|
||||
public function addPrinter($machineCode, $mSign, $printName = '', $phone = '')
|
||||
{
|
||||
$params = array(
|
||||
'machine_code' => $machineCode,
|
||||
'msign' => $mSign,
|
||||
);
|
||||
if (!empty($phone)) {
|
||||
$params['phone'] = $phone;
|
||||
}
|
||||
if (!empty($printName)) {
|
||||
$params['print_name'] = $printName;
|
||||
}
|
||||
return $this->client->call('printer/addprinter', $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置内置语音接口
|
||||
* 注意: 仅支持K4-WA、K4-GAD、K4-WGEAD型号
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $content string 在线语音地址链接 or 自定义语音内容
|
||||
* @param bool $isFile true or false
|
||||
* @param string $aid int 0~9 , 定义需设置的语音编号,若不提交,默认升序
|
||||
* @return mixed
|
||||
*/
|
||||
public function setVoice($machineCode, $content, $isFile = false, $aid = '')
|
||||
{
|
||||
$params = array(
|
||||
'machine_code' => $machineCode,
|
||||
'content' => $content,
|
||||
'is_file' => $isFile,
|
||||
);
|
||||
if (!empty($aid)){
|
||||
$params ['aid'] = $aid;
|
||||
}
|
||||
return $this->client->call('printer/setvoice', $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除内置语音接口
|
||||
* 注意: 仅支持K4-WA、K4-GAD、K4-WGEAD型号
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $aid int 0 ~ 9 编号
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteVoice($machineCode, $aid)
|
||||
{
|
||||
return $this->client->call('printer/deletevoice', array('machine_code' => $machineCode, 'aid' => $aid));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除终端授权接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @return mixed
|
||||
*/
|
||||
public function deletePrinter($machineCode)
|
||||
{
|
||||
return $this->client->call('printer/deleteprinter', array('machine_code' => $machineCode));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关机重启接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $responseType string restart or shutdown
|
||||
* @return mixed
|
||||
*/
|
||||
public function shutdownRestart($machineCode, $responseType)
|
||||
{
|
||||
return $this->client->call('printer/shutdownrestart', array('machine_code' => $machineCode, 'response_type' => $responseType));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 声音调节接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $voice string 音量 0 or 1 or 2 or 3
|
||||
* @param $responseType string buzzer (蜂鸣器) or horn (喇叭)
|
||||
* @return mixed
|
||||
*/
|
||||
public function setsound($machineCode, $voice, $responseType)
|
||||
{
|
||||
return $this->client->call('printer/setsound', array('machine_code' => $machineCode, 'voice' => $voice, 'response_type' => $responseType));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取机型打印宽度接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @return mixed
|
||||
*/
|
||||
public function printInfo($machineCode)
|
||||
{
|
||||
return $this->client->call('printer/printinfo', array('machine_code' => $machineCode));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取机型软硬件版本接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion($machineCode)
|
||||
{
|
||||
return $this->client->call('printer/getversion', array('machine_code' => $machineCode));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取消所有未打印订单接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @return mixed
|
||||
*/
|
||||
public function cancelAll($machineCode)
|
||||
{
|
||||
return $this->client->call('printer/cancelall', array('machine_code' => $machineCode));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取消单条未打印订单接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $orderId string 未打印的易联云ID
|
||||
* @return mixed
|
||||
*/
|
||||
public function cancelOne($machineCode, $orderId)
|
||||
{
|
||||
return $this->client->call('printer/cancelone', array('machine_code' => $machineCode, 'order_id' => $orderId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置logo接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $imgUrl string logo链接地址
|
||||
* @return mixed
|
||||
*/
|
||||
public function setIcon($machineCode, $imgUrl)
|
||||
{
|
||||
return $this->client->call('printer/seticon', array('machine_code' => $machineCode, 'img_url' => $imgUrl));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取消logo接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteIcon($machineCode)
|
||||
{
|
||||
return $this->client->call('printer/deleteicon', array('machine_code' => $machineCode));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 打印方式接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $responseType string btnopen or btnclose
|
||||
* @return mixed
|
||||
*/
|
||||
public function btnPrint($machineCode, $responseType)
|
||||
{
|
||||
return $this->client->call('printer/btnprint', array('machine_code' => $machineCode, 'response_type' => $responseType));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 接单拒单设置接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $responseType string open or close
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOrder($machineCode, $responseType)
|
||||
{
|
||||
return $this->client->call('printer/getorder', array('machine_code' => $machineCode, 'response_type' => $responseType));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取订单状态接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $orderId string 易联云订单id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOrderStatus($machineCode, $orderId)
|
||||
{
|
||||
return $this->client->call('printer/getorderstatus', array('machine_code' => $machineCode, 'order_id' => $orderId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取订单列表接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @param $pageIndex int 第几页
|
||||
* @param $pageSize int 查询条数
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOrderPagingList($machineCode, $pageIndex = 1 , $pageSize = 10)
|
||||
{
|
||||
return $this->client->call('printer/getorderpaginglist', array('machine_code' => $machineCode, 'page_index' => $pageIndex, 'page_size' => $pageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取终端状态接口
|
||||
*
|
||||
* @param $machineCode string 机器码
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPrintStatus($machineCode)
|
||||
{
|
||||
return $this->client->call('printer/getprintstatus', array('machine_code' => $machineCode));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
17
addon/printer/data/sdk/yilianyun/api/RpcService.php
Executable file
17
addon/printer/data/sdk/yilianyun/api/RpcService.php
Executable file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace addon\printer\data\sdk\yilianyun\api;
|
||||
|
||||
use addon\printer\data\sdk\yilianyun\config\YlyConfig;
|
||||
use addon\printer\data\sdk\yilianyun\protocol\YlyRpcClient;
|
||||
|
||||
class RpcService{
|
||||
|
||||
protected $client;
|
||||
|
||||
public function __construct($token, YlyConfig $config)
|
||||
{
|
||||
$this->client = new YlyRpcClient($token, $config);
|
||||
}
|
||||
|
||||
}
|
||||
65
addon/printer/data/sdk/yilianyun/config/YlyConfig.php
Executable file
65
addon/printer/data/sdk/yilianyun/config/YlyConfig.php
Executable file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace addon\printer\data\sdk\yilianyun\config;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class YlyConfig{
|
||||
|
||||
private $clientId = '';
|
||||
private $clientSecret = '';
|
||||
private $requestUrl = "https://open-api.10ss.net";
|
||||
private $log;
|
||||
|
||||
public function __construct($clientId, $clientSecret)
|
||||
{
|
||||
|
||||
if ($clientId == null || $clientId == "") {
|
||||
throw new InvalidArgumentException("clientId is required");
|
||||
}
|
||||
|
||||
if ($clientSecret == null || $clientSecret == "") {
|
||||
throw new InvalidArgumentException("clientSecret is required");
|
||||
}
|
||||
|
||||
$this->clientId = $clientId;
|
||||
$this->clientSecret = $clientSecret;
|
||||
}
|
||||
|
||||
public function getClientId()
|
||||
{
|
||||
return $this->clientId;
|
||||
}
|
||||
|
||||
|
||||
public function getClientSecret()
|
||||
{
|
||||
return $this->clientSecret;
|
||||
}
|
||||
|
||||
public function getRequestUrl()
|
||||
{
|
||||
return $this->requestUrl;
|
||||
}
|
||||
|
||||
public function setRequestUrl($requestUrl)
|
||||
{
|
||||
$this->requestUrl = $requestUrl;
|
||||
}
|
||||
|
||||
public function getLog()
|
||||
{
|
||||
return $this->log;
|
||||
}
|
||||
|
||||
public function setLog($log)
|
||||
{
|
||||
if (!method_exists($log, "info")) {
|
||||
throw new InvalidArgumentException("logger need have method 'info(\$message)'");
|
||||
}
|
||||
if (!method_exists($log, "error")) {
|
||||
throw new InvalidArgumentException("logger need have method 'error(\$message)'");
|
||||
}
|
||||
$this->log = $log;
|
||||
}
|
||||
|
||||
}
|
||||
129
addon/printer/data/sdk/yilianyun/oauth/YlyOauthClient.php
Executable file
129
addon/printer/data/sdk/yilianyun/oauth/YlyOauthClient.php
Executable file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace addon\printer\data\sdk\yilianyun\oauth;
|
||||
|
||||
use addon\printer\data\sdk\yilianyun\config\YlyConfig;
|
||||
use Exception;
|
||||
|
||||
class YlyOauthClient
|
||||
{
|
||||
|
||||
private $clientId;
|
||||
private $clientSecret;
|
||||
private $tokenUrl;
|
||||
private $log;
|
||||
|
||||
|
||||
public function __construct(YlyConfig $config)
|
||||
{
|
||||
$this->clientId = $config->getClientId();
|
||||
$this->clientSecret = $config->getClientSecret();
|
||||
$this->tokenUrl = $config->getRequestUrl() . '/oauth/oauth';
|
||||
$this->log = $config->getLog();
|
||||
}
|
||||
|
||||
|
||||
public function getToken($code = '')
|
||||
{
|
||||
$time = time();
|
||||
$params = array(
|
||||
'client_id' => $this->clientId,
|
||||
'timestamp' => $time,
|
||||
'sign' => $this->getSign($time),
|
||||
'id' => $this->uuid4(),
|
||||
'scope' => 'all'
|
||||
);
|
||||
$params[ 'grant_type' ] = 'client_credentials';
|
||||
if (!empty($code)) {
|
||||
$params[ 'code' ] = $code;
|
||||
$params[ 'grant_type' ] = 'authorization_code';
|
||||
}
|
||||
return $this->send($params);
|
||||
}
|
||||
|
||||
|
||||
public function refreshToken($refreshToken)
|
||||
{
|
||||
$time = time();
|
||||
$params = array(
|
||||
'client_id' => $this->clientId,
|
||||
'timestamp' => $time,
|
||||
'sign' => $this->getSign($time),
|
||||
'id' => $this->uuid4(),
|
||||
'scope' => 'all',
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refreshToken,
|
||||
);
|
||||
return $this->send($params);
|
||||
}
|
||||
|
||||
|
||||
public function getSign($timestamp)
|
||||
{
|
||||
return md5(
|
||||
$this->clientId .
|
||||
$timestamp .
|
||||
$this->clientSecret
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function uuid4()
|
||||
{
|
||||
mt_srand((double) microtime() * 10000);
|
||||
$charid = strtolower(md5(uniqid(rand(), true)));
|
||||
$hyphen = '-';
|
||||
$uuidV4 =
|
||||
substr($charid, 0, 8) . $hyphen .
|
||||
substr($charid, 8, 4) . $hyphen .
|
||||
substr($charid, 12, 4) . $hyphen .
|
||||
substr($charid, 16, 4) . $hyphen .
|
||||
substr($charid, 20, 12);
|
||||
return $uuidV4;
|
||||
}
|
||||
|
||||
|
||||
public function send($data)
|
||||
{
|
||||
$requestInfo = http_build_query($data);
|
||||
$log = $this->log;
|
||||
if ($log != null) {
|
||||
$log->info("request data: " . $requestInfo);
|
||||
}
|
||||
$curl = curl_init(); // 启动一个CURL会话
|
||||
curl_setopt($curl, CURLOPT_URL, $this->tokenUrl); // 要访问的地址
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检测
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Expect:'
|
||||
)); // 解决数据包大不能提交
|
||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
|
||||
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
|
||||
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestInfo); // Post提交的数据包
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
|
||||
$requestResponse = curl_exec($curl); // 执行操作
|
||||
$response = json_decode($requestResponse);
|
||||
if (curl_errno($curl)) {
|
||||
if ($log != null) {
|
||||
$log->error("error: " . curl_error($curl));
|
||||
}
|
||||
throw new Exception(curl_error($curl));
|
||||
}
|
||||
if (is_null($response)) {
|
||||
throw new Exception("illegal response :" . $requestResponse);
|
||||
}
|
||||
|
||||
if ($response->error != 0 && $response->error_description != 'success') {
|
||||
throw new Exception(json_encode($response, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($this->log != null) {
|
||||
$this->log->info("response: " . json_encode($response));
|
||||
}
|
||||
curl_close($curl); // 关键CURL会话
|
||||
return $response->body; // 返回数据
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
105
addon/printer/data/sdk/yilianyun/protocol/YlyRpcClient.php
Executable file
105
addon/printer/data/sdk/yilianyun/protocol/YlyRpcClient.php
Executable file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace addon\printer\data\sdk\yilianyun\protocol;
|
||||
|
||||
use addon\printer\data\sdk\yilianyun\config\YlyConfig;
|
||||
use Exception;
|
||||
|
||||
class YlyRpcClient
|
||||
{
|
||||
|
||||
private $clientId;
|
||||
private $clientSecret;
|
||||
private $requestUrl;
|
||||
private $token;
|
||||
private $log;
|
||||
|
||||
|
||||
public function __construct($token, YlyConfig $config)
|
||||
{
|
||||
$this->clientId = $config->getClientId();
|
||||
$this->clientSecret = $config->getClientSecret();
|
||||
$this->requestUrl = $config->getRequestUrl();
|
||||
$this->log = $config->getLog();
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
|
||||
public function call($action, array $params)
|
||||
{
|
||||
$time = time();
|
||||
$params = array_merge(array(
|
||||
'client_id' => $this->clientId,
|
||||
'timestamp' => $time,
|
||||
'sign' => $this->getSign($time),
|
||||
'id' => $this->uuid4(),
|
||||
'access_token' => $this->token,
|
||||
), $params);
|
||||
|
||||
$result = $this->send($params, $this->requestUrl . '/' . $action);
|
||||
$response = json_decode($result, false, 512, JSON_BIGINT_AS_STRING);
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
public function getSign($timestamp)
|
||||
{
|
||||
return md5(
|
||||
$this->clientId .
|
||||
$timestamp .
|
||||
$this->clientSecret
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function uuid4()
|
||||
{
|
||||
mt_srand((double) microtime() * 10000);
|
||||
$charid = strtolower(md5(uniqid(rand(), true)));
|
||||
$hyphen = '-';
|
||||
$uuidV4 =
|
||||
substr($charid, 0, 8) . $hyphen .
|
||||
substr($charid, 8, 4) . $hyphen .
|
||||
substr($charid, 12, 4) . $hyphen .
|
||||
substr($charid, 16, 4) . $hyphen .
|
||||
substr($charid, 20, 12);
|
||||
return $uuidV4;
|
||||
}
|
||||
|
||||
|
||||
public function send($data, $url)
|
||||
{
|
||||
$requestInfo = http_build_query($data);
|
||||
$log = $this->log;
|
||||
if ($log != null) {
|
||||
$log->info("request data: " . $requestInfo);
|
||||
}
|
||||
$curl = curl_init(); // 启动一个CURL会话
|
||||
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检测
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Expect:'
|
||||
)); // 解决数据包大不能提交
|
||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
|
||||
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
|
||||
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestInfo); // Post提交的数据包
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
|
||||
$response = curl_exec($curl); // 执行操作
|
||||
if (curl_errno($curl)) {
|
||||
if ($log != null) {
|
||||
$log->error("error: " . curl_error($curl));
|
||||
}
|
||||
throw new Exception(curl_error($curl));
|
||||
}
|
||||
if ($log != null) {
|
||||
$log->info("response: " . $response);
|
||||
}
|
||||
curl_close($curl); // 关键CURL会话
|
||||
return $response; // 返回数据
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
5
addon/printer/data/sdk/yilianyun/token.php
Executable file
5
addon/printer/data/sdk/yilianyun/token.php
Executable file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
];
|
||||
1
addon/printer/data/uninstall.sql
Executable file
1
addon/printer/data/uninstall.sql
Executable file
@@ -0,0 +1 @@
|
||||
SET NAMES 'utf8';
|
||||
25
addon/printer/event/Install.php
Executable file
25
addon/printer/event/Install.php
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
/**
|
||||
* 应用安装
|
||||
*/
|
||||
class Install
|
||||
{
|
||||
/**
|
||||
* 执行安装
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return success();
|
||||
}
|
||||
}
|
||||
32
addon/printer/event/MemberRechargeOrderPay.php
Executable file
32
addon/printer/event/MemberRechargeOrderPay.php
Executable file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
use app\model\system\Cron;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 充值完成
|
||||
*/
|
||||
class MemberRechargeOrderPay
|
||||
{
|
||||
|
||||
public function handle($param)
|
||||
{
|
||||
// 收银台主动调用小票打印接口了,执行回调不需要再打印了
|
||||
if (!empty($param[ 'order_from' ]) && $param[ 'order_from' ] == 'cashier') {
|
||||
return;
|
||||
}
|
||||
Log::write('会员充值完成,小票打印_MemberRechargeOrderPay' . json_encode($param));
|
||||
$cron = new Cron();
|
||||
$cron->addCron(1, 0, "充值小票打印", "MemberRechargeOrderPayPrinter", time(), $param[ 'order_id' ]);
|
||||
}
|
||||
}
|
||||
29
addon/printer/event/MemberRechargeOrderPayPrinter.php
Executable file
29
addon/printer/event/MemberRechargeOrderPayPrinter.php
Executable file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
use addon\printer\model\PrinterOrder;
|
||||
|
||||
/**
|
||||
* 充值订单打印
|
||||
*/
|
||||
class MemberRechargeOrderPayPrinter
|
||||
{
|
||||
public function handle($param)
|
||||
{
|
||||
$printer_order_model = new PrinterOrder();
|
||||
return $printer_order_model->printer([
|
||||
'order_id' => $param['relate_id'],
|
||||
'type' => 'recharge',
|
||||
]);
|
||||
}
|
||||
}
|
||||
29
addon/printer/event/OrderPay.php
Executable file
29
addon/printer/event/OrderPay.php
Executable file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
use addon\printer\model\PrinterOrder;
|
||||
use app\model\system\Cron;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 订单打印
|
||||
*/
|
||||
class OrderPay
|
||||
{
|
||||
|
||||
public function handle($param)
|
||||
{
|
||||
Log::write('订单小票打印_OrderPay' . json_encode($param));
|
||||
$cron = new Cron();
|
||||
$cron->addCron(1, 0, '订单小票打印', 'OrderPayPrinter', time(), $param[ 'order_id' ]);
|
||||
}
|
||||
}
|
||||
30
addon/printer/event/OrderPayPrinter.php
Executable file
30
addon/printer/event/OrderPayPrinter.php
Executable file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
use addon\printer\model\PrinterOrder;
|
||||
|
||||
/**
|
||||
* 订单支付打印
|
||||
*/
|
||||
class OrderPayPrinter
|
||||
{
|
||||
|
||||
public function handle($param)
|
||||
{
|
||||
$printer_order_model = new PrinterOrder();
|
||||
return $printer_order_model->printer([
|
||||
'order_id' => $param[ 'relate_id' ],
|
||||
'type' => 'goodsorder',
|
||||
'printer_type' => 'order_pay',
|
||||
]);
|
||||
}
|
||||
}
|
||||
28
addon/printer/event/OrderTakeDeliveryAfter.php
Executable file
28
addon/printer/event/OrderTakeDeliveryAfter.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
use app\model\system\Cron;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 订单收货
|
||||
*/
|
||||
class OrderTakeDeliveryAfter
|
||||
{
|
||||
|
||||
public function handle($param)
|
||||
{
|
||||
Log::write('订单收货小票打印_OrderTakeDelivery' . json_encode($param));
|
||||
$cron = new Cron();
|
||||
$cron->addCron(1, 0, "订单收货小票打印", "OrderTakeDeliveryPrinter", time(), $param[ 'order_id' ]);
|
||||
}
|
||||
}
|
||||
32
addon/printer/event/OrderTakeDeliveryPrinter.php
Executable file
32
addon/printer/event/OrderTakeDeliveryPrinter.php
Executable file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
use addon\printer\model\PrinterOrder;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 订单收货打印
|
||||
*/
|
||||
class OrderTakeDeliveryPrinter
|
||||
{
|
||||
|
||||
public function handle($param)
|
||||
{
|
||||
Log::write('订单收货打印OrderTakeDeliveryPrinter' . json_encode($param));
|
||||
$printer_order_model = new PrinterOrder();
|
||||
return $printer_order_model->printer([
|
||||
'order_id' => $param[ 'relate_id' ],
|
||||
'type' => 'goodsorder',
|
||||
'printer_type' => 'take_delivery',
|
||||
]);
|
||||
}
|
||||
}
|
||||
26
addon/printer/event/PrintOrder.php
Executable file
26
addon/printer/event/PrintOrder.php
Executable file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
use addon\printer\model\PrinterOrder;
|
||||
|
||||
/**
|
||||
* 小票打印
|
||||
*/
|
||||
class PrintOrder
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
$printer_order_model = new PrinterOrder();
|
||||
return $printer_order_model->printer($params);
|
||||
}
|
||||
}
|
||||
329
addon/printer/event/PrinterContent.php
Executable file
329
addon/printer/event/PrinterContent.php
Executable file
@@ -0,0 +1,329 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
use addon\printer\model\Printer;
|
||||
use addon\printer\model\PrinterTemplate;
|
||||
use app\model\order\OrderCommon as OrderCommonModel;
|
||||
use app\model\shop\Shop;
|
||||
use app\Controller;
|
||||
use app\model\store\Store;
|
||||
use app\model\system\Site;
|
||||
|
||||
/**
|
||||
* 打印内容
|
||||
*/
|
||||
class PrinterContent extends Controller
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
|
||||
if ($params[ 'type' ] == 'goodsorder') {
|
||||
$stage = $params[ 'printer_type' ];//打印类型,手动打印、支付、收货
|
||||
$order_id = $params[ 'order_id' ];
|
||||
|
||||
$order_common_model = new OrderCommonModel();
|
||||
$order_info = $order_common_model->getOrderDetail($order_id)[ 'data' ];
|
||||
$site_id = $order_info[ 'site_id' ];
|
||||
$store_id = $order_info[ 'store_id' ];
|
||||
|
||||
//获取店铺信息
|
||||
$shop_model = new Shop();
|
||||
$shop_info = $shop_model->getShopInfo([ [ 'site_id', '=', $site_id ] ])[ 'data' ];
|
||||
|
||||
$site_name = ( new Site() )->getSiteInfo([ [ 'site_id', '=', $site_id ] ], 'site_name')[ 'data' ][ 'site_name' ] ?? '';
|
||||
|
||||
//获取打印机列表
|
||||
$print_model = new Printer();
|
||||
$printer_condition = [
|
||||
[ 'site_id', '=', $site_id ]
|
||||
];
|
||||
if (addon_is_exit('store', $site_id)) $printer_condition[] = [ 'store_id', '=', $store_id ];
|
||||
//指定打印机
|
||||
if(isset($params['printer_ids']) && $params['printer_ids'] != 'all'){
|
||||
if(empty($params['printer_ids'])) $params['printer_ids'] = '0';
|
||||
$printer_condition[] = ['printer_id', 'in', $params['printer_ids']];
|
||||
}
|
||||
|
||||
switch ( $stage ) {
|
||||
case 'order_pay':
|
||||
$printer_condition[] = [ 'order_pay_open', '=', 1 ];
|
||||
$printer_condition[] = [ 'order_pay_order_type', 'like', '%,' . $order_info[ 'order_type' ] . ',%' ];
|
||||
break;
|
||||
case 'take_delivery':
|
||||
$printer_condition[] = [ 'take_delivery_open', '=', 1 ];
|
||||
$printer_condition[] = [ 'take_delivery_order_type', 'like', '%,' . $order_info[ 'order_type' ] . ',%' ];
|
||||
break;
|
||||
case 'manual':
|
||||
$printer_condition[] = [ 'manual_open', '=', 1 ];
|
||||
break;
|
||||
}
|
||||
|
||||
$printer_data = $print_model->getPrinterList($printer_condition)[ 'data' ] ?? [];
|
||||
$res_data = [];
|
||||
|
||||
foreach ($printer_data as $k => $v) {
|
||||
//此处应该根据打印机不同分别设置返回不同的数据。当前为易联云
|
||||
$array = [];
|
||||
$array[ 'printer_info' ] = $v;
|
||||
$print_template_model = new PrinterTemplate();
|
||||
|
||||
$template_id = 0;
|
||||
$print_num = 1;
|
||||
switch ( $stage ) {
|
||||
case 'order_pay':
|
||||
//支付
|
||||
$template_id = $v[ 'order_pay_template_id' ];
|
||||
$print_num = $v[ 'order_pay_print_num' ];
|
||||
break;
|
||||
case 'take_delivery':
|
||||
//收货
|
||||
$template_id = $v[ 'take_delivery_template_id' ];
|
||||
$print_num = $v[ 'take_delivery_print_num' ];
|
||||
break;
|
||||
case 'manual':
|
||||
//手动打印
|
||||
$template_id = $v[ 'template_id' ];
|
||||
$print_num = $v[ 'print_num' ];
|
||||
break;
|
||||
}
|
||||
|
||||
$print_template = $print_template_model->getPrinterTemplateInfo([ [ 'template_id', '=', $template_id ] ])[ 'data' ];
|
||||
|
||||
$array[ 'printer_code' ] = $v[ 'printer_code' ]; //商户授权机器码
|
||||
$array[ 'origin_id' ] = $order_info[ 'order_no' ]; //内部订单号(32位以内)
|
||||
/**文本接口开始**/
|
||||
|
||||
$content = "<MN>" . $print_num . "</MN>";
|
||||
|
||||
//小票名称
|
||||
if ($print_template[ 'title' ] != '') {
|
||||
$content .= "<center>" . $print_template[ 'title' ] . "</center>";
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
//商城名称
|
||||
if ($print_template[ 'head' ] == 1) {
|
||||
$content .= "<FH2><FS><center>" . $site_name . "</center></FS></FH2>";
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
|
||||
if (!empty($order_info[ 'pay_time' ])) {
|
||||
$content .= "订单时间:" . date("Y-m-d H:i", $order_info[ 'pay_time' ]) . "\n";
|
||||
} else {
|
||||
$content .= "订单时间:" . date("Y-m-d H:i", time()) . "\n";
|
||||
}
|
||||
$content .= "订单编号:" . $order_info[ 'order_no' ] . "\n";
|
||||
$content .= "支付方式:" . $order_info[ 'pay_type_name' ] . "\n";
|
||||
|
||||
switch ( $order_info[ 'order_type' ] ) {
|
||||
case 1 :
|
||||
// 物流订单
|
||||
break;
|
||||
case 2 :
|
||||
// 自提订单
|
||||
// if ($order_info[ 'buyer_ask_delivery_time' ] == 0) {
|
||||
// $buyer_ask_delivery_time_str = '立即自提';
|
||||
// } elseif (strpos($order_info[ 'buyer_ask_delivery_time' ], '-') !== false) {
|
||||
// $buyer_ask_delivery_time_str = $order_info[ 'buyer_ask_delivery_time' ];
|
||||
// } else {
|
||||
// $buyer_ask_delivery_time_str = date("H:i:s", $order_info[ 'buyer_ask_delivery_time' ]);
|
||||
// }
|
||||
$buyer_ask_delivery_time_str = $order_info[ 'buyer_ask_delivery_time' ];
|
||||
$content .= "要求自提时间:" . $buyer_ask_delivery_time_str . "\n";
|
||||
break;
|
||||
case 3 :
|
||||
// 外卖订单
|
||||
// if ($order_info[ 'buyer_ask_delivery_time' ] == 0) {
|
||||
// $buyer_ask_delivery_time_str = '立即送达';
|
||||
// } elseif (strpos($order_info[ 'buyer_ask_delivery_time' ], '-') !== false) {
|
||||
// $buyer_ask_delivery_time_str = $order_info[ 'buyer_ask_delivery_time' ];
|
||||
// } else {
|
||||
// $buyer_ask_delivery_time_str = date("H:i:s", $order_info[ 'buyer_ask_delivery_time' ]);
|
||||
// }
|
||||
$buyer_ask_delivery_time_str = $order_info[ 'buyer_ask_delivery_time' ];
|
||||
$content .= "要求送达时间:" . $buyer_ask_delivery_time_str . "\n";
|
||||
break;
|
||||
case 4 :
|
||||
// 虚拟订单
|
||||
break;
|
||||
case 5 :
|
||||
// 收银订单
|
||||
break;
|
||||
}
|
||||
|
||||
$content .= str_repeat('.', 32);
|
||||
$content .= "<table>";
|
||||
$content .= "<tr>";
|
||||
if ($print_template[ 'goods_price_show' ]) {
|
||||
$content .= "<td>商品名称</td><td></td><td>数量</td><td>金额</td>";
|
||||
} else {
|
||||
$content .= "<td>商品名称</td><td></td><td></td><td>数量</td>";
|
||||
}
|
||||
$content .= "</tr>";
|
||||
$content .= "</table>";
|
||||
$content .= str_repeat('.', 32);
|
||||
$content .= "<table>";
|
||||
foreach ($order_info[ 'order_goods' ] as $goods) {
|
||||
//显示售价或卖价
|
||||
$price = $print_template[ 'goods_price_type' ] == 'price' ? $goods[ 'price' ] : $goods[ 'real_goods_money' ];
|
||||
if ($print_template[ 'goods_price_show' ]) {
|
||||
$content .= "<tr><td>" . $goods[ 'sku_name' ] . "</td><td></td><td>x" . $goods[ 'num' ] . "</td><td>¥" . $price . "</td></tr>";
|
||||
} else {
|
||||
$content .= "<tr><td>" . $goods[ 'sku_name' ] . "</td><td></td><td></td><td>x" . $goods[ 'num' ] . "</td></tr>";
|
||||
}
|
||||
|
||||
//商品编码
|
||||
if ($print_template[ 'goods_code_show' ] && !empty($goods[ 'sku_no' ])) {
|
||||
$content .= "<tr><td>[" . $goods[ 'sku_no' ] . "]</td><td></td><td></td><td></td></tr>";
|
||||
}
|
||||
|
||||
}
|
||||
$content .= "</table>";
|
||||
$content .= str_repeat('.', 32);
|
||||
if ($order_info[ "goods_money" ] > 0) {
|
||||
$content .= "商品总额:¥" . $order_info[ "goods_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "coupon_money" ] > 0) {
|
||||
$content .= "店铺优惠券:¥" . $order_info[ "coupon_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "promotion_money" ] > 0) {
|
||||
$content .= "店铺优惠:¥" . $order_info[ "promotion_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "point_money" ] > 0) {
|
||||
$content .= "积分抵扣:¥" . $order_info[ "point_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "adjust_money" ] > 0) {
|
||||
$content .= "订单调价:¥" . $order_info[ "adjust_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ 'reduction' ] > 0) {
|
||||
$content .= "订单减免:¥" . $order_info[ "reduction" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "balance_money" ] > 0) {
|
||||
$content .= "余额抵扣:¥" . $order_info[ "balance_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "delivery_money" ] > 0) {
|
||||
$content .= "配送费用:¥" . $order_info[ "delivery_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "invoice_money" ] > 0) {
|
||||
$content .= "发票费用:¥" . $order_info[ "invoice_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "invoice_delivery_money" ] > 0) {
|
||||
$content .= "发票邮寄费用:¥" . $order_info[ "invoice_delivery_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "goods_num" ] > 0) {
|
||||
$content .= "订单共" . $order_info[ 'goods_num' ] . "件商品,总计: ¥" . $order_info[ 'order_money' ] . " \n";
|
||||
}
|
||||
$content .= str_repeat('.', 32);
|
||||
|
||||
/******************** 备注信息 **************************/
|
||||
//买家留言
|
||||
if ($print_template[ 'buy_notes' ] == 1) {
|
||||
$order_info[ "buyer_message" ] = $order_info[ "buyer_message" ] ? $order_info[ "buyer_message" ] : '无';
|
||||
$content .= "<FH2>买家留言:" . $order_info[ "buyer_message" ] . "</FH2>\n";
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
//卖家留言
|
||||
if ($print_template[ 'seller_notes' ] == 1) {
|
||||
$order_info[ "remark" ] = $order_info[ "remark" ] ? $order_info[ "remark" ] : '无';
|
||||
$content .= "<FH2>卖家留言:" . $order_info[ "remark" ] . "</FH2>\n";
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
|
||||
//表单
|
||||
if ($print_template[ 'form_show' ] == 1 && addon_is_exit('form')) {
|
||||
$form_info = model('form_data')->getInfo([ [ 'site_id', '=', $site_id ], [ 'scene', '=', 'order' ], [ 'relation_id', '=', $order_id ] ]);
|
||||
if (!empty($form_info) && !empty($form_info[ 'form_data' ])) {
|
||||
$form_data = json_decode($form_info[ 'form_data' ], true);
|
||||
foreach ($form_data as $item) {
|
||||
$content .= "<FH2>" . $item['value'][ 'title' ] . ":" . $item[ "val" ] . "</FH2>\n";
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************** 买家信息 **************************/
|
||||
if ($order_info[ 'member_id' ]) {
|
||||
$member_info = model('member')->getInfo([['member_id', '=', $order_info[ 'member_id' ]]]);
|
||||
//买家姓名
|
||||
if ($print_template[ 'buy_name' ] == 1) {
|
||||
if($order_info[ 'order_type' ] == 2){
|
||||
$content .= "" . $order_info[ "name" ] ?: $member_info[ "nickname" ] . "\n";
|
||||
}else{
|
||||
$content .= "" . $order_info[ "name" ] . "\n";
|
||||
}
|
||||
|
||||
}
|
||||
//联系方式
|
||||
if ($print_template[ 'buy_mobile' ] == 1) {
|
||||
if($order_info[ 'order_type' ] == 2){
|
||||
$content .= "" . $order_info[ "mobile" ] ?: $member_info[ "mobile" ] . "\n";
|
||||
}else{
|
||||
$content .= "" . $order_info[ "mobile" ] . "\n";
|
||||
}
|
||||
|
||||
}
|
||||
//地址
|
||||
if ($print_template[ 'buy_address' ] == 1) {
|
||||
if($order_info[ 'order_type' ] == 2){
|
||||
$content .= "自提门店:" . $order_info[ 'delivery_store_name' ] . "\n";
|
||||
}else{
|
||||
$content .= "" . $order_info[ 'full_address' ] . "-" . $order_info[ 'address' ] . "\n";
|
||||
}
|
||||
|
||||
}
|
||||
if ($print_template[ 'buy_name' ] == 1 || $print_template[ 'buy_mobile' ] == 1 || $print_template[ 'buy_address' ] == 1) {
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
}
|
||||
/******************** 商城信息 **************************/
|
||||
//联系方式
|
||||
if ($print_template[ 'shop_mobile' ] == 1) {
|
||||
$content .= "" . $shop_info[ "mobile" ] . "\n";
|
||||
}
|
||||
|
||||
//地址
|
||||
if ($print_template[ 'shop_address' ] == 1) {
|
||||
$content .= "" . $shop_info[ 'province_name' ] . $shop_info[ 'city_name' ] . $shop_info[ 'district_name' ] . $shop_info[ 'address' ] . "\n";
|
||||
}
|
||||
|
||||
if ($print_template[ 'shop_mobile' ] == 1 || $print_template[ 'shop_address' ] == 1) {
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
|
||||
//二维码
|
||||
if ($print_template[ 'shop_qrcode' ] == 1) {
|
||||
$content .= "<QR>" . $print_template[ 'qrcode_url' ] . "</QR>";
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
|
||||
/******************** 门店信息 **************************/
|
||||
if ($order_info[ 'store_id' ] > 0) {
|
||||
$store_info = ( new Store() )->getStoreInfo([ [ 'store_id', '=', $order_info[ 'store_id' ] ] ], 'store_name,telphone,full_address')[ 'data' ];
|
||||
$content .= "" . $order_info[ "store_name" ] . "\n";//门店名称
|
||||
$content .= "" . $store_info[ "telphone" ] . "\n";//门店电话
|
||||
$content .= "" . $store_info[ "full_address" ] . "\n";//门店地址
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
|
||||
//底部内容
|
||||
if (!empty($print_template[ 'bottom' ])) {
|
||||
$content .= "<center>" . $print_template[ 'bottom' ] . "</center>";
|
||||
}
|
||||
$array[ 'content' ] = $content;
|
||||
|
||||
$res_data[] = $array;
|
||||
}
|
||||
return $res_data;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
28
addon/printer/event/PrinterTemplate.php
Executable file
28
addon/printer/event/PrinterTemplate.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
use addon\printer\model\PrinterTemplate as PrinterTemplateModel;
|
||||
use app\Controller;
|
||||
|
||||
/**
|
||||
* 模板
|
||||
*/
|
||||
class PrinterTemplate extends Controller
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
$model = new PrinterTemplateModel();
|
||||
$action_type = $params[ 'action' ] ?? 'add';
|
||||
return $this->fetch($model->getTemplateType()[ $params[ 'type' ] ][ $action_type ]);
|
||||
}
|
||||
}
|
||||
27
addon/printer/event/PromotionType.php
Executable file
27
addon/printer/event/PromotionType.php
Executable file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
*/
|
||||
class PromotionType
|
||||
{
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return [ "name" => "小票打印", "type" => "printer" ];
|
||||
}
|
||||
}
|
||||
46
addon/printer/event/ShowPromotion.php
Executable file
46
addon/printer/event/ShowPromotion.php
Executable file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
/**
|
||||
* 活动展示
|
||||
*/
|
||||
class ShowPromotion
|
||||
{
|
||||
|
||||
/**
|
||||
* 活动展示
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$data = [
|
||||
'shop' => [
|
||||
[
|
||||
//插件名称
|
||||
'name' => 'printer',
|
||||
//店铺端展示分类 shop:营销活动 member:互动营销
|
||||
'show_type' => 'tool',
|
||||
//展示主题
|
||||
'title' => '小票打印',
|
||||
//展示介绍
|
||||
'description' => '客户下单自动打印订单小票',
|
||||
//展示图标
|
||||
'icon' => 'addon/printer/icon.png',
|
||||
//跳转链接
|
||||
'url' => 'printer://shop/printer/lists',
|
||||
]
|
||||
]
|
||||
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
25
addon/printer/event/UnInstall.php
Executable file
25
addon/printer/event/UnInstall.php
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
/**
|
||||
* 应用卸载
|
||||
*/
|
||||
class UnInstall
|
||||
{
|
||||
/**
|
||||
* 执行卸载
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return success();
|
||||
}
|
||||
}
|
||||
BIN
addon/printer/icon.png
Executable file
BIN
addon/printer/icon.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
295
addon/printer/model/Printer.php
Executable file
295
addon/printer/model/Printer.php
Executable file
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use addon\printer\data\sdk\yilianyun\api\PrinterService;
|
||||
use addon\printer\data\sdk\yilianyun\config\YlyConfig;
|
||||
use addon\printer\data\sdk\yilianyun\oauth\YlyOauthClient;
|
||||
use app\model\system\Config;
|
||||
|
||||
class Printer extends BaseModel
|
||||
{
|
||||
|
||||
private $brand = [
|
||||
// ['brand' => '365','name' => '365'],
|
||||
// ['brand' => 'feie','name' => '飞鹅'],
|
||||
[ 'brand' => 'yilianyun', 'name' => '易联云' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取打印机品牌
|
||||
* @return array
|
||||
*/
|
||||
public function getPrinterBrand()
|
||||
{
|
||||
return $this->brand;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加小票打印
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function addPrinter($data)
|
||||
{
|
||||
|
||||
model('printer')->startTrans();
|
||||
try {
|
||||
$data[ 'create_time' ] = time();
|
||||
$res = model('printer')->add($data);
|
||||
|
||||
//易联云
|
||||
if ($data[ 'printer_type' ] == 'cloud' && $data[ 'brand' ] == 'yilianyun') {
|
||||
$data[ 'printer_id' ] = $res;
|
||||
$result = $this->addPrinterYly($data);
|
||||
if ($result[ 'code' ] < 0) {
|
||||
model('printer')->rollback();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
model('printer')->commit();
|
||||
return $this->success($res);
|
||||
} catch (\Exception $e) {
|
||||
model('printer')->rollback();
|
||||
return $this->error('', '添加失败 ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑小票打印
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function editPrinter($data)
|
||||
{
|
||||
$data[ 'update_time' ] = time();
|
||||
$res = model('printer')->update($data, [ [ 'printer_id', '=', $data[ 'printer_id' ] ] ]);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function deletePrinter($condition)
|
||||
{
|
||||
model('printer')->startTrans();
|
||||
try {
|
||||
$printer_info = model('printer')->getInfo($condition, '*');
|
||||
|
||||
$res = model('printer')->delete($condition);
|
||||
//易联云
|
||||
if ($printer_info[ 'printer_type' ] == 'cloud' && $printer_info[ 'brand' ] == 'yilianyun') {
|
||||
$result = $this->deletePrinterYly($printer_info);
|
||||
if ($result[ 'code' ] < 0) {
|
||||
\think\facade\Log::write('删除打印机错误');
|
||||
\think\facade\Log::write($result);
|
||||
}
|
||||
}
|
||||
model('printer')->commit();
|
||||
return $this->success([$res,$result ?? null]);
|
||||
} catch (\Exception $e) {
|
||||
model('printer')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小票打印信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getPrinterInfo($condition = [], $field = '*')
|
||||
{
|
||||
$res = model('printer')->getInfo($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小票打印列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getPrinterList($condition = [], $field = '*', $order = '', $limit = null)
|
||||
{
|
||||
$list = model('printer')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小票打印分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getPrinterPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
|
||||
{
|
||||
$list = model('printer')->pageList($condition, $field, $order, $page, $page_size);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**************************************************** 打印机管理(第三方) *********************************************************/
|
||||
|
||||
/******************** 易联云 start ************************/
|
||||
|
||||
/**
|
||||
* 设置易联云配置
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function setYlyTokenConfig($data)
|
||||
{
|
||||
$config = new Config();
|
||||
$res = $config->setConfig($data, '易联云小票打印token', 1, [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'PRINTER_YLYTOKEN' ] ]);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取易联云配置
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function getYlyTokenConfig($site_id)
|
||||
{
|
||||
$config = new Config();
|
||||
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'PRINTER_YLYTOKEN' ] ]);
|
||||
if (empty($res[ 'data' ][ 'value' ])) {
|
||||
$res[ 'data' ][ 'value' ] = [
|
||||
'access_token' => '',
|
||||
'end_time' => '0'//token有效期
|
||||
];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取易联云token
|
||||
* @param $yly_config
|
||||
* @param $site_id
|
||||
* @param int $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function getYlyToken($yly_config, $site_id, $type = 0)
|
||||
{
|
||||
//token配置
|
||||
$config_data = $this->getYlyTokenConfig($site_id);
|
||||
$config = $config_data[ 'data' ][ 'value' ];
|
||||
|
||||
if ($config[ 'end_time' ] == 0 || $config[ 'end_time' ] < time() || $type == 1) {
|
||||
$client = new YlyOauthClient($yly_config);
|
||||
$token = $client->getToken(); //若是开放型应用请传授权码code
|
||||
$access_token = $token->access_token; //调用API凭证AccessToken
|
||||
|
||||
//更新token
|
||||
$expires_in = $token->expires_in;
|
||||
$end_time = time() + $expires_in;
|
||||
$token_data = [
|
||||
'site_id' => $site_id,
|
||||
'access_token' => $token->access_token,
|
||||
'end_time' => $end_time
|
||||
];
|
||||
$this->setYlyTokenConfig($token_data);
|
||||
} else {
|
||||
$access_token = $config[ 'access_token' ];
|
||||
}
|
||||
return $access_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加易联云打印机授权
|
||||
* @param $param
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function addPrinterYly($param)
|
||||
{
|
||||
$yly_config = new YlyConfig($param[ 'open_id' ], $param[ 'apikey' ]);
|
||||
|
||||
$access_token = $this->getYlyToken($yly_config, $param[ 'printer_id' ]);
|
||||
|
||||
//添加打印机
|
||||
$printer = new PrinterService($access_token, $yly_config);
|
||||
$data = $printer->addPrinter($param[ 'printer_code' ], $param[ 'printer_key' ], '', '');
|
||||
|
||||
if (isset($data->error) && $data->error == 0) {
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->error(object_to_array($data), '添加打印机错误');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除易联云打印机授权
|
||||
* @param $param
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function deletePrinterYly($param)
|
||||
{
|
||||
|
||||
$yly_config = new YlyConfig($param[ 'open_id' ], $param[ 'apikey' ]);
|
||||
$access_token = $this->getYlyToken($yly_config, $param[ 'printer_id' ]);
|
||||
|
||||
//添加打印机
|
||||
$printer = new PrinterService($access_token, $yly_config);
|
||||
$data = $printer->deletePrinter($param[ 'printer_code' ]);
|
||||
if (isset($data->error) && $data->error == 0) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error([], $data->error_description);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新获取易联云token
|
||||
* @param $site_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function refreshToken($printer_id, $site_id)
|
||||
{
|
||||
model('config')->startTrans();
|
||||
try {
|
||||
//token配置
|
||||
$printer_info = model('printer')->getInfo([ [ 'site_id', '=', $site_id ], [ 'printer_id', '=', $printer_id ] ], '*');
|
||||
$yly_config = new YlyConfig($printer_info[ 'open_id' ], $printer_info[ 'apikey' ]);
|
||||
$client = new YlyOauthClient($yly_config);
|
||||
|
||||
$token = $client->getToken(); // 若是开放型应用请传授权码code
|
||||
|
||||
//更新token
|
||||
$expires_in = $token->expires_in;
|
||||
$end_time = strtotime('+' . $expires_in / 86400 . 'day');
|
||||
$token_data = [
|
||||
'site_id' => $site_id,
|
||||
'access_token' => $token->access_token,
|
||||
'end_time' => $end_time
|
||||
];
|
||||
$this->setYlyTokenConfig($token_data);
|
||||
|
||||
model('config')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('config')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************** 易联云 end ************************/
|
||||
|
||||
}
|
||||
411
addon/printer/model/PrinterOrder.php
Executable file
411
addon/printer/model/PrinterOrder.php
Executable file
@@ -0,0 +1,411 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\model;
|
||||
|
||||
use addon\printer\data\sdk\yilianyun\api\PrintService;
|
||||
use addon\printer\data\sdk\yilianyun\config\YlyConfig;
|
||||
use app\model\BaseModel;
|
||||
use app\model\system\Site;
|
||||
|
||||
class PrinterOrder extends BaseModel
|
||||
{
|
||||
|
||||
/************************************************ 正式打印 start ******************************************************************/
|
||||
/**
|
||||
* 打印
|
||||
* @param $data
|
||||
* @return array|mixed|void
|
||||
*/
|
||||
public function printer($data)
|
||||
{
|
||||
$items = event('PrinterContent', $data, true);
|
||||
if (empty($items)) return $this->success();
|
||||
if (isset($items[ 'code' ]) && $items[ 'code' ] != 0) return $items;
|
||||
$printer_model = new Printer();
|
||||
foreach ($items as $k => $v) {
|
||||
$printer = $v[ 'printer_info' ] ?? [];
|
||||
|
||||
switch ($printer[ 'brand' ]) {
|
||||
case '365'://365打印机
|
||||
break;
|
||||
case 'feie'://飞鹅打印机
|
||||
break;
|
||||
case 'yilianyun'://易联云打印机
|
||||
try {
|
||||
$config = new YlyConfig($printer[ 'open_id' ], $printer[ 'apikey' ]);
|
||||
$access_token = $printer_model->getYlyToken($config, $printer[ 'printer_id' ]);
|
||||
$machine_code = $v[ 'printer_code' ];//商户授权机器码
|
||||
$origin_id = $v[ 'origin_id' ]; //内部订单号(32位以内)
|
||||
$print = new PrintService($access_token, $config);
|
||||
$content = $v[ 'content' ];
|
||||
$print->index($machine_code, $content, $origin_id, $printer);
|
||||
} catch (\Exception $e) {
|
||||
// return $this->error('', $e->getMessage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->success($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单打印
|
||||
*/
|
||||
public function printOrder($data)
|
||||
{
|
||||
|
||||
// //获取订单详情
|
||||
// $order_common_model = new OrderCommonModel();
|
||||
// $order_detail_result = $order_common_model->getOrderDetail($order_id);
|
||||
// $order_info = $order_detail_result['data'];
|
||||
//
|
||||
// if (empty($order_info)) {
|
||||
// return $this->success();
|
||||
// }
|
||||
//
|
||||
// //获取店铺信息
|
||||
// $shop_model = new Shop();
|
||||
// $shop = $shop_model->getShopInfo([['site_id', '=', $order_info['site_id']]]);
|
||||
// $shop_info = $shop['data'];
|
||||
//
|
||||
// //获取打印机列表
|
||||
// $print_model = new Printer();
|
||||
// $printer_data = $print_model->getPrinterList([['site_id', '=', $order_info['site_id']],['store_id','=',0]]);
|
||||
//
|
||||
// if($order_info['delivery_store_id'] == 0){
|
||||
// $store_printer_data['data'] = [];
|
||||
// }else{
|
||||
// $store_printer_data = $print_model->getPrinterList([['site_id', '=', $order_info['site_id']], ['order_type', 'like', '%,' . $order_info['order_type'] . ',%'],['store_id','=',$order_info['delivery_store_id']]]);
|
||||
// }
|
||||
// if (empty($printer_data['data']) && empty($store_printer_data['data'])) {
|
||||
// return $this->success();
|
||||
// }
|
||||
//
|
||||
// $printer_list = array_merge($printer_data['data'],$store_printer_data['data']);
|
||||
// foreach ($printer_list as $v) {
|
||||
//
|
||||
// switch ($v['brand']) {
|
||||
//
|
||||
// case '365'://365打印机
|
||||
//
|
||||
// break;
|
||||
// case 'feie'://飞鹅打印机
|
||||
//
|
||||
// break;
|
||||
// case 'yilianyun'://易联云打印机
|
||||
//
|
||||
// $this->Ylyprint($order_info, $v, $shop_info);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 【测试】易联云打印
|
||||
* @param $order_info
|
||||
* @param $printer
|
||||
* @param $shop_info
|
||||
*/
|
||||
public function Ylyprint($order_info, $printer, $shop_info)
|
||||
{
|
||||
//打印模板
|
||||
$print_template_model = new PrinterTemplate();
|
||||
$print_template = $print_template_model->getPrinterTemplateInfo([ [ 'template_id', '=', $printer[ 'template_id' ] ] ])[ 'data' ];
|
||||
|
||||
$config = new YlyConfig($printer[ 'open_id' ], $printer[ 'apikey' ]);
|
||||
$printer_model = new Printer();
|
||||
$access_token = $printer_model->getYlyToken($config, $printer[ 'printer_id' ]);
|
||||
$machine_code = $printer[ 'printer_code' ]; //商户授权机器码
|
||||
$origin_id = $order_info[ 'order_no' ]; //内部订单号(32位以内)
|
||||
|
||||
$site_name = ( new Site() )->getSiteInfo([ [ 'site_id', '=', $printer[ 'site_id' ] ] ], 'site_name')[ 'data' ][ 'site_name' ] ?? '';
|
||||
|
||||
/**文本接口开始**/
|
||||
$print = new PrintService($access_token, $config);
|
||||
$content = "<MN>" . $printer[ 'print_num' ] . "</MN>";
|
||||
//小票名称
|
||||
if ($print_template[ 'title' ] != '') {
|
||||
$content .= "<center>" . $print_template[ 'title' ] . "</center>";
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
//商城名称
|
||||
if ($print_template[ 'head' ] == 1) {
|
||||
$content .= "<FH2><FS><center>" . $site_name . "</center></FS></FH2>";
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
if (!empty($order_info[ 'pay_time' ])) {
|
||||
$content .= "订单时间:" . date("Y-m-d H:i", $order_info[ 'pay_time' ]) . "\n";
|
||||
} else {
|
||||
$content .= "订单时间:" . date("Y-m-d H:i", time()) . "\n";
|
||||
}
|
||||
$content .= "订单编号:" . $order_info[ 'order_no' ] . "\n";
|
||||
|
||||
$content .= str_repeat('.', 32);
|
||||
$content .= "<table>";
|
||||
$content .= "<tr><td>商品名称</td><td></td><td>数量</td><td>金额</td></tr>";
|
||||
$content .= "</table>";
|
||||
$content .= str_repeat('.', 32);
|
||||
$content .= "<table>";
|
||||
foreach ($order_info[ 'order_goods' ] as $goods) {
|
||||
|
||||
$sku_name_list = $this->r_str_pad_1($goods[ 'sku_name' ], 7);
|
||||
foreach ($sku_name_list as $index => $value) {
|
||||
if ($index == 0) {
|
||||
$content .= "<tr><td>" . $value . "</td><td></td><td>x" . numberFormat($goods[ 'num' ]) . "</td><td>¥" . $goods[ 'price' ] . "</td></tr>";
|
||||
} else {
|
||||
$content .= "<tr><td>" . $value . "</td></tr>";
|
||||
}
|
||||
}
|
||||
}
|
||||
$content .= "</table>";
|
||||
$content .= str_repeat('.', 32);
|
||||
if ($order_info[ "goods_money" ] > 0) {
|
||||
$content .= "商品总额:¥" . $order_info[ "goods_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "coupon_money" ] > 0) {
|
||||
$content .= "店铺优惠券:¥" . $order_info[ "coupon_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "promotion_money" ] > 0) {
|
||||
$content .= "店铺优惠:¥" . $order_info[ "promotion_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "point_money" ] > 0) {
|
||||
$content .= "积分抵扣:¥" . $order_info[ "point_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "adjust_money" ] > 0) {
|
||||
$content .= "订单调价:¥" . $order_info[ "adjust_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ 'reduction' ] > 0) {
|
||||
$content .= "订单减免:¥" . $order_info[ "reduction" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "balance_money" ] > 0) {
|
||||
$content .= "余额抵扣:¥" . $order_info[ "balance_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "delivery_money" ] > 0) {
|
||||
$content .= "配送费用:¥" . $order_info[ "delivery_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "invoice_money" ] > 0) {
|
||||
$content .= "发票费用:¥" . $order_info[ "invoice_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "invoice_delivery_money" ] > 0) {
|
||||
$content .= "发票邮寄费用:¥" . $order_info[ "invoice_delivery_money" ] . "\n";
|
||||
}
|
||||
if ($order_info[ "goods_num" ] > 0) {
|
||||
$content .= "订单共" . numberFormat($order_info[ 'goods_num' ]) . "件商品,总计: ¥" . $order_info[ 'order_money' ] . " \n";
|
||||
}
|
||||
$content .= str_repeat('.', 32);
|
||||
|
||||
/******************** 备注信息 **************************/
|
||||
//买家留言
|
||||
if ($print_template[ 'buy_notes' ] == 1) {
|
||||
$content .= "<FH2>买家留言:" . $order_info[ "buyer_message" ] . "</FH2>\n";
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
//卖家留言
|
||||
if ($print_template[ 'seller_notes' ] == 1) {
|
||||
$content .= "<FH2>卖家留言:" . $order_info[ "remark" ] . "</FH2>\n";
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
|
||||
/******************** 买家信息 **************************/
|
||||
//买家姓名
|
||||
if ($print_template[ 'buy_name' ] == 1) {
|
||||
$content .= "" . $order_info[ "name" ] . "\n";
|
||||
}
|
||||
//联系方式
|
||||
if ($print_template[ 'buy_mobile' ] == 1) {
|
||||
$content .= "" . $order_info[ "mobile" ] . "\n";
|
||||
}
|
||||
//地址
|
||||
if ($print_template[ 'buy_address' ] == 1) {
|
||||
$content .= "" . $order_info[ 'full_address' ] . "-" . $order_info[ 'address' ] . "\n";
|
||||
}
|
||||
if ($print_template[ 'buy_name' ] == 1 || $print_template[ 'buy_mobile' ] == 1 || $print_template[ 'buy_address' ] == 1) {
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
/******************** 商城信息 **************************/
|
||||
//联系方式
|
||||
if ($print_template[ 'shop_mobile' ] == 1) {
|
||||
$content .= "" . $shop_info[ "mobile" ] . "\n";
|
||||
}
|
||||
//地址
|
||||
if ($print_template[ 'shop_address' ] == 1) {
|
||||
|
||||
$content .= "" . $shop_info[ 'province_name' ] . $shop_info[ 'city_name' ] . $shop_info[ 'district_name' ] . $shop_info[ 'address' ] . "\n";
|
||||
}
|
||||
if ($print_template[ 'shop_mobile' ] == 1 || $print_template[ 'shop_address' ] == 1) {
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
//二维码
|
||||
if ($print_template[ 'shop_qrcode' ] == 1) {
|
||||
$content .= "<QR>" . $print_template[ 'qrcode_url' ] . "</QR>";
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
|
||||
/******************** 门店信息 **************************/
|
||||
if ($order_info[ 'delivery_store_id' ] > 0 && !empty($order_info[ 'delivery_store_name' ]) && !empty($order_info[ 'delivery_store_info' ])) {
|
||||
$store_info = json_decode($order_info[ 'delivery_store_info' ], true);
|
||||
|
||||
$content .= "" . $order_info[ "delivery_store_name" ] . "\n";//门店名称
|
||||
$content .= "" . $store_info[ "telphone" ] . "\n";//门店电话
|
||||
$content .= "" . $store_info[ "full_address" ] . "\n";//门店地址
|
||||
$content .= str_repeat('.', 32);
|
||||
}
|
||||
|
||||
//底部内容
|
||||
if (!empty($print_template[ 'bottom' ])) {
|
||||
$content .= "<center>" . $print_template[ 'bottom' ] . "</center>";
|
||||
}
|
||||
|
||||
try {
|
||||
$print->index($machine_code, $content, $origin_id, $printer);
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 补齐空格,每n个中文字符长度为一个数组元素
|
||||
* @param $input
|
||||
* @param int $n
|
||||
* @return array
|
||||
*/
|
||||
public function r_str_pad_1($input, $n = 7)
|
||||
{
|
||||
$string = "";
|
||||
$count = 0;
|
||||
$c_count = 0;
|
||||
$arr = array();
|
||||
for ($i = 0; $i < mb_strlen($input, 'UTF-8'); $i++) {
|
||||
$char = mb_substr($input, $i, 1, 'UTF-8');
|
||||
$string .= $char;
|
||||
if (strlen($char) == 3) {
|
||||
$count += 2;
|
||||
$c_count++;
|
||||
} else {
|
||||
$count += 1;
|
||||
}
|
||||
if ($count >= $n * 2) {
|
||||
$arr[] = $string;
|
||||
$string = '';
|
||||
$count = 0;
|
||||
$c_count = 0;
|
||||
}
|
||||
}
|
||||
if ($count < $n * 2) {
|
||||
$string = str_pad($string, $n * 2 + $c_count);
|
||||
$arr[] = $string;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/************************************************ 正式打印 end ******************************************************************/
|
||||
|
||||
|
||||
/************************************************ 测试打印 start ******************************************************************/
|
||||
|
||||
/**
|
||||
* 测试打印
|
||||
* @param $printer_id
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function testPrint($printer_id, $site_id)
|
||||
{
|
||||
//获取打印机列表
|
||||
$printer_info = model('printer')->getInfo([ [ 'site_id', '=', $site_id ], [ 'printer_id', '=', $printer_id ] ]);
|
||||
if (empty($printer_info)) {
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
switch ($printer_info[ 'brand' ]) {
|
||||
case '365':
|
||||
// 365打印机
|
||||
break;
|
||||
case 'feie':
|
||||
// 飞鹅打印机
|
||||
break;
|
||||
case 'yilianyun':
|
||||
// 易联云打印机
|
||||
$res = $this->testYlyprint($printer_info);
|
||||
break;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试打印
|
||||
* @param $printer
|
||||
* @return array
|
||||
*/
|
||||
public function testYlyprint($printer)
|
||||
{
|
||||
$config = new YlyConfig($printer[ 'open_id' ], $printer[ 'apikey' ]);
|
||||
|
||||
$printer_model = new Printer();
|
||||
$access_token = $printer_model->getYlyToken($config, $printer[ 'printer_id' ]);
|
||||
$machine_code = $printer[ 'printer_code' ]; //商户授权机器码
|
||||
$origin_id = date('YmdHis') . rand(1, 999); //内部订单号(32位以内)
|
||||
|
||||
/**文本接口开始**/
|
||||
$print = new PrintService($access_token, $config);
|
||||
|
||||
$content = "<MN>" . $printer[ 'print_num' ] . "</MN>";
|
||||
|
||||
$content .= "<center>小票名称</center>";
|
||||
$content .= str_repeat('.', 32);
|
||||
$content .= "<FH2><FS><center>商城名称</center></FS></FH2>";
|
||||
$content .= str_repeat('.', 32);
|
||||
|
||||
$content .= "订单时间:" . date("Y-m-d H:i") . "\n";
|
||||
$content .= "订单编号:" . $origin_id . "\n";
|
||||
|
||||
$content .= str_repeat('.', 32);
|
||||
$content .= "<table>";
|
||||
$content .= "<tr><td>商品名称</td><td></td><td>数量</td><td>金额</td></tr>";
|
||||
$content .= "</table>";
|
||||
$content .= str_repeat('.', 32);
|
||||
|
||||
$content .= "<table>";
|
||||
$content .= "<tr><td>烤土豆(超级辣)</td><td></td><td>x3</td><td>5</td></tr>";
|
||||
$content .= "<tr><td>烤豆干(超级辣)</td><td></td><td>x2</td><td>10</td></tr>";
|
||||
$content .= "<tr><td>烤鸡翅(超级辣)</td><td></td><td>x3</td><td>15</td></tr>";
|
||||
$content .= "</table>";
|
||||
$content .= str_repeat('.', 32);
|
||||
|
||||
$content .= "商品总额:¥30 \n";
|
||||
$content .= "订单共8件商品,总计: ¥30 \n";
|
||||
$content .= str_repeat('.', 32);
|
||||
|
||||
/******************** 备注信息 **************************/
|
||||
//买家留言
|
||||
|
||||
$content .= "<FH2>买家留言:微辣,多放孜然</FH2>\n";
|
||||
$content .= str_repeat('.', 32);
|
||||
|
||||
$content .= "<center>谢谢惠顾,欢迎下次光临</center>";
|
||||
|
||||
try {
|
||||
|
||||
$res = $print->index($machine_code, $content, $origin_id, $printer);
|
||||
if ($res->error == 0) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', $res->error_description);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
114
addon/printer/model/PrinterTemplate.php
Executable file
114
addon/printer/model/PrinterTemplate.php
Executable file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
|
||||
class PrinterTemplate extends BaseModel
|
||||
{
|
||||
public $type = [
|
||||
'goodsorder' => [
|
||||
'type' => 'goodsorder',
|
||||
'type_name' => '商品订单',
|
||||
'edit' => 'addon/printer/shop/view/template/goodsorder_template.html',
|
||||
'add' => 'addon/printer/shop/view/template/goodsorder_template.html',
|
||||
]
|
||||
];
|
||||
|
||||
public function getTemplateType()
|
||||
{
|
||||
$type = $this->type;
|
||||
$other_type = event('PrinterTemplateType', []);
|
||||
foreach ($other_type as $k => $v) {
|
||||
foreach ($v as $val) {
|
||||
$type[ $val[ 'type' ] ] = $val;
|
||||
}
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加打印模板
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function addPrinterTemplate($data)
|
||||
{
|
||||
$data[ 'create_time' ] = time();
|
||||
$res = model('printer_template')->add($data);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑打印模板
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function editPrinterTemplate($data)
|
||||
{
|
||||
$data[ 'update_time' ] = time();
|
||||
$res = model('printer_template')->update($data, [ [ 'template_id', '=', $data[ 'template_id' ] ] ]);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function deletePrinterTemplate($condition)
|
||||
{
|
||||
$res = model('printer_template')->delete($condition);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取打印模板信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getPrinterTemplateInfo($condition = [], $field = '*')
|
||||
{
|
||||
$res = model('printer_template')->getInfo($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取打印模板列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getPrinterTemplateList($condition = [], $field = '*', $order = '', $limit = null)
|
||||
{
|
||||
$list = model('printer_template')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取打印模板分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getPrinterTemplatePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
|
||||
{
|
||||
$list = model('printer_template')->pageList($condition, $field, $order, $page, $page_size);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
}
|
||||
27
addon/printer/shop/controller/BaseController.php
Executable file
27
addon/printer/shop/controller/BaseController.php
Executable file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\shop\controller;
|
||||
|
||||
use app\shop\controller\BaseShop;
|
||||
|
||||
class BaseController extends BaseShop
|
||||
{
|
||||
|
||||
public function fetch($template = '', $replace = [], $config = [])
|
||||
{
|
||||
$config = array_merge($config, [
|
||||
'SHOP_ADDON_CSS' => __ROOT__ . '/addon/printer/shop/view/public/css',
|
||||
'SHOP_ADDON_IMG' => __ROOT__ . '/addon/printer/shop/view/public/img',
|
||||
'SHOP_ADDON_JS' => __ROOT__ . '/addon/printer/shop/view/public/js',
|
||||
]);
|
||||
return parent::fetch($template, $replace, $config);
|
||||
}
|
||||
}
|
||||
269
addon/printer/shop/controller/Printer.php
Executable file
269
addon/printer/shop/controller/Printer.php
Executable file
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\shop\controller;
|
||||
|
||||
use addon\printer\model\PrinterOrder;
|
||||
use app\model\store\Store;
|
||||
use addon\printer\model\PrinterTemplate;
|
||||
use addon\printer\model\Printer as PrinterModel;
|
||||
use app\model\order\OrderCommon as OrderCommonModel;
|
||||
|
||||
class Printer extends BaseController
|
||||
{
|
||||
|
||||
/*
|
||||
* 小票打印列表
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
$model = new PrinterModel();
|
||||
|
||||
if (request()->isJson()) {
|
||||
$condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
$page = input('page', 1);
|
||||
$page_size = input('page_size', PAGE_LIST_ROWS);
|
||||
$list = $model->getPrinterPageList($condition, $page, $page_size, 'printer_id desc');
|
||||
return $list;
|
||||
}
|
||||
return $this->fetch("printer/lists");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加小票打印
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$model = new PrinterModel();
|
||||
if (request()->isJson()) {
|
||||
$data = [
|
||||
'site_id' => $this->site_id,
|
||||
'printer_name' => input('printer_name', ''),
|
||||
'brand' => input('brand', ''),
|
||||
'printer_code' => input('printer_code', ''),
|
||||
'printer_key' => input('printer_key', ''),
|
||||
'open_id' => input('open_id', ''),
|
||||
'apikey' => input('apikey', ''),
|
||||
'store_id' => input('store_id', ''),
|
||||
'printer_type' => input('printer_type', ''),
|
||||
|
||||
//订单
|
||||
'order_pay_open' => input('order_pay_open', 0),
|
||||
'order_pay_template_id' => input('order_pay_template_id', 0),
|
||||
'order_pay_print_num' => input('order_pay_print_num', 1),
|
||||
'order_pay_order_type' => input('order_pay_order_type', ''),
|
||||
|
||||
'take_delivery_open' => input('take_delivery_open', 0),
|
||||
'take_delivery_template_id' => input('take_delivery_template_id', 0),
|
||||
'take_delivery_print_num' => input('take_delivery_print_num', 1),
|
||||
'take_delivery_order_type' => input('take_delivery_order_type', ''),
|
||||
|
||||
'manual_open' => input('manual_open', 0),
|
||||
'template_id' => input('template_id', 0),
|
||||
'print_num' => input('print_num', 1),
|
||||
|
||||
//充值
|
||||
'recharge_open' => input('recharge_open', 0),
|
||||
'recharge_template_id' => input('recharge_template_id', 0),
|
||||
'recharge_print_num' => input('recharge_print_num', 1),
|
||||
|
||||
'change_shifts_open' => input('change_shifts_open', 0),
|
||||
'change_shifts_template_id' => input('change_shifts_template_id', 0),
|
||||
'change_shifts_print_num' => input('change_shifts_print_num', 1),
|
||||
|
||||
'host' => input('host', ''),
|
||||
'ip' => input('ip', ''),
|
||||
'port' => input('port', ''),
|
||||
'print_width' => input('print_width', '58mm')
|
||||
|
||||
];
|
||||
if ($data[ 'order_pay_order_type' ]) $data[ 'order_pay_order_type' ] = ',' . $data[ 'order_pay_order_type' ] . ',';
|
||||
if ($data[ 'take_delivery_order_type' ]) $data[ 'take_delivery_order_type' ] = ',' . $data[ 'take_delivery_order_type' ] . ',';
|
||||
return $model->addPrinter($data);
|
||||
|
||||
} else {
|
||||
//模板列表
|
||||
$template_model = new PrinterTemplate();
|
||||
$condition = [
|
||||
[ 'site_id', '=', $this->site_id ],
|
||||
];
|
||||
$template_list = $template_model->getPrinterTemplateList($condition, 'template_id,template_name,type', 'template_id desc');
|
||||
$this->assign('template_list', $template_list[ 'data' ]);
|
||||
|
||||
//打印机品牌
|
||||
$brand = $model->getPrinterBrand();
|
||||
$this->assign('brand', $brand);
|
||||
|
||||
//订单类型
|
||||
$order_common_model = new OrderCommonModel();
|
||||
$order_type_list = $order_common_model->getOrderTypeStatusList();
|
||||
unset($order_type_list[ 'all' ]);
|
||||
$this->assign("order_type_list", $order_type_list);
|
||||
|
||||
$is_exit_store = addon_is_exit('store');
|
||||
if ($is_exit_store == 1) {
|
||||
$store_model = new Store();
|
||||
$store_field = 'store_id,store_name';
|
||||
$store_list = $store_model->getStoreList([ [ 'site_id', '=', $this->site_id ] ], $store_field);
|
||||
$this->assign('store_list', $store_list[ 'data' ]);
|
||||
}
|
||||
$this->assign('is_exit_store', $is_exit_store);
|
||||
return $this->fetch("printer/add");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑小票打印
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$model = new PrinterModel();
|
||||
$printer_id = input('printer_id', 0);
|
||||
if (request()->isJson()) {
|
||||
$data = [
|
||||
'printer_id' => $printer_id,
|
||||
|
||||
'site_id' => $this->site_id,
|
||||
'printer_name' => input('printer_name', ''),
|
||||
'brand' => input('brand', ''),
|
||||
'printer_code' => input('printer_code', ''),
|
||||
'printer_key' => input('printer_key', ''),
|
||||
'open_id' => input('open_id', ''),
|
||||
'apikey' => input('apikey', ''),
|
||||
'store_id' => input('store_id', ''),
|
||||
'printer_type' => input('printer_type', ''),
|
||||
|
||||
//订单
|
||||
'order_pay_open' => input('order_pay_open', 0),
|
||||
'order_pay_template_id' => input('order_pay_template_id', 0),
|
||||
'order_pay_print_num' => input('order_pay_print_num', 1),
|
||||
'order_pay_order_type' => input('order_pay_order_type', ''),
|
||||
|
||||
'take_delivery_open' => input('take_delivery_open', 0),
|
||||
'take_delivery_template_id' => input('take_delivery_template_id', 0),
|
||||
'take_delivery_print_num' => input('take_delivery_print_num', 1),
|
||||
'take_delivery_order_type' => input('take_delivery_order_type', ''),
|
||||
|
||||
'manual_open' => input('manual_open', 0),
|
||||
'template_id' => input('template_id', 0),
|
||||
'print_num' => input('print_num', 1),
|
||||
|
||||
//充值
|
||||
'recharge_open' => input('recharge_open', 0),
|
||||
'recharge_template_id' => input('recharge_template_id', 0),
|
||||
'recharge_print_num' => input('recharge_print_num', 1),
|
||||
|
||||
'change_shifts_open' => input('change_shifts_open', 0),
|
||||
'change_shifts_template_id' => input('change_shifts_template_id', 0),
|
||||
'change_shifts_print_num' => input('change_shifts_print_num', 1),
|
||||
|
||||
'host' => input('host', ''),
|
||||
'ip' => input('ip', ''),
|
||||
'port' => input('port', ''),
|
||||
'print_width' => input('print_width', '58mm')
|
||||
];
|
||||
|
||||
if ($data[ 'order_pay_order_type' ]) $data[ 'order_pay_order_type' ] = ',' . $data[ 'order_pay_order_type' ] . ',';
|
||||
if ($data[ 'take_delivery_order_type' ]) $data[ 'take_delivery_order_type' ] = ',' . $data[ 'take_delivery_order_type' ] . ',';
|
||||
|
||||
return $model->editPrinter($data);
|
||||
} else {
|
||||
|
||||
$info = $model->getPrinterInfo([ [ 'printer_id', '=', $printer_id ], [ 'site_id', '=', $this->site_id ] ]);
|
||||
$info[ 'data' ][ 'take_delivery_order_type' ] = explode(',', $info[ 'data' ][ 'take_delivery_order_type' ]);
|
||||
$info[ 'data' ][ 'order_pay_order_type' ] = explode(',', $info[ 'data' ][ 'order_pay_order_type' ]);
|
||||
$this->assign('printer_info', $info[ 'data' ]);
|
||||
|
||||
//模板列表
|
||||
$template_model = new PrinterTemplate();
|
||||
$condition = [
|
||||
[ 'site_id', '=', $this->site_id ],
|
||||
];
|
||||
$template_list = $template_model->getPrinterTemplateList($condition, 'template_id,template_name,type', 'template_id desc');
|
||||
$this->assign('template_list', $template_list[ 'data' ]);
|
||||
|
||||
//打印机品牌
|
||||
$brand = $model->getPrinterBrand();
|
||||
$this->assign('brand', $brand);
|
||||
|
||||
//订单类型
|
||||
$order_common_model = new OrderCommonModel();
|
||||
$order_type_list = $order_common_model->getOrderTypeStatusList();
|
||||
unset($order_type_list[ 'all' ]);
|
||||
$this->assign("order_type_list", $order_type_list);
|
||||
|
||||
//是否存在门店
|
||||
$is_exit_store = addon_is_exit('store');
|
||||
if ($is_exit_store == 1) {
|
||||
$store_model = new Store();
|
||||
$store_field = 'store_id,store_name';
|
||||
$store_list = $store_model->getStoreList([ [ 'site_id', '=', $this->site_id ] ], $store_field);
|
||||
$this->assign('store_list', $store_list[ 'data' ]);
|
||||
}
|
||||
$this->assign('is_exit_store', $is_exit_store);
|
||||
return $this->fetch("printer/edit");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 删除
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$printer_id = input('printer_id', '');
|
||||
|
||||
$printer_model = new PrinterModel();
|
||||
return $printer_model->deletePrinter([ [ 'printer_id', '=', $printer_id ], [ 'site_id', '=', $this->site_id ] ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试打印
|
||||
*/
|
||||
public function testPrint()
|
||||
{
|
||||
$printer_id = input('printer_id', '');
|
||||
$print_model = new PrinterOrder();
|
||||
$res = $print_model->testPrint($printer_id, $this->site_id);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新token
|
||||
*/
|
||||
public function refreshToken()
|
||||
{
|
||||
$printer_id = input('printer_id', '');
|
||||
$print_model = new PrinterModel();
|
||||
$res = $print_model->refreshToken($printer_id, $this->site_id);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试打印
|
||||
*/
|
||||
public function test()
|
||||
{
|
||||
// $print_model = new PrinterOrder();
|
||||
// $res = $print_model->printer([
|
||||
//// 'order_id' => '5630',
|
||||
//// 'type' => 'goodsorder',
|
||||
//// 'printer_type' => 'order_pay',
|
||||
//// 'site_id' => $this->site_id
|
||||
// 'order_id' => '32',
|
||||
// 'type' => 'recharge',
|
||||
// 'site_id' => $this->site_id
|
||||
// ]);
|
||||
// return $res;
|
||||
$res = event('MemberRechargeOrderPayPrinter', [
|
||||
'relate_id' => 66
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
134
addon/printer/shop/controller/Template.php
Executable file
134
addon/printer/shop/controller/Template.php
Executable file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\shop\controller;
|
||||
|
||||
use app\shop\controller\BaseShop;
|
||||
use addon\printer\model\PrinterTemplate;
|
||||
|
||||
class Template extends BaseShop
|
||||
{
|
||||
|
||||
/*
|
||||
* 模板管理列表
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
$model = new PrinterTemplate();
|
||||
|
||||
if (request()->isJson()) {
|
||||
$condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
$page = input('page', 1);
|
||||
$page_size = input('page_size', PAGE_LIST_ROWS);
|
||||
$list = $model->getPrinterTemplatePageList($condition, $page, $page_size, 'template_id desc');
|
||||
return $list;
|
||||
}
|
||||
return $this->fetch("template/lists");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加模板管理
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$model = new PrinterTemplate();
|
||||
|
||||
$type = input('type', 'goodsorder');
|
||||
if (request()->isJson()) {
|
||||
$data = [
|
||||
'site_id' => $this->site_id,
|
||||
'site_name' => $this->shop_info[ 'site_name' ],
|
||||
'template_type' => input('template_type', ''),
|
||||
'template_name' => input('template_name', ''),
|
||||
|
||||
'title' => input('title', ''),
|
||||
'head' => input('head', ''),
|
||||
'buy_notes' => input('buy_notes', ''),
|
||||
'seller_notes' => input('seller_notes', ''),
|
||||
'buy_name' => input('buy_name', ''),
|
||||
'buy_mobile' => input('buy_mobile', ''),
|
||||
'buy_address' => input('buy_address', ''),
|
||||
'shop_mobile' => input('shop_mobile', ''),
|
||||
'shop_address' => input('shop_address', ''),
|
||||
'shop_qrcode' => input('shop_qrcode', ''),
|
||||
'qrcode_url' => input('qrcode_url', ''),
|
||||
'bottom' => input('bottom', ''),
|
||||
|
||||
'type' => input('type', ''),
|
||||
'type_name' => input('type_name', ''),
|
||||
'goods_price_show' => input('goods_price_show', 0),
|
||||
'goods_code_show' => input('goods_code_show', 0),
|
||||
'form_show' => input('form_show', 0),
|
||||
'goods_price_type' => input('goods_price_type', ''),
|
||||
];
|
||||
|
||||
return $model->addPrinterTemplate($data);
|
||||
} else {
|
||||
$this->assign('template_type', $model->getTemplateType());
|
||||
$this->assign('type', $type);
|
||||
return event('PrinterTemplate', [ 'type' => $type, 'action' => 'add' ], true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑模板管理
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$model = new PrinterTemplate();
|
||||
$template_id = input('template_id', 0);
|
||||
if (request()->isJson()) {
|
||||
$data = [
|
||||
'template_id' => $template_id,
|
||||
'site_id' => $this->site_id,
|
||||
'template_type' => input('template_type', ''),
|
||||
'template_name' => input('template_name', ''),
|
||||
|
||||
'title' => input('title', ''),
|
||||
'head' => input('head', ''),
|
||||
'buy_notes' => input('buy_notes', ''),
|
||||
'seller_notes' => input('seller_notes', ''),
|
||||
'buy_name' => input('buy_name', ''),
|
||||
'buy_mobile' => input('buy_mobile', ''),
|
||||
'buy_address' => input('buy_address', ''),
|
||||
'shop_mobile' => input('shop_mobile', ''),
|
||||
'shop_address' => input('shop_address', ''),
|
||||
'shop_qrcode' => input('shop_qrcode', ''),
|
||||
'qrcode_url' => input('qrcode_url', ''),
|
||||
'bottom' => input('bottom', ''),
|
||||
|
||||
'goods_price_show' => input('goods_price_show', 0),
|
||||
'goods_code_show' => input('goods_code_show', 0),
|
||||
'form_show' => input('form_show', 0),
|
||||
'goods_price_type' => input('goods_price_type', ''),
|
||||
|
||||
];
|
||||
return $model->editPrinterTemplate($data);
|
||||
|
||||
} else {
|
||||
$info = $model->getPrinterTemplateInfo([ [ 'template_id', '=', $template_id ], [ 'site_id', '=', $this->site_id ] ]);
|
||||
$this->assign('info', $info[ 'data' ]);
|
||||
|
||||
return event('PrinterTemplate', [ 'type' => $info[ 'data' ][ 'type' ], 'action' => 'edit' ], true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 删除
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$template_id = input('template_id', '');
|
||||
|
||||
$printer_model = new PrinterTemplate();
|
||||
return $printer_model->deletePrinterTemplate([ [ 'template_id', '=', $template_id ], [ 'site_id', '=', $this->site_id ] ]);
|
||||
}
|
||||
|
||||
}
|
||||
290
addon/printer/shop/view/printer/add.html
Executable file
290
addon/printer/shop/view/printer/add.html
Executable file
@@ -0,0 +1,290 @@
|
||||
<div class="layui-collapse tips-wrap">
|
||||
<div class="layui-colla-item">
|
||||
<h2 class="layui-colla-title">操作提示</h2>
|
||||
<ul class="layui-colla-content layui-show">
|
||||
<li>易联云的打印机请购买k6、k4、w1系列的打印机</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form form-wrap">
|
||||
|
||||
<div class="layui-card card-common card-brief">
|
||||
<div class="layui-card-header">
|
||||
<span class="card-title">打印机设置</span>
|
||||
</div>
|
||||
<div class="layui-card-body">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机名称:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="printer_name" lay-verify="required" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机类型:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="printer_type" value="cloud" lay-verify="required" checked title="云打印机" lay-filter="printer_type">
|
||||
<input type="radio" name="printer_type" value="local" lay-verify="required" title="本地打印机" lay-filter="printer_type">
|
||||
<!-- <input type="radio" name="printer_type" value="network" lay-verify="required" title="网络打印机" lay-filter="printer_type">-->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="printer-type cloud" style="display:block;">
|
||||
<div class="layui-form-item express_company">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机品牌:</label>
|
||||
<div class="layui-input-block len-mid">
|
||||
<select name="brand" lay-verify="cloudRequired" lay-filter="brand">
|
||||
{foreach $brand as $k=>$v}
|
||||
<option value="{$v.brand}">{$v.name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机编号:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="printer_code" lay-verify="cloudRequired" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机秘钥:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="printer_key" lay-verify="cloudRequired" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 飞鹅打印机 -->
|
||||
<div class="layui-form-item feie">
|
||||
<label class="layui-form-label"><span class="required">*</span>USER:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="user" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
<p>飞鹅云后台注册用户名</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item feie">
|
||||
<label class="layui-form-label"><span class="required">*</span>UKEY:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="ukey" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
<p>飞鹅云后台登录生成的UKEY</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 易联云打印机 -->
|
||||
<div class="layui-form-item yilianyun">
|
||||
<label class="layui-form-label"><span class="required">*</span>应用id:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="open_id" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
<p>应用id(易联云-开发者中心后台应用中心里获取)</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item yilianyun">
|
||||
<label class="layui-form-label"><span class="required">*</span>apiKey:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="apikey" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
<p>apiKey(易联云-开发者中心后台应用中心里获取)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="printer-type local">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机端口:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="host" autocomplete="off" class="layui-input len-long" lay-verify="localRequired">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
<p>打印机端口 (可以填写打印机端口号:如LPT1 或 本地网络共享打印机:如\\192.168.1.100\POS_NAME)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="printer-type network">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机IP:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="ip" autocomplete="off" class="layui-input len-long" lay-verify="networkRequired">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机端口:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="port" autocomplete="off" class="layui-input len-long" lay-verify="networkRequired">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="printer-type network local">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">打印宽度:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="print_width" value="58mm" checked title="58mm">
|
||||
<input type="radio" name="print_width" value="80mm" title="80mm">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{if $is_exit_store == 1}
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">关联门店:</label>
|
||||
<div class="layui-input-block len-mid">
|
||||
<select name="store_id" lay-verify="">
|
||||
<option value="">请选择</option>
|
||||
{foreach $store_list as $k=>$v}
|
||||
<option value="{$v.store_id}">{$v.store_name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-card card-common card-brief">
|
||||
<div class="layui-card-header">
|
||||
<span class="card-title">订单打印</span>
|
||||
</div>
|
||||
<div class="layui-card-body">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">支付打印:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="order_pay_open" lay-filter="order_pay_open" value="1" lay-skin="switch" checked/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item express_company order_pay_item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印模板:</label>
|
||||
<div class="layui-input-block len-mid">
|
||||
<select name="order_pay_template_id" lay-verify="required" >
|
||||
<option value="">请选择</option>
|
||||
{foreach $template_list as $k=>$v}
|
||||
{if $v['type'] == 'goodsorder'}
|
||||
<option value="{$v.template_id}">{$v.template_name}</option>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item order_pay_item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印联数:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="order_pay_print_num" value="1" lay-verify="required" checked autocomplete="off" title="1" class="layui-input len-long">
|
||||
<input type="radio" name="order_pay_print_num" value="2" lay-verify="required" autocomplete="off" title="2" class="layui-input len-long">
|
||||
<input type="radio" name="order_pay_print_num" value="3" lay-verify="required" autocomplete="off" title="3" class="layui-input len-long">
|
||||
<input type="radio" name="order_pay_print_num" value="4" lay-verify="required" autocomplete="off" title="4" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item order_pay_item">
|
||||
<label class="layui-form-label"><span class="required">*</span>订单类型:</label>
|
||||
<div class="layui-input-block">
|
||||
{foreach $order_type_list as $v}
|
||||
<input class="order-pay-order-type" type="checkbox" value="{$v.type}" lay-verify="required" lay-skin="primary" title="{$v.name}" checked="">
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">收货打印:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="take_delivery_open" lay-filter="take_delivery_open" value="1" lay-skin="switch" checked/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item express_company take_delivery_item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印模板:</label>
|
||||
<div class="layui-input-block len-mid">
|
||||
<select name="take_delivery_template_id" lay-verify="required" >
|
||||
<option value="">请选择</option>
|
||||
{foreach $template_list as $k=>$v}
|
||||
{if $v['type'] == 'goodsorder'}
|
||||
<option value="{$v.template_id}">{$v.template_name}</option>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item take_delivery_item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印联数:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="take_delivery_print_num" value="1" lay-verify="required" checked autocomplete="off" title="1" class="layui-input len-long">
|
||||
<input type="radio" name="take_delivery_print_num" value="2" lay-verify="required" autocomplete="off" title="2" class="layui-input len-long">
|
||||
<input type="radio" name="take_delivery_print_num" value="3" lay-verify="required" autocomplete="off" title="3" class="layui-input len-long">
|
||||
<input type="radio" name="take_delivery_print_num" value="4" lay-verify="required" autocomplete="off" title="4" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item take_delivery_item">
|
||||
<label class="layui-form-label"><span class="required">*</span>订单类型:</label>
|
||||
<div class="layui-input-block">
|
||||
{foreach $order_type_list as $v}
|
||||
<input class="take-delivery-order-type" type="checkbox" value="{$v.type}" lay-verify="required" lay-skin="primary" title="{$v.name}" checked="">
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">手动打印:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="manual_open" lay-filter="manual_open" value="1" lay-skin="switch" checked/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item express_company default_item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印模板:</label>
|
||||
<div class="layui-input-block len-mid">
|
||||
<select name="template_id" lay-verify="required" >
|
||||
<option value="">请选择</option>
|
||||
{foreach $template_list as $k=>$v}
|
||||
{if $v['type'] == 'goodsorder'}
|
||||
<option value="{$v.template_id}">{$v.template_name}</option>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item default_item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印联数:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="print_num" value="1" lay-verify="required" checked autocomplete="off" title="1" class="layui-input len-long">
|
||||
<input type="radio" name="print_num" value="2" lay-verify="required" autocomplete="off" title="2" class="layui-input len-long">
|
||||
<input type="radio" name="print_num" value="3" lay-verify="required" autocomplete="off" title="3" class="layui-input len-long">
|
||||
<input type="radio" name="print_num" value="4" lay-verify="required" autocomplete="off" title="4" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{php}
|
||||
$html = event('PrinterHtml');
|
||||
foreach($html as $k => $v) echo $v;
|
||||
{/php}
|
||||
|
||||
<div class="form-row">
|
||||
<button class="layui-btn" lay-submit lay-filter="save">保存</button>
|
||||
<button class="layui-btn layui-btn-primary" onclick="backPrinterList()">返回</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="SHOP_ADDON_JS/printer.js"></script>
|
||||
288
addon/printer/shop/view/printer/edit.html
Executable file
288
addon/printer/shop/view/printer/edit.html
Executable file
@@ -0,0 +1,288 @@
|
||||
<div class="layui-collapse tips-wrap">
|
||||
<div class="layui-colla-item">
|
||||
<h2 class="layui-colla-title">操作提示</h2>
|
||||
<ul class="layui-colla-content layui-show">
|
||||
<li>易联云的打印机请购买k6、k4、w1系列的打印机</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form form-wrap">
|
||||
|
||||
<div class="layui-card card-common card-brief">
|
||||
<div class="layui-card-header">
|
||||
<span class="card-title">打印机设置</span>
|
||||
</div>
|
||||
<div class="layui-card-body">
|
||||
<input type="hidden" value="{$printer_info['printer_id']}" name="printer_id">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机名称:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="printer_name" value="{$printer_info['printer_name']}" lay-verify="required" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机类型:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="printer_type" value="cloud" lay-verify="required" {if $printer_info.printer_type eq 'cloud'} checked{/if} title="云打印机" lay-filter="printer_type">
|
||||
<input type="radio" name="printer_type" value="local" lay-verify="required" {if $printer_info.printer_type eq 'local'} checked{/if} title="本地打印机" lay-filter="printer_type">
|
||||
<input type="radio" name="printer_type" value="network" lay-verify="required" {if $printer_info.printer_type eq 'network'} checked{/if} title="网络打印机" lay-filter="printer_type">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="printer-type cloud" {if $printer_info.printer_type eq 'cloud'}style="display:block;"{/if}>
|
||||
<div class="layui-form-item express_company">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机品牌:</label>
|
||||
<div class="layui-input-block len-short">
|
||||
<select name="brand" lay-verify="cloudRequired" lay-filter="brand">
|
||||
{foreach $brand as $k=>$v}
|
||||
<option value="{$v.brand}" {if $v.brand == $printer_info['brand']} selected {/if}>{$v.name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机编号:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="printer_code" value="{$printer_info['printer_code']}" lay-verify="cloudRequired" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机秘钥:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="printer_key" value="{$printer_info['printer_key']}" lay-verify="cloudRequired" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 飞鹅打印机 -->
|
||||
<div class="layui-form-item feie">
|
||||
<label class="layui-form-label"><span class="required">*</span>USER:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="user" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
<p>飞鹅云后台注册用户名</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item feie">
|
||||
<label class="layui-form-label"><span class="required">*</span>UKEY:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="ukey" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
<p>飞鹅云后台登录生成的UKEY</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 易联云打印机 -->
|
||||
<div class="layui-form-item yilianyun">
|
||||
<label class="layui-form-label"><span class="required">*</span>应用id:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="open_id" value="{$printer_info['open_id']}" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
<p>应用id(易联云-开发者中心后台应用中心里获取)</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item yilianyun">
|
||||
<label class="layui-form-label"><span class="required">*</span>apiKey:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="apikey" value="{$printer_info['apikey']}" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
<p>apiKey(易联云-开发者中心后台应用中心里获取)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="printer-type local" {if $printer_info.printer_type eq 'local'}style="display:block;"{/if}>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机端口:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" value="{$printer_info['host']}" name="host" autocomplete="off" class="layui-input len-long" lay-verify="localRequired">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
<p>打印机端口 (可以填写打印机端口号:如LPT1 或 本地网络共享打印机:如\\192.168.1.100\POS_NAME)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="printer-type network" {if $printer_info.printer_type eq 'network'}style="display:block;"{/if}>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机IP:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" value="{$printer_info['ip']}" name="ip" autocomplete="off" class="layui-input len-long" lay-verify="networkRequired">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印机端口:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" value="{$printer_info['port']}" name="port" autocomplete="off" class="layui-input len-long" lay-verify="networkRequired">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="printer-type network local" {if $printer_info.printer_type eq 'network' || $printer_info.printer_type eq 'local'}style="display:block;"{/if}>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">打印宽度:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="print_width" value="58mm" {if $printer_info.print_width eq '58mm'} checked{/if} title="58mm">
|
||||
<input type="radio" name="print_width" value="80mm" {if $printer_info.print_width eq '80mm'} checked{/if} title="80mm">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{if $is_exit_store == 1}
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">关联门店:</label>
|
||||
<div class="layui-input-block len-short">
|
||||
<select name="store_id" lay-verify="">
|
||||
<option value="">请选择</option>
|
||||
{foreach $store_list as $k=>$v}
|
||||
<option value="{$v.store_id}" {if $v['store_id'] == $printer_info['store_id']} selected {/if}>{$v.store_name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-card card-common card-brief">
|
||||
<div class="layui-card-header">
|
||||
<span class="card-title">订单打印</span>
|
||||
</div>
|
||||
<div class="layui-card-body">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">支付打印:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="order_pay_open" lay-filter="order_pay_open" value="1" lay-skin="switch" {if $printer_info['order_pay_open']} checked {/if}/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item express_company order_pay_item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印模板:</label>
|
||||
<div class="layui-input-block len-mid">
|
||||
<select name="order_pay_template_id" {if $printer_info['order_pay_open'] == 1}lay-verify="required"{/if}>
|
||||
<option value="">请选择</option>
|
||||
{foreach $template_list as $k=>$v}
|
||||
{if $v['type'] == 'goodsorder'}
|
||||
<option value="{$v.template_id}" {if $printer_info['order_pay_template_id'] == $v['template_id']} selected {/if}>{$v.template_name}</option>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item order_pay_item {if $printer_info['order_pay_open'] == 0}layui-hide{/if}">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印联数:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="order_pay_print_num" value="1" lay-verify="required" {if $printer_info['order_pay_print_num'] == 1} checked {/if} autocomplete="off" title="1" class="layui-input len-long">
|
||||
<input type="radio" name="order_pay_print_num" value="2" lay-verify="required" {if $printer_info['order_pay_print_num'] == 2} checked {/if} autocomplete="off" title="2" class="layui-input len-long">
|
||||
<input type="radio" name="order_pay_print_num" value="3" lay-verify="required" {if $printer_info['order_pay_print_num'] == 3} checked {/if} autocomplete="off" title="3" class="layui-input len-long">
|
||||
<input type="radio" name="order_pay_print_num" value="4" lay-verify="required" {if $printer_info['order_pay_print_num'] == 4} checked {/if} autocomplete="off" title="4" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item order_pay_item {if $printer_info['order_pay_open'] == 0}layui-hide{/if}">
|
||||
<label class="layui-form-label"><span class="required">*</span>订单类型:</label>
|
||||
<div class="layui-input-block">
|
||||
{foreach $order_type_list as $v}
|
||||
<input class="order-pay-order-type" type="checkbox" value="{$v.type}" lay-verify="required" lay-skin="primary" title="{$v.name}" {if in_array($v.type,$printer_info.order_pay_order_type)} checked="" {/if}>
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">收货打印:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="take_delivery_open" lay-filter="take_delivery_open" value="1" lay-skin="switch" {if $printer_info['take_delivery_open']} checked {/if}/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item express_company take_delivery_item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印模板:</label>
|
||||
<div class="layui-input-block len-mid">
|
||||
<select name="take_delivery_template_id" {if $printer_info['take_delivery_open'] == 1}lay-verify="required"{/if}>
|
||||
<option value="">请选择</option>
|
||||
{foreach $template_list as $k=>$v}
|
||||
{if $v['type'] == 'goodsorder'}
|
||||
<option value="{$v.template_id}" {if $printer_info['take_delivery_template_id'] == $v['template_id']} selected {/if}>{$v.template_name}</option>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item take_delivery_item {if $printer_info['take_delivery_open'] == 0}layui-hide{/if}">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印联数:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="take_delivery_print_num" {if $printer_info['take_delivery_print_num'] == 1} checked {/if} value="1" lay-verify="required" autocomplete="off" title="1" class="layui-input len-long">
|
||||
<input type="radio" name="take_delivery_print_num" {if $printer_info['take_delivery_print_num'] == 2} checked {/if} value="2" lay-verify="required" autocomplete="off" title="2" class="layui-input len-long">
|
||||
<input type="radio" name="take_delivery_print_num" {if $printer_info['take_delivery_print_num'] == 3} checked {/if} value="3" lay-verify="required" autocomplete="off" title="3" class="layui-input len-long">
|
||||
<input type="radio" name="take_delivery_print_num" {if $printer_info['take_delivery_print_num'] == 4} checked {/if} value="4" lay-verify="required" autocomplete="off" title="4" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item take_delivery_item {if $printer_info['take_delivery_open'] == 0}layui-hide{/if}">
|
||||
<label class="layui-form-label"><span class="required">*</span>订单类型:</label>
|
||||
<div class="layui-input-block">
|
||||
{foreach $order_type_list as $v}
|
||||
<input class="take-delivery-order-type" type="checkbox" value="{$v.type}" lay-verify="required" lay-skin="primary" title="{$v.name}" {if in_array($v.type,$printer_info.take_delivery_order_type)} checked="" {/if}>
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">手动打印:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="manual_open" lay-filter="manual_open" value="1" lay-skin="switch" {if $printer_info['manual_open']} checked {/if}/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item express_company default_item">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印模板:</label>
|
||||
<div class="layui-input-block len-mid">
|
||||
<select name="template_id" {if $printer_info['manual_open'] == 1}lay-verify="required"{/if}>
|
||||
<option value="">请选择</option>
|
||||
{foreach $template_list as $k=>$v}
|
||||
{if $v['type'] == 'goodsorder'}
|
||||
<option value="{$v.template_id}" {if $printer_info['template_id'] == $v['template_id']} selected {/if}>{$v.template_name}</option>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item default_item {if $printer_info['manual_open'] == 0}layui-hide{/if}">
|
||||
<label class="layui-form-label"><span class="required">*</span>打印联数:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="print_num" value="1" {if $printer_info['print_num'] == 1} checked {/if} lay-verify="required" autocomplete="off" title="1" class="layui-input len-long">
|
||||
<input type="radio" name="print_num" value="2" {if $printer_info['print_num'] == 2} checked {/if} lay-verify="required" autocomplete="off" title="2" class="layui-input len-long">
|
||||
<input type="radio" name="print_num" value="3" {if $printer_info['print_num'] == 3} checked {/if} lay-verify="required" autocomplete="off" title="3" class="layui-input len-long">
|
||||
<input type="radio" name="print_num" value="4" {if $printer_info['print_num'] == 4} checked {/if} lay-verify="required" autocomplete="off" title="4" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{php}
|
||||
$html = event('PrinterHtml');
|
||||
foreach($html as $k => $v) echo $v;
|
||||
{/php}
|
||||
<div class="form-row">
|
||||
<button class="layui-btn" lay-submit lay-filter="save">保存</button>
|
||||
<button class="layui-btn layui-btn-primary" onclick="backPrinterList()">返回</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="SHOP_ADDON_JS/printer.js"></script>
|
||||
201
addon/printer/shop/view/printer/lists.html
Executable file
201
addon/printer/shop/view/printer/lists.html
Executable file
@@ -0,0 +1,201 @@
|
||||
<!-- 搜索框 -->
|
||||
<div class="single-filter-box">
|
||||
<button class="layui-btn" onclick="add()">添加打印机</button>
|
||||
</div>
|
||||
|
||||
<table id="printer_list" lay-filter="printer_list"></table>
|
||||
|
||||
<!-- 操作 -->
|
||||
<script type="text/html" id="operation">
|
||||
<div class="table-btn">
|
||||
<a class="layui-btn" lay-event="edit">编辑</a>
|
||||
<a class="layui-btn" lay-event="del">删除</a>
|
||||
<a class="layui-btn" lay-event="print">测试打印</a>
|
||||
|
||||
{{# if(d.brand == 'yilianyun'){ }}
|
||||
<a class="layui-btn" lay-event="refresh_token">授权</a>
|
||||
{{# } }}
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script>
|
||||
var table,form,repeat_flag = false; //防重复标识
|
||||
layui.use(['form'], function() {
|
||||
form = layui.form;
|
||||
form.render();
|
||||
|
||||
table = new Table({
|
||||
elem: '#printer_list',
|
||||
url: ns.url("printer://shop/printer/lists"),
|
||||
cols: [
|
||||
[{
|
||||
'field':'printer_name',
|
||||
title: '打印机名称',
|
||||
unresize: 'false'
|
||||
},{
|
||||
'field':'printer_name',
|
||||
title: '打印机类型',
|
||||
unresize: 'false',
|
||||
templet: function(data) {
|
||||
if(data.printer_type == 'local'){
|
||||
return '本地打印机';
|
||||
} else {
|
||||
return '云打印机';
|
||||
}
|
||||
}
|
||||
}, {
|
||||
field: 'brand',
|
||||
title: '打印机品牌',
|
||||
unresize: 'false',
|
||||
templet: function(data) {
|
||||
if(data.brand == '365'){
|
||||
return '365';
|
||||
} else if(data.brand == 'yilianyun'){
|
||||
return '易联云';
|
||||
} else if (data.brand == 'feie') {
|
||||
return '飞鹅';
|
||||
}
|
||||
}
|
||||
}, {
|
||||
field: 'is_default',
|
||||
title: '一次打印',
|
||||
unresize: 'false',
|
||||
templet: function(data) {
|
||||
return data.print_num + '张';
|
||||
}
|
||||
}, {
|
||||
title: '添加时间',
|
||||
unresize: 'false',
|
||||
templet: function(data) {
|
||||
return ns.time_to_date(data.create_time);
|
||||
}
|
||||
}, {
|
||||
title: '操作',
|
||||
toolbar: '#operation',
|
||||
unresize: 'false',
|
||||
align:'right'
|
||||
}]
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* 监听工具栏操作
|
||||
*/
|
||||
table.tool(function(obj) {
|
||||
var data = obj.data;
|
||||
switch (obj.event) {
|
||||
case 'edit': //编辑
|
||||
location.hash = ns.hash("printer://shop/printer/edit", {"printer_id": data.printer_id});
|
||||
break;
|
||||
case 'del': //删除
|
||||
deletePrinter(data.printer_id);
|
||||
break;
|
||||
case 'print': //测试打印
|
||||
testPrint(data.printer_id);
|
||||
break;
|
||||
case 'refresh_token': //测试打印
|
||||
refreshToken(data.printer_id);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
function refreshToken(printer_id){
|
||||
layer.confirm('若易联云打印机在 "测试打印" 时提示 "access_token过期或错误",请重新授权,是否重新授权', function(index) {
|
||||
if (repeat_flag) return;
|
||||
repeat_flag = true;
|
||||
layer.close(index);
|
||||
|
||||
$.ajax({
|
||||
url: ns.url("printer://shop/printer/refreshtoken"),
|
||||
data: {
|
||||
printer_id: printer_id
|
||||
},
|
||||
dataType: 'JSON',
|
||||
type: 'POST',
|
||||
success: function(res) {
|
||||
layer.msg(res.message);
|
||||
repeat_flag = false;
|
||||
if (res.code == 0) {
|
||||
table.reload({
|
||||
page: {
|
||||
curr: 1
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}, function() {
|
||||
layer.close();
|
||||
repeat_flag = false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
function deletePrinter(printer_id) {
|
||||
layer.confirm('确定要删除该打印机吗?', function(index) {
|
||||
if (repeat_flag) return;
|
||||
repeat_flag = true;
|
||||
layer.close(index);
|
||||
|
||||
$.ajax({
|
||||
url: ns.url("printer://shop/printer/delete"),
|
||||
data: {
|
||||
printer_id: printer_id
|
||||
},
|
||||
dataType: 'JSON',
|
||||
type: 'POST',
|
||||
success: function(res) {
|
||||
layer.msg(res.message);
|
||||
repeat_flag = false;
|
||||
if (res.code == 0) {
|
||||
table.reload({
|
||||
page: {
|
||||
curr: 1
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}, function() {
|
||||
layer.close();
|
||||
repeat_flag = false;
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* 测试打印
|
||||
*/
|
||||
function testPrint(printer_id)
|
||||
{
|
||||
layer.confirm('确定测试打印吗?', function(index) {
|
||||
if (repeat_flag) return;
|
||||
repeat_flag = true;
|
||||
layer.close(index);
|
||||
|
||||
$.ajax({
|
||||
url: ns.url("printer://shop/printer/testPrint"),
|
||||
data: {
|
||||
printer_id: printer_id
|
||||
},
|
||||
dataType: 'JSON',
|
||||
type: 'POST',
|
||||
success: function(res) {
|
||||
repeat_flag = false;
|
||||
layer.msg(res.message);
|
||||
}
|
||||
});
|
||||
}, function() {
|
||||
layer.close();
|
||||
repeat_flag = false;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function add() {
|
||||
location.hash = ns.hash("printer://shop/printer/add");
|
||||
}
|
||||
</script>
|
||||
BIN
addon/printer/shop/view/public/img/distribution.png
Executable file
BIN
addon/printer/shop/view/public/img/distribution.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
BIN
addon/printer/shop/view/public/img/distribution_new.png
Executable file
BIN
addon/printer/shop/view/public/img/distribution_new.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
addon/printer/shop/view/public/img/distribution_select.png
Executable file
BIN
addon/printer/shop/view/public/img/distribution_select.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
226
addon/printer/shop/view/public/js/printer.js
Executable file
226
addon/printer/shop/view/public/js/printer.js
Executable file
@@ -0,0 +1,226 @@
|
||||
layui.use(['form',], function () {
|
||||
var form = layui.form,
|
||||
repeat_flag = false;
|
||||
|
||||
form.render();
|
||||
|
||||
form.on('radio(printer_type)', function (e) {
|
||||
$('.printer-type').hide()
|
||||
$('.printer-type.' + e.value).show()
|
||||
})
|
||||
|
||||
form.on('select(brand)', function (data) {
|
||||
var value = data.value;
|
||||
if (value == '365') {
|
||||
$('.feie').hide();
|
||||
$('.yilianyun').hide();
|
||||
|
||||
$("input[name='user']").attr("lay-verify", "");
|
||||
$("input[name='ukey']").attr("lay-verify", "");
|
||||
|
||||
$("input[name='open_id']").attr("lay-verify", "");
|
||||
$("input[name='apikey']").attr("lay-verify", "");
|
||||
}
|
||||
|
||||
if (value == 'feie') {
|
||||
$('.feie').show();
|
||||
$('.yilianyun').hide();
|
||||
|
||||
$("input[name='user']").attr("lay-verify", "cloudRequired");
|
||||
$("input[name='ukey']").attr("lay-verify", "cloudRequired");
|
||||
|
||||
$("input[name='open_id']").attr("lay-verify", "");
|
||||
$("input[name='apikey']").attr("lay-verify", "");
|
||||
}
|
||||
|
||||
if (value == 'yilianyun') {
|
||||
$('.yilianyun').show();
|
||||
$('.feie').hide();
|
||||
|
||||
$("input[name='open_id']").attr("lay-verify", "cloudRequired");
|
||||
$("input[name='apikey']").attr("lay-verify", "cloudRequired");
|
||||
|
||||
$("input[name='user']").attr("lay-verify", "");
|
||||
$("input[name='ukey']").attr("lay-verify", "");
|
||||
}
|
||||
});
|
||||
|
||||
form.on('switch(recharge_open)', function (data) {
|
||||
if (data.elem.checked) {
|
||||
$(".layui-form-item.recharge_item").removeClass('layui-hide');
|
||||
$('.recharge-content').removeClass('layui-hide');
|
||||
$('.recharge-content [name="recharge_template_id"]').attr('lay-verify', 'required');
|
||||
} else {
|
||||
$(".layui-form-item.recharge_item").addClass('layui-hide');
|
||||
$('.recharge-content').addClass('layui-hide');
|
||||
$('.recharge-content [name="recharge_template_id"]').attr('lay-verify', '');
|
||||
}
|
||||
});
|
||||
|
||||
form.on('switch(order_pay_open)', function (data) {
|
||||
if (data.elem.checked) {
|
||||
$('.order_pay_item').removeClass('layui-hide');
|
||||
$('.order_pay_item [name="order_pay_template_id"]').attr('lay-verify', 'required');
|
||||
} else {
|
||||
$('.order_pay_item').addClass('layui-hide');
|
||||
$('.order_pay_item [name="order_pay_template_id"]').attr('lay-verify', '');
|
||||
}
|
||||
});
|
||||
|
||||
form.on('switch(change_shifts_open)', function (data) {
|
||||
if (data.elem.checked) {
|
||||
$('.change_shifts-content').removeClass('layui-hide');
|
||||
$('.change_shifts-box [name="change_shifts_template_id"]').attr('lay-verify', 'required');
|
||||
} else {
|
||||
$('.change_shifts-content').addClass('layui-hide');
|
||||
$('.change_shifts-box [name="change_shifts_template_id"]').attr('lay-verify', '');
|
||||
}
|
||||
});
|
||||
|
||||
form.on('switch(take_delivery_open)', function (data) {
|
||||
if (data.elem.checked) {
|
||||
$('.take_delivery_item').removeClass('layui-hide');
|
||||
$('.take_delivery_item [name="take_delivery_template_id"]').attr('lay-verify', 'required');
|
||||
} else {
|
||||
$('.take_delivery_item').addClass('layui-hide');
|
||||
$('.take_delivery_item [name="take_delivery_template_id"]').attr('lay-verify', '');
|
||||
}
|
||||
});
|
||||
|
||||
form.on('switch(manual_open)', function (data) {
|
||||
if (data.elem.checked) {
|
||||
$('.default_item').removeClass('layui-hide');
|
||||
$('.default_item [name="template_id"]').attr('lay-verify', 'required');
|
||||
} else {
|
||||
$('.default_item').addClass('layui-hide');
|
||||
$('.default_item [name="template_id"]').attr('lay-verify', '');
|
||||
}
|
||||
});
|
||||
|
||||
var printer_type = $('input[name="printer_type"]:checked').val()
|
||||
$(`input[name="printer_type"][value="${printer_type}"]`).next('.layui-unselect.layui-form-radio').click()
|
||||
|
||||
var brand = $('select[name="brand"] option:checked').val()
|
||||
$("select[name='brand']").siblings("div.layui-form-select").find("dl dd[lay-value='" + brand + "']").click();
|
||||
|
||||
form.verify({
|
||||
time: function (value) {
|
||||
var now_time = (new Date()).getTime();
|
||||
var start_time = (new Date($("#start_time").val())).getTime();
|
||||
var end_time = (new Date(value)).getTime();
|
||||
if (now_time > end_time) {
|
||||
return '结束时间不能小于当前时间!'
|
||||
}
|
||||
if (start_time > end_time) {
|
||||
return '结束时间不能小于开始时间!';
|
||||
}
|
||||
},
|
||||
flnum: function (value) {
|
||||
var arrMen = value.split(".");
|
||||
var val = 0;
|
||||
if (arrMen.length == 2) {
|
||||
val = arrMen[1];
|
||||
}
|
||||
if (val.length > 2) {
|
||||
return '保留小数点后两位!'
|
||||
}
|
||||
},
|
||||
int: function (value) {
|
||||
if (value <= 1 || value % 1 != 0) {
|
||||
return '请输入大于1的正整数!'
|
||||
}
|
||||
},
|
||||
cloudRequired: function (value, ele) {
|
||||
if ($('[name="printer_type"]:checked').val() == 'cloud' && !/[\S]+/.test(value)) {
|
||||
var label = $(ele).parents('.layui-form-item').find('.layui-form-label').text().replace(':', '').replace('*', '')
|
||||
return label + '不能为空'
|
||||
}
|
||||
},
|
||||
localRequired: function (value, ele) {
|
||||
if ($('[name="printer_type"]:checked').val() == 'local' && !/[\S]+/.test(value)) {
|
||||
var label = $(ele).parents('.layui-form-item').find('.layui-form-label').text().replace(':', '').replace('*', '')
|
||||
return label + '不能为空'
|
||||
}
|
||||
},
|
||||
networkRequired: function (value, ele) {
|
||||
if ($('[name="printer_type"]:checked').val() == 'newwork' && !/[\S]+/.test(value)) {
|
||||
var label = $(ele).parents('.layui-form-item').find('.layui-form-label').text().replace(':', '').replace('*', '')
|
||||
return label + '不能为空'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
form.on('submit(save)', function (data) {
|
||||
|
||||
var field = data.field;
|
||||
if (field.brand == 'feie') {
|
||||
field.open_id = field.user;
|
||||
field.apikey = field.ukey;
|
||||
}
|
||||
|
||||
var order_pay_order_type_arr = [];
|
||||
if (field.order_pay_open) {
|
||||
$(".order-pay-order-type").each(function () {
|
||||
if ($(this).is(":checked")) {
|
||||
order_pay_order_type_arr.push($(this).val());
|
||||
}
|
||||
});
|
||||
if (order_pay_order_type_arr == "") {
|
||||
layer.msg('请选择支付打印的订单类型');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
field.order_pay_order_type = order_pay_order_type_arr.toString();
|
||||
|
||||
var take_delivery_order_type_arr = [];
|
||||
if (field.order_pay_open) {
|
||||
$(".order-pay-order-type").each(function () {
|
||||
if ($(this).is(":checked")) {
|
||||
take_delivery_order_type_arr.push($(this).val());
|
||||
}
|
||||
});
|
||||
if (take_delivery_order_type_arr == "") {
|
||||
layer.msg('请选择收货打印的订单类型');
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
field.take_delivery_order_type = take_delivery_order_type_arr.toString();
|
||||
|
||||
if (repeat_flag) return;
|
||||
repeat_flag = true;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
url: field.printer_id ? ns.url("printer://shop/printer/edit") : ns.url("printer://shop/printer/add"),
|
||||
data: field,
|
||||
async: false,
|
||||
success: function (res) {
|
||||
repeat_flag = false;
|
||||
|
||||
if (res.code == 0) {
|
||||
layer.confirm(field.printer_id ? '编辑成功' : '添加成功', {
|
||||
title: '操作提示',
|
||||
btn: ['返回列表', field.printer_id ? '继续编辑' : '继续添加'],
|
||||
closeBtn: 0,
|
||||
yes: function (index, layero) {
|
||||
location.hash = ns.hash("printer://shop/printer/lists");
|
||||
layer.close(index);
|
||||
},
|
||||
btn2: function (index, layero) {
|
||||
listenerHash(); // 刷新页面
|
||||
layer.close(index);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.message);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
function backPrinterList() {
|
||||
location.hash = ns.hash("printer://shop/printer/lists");
|
||||
}
|
||||
559
addon/printer/shop/view/template/goodsorder_template.html
Executable file
559
addon/printer/shop/view/template/goodsorder_template.html
Executable file
@@ -0,0 +1,559 @@
|
||||
<style>
|
||||
.printer-box{display: flex;}
|
||||
.printer-box > .layui-form{flex: 1;}
|
||||
.printer-box .preview{width: 310px;margin: 0 20px;}
|
||||
.printer-box .preview .layui-card-body{margin: 20px;padding: 0 10px;border: 1px solid #ededed;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;}
|
||||
.printer-box .preview .layui-card-body div{font-size: 12px;color: #333;}
|
||||
.printer-box .preview .layui-card-body div ~ div{border-top: 1px dashed #ededed ;}
|
||||
.printer-box .preview .receipt-name{text-align: center;line-height: 40px;}
|
||||
.printer-box .preview .shopping-name{line-height: 40px;font-size: 16px !important;text-align: center;}
|
||||
.printer-box .preview .order-info, .printer-box .preview .goods-info, .printer-box .preview .price-info, .printer-box .preview .buyer-info, .printer-box .preview .shopping-info{padding: 8px 0;}
|
||||
.printer-box .preview .order-info span{display: block;line-height: 2.5;}
|
||||
.printer-box .preview .goods-info table{width: 100%;}
|
||||
.printer-box .preview .goods-info table tr{line-height: 2.5;}
|
||||
.printer-box .preview .goods-info table th{font-weight: normal;}
|
||||
.printer-box .preview .price-info p{display: flex;line-height: 2.5;justify-content: space-between;}
|
||||
.printer-box .preview .buyer-info span, .printer-box .preview .shopping-info span{display: block;line-height: 2;}
|
||||
.printer-box .preview .buyer-message,.printer-box .preview .merchant-message{padding: 10px 0;line-height: 1.5;}
|
||||
.preview .button-info{height: 40px;line-height: 40px;text-align: center}
|
||||
.preview .shopping-code{text-align: center;}
|
||||
.preview .shopping-code img{width: 100px;height: 100px;margin: 10px 0;}
|
||||
.commodity-type-box{
|
||||
display: flex;
|
||||
}
|
||||
.commodity-type-item{
|
||||
margin-right: 15px;
|
||||
padding: 0px 20px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
border: 1px solid #e5e5e5;
|
||||
cursor: pointer;
|
||||
}
|
||||
.goods_code_show td{line-height: 1;padding-bottom: 5px}
|
||||
</style>
|
||||
|
||||
<div class="printer-box">
|
||||
<div class="layui-form form-wrap">
|
||||
<div class="layui-card card-common card-brief">
|
||||
<div class="layui-card-header">
|
||||
<span class="card-title">模板信息</span>
|
||||
</div>
|
||||
<div class="layui-card-body">
|
||||
{if empty($info)}
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>模板类型:</label>
|
||||
<div class="layui-input-block commodity-type-box">
|
||||
{foreach $template_type as $k => $v}
|
||||
<div class="commodity-type-item {if $type == $k} border-color{/if}" onclick="location.hash = ns.hash('printer://shop/template/add', {'type' : '{$v['type']}'})">
|
||||
<span class="{if $type == $k} text-color{/if}">{$v['type_name']}</span>
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="type_name" value="{$template_type[$type]['type_name']}">
|
||||
<input type="hidden" name="type" value="{$type}">
|
||||
{/if}
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required"></span>模板名称:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="template_name" lay-verify="required" {if !empty($info)} value="{$info['template_name']}" {/if} autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
{if !empty($info)}
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required"></span>模板类型:</label>
|
||||
<div class="layui-input-block">{$info['type_name']}</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-card card-common card-brief">
|
||||
|
||||
<div class="layui-card-header">
|
||||
<span class="card-title">打印信息</span>
|
||||
</div>
|
||||
<div class="layui-card-body">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">小票名称:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="title" {if !empty($info)} value="{$info['title']}"{else/} value="小票名称" {/if} lay-verify="required" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">商城名称:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" lay-filter="shop_name" name="head" value="1" title="显示" {if (!empty($info) && $info['head'] == 1) || empty($info) } checked {/if} autocomplete="off" class="layui-input len-long">
|
||||
<input type="radio" lay-filter="shop_name" name="head" value="0" title="不显示" {if !empty($info) && !$info['head']} checked {/if} autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">商品信息:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="goods_price_show" value="1" lay-skin="primary" title="商品金额" {if (!empty($info) && $info['goods_price_show'] == 1) || empty($info) } checked {/if} lay-filter="goods_price_show">
|
||||
<input type="checkbox" name="goods_code_show" value="1" lay-skin="primary" title="商品编码" {if !empty($info) && $info['goods_code_show'] == 1 } checked {/if} lay-filter="goods_code_show">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item goods_price_type ">
|
||||
<label class="layui-form-label">商品金额:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" lay-filter="goods_price_type" name="goods_price_type" value="price" title="售价" {if (!empty($info) && $info['goods_price_type'] == 'price') || empty($info) } checked {/if} autocomplete="off" class="layui-input len-long">
|
||||
<input type="radio" lay-filter="goods_price_type" name="goods_price_type" value="order_price" title="实付价" {if !empty($info) && $info['goods_price_type'] == 'order_price'} checked {/if} autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
{if addon_is_exit('form')}
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">表单信息:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="form_show" value="1" lay-skin="primary" title="表单" {if (!empty($info) && $info['form_show']) || empty($info) } checked {/if} lay-filter="form_show">
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">备注信息:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="buy_notes" value="1" lay-skin="primary" title="买家留言" {if (!empty($info) && $info['buy_notes']) || empty($info) } checked {/if} lay-filter="buyer_message">
|
||||
<input type="checkbox" name="seller_notes" value="1" lay-skin="primary" title="卖家留言" {if (!empty($info) && $info['seller_notes']) } checked {/if} lay-filter="merchant_message">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">买家信息:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="buy_name" value="1" lay-filter="buyer_name" lay-skin="primary" title="姓名" {if (!empty($info) && $info['buy_name']) || empty($info) } checked {/if}>
|
||||
<input type="checkbox" name="buy_mobile" value="1" lay-filter="buyer_phone" lay-skin="primary" title="联系方式" {if (!empty($info) && $info['buy_mobile']) || empty($info) } checked {/if}>
|
||||
<input type="checkbox" name="buy_address" value="1" lay-filter="buyer_address" lay-skin="primary" title="地址" {if (!empty($info) && $info['buy_address']) || empty($info) } checked {/if}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">商城信息:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="shop_mobile" value="1" lay-filter="shopping_phone" lay-skin="primary" title="联系方式" {if (!empty($info) && $info['shop_mobile'])} checked {/if}>
|
||||
<input type="checkbox" name="shop_address" value="1" lay-filter="shopping_addres" lay-skin="primary" title="地址" {if (!empty($info) && $info['shop_address'])} checked {/if}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">商城二维码:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="shop_qrcode" value="1" lay-filter="shop_qrcode" lay-skin="primary" title="商城二维码" {if (!empty($info) && $info['shop_qrcode']) || empty($info) } checked {/if}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item qrcode_url">
|
||||
<label class="layui-form-label"><span class="required">*</span>商城二维码链接:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="qrcode_url" lay-verify="required" autocomplete="off" class="layui-input len-long" {if (!empty($info) && $info['qrcode_url'])} value="{$info['qrcode_url']}" {/if}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">底部信息:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="bottom" {if (!empty($info) && $info['bottom'])} value="{$info['bottom']}"{else /} value="谢谢惠顾,欢迎下次光临" {/if} lay-verify="required" placeholder="" autocomplete="off" class="layui-input len-long">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{if !empty($info)}
|
||||
<input type="hidden" name="template_id" value="{$info['template_id']}">
|
||||
{/if}
|
||||
<div class="form-row">
|
||||
<button class="layui-btn" lay-submit lay-filter="save">保存</button>
|
||||
<button class="layui-btn layui-btn-primary" onclick="backPrinterTemplateList()">返回</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="preview">
|
||||
<div class="layui-card card-common card-brief">
|
||||
|
||||
<div class="layui-card-header">
|
||||
<span class="card-title">预览图</span>
|
||||
</div>
|
||||
|
||||
<div class="layui-card-body">
|
||||
<div class="receipt-name">小票名称</div>
|
||||
<div class="shopping-name">商城名称</div>
|
||||
<div class="order-info">
|
||||
<span>订单时间:2023年2月11日 11:16:44</span>
|
||||
<span>订单编号:ME20180702231831547866</span>
|
||||
<span>支付方式:微信支付</span>
|
||||
<span>配送时间:立即送达(自提提货、本地配送展示)</span>
|
||||
</div>
|
||||
<div class="goods-info">
|
||||
<table>
|
||||
<tr>
|
||||
<th align="left">商品名称</th>
|
||||
<th align="center">数量</th>
|
||||
<th align="right" class="goods_price_show">金额</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>男子运动外套</td>
|
||||
<td align="center">2</td>
|
||||
<td align="right" class="goods_price_show">¥388.00</td>
|
||||
</tr>
|
||||
<tr class="goods_code_show layui-hide">
|
||||
<td colspan="3">[G00000001]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>白色跑步鞋</td>
|
||||
<td align="center">2</td>
|
||||
<td align="right" class="goods_price_show">¥1689.00</td>
|
||||
</tr>
|
||||
<tr class="goods_code_show layui-hide">
|
||||
<td colspan="3">[G00000002]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>运费</td>
|
||||
<td colspan="2" align="right">¥0.00</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="price-info">
|
||||
<p>
|
||||
<span>订单原价</span>
|
||||
<span>¥2010</span>
|
||||
</p>
|
||||
<p>
|
||||
<span>优惠金额</span>
|
||||
<span>¥2010</span>
|
||||
</p>
|
||||
<p>
|
||||
<span>实付金额</span>
|
||||
<span>¥2010</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="buyer-message">买家留言:物流很快</div>
|
||||
<div class="merchant-message layui-hide">卖家留言:欢迎下次购买</div>
|
||||
{if addon_is_exit('form')}
|
||||
<div class="form_show">标题:内容</div>
|
||||
{/if}
|
||||
<div class="buyer-info">
|
||||
<span class="name">niushop</span>
|
||||
<span class="phone">15135669878</span>
|
||||
<span class="addres">山西省 太原市 小店区 创业街</span>
|
||||
</div>
|
||||
<div class="shopping-info layui-hide">
|
||||
<span class="phone layui-hide">4008867993 </span>
|
||||
<span class="addres layui-hide">山西省 太原市 小店区 创业街 世纪中心4单元1025</span>
|
||||
</div>
|
||||
<div class="shopping-code">
|
||||
<img src="SHOP_IMG/shopping_code.png" alt="">
|
||||
</div>
|
||||
<div class="button-info">谢谢惠顾,欢迎下次光临</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
layui.use(['form'], function() {
|
||||
var form = layui.form,
|
||||
repeat_flag = false;
|
||||
|
||||
form.render();
|
||||
|
||||
/**
|
||||
* 表单验证
|
||||
*/
|
||||
form.verify({
|
||||
time: function(value) {
|
||||
var now_time = (new Date()).getTime();
|
||||
var start_time = (new Date($("#start_time").val())).getTime();
|
||||
var end_time = (new Date(value)).getTime();
|
||||
if (now_time > end_time) {
|
||||
return '结束时间不能小于当前时间!'
|
||||
}
|
||||
if (start_time > end_time) {
|
||||
return '结束时间不能小于开始时间!';
|
||||
}
|
||||
},
|
||||
flnum: function(value) {
|
||||
var arrMen = value.split(".");
|
||||
var val = 0;
|
||||
if (arrMen.length == 2) {
|
||||
val = arrMen[1];
|
||||
}
|
||||
if (val.length > 2) {
|
||||
return '保留小数点后两位!'
|
||||
}
|
||||
},
|
||||
int: function(value) {
|
||||
if (value <= 1 || value % 1 != 0) {
|
||||
return '请输入大于1的正整数!'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
form.on('checkbox(shop_qrcode)', function(data){
|
||||
|
||||
var value = data.elem.checked;
|
||||
if(value == true){
|
||||
$(".preview .shopping-code").removeClass("layui-hide");
|
||||
$(".qrcode_url").removeClass('layui-hide');
|
||||
$("input[name='qrcode_url']").attr("lay-verify", "required");
|
||||
}else{
|
||||
$(".preview .shopping-code").addClass("layui-hide");
|
||||
$(".qrcode_url").addClass('layui-hide');
|
||||
$("input[name='qrcode_url']").attr("lay-verify", "");
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 表单提交
|
||||
*/
|
||||
form.on('submit(save)', function(data){
|
||||
|
||||
var field = data.field;
|
||||
if(repeat_flag) return;
|
||||
repeat_flag = true;
|
||||
let url = ns.url("printer://shop/template/add");
|
||||
if(parseInt(field.template_id) > 0 ) url = ns.url("printer://shop/template/edit");
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
url: url,
|
||||
data: field,
|
||||
async: false,
|
||||
success: function(res){
|
||||
repeat_flag = false;
|
||||
|
||||
if (res.code == 0) {
|
||||
layer.confirm('操作成功', {
|
||||
title:'操作提示',
|
||||
btn: ['返回列表', '{$info ? "继续编辑" : "继续添加"}'],
|
||||
closeBtn: 0,
|
||||
yes: function(index, layero){
|
||||
location.hash = ns.hash("printer://shop/template/lists");
|
||||
layer.close(index);
|
||||
},
|
||||
btn2: function(index, layero) {
|
||||
listenerHash(); // 刷新页面
|
||||
layer.close(index);
|
||||
}
|
||||
});
|
||||
}else{
|
||||
layer.msg(res.message);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// 小票打印
|
||||
$("input[name='title']").bind("input propertychange",function(event){
|
||||
$(".preview .receipt-name").text($("input[name='title']").val());
|
||||
});
|
||||
|
||||
//商城名称
|
||||
form.on('radio(shop_name)', function(data){
|
||||
if (parseInt(data.value)) $(".shopping-name").removeClass("layui-hide");
|
||||
else $(".shopping-name").addClass("layui-hide");
|
||||
});
|
||||
|
||||
//商品价格
|
||||
form.on('checkbox(goods_price_show)', function(data){
|
||||
if (data.elem.checked) {
|
||||
$(".goods_price_show").removeClass("layui-hide");
|
||||
$('.goods_price_type').removeClass("layui-hide");
|
||||
}else {
|
||||
$('.goods_price_type').addClass("layui-hide");
|
||||
$(".goods_price_show").addClass("layui-hide");
|
||||
}
|
||||
});
|
||||
|
||||
//商品编码
|
||||
form.on('checkbox(goods_code_show)', function(data){
|
||||
if (data.elem.checked) $(".goods_code_show").removeClass("layui-hide");
|
||||
else $(".goods_code_show").addClass("layui-hide");
|
||||
});
|
||||
|
||||
//表单
|
||||
form.on('checkbox(form_show)', function(data){
|
||||
if (data.elem.checked) $(".form_show").removeClass("layui-hide");
|
||||
else $(".form_show").addClass("layui-hide");
|
||||
});
|
||||
|
||||
//买家留言
|
||||
form.on('checkbox(buyer_message)', function(data){
|
||||
if(data.elem.checked)
|
||||
$(".buyer-message").removeClass("layui-hide");
|
||||
else
|
||||
$(".buyer-message").addClass("layui-hide");
|
||||
});
|
||||
|
||||
//卖家留言
|
||||
form.on('checkbox(merchant_message)', function(data){
|
||||
if(data.elem.checked)
|
||||
$(".merchant-message").removeClass("layui-hide");
|
||||
else
|
||||
$(".merchant-message").addClass("layui-hide");
|
||||
});
|
||||
|
||||
var buyerName = true,buyerPhone=true,buyerAddres=true;
|
||||
|
||||
//买家姓名
|
||||
form.on('checkbox(buyer_name)', function(data){
|
||||
buyerName = data.elem.checked;
|
||||
|
||||
if(data.elem.checked)
|
||||
$(".buyer-info .name").removeClass("layui-hide");
|
||||
else
|
||||
$(".buyer-info .name").addClass("layui-hide");
|
||||
|
||||
buyerFn();
|
||||
});
|
||||
|
||||
//买家手机号
|
||||
form.on('checkbox(buyer_phone)', function(data){
|
||||
buyerPhone = data.elem.checked;
|
||||
|
||||
if(data.elem.checked)
|
||||
$(".buyer-info .phone").removeClass("layui-hide");
|
||||
else
|
||||
$(".buyer-info .phone").addClass("layui-hide");
|
||||
|
||||
buyerFn();
|
||||
});
|
||||
|
||||
//买家地址
|
||||
form.on('checkbox(buyer_address)', function(data){
|
||||
buyerAddres= data.elem.checked;
|
||||
if(data.elem.checked)
|
||||
$(".buyer-info .addres").removeClass("layui-hide");
|
||||
else
|
||||
$(".buyer-info .addres").addClass("layui-hide");
|
||||
buyerFn();
|
||||
});
|
||||
|
||||
function buyerFn() {
|
||||
if (!buyerName && !buyerPhone && !buyerAddres)
|
||||
$(".buyer-info").addClass("layui-hide");
|
||||
else
|
||||
$(".buyer-info").removeClass("layui-hide");
|
||||
}
|
||||
|
||||
var shoppingPhone=false,shoppingAddress=false;
|
||||
//商家手机号
|
||||
form.on('checkbox(shopping_phone)', function(data){
|
||||
shoppingPhone = data.elem.checked;
|
||||
|
||||
if(data.elem.checked)
|
||||
$(".shopping-info .phone").removeClass("layui-hide");
|
||||
else
|
||||
$(".shopping-info .phone").addClass("layui-hide");
|
||||
|
||||
shoppingFn();
|
||||
});
|
||||
//商家地址
|
||||
form.on('checkbox(shopping_addres)', function(data){
|
||||
shoppingAddress= data.elem.checked;
|
||||
|
||||
if(data.elem.checked)
|
||||
$(".shopping-info .addres").removeClass("layui-hide");
|
||||
else
|
||||
$(".shopping-info .addres").addClass("layui-hide");
|
||||
shoppingFn();
|
||||
});
|
||||
|
||||
function shoppingFn() {
|
||||
if (!shoppingPhone && !shoppingAddress)
|
||||
$(".shopping-info").addClass("layui-hide");
|
||||
else
|
||||
$(".shopping-info").removeClass("layui-hide");
|
||||
}
|
||||
|
||||
// 底部信息
|
||||
$("input[name='bottom']").bind("input propertychange",function(event){
|
||||
$(".preview .button-info").text($("input[name='bottom']").val());
|
||||
});
|
||||
});
|
||||
|
||||
function backPrinterTemplateList() {
|
||||
location.hash = ns.hash("printer://shop/template/lists");
|
||||
}
|
||||
|
||||
</script>
|
||||
{if !empty($info)}
|
||||
<script>
|
||||
var shop_qrcode = {$info['shop_qrcode']};
|
||||
if(shop_qrcode){
|
||||
$(".preview .shopping-code").removeClass("layui-hide");
|
||||
$(".qrcode_url").removeClass('layui-hide');
|
||||
$("input[name='qrcode_url']").attr("lay-verify", "required");
|
||||
}else{
|
||||
$(".preview .shopping-code").addClass("layui-hide");
|
||||
$(".qrcode_url").addClass('layui-hide');
|
||||
$("input[name='qrcode_url']").attr("lay-verify", "");
|
||||
}
|
||||
|
||||
var head = {$info['head']};
|
||||
if (head) {
|
||||
$(".shopping-name").removeClass("layui-hide");
|
||||
}else {
|
||||
$(".shopping-name").addClass("layui-hide");
|
||||
}
|
||||
|
||||
var goods_price_show = {$info['goods_price_show']};
|
||||
if (goods_price_show) {
|
||||
$(".goods_price_show").removeClass("layui-hide");
|
||||
$('.goods_price_type').removeClass("layui-hide");
|
||||
}else {
|
||||
$('.goods_price_type').addClass("layui-hide");
|
||||
$(".goods_price_show").addClass("layui-hide");
|
||||
}
|
||||
|
||||
var goods_code_show = {$info['goods_code_show']};
|
||||
if (goods_code_show) $(".goods_code_show").removeClass("layui-hide");
|
||||
else $(".goods_code_show").addClass("layui-hide");
|
||||
|
||||
var form_show = {$info['form_show']};
|
||||
if (form_show) $(".form_show").removeClass("layui-hide");
|
||||
else $(".form_show").addClass("layui-hide");
|
||||
|
||||
var buy_notes = {$info['buy_notes']};
|
||||
if(buy_notes) $(".buyer-message").removeClass("layui-hide");
|
||||
else $(".buyer-message").addClass("layui-hide");
|
||||
|
||||
var seller_notes = {$info['seller_notes']};
|
||||
if(seller_notes) $(".merchant-message").removeClass("layui-hide");
|
||||
else $(".merchant-message").addClass("layui-hide");
|
||||
|
||||
buyerName = {$info['buy_name']},buyerPhone={$info['buy_mobile']},buyerAddres={$info['buy_address']};
|
||||
if(buyerName) $(".buyer-info .name").removeClass("layui-hide");
|
||||
else $(".buyer-info .name").addClass("layui-hide");
|
||||
|
||||
if(buyerPhone) $(".buyer-info .phone").removeClass("layui-hide");
|
||||
else $(".buyer-info .phone").addClass("layui-hide");
|
||||
|
||||
if(buyerAddres) $(".buyer-info .addres").removeClass("layui-hide");
|
||||
else $(".buyer-info .addres").addClass("layui-hide");
|
||||
|
||||
if (!buyerName && !buyerPhone && !buyerAddres) $(".buyer-info").addClass("layui-hide");
|
||||
else $(".buyer-info").removeClass("layui-hide");
|
||||
|
||||
shoppingPhone= {$info['shop_mobile']},shoppingAddress= {$info['shop_address']};
|
||||
|
||||
//商家手机号
|
||||
if(shoppingPhone)$(".shopping-info .phone").removeClass("layui-hide");
|
||||
else $(".shopping-info .phone").addClass("layui-hide");
|
||||
|
||||
//商家地址
|
||||
if(shoppingAddress) $(".shopping-info .addres").removeClass("layui-hide");
|
||||
else $(".shopping-info .addres").addClass("layui-hide");
|
||||
|
||||
if (!shoppingPhone && !shoppingAddress) $(".shopping-info").addClass("layui-hide");
|
||||
else $(".shopping-info").removeClass("layui-hide");
|
||||
|
||||
</script>
|
||||
{/if}
|
||||
106
addon/printer/shop/view/template/lists.html
Executable file
106
addon/printer/shop/view/template/lists.html
Executable file
@@ -0,0 +1,106 @@
|
||||
<!-- 搜索框 -->
|
||||
<div class="single-filter-box">
|
||||
<button class="layui-btn" onclick="add()">添加打印模板</button>
|
||||
</div>
|
||||
|
||||
<table id="template_list" lay-filter="template_list"></table>
|
||||
|
||||
<!-- 操作 -->
|
||||
<script type="text/html" id="operation">
|
||||
<div class="table-btn">
|
||||
<a class="layui-btn" lay-event="edit">编辑</a>
|
||||
<a class="layui-btn" lay-event="del">删除</a>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script>
|
||||
layui.use(['form'], function() {
|
||||
var table,
|
||||
form = layui.form,
|
||||
repeat_flag = false; //防重复标识
|
||||
form.render();
|
||||
|
||||
table = new Table({
|
||||
elem: '#template_list',
|
||||
url: ns.url("printer://shop/template/lists"),
|
||||
cols: [
|
||||
[{
|
||||
'field':'template_name',
|
||||
title: '模板名称',
|
||||
unresize: 'false'
|
||||
}, {
|
||||
title: '模板类型',
|
||||
unresize: 'false',
|
||||
templet: function(data) {
|
||||
return data.type_name;
|
||||
}
|
||||
}, {
|
||||
title: '添加时间',
|
||||
unresize: 'false',
|
||||
templet: function(data) {
|
||||
return ns.time_to_date(data.create_time);
|
||||
}
|
||||
}, {
|
||||
title: '操作',
|
||||
toolbar: '#operation',
|
||||
unresize: 'false',
|
||||
align:'right'
|
||||
}]
|
||||
]
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* 监听工具栏操作
|
||||
*/
|
||||
table.tool(function(obj) {
|
||||
var data = obj.data;
|
||||
switch (obj.event) {
|
||||
case 'edit': //编辑
|
||||
location.hash = ns.hash("printer://shop/template/edit", {"template_id": data.template_id});
|
||||
break;
|
||||
case 'del': //删除
|
||||
deleteTemplate(data.template_id);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
function deleteTemplate(template_id) {
|
||||
layer.confirm('确定要删除该模板吗?', function(index) {
|
||||
if (repeat_flag) return;
|
||||
repeat_flag = true;
|
||||
layer.close(index);
|
||||
|
||||
$.ajax({
|
||||
url: ns.url("printer://shop/template/delete"),
|
||||
data: {
|
||||
template_id: template_id
|
||||
},
|
||||
dataType: 'JSON',
|
||||
type: 'POST',
|
||||
success: function(res) {
|
||||
layer.msg(res.message);
|
||||
repeat_flag = false;
|
||||
if (res.code == 0) {
|
||||
table.reload({
|
||||
page: {
|
||||
curr: 1
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}, function() {
|
||||
layer.close();
|
||||
repeat_flag = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function add() {
|
||||
location.hash = ns.hash("printer://shop/template/add");
|
||||
}
|
||||
</script>
|
||||
238
addon/printer/storeapi/controller/Printer.php
Executable file
238
addon/printer/storeapi/controller/Printer.php
Executable file
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\printer\storeapi\controller;
|
||||
|
||||
use addon\printer\model\PrinterOrder;
|
||||
use app\model\order\OrderCommon as OrderCommonModel;
|
||||
use addon\printer\model\PrinterTemplate;
|
||||
use addon\printer\model\Printer as PrinterModel;
|
||||
use app\storeapi\controller\BaseStoreApi;
|
||||
|
||||
class Printer extends BaseStoreApi
|
||||
{
|
||||
/*
|
||||
* 小票打印列表
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
$model = new PrinterModel();
|
||||
$site_id = $this->params[ 'site_id' ] ?? 1;
|
||||
$store_id = $this->params[ 'store_id' ] ?? 1;
|
||||
$page = $this->params[ 'page' ] ?? 1;
|
||||
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
|
||||
$condition[] = [ 'site_id', '=', $site_id ];
|
||||
$condition[] = [ 'store_id', '=', $store_id ];
|
||||
$list = $model->getPrinterPageList($condition, $page, $page_size, 'printer_id desc');
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印机信息
|
||||
* @return false|string
|
||||
*/
|
||||
public function info()
|
||||
{
|
||||
$site_id = $this->params[ 'site_id' ] ?? 1;
|
||||
$store_id = $this->params[ 'store_id' ] ?? 1;
|
||||
$printer_id = $this->params[ 'printer_id' ] ?? 1;
|
||||
$model = new PrinterModel();
|
||||
$info = $model->getPrinterInfo([ [ 'printer_id', '=', $printer_id ], [ 'site_id', '=', $site_id ], [ 'store_id', '=', $store_id ] ]);
|
||||
$info[ 'data' ][ 'take_delivery_order_type' ] = explode(',', $info[ 'data' ][ 'take_delivery_order_type' ]);
|
||||
$info[ 'data' ][ 'order_pay_order_type' ] = explode(',', $info[ 'data' ][ 'order_pay_order_type' ]);
|
||||
|
||||
$order_common_model = new OrderCommonModel();
|
||||
$order_type_list = $order_common_model->getOrderTypeStatusList();
|
||||
unset($order_type_list[ 'all' ]);
|
||||
$info[ 'data' ][ 'order_type_list' ] = $order_type_list;
|
||||
return $this->response($info);
|
||||
}
|
||||
|
||||
public function getOrderType()
|
||||
{
|
||||
$order_common_model = new OrderCommonModel();
|
||||
$order_type_list = $order_common_model->getOrderTypeStatusList();
|
||||
unset($order_type_list[ 'all' ]);
|
||||
return $this->response($this->success($order_type_list));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印机品牌
|
||||
* @return false|string
|
||||
*/
|
||||
public function brand()
|
||||
{
|
||||
$model = new PrinterModel();
|
||||
$brand = $model->getPrinterBrand();
|
||||
return $this->response($brand);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印模板
|
||||
*/
|
||||
public function template()
|
||||
{
|
||||
$site_id = $this->params[ 'site_id' ] ?? 1;
|
||||
$template_model = new PrinterTemplate();
|
||||
$condition = [
|
||||
[ 'site_id', '=', $site_id ],
|
||||
];
|
||||
$template_list = $template_model->getPrinterTemplateList($condition, 'template_id,template_name,type', 'template_id desc');
|
||||
return $this->response($template_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加小票打印
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$model = new PrinterModel();
|
||||
$data = [
|
||||
'site_id' => $this->params[ 'site_id' ] ?? 1,
|
||||
'printer_name' => $this->params[ 'printer_name' ] ?? '',
|
||||
'brand' => $this->params[ 'brand' ] ?? '',
|
||||
'printer_code' => $this->params[ 'printer_code' ] ?? '',
|
||||
'printer_key' => $this->params[ 'printer_key' ] ?? '',
|
||||
'open_id' => $this->params[ 'open_id' ] ?? '',
|
||||
'apikey' => $this->params[ 'apikey' ] ?? '',
|
||||
'store_id' => $this->params[ 'store_id' ] ?? 1,
|
||||
'printer_type' => $this->params[ 'printer_type' ] ?? 'cloud',
|
||||
|
||||
//订单
|
||||
'order_pay_open' => $this->params[ 'order_pay_open' ] ?? 0,
|
||||
'order_pay_template_id' => $this->params[ 'order_pay_template_id' ] ?? 0,
|
||||
'order_pay_print_num' => $this->params[ 'order_pay_print_num' ] ?? 1,
|
||||
'order_pay_order_type' => $this->params[ 'order_pay_order_type' ] ?? '',
|
||||
|
||||
'take_delivery_open' => $this->params[ 'take_delivery_open' ] ?? 0,
|
||||
'take_delivery_template_id' => $this->params[ 'take_delivery_template_id' ] ?? 0,
|
||||
'take_delivery_print_num' => $this->params[ 'take_delivery_print_num' ] ?? 1,
|
||||
'take_delivery_order_type' => $this->params[ 'take_delivery_order_type' ] ?? '',
|
||||
|
||||
'manual_open' => $this->params[ 'manual_open' ] ?? 0,
|
||||
'template_id' => $this->params[ 'template_id' ] ?? 0,
|
||||
'print_num' => $this->params[ 'print_num' ] ?? 1,
|
||||
|
||||
//充值
|
||||
'recharge_open' => $this->params[ 'recharge_open' ] ?? 0,
|
||||
'recharge_template_id' => $this->params[ 'recharge_template_id' ] ?? 0,
|
||||
'recharge_print_num' => $this->params[ 'recharge_print_num' ] ?? 1,
|
||||
|
||||
'change_shifts_open' => $this->params[ 'change_shifts_open' ] ?? 0,
|
||||
'change_shifts_template_id' => $this->params[ 'change_shifts_template_id' ] ?? 0,
|
||||
'change_shifts_print_num' => $this->params[ 'change_shifts_print_num' ] ?? 1,
|
||||
|
||||
'host' => $this->params[ 'host' ] ?? '',
|
||||
'ip' => $this->params[ 'ip' ] ?? '',
|
||||
'port' => $this->params[ 'port' ] ?? '',
|
||||
'print_width' => $this->params[ 'print_width' ] ?? '58mm'
|
||||
];
|
||||
if ($data[ 'order_pay_order_type' ]) $data[ 'order_pay_order_type' ] = ',' . $data[ 'order_pay_order_type' ] . ',';
|
||||
if ($data[ 'take_delivery_order_type' ]) $data[ 'take_delivery_order_type' ] = ',' . $data[ 'take_delivery_order_type' ] . ',';
|
||||
return $this->response($model->addPrinter($data));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑小票打印
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$model = new PrinterModel();
|
||||
$data = [
|
||||
'printer_id' => $this->params[ 'printer_id' ] ?? 1,
|
||||
'site_id' => $this->params[ 'site_id' ] ?? 1,
|
||||
'printer_name' => $this->params[ 'printer_name' ] ?? '',
|
||||
'brand' => $this->params[ 'brand' ] ?? '',
|
||||
'printer_code' => $this->params[ 'printer_code' ] ?? '',
|
||||
'printer_key' => $this->params[ 'printer_key' ] ?? '',
|
||||
'open_id' => $this->params[ 'open_id' ] ?? '',
|
||||
'apikey' => $this->params[ 'apikey' ] ?? '',
|
||||
'store_id' => $this->params[ 'store_id' ] ?? 1,
|
||||
'printer_type' => $this->params[ 'printer_type' ] ?? 'cloud',
|
||||
|
||||
//订单
|
||||
'order_pay_open' => $this->params[ 'order_pay_open' ] ?? 0,
|
||||
'order_pay_template_id' => $this->params[ 'order_pay_template_id' ] ?? 0,
|
||||
'order_pay_print_num' => $this->params[ 'order_pay_print_num' ] ?? 1,
|
||||
'order_pay_order_type' => $this->params[ 'order_pay_order_type' ] ?? '',
|
||||
|
||||
'take_delivery_open' => $this->params[ 'take_delivery_open' ] ?? 0,
|
||||
'take_delivery_template_id' => $this->params[ 'take_delivery_template_id' ] ?? 0,
|
||||
'take_delivery_print_num' => $this->params[ 'take_delivery_print_num' ] ?? 1,
|
||||
'take_delivery_order_type' => $this->params[ 'take_delivery_order_type' ] ?? '',
|
||||
|
||||
'manual_open' => $this->params[ 'manual_open' ] ?? 0,
|
||||
'template_id' => $this->params[ 'template_id' ] ?? 0,
|
||||
'print_num' => $this->params[ 'print_num' ] ?? 1,
|
||||
|
||||
//充值
|
||||
'recharge_open' => $this->params[ 'recharge_open' ] ?? 0,
|
||||
'recharge_template_id' => $this->params[ 'recharge_template_id' ] ?? 0,
|
||||
'recharge_print_num' => $this->params[ 'recharge_print_num' ] ?? 1,
|
||||
|
||||
'change_shifts_open' => $this->params[ 'change_shifts_open' ] ?? 0,
|
||||
'change_shifts_template_id' => $this->params[ 'change_shifts_template_id' ] ?? 0,
|
||||
'change_shifts_print_num' => $this->params[ 'change_shifts_print_num' ] ?? 1,
|
||||
|
||||
'host' => $this->params[ 'host' ] ?? '',
|
||||
'ip' => $this->params[ 'ip' ] ?? '',
|
||||
'port' => $this->params[ 'port' ] ?? '',
|
||||
'print_width' => $this->params[ 'print_width' ] ?? '58mm'
|
||||
];
|
||||
if ($data[ 'order_pay_order_type' ]) {
|
||||
$data[ 'order_pay_order_type' ] = ',' . $data[ 'order_pay_order_type' ] . ',';
|
||||
$data[ 'order_pay_order_type' ] = str_replace(',,', ',', $data[ 'order_pay_order_type' ]);
|
||||
}
|
||||
if ($data[ 'take_delivery_order_type' ]) {
|
||||
$data[ 'take_delivery_order_type' ] = ',' . $data[ 'take_delivery_order_type' ] . ',';
|
||||
$data[ 'take_delivery_order_type' ] = str_replace(',,', ',', $data[ 'take_delivery_order_type' ]);
|
||||
}
|
||||
return $this->response($model->editPrinter($data));
|
||||
}
|
||||
|
||||
/*
|
||||
* 删除
|
||||
*/
|
||||
public function deletePrinter()
|
||||
{
|
||||
$printer_id = $this->params[ 'printer_id' ] ?? 0;
|
||||
$store_id = $this->params[ 'store_id' ] ?? 0;
|
||||
|
||||
$printer_model = new PrinterModel();
|
||||
$res = $printer_model->deletePrinter([ [ 'printer_id', '=', $printer_id ], [ 'store_id', '=', $store_id ] ]);
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试打印
|
||||
*/
|
||||
public function testPrint()
|
||||
{
|
||||
$printer_id = $this->params[ 'printer_id' ] ?? 0;
|
||||
$site_id = $this->params[ 'site_id' ] ?? 1;
|
||||
$print_model = new PrinterOrder();
|
||||
$res = $print_model->testPrint($printer_id, $site_id);
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新token
|
||||
*/
|
||||
public function refreshToken()
|
||||
{
|
||||
$printer_id = $this->params[ 'printer_id' ] ?? 0;
|
||||
$site_id = $this->params[ 'site_id' ] ?? 1;
|
||||
$print_model = new PrinterModel();
|
||||
$res = $print_model->refreshToken($printer_id, $site_id);
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user