Пример #1
0
        protected virtual void BeforePrint()
        {
            BufferList = new List <byte[]>();
            // 打印当日序号
            BufferList.Add(PrinterCmdUtils.AlignCenter());
            BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2));
            BufferList.Add(Encoding.GetEncoding("gbk").GetBytes("#" + Order.Identifier + " 简单猫"));
            BufferList.Add(PrinterCmdUtils.NextLine());
            BufferList.Add(PrinterCmdUtils.NextLine());
            BufferList.Add(PrinterCmdUtils.AlignLeft());
            // 备注
            if (!string.IsNullOrEmpty(Order.Remark))
            {
                BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2));
                BufferList.Add(PrinterCmdUtils.BoldOn());
                BufferList.Add(Encoding.GetEncoding("gbk").GetBytes($"备注:{Order.Remark}"));
                BufferList.Add(PrinterCmdUtils.NextLine());
                BufferList.Add(PrinterCmdUtils.FontSizeSetBig(1));
                BufferList.Add(PrinterCmdUtils.BoldOff());
                BufferList.Add(PrinterCmdUtils.NextLine());
            }
            BufferList.Add(PrinterCmdUtils.FontSizeSetBig(1));

            BufferList.Add(Encoding.GetEncoding("gbk").GetBytes("下单时间:" + Order.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")));

            BufferList.Add(PrinterCmdUtils.NextLine());
            BufferList.Add(PrinterCmdUtils.SplitLine("-", Printer.Format));
            BufferList.Add(PrinterCmdUtils.NextLine());
            BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2));
        }
Пример #2
0
        /// <summary>
        /// 打印左右对齐的行
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        private byte[] PrintLineLeftRight(string left, string right, int fontSize = 1)
        {
            var zhLeft  = PrinterCmdUtils.CalcZhQuantity(left);                                   // 左边文本的中文字符长度
            var enLeft  = left.Length - zhLeft;                                                   // 左边文本的其他字符长度
            var zhRight = PrinterCmdUtils.CalcZhQuantity(right);                                  // 右边文本的中文字符长度
            var enRight = right.Length - zhRight;                                                 // 右边文本的其他字符长度
            var len     = FormatLen - ((zhLeft * 2 + enLeft + zhRight * 2 + enRight) * fontSize); // 缺少的字符长度

            if (len > 0)
            {
                for (int i = 0; i < len / fontSize; i++)
                {
                    left += " ";
                }
            }
            else
            {
                var times = 1;
                while (true)
                {
                    if (FormatLen * times + len > 0)
                    {
                        break;
                    }
                    times++;
                }
                for (int i = 0; i < (FormatLen * times + len) / fontSize; i++)
                {
                    left += " ";
                }
            }
            return(TextToByte(left + right));
        }
Пример #3
0
 protected virtual void BeforePrint()
 {
     BufferList = new List <byte[]>();
     // 打印当日序号
     BufferList.Add(PrinterCmdUtils.AlignCenter());
     BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2));
     BufferList.Add(TextToByte(Title));
     BufferList.Add(PrinterCmdUtils.NextLine());
     BufferList.Add(PrinterCmdUtils.AlignLeft());
     BufferList.Add(PrinterCmdUtils.PrintLineLeftRight($"餐桌:{Order.DeskName}", $"单号:{Order.Identifier}", fontSize: 2));
     BufferList.Add(PrinterCmdUtils.NextLine());
     if (!string.IsNullOrEmpty(Order.Remark))
     {
         BufferList.Add(PrinterCmdUtils.BoldOn());
         BufferList.Add(TextToByte($"备注:{Order.Remark}"));
         BufferList.Add(PrinterCmdUtils.NextLine());
         BufferList.Add(PrinterCmdUtils.BoldOff());
         BufferList.Add(PrinterCmdUtils.NextLine());
     }
     BufferList.Add(PrinterCmdUtils.FontSizeSetBig(1));
     BufferList.Add(TextToByte($"服务员:{Order.StaffName}"));
     BufferList.Add(PrinterCmdUtils.NextLine());
     BufferList.Add(TextToByte($"打印时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}"));
     BufferList.Add(PrinterCmdUtils.NextLine());
     BufferList.Add(PrinterCmdUtils.SplitLine("-", Printer.Device.Format));
     BufferList.Add(PrinterCmdUtils.NextLine());
     BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2));
 }
