jh-admin/addon/cashier/event/PrinterContent.php

119 lines
5.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* SaaSMall商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 成都SAAS云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.gobuysaas.com
* =========================================================
*/
namespace addon\cashier\event;
use addon\cashier\model\Cashier;
use addon\printer\model\Printer;
use addon\printer\model\PrinterTemplate;
/**
* 打印内容
*/
class PrinterContent
{
public function handle($params)
{
if ($params[ 'type' ] == 'change_shifts') {
$print_model = new Printer();
$printer_data = $print_model->getPrinterList([ [ 'site_id', '=', $params[ 'site_id' ] ], [ 'store_id', '=', $params[ 'store_id' ] ], [ 'change_shifts_open', '=', 1 ] ])[ 'data' ] ?? [];
if (empty($printer_data)) return error(-1, '未找到可用的打印机');
if (isset($params[ 'record_id' ]) && !empty($params[ 'record_id' ])) {
$shifts_data = ( new Cashier() )->getChangeShiftsRecordInfo([
[ 'r.site_id', '=', $params[ 'site_id' ] ], [ 'r.store_id', '=', $params[ 'store_id' ] ], [ 'r.id', '=', $params[ 'record_id' ] ]
], 'r.*,u.username', 'r', [ [ 'user u', 'r.uid = u.uid', 'inner' ] ])[ 'data' ];
if (empty($shifts_data)) return error(-1, '未查询到交班记录');
$userinfo = [
'username' => $shifts_data[ 'username' ]
];
} else {
$shifts_data = ( new Cashier() )->getShiftsData($params[ 'site_id' ], $params[ 'store_id' ]);
$userinfo = $params[ 'userinfo' ];
}
$res_data = [];
foreach ($printer_data as $k => $v) {
//此处应该根据打印机不同分别设置返回不同的数据。当前为易联云
$array = [];
$array[ 'printer_info' ] = $v;
$template_id = $v[ 'change_shifts_template_id' ];
$print_num = $v[ 'change_shifts_print_num' ];
$print_template_model = new PrinterTemplate();
$print_template = $print_template_model->getPrinterTemplateInfo([ [ 'template_id', '=', $template_id ] ])[ 'data' ];
if (empty($print_template)) continue;
$array[ 'printer_code' ] = $v[ 'printer_code' ]; //商户授权机器码
$array[ 'origin_id' ] = time();
$array[ 'content' ] = $this->handleChangeShiftsPrintContent($print_num, $print_template, $userinfo, $shifts_data);
$res_data[] = $array;
}
return $res_data;
}
}
/**
* 获取收银交班打印内容
* @param $print_num
* @param $print_template
* @param $userinfo
* @param $shifts_data
* @return string
*/
private function handleChangeShiftsPrintContent($print_num, $print_template, $userinfo, $shifts_data)
{
$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>" . $print_template[ 'site_name' ] . "</center></FS></FH2>";
$content .= str_repeat('.', 32);
}
$content .= "交班员工:" . $userinfo[ 'username' ] . "\n";
$content .= "上班时间:" . ( $shifts_data[ 'start_time' ] ? date("Y-m-d H:i:s", $shifts_data[ 'start_time' ]) : '初始化' ) . "\n";
$content .= "交班时间:" . date("Y-m-d H:i:s", $shifts_data[ 'end_time' ]) . "\n";
$content .= str_repeat('.', 32);
$content .= "<FH2><FS>总销售</FS></FH2>\n";
$content .= "开单销售:¥" . $shifts_data[ "billing_money" ] . "\n";
$content .= "售卡销售:¥" . $shifts_data[ "buycard_money" ] . "\n";
$content .= str_repeat('.', 32);
$content .= "<FH2><FS>会员充值</FS></FH2>\n";
$content .= "会员充值:¥" . $shifts_data[ "recharge_money" ] . "\n";
$content .= str_repeat('.', 32);
$content .= "<FH2><FS>应收金额</FS></FH2>\n";
$content .= "开单销售:¥" . $shifts_data[ "billing_money" ] . "\n";
$content .= "售卡销售:¥" . $shifts_data[ "buycard_money" ] . "\n";
$content .= "会员充值:¥" . $shifts_data[ "recharge_money" ] . "\n";
$content .= "订单退款:¥" . $shifts_data[ "refund_money" ] . "\n";
$content .= str_repeat('.', 32);
if ($shifts_data[ "billing_money" ] > 0 || $shifts_data[ "buycard_money" ] > 0 || $shifts_data[ "recharge_money" ] > 0) {
$content .= "<FH2><FS>支付统计</FS></FH2>\n";
if ($shifts_data[ "cash" ] > 0) $content .= "现金收款:¥" . $shifts_data[ "cash" ] . "\n";
if ($shifts_data[ "wechatpay" ] > 0) $content .= "微信收款:¥" . $shifts_data[ "wechatpay" ] . "\n";
if ($shifts_data[ "alipay" ] > 0) $content .= "支付宝收款:¥" . $shifts_data[ "alipay" ] . "\n";
if ($shifts_data[ "own_wechatpay" ] > 0) $content .= "个人微信收款:¥" . $shifts_data[ "own_wechatpay" ] . "\n";
if ($shifts_data[ "own_alipay" ] > 0) $content .= "个人支付宝收款:¥" . $shifts_data[ "own_alipay" ] . "\n";
if ($shifts_data[ "own_pos" ] > 0) $content .= "个人POS收款" . $shifts_data[ "own_pos" ] . "\n";
}
return $content;
}
}