1682 行
78 KiB
PHP
可执行文件
1682 行
78 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace PayApi\Controller;
|
||
|
||
use Common\Model\RetailPrinterModel;
|
||
use Common\Model\StoreConfigModel;
|
||
use Think\Controller;
|
||
|
||
vendor('Yly.Oauth.YlyOauthClient');
|
||
|
||
//[1.9.20]
|
||
|
||
/**
|
||
* 打印小票 2019-6-27
|
||
* Class PrinterController
|
||
* @package Api\Controller
|
||
*/
|
||
class PrinterController extends Controller
|
||
{
|
||
/**
|
||
* 线下和线上订单打印 2019-6-27
|
||
* @param $store_id 门店id
|
||
* @param $bill_id 订单id
|
||
* @return mixed
|
||
* @throws \Exception
|
||
*/
|
||
public function linePrinting_v1($store_id, $bill_id, $force = false)
|
||
{
|
||
// 防止重复打印:使用Redis记录已打印的订单,有效期24小时
|
||
if (!$force && C('IS_SET_REDIS')) {
|
||
$print_lock_key = 'print_lock_' . $store_id . '_' . $bill_id;
|
||
$ApiRedis = new \Addons\Api\RedisController();
|
||
if ($ApiRedis::$redis->get($print_lock_key)) {
|
||
return array('status' => 0, 'msg' => '该订单已打印,请勿重复打印');
|
||
}
|
||
$ApiRedis::$redis->setex($print_lock_key, 86400, 1);
|
||
}
|
||
$PrinterModel = new RetailPrinterModel();
|
||
$parameter = array(
|
||
'store_id' => $store_id,
|
||
'bill_id' => $bill_id
|
||
);
|
||
$param_info = $PrinterModel->verifyInfo($parameter); //验证参数以及是否开启打印机
|
||
if ($param_info['status'] == 0) {
|
||
return $param_info;
|
||
}
|
||
$printSet = $param_info['data']['print_set'];
|
||
$parameter['print_set'] = $printSet;
|
||
$print_info = $PrinterModel->getPrintInfo($parameter); //获取打印信息
|
||
if ($print_info['status'] == 0) {
|
||
return $print_info;
|
||
}
|
||
$type = $print_info['data']['type'];
|
||
$sell_goods = $print_info['data']['sell_goods'];
|
||
$printItem = $print_info['data']['print_info'];
|
||
|
||
// 获取打印配置--store_config--mobile_set
|
||
$StoreConfigModel = new StoreConfigModel();
|
||
$mobile_set = $StoreConfigModel->getFind(['store_id' => $store_id], 'mobile_set');
|
||
if ($mobile_set['mobile_set'] == 1) { // 需要隐藏手机号
|
||
if ($printItem['address_info']['phone']) {
|
||
$printItem['address_info']['phone'] = preg_replace('/(\d{3})\d{4}(\d{4})/', '$1****$2', $printItem['address_info']['phone']);
|
||
}
|
||
if ($printItem['vip_info']['mobile_phone']) {
|
||
$printItem['vip_info']['mobile_phone'] = preg_replace('/(\d{3})\d{4}(\d{4})/', '$1****$2', $printItem['vip_info']['mobile_phone']);
|
||
}
|
||
}
|
||
|
||
$pageGoods = array();//分页打印商品
|
||
foreach ($printSet as $value) {
|
||
//先判断是否开启线上打印
|
||
$printItem['printSet'] = $value;
|
||
if ($value[$PrinterModel::ONLINE_STATUS] == 2 && $type == 1 || $type == 2 && $value[$PrinterModel::LINE_STATUS] == 2) {
|
||
//先判断打印机是否开启线上或线下打印和分页打印 1:开启 2:不开启
|
||
if ($value[$PrinterModel::IS_PAGING] == 1) {
|
||
//继续判断是否开启标签打印 1:整单打印 2:分单打印
|
||
if ($value[$PrinterModel::PRINT_TYPE] == 1) {
|
||
//整单并分页
|
||
if (count($sell_goods) <= $value[$PrinterModel::PAGES]) {
|
||
//不到分页条数
|
||
$printItem['goodsList'] = $sell_goods;
|
||
$this->printOrder_v1($printItem);
|
||
} else {
|
||
//分单打印并开启分页
|
||
foreach ($sell_goods as $k => $v) {
|
||
if (count($pageGoods) < $value[$PrinterModel::PAGES]) {
|
||
$pageGoods[] = $v;
|
||
if (count($pageGoods) == $value[$PrinterModel::PAGES]) {
|
||
$printItem['goodsList'] = $pageGoods;
|
||
$this->printOrder_v1($printItem);
|
||
$pageGoods = array();
|
||
}
|
||
}
|
||
}
|
||
if (count($pageGoods) > 0) {
|
||
$printItem['goodsList'] = $pageGoods;
|
||
$this->printOrder_v1($printItem);
|
||
}
|
||
}
|
||
} else {
|
||
//开启分页 及标签打印
|
||
$label_goods = array();
|
||
$label = explode(',', trim($value[$PrinterModel::LABEL_ID], ','));
|
||
foreach ($sell_goods as $v) {
|
||
foreach ($label as $lval) {
|
||
if ($v['label_id'] == $lval) {
|
||
$label_goods[] = $v;
|
||
}
|
||
}
|
||
}
|
||
if (count($label_goods) > 0) {
|
||
foreach ($label_goods as $k => $v) {
|
||
if (count($pageGoods) < $value[$PrinterModel::PAGES]) {
|
||
$pageGoods[] = $v;
|
||
if (count($pageGoods) == $value['pages']) {
|
||
$printItem['goodsList'] = $pageGoods;
|
||
$this->printOrder_v1($printItem);
|
||
$pageGoods = array();
|
||
}
|
||
}
|
||
}
|
||
if (count($pageGoods) > 0) {
|
||
$printItem['goodsList'] = $pageGoods;
|
||
$this->printOrder_v1($printItem);
|
||
}
|
||
}
|
||
}
|
||
} else {
|
||
//没有开启分页
|
||
//继续判断是否开启标签打印 1:整单打印 2:分单打印
|
||
if ($value[$PrinterModel::PRINT_TYPE] == 1) {
|
||
$printItem['goodsList'] = $sell_goods;
|
||
$this->printOrder_v1($printItem);
|
||
} else {
|
||
//未开启分页开启分单
|
||
$label_goods = array();
|
||
$label = explode(',', trim($value[$PrinterModel::LABEL_ID], ','));
|
||
foreach ($sell_goods as $v) {
|
||
foreach ($label as $lval) {
|
||
if ($v['label_id'] == $lval) {
|
||
$label_goods[] = $v;
|
||
}
|
||
}
|
||
}
|
||
if (count($label_goods) > 0) {
|
||
$printItem['goodsList'] = $label_goods;
|
||
$this->printOrder_v1($printItem);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 调用打印订单 2019-6-27
|
||
* store_name 门店名称
|
||
* billOrder billOrder表数据
|
||
* billOnline 线上订单详情
|
||
* billDiscount 优惠详情
|
||
* goodsList sell商品详情表数据
|
||
* payList 支付方式数组
|
||
* addressInfo 地址详情
|
||
* printSet 打印机详情
|
||
* vipInfo 会员详情
|
||
* cashier_name 收银员姓名
|
||
* guide_name 导购员姓名
|
||
* @param array $printItem
|
||
* @throws \Exception
|
||
*/
|
||
protected function printOrder_v1($printItem = array())
|
||
{
|
||
$PrinterModel = D('RetailPrinter');
|
||
$BillModel = D('RetailBillOrder');
|
||
if ($printItem['printSet'][$PrinterModel::PRINTER_TYPE] == 1) {
|
||
//飞蛾打印
|
||
switch ($printItem['bill_order'][$BillModel::ORDER_TYPE]) {
|
||
case 1:
|
||
//购买订单
|
||
$this->FePrintsPlaceOrder_v1($printItem);
|
||
break;
|
||
case 2:
|
||
//退款订单
|
||
$this->FePrintsRefundOrder_v1($printItem);
|
||
break;
|
||
case 3:
|
||
//换货订单
|
||
$this->FePrintsExchangeGoods($printItem);
|
||
break;
|
||
}
|
||
} else if ($printItem['printSet'][$PrinterModel::PRINTER_TYPE] == 2) {
|
||
//易连云
|
||
switch ($printItem['bill_order'][$BillModel::ORDER_TYPE]) {
|
||
case 1:
|
||
//购买订单
|
||
$this->YlyPrintsPlaceOrder_v1($printItem);
|
||
break;
|
||
case 2:
|
||
//退款订单
|
||
$this->YlyPrintsRefundOrder_v1($printItem);
|
||
break;
|
||
case 3:
|
||
//换货订单
|
||
$this->YlyPrintsExchangeGoods($printItem);
|
||
break;
|
||
}
|
||
} else if ($printItem['printSet'][$PrinterModel::PRINTER_TYPE] == 3) {
|
||
//易连云
|
||
switch ($printItem['bill_order'][$BillModel::ORDER_TYPE]) {
|
||
case 1:
|
||
//购买订单
|
||
A('Api/Xpyun')->buy($printItem);
|
||
break;
|
||
case 2:
|
||
//退款订单
|
||
A('Api/Xpyun')->refund($printItem);
|
||
break;
|
||
case 3:
|
||
//换货订单
|
||
A('Api/Xpyun')->exchange($printItem);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 飞蛾打印购买订单
|
||
* @param array $printItem [store_name=>门店名称,billOrder=>billOrder表数据,
|
||
* billOnline=>线上订单详情,billDiscount=>优惠详情,goodsList=>sell商品详情表数据
|
||
* payList=>支付方式数组,addressInfo=>地址详情,printSet=>打印机详情,vipInfo=>会员详情
|
||
* cashier_name=>收银员姓名,guide_name=>导购员姓名,advance_order=>预售订单信息]
|
||
* @return string
|
||
*/
|
||
protected function FePrintsPlaceOrder_v1($printItem = array())
|
||
{
|
||
$PrinterModel = D('RetailPrinter');
|
||
$BillModel = D('RetailBillOrder');
|
||
$BillOnlineModel = D('RetailBillOnline');
|
||
$BillDisModel = D('RetailBillDiscount');
|
||
$SellModel = D('RetailSell');
|
||
$printSet = $printItem['printSet'];
|
||
$bill_order = $printItem['bill_order'];
|
||
$bill_online = $printItem['bill_online'];
|
||
$bill_discount = $printItem['bill_discount'];
|
||
$goodsList = $printItem['goodsList'];
|
||
$pay_list = $printItem['pay_list'];
|
||
$address_info = $printItem['address_info'];
|
||
if ($bill_online['order_genre'] == 4) {
|
||
$advance_order = $printItem['advance_order'];
|
||
}
|
||
|
||
$content[] = "<CB>-- #" . $bill_order['print_number'] . " --</CB>";
|
||
|
||
if ($printSet[$PrinterModel::TITLE]) {
|
||
$content = array('title' => "<CB>{$printSet[$PrinterModel::TITLE]}</CB>");//title为自定义头部信息,如果没有显示门店名
|
||
}
|
||
$content[] = "<L><C>{$printItem['store_name']}</C></L>";//title为自定义头部信息,如果没有显示门店名
|
||
$content[] = '';
|
||
$content[] = '';
|
||
$content[] = "订单时间:" . date('Y-m-d H:i:s', $bill_order[$BillModel::ADD_TIME]);
|
||
if ($bill_online['order_genre'] == 4) {
|
||
if ($advance_order['advance_type'] == 2) {
|
||
$content[] = "定金支付时间:" . $advance_order['earnest_pay_time'];
|
||
if ($advance_order['state'] == 2) {
|
||
$content[] = "尾款支付时间:" . $advance_order['tail_time'];
|
||
}
|
||
} else {
|
||
$content[] = "支付时间:" . $advance_order['tail_time'];
|
||
}
|
||
}
|
||
$content[] = "订单号:<BOLD>{$bill_order[$BillModel::ORDER_NO]}</BOLD>";
|
||
if (!empty($printItem['cashier_name'])) {
|
||
$content[] = "收 银 员:<BOLD>{$printItem['cashier_name']}</BOLD>";
|
||
}
|
||
if (!empty($printItem['guide_name'])) {
|
||
$content[] = "导 购 员:<BOLD>{$printItem['guide_name']}</BOLD>";
|
||
}
|
||
$content[] = '名称 数量 单价 应收';
|
||
$content[] = '------------------------------';
|
||
foreach ($goodsList as $k => $val) {
|
||
$goods_name = $val[$SellModel::GOODS_NAME] ? $val[$SellModel::GOODS_NAME] : '无码商品';
|
||
if (!empty($val['skuinfo'])) {
|
||
$sku_name = json_decode($val['skuinfo'], true)[0]['sku'];
|
||
$goods_name = $goods_name . ":" . $sku_name;
|
||
} else if (!empty($val[$SellModel::SKU_JSON_INFO])) {
|
||
$sku_name = json_decode($val[$SellModel::SKU_JSON_INFO], true)['name'];
|
||
$goods_name = $goods_name . ":" . $sku_name;
|
||
}
|
||
$content[] = "{$goods_name}";//商品名
|
||
$str = '';
|
||
if ($val[$SellModel::PRICING_METHOD] == 1 || !empty($val[$SellModel::SKU_JSON_INFO])) {
|
||
$str .= ' x' . str_pad(round($val[$SellModel::NUM], 2), '8', ' ', STR_PAD_RIGHT);
|
||
} else if ($val[$SellModel::PRICING_METHOD] == 2) {
|
||
$str .= ' x' . str_pad(round($val[$SellModel::NUM], 2) . $val['company'], '8', ' ', STR_PAD_RIGHT);
|
||
}
|
||
$str .= '' . str_pad($val['unit_price'], '8', ' ', STR_PAD_RIGHT);
|
||
$str .= '' . str_pad($val['before_money'], '8', ' ', STR_PAD_RIGHT);
|
||
$content[] = $str;
|
||
}
|
||
$content[] = '------------------------------';
|
||
$content[] = "<BOLD>合 计:{$bill_order['before_money']}元</BOLD>";
|
||
$content[] = "<BOLD>应 收:{$bill_order['all_money']}元</BOLD>";
|
||
if ($bill_online['order_genre'] == 4 && $advance_order['advance_type'] == 2) {
|
||
$content[] = "<BOLD><B>实收定金:{$advance_order['all_earnest_price']}元</B></BOLD>";
|
||
if (!empty($advance_order['all_arrive_price'])) {
|
||
$content[] = "定金抵扣金额:<BOLD>{$advance_order['all_arrive_price']}元</BOLD>";
|
||
}
|
||
if ($advance_order['state'] == 2) {
|
||
$content[] = "<BOLD><B>实收尾款:{$advance_order['tail_price']}元</B></BOLD>";
|
||
} else if ($advance_order['state'] == 1) {
|
||
$content[] = "待付尾款:<BOLD>{$advance_order['tail_price']}</BOLD>元";
|
||
}
|
||
} else {
|
||
$content[] = "<BOLD><B>实收:{$bill_order['amount_received']}元</B></BOLD>";
|
||
}
|
||
if (count($pay_list) == 1) {
|
||
if ($bill_online['order_genre'] == 4) {
|
||
if ($advance_order['advance_type'] == 2) {
|
||
$content[] = "支付方式:";
|
||
$content[] = $pay_list[0]['pay_type_name'] . ":" . $pay_list[0]['name'] . "\n";
|
||
} else {
|
||
$content[] = "支付方式:" . "{$pay_list[0]['name']}";
|
||
}
|
||
} else {
|
||
$content[] = "支付方式:" . "<BOLD>{$pay_list[0]['name']}</BOLD>";
|
||
}
|
||
} else {
|
||
$content[] = "支付方式:" . "<BOLD>组合支付</BOLD>";
|
||
if ($bill_online['order_genre'] == 4) {
|
||
//预售
|
||
foreach ($pay_list as $v) {
|
||
$content[] = "{$v['pay_type_name']}-{$v['name']}";
|
||
}
|
||
} else {
|
||
foreach ($pay_list as $v) {
|
||
$content[] = "{$v['name']}:" . "<BOLD>{$v['money']}</BOLD>";
|
||
}
|
||
}
|
||
}
|
||
if ($bill_order[$BillModel::TYPE] == 2 && !empty($bill_order[$BillModel::GIVE_CHANGE]) && floatval($bill_order[$BillModel::GIVE_CHANGE]) > 0) {
|
||
$content[] = "找零:<BOLD>{$bill_order[$BillModel::GIVE_CHANGE]}元</BOLD>";
|
||
}
|
||
if ($bill_order[$BillModel::TYPE] == 2 && !empty($bill_order[$BillModel::ZERO_STORAGE]) && floatval($bill_order[$BillModel::ZERO_STORAGE]) > 0) {
|
||
$content[] = "存零:<BOLD>{$bill_order[$BillModel::ZERO_STORAGE]}元</BOLD>";
|
||
}
|
||
if (!empty($bill_order[$BillModel::VID]) && $bill_discount['vip_less_money'] > 0) {
|
||
$content[] = "会员价已优惠:<BOLD>{$bill_discount[$BillDisModel::VIP_LESS_MONEY]}元</BOLD>";
|
||
}
|
||
if (!empty($bill_order[$BillModel::VID]) && $bill_discount['vip_dis_money'] > 0) {
|
||
$content[] = "会员 折扣:<BOLD>{$bill_discount[$BillDisModel::VIP_DIS_MONEY]}元</BOLD>";
|
||
}
|
||
if ((!empty($bill_order[$BillModel::VID]) || $bill_discount['coupon_type'] == 3) && $bill_discount['coupon_money'] > 0) {
|
||
$content[] = "优 惠 券:<BOLD>{$bill_discount[$BillDisModel::COUPON_MONEY]}元</BOLD>";
|
||
}
|
||
if ($bill_discount['pay_coupon_fee'] > 0) {
|
||
$content[] = "代 金 券:<BOLD>{$bill_discount['pay_coupon_fee']}元</BOLD>";
|
||
}
|
||
if (!empty($bill_order[$BillModel::VID])) {
|
||
if ($bill_discount['integral_dis_money'] > 0) {
|
||
if ($bill_discount['integral_marketing'] == 2) {
|
||
$content[] = "购买 积分:<BOLD>{$bill_discount[$BillDisModel::INTEGRAL_DIS_MONEY]}</BOLD>元";
|
||
} else {
|
||
$content[] = "积分 抵扣:<BOLD>{$bill_discount[$BillDisModel::INTEGRAL_DIS_MONEY]}</BOLD>元";
|
||
}
|
||
}
|
||
if (!empty($bill_discount['use_integral'])) {
|
||
$content[] = "扣除 积分:<BOLD>{$bill_discount[$BillDisModel::USE_INTEGRAL]}</BOLD>";
|
||
}
|
||
}
|
||
if (!empty($bill_discount[$BillDisModel::CASHIER_DIS_MONEY])) {
|
||
$content[] = "整单折扣优惠:<BOLD>{$bill_discount[$BillDisModel::CASHIER_DIS_MONEY]}</BOLD>元";
|
||
}
|
||
if (!empty($bill_discount[$BillDisModel::CASHIER_MANUAL_MONEY])) {
|
||
$content[] = "单品打折优惠:<BOLD>{$bill_discount[$BillDisModel::CASHIER_MANUAL_MONEY]}</BOLD>元";
|
||
}
|
||
if (!empty($bill_discount[$BillDisModel::SMALL_CHANGES_MONEY])) {
|
||
$content[] = "收银员抹零:<BOLD>{$bill_discount[$BillDisModel::SMALL_CHANGES_MONEY]}</BOLD>元";
|
||
}
|
||
if ($bill_order[$BillModel::TYPE] == 1 && ($bill_online[$BillOnlineModel::PICKUP_TYPE] == 2 || $bill_online[$BillOnlineModel::PICKUP_TYPE] == 3 || $bill_online[$BillOnlineModel::PICKUP_TYPE] == 5)) {
|
||
$content[] = "配 送 费:<BOLD>{$bill_online[$BillOnlineModel::DELIVERY_FEE]}</BOLD>元";
|
||
}
|
||
if (!empty($printItem['vip_info'])) {
|
||
//会员买单
|
||
$VipModel = D('RetailVip');
|
||
$vip_info = $printItem['vip_info'];
|
||
$vipName = mb_substr($vip_info['name'], 0, 1, 'utf-8');
|
||
$name = '';
|
||
for ($i = 1; $i < mb_strlen($vip_info['name'], 'utf-8'); $i++) {
|
||
$name .= '*';
|
||
}
|
||
$vipName = $vipName . $name;
|
||
$vipName = $vipName ? $vipName : $vip_info[$VipModel::NICK_NAME];
|
||
// $vipPhone = str_replace(substr($vip_info[$VipModel::MOBILE_PHONE], 3, 4), '****', $vip_info[$VipModel::MOBILE_PHONE]);
|
||
$vipPhone = $printItem['vip_info']['mobile_phone'];
|
||
$content[] = '------------------------------';
|
||
$content[] = "会员姓名:{$vipName}";
|
||
$content[] = "会员手机:{$vipPhone}";
|
||
$content[] = "会员余额:{$vip_info[$VipModel::BALANCE]}";
|
||
}
|
||
if ($printItem['bill_order']['third_vip_code']) {
|
||
$content[] = "会员名称:{$printItem['bill_order']['third_vip_name']}";
|
||
$content[] = "会员标识:{$printItem['bill_order']['third_vip_code']}";
|
||
}
|
||
|
||
$content[] = '------------------------------';
|
||
if ($bill_order['type'] == 1) {
|
||
$content[] = "配送方式:" . "<BOLD>{$bill_online['pickup_name']}</BOLD>";
|
||
}
|
||
if ($bill_order[$BillModel::TYPE] == 1 && !empty($bill_online['user_select_time'])) {
|
||
$user_select_time = date('Y-m-d H:i:s', $bill_online['user_select_time']);
|
||
switch ($bill_online[$BillOnlineModel::PICKUP_TYPE]) {
|
||
case 1:
|
||
$content[] = "自提时间:" . "<BOLD>{$user_select_time}</BOLD>";
|
||
break;
|
||
case 2:
|
||
$content[] = "配送时间:" . "<BOLD>{$user_select_time}</BOLD>";
|
||
break;
|
||
}
|
||
}
|
||
if (!empty($address_info)) {
|
||
if (!($bill_online['order_genre'] == 4 && $bill_online['pickup_type'] == 1)) {
|
||
$content[] = "地 址:" . "<BOLD>{$address_info['address']}</BOLD>";
|
||
}
|
||
$consignee = $bill_online['pickup_type'] == 1 ? "取 货 人:" : "收 货 人";
|
||
$content[] = $consignee . "<BOLD>{$address_info['name']}先生/女士</BOLD>";
|
||
$content[] = "手 机 号:" . "<BOLD>{$address_info['phone']}</BOLD>";
|
||
}
|
||
if (!empty($bill_online[$BillOnlineModel::REMARK])) {
|
||
$content[] = '------------------------------';
|
||
$content[] = "买家留言:" . "<BOLD><B>{$bill_online[$BillOnlineModel::REMARK]}</B></BOLD>";
|
||
}
|
||
$content[] = '';
|
||
$content[] = "<C>{$printSet[$PrinterModel::FOOTER]}</C>";//title为自定义头部信息,如果没有显示门店名
|
||
$status = $this->fe_print($printSet[$PrinterModel::API_NAME], $printSet[$PrinterModel::API_KEY], $printSet[$PrinterModel::PRINTER_SN], implode('<BR>', $content), 1);
|
||
if ($status == 'ok') {
|
||
return 'ok';
|
||
} else {
|
||
return 'error';
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 飞蛾打印退款订单 2019-6-27
|
||
* store_name 门店名称
|
||
* billOrder billOrder表数据
|
||
* billOnline 线上订单详情
|
||
* billDiscount 优惠详情
|
||
* goodsList sell商品详情表数据
|
||
* payList 支付方式数组
|
||
* addressInfo 地址详情
|
||
* printSet 打印机详情
|
||
* vipInfo 会员详情
|
||
* @param array $printItem
|
||
* @return string
|
||
*/
|
||
public function FePrintsRefundOrder_v1($printItem = array())
|
||
{
|
||
$PrinterModel = D('RetailPrinter');
|
||
$BillModel = D('RetailBillOrder');
|
||
$BillDisModel = D('RetailBillDiscount');
|
||
$SellModel = D('RetailSell');
|
||
$printSet = $printItem['printSet'];
|
||
$order = $printItem['bill_order'];
|
||
$billOnline = $printItem['bill_online'];
|
||
$billDiscount = $printItem['bill_discount'];
|
||
$goodsList = $printItem['goodsList'];
|
||
$payList = $printItem['pay_list'];
|
||
if ($printSet[$PrinterModel::TITLE]) {
|
||
$content = array('title' => "<CB>{$printSet[$PrinterModel::TITLE]}</CB>");//title为自定义头部信息,如果没有显示门店名
|
||
}
|
||
$content[] = "<L><C>{$printItem['store_name']}</C></L>";//title为自定义头部信息,如果没有显示门店名
|
||
$content[] = '';
|
||
$content[] = "订单编号:<BOLD>{$order[$BillModel::ORDER_NO]}</BOLD>";
|
||
$content[] = "订单类型:退款订单";
|
||
$content[] = "申请时间:" . date('Y-m-d H:i:s', $order[$BillModel::ADD_TIME]);
|
||
if (!empty($order["finish_time"])) {
|
||
$content[] = "退款时间:" . date('Y-m-d H:i:s', $order["finish_time"]);
|
||
}
|
||
$content[] = '名称 数量 单价';
|
||
$content[] = '------------------------------';
|
||
foreach ($goodsList as $k => $val) {
|
||
$goods_name = $val[$SellModel::GOODS_NAME] ? $val[$SellModel::GOODS_NAME] : '无码商品';
|
||
if (!empty($val['skuinfo'])) {
|
||
$sku_name = json_decode($val['skuinfo'], true)[0]['sku'];
|
||
$goods_name = $goods_name . ":" . $sku_name;
|
||
} else if (!empty($val[$SellModel::SKU_JSON_INFO])) {
|
||
$sku_name = json_decode($val[$SellModel::SKU_JSON_INFO], true)['name'];
|
||
$goods_name = $goods_name . ":" . $sku_name;
|
||
}
|
||
$content[] = "{$goods_name}";//商品名
|
||
$str = '';
|
||
if ($val[$SellModel::PRICING_METHOD] == 1 || !empty($val[$SellModel::SKU_JSON_INFO])) {
|
||
$str .= ' X' . str_pad(round($val[$SellModel::NUM], 2), '6', ' ', STR_PAD_RIGHT);
|
||
} else if ($val[$SellModel::PRICING_METHOD] == 2) {
|
||
$str .= ' X' . str_pad(round($val[$SellModel::NUM], 2) . $val['company'], '6', ' ', STR_PAD_RIGHT);
|
||
}
|
||
$str .= '' . str_pad($val[$SellModel::PRICE], '9', ' ', STR_PAD_RIGHT);
|
||
$content[] = $str;
|
||
}
|
||
$content[] = '------------------------------';
|
||
if (count($payList) == 1) {
|
||
$content[] = "退款方式:" . "<BOLD>{$payList[0]['name']}</BOLD>";
|
||
} else {
|
||
$content[] = "退款方式:" . "<BOLD>组合退款</BOLD>";
|
||
foreach ($payList as $v) {
|
||
$content[] = "{$v['name']}:" . "<BOLD>{$v['money']}</BOLD>";
|
||
}
|
||
}
|
||
if ($billDiscount['integral_dis_money'] > 0) {
|
||
if ($billDiscount['integral_marketing'] == 2) {
|
||
$content[] = "购买积分金额:{$billDiscount[$BillDisModel::INTEGRAL_DIS_MONEY]}元";
|
||
} else {
|
||
$content[] = "积分抵扣:{$billDiscount[$BillDisModel::INTEGRAL_DIS_MONEY]}元";
|
||
}
|
||
}
|
||
if ($billDiscount['use_integral'] > 0) {
|
||
$content[] = "退还积分:" . $billDiscount[$BillDisModel::USE_INTEGRAL];
|
||
}
|
||
|
||
$print_time = date('Y/m/d H:i:s', time());
|
||
if ($billOnline['pickup_type'] == 2) {
|
||
$content[] = "退还配送费:" . "<BOLD>{$billOnline["delivery_fee"]}元</BOLD>";
|
||
}
|
||
if ($billDiscount['pay_coupon_fee'] > 0) {
|
||
$content[] = "代金券:" . "<BOLD>{$billDiscount['pay_coupon_fee']}元</BOLD>";
|
||
}
|
||
$content[] = "实退金额:" . "<BOLD>{$order[$BillModel::ALL_MONEY]}元</BOLD>";
|
||
$content[] = "打印时间:" . "<BOLD>{$print_time}</BOLD>";
|
||
$content[] = '';
|
||
$content[] = "<C>{$printSet[$PrinterModel::FOOTER]}</C>";//title为自定义头部信息,如果没有显示门店名
|
||
$status = $this->fe_print($printSet[$PrinterModel::API_NAME], $printSet[$PrinterModel::API_KEY], $printSet[$PrinterModel::PRINTER_SN], implode('<BR>', $content), 1);
|
||
if ($status == 'ok') {
|
||
return 'ok';
|
||
} else {
|
||
return 'error';
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 飞蛾打印换货订单 2020-3-20
|
||
* store_name 门店名称
|
||
* billOrder billOrder表数据
|
||
* billOnline 线上订单详情
|
||
* billDiscount 优惠详情
|
||
* goodsList sell商品详情表数据
|
||
* addressInfo 地址详情
|
||
* printSet 打印机详情
|
||
* vipInfo 会员详情
|
||
* @param array $printItem
|
||
* @return string
|
||
*/
|
||
public function FePrintsExchangeGoods($printItem)
|
||
{
|
||
$PrinterModel = D('RetailPrinter');
|
||
$BillModel = D('RetailBillOrder');
|
||
$BillDisModel = D('RetailBillDiscount');
|
||
$SellModel = D('RetailSell');
|
||
$printSet = $printItem['printSet'];
|
||
$order = $printItem['bill_order'];
|
||
$billDiscount = $printItem['bill_discount'];
|
||
$goodsList = $printItem['goodsList'];
|
||
$payList = $printItem['pay_list'];
|
||
if ($printSet[$PrinterModel::TITLE]) {
|
||
$content = array('title' => "<CB>{$printSet[$PrinterModel::TITLE]}</CB>");//title为自定义头部信息,如果没有显示门店名
|
||
}
|
||
$content[] = "<L><C>{$printItem['store_name']}</C></L>";//title为自定义头部信息,如果没有显示门店名
|
||
$content[] = '';
|
||
$content[] = "订单编号:<BOLD>{$order[$BillModel::ORDER_NO]}</BOLD>";
|
||
$content[] = "订单类型:换货订单";
|
||
$content[] = "申请时间:" . date('Y-m-d H:i:s', $order[$BillModel::ADD_TIME]);
|
||
if (!empty($order["finish_time"])) {
|
||
$content[] = "换货时间:" . date('Y-m-d H:i:s', $order["finish_time"]);
|
||
}
|
||
$content[] = '名称 数量 单价';
|
||
$content[] = '------------------------------';
|
||
foreach ($goodsList as $k => $val) {
|
||
$goods_name = $val[$SellModel::GOODS_NAME] ? $val[$SellModel::GOODS_NAME] : '无码商品';
|
||
if (!empty($val['skuinfo'])) {
|
||
$sku_name = json_decode($val['skuinfo'], true)[0]['sku'];
|
||
$goods_name = $goods_name . ":" . $sku_name;
|
||
} else if (!empty($val[$SellModel::SKU_JSON_INFO])) {
|
||
$sku_name = json_decode($val[$SellModel::SKU_JSON_INFO], true)['name'];
|
||
$goods_name = $goods_name . ":" . $sku_name;
|
||
}
|
||
$content[] = "{$goods_name}";//商品名
|
||
$str = '';
|
||
if ($val[$SellModel::PRICING_METHOD] == 1 || !empty($val[$SellModel::SKU_JSON_INFO])) {
|
||
$str .= ' X' . str_pad(round($val[$SellModel::NUM], 2), '6', ' ', STR_PAD_RIGHT);
|
||
} else if ($val[$SellModel::PRICING_METHOD] == 2) {
|
||
$str .= ' X' . str_pad(round($val[$SellModel::NUM], 2) . $val['company'], '6', ' ', STR_PAD_RIGHT);
|
||
}
|
||
$str .= '' . str_pad($val[$SellModel::PRICE], '9', ' ', STR_PAD_RIGHT);
|
||
$content[] = $str;
|
||
}
|
||
$content[] = '------------------------------';
|
||
$content[] = '姓名:' . $printItem['addressInfo']['name'];
|
||
$content[] = '手机号:' . $printItem['addressInfo']['phone'];
|
||
if ($order['pickup_type'] != 1) {
|
||
$content[] = '收货地址:' . $printItem['addressInfo']['address'];
|
||
}
|
||
$print_time = date('Y/m/d H:i:s', time());
|
||
$content[] = "打印时间:" . "<BOLD>{$print_time}</BOLD>";
|
||
$content[] = '';
|
||
$content[] = "<C>{$printSet[$PrinterModel::FOOTER]}</C>";//title为自定义头部信息,如果没有显示门店名
|
||
$status = $this->fe_print($printSet[$PrinterModel::API_NAME], $printSet[$PrinterModel::API_KEY], $printSet[$PrinterModel::PRINTER_SN], implode('<BR>', $content), 1);
|
||
if ($status == 'ok') {
|
||
return 'ok';
|
||
} else {
|
||
return 'error';
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 飞蛾打印发送打印请求
|
||
* @param $print_uid 飞鹅打印机管理账户
|
||
* @param $print_pass API密钥
|
||
* @param $printer_sn 打印机编号
|
||
* @param $orderInfo 打印的订单信息
|
||
* @param $times 打印次数
|
||
* @return string
|
||
*/
|
||
public function fe_print($print_uid, $print_pass, $printer_sn, $orderInfo, $times)
|
||
{
|
||
$sig = sha1($print_uid . $print_pass . time());
|
||
$content = array(
|
||
'user' => $print_uid,
|
||
'stime' => time(),
|
||
'sig' => $sig,
|
||
'apiname' => 'Open_printMsg',
|
||
'sn' => $printer_sn,
|
||
'content' => $orderInfo,
|
||
'times' => $times//打印次数
|
||
);
|
||
$client = new \Think\HttpClient('api.feieyun.cn', 80);
|
||
if (!$client->post('/Api/Open/', $content)) {
|
||
echo 'error';
|
||
} else {
|
||
//服务器返回的JSON字符串,建议要当做日志记录起来
|
||
$stat = json_decode($client->getContent(), true);
|
||
return 'ok';
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 易联云打印购买订单 2019-6-27
|
||
* store_name 门店名称
|
||
* billOrder billOrder表数据
|
||
* billOnline 线上订单详情
|
||
* billDiscount 优惠详情
|
||
* goodsList sell商品详情表数据
|
||
* payList 支付方式数组
|
||
* addressInfo 地址详情
|
||
* printSet 打印机详情
|
||
* vipInfo 会员详情
|
||
* cashier_name 收银员姓名
|
||
* guide_name 导购员姓名
|
||
* @param array $printItem
|
||
* @throws \Exception
|
||
*/
|
||
protected function YlyPrintsPlaceOrder_v1($printItem = array())
|
||
{
|
||
$PrinterModel = D('RetailPrinter');
|
||
$BillModel = D('RetailBillOrder');
|
||
$BillOnlineModel = D('RetailBillOnline');
|
||
$BillDisModel = D('RetailBillDiscount');
|
||
$SellModel = D('RetailSell');
|
||
$printSet = $printItem['printSet'];
|
||
$bill_order = $printItem['bill_order'];
|
||
$bill_online = $printItem['bill_online'];
|
||
$bill_discount = $printItem['bill_discount'];
|
||
$goodsList = $printItem['goodsList'];
|
||
$pay_list = $printItem['pay_list'];
|
||
$address_info = $printItem['address_info'];
|
||
if ($bill_online['order_genre'] == 4) {
|
||
$advance_order = $printItem['advance_order'];
|
||
}
|
||
|
||
// 小票样式
|
||
$content = "<FH2><FW2><center>** #" . $bill_order['print_number'] . " **</center></FW2></FH2>";
|
||
|
||
if (!empty($printSet[$PrinterModel::TITLE])) {
|
||
$content .= "<FS2><center>--" . $printSet[$PrinterModel::TITLE] . "--</center></FS2>";
|
||
} else {
|
||
$printerSet['title'] = '欢迎光临';
|
||
$content .= "<FS2><center>--" . $printSet[$PrinterModel::TITLE] . "--</center></FS2>";
|
||
}
|
||
$content .= "<FS><center>" . $printItem['store_name'] . "</center></FS>";
|
||
$content .= "订单时间:" . date("Y-m-d H:i:s", $bill_order[$BillModel::ADD_TIME]) . "\n";
|
||
if ($bill_online['order_genre'] == 4) {
|
||
if ($advance_order['advance_type'] == 2) {
|
||
$content .= "定金支付时间:" . $advance_order['earnest_pay_time'] . "\n";
|
||
if ($advance_order['state'] == 2) {
|
||
$content .= "尾款支付时间:" . $advance_order['tail_time'] . "\n";
|
||
}
|
||
} else {
|
||
$content .= "支付时间:" . $advance_order['tail_time'] . "\n";
|
||
}
|
||
}
|
||
$content .= "订单号:" . $bill_order[$BillModel::ORDER_NO] . "\n";
|
||
if (!empty($printItem['cashier_name'])) {
|
||
$content .= "收 银 员:" . $printItem['cashier_name'] . "\n";
|
||
}
|
||
if (!empty($printItem['guide_name'])) {
|
||
$content .= "导 购 员:" . $printItem['guide_name'] . "\n";
|
||
}
|
||
$content .= '名称 数量 单价 应收' . "\n";
|
||
$content .= str_repeat('*', 14) . str_repeat("*", 17) . "\n";
|
||
$content .= "<table>";
|
||
//此处对商品进行处理
|
||
foreach ($goodsList as &$value) {
|
||
$goods_name = $value[$SellModel::GOODS_NAME] ? $value[$SellModel::GOODS_NAME] : '无码商品';
|
||
if (!empty($value['skuinfo'])) {
|
||
$sku_name = json_decode($value['skuinfo'], true)[0]['sku'];
|
||
$goods_name = $goods_name . ":" . $sku_name;
|
||
} else if (!empty($value[$SellModel::SKU_JSON_INFO])) {
|
||
$sku_name = json_decode($value[$SellModel::SKU_JSON_INFO], true)['name'];
|
||
$goods_name = $goods_name . ":" . $sku_name;
|
||
}
|
||
$content .= "<tr><td>" . $goods_name . "</td></tr>";
|
||
|
||
if ($value[$SellModel::PRICING_METHOD] == 1 || !empty($value[$SellModel::SKU_JSON_INFO])) {
|
||
$value[$SellModel::NUM] = round($value[$SellModel::NUM]);
|
||
} else {
|
||
$value[$SellModel::NUM] = round($value[$SellModel::NUM], 2) . $value['company'];
|
||
}
|
||
$content .= "<tr><td></td><td>x" . $value[$SellModel::NUM] . "</td><td>" . $value['unit_price'] . "</td><td>" . $value['before_money'] . "</td></tr>";
|
||
}
|
||
$content .= "</table>";
|
||
$content .= str_repeat('.', 32) . "\n";
|
||
$content .= "合计:" . $bill_order['before_money'] . "元" . " \n";
|
||
$content .= "应收:" . $bill_order['all_money'] . "元" . " \n";
|
||
if ($bill_online['order_genre'] == 4 && $advance_order['advance_type'] == 2) {
|
||
$content .= "@@2实收定金:" . $advance_order['all_earnest_price'] . "元" . "\n";
|
||
if (!empty($advance_order['all_arrive_price'])) {
|
||
$content .= "定金抵扣金额:" . $advance_order['all_arrive_price'] . "元" . " \n";
|
||
}
|
||
if ($advance_order['state'] == 2) {
|
||
$content .= "@@2实收尾款:" . $advance_order['tail_price'] . "元" . "\n";
|
||
} else if ($advance_order['state'] == 1) {
|
||
$content .= "待收尾款:" . $advance_order['tail_price'] . "元" . "\n";
|
||
}
|
||
} else {
|
||
$content .= "@@2实收:" . $bill_order['amount_received'] . "元" . "\n";
|
||
}
|
||
if ($bill_order[$BillModel::TYPE] == 2 && !empty($bill_order[$BillModel::GIVE_CHANGE]) && floatval($bill_order[$BillModel::GIVE_CHANGE]) > 0) {
|
||
$content .= "找零:" . $bill_order[$BillModel::GIVE_CHANGE] . "元" . "\n";
|
||
}
|
||
if ($bill_order[$BillModel::TYPE] == 2 && !empty($bill_order[$BillModel::ZERO_STORAGE]) && floatval($bill_order[$BillModel::ZERO_STORAGE]) > 0) {
|
||
$content .= "存零:" . $bill_order[$BillModel::ZERO_STORAGE] . "元" . "\n";
|
||
}
|
||
if (count($pay_list) == 1) {
|
||
if ($bill_online['order_genre'] == 4) {
|
||
if ($advance_order['advance_type'] == 2) {
|
||
$content .= "支付方式" . " \n";
|
||
$content .= $pay_list[0]['pay_type_name'] . ":" . $pay_list[0]['name'] . "\n";
|
||
} else {
|
||
$content .= "支付方式:@@2" . $pay_list[0]['name'] . "\n";
|
||
}
|
||
} else {
|
||
$content .= "支付方式:@@2" . $pay_list[0]['name'] . "\n";
|
||
}
|
||
} else {
|
||
if ($bill_online['order_genre'] == 4) {
|
||
$content .= "支付方式" . " \n";
|
||
foreach ($pay_list as $v) {
|
||
$content .= $v['pay_type_name'] . ":" . $v['name'] . "\n";
|
||
}
|
||
} else {
|
||
$content .= "支付方式:@@2组合支付" . " \n";
|
||
foreach ($pay_list as $v) {
|
||
$content .= $v['name'] . ":" . $v['money'] . "\n";
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!empty($bill_order[$BillModel::VID]) && $bill_discount['vip_less_money'] > 0) {
|
||
$content .= "会员价已优惠:" . $bill_discount[$BillDisModel::VIP_LESS_MONEY] . "元" . " \n";
|
||
}
|
||
if (!empty($bill_order[$BillModel::VID]) && $bill_discount['vip_dis_money'] > 0) {
|
||
$content .= "会员 折扣:" . $bill_discount[$BillDisModel::VIP_DIS_MONEY] . "元" . "\n";
|
||
}
|
||
if ((!empty($bill_order[$BillModel::VID]) || $bill_discount['coupon_type'] == 3) && $bill_discount['coupon_money'] > 0) {
|
||
$content .= "优 惠 券:" . $bill_discount[$BillDisModel::COUPON_MONEY] . "元" . " \n";
|
||
}
|
||
if ($bill_discount['pay_coupon_fee'] > 0) {
|
||
$content .= "代 金 券:" . $bill_discount['pay_coupon_fee'] . "元" . " \n";
|
||
}
|
||
|
||
if (!empty($bill_order[$BillModel::VID])) {
|
||
if ($bill_discount['integral_dis_money'] > 0) {
|
||
if ($bill_discount['integral_marketing'] == 2) {
|
||
$content .= "购买 积分:" . $bill_discount[$BillDisModel::INTEGRAL_DIS_MONEY] . "元" . " \n";
|
||
} else {
|
||
$content .= "积分 抵扣:" . $bill_discount[$BillDisModel::INTEGRAL_DIS_MONEY] . "元" . " \n";
|
||
}
|
||
}
|
||
if ($bill_discount['use_integral'] > 0) {
|
||
$content .= "扣除 积分:" . $bill_discount[$BillDisModel::USE_INTEGRAL] . "\n";
|
||
}
|
||
}
|
||
if ($printItem['bill_order']['third_vip_code']) {
|
||
$content .= "会员名称:" . $printItem['bill_order']['third_vip_name'] . "\n";
|
||
$content .= "会员标识:" . $printItem['bill_order']['third_vip_code'] . "\n";
|
||
}
|
||
|
||
if ($bill_order[$BillModel::TYPE] == 2 && !empty($bill_discount[$BillDisModel::CASHIER_DIS_MONEY])) {
|
||
$content .= "整单折扣优惠:" . $bill_discount[$BillDisModel::CASHIER_DIS_MONEY] . "元" . "\n";
|
||
}
|
||
if ($bill_order[$BillModel::TYPE] == 2 && !empty($bill_discount[$BillDisModel::CASHIER_MANUAL_MONEY])) {
|
||
$content .= "单品打折优惠:" . $bill_discount[$BillDisModel::CASHIER_MANUAL_MONEY] . "元" . "\n";
|
||
}
|
||
if ($bill_order[$BillModel::TYPE] == 2 && !empty($bill_discount[$BillDisModel::SMALL_CHANGES_MONEY])) {
|
||
$content .= "收银员抹零:" . $bill_discount[$BillDisModel::SMALL_CHANGES_MONEY] . "元" . "\n";
|
||
}
|
||
if ($bill_order[$BillModel::TYPE] == 1 && $bill_online[$BillOnlineModel::PICKUP_TYPE] == 2 || $bill_online[$BillOnlineModel::PICKUP_TYPE] == 3 || $bill_online[$BillOnlineModel::PICKUP_TYPE] == 5) {
|
||
$content .= "配 送 费:" . $bill_online[$BillOnlineModel::DELIVERY_FEE] . "元" . "\n";
|
||
}
|
||
|
||
if (!empty($printItem['vip_info'])) {
|
||
$VipModel = D('RetailVip');
|
||
$vip_info = $printItem['vip_info'];
|
||
$vipName = mb_substr($vip_info['name'], 0, 1, 'utf-8');
|
||
$name = '';
|
||
for ($i = 1; $i < mb_strlen($vip_info['name'], 'utf-8'); $i++) {
|
||
$name .= '*';
|
||
}
|
||
$vipName = $vipName . $name;
|
||
$vipName = $vipName ? $vipName : $vip_info['nickname'];
|
||
// $vipPhone = str_replace(substr($vip_info[$VipModel::MOBILE_PHONE], 3, 4), '****', $vip_info[$VipModel::MOBILE_PHONE]);
|
||
$vipPhone = $printItem['vip_info']['mobile_phone'];
|
||
$content .= str_repeat('-', 14) . str_repeat("-", 17);
|
||
$content .= "会员姓名:" . $vipName . " \n";
|
||
$content .= "会员手机号:" . $vipPhone . " \n";
|
||
$content .= "会员余额:" . $vip_info[$VipModel::BALANCE] . " \n";
|
||
}
|
||
//根据不同订单打印不同内容
|
||
$content .= str_repeat('.', 14) . str_repeat(".", 17);
|
||
if ($bill_order['type'] == 1) {
|
||
$content .= "配送方式:" . $bill_online['pickup_name'] . "\n";
|
||
}
|
||
if ($bill_order[$BillModel::TYPE] == 1 && !empty($bill_online['user_select_time'])) {
|
||
$user_select_time = date('Y-m-d H:i:s', $bill_online['user_select_time']);
|
||
switch ($bill_online[$BillOnlineModel::PICKUP_TYPE]) {
|
||
case 1:
|
||
$content .= "自提时间:" . $user_select_time . "\n";
|
||
break;
|
||
case 2:
|
||
$content .= "配送时间:" . $user_select_time . "\n";
|
||
break;
|
||
}
|
||
}
|
||
if (!empty($address_info)) {
|
||
if (!($bill_online['order_genre'] == 4 && $bill_online['pickup_type'] == 1)) {
|
||
$content .= "地址:" . $address_info['address'] . "\n";
|
||
}
|
||
$consignee = $bill_online['pickup_type'] == 1 ? "取 货 人:" : "收 货 人";
|
||
$content .= $consignee . $address_info['name'] . "先生/女士\n";
|
||
$content .= "@@2手机号:" . $address_info['phone'] . "\n";
|
||
}
|
||
if (!empty($bill_online[$BillOnlineModel::REMARK])) {
|
||
$content .= str_repeat('.', 14) . str_repeat(".", 17);
|
||
$content .= "@@2买家留言:" . $bill_online[$BillOnlineModel::REMARK] . "\n";
|
||
}
|
||
if (!empty($printSet[$PrinterModel::FOOTER])) {
|
||
$content .= "<FS2><center>--" . $printSet[$PrinterModel::FOOTER] . "--</center></FS2>";
|
||
}
|
||
$this->yly_print($printSet[$PrinterModel::API_NAME], $printSet[$PrinterModel::API_KEY], $printSet[$PrinterModel::PRINTER_SN], $content);
|
||
}
|
||
|
||
/**
|
||
* 易联云打印退款订单 2019-6-27
|
||
* store_name 门店名称
|
||
* billOrder billOrder表数据
|
||
* billOnline 线上订单详情
|
||
* billDiscount 优惠详情
|
||
* goodsList sell商品详情表数据
|
||
* payList 支付方式数组
|
||
* addressInfo 地址详情
|
||
* printSet 打印机详情
|
||
* vipInfo 会员详情
|
||
* @param array $printItem
|
||
* @throws \Exception
|
||
*/
|
||
protected function YlyPrintsRefundOrder_v1($printItem = array())
|
||
{
|
||
$PrinterModel = D('RetailPrinter');
|
||
$BillModel = D('RetailBillOrder');
|
||
$BillDisModel = D('RetailBillDiscount');
|
||
$SellModel = D('RetailSell');
|
||
$printSet = $printItem['printSet'];
|
||
$order = $printItem['bill_order'];
|
||
$billOnline = $printItem['bill_online'];
|
||
$billDiscount = $printItem['bill_discount'];
|
||
$goodsList = $printItem['goodsList'];
|
||
$payList = $printItem['pay_list'];
|
||
if (!empty($printSet[$PrinterModel::TITLE])) {
|
||
$content = "<FS2><center>--" . $printSet[$PrinterModel::TITLE] . "--</center></FS2>";
|
||
} else {
|
||
$printerSet['title'] = '欢迎光临';
|
||
$content = "<FS2><center>--" . $printSet[$PrinterModel::TITLE] . "--</center></FS2>";
|
||
}
|
||
$content .= "<FS><center>" . $printItem['store_name'] . "</center></FS>";
|
||
$content .= "订单类型:退款订单" . "\n";
|
||
$content .= "申请时间:" . date("Y-m-d H:i:s", $order[$BillModel::ADD_TIME]) . "\n";
|
||
if (!empty($order["finish_time"])) {
|
||
$content .= "退款时间:" . date("Y-m-d H:i:s", $order["finish_time"]) . "\n";
|
||
}
|
||
$content .= "订单编号:" . $order[$BillModel::ORDER_NO] . "\n";
|
||
$content .= '名称 数量 单价' . "\n";
|
||
$content .= str_repeat('*', 14) . str_repeat("*", 17);
|
||
$content .= "<table>";
|
||
//此处对商品进行处理
|
||
foreach ($goodsList as &$value) {
|
||
$goods_name = $value[$SellModel::GOODS_NAME] ? $value[$SellModel::GOODS_NAME] : '无码商品';
|
||
if (!empty($value['skuinfo'])) {
|
||
$sku_name = json_decode($value['skuinfo'], true)[0]['sku'];
|
||
$goods_name = $goods_name . ":" . $sku_name;
|
||
} else if (!empty($value[$SellModel::SKU_JSON_INFO])) {
|
||
$sku_name = json_decode($value[$SellModel::SKU_JSON_INFO], true)['name'];
|
||
$goods_name = $goods_name . ":" . $sku_name;
|
||
}
|
||
$content .= "<tr><td>" . $goods_name . "</td></tr>";
|
||
|
||
if ($value[$SellModel::PRICING_METHOD] == 1 || !empty($value[$SellModel::SKU_JSON_INFO])) {
|
||
$value[$SellModel::NUM] = round($value[$SellModel::NUM]);
|
||
} else {
|
||
$value[$SellModel::NUM] = round($value[$SellModel::NUM], 2) . $value['company'];
|
||
}
|
||
$content .= "<tr><td></td><td>x" . $value[$SellModel::NUM] . "</td><td>" . $value[$SellModel::PRICE] . "</td></tr>";
|
||
}
|
||
$content .= "</table>";
|
||
$content .= str_repeat('.', 32);
|
||
|
||
if (count($payList) == 1) {
|
||
$content .= "退款方式:" . $payList[0]['name'] . "\n";
|
||
} else {
|
||
$content .= "退款方式:组合退款" . " \n";
|
||
foreach ($payList as $v) {
|
||
$content .= $v['name'] . ":" . $v['money'] . "\n";
|
||
}
|
||
}
|
||
if ($billDiscount['integral_dis_money'] > 0) {
|
||
if ($billDiscount['integral_marketing'] == 2) {
|
||
$content .= "购买积分金额:{$billDiscount[$BillDisModel::INTEGRAL_DIS_MONEY]}元" . "\n";
|
||
} else {
|
||
$content .= "积分抵扣:{$billDiscount[$BillDisModel::INTEGRAL_DIS_MONEY]}元" . "\n";
|
||
}
|
||
}
|
||
if ($billDiscount['use_integral'] > 0) {
|
||
$content .= "退还积分:" . $billDiscount[$BillDisModel::USE_INTEGRAL] . "\n";
|
||
}
|
||
if ($billOnline["pickup_type"] == 2) {
|
||
$content .= "退还配送费:" . $billOnline["delivery_fee"] . "\n";
|
||
}
|
||
if ($billDiscount['pay_coupon_fee'] > 0) {
|
||
$content .= "代金券:" . $billDiscount['pay_coupon_fee'] . "\n";
|
||
}
|
||
$content .= "实退金额:" . $order[$BillModel::ALL_MONEY] . "\n";
|
||
$print_time = date('Y/m/d H:i:s', time());
|
||
$content .= "打印时间:" . $print_time . "\n";
|
||
if (!empty($printerSet['footer'])) {
|
||
$content .= "<FS2><center>--" . $printerSet['footer'] . "--</center></FS2>";
|
||
}
|
||
$this->yly_print($printSet[$PrinterModel::API_NAME], $printSet[$PrinterModel::API_KEY], $printSet[$PrinterModel::PRINTER_SN], $content);
|
||
}
|
||
|
||
/**
|
||
* 易联云打印换货订单 2020-3-20
|
||
* store_name 门店名称
|
||
* billOrder billOrder表数据
|
||
* billOnline 线上订单详情
|
||
* billDiscount 优惠详情
|
||
* goodsList sell商品详情表数据
|
||
* payList 支付方式数组
|
||
* addressInfo 地址详情
|
||
* printSet 打印机详情
|
||
* vipInfo 会员详情
|
||
* @param array $printItem
|
||
* @throws \Exception
|
||
*/
|
||
protected function YlyPrintsExchangeGoods($printItem)
|
||
{
|
||
$PrinterModel = D('RetailPrinter');
|
||
$BillModel = D('RetailBillOrder');
|
||
$BillDisModel = D('RetailBillDiscount');
|
||
$SellModel = D('RetailSell');
|
||
$printSet = $printItem['printSet'];
|
||
$order = $printItem['bill_order'];
|
||
$billDiscount = $printItem['bill_discount'];
|
||
$goodsList = $printItem['goodsList'];
|
||
$payList = $printItem['pay_list'];
|
||
if (!empty($printSet[$PrinterModel::TITLE])) {
|
||
$content = "<FS2><center>--" . $printSet[$PrinterModel::TITLE] . "--</center></FS2>";
|
||
} else {
|
||
$printerSet['title'] = '欢迎光临';
|
||
$content = "<FS2><center>--" . $printSet[$PrinterModel::TITLE] . "--</center></FS2>";
|
||
}
|
||
$content .= "<FS><center>" . $printItem['store_name'] . "</center></FS>";
|
||
$content .= "订单类型:换货订单" . "\n";
|
||
$content .= "申请时间:" . date("Y-m-d H:i:s", $order[$BillModel::ADD_TIME]) . "\n";
|
||
if (!empty($order["finish_time"])) {
|
||
$content .= "换货时间:" . date("Y-m-d H:i:s", $order["finish_time"]) . "\n";
|
||
}
|
||
$content .= "订单编号:" . $order[$BillModel::ORDER_NO] . "\n";
|
||
$content .= '名称 数量 单价' . "\n";
|
||
$content .= str_repeat('*', 14) . str_repeat("*", 17);
|
||
$content .= "<table>";
|
||
//此处对商品进行处理
|
||
foreach ($goodsList as &$value) {
|
||
$goods_name = $value[$SellModel::GOODS_NAME] ? $value[$SellModel::GOODS_NAME] : '无码商品';
|
||
if (!empty($value['skuinfo'])) {
|
||
$sku_name = json_decode($value['skuinfo'], true)[0]['sku'];
|
||
$goods_name = $goods_name . ":" . $sku_name;
|
||
} else if (!empty($value[$SellModel::SKU_JSON_INFO])) {
|
||
$sku_name = json_decode($value[$SellModel::SKU_JSON_INFO], true)['name'];
|
||
$goods_name = $goods_name . ":" . $sku_name;
|
||
}
|
||
$content .= "<tr><td>" . $goods_name . "</td></tr>";
|
||
|
||
if ($value[$SellModel::PRICING_METHOD] == 1 || !empty($value[$SellModel::SKU_JSON_INFO])) {
|
||
$value[$SellModel::NUM] = round($value[$SellModel::NUM]);
|
||
} else {
|
||
$value[$SellModel::NUM] = round($value[$SellModel::NUM], 2) . $value['company'];
|
||
}
|
||
$content .= "<tr><td></td><td>x" . $value[$SellModel::NUM] . "</td><td>" . $value[$SellModel::PRICE] . "</td></tr>";
|
||
}
|
||
$content .= "</table>";
|
||
$content .= str_repeat('.', 32);
|
||
$content .= "姓名:" . $printItem['addressInfo']['name'] . "\n";
|
||
$content .= "手机号:" . $printItem['addressInfo']['phone'] . "\n";
|
||
if ($order['pickup_type'] != 1) {
|
||
$content .= "收货地址:" . $printItem['addressInfo']['address'] . "\n";
|
||
}
|
||
$print_time = date('Y/m/d H:i:s', time());
|
||
$content .= "打印时间:" . $print_time . "\n";
|
||
if (!empty($printerSet['footer'])) {
|
||
$content .= "<FS2><center>--" . $printerSet['footer'] . "--</center></FS2>";
|
||
}
|
||
$this->yly_print($printSet[$PrinterModel::API_NAME], $printSet[$PrinterModel::API_KEY], $printSet[$PrinterModel::PRINTER_SN], $content);
|
||
}
|
||
|
||
/**
|
||
* 易联云发送打印请求 2019-6-27
|
||
* @param $api_name
|
||
* @param $api_key
|
||
* @param $machine_code
|
||
* @param $content
|
||
* @throws \Exception
|
||
*/
|
||
public function yly_print($api_name, $api_key, $machine_code, $content)
|
||
{
|
||
$client = new \YlyOauthClient();
|
||
//获取签名
|
||
$time = time();
|
||
$params['appid'] = $api_name;
|
||
$params['appsecret'] = $api_key;
|
||
$sign = $client->getSign($time, $params);
|
||
|
||
$token = $this->getAccessToken($api_name, $api_key);
|
||
|
||
$checkData['client_id'] = $api_name;//应用id,在易联云开放平台创建应用时获取
|
||
$checkData['access_token'] = $token;//通过请求获取令牌接口获取到的令牌信息
|
||
$checkData['machine_code'] = $machine_code;//打印机终端号
|
||
$checkData['content'] = $content;
|
||
$checkData['sign'] = $sign;//获取到的签名
|
||
$checkData['id'] = $client->uuid4();//UUID4;详情参考官方文档
|
||
$checkData['timestamp'] = $time;//当前服务器时间戳
|
||
$checkData['origin_id'] = $time;//当前服务器时间戳
|
||
$check = $client->send("https://open-api.10ss.net/print/index", $checkData);
|
||
}
|
||
|
||
protected function getAccessToken($appid, $appsecret)
|
||
{
|
||
$map['appid'] = $appid;
|
||
$map['appsecret'] = $appsecret;
|
||
$find = M("yiliancloud")->where($map)->find();
|
||
if ($find) {
|
||
return $find['access_token'];
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 会员余额退款打印2020-1-4
|
||
*/
|
||
public function balanceRefundPrint($print_parameter)
|
||
{
|
||
$store_id = $print_parameter['store_id'];
|
||
if (!$store_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
return $res;
|
||
}
|
||
$PrinterModel = D('RetailPrinter');
|
||
$map = array(
|
||
$PrinterModel::STORE_ID => $store_id,
|
||
$PrinterModel::STATUS => 2
|
||
);
|
||
$printSet = $PrinterModel->getSelect($map); //根据传入的门店id,查询该门店是否配置打印机或已开启打印机
|
||
if (empty($printSet)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '暂无可用打印机';
|
||
return $res;
|
||
}
|
||
foreach ($printSet as $val) {
|
||
$parameter = array(
|
||
'parameter' => $print_parameter,
|
||
'printSet' => $val,
|
||
);
|
||
switch ($val[$PrinterModel::PRINTER_TYPE]) {
|
||
case 1:
|
||
//飞蛾
|
||
$this->FePrintsBalanceRefund($parameter);
|
||
break;
|
||
case 2:
|
||
//易联云
|
||
$this->YlyPrintsBalanceRefund($parameter);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 易联云打印会员余额退款 2019-6-27
|
||
* store_name 门店名称
|
||
* @param array $printItem
|
||
* @throws \Exception
|
||
*/
|
||
public function YlyPrintsBalanceRefund($parameter)
|
||
{
|
||
$info = $parameter['parameter'];
|
||
$printSet = $parameter['printSet'];
|
||
if (!empty($printSet['title'])) {
|
||
$content = "<FS2><center>--" . $printSet['title'] . "--</center></FS2>";
|
||
}
|
||
$content .= "<FS><center>" . $info['store_name'] . "</center></FS>";
|
||
$content .= "订单编号:" . $info['order_number'] . "\n";
|
||
$content .= "订单类型:会员充值退款\n";
|
||
$content .= "退款方式:" . $info['pay_name'] . "\n";
|
||
$content .= "退款金额:" . $info['trade_amount'] . "元\n";
|
||
$content .= "会员名称:" . $info['name'] . "\n";
|
||
$content .= "会员号:" . $info['vip_number'] . "\n";
|
||
$content .= "会员等级:" . $info['grade_name'] . "\n";
|
||
$content .= "会员余额:" . $info['balance'] . "元\n";
|
||
$content .= "会员积分:" . $info['integral'] . "\n";
|
||
$content .= "订单时间:" . $info['time'] . "\n";
|
||
$content .= str_repeat('*', 14) . str_repeat("*", 18);
|
||
if (!empty($printSet['footer'])) {
|
||
$content .= "<FS2><center>--" . $printSet['footer'] . "--</center></FS2>";
|
||
}
|
||
$this->yly_print($printSet['api_name'], $printSet['api_key'], $printSet['printer_sn'], $content);
|
||
}
|
||
|
||
/**会员余额退款飞蛾打印
|
||
* @param $parameter 参数
|
||
*/
|
||
public function FePrintsBalanceRefund($parameter)
|
||
{
|
||
$info = $parameter['parameter'];
|
||
$printSet = $parameter['printSet'];
|
||
if ($printSet['title']) {
|
||
$content = array('title' => "<CB>{$printSet['title']}</CB>");//title为自定义头部信息,如果没有显示门店名
|
||
}
|
||
$content[] = "<L><C>{$info['store_name']}</C></L>";//title为自定义头部信息,如果没有显示门店名
|
||
$content[] = '';
|
||
$content[] = "订单编号:<BOLD>{$info['order_number']}</BOLD>";
|
||
$content[] = "订单类型:会员充值退款";
|
||
$content[] = "退款方式:" . $info['pay_name'];
|
||
$content[] = "退款金额:" . $info['trade_amount'] . "元";
|
||
$content[] = "会员名称:" . $info['name'];
|
||
$content[] = "会员号:" . $info['vip_number'];
|
||
$content[] = "会员等级:" . $info['grade_name'];
|
||
$content[] = "会员余额:" . $info['balance'] . "元";
|
||
$content[] = "会员积分:" . $info['integral'];
|
||
$content[] = "订单时间:" . $info['time'];
|
||
$content[] = '------------------------------';
|
||
$content[] = '';
|
||
$content[] = "<C>{$printSet['footer']}</C>";//title为自定义头部信息,如果没有显示门店名
|
||
$status = $this->fe_print($printSet['api_name'], $printSet['api_key'], $printSet['printer_sn'], implode('<BR>', $content), 1);
|
||
if ($status == 'ok') {
|
||
return 'ok';
|
||
} else {
|
||
return 'error';
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 小助手进销存打印
|
||
* $order_info 订单信息
|
||
* $id 订单id
|
||
* $identity 1商户 2门店
|
||
* $type 门店订单类型 入库类型 0其他入库 1采购入库 2补货入库 3盘盈入库 4退货入库 5初始化入库 6采购退货 7其他出库 8向商户退货出库 9调拨出库 10向供货商退货出库 11商户调拨入库 12门店调拨入库
|
||
*/
|
||
public function inventoryPrint($print_parameter)
|
||
{
|
||
$id = $print_parameter['id'];
|
||
$order_info = $print_parameter['order_info'];
|
||
$identity = $print_parameter['identity'];
|
||
$type = $print_parameter['type'];
|
||
$store_id = $print_parameter['store_id'];
|
||
if (!$order_info || !$identity || !$type) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
return $res;
|
||
}
|
||
$PrinterModel = D('RetailPrinter');
|
||
$map = array(
|
||
$PrinterModel::STORE_ID => $store_id,
|
||
$PrinterModel::INVENTORY_STATUS => 1,
|
||
$PrinterModel::STATUS => 2
|
||
);
|
||
$printSet = $PrinterModel->getSelect($map); //根据传入的门店id,查询该门店是否配置打印机或已开启打印机
|
||
if (empty($printSet)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '暂无可用打印机';
|
||
return $res;
|
||
}
|
||
switch ($identity) {
|
||
case 1:
|
||
break;
|
||
case 2:
|
||
if (!$store_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
return $res;
|
||
}
|
||
$printSetInfo = D("InventoryPrint")->getFind(array('type' => 2, 'store_id' => $store_id));
|
||
$StoreModel = D('RetailStore');
|
||
$store_name = $StoreModel->getFindField(array($StoreModel::ID => $store_id), $StoreModel::STORE_NAME); //门店名称
|
||
switch ($type) {
|
||
case 1:
|
||
$where = array(
|
||
'purchase_order_id' => $id,
|
||
);
|
||
$content = D("SPurchaseGoods")->getSelect($where, $page = "", $limit = "", "goods_name,sku_name,purchase_num", "id asc");
|
||
break;
|
||
case 6:
|
||
$where = array(
|
||
'retreat_order_id' => $id,
|
||
);
|
||
$content = D("SRetreatGoods")->getSelect($where, $page = "", $limit = "", "goods_name,sku_name,retreat_num", "id asc");
|
||
break;
|
||
case 7:
|
||
case 8:
|
||
case 9:
|
||
case 10:
|
||
$where = array(
|
||
'stock_out_id' => $id,
|
||
);
|
||
$content = D("SStockOutGoods")->getSelect($where, $page = "", $limit = "", "goods_name,sku_name,stock_num", "id asc");
|
||
break;
|
||
case 11:
|
||
$where = array(
|
||
'warehouse_record_id' => $id
|
||
);
|
||
$content = D("SWarehousingGoods")->getSelect($where, $page = "", $limit = "", "goods_name,sku_name,warehouse_num", "id asc");
|
||
break;
|
||
}
|
||
break;
|
||
}
|
||
if (!empty($content)) {
|
||
if (!empty($printSetInfo)) {
|
||
foreach ($content as $key => $val) {
|
||
if (!empty($printSetInfo['font_num'])) {
|
||
if (mb_strlen($val['goods_name']) > $printSetInfo['font_num']) {
|
||
$content[$key]['goods_name'] = mb_substr($val['goods_name'], 0, $printSetInfo['font_num'], 'utf-8');
|
||
}
|
||
}
|
||
if (!empty($printSetInfo['sku_num'])) {
|
||
if (mb_strlen($val['sku_name']) > $printSetInfo['sku_num']) {
|
||
$content[$key]['sku_name'] = mb_substr($val['sku_name'], 0, $printSetInfo['sku_num'], 'utf-8');
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$order_info['operator'] = A('Api/Inventory')->OperatorName($order_info['operator_id']);
|
||
switch ($type) {
|
||
case 1:
|
||
$type_name = '采购单';
|
||
foreach ($content as &$value) {
|
||
$value['goods_num'] = round($value['purchase_num'], 3);
|
||
}
|
||
break;
|
||
case 6:
|
||
$type_name = '采购退货单';
|
||
foreach ($content as &$value) {
|
||
$value['goods_num'] = round($value['retreat_num'], 3);
|
||
}
|
||
break;
|
||
case 7:
|
||
case 8:
|
||
case 9:
|
||
case 10:
|
||
switch ($type) {
|
||
case 7:
|
||
$type_name = '其他出库单';
|
||
break;
|
||
case 8 :
|
||
$type_name = '向商户退货单';
|
||
break;
|
||
case 9:
|
||
$type_name = '调拨出库单';
|
||
break;
|
||
case 10:
|
||
$type_name = '向供货商退货单';
|
||
break;
|
||
}
|
||
foreach ($content as &$value) {
|
||
$value['goods_num'] = round($value['stock_num'], 3);
|
||
}
|
||
break;
|
||
case 11:
|
||
case 12:
|
||
switch ($type) {
|
||
case 11:
|
||
$type_name = "商户调拨入库单";
|
||
break;
|
||
case 12:
|
||
$type_name = "入库单";
|
||
break;
|
||
}
|
||
foreach ($content as &$value) {
|
||
$value['goods_num'] = round($value['warehouse_num'], 3);
|
||
}
|
||
break;
|
||
}
|
||
foreach ($printSet as $val) {
|
||
$parameter = array(
|
||
'store_name' => $store_name,
|
||
'type_name' => $type_name,
|
||
'order_info' => $order_info,
|
||
'list' => $content,
|
||
'printSet' => $val
|
||
);
|
||
switch ($val[$PrinterModel::PRINTER_TYPE]) {
|
||
case 1:
|
||
//飞蛾
|
||
$this->FePrintsInventory($parameter);
|
||
break;
|
||
case 2:
|
||
//易联云
|
||
$this->YlyPrintsInventory($parameter);
|
||
break;
|
||
}
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '暂无商品信息';
|
||
return;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 易联云打印进销存 2019-6-27
|
||
* store_name 门店名称
|
||
* $order_info 订单信息
|
||
* $content 商品信息
|
||
* $printSet 打印机设置
|
||
* $type_name 订单类型
|
||
* @param array $printItem
|
||
* @throws \Exception
|
||
*/
|
||
public function YlyPrintsInventory($parameter)
|
||
{
|
||
$store_name = $parameter['store_name'];
|
||
$order_info = $parameter['order_info'];
|
||
$list = $parameter['list'];
|
||
$printSet = $parameter['printSet'];
|
||
$type_name = $parameter['type_name'];
|
||
if (!empty($printSet['title'])) {
|
||
$content = "<FS2><center>--" . $printSet['title'] . "--</center></FS2>";
|
||
}
|
||
$content .= "<FS><center>" . $store_name . $type_name . "</center></FS>";
|
||
$content .= "操作人:" . $order_info['operator'] . "\n";
|
||
$content .= "订单时间:" . date("Y-m-d H:i:s", $order_info['add_time']) . "\n";
|
||
$content .= "订单编号:" . $order_info['order_number'] . "\n";
|
||
$content .= '商品名称 规格 数量' . "\n";
|
||
$content .= str_repeat('*', 14) . str_repeat("*", 18);
|
||
$content .= "<table>";
|
||
//此处对商品进行处理
|
||
foreach ($list as $value) {
|
||
$content .= "<tr><td>" . $value['goods_name'] . "</td></tr>";
|
||
$content .= "<tr><td></td><td>" . $value['sku_name'] . "</td><td>" . $value['goods_num'] . "</td></tr>";
|
||
}
|
||
$content .= "</table>";
|
||
$content .= str_repeat('.', 32);
|
||
if (!empty($printSet['footer'])) {
|
||
$content .= "<FS2><center>--" . $printSet['footer'] . "--</center></FS2>";
|
||
}
|
||
$this->yly_print($printSet['api_name'], $printSet['api_key'], $printSet['printer_sn'], $content);
|
||
}
|
||
|
||
/**
|
||
* 进销存模块飞蛾打印机
|
||
*/
|
||
protected function FePrintsInventory($parameter)
|
||
{
|
||
$store_name = $parameter['store_name'];
|
||
$order_info = $parameter['order_info'];
|
||
$list = $parameter['list'];
|
||
$printSet = $parameter['printSet'];
|
||
$type_name = $parameter['type_name'];
|
||
$PrinterModel = D('RetailPrinter');
|
||
if ($printSet[$PrinterModel::TITLE]) {
|
||
$content = array('title' => "<CB>{$printSet[$PrinterModel::TITLE]}</CB>");//title为自定义头部信息,如果没有显示门店名
|
||
}
|
||
$content[] = "<L><C>{$store_name}{$type_name}</C></L>";//title为自定义头部信息,如果没有显示门店名
|
||
$content[] = '';
|
||
$content[] = "操作人:" . $order_info['operator'];
|
||
$content[] = "订单时间:" . date('Y-m-d H:i:s', $order_info['add_time']);
|
||
$content[] = "订单编号:<BOLD>{$order_info['order_number']}</BOLD>";
|
||
$content[] = '商品名称 规格 数量';
|
||
$content[] = '------------------------------';
|
||
foreach ($list as $k => $val) {
|
||
$content[] = "{$val['goods_name']}";//商品名
|
||
$str = '';
|
||
$str .= ' ' . $val['sku_name'];
|
||
if (!empty($val['sku_name'])) {
|
||
$str .= ' ' . round($val['goods_num'], 3);
|
||
} else {
|
||
$str .= ' ' . round($val['goods_num'], 3);
|
||
}
|
||
$content[] = $str;
|
||
}
|
||
$content[] = '------------------------------';
|
||
$content[] = '';
|
||
$content[] = "<C>{$printSet[$PrinterModel::FOOTER]}</C>";//title为自定义头部信息,如果没有显示门店名
|
||
$status = $this->fe_print($printSet[$PrinterModel::API_NAME], $printSet[$PrinterModel::API_KEY], $printSet[$PrinterModel::PRINTER_SN], implode('<BR>', $content), 1);
|
||
if ($status == 'ok') {
|
||
return 'ok';
|
||
} else {
|
||
return 'error';
|
||
}
|
||
}
|
||
|
||
|
||
/****************充值打印**********************/
|
||
|
||
/**
|
||
* wifi打印充值订单
|
||
* @param $param array 打印信息
|
||
* $param['cashier_name']
|
||
* $param['store_name']
|
||
* $param['order_id']
|
||
* $param['store_id']
|
||
* @return array
|
||
*/
|
||
public function rechargeWifiPrint($param = array())
|
||
{
|
||
try {
|
||
// 获取打印信息
|
||
$result = $this->getPrintInfo($param);
|
||
if ($result['status'] == 0) {
|
||
return $result;
|
||
}
|
||
$print_info = $result['print_info'];
|
||
// 获取wifi打印机
|
||
$PrinterModel = D('RetailPrinter');
|
||
$map = array(
|
||
$PrinterModel::STORE_ID => $param['store_id'],
|
||
$PrinterModel::STATUS => 2,
|
||
$PrinterModel::LINE_STATUS => 2
|
||
);
|
||
// 判断该门店是否配置打印机或已开启打印机
|
||
$print_set = $PrinterModel->getSelect($map);
|
||
if (empty($print_set)) {
|
||
return ['status' => 0, 'msg' => '暂无可用的打印机'];
|
||
}
|
||
foreach ($print_set as &$val) {
|
||
switch ($val[$PrinterModel::PRINTER_TYPE]) {
|
||
case 1:
|
||
$this->fe_print_rechharge($print_info, $val);
|
||
break;
|
||
case 2:
|
||
$this->yly_print_rechharge($print_info, $val);
|
||
break;
|
||
default:
|
||
// 打印机类型错误
|
||
continue;
|
||
}
|
||
}
|
||
return array('status' => 1, 'msg' => '已向打印机发送打印信息');
|
||
} catch (\Exception $e) {
|
||
// 异常操作,抛出错误
|
||
return array('status' => 0, 'msg' => '暂无可用的打印机');
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取打印信息(公共方法)
|
||
* @param $param array 打印信息
|
||
* $param['cashier_name']
|
||
* $param['store_name']
|
||
* $param['order_id']
|
||
* $param['store_id']
|
||
* @return $res array
|
||
*/
|
||
public function getPrintInfo($param)
|
||
{
|
||
// 实例化模型
|
||
$RechargeViewModel = D('RechargeView');
|
||
$print_info = array();
|
||
// 订单查询条件
|
||
$map = array(
|
||
'RetailPayOrder.id' => $param['order_id'],
|
||
'RetailPayOrder.order_type' => 2,
|
||
'RetailPayOrder.order_state' => 'SUCCESS',
|
||
'RetailRechargeOrder.status' => 1,
|
||
);
|
||
$field = array(
|
||
'pay_type',
|
||
'out_trade_no',
|
||
'add_time',
|
||
'money',
|
||
'all_money',
|
||
'user_type',
|
||
'mobile_phone',
|
||
'balance',
|
||
'name',
|
||
'nickname',
|
||
'integral',
|
||
'card_key',
|
||
'give_money',
|
||
'repay_name',
|
||
'cashier_id',
|
||
);
|
||
// 查询订单
|
||
$order_data = $RechargeViewModel->getFind($map, $field);
|
||
if (!$order_data) {
|
||
$res = array('status' => 0, 'msg' => '订单查询失败');
|
||
return $res;
|
||
}
|
||
// 门店名称
|
||
if (empty($param['store_name'])) {
|
||
$param['store_name'] = D('RetailStore')->getFindField(['id' => $param['store_id']], 'storetag');
|
||
}
|
||
$print_info['store_name'] = $param['store_name'];
|
||
// 订单编号
|
||
$print_info['order_number'] = $order_data['out_trade_no'];
|
||
// 支付类型
|
||
switch ($order_data['pay_type']) {
|
||
case 1:
|
||
$print_info['pay_type_name'] = '微信支付';
|
||
break;
|
||
case 2:
|
||
$print_info['pay_type_name'] = '支付宝支付';
|
||
break;
|
||
case 3:
|
||
$print_info['pay_type_name'] = '现金支付';
|
||
break;
|
||
default:
|
||
$print_info['pay_type_name'] = '支付类型未知';
|
||
}
|
||
// 会员名称
|
||
$print_info['vip_name'] = $order_data['name'] ? $order_data['name'] : ($order_data['nickname'] ? $order_data['nickname'] : '未设置');
|
||
// 卡号
|
||
if ($order_data['mobile_phone']) {
|
||
$print_info['card_num'] = substr($order_data['mobile_phone'], 0, 3) . '****' . substr($order_data['mobile_phone'], -3);
|
||
} else {
|
||
if ($order_data['card_key'] && ($order_data['card_key'] != 0 || $order_data['card_key'] != '0')) {
|
||
$print_info['card_num'] = substr($order_data['card_key'], 0, 3) . '****' . substr($order_data['card_key'], -3);
|
||
} else {
|
||
$print_info['card_num'] = '未设置';
|
||
}
|
||
}
|
||
// 金额
|
||
$print_info['money'] = $order_data['money'] ? floatval($order_data['money']) : 0;
|
||
$print_info['all_money'] = $order_data['all_money'] ? floatval($order_data['all_money']) : 0;
|
||
$print_info['give_money'] = $order_data['give_money'] ? floatval($order_data['give_money']) : 0; //赠送金额
|
||
$print_info['balance'] = $order_data['balance'] ? floatval($order_data['balance']) : 0; // 余额
|
||
$print_info['integral'] = $order_data['integral'] ? floatval($order_data['integral']) : 0; // 积分
|
||
// 时间
|
||
$print_info['add_time'] = date('Y/m/d H:i:s', $order_data['add_time']);
|
||
$print_info['print_time'] = date('Y/m/d H:i:s', time());
|
||
// 操作人员
|
||
switch ($order_data['user_type']) {
|
||
case 1:
|
||
$print_info['use_name'] = '商家';
|
||
break;
|
||
case 2:
|
||
$print_info['use_name'] = '店长';
|
||
break;
|
||
case 3:
|
||
if (empty($param['cashier_name'])) {
|
||
$param['cashier_name'] = D('RetailCashier')->getFindField(['id' => $order_data['cashier_id']], 'name');
|
||
}
|
||
$print_info['use_name'] = $param['cashier_name'];
|
||
break;
|
||
default:
|
||
$print_info['use_name'] = '未知操作人员';
|
||
}
|
||
// 到账方式
|
||
switch ($order_data['repay_name']) {
|
||
case 0:
|
||
$print_info['repay_name'] = '直接到账';
|
||
break;
|
||
case 1:
|
||
$print_info['repay_name'] = '分期到账';
|
||
break;
|
||
default:
|
||
$print_info['repay_name'] = '未知到账方式';
|
||
}
|
||
// 返回参数
|
||
$res = array('status' => 1, 'print_info' => $print_info);
|
||
return $res;
|
||
}
|
||
|
||
|
||
/**
|
||
* 飞蛾打印信息
|
||
* @param $print_info array 打印信息
|
||
* @param $print_set array 门店信息
|
||
* @return array $res
|
||
*/
|
||
public function fe_print_rechharge($print_info, $print_set)
|
||
{
|
||
// print_r($print_info);
|
||
// print_r($print_set);
|
||
// die;
|
||
$PrinterModel = D('RetailPrinter');
|
||
// 判断头部信息
|
||
$title = $print_set[$PrinterModel::TITLE] ? $print_set[$PrinterModel::TITLE] : $print_info['store_name'];
|
||
$footer = $print_set[$PrinterModel::FOOTER] ? $print_set[$PrinterModel::FOOTER] : $print_info['store_name'];
|
||
$content = array(
|
||
"<L><C>{$title}</C></L>",
|
||
"订单编号:<BOLD>{$print_info['order_number']}</BOLD>",
|
||
"订单类型:<BOLD>会员充值</BOLD>",
|
||
"支付方式:<BOLD>{$print_info['pay_type_name']}</BOLD>",
|
||
"订单实付:<BOLD>{$print_info['money']}</BOLD>",
|
||
"充值获得:<BOLD>{$print_info['all_money']}</BOLD>",
|
||
"赠送金额:<BOLD>{$print_info['give_money']}</BOLD>",
|
||
"到账方式:<BOLD>{$print_info['repay_name']}</BOLD>",
|
||
"会员名称:<BOLD>{$print_info['vip_name']}</BOLD>",
|
||
"会员账号:<BOLD>{$print_info['card_num']}</BOLD>",
|
||
"会员余额:<BOLD>{$print_info['balance']}</BOLD>",
|
||
"会员积分:<BOLD>{$print_info['integral']}</BOLD>",
|
||
"充值时间:<BOLD>{$print_info['add_time']}</BOLD>",
|
||
"操作人员:<BOLD>{$print_info['use_name']}</BOLD>",
|
||
"打印时间:<BOLD>{$print_info['print_time']}</BOLD>",
|
||
"<C>{$print_set[$PrinterModel::FOOTER]}</C>"
|
||
);
|
||
// 发送打印
|
||
A('PayApi/Printer')->fe_print($print_set[$PrinterModel::API_NAME], $print_set[$PrinterModel::API_KEY], $print_set[$PrinterModel::PRINTER_SN], implode('<BR>', $content), 1);
|
||
}
|
||
|
||
|
||
/**
|
||
* 易连云打印信息
|
||
* @param $print_info array 打印信息
|
||
* @param $print_set array 门店信息
|
||
* @return array $res
|
||
*/
|
||
public function yly_print_rechharge($print_info, $print_set)
|
||
{
|
||
$PrinterModel = D('RetailPrinter');
|
||
// 判断头部信息
|
||
$title = $print_set[$PrinterModel::TITLE] ? $print_set[$PrinterModel::TITLE] : $print_info['store_name'];
|
||
$footer = $print_set[$PrinterModel::FOOTER] ? $print_set[$PrinterModel::FOOTER] : $print_info['store_name'];
|
||
$content = array(
|
||
"<FS><center>{$title}</center></FS>",
|
||
"订单编号:{$print_info['order_number']}",
|
||
"订单类型:会员充值",
|
||
"支付方式:{$print_info['pay_type_name']}",
|
||
"订单实付:{$print_info['money']}",
|
||
"充值获得:{$print_info['all_money']}",
|
||
"赠送金额:{$print_info['give_money']}",
|
||
"到账方式:{$print_info['repay_name']}",
|
||
"会员名称:{$print_info['vip_name']}",
|
||
"会员账号:{$print_info['card_num']}",
|
||
"会员余额:{$print_info['balance']}",
|
||
"会员积分:{$print_info['integral']}",
|
||
"充值时间:{$print_info['add_time']}",
|
||
"操作人员:{$print_info['use_name']}",
|
||
"打印时间:{$print_info['print_time']}",
|
||
"<center>{$print_set[$PrinterModel::FOOTER]}</center>"
|
||
);
|
||
// 发送打印
|
||
A('PayApi/Printer')->yly_print($print_set[$PrinterModel::API_NAME], $print_set[$PrinterModel::API_KEY], $print_set[$PrinterModel::PRINTER_SN], implode("\n", $content));
|
||
}
|
||
|
||
} |