Пример #4
0
 protected override void Printing()
 {
     foreach (var product in Products)
     {
         var name = product.Name;
         if (!string.IsNullOrEmpty(product.Description))
         {
             name += $"({product.Description})";
         }
         BufferList.Add(PrinterCmdUtils.PrintLineLeftRight2("*" + product.Quantity, name, Printer.FormatLen, 2));
         BufferList.Add(PrinterCmdUtils.NextLine());
     }
 }
Пример #5
0
 private void Format(string name, string description)
 {
     BeforePrint();
     if (!string.IsNullOrEmpty(description))
     {
         name += $"({description})";
     }
     BufferList.Add(PrinterCmdUtils.FontSizeSetBig(3));
     BufferList.Add(PrinterCmdUtils.AlignLeft());
     BufferList.Add(PrinterCmdUtils.PrintLineLeftRight(name, "*1", Printer.FormatLen, 3));
     BufferList.Add(PrinterCmdUtils.NextLine());
     AfterPrint();
     Send();
 }
Пример #6
0
 protected override void Printing()
 {
     BufferList.Add(PrinterCmdUtils.FontSizeSetBig(3));
     BufferList.Add(PrinterCmdUtils.AlignLeft());
     foreach (var product in Products)
     {
         var name = product.Name;
         if (!string.IsNullOrEmpty(product.Description))
         {
             name += $"({product.Description})";
         }
         BufferList.Add(PrinterCmdUtils.PrintLineLeftRight(name, "*" + double.Parse(product.Quantity + "").ToString(), Printer.FormatLen, 3));
         BufferList.Add(PrinterCmdUtils.NextLine());
     }
 }
Пример #7
0
 private void Format(string name, string description, double quantity, string remark)
 {
     BeforePrint();
     if (!string.IsNullOrEmpty(description))
     {
         name += $"({description})";
     }
     BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2));
     BufferList.Add(PrinterCmdUtils.AlignLeft());
     BufferList.Add(PrinterCmdUtils.PrintLineLeftRight2("*" + quantity, name, Printer.FormatLen, 2));
     BufferList.Add(PrinterCmdUtils.NextLine());
     if (remark != null)
     {
         BufferList.Add(TextToByte($"备注:{remark}"));
         BufferList.Add(PrinterCmdUtils.NextLine());
     }
     AfterPrint();
     Send();
 }
Пример #8
0
        protected virtual void BeforePrint()
        {
            BufferList = new List <byte[]>();
            var sign = Order.OrderSource == 0 ? "美团" : "饿了么";

            // 打印当日序号
            BufferList.Add(PrinterCmdUtils.AlignCenter());
            BufferList.Add(PrinterCmdUtils.FontSizeSetBig(3));
            BufferList.Add(Encoding.GetEncoding("gbk").GetBytes(sign + "  #" + Order.DaySeq));
            BufferList.Add(PrinterCmdUtils.NextLine());
            if (Order.PrintTimes > 0)
            {
                BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2));
                BufferList.Add("(补打)".ToByte());
                BufferList.Add(PrinterCmdUtils.NextLine());
            }
            BufferList.Add(PrinterCmdUtils.AlignLeft());
            // 备注
            if (!string.IsNullOrEmpty(Order.Caution))
            {
                BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2));
                BufferList.Add(PrinterCmdUtils.BoldOn());
                BufferList.Add(Encoding.GetEncoding("gbk").GetBytes($"备注:{Order.Caution}"));
                BufferList.Add(PrinterCmdUtils.NextLine());
                BufferList.Add(PrinterCmdUtils.FontSizeSetBig(1));
                BufferList.Add(PrinterCmdUtils.BoldOff());
                BufferList.Add(PrinterCmdUtils.NextLine());
            }
            BufferList.Add(PrinterCmdUtils.FontSizeSetBig(1));

            BufferList.Add(Encoding.GetEncoding("gbk").GetBytes("下单时间:" + Order.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")));

            BufferList.Add(PrinterCmdUtils.NextLine());
            BufferList.Add(PrinterCmdUtils.SplitLine("-", Printer.Device.Format));
            BufferList.Add(PrinterCmdUtils.NextLine());
            BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2));
        }
Пример #9
0
        /// <summary>
        /// 打印订单商品
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        private List <byte[]> ProductLine(ThirdOrderProduct product, int fontSize = 1)
        {
            var left = product.Name;

            if (!string.IsNullOrEmpty(product.GetDesc()))
            {
                left += "(" + product.GetDesc() + ")";
            }
            var middle = "*" + Convert.ToDouble(product.Quantity);
            var right  = Convert.ToDouble(product.Price * product.Quantity) + "";
            var place  = string.Empty;

            for (int i = 0; i < maxRightLen - middle.Length - right.Length; i++)
            {
                place += " ";
            }
            right = middle + place + right;

            var buffer = PrinterCmdUtils.PrintLineLeftRight(left, right, fontSize: fontSize);

            return(new List <byte[]> {
                buffer
            });
        }
Пример #10
0
        /// <summary>
        /// 前台打印(第三方订单)
        /// </summary>
        /// <param name="order"></param>
        /// <param name="socket"></param>
        private void ReceptionPrint(ThirdOrder order, Socket socket)
        {
            var bufferArr = new List <byte[]>();
            var sign      = order.OrderSource == 0 ? "美团" : "饿了么";

            // 打印当日序号
            bufferArr.Add(PrinterCmdUtils.AlignCenter());
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(3));
            bufferArr.Add(TextToByte(sign + " #" + order.DaySeq));
            //bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
            //bufferArr.Add(TextToByte(sign));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            if (order.PrintTimes > 0)
            {
                bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
                bufferArr.Add(TextToByte("(补打)"));
                bufferArr.Add(PrinterCmdUtils.NextLine());
            }
            // 打印小票类别
            bufferArr.Add(PrinterCmdUtils.AlignLeft());
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(1));
            bufferArr.Add(TextToByte("前台小票"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 分隔
            bufferArr.Add(PrinterCmdUtils.SplitLine("-", Device.Format));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 备注
            if (!string.IsNullOrEmpty(order.Caution))
            {
                bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
                bufferArr.Add(TextToByte($"备注:{order.Caution}"));
                bufferArr.Add(PrinterCmdUtils.NextLine());
                bufferArr.Add(PrinterCmdUtils.NextLine());
            }
            // 开票信息
            if (!string.IsNullOrEmpty(order.InvoiceTitle) && !string.IsNullOrEmpty(order.TaxpayerId))
            {
                bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
                bufferArr.Add(TextToByte($"开票信息:{order.InvoiceTitle},{order.TaxpayerId}"));
                bufferArr.Add(PrinterCmdUtils.NextLine());
                bufferArr.Add(PrinterCmdUtils.NextLine());
            }
            // 商户名称
            bufferArr.Add(PrinterCmdUtils.AlignCenter());
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
            bufferArr.Add(TextToByte(ApplicationObject.App.Business.Name));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(PrinterCmdUtils.AlignLeft());
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(1));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 下单时间
            bufferArr.Add(TextToByte($"下单时间:{order.Ctime:yyyy-MM-dd HH:mm:ss}"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 订单编号
            bufferArr.Add(TextToByte($"订单编号:{order.OrderId}"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 商品分隔
            bufferArr.Add(PrinterCmdUtils.SplitText("-", "购买商品", Device.Format));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 打印商品
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
            foreach (var product in order.ThirdOrderProducts)
            {
                if (order.OrderSource == 1 && product.Name == "餐盒")
                {
                    continue;
                }
                var buffer = ProductLine(product, 2);
                buffer.ForEach(a =>
                {
                    bufferArr.Add(a);
                    bufferArr.Add(PrinterCmdUtils.NextLine());
                });
                if (product.Tag1 != null && product.Tag1.Count > 0)
                {
                    bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(1));
                    // 套餐打印明细
                    product.Tag1.ForEach(a =>
                    {
                        bufferArr.Add($"  - {a.Name}".ToByte());
                        bufferArr.Add(PrinterCmdUtils.NextLine());
                    });
                    bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
                }
            }
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(1));
            // 分隔
            bufferArr.Add(PrinterCmdUtils.SplitText("-", "其他", Device.Format));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 包装费
            bufferArr.Add(PrintLineLeftRight("包装费", order.PackageFee + ""));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 配送费
            bufferArr.Add(PrintLineLeftRight("配送费", order.ShippingFee + ""));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 满减活动打印
            if (order.ThirdOrderActivities != null && order.ThirdOrderActivities.Count > 0)
            {
                foreach (var item in order.ThirdOrderActivities)
                {
                    bufferArr.Add(PrintLineLeftRight(item.Remark, "-¥" + item.ReduceFee));
                    bufferArr.Add(PrinterCmdUtils.NextLine());
                }
            }
            // 订单金额
            bufferArr.Add(PrinterCmdUtils.AlignRight());
            bufferArr.Add(TextToByte("实付:"));
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
            bufferArr.Add(TextToByte(order.Amount + "元"));
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(1));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(PrinterCmdUtils.AlignLeft());
            // 分隔
            bufferArr.Add(PrinterCmdUtils.SplitLine("*", Device.Format));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 地址
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
            bufferArr.Add(TextToByte(order.RecipientAddress));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(TextToByte(order.RecipientPhone));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(TextToByte(order.RecipientName));
            bufferArr.Add(PrinterCmdUtils.NextLine());

            // 切割
            bufferArr.Add(PrinterCmdUtils.FeedPaperCutAll());

            // 打印
            bufferArr.ForEach(a => socket.Send(a));
        }
Пример #11
0
        /// <summary>
        /// 前台打印(堂食订单)
        /// </summary>
        /// <param name="order"></param>
        /// <param name="socket"></param>
        private void ReceptionPrint(TangOrder order, Socket socket, PrintOption option)
        {
            var bufferArr = new List <byte[]>
            {
                // 打印当日序号
                PrinterCmdUtils.AlignCenter(),
                PrinterCmdUtils.FontSizeSetBig(2),
                TextToByte(ApplicationObject.App.Business.Name),
                PrinterCmdUtils.NextLine(),
                TextToByte($"当日流水:{order.Identifier}"),
                PrinterCmdUtils.NextLine(),
                TextToByte(option.Title ?? "结账单"),
                PrinterCmdUtils.NextLine()
            };

            // 餐桌
            if (order.DeskId != null)
            {
                bufferArr.Add(PrinterCmdUtils.AlignLeft());
                bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
                bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight($"餐桌:{order.DeskName}", $"人数:{order.PeopleNumber}", fontSize: 2));
                bufferArr.Add(PrinterCmdUtils.NextLine());
            }
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(1));
            // 订单编号
            bufferArr.Add(TextToByte($"订单编号:{order.Code}"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 下单
            bufferArr.Add(TextToByte($"下单时间:{order.CreateTime:yyyy-MM-dd HH:mm:ss}"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 服务员
            bufferArr.Add(TextToByte($"收银员:{order.StaffName}"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 备注
            if (!string.IsNullOrEmpty(order.Remark))
            {
                bufferArr.Add(TextToByte($"备注:{order.Remark}"));
                bufferArr.Add(PrinterCmdUtils.NextLine());
            }
            // 商品分隔
            bufferArr.Add(PrinterCmdUtils.SplitText("-", "购买商品", Device.Format));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 打印商品
            foreach (var product in option.Products)
            {
                var buffer = ProductLine(product);
                buffer.ForEach(a =>
                {
                    bufferArr.Add(a);
                    bufferArr.Add(PrinterCmdUtils.NextLine());
                });
            }
            // 分隔
            bufferArr.Add(PrinterCmdUtils.SplitLine("-", Device.Format));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 金额
            bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("餐位费:", order.MealFee.ToString()));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("原价:", order.OriginalAmount.ToString()));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("优惠:", (order.OriginalAmount - order.Amount + order.PreferentialAmount).ToString()));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("实收:", order.ActualAmount.ToString()));
            bufferArr.Add(PrinterCmdUtils.NextLine());

            //if (!string.IsNullOrEmpty(order.PaymentTypeName))
            //{
            //    bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("付款方式:", order.PaymentTypeName));
            //    bufferArr.Add(PrinterCmdUtils.NextLine());
            //}
            if (order.TangOrderPayments != null && order.TangOrderPayments.Count > 0)
            {
                if (order.TangOrderPayments.Count == 1)
                {
                    var first = order.TangOrderPayments.First();
                    bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("付款方式:", first.Name));
                    bufferArr.Add(PrinterCmdUtils.NextLine());
                }
                else
                {
                    var first = order.TangOrderPayments.First();
                    bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("付款方式:", $"{first.Name}:{first.Amount}"));
                    bufferArr.Add(PrinterCmdUtils.NextLine());
                    for (int i = 1; i < order.TangOrderPayments.Count; i++)
                    {
                        bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("", $"{order.TangOrderPayments[i].Name}:{order.TangOrderPayments[i].Amount}"));
                        bufferArr.Add(PrinterCmdUtils.NextLine());
                    }
                }
            }
            if (!string.IsNullOrEmpty(order.PaymentRemark))
            {
                bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("支付备注:", order.PaymentRemark));
                bufferArr.Add(PrinterCmdUtils.NextLine());
            }
            // 分隔
            bufferArr.Add(PrinterCmdUtils.SplitText("-", "其他", Device.Format));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 打印时间
            bufferArr.Add(TextToByte($"打印时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(TextToByte(ApplicationObject.App.Business.Name));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(TextToByte($"电话:{ApplicationObject.App.Business.Mobile}"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(TextToByte($"地址:{ApplicationObject.App.Business.Address}"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(PrinterCmdUtils.AlignCenter());
            bufferArr.Add(TextToByte($"谢谢您的惠顾"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(PrinterCmdUtils.AlignLeft());
            bufferArr.Add(PrinterCmdUtils.NextLine());

            // 切割
            bufferArr.Add(PrinterCmdUtils.FeedPaperCutAll());

            // 打印
            bufferArr.ForEach(a => socket.Send(a));
        }
Пример #12
0
        /// <summary>
        /// 前台打印
        /// </summary>
        /// <param name="order"></param>
        /// <param name="socket"></param>
        private void ReceptionPrint(Order order, Socket socket)
        {
            var bufferArr = new List <byte[]>();

            // 打印当日序号
            bufferArr.Add(PrinterCmdUtils.AlignCenter());
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(3));
            bufferArr.Add(TextToByte("简单猫 #" + order.Identifier));
            //bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
            //bufferArr.Add(TextToByte("简单猫"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 打印小票类别
            bufferArr.Add(PrinterCmdUtils.AlignLeft());
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(1));
            bufferArr.Add(TextToByte("前台小票"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 分隔
            bufferArr.Add(PrinterCmdUtils.SplitLine("-", Device.Format));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 备注
            if (!string.IsNullOrEmpty(order.Remark))
            {
                bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
                bufferArr.Add(TextToByte($"备注:{order.Remark}"));
                bufferArr.Add(PrinterCmdUtils.NextLine());
                bufferArr.Add(PrinterCmdUtils.NextLine());
            }
            // 开票信息
            if (!string.IsNullOrEmpty(order.InvoiceTax) && !string.IsNullOrEmpty(order.InvoiceName))
            {
                bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
                bufferArr.Add(TextToByte($"开票信息:{order.InvoiceName},{order.InvoiceTax}"));
                bufferArr.Add(PrinterCmdUtils.NextLine());
                bufferArr.Add(PrinterCmdUtils.NextLine());
            }
            // 商户名称
            bufferArr.Add(PrinterCmdUtils.AlignCenter());
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
            bufferArr.Add(TextToByte(ApplicationObject.App.Business.Name));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(PrinterCmdUtils.AlignLeft());
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(1));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 下单时间
            bufferArr.Add(TextToByte($"下单时间:{order.PayTime:yyyy-MM-dd HH:mm:ss}"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 订单编号
            bufferArr.Add(TextToByte($"订单编号:{order.OrderCode}"));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 商品分隔
            bufferArr.Add(PrinterCmdUtils.SplitText("-", "购买商品", Device.Format));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 打印商品
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
            foreach (var product in order.Products)
            {
                var buffer = ProductLine(product, 2);
                buffer.ForEach(a =>
                {
                    bufferArr.Add(a);
                    bufferArr.Add(PrinterCmdUtils.NextLine());
                });
                if (product.Tag1 != null && product.Tag1.Count > 0)
                {
                    bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(1));
                    // 套餐打印明细
                    product.Tag1.ForEach(a =>
                    {
                        bufferArr.Add($"  - {a.Name}".ToByte());
                        bufferArr.Add(PrinterCmdUtils.NextLine());
                    });
                    bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
                }
            }
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(1));
            // 分隔
            bufferArr.Add(PrinterCmdUtils.SplitText("-", "其他", Device.Format));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 包装费
            if (order.PackagePrice.HasValue)
            {
                bufferArr.Add(PrintLineLeftRight("包装费", double.Parse(order.PackagePrice + "") + ""));
                bufferArr.Add(PrinterCmdUtils.NextLine());
            }
            // 配送费
            bufferArr.Add(PrintLineLeftRight("配送费", double.Parse(order.Freight + "") + ""));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 满减活动打印
            if (order.SaleFullReduce != null)
            {
                bufferArr.Add(PrintLineLeftRight(order.SaleFullReduce.Name, "-¥" + double.Parse(order.SaleFullReduce.ReduceMoney + "") + ""));
                bufferArr.Add(PrinterCmdUtils.NextLine());
            }
            // 优惠券打印
            if (order.SaleCouponUser != null)
            {
                bufferArr.Add(PrintLineLeftRight(order.SaleCouponUser.Name, "-¥" + order.SaleCouponUser.Value + ""));
                bufferArr.Add(PrinterCmdUtils.NextLine());
            }
            // 订单金额
            bufferArr.Add(PrinterCmdUtils.AlignRight());
            bufferArr.Add(TextToByte("实付:"));
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
            bufferArr.Add(TextToByte(order.Price + "元"));
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(1));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(PrinterCmdUtils.AlignLeft());
            // 分隔
            bufferArr.Add(PrinterCmdUtils.SplitLine("*", Device.Format));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            // 地址
            bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2));
            bufferArr.Add(TextToByte(order.ReceiverAddress));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(TextToByte(order.Phone));
            bufferArr.Add(PrinterCmdUtils.NextLine());
            bufferArr.Add(TextToByte(order.ReceiverName));
            bufferArr.Add(PrinterCmdUtils.NextLine());

            // 切割
            bufferArr.Add(PrinterCmdUtils.FeedPaperCutAll());

            // 打印
            bufferArr.ForEach(a => socket.Send(a));
        }
Пример #13
0
 protected virtual void AfterPrint()
 {
     BufferList.Add(PrinterCmdUtils.NextLine(2));
     BufferList.Add(PrinterCmdUtils.FeedPaperCutAll());
 }