Example #1
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));
        }
Example #2
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));
        }
Example #3
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));
        }
 protected virtual void AfterPrint()
 {
     BufferList.Add(PrinterCmdUtils.NextLine(2));
     BufferList.Add(PrinterCmdUtils.FeedPaperCutAll());
 }