getOrderDetail($order_id); $order_info = $order_detail_result['data']; $site_id = $order_info['site_id']; $store_id = $order_info['store_id']; $params['site_id'] = $order_info['site_id']; //获取店铺信息 $shop_model = new Shop(); $shop = $shop_model->getShopInfo([['site_id', '=', $params['site_id']]]); $shop_info = $shop['data']; $site_name = (new Site())->getSiteInfo([['site_id', '=', $params['site_id']]], 'site_name')['data']['site_name'] ?? ''; //获取打印机列表 $print_model = new Printer(); $printer_condition = [ ['site_id', '=', $params['site_id']] ]; if($order_info['order_type']==6){ $order_info['store_id'] = 0; }else{ 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_data = $print_template_model->getPrinterTemplateInfo([['template_id', '=', $template_id]]); $print_template = $print_template_data['data']; $array['printer_code'] = $v['printer_code']; //商户授权机器码 $array['origin_id'] = $order_info['order_no']; //内部订单号(32位以内) switch ($v['brand']) { case '365'://365打印机 break; case 'feie'://365飞蛾打印机 $array['content'] = $this->feieContent($order_id, $print_num, $print_template, $site_name, $shop_info, $order_info, $params); break; case 'yilianyun'://易联云打印机 $array['content'] = $this->yilianyun($order_id, $print_num, $print_template, $site_name, $shop_info, $order_info, $params); break; } $res_data[] = $array; } return $res_data; } } public function feieContent($order_id, $print_num, $print_template, $site_name, $shop_info, $order_info, $params) { /**文本接口开始**/ $content = ''; //小票名称 if ($print_template['title'] != '') { $content .= "" . $print_template['title'] . "
"; $content .= str_repeat('.', 32); } //商城名称 if ($print_template['head'] == 1) { $content .= "" . $site_name . "
"; $content .= str_repeat('.', 32) . "
"; } if (!empty($order_info['pay_time'])) { $content .= "订单时间:" . date("Y-m-d H:i", $order_info['pay_time']) . "
"; } else { $content .= "订单时间:" . date("Y-m-d H:i", time()) . "
"; } $content .= "订单编号:" . $order_info['order_no'] . "
"; $content .= "支付方式:" . $order_info['pay_type_name'] . "
"; // 2:自提提货,3:本地配送外卖 if ($order_info['order_type'] == 2 || $order_info['order_type'] == 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 . "
"; } $content .= str_repeat('.', 32); if ($print_template['goods_price_show']) { $content .= "商品名称      数量 金额
"; } else { $content .= "商品名称      数量
"; } $content .= str_repeat('.', 32) . "
"; foreach ($order_info['order_goods'] as $goods) { if ($print_template['goods_price_show']) { $str_pad = $this->r_str_pad_1($goods['sku_name'], 32); $np = ' x' . $goods['num'] . ' ¥' . $goods['price']; if (count($str_pad) > 1) { foreach ($str_pad as $k => $val) { if ($k == count($str_pad) - 1) { $content .= $this->r_str_pad_1($val, strlen($np))[0]; } else { $content .= $val . "
"; } } } else { $content .= $this->r_str_pad_1($goods['sku_name'], strlen($np))[0]; } $content .= $np . "
"; } else { $str_pad = $this->r_str_pad_1($goods['sku_name'], 16); $content .= $str_pad[0] . ' x' . $goods['num'] . "
"; } //商品编码 if ($print_template['goods_code_show'] && !empty($goods['sku_no'])) { $content .= str_repeat('.', 32); $content .= "商品编号:" . $goods['sku_no'] . "
"; } } $content .= str_repeat('.', 32) . "
"; if ($order_info["goods_money"] > 0) { $content .= "商品总额:¥" . $order_info["goods_money"] . "
"; } if ($order_info["coupon_money"] > 0) { $content .= "店铺优惠券:¥" . $order_info["coupon_money"] . "
"; } if ($order_info["promotion_money"] > 0) { $content .= "店铺优惠:¥" . $order_info["promotion_money"] . "
"; } if ($order_info["point_money"] > 0) { $content .= "积分抵扣:¥" . $order_info["point_money"] . "
"; } if ($order_info["adjust_money"] > 0) { $content .= "订单调价:¥" . $order_info["adjust_money"] . "
"; } if ($order_info['reduction'] > 0) { $content .= "订单减免:¥" . $order_info["reduction"] . "
"; } if ($order_info["balance_money"] > 0) { $content .= "余额抵扣:¥" . $order_info["balance_money"] . "
"; } if ($order_info["delivery_money"] > 0) { $content .= "配送费用:¥" . $order_info["delivery_money"] . "
"; } if ($order_info["invoice_money"] > 0) { $content .= "发票费用:¥" . $order_info["invoice_money"] . "
"; } if ($order_info["invoice_delivery_money"] > 0) { $content .= "发票邮寄费用:¥" . $order_info["invoice_delivery_money"] . "
"; } if ($order_info["goods_num"] > 0) { $content .= "订单共" . $order_info['goods_num'] . "件商品,总计: ¥" . $order_info['order_money'] . "
"; } $content .= str_repeat('.', 32); /******************** 备注信息 **************************/ //买家留言 if ($print_template['buy_notes'] == 1) { $order_info["buyer_message"] = $order_info["buyer_message"] ? $order_info["buyer_message"] : '无'; $content .= "买家留言:" . $order_info["buyer_message"] . "
"; $content .= str_repeat('.', 32); } //卖家留言 if ($print_template['seller_notes'] == 1) { $order_info["remark"] = $order_info["remark"] ? $order_info["remark"] : '无'; $content .= "卖家留言:" . $order_info["remark"] . "
"; $content .= str_repeat('.', 32); } //表单 if ($print_template['form_show'] == 1 && addon_is_exit('form')) { $form_info = model('form_data')->getInfo([['site_id', '=', $params['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 .= "" . $item['title'] . ":" . $item["val"] . "
"; $content .= str_repeat('.', 32); } } } /******************** 买家信息 **************************/ if ($order_info['member_id']) { //买家姓名 if ($print_template['buy_name'] == 1) { $content .= "" . $order_info["name"] . "
"; } //联系方式 if ($print_template['buy_mobile'] == 1) { $content .= "" . $order_info["mobile"] . "
"; } //地址 if ($print_template['buy_address'] == 1) { $content .= "" . $order_info['full_address'] . "-" . $order_info['address'] . "
"; } 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"] . "
"; } //地址 if ($print_template['shop_address'] == 1) { $content .= "" . $shop_info['province_name'] . $shop_info['city_name'] . $shop_info['district_name'] . $shop_info['address'] . "
"; } if ($print_template['shop_mobile'] == 1 || $print_template['shop_address'] == 1) { $content .= str_repeat('.', 32); } //二维码 if ($print_template['shop_qrcode'] == 1) { $content .= "" . $print_template['qrcode_url'] . ""; $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"] . "
";//门店名称 $content .= "" . $store_info["telphone"] . "
";//门店电话 $content .= "" . $store_info["full_address"] . "
";//门店地址 $content .= str_repeat('.', 32); } /******************** 团长信息 **************************/ if($order_info['order_type']==6){ $delivery_community_info=json_decode($order_info['delivery_community_info'],true); $content .= "社区:" . $delivery_community_info["name"]."
";//社区名称 $content .= "团长:" . $delivery_community_info["mobile"] . "
";//门店电话 $content .= $delivery_community_info["full_address"] . "
";//门店地址 } //底部内容 if (!empty($print_template['bottom'])) { $content .= "" . $print_template['bottom'] . ""; } $content .= "" . $print_num . ""; return $content; } public function yilianyun($order_id, $print_num, $print_template, $site_name, $shop_info, $order_info, $params) { /**文本接口开始**/ $content = "" . $print_num . ""; //小票名称 if ($print_template['title'] != '') { $content .= "
" . $print_template['title'] . "
"; $content .= str_repeat('.', 32); } //商城名称 if ($print_template['head'] == 1) { $content .= "
" . $site_name . "
"; $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"; // 2:自提提货,3:本地配送外卖 if ($order_info['order_type'] == 2 || $order_info['order_type'] == 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"; } $content .= str_repeat('.', 32); $content .= ""; $content .= ""; if ($print_template['goods_price_show']) { $content .= ""; } else { $content .= ""; } $content .= ""; $content .= "
商品名称数量金额商品名称数量
"; $content .= str_repeat('.', 32); $content .= ""; 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 .= ""; } else { $content .= ""; } //商品编码 if ($print_template['goods_code_show'] && !empty($goods['sku_no'])) { $content .= ""; } } $content .= "
" . $goods['sku_name'] . "x" . $goods['num'] . "¥" . $price . "
" . $goods['sku_name'] . "x" . $goods['num'] . "
[" . $goods['sku_no'] . "]
"; $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 .= "买家留言:" . $order_info["buyer_message"] . "\n"; $content .= str_repeat('.', 32); } //卖家留言 if ($print_template['seller_notes'] == 1) { $order_info["remark"] = $order_info["remark"] ? $order_info["remark"] : '无'; $content .= "卖家留言:" . $order_info["remark"] . "\n"; $content .= str_repeat('.', 32); } //表单 if ($print_template['form_show'] == 1 && addon_is_exit('form')) { $form_info = model('form_data')->getInfo([['site_id', '=', $params['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 .= "" . $item['title'] . ":" . $item["val"] . "\n"; $content .= str_repeat('.', 32); } } } /******************** 买家信息 **************************/ if ($order_info['member_id']) { //买家姓名 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 .= "" . $print_template['qrcode_url'] . ""; $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($order_info['order_type']==6){ $delivery_community_info=json_decode($order_info['delivery_community_info'],true); $content .= "社区:" . $delivery_community_info["name"]."\n";//社区名称 $content .= "团长:" . $delivery_community_info["mobile"] . "\n";//门店电话 $content .= $delivery_community_info["full_address"] . "\n";//门店地址 } //底部内容 if (!empty($print_template['bottom'])) { $content .= "
" . $print_template['bottom'] . "
"; } return $content; } private 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; } }