Пример #1
0
        /// <summary>
        /// 生成结账单
        /// </summary>
        /// <param name="order"></param>
        /// <param name="curorderDetailList"></param>
        /// <returns></returns>
        public static string GenerateBill(Curorder order, ObservableCollection <CurorderDetail> DetailList, string PayType)
        {
            int     col1 = 16, col2 = 8, col3 = 8;
            decimal sum = 0, qtys = 0;
            string  s = string.Empty;

            s += CharTool.Append(App.DinnerName);
            s += CharTool.Append("结账单");
            s += CharTool.Append("流水:" + order.CurorderId, AlignType.Left);
            s += CharTool.Split();

            s += CharTool.Append("品名", AlignType.Left, col1) + CharTool.Append("数量", AlignType.Left, col2) + CharTool.Append("单价", AlignType.Left, col3);
            s += "\n";

            foreach (var item in DetailList)
            {
                qtys += item.Quantity;
                sum  += item.Quantity * item.Price * item.DiscountRate;
                s    += CharTool.Append(item.DishName, AlignType.Left, col1) + CharTool.Append(item.Quantity, AlignType.Left, col2) + CharTool.Append(item.Price, AlignType.Left, col3);
                s    += "\n";
            }
            s += CharTool.Split();
            s += CharTool.Append("合计:", AlignType.Left, col1) + CharTool.Append(qtys.ToString("0.00"), AlignType.Left, col2) + CharTool.Append(sum.ToString("0.00"), AlignType.Left, col3);
            s += "\n";
            s += CharTool.Append(PayType + "支付", AlignType.Left, col1);
            s += CharTool.Append("收银:" + App.OperatorId, AlignType.Right, col2 + col3);
            s += "\n";
            s += CharTool.Append(DateTime.Now, AlignType.Left);
            s += CharTool.Append("欢迎下次光临");
            return(s);
        }
Пример #2
0
        private Curorder CreateCurorder()
        {
            string   id    = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            Curorder order = new Curorder();

            order.AllDiscount  = "0";
            order.Amount       = OrderedDishAmount;
            order.CurorderId   = "ZD" + id;
            order.Discount     = 0;
            order.DiscountRate = 1.00m;
            order.DishAmount   = OrderedDishAmount;
            order.FreeCharge   = 0;
            order.HmeOrderId   = "CRM" + App.ShopId + id;
            order.HmeUserId    = 0;
            order.Operatorname = App.OperatorName;
            order.OrderDate    = DateTime.Now;
            order.Paytype      = PayType;
            order.PeopleNum    = 0;
            order.Posname      = "快餐厅";
            order.PrepayAmount = 0;
            order.Roomfee      = 0;
            order.Shift        = DbTool.GetShift();
            order.Shouldpay    = OrderedDishAmount;
            order.Srvfee       = 0.00m;
            order.SrvRate      = 0.00m;
            order.TableName    = App.TableName;
            order.HmeTableId   = App.HmeTableId;
            order.Waiter       = App.OperatorName;
            order.Yetpay       = OrderedDishAmount;
            return(order);
        }
Пример #3
0
        private Hisorder CurorderToHisorder(Curorder order)
        {
            Hisorder h = new Hisorder();

            h.AllDiscount  = order.AllDiscount;
            h.Amount       = order.Amount;
            h.BillDate     = DateTime.Now;
            h.Discount     = order.Discount;
            h.DiscountRate = order.DiscountRate;
            h.DishAmount   = order.DishAmount;
            h.FreeCharge   = order.FreeCharge;
            h.HisorderId   = order.CurorderId;
            h.HmeOrderId   = order.HmeOrderId;
            h.HmeTableId   = order.HmeTableId;
            h.HmeUserId    = order.HmeUserId;
            h.Operatorname = order.Operatorname;
            h.OrderDate    = order.OrderDate;
            h.Paytype      = order.Paytype;
            h.PeopleNum    = order.PeopleNum;
            h.Posname      = order.Posname;
            h.PrepayAmount = order.PrepayAmount;
            h.Roomfee      = order.Roomfee;
            h.Shift        = order.Shift;
            h.Shouldpay    = order.Shouldpay;
            h.Srvfee       = order.Srvfee;
            h.TableName    = order.TableName;
            h.Waiter       = order.Waiter;
            h.Yetpay       = order.Yetpay;
            return(h);
        }
Пример #4
0
        public Curorder GetByTablename(string tablename)
        {
            string    sql = "select * from curorder where tablename = ?";
            DataTable dt  = OdbcTool.ExecuteDataTable(sql, tablename);

            dt.TableName = "curorder";
            Curorder o = dt.ToEntity <Curorder>();

            return(o);
        }
Пример #5
0
        public Curorder GetByCurorderId(string id)
        {
            Curorder  o   = new Curorder();
            string    sql = "select * from curorder where curorder_id = ?";
            DataTable dt  = OdbcTool.ExecuteDataTable(sql, id);

            dt.TableName = "curorder";
            o            = dt.ToEntity <Curorder>();
            return(o);
        }
Пример #6
0
        public MsgArgs Request(Curorder order, IList <CurorderDetail> details)
        {
            init();
            JObject json = new JObject();

            json.Add(new JProperty("clientNo", is_ClientNo));
            json.Add(new JProperty("version", is_Version));
            json.Add(new JProperty("shopId", is_ShopId));
            json.Add(new JProperty("account", is_Account));
            json.Add(new JProperty("timestamp", timestamp));

            string serialNo   = order.CurorderId;
            string totalMoney = order.Shouldpay.ToString("0.00");
            string mac        = Tools.MD5Encode(is_ClientNo + is_Version + is_ShopId + serialNo + totalMoney + payState + is_Account + timestamp + is_Key);

            json.Add(new JProperty("mac", mac));
            json.Add(new JProperty("serialNo", serialNo));
            json.Add(new JProperty("userId", order.HmeUserId));
            json.Add(new JProperty("giveIntegral", 0));
            json.Add(new JProperty("tableId", order.HmeTableId));
            json.Add(new JProperty("tableName", order.TableName));
            json.Add(new JProperty("shopAreaName", order.Posname + "-" + order.TableName));
            json.Add(new JProperty("consumeTime", order.OrderDate.ToString("yyyy-MM-dd HH:mm:ss")));
            json.Add(new JProperty("endTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
            json.Add(new JProperty("containOrderNos", order.HmeOrderId));
            json.Add(new JProperty("mealFee", 0));
            json.Add(new JProperty("serviceFeeRatio", order.SrvRate));
            json.Add(new JProperty("roomFee", order.Roomfee));
            json.Add(new JProperty("serviceFee", order.Srvfee));
            json.Add(new JProperty("nonZero", order.FreeCharge));
            json.Add(new JProperty("totalMoney", order.Shouldpay));
            json.Add(new JProperty("offLinePayMoney", 0));
            json.Add(new JProperty("isWholeBill", order.AllDiscount));
            json.Add(new JProperty("ratePerson", order.DiscountRate));
            json.Add(new JProperty("payState", payState));

            JArray array = new JArray();

            foreach (var item in details)
            {
                JObject o = new JObject();
                o.Add(new JProperty("dishId", item.DishId));
                o.Add(new JProperty("dishName", item.DishName));
                o.Add(new JProperty("quantity", item.Quantity));
                o.Add(new JProperty("price", item.Price));
                o.Add(new JProperty("orderType", item.OrderType));
                o.Add(new JProperty("unit", item.Unit));
                o.Add(new JProperty("orderDetailId", 0));
                array.Add(o);
            }
            json.Add(new JProperty("detail", array));
            string response = HttpTool.PostDefault(HttpMethodInfo.Submit_Consume_Serial, json.ToString());

            return(ParseResponse(response));
        }
Пример #7
0
        /// <summary>
        /// 结账逻辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="para"></param>
        /// <returns></returns>
        private object DoCheckout(object sender, object para)
        {
            MsgArgs arg = para as MsgArgs;

            if (arg == null)
            {
                throw new Exception(string.Format("获取结账返回参数出错!"));
            }

            try
            {
                string PayCode = arg.Extra["PayCode"].ToString();
                PayType = arg.Extra["PayType"].ToString();
                int      PayChannel = int.Parse(arg.Extra["PayChannel"].ToString());
                Curorder order      = CreateCurorder();
                int      index      = 0;
                foreach (var item in CurorderDetailList)
                {
                    item.CurorderId      = order.CurorderId;
                    item.CurrderDetailId = "MX" + DateTime.Now.ToString("yyMMddHHmmss") + (++index).ToString("000");
                }
                CurorderService service = new CurorderService();
                //添加账单及付款请求
                service.AddOrder(order, CurorderDetailList, PayChannel, PayCode);
                //生成结账单字符串
                string str = BillTemplate.GenerateBill(order, CurorderDetailList, PayType);

                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    CurorderDetailList.Clear();
                    RaisePropertyChanged("OrderedDishQty");
                    RaisePropertyChanged("OrderedDishAmount");
                }
                                                                 ));
                return(new MsgArgs(MsgCode.Succ)
                {
                    Content = str
                });
            }
            catch (Exception e)
            {
                return(new MsgArgs(MsgCode.Faild, e.Message));
            }
        }
Пример #8
0
        /// <summary>
        /// 添加客单
        /// </summary>
        /// <returns></returns>
        public bool AddOrder(Curorder order, IList <CurorderDetail> details, int channel, string paycode)
        {
            int    UserId         = 0;
            string Phone          = string.Empty;
            string HmeFlowId_Last = string.Empty;

            if (order == null || details.Count < 1)
            {
                throw new Exception("客单或客单明细不能为空");
            }

            if (channel > 0)  //如果非现金支付
            {
                Debug.WriteLine(DateTime.Now.ToString() + "\r\n开始提交预结账流水", "结账");
                //提交消费流水(预流水)
                MsgArgs msg = (new HttpSubmitConsumeSerial("0")).Request(order, details);
                if (msg.Code != 1)
                {
                    throw new Exception("提交流水失败\n" + msg.ErrMessage);
                }
                Debug.WriteLine(DateTime.Now.ToString() + "\r\n开始支付", "结账");
                //提交扫码支付
                msg = (new HttpMicropay()).Request(order.HmeOrderId, channel, paycode);
                if (msg.Code != 1)
                {
                    throw new Exception("付款失败\n" + msg.ErrMessage);
                }
                Debug.WriteLine(DateTime.Now.ToString() + "\r\n支付返回", "结账");
                JObject jobj = JObject.Parse(msg.Content);
                if (string.IsNullOrEmpty(jobj["data"]["userId"].ToString()))
                {
                    UserId = 0;
                }
                else
                {
                    UserId = int.Parse(jobj["data"]["userId"].ToString());
                }
                Phone = jobj["data"]["phone"].ToString();
            }

            //转换当前客单及明细为历史客单及明细
            Hisorder h = CurorderToHisorder(order);

            order.HmeUserId = UserId;
            h.HmeUserId     = UserId;
            List <HisorderDetail> hlist = new List <HisorderDetail>();
            Bill bill = CreateBill(h);

            for (int i = 0; i < details.Count; i++)
            {
                hlist.Add(CurorderDetailToHisorderDetail(details[i]));
            }
            try
            {
                Debug.WriteLine(DateTime.Now.ToString() + "\r\n开始保存本地账单", "结账");
                OdbcTransTool tran = new OdbcTransTool();
                OdbcCommand   cmd;
                DataTable     dtHisorder = EntityTool.EntityToDataTable <Hisorder>(h, out cmd);
                tran.UpdateDataTableUsingTrans(dtHisorder, cmd);
                DataTable dtHisorderDetail = EntityTool.EntityListToDataTable(hlist, out cmd);
                tran.UpdateDataTableUsingTrans(dtHisorderDetail, cmd);
                DataTable dtBill = EntityTool.EntityToDataTable <Bill>(bill, out cmd);
                tran.UpdateDataTableUsingTrans(dtBill, cmd);
                tran.Commit();
                Debug.WriteLine(DateTime.Now.ToString() + "\r\n本地账单保存完成", "结账");
                try
                {
                    Debug.WriteLine(DateTime.Now.ToString() + "\r\n开始提交最终结账流水", "结账");
                    //提交消费流水(最终流水),就算失败也不影响结账流程
                    MsgArgs msg = (new HttpSubmitConsumeSerial("1")).Request(order, details);
                    if (msg.Code != 1)
                    {
                        MessageBox.Show("结账成功但提交流水失败\n" + msg.ErrMessage, "提示信息");
                    }
                    Debug.WriteLine(DateTime.Now.ToString() + "\r\n最终结账流水提交完成", "结账");
                    HmeFlowId_Last = JObject.Parse(msg.Content)["data"].ToString();
                }
                catch (Exception e)
                {
                    MessageBox.Show("结账成功但提交流水失败\n" + e.Message, "提示信息");
                }
                string sql = "update hisorder set hme_id = ? where hisorder_id = ?";
                OdbcTool.ExecuteSql(sql, HmeFlowId_Last, h.HisorderId.Substring(0, 18));
                return(true);
            }
            catch (Exception e)
            {
                throw new Exception("添加客单失败\n" + e.Message);
            }
        }