Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ActionResult Edit(string act = "", int id = 0, int aId = 0, int storeId = 0, DishPrint model = null, int fid = 0, List <string> printtags = null)
        {
            //参数验证
            if (id < 0 || aId <= 0 || storeId <= 0)
            {
                _result.msg = "参数错误";
                return(Json(_result));
            }
            //显示
            if (string.IsNullOrEmpty(act))
            {
                if (id == 0)
                {
                    model = new DishPrint();
                }
                else
                {
                    model = DishPrintBLL.SingleModel.GetModel(id);
                    if (model == null)
                    {
                        return(Content("打印机不存在"));
                    }
                }
                EditModel <DishPrint> em = new EditModel <DishPrint>();
                em.DataModel             = model;
                em.aId                   = aId;
                em.storeId               = storeId;
                ViewBag.dishPrintTagList = DishTagBLL.SingleModel.GetList($"state=1 and aid={aId} and storeId={storeId}");
                return(View(em));
            }
            else
            {
                if (act == "edit")
                {
                    model.print_tags = printtags != null?string.Join(",", printtags) : "";

                    if (id == 0)
                    {
                        //先访问易连云接口添加,成功后才在系统内添加记录
                        PrintErrorData returnMsg = FoodYiLianYunPrintHelper.addPrinter(model.apiPrivateKey, model.platform_userId.ToString(), model.print_bianma, model.print_shibiema, "", model.platform_userName, model.print_name);
                        if (returnMsg.errno != 1)//returnMsg.errno>2 建议这里大于2
                        {
                            _result.msg = returnMsg.error;
                            return(Json(_result));
                        }
                        int newid = Convert.ToInt32(DishPrintBLL.SingleModel.Add(model));
                        _result.msg  = newid > 0 ? "添加成功" : "添加失败";
                        _result.code = newid > 0 ? 1 : 0;
                    }
                    else
                    {
                        bool updateResult = DishPrintBLL.SingleModel.Update(model, "print_name,print_type,print_d_type,print_dnum,print_ziti_type,print_goods_ziti_type,print_top_copy,print_bottom_copy,print_tags,state");
                        _result.msg  = updateResult ? "修改成功" : "修改失败";
                        _result.code = updateResult ? 1 : 0;
                    }
                }
            }
            return(Json(_result));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 智慧餐厅打单内容 - 分单
        /// </summary>
        /// <returns></returns>
        public static List <string> GetPrintContent_Part(DishStore store, DishOrder order, List <DishShoppingCart> carts, DishPrint print)
        {
            List <string>   printContents = new List <string>();
            string          printContent  = string.Empty;
            List <DishGood> goods         = DishGoodBLL.SingleModel.GetList($" id in ({string.Join(",", carts.Select(c => c.goods_id))}) ");

            if (goods == null)
            {
                log4net.LogHelper.WriteInfo(typeof(PrinterHelper), $"参数为空导致无法打印:goods:{goods == null}");
                return(printContents);
            }

            //得出此次要打印的购物车记录
            List <DishShoppingCart> printShoppingCarts = carts;

            if (!string.IsNullOrWhiteSpace(print.print_tags))
            {
                int[] selTagsId = print.print_tags.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToArray();
                printShoppingCarts = (from c in carts
                                      join g in goods on c.goods_id equals g.id
                                      where selTagsId.Contains(g.g_print_tag)
                                      select c)?.ToList();
            }
            if (printShoppingCarts == null || !printShoppingCarts.Any())
            {
                return(printContents);                                                         //当前打印机无要打印的内容
            }
            //处理商品字体
            Func <string, string> goodsFont = (info) =>
            {
                if (print.print_goods_ziti_type == 0)
                {
                    return($"{info}");
                }
                else
                {
                    return($"<FS2>{info}</FS2>");
                }
            };

            //处理其它资料字体
            Func <string, string> msgFont = (info) =>
            {
                if (print.print_ziti_type == 0)
                {
                    return($"{info}");
                }
                else
                {
                    return($"<FS>{info}</FS>");
                }
            };

            #region 分单打单
            foreach (DishShoppingCart item in printShoppingCarts)
            {
                printContent  = string.Empty;
                printContent += $"<MC>0,00005,0</MC><MN>{print.print_dnum}</MN>";
                printContent += $"<FS2>{store.dish_name}</FS2>\r\n";
                printContent += $"<FS2>{order.order_haoma}号</FS2>\r\n";
                printContent += $"<FS2>{order.order_type_txt}订单{(!string.IsNullOrWhiteSpace(order.order_table_id) ? $":{order.order_table_id}" : string.Empty)}</FS2>\r\n";
                printContent += "<table><tr><td>@@2................................</td></tr>";
                //printContent += $"<tr><td>{msgFont("菜品")}       </td><td>{msgFont("单价")} </td><td>{msgFont("数量")} </td><td>{msgFont("金额")} </td></tr>";
                printContent += $"<tr><td>{msgFont("菜品")}       </td><td>{msgFont("数量")} </td><td>{msgFont("金额")} </td></tr>";
                printContent += $"<tr><td>┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄</td></tr>";
                if (!string.IsNullOrEmpty(item.goods_attr))
                {
                    //printContent += $"<tr><td>{goodsFont($"{item.goods_name}({item.goods_attr})")}</td><td>{msgFont(item.goods_price.ToString())}  </td><td>{msgFont(item.goods_number.ToString())}  </td><td>{msgFont((item.goods_price * item.goods_number).ToString())}  </td></tr>";
                    printContent += $"<tr><td>{goodsFont($"{item.goods_name}({item.goods_attr})")}</td><td>{msgFont(item.goods_number.ToString())}  </td><td>{msgFont((item.goods_price * item.goods_number).ToString())}  </td></tr>";
                }
                else
                {
                    //printContent += $"<tr><td>{goodsFont(item.goods_name)}</td><td>{msgFont(item.goods_price.ToString())}  </td><td>{msgFont(item.goods_number.ToString())}  </td><td>{msgFont((item.goods_price * item.goods_number).ToString())}  </td></tr>";
                    printContent += $"<tr><td>{goodsFont(item.goods_name)}</td><td>x{msgFont(item.goods_number.ToString())}  </td><td>{msgFont((item.goods_price * item.goods_number).ToString())}  </td></tr>";
                }
                printContent += $"</table>";
                printContent += $"┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄\r\n";
                printContent += $"{msgFont($"订单号:{order.order_sn}")}\r\n";
                printContent += $"{msgFont($"下单时间:{order.add_time_txt}")}\r\n";
                printContent += $"{msgFont($"订单备注:{order.post_info}")}\r\n";

                printContents.Add(printContent);//添加入分单内容集合
            }
            #endregion
            return(printContents);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 智慧餐厅打单内容 - 总单
        /// </summary>
        /// <returns></returns>
        public static string GetPrintContent_Total(DishStore store, DishOrder order, List <DishShoppingCart> carts, DishPrint print)
        {
            string          printContent = string.Empty;
            List <DishGood> goods        = DishGoodBLL.SingleModel.GetList($" id in ({string.Join(",", carts.Select(c => c.goods_id))}) ");

            if (goods == null)
            {
                log4net.LogHelper.WriteInfo(typeof(PrinterHelper), $"参数为空导致无法打印:goods:{goods == null}");
                return(printContent);
            }

            List <DishShoppingCart> printShoppingCarts = carts;

            //得出此次要打印的购物车记录
            if (!string.IsNullOrWhiteSpace(print.print_tags))
            {
                int[] selTagsId = print.print_tags.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToArray();
                printShoppingCarts = (from c in carts
                                      join g in goods on c.goods_id equals g.id
                                      where selTagsId.Contains(g.g_print_tag)
                                      select c)?.ToList();
            }
            if (printShoppingCarts == null || !printShoppingCarts.Any())
            {
                return(printContent);                                                         //当前打印机无要打印的内容
            }
            //处理商品字体
            Func <string, string> goodsFont = (info) =>
            {
                if (print.print_goods_ziti_type == 0)
                {
                    return($"{info}");
                }
                else
                {
                    return($"<FS2>{info}</FS2>");
                }
            };

            //处理其它资料字体
            Func <string, string> msgFont = (info) =>
            {
                if (print.print_ziti_type == 0)
                {
                    return($"{info}");
                }
                else
                {
                    return($"<FS>{info}</FS>");
                }
            };

            #region 订单打单内容拼接
            printContent  = string.Empty;
            printContent += $"<MC>0,00005,0</MC><MN>{print.print_dnum}</MN>";
            printContent += $"<center>{print.print_top_copy}</center>\r\n";
            printContent += $"<FS2>{store.dish_name}</FS2>\r\n";
            printContent += $"<FS2>{order.order_haoma}号</FS2>\r\n";
            printContent += $"<FS2>{order.order_type_txt}订单{(!string.IsNullOrWhiteSpace(order.order_table_id) ? $":{order.order_table_id}" : string.Empty)}</FS2>\r\n";
            printContent += "<table><tr><td>@@2................................</td></tr>";
            //printContent += $"<tr><td>{msgFont("名称")}   </td><td>{msgFont("单价")}  </td><td>{msgFont("数量")} </td><td>{msgFont("金额")}</td></tr>";
            printContent += $"<tr><td>{msgFont("名称")}   </td><td>{msgFont("数量")}  </td><td>{msgFont("金额")}  </td></tr>";
            printContent += $"<tr><td>┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄</td></tr>";
            foreach (DishShoppingCart item in printShoppingCarts)
            {
                if (!string.IsNullOrEmpty(item.goods_attr))
                {
                    //printContent += $"<tr><td>{goodsFont($"{item.goods_name}({item.goods_attr})")}</td><td>{msgFont(item.goods_price.ToString())}  </td><td>{msgFont(item.goods_number.ToString())}  </td><td>{msgFont((item.goods_price * item.goods_number).ToString())}  </td></tr>";
                    printContent += $"<tr><td>{goodsFont($"{item.goods_name}({item.goods_attr})")}</td><td>{msgFont(item.goods_number.ToString())}  </td><td>{msgFont((item.goods_price * item.goods_number).ToString())}  </td></tr>";
                }
                else
                {
                    //printContent += $"<tr><td>{goodsFont(item.goods_name)}</td><td>{msgFont(item.goods_price.ToString())}  </td><td>{msgFont(item.goods_number.ToString())}  </td><td>{msgFont((item.goods_price * item.goods_number).ToString())}  </td></tr>";
                    printContent += $"<tr><td>{goodsFont(item.goods_name)}</td><td>x{msgFont(item.goods_number.ToString())}  </td><td>{msgFont((item.goods_price * item.goods_number).ToString())}  </td></tr>";
                }
            }

            #region 优惠内容
            string youhuiContent = string.Empty;
            if (order.shipping_fee > 0.00d)
            {
                youhuiContent += $"<tr><td>{msgFont("配送费")}</td><td></td><td></td><td>{msgFont($"¥{order.shipping_fee}")}</td></tr>";
            }
            if (order.dabao_fee > 0.00d)
            {
                youhuiContent += $"<tr><td>{msgFont("餐盒费")}</td><td></td><td></td><td>{msgFont($"¥{order.dabao_fee}")}</td></tr>";
            }
            if (order.huodong_quan_jiner > 0.00d)
            {
                youhuiContent += $"<tr><td>{msgFont("优惠券")}</td><td></td><td></td><td>{msgFont($"¥{order.huodong_quan_jiner}")}</td></tr>";
            }
            if (order.huodong_shou_jiner > 0.00d)
            {
                youhuiContent += $"<tr><td>{msgFont("首单减")}</td><td></td><td></td><td>{msgFont($"¥{order.huodong_shou_jiner}")}</td></tr>";
            }
            if (order.huodong_manjin_jiner > 0.00d)
            {
                youhuiContent += $"<tr><td>{msgFont("满减")}</td><td></td><td></td><td>{msgFont($"¥{order.huodong_manjin_jiner}")}</td></tr>";
            }

            //优惠文案不为空时才添加到打印内容
            if (!string.IsNullOrWhiteSpace(youhuiContent))
            {
                printContent += $"<tr><td>┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄</td></tr>" + youhuiContent;
            }
            #endregion

            printContent += $"</table>";
            printContent += $"┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄\r\n";

            string payText = order.pay_name;
            if ((int)DishEnums.PayMode.微信支付 == order.pay_id)
            {
                payText = order.pay_status == (int)DishEnums.PayState.未付款 ? "微信未支付" :
                          order.pay_status == (int)DishEnums.PayState.已付款 ? "微信已支付" : payText;
            }
            printContent += $"{msgFont($"合计:¥{order.settlement_total_fee} {(order.pay_id > 0 ? $"({payText})" : "")}")}\r\n";
            printContent += $"{msgFont($"订单号:{order.order_sn}")}\r\n";
            printContent += $"{msgFont($"下单时间:{order.add_time_txt}")}\r\n";
            printContent += $"{msgFont($"订单备注:{order.post_info}")}\r\n";

            if (order.order_type == (int)DishEnums.OrderType.外卖)//外卖额外信息
            {
                printContent += $"┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄\r\n";
                printContent += $"<FW2><FH2>配送信息</FH2></FW2>\r\n";
                printContent += $"{msgFont($"收货人:{order.consignee}")}\r\n";
                printContent += $"{msgFont($"收货地址:{order.address}")}\r\n";
                printContent += $"{msgFont($"联系电话:{order.mobile}")}\r\n";
            }
            if (order.is_fapiao == 1)//如果要发票
            {
                printContent += $"{msgFont($"发票:【{order.fapiao_leixing_txt}】【{order.fapiao_text}】【{order.fapiao_no}】")}\r\n";
            }
            printContent += $"<center>{print.print_bottom_copy}</center>\r\n";
            #endregion

            return(printContent);
        }
Ejemplo n.º 4
0
        public ActionResult Index(string act = "", int id = 0, int aId = 0, int storeId = 0, int pageIndex = 0, int pageSize = 20)
        {
            //显示
            if (string.IsNullOrEmpty(act))
            {
                ViewModel <DishPrint> vm = new ViewModel <DishPrint>();
                vm.DataList = DishPrintBLL.SingleModel.GetListBySql($"select * from dishprint where state >-1 and aid={aId} and storeid={storeId}");
                if (vm.DataList != null && vm.DataList.Count > 0)
                {
                    foreach (var item in vm.DataList)
                    {
                        if (!string.IsNullOrEmpty(item.print_tags))
                        {
                            List <DishTag> tagList = DishTagBLL.SingleModel.GetList($" id in ({item.print_tags})");
                            item.tags = string.Join(",", tagList.Select(tag => tag.name));
                        }
                    }
                }
                vm.PageIndex = pageIndex;
                vm.PageSize  = pageSize;
                vm.aId       = aId;
                vm.storeId   = storeId;
                return(View(vm));
            }
            else
            {
                if (id <= 0)
                {
                    _result.msg = "参数错误";
                }
                else
                {
                    DishPrint updateModel = DishPrintBLL.SingleModel.GetModel(id);
                    if (updateModel != null)
                    {
                        bool updateResult = false;
                        switch (act)
                        {
                        case "del":     //删除
                            switch (updateModel.print_name_type)
                            {
                            case 0:
                                //先访问易连云接口删除,成功后才在系统内操作记录
                                string returnMsg = FoodYiLianYunPrintHelper.deletePrinter(updateModel.apiPrivateKey, updateModel.platform_userId.ToString(), updateModel.print_bianma, updateModel.print_shibiema);
                                break;

                            default:
                                break;
                            }

                            //if (isDeletePrintByDiSanFang_Success)
                            //{
                            //无论打印机解绑失败与否,都让用户删除打印机。避免用户在第三方平台上删除后,此打印机删除不了的情况
                            updateModel.state = -1;
                            updateResult      = DishPrintBLL.SingleModel.Update(updateModel);
                            if (updateResult)
                            {
                                _result.code = 1;
                                _result.msg  = "删除成功";
                            }
                            else
                            {
                                _result.msg = "删除失败";
                            }
                            //}
                            //else
                            //{
                            //    _result.msg = "解绑第三方平台打印机绑定失败,删除失败";
                            //}
                            break;

                        case "ban":
                            updateModel.state = 0;
                            updateResult      = DishPrintBLL.SingleModel.Update(updateModel);
                            if (updateResult)
                            {
                                _result.code = 1;
                                _result.msg  = "操作成功";
                            }
                            else
                            {
                                _result.msg = "操作失败";
                            }
                            break;

                        case "start":
                            updateModel.state = 1;
                            updateResult      = DishPrintBLL.SingleModel.Update(updateModel);
                            if (updateResult)
                            {
                                _result.code = 1;
                                _result.msg  = "操作成功";
                            }
                            else
                            {
                                _result.msg = "操作失败";
                            }
                            break;
                        }
                    }
                    else
                    {
                        _result.msg = "删除失败,数据不存在或已删除";
                    }
                }
            }
            return(Json(_result));
        }