chore(src): 所有代码上传
This commit is contained in:
@@ -1,38 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
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' => []
|
||||
<?php
|
||||
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' => []
|
||||
];
|
||||
@@ -1,20 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
return [
|
||||
'name' => 'printer',
|
||||
'title' => '小票打印',
|
||||
'description' => '小票打印',
|
||||
'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
|
||||
'status' => 1,
|
||||
'author' => '',
|
||||
'version' => '5.3.1',
|
||||
'version_no' => '525231212001',
|
||||
'content' => '',
|
||||
<?php
|
||||
return [
|
||||
'name' => 'printer',
|
||||
'title' => '小票打印',
|
||||
'description' => '小票打印',
|
||||
'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
|
||||
'status' => 1,
|
||||
'author' => '',
|
||||
'version' => '5.3.1',
|
||||
'version_no' => '525231212001',
|
||||
'content' => '',
|
||||
];
|
||||
@@ -1,25 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
/**
|
||||
* 应用安装
|
||||
*/
|
||||
class Install
|
||||
{
|
||||
/**
|
||||
* 执行安装
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return success();
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
/**
|
||||
* 应用安装
|
||||
*/
|
||||
class Install
|
||||
{
|
||||
/**
|
||||
* 执行安装
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return success();
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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' ]);
|
||||
}
|
||||
<?php
|
||||
|
||||
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' ]);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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',
|
||||
]);
|
||||
}
|
||||
<?php
|
||||
|
||||
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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
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' ]);
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
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' ]);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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',
|
||||
]);
|
||||
}
|
||||
<?php
|
||||
|
||||
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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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' ]);
|
||||
}
|
||||
<?php
|
||||
|
||||
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' ]);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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',
|
||||
]);
|
||||
}
|
||||
<?php
|
||||
|
||||
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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
<?php
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,320 +1,312 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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 ];
|
||||
|
||||
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' ]);
|
||||
}
|
||||
$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' ]);
|
||||
}
|
||||
$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[ '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 .= "" . $member_info[ "nickname" ] . "\n";
|
||||
}else{
|
||||
$content .= "" . $order_info[ "name" ] . "\n";
|
||||
}
|
||||
|
||||
}
|
||||
//联系方式
|
||||
if ($print_template[ 'buy_mobile' ] == 1) {
|
||||
if($order_info[ 'order_type' ] == 2){
|
||||
$content .= "" . $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;
|
||||
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
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 ];
|
||||
|
||||
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' ]);
|
||||
}
|
||||
$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' ]);
|
||||
}
|
||||
$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[ '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 .= "" . $member_info[ "nickname" ] . "\n";
|
||||
}else{
|
||||
$content .= "" . $order_info[ "name" ] . "\n";
|
||||
}
|
||||
|
||||
}
|
||||
//联系方式
|
||||
if ($print_template[ 'buy_mobile' ] == 1) {
|
||||
if($order_info[ 'order_type' ] == 2){
|
||||
$content .= "" . $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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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 ]);
|
||||
}
|
||||
<?php
|
||||
|
||||
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 ]);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
*/
|
||||
class PromotionType
|
||||
{
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return [ "name" => "小票打印", "type" => "printer" ];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
*/
|
||||
class PromotionType
|
||||
{
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return [ "name" => "小票打印", "type" => "printer" ];
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
<?php
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
/**
|
||||
* 应用卸载
|
||||
*/
|
||||
class UnInstall
|
||||
{
|
||||
/**
|
||||
* 执行卸载
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return success();
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\printer\event;
|
||||
|
||||
/**
|
||||
* 应用卸载
|
||||
*/
|
||||
class UnInstall
|
||||
{
|
||||
/**
|
||||
* 执行卸载
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return success();
|
||||
}
|
||||
}
|
||||
@@ -1,297 +1,289 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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) {
|
||||
model('printer')->rollback();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
model('printer')->commit();
|
||||
return $this->success($res);
|
||||
} 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();
|
||||
} else {
|
||||
return $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 $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新获取易联云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' => $printer_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 ************************/
|
||||
|
||||
<?php
|
||||
|
||||
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) {
|
||||
model('printer')->rollback();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
model('printer')->commit();
|
||||
return $this->success($res);
|
||||
} 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();
|
||||
} else {
|
||||
return $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 $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新获取易联云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' => $printer_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 ************************/
|
||||
|
||||
}
|
||||
@@ -1,411 +1,403 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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->error('', '没有可用的打印机');
|
||||
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);
|
||||
} 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);
|
||||
if ($res->error == 0) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', $res->error_description);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
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->error('', '没有可用的打印机');
|
||||
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);
|
||||
} 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);
|
||||
if ($res->error == 0) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', $res->error_description);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,114 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,27 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
<?php
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,269 +1,261 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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
|
||||
]);
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
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
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,134 +1,126 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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 ] ]);
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
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 ] ]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,238 +1,230 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
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