Esempio n. 1
0
        public ActionResult SearchMemberInfo(string text)
        {
            Response res = new Response();

            res.Successed = false;
            try
            {
                var currentUser = OperatorProvider.Provider.GetCurrent();
                var verifyInfo  = new VerifySourceInfoDTO();
                verifyInfo.RestaruantId = currentUser.DepartmentId.ToInt();
                var resultInfo = _checkOutService.VerifyOutsideInfo(verifyInfo);
                if (resultInfo != null && resultInfo.Count > 0)
                {
                    res.Successed = true;
                }
                else
                {
                    res.Message = "网络故障,请稍后重新操作!";
                }
                res.Data = resultInfo;

                return(Json(res));
            }
            catch (Exception ex)
            {
                res.Message = ex.Message;
            }

            return(Json(res));
        }
Esempio n. 2
0
        public ActionResult VerifyByOutsideInfo(int id, string name, decimal money, CyddPayType payType)
        {
            Response res = new Response();

            res.Successed = false;
            try
            {
                var currentUser = OperatorProvider.Provider.GetCurrent();
                var verifyInfo  = new VerifySourceInfoDTO();
                verifyInfo.SourceId     = id;
                verifyInfo.SourceName   = name;
                verifyInfo.RestaruantId = currentUser.DepartmentId.ToInt();
                verifyInfo.PayMethod    = (int)payType;
                verifyInfo.OperateValue = money;
                var resultInfo = _checkOutService.VerifyOutsideInfo(verifyInfo);
                if (resultInfo != null && resultInfo.Count > 0)
                {
                    res.Successed = true;
                }
                else
                {
                    res.Message = "网络故障,请稍后重新操作!";
                }
                res.Data = resultInfo;

                return(Json(res));
            }
            catch (Exception ex)
            {
                res.Message = ex.Message;
            }

            return(Json(res));
        }
Esempio n. 3
0
        public List <string> SearchVerifyOutsideInfo(VerifySourceInfoDTO verifySource, SqlSugarClient db)
        {
            bool isOutside = false;

            if (db == null)
            {
                db        = new SqlSugarClient(Connection);
                isOutside = true;
            }

            List <string> infoList = new List <string>();

            if (verifySource.PayMethod == (int)CyddPayType.挂账)
            {
                if (verifySource.SourceId <= 0)
                {
                    throw new Exception("请选择有效的挂账客户!");
                }
                string lxdmSql = string.Format("SELECT lxdmdm00 AS Code, lxdmgzxe AS LimitAmount, lxdmye00 AS RemainAmount FROM dbo.lxdm WHERE Id = {0}", verifySource.SourceId);

                var info = db.SqlQuery <SearchLxdmInfo>(lxdmSql);

                if (info == null || info.Count == 0)
                {
                    throw new Exception(string.Format("无法找到此客户({0}),请重新确认挂账客户!", verifySource.SourceName));
                }

                infoList.Add(info[0].Code.Trim());
            }
            else if (verifySource.PayMethod == (int)CyddPayType.转客房)
            {
                #region 转客房验证
                if (string.IsNullOrEmpty(verifySource.SourceName))
                {
                    throw new Exception("请输入房号!");
                }

                string sqlRoom = string.Format("SELECT TOP 1 krzlfh00 " +
                                               "FROM krzl WHERE krzlzt00 = 'I' AND (krzlzh00 = '{0}' or (krzlkrlx='G' and krzlth00='{0}'))", verifySource.SourceId);

                var rooms = db.SqlQuery <string>(sqlRoom);
                if (rooms == null || rooms.Count == 0)
                {
                    throw new Exception(string.Format("无此在住房号({0}),请重新确认转客房房号!", verifySource.SourceName));
                }

                //取在住主结人
                string customerSql = string.Format("SELECT TOP 1 krzlzh00 AS CustomerId, ISNULL(krzlgzxe, 0) AS LastAmount, isnull(krzlye00, 0) as LimitAmount, " +
                                                   "(select sum(ysq0je00) from ysq0 where ysq0zh00=k.krzlzh00) as PreAmount FROM krzl k " +
                                                   "WHERE krzlzt00 = 'I' AND (krzlzh00 = '{0}' or (krzlkrlx='G' and krzlth00='{0}')) AND krzlzh00 = krzltzxh", verifySource.SourceId);
                var customers = db.SqlQuery <SearchKrzlInfo>(customerSql);

                if (customers == null || customers.Count == 0)
                {
                    throw new Exception(string.Format("此房号({0})无在住客人!", verifySource.SourceName));
                }

                if (customers[0].LastAmount != 0)
                {
                    if (customers[0].LastAmount < verifySource.OperateValue)
                    {
                        throw new Exception(string.Format("此客户({0})可挂账限额({1})小于当前输入金额无法挂账, 请重新确认!", verifySource.SourceName, customers[0].LastAmount));
                    }
                }

                //if (customers[0].LimitAmount != 0)
                //{
                //    if (customers[0].LimitAmount + verifySource.OperateValue>0)
                //        throw new Exception(string.Format("此客户({0})可挂账余额({1})小于当前输入金额无法挂账, 请重新确认!", verifySource.SourceName, customers[0].LimitAmount));
                //}

                var codes = db.SqlQuery <string>("select top 1 cyctzwdm from cyct where id=" + verifySource.RestaruantId);
                if (codes == null || codes.Count == 0)
                {
                    throw new Exception("当前餐厅未设置账务代码!");
                }

                var hasCode = db.SqlQuery <string>("select top 1 zwdmdm00 from zwdm where zwdmdm00='" + codes[0] + "'");
                if (hasCode == null || hasCode.Count == 0)
                {
                    throw new Exception("当前餐厅账务代码设置不正确,请重新确认!");
                }

                infoList.Add(codes[0]);
                infoList.Add(customers[0].CustomerId.ToString());
                #endregion
            }
            else if (verifySource.PayMethod == (int)CyddPayType.会员卡)
            {
                var member = VerifyMemberInfo(verifySource.SourceId, verifySource.OperateValue, verifySource.SourceName);
                if (member != null && member.Id > 0)
                {
                    infoList.Add(member.Id.ToString());
                }
            }

            if (isOutside)
            {
                db.Dispose();
            }

            return(infoList);
        }
Esempio n. 4
0
        public CheckOutResultDTO ReverseOrder(ReverseOrderDTO req)
        {
            using (var db = new SqlSugarClient(Connection))
            {
                CheckOutResultDTO res = null;
                try
                {
                    var dateItem = _extendItemRepository.GetModelList(req.CompanyId, 10003).FirstOrDefault();

                    if (dateItem == null)
                    {
                        throw new Exception("餐饮账务日期尚未初始化,请联系管理员");
                    }
                    DateTime accDate = DateTime.Today;
                    if (!DateTime.TryParse(dateItem.ItemValue, out accDate))
                    {
                        throw new Exception("餐饮账务日期设置错误,请联系管理员");
                    }
                    var tables = db.Queryable <R_Table>().JoinTable <R_OrderTable>
                                     ((s1, s2) => s1.Id == s2.R_Table_Id).Where <R_OrderTable>((s1, s2) =>
                                                                                               s2.R_OrderMainPay_Id == req.MainPayId).Select("s1.*").ToList();
                    var tableIds       = tables.Select(p => p.Id).ToArray();
                    var tableOrderIngs = tables.Where(p => p.CythStatus == CythStatus.在用).ToList();
                    if (tableOrderIngs.Any())
                    {
                        var tableNames = string.Join(",", tableOrderIngs.Select(p => p.Name));
                        throw new Exception(string.Format("({0}) 正在开台状态,请结账后再执行该账单的反结操作", tableNames));
                    }

                    var reverTableNames = string.Join(",", tables.Select(p => p.Name));
                    var mainPayModel    = db.Queryable <R_OrderMainPay>().First(p => p.Id == req.MainPayId);
                    if (mainPayModel.BillDate.Date != accDate.Date)
                    {
                        throw new Exception("该账单账务日期和系统当前账务日期不一致,不允许反结");
                    }
                    var orderModel  = db.Queryable <R_Order>().First(p => p.Id == mainPayModel.R_Order_Id);
                    var orderTables = db.Queryable <R_OrderTable>()
                                      .Where(p => p.R_OrderMainPay_Id == mainPayModel.Id).ToList();
                    var orderTableIds = orderTables.Select(p => p.Id).ToArray();
                    var orderDetails  = db.Queryable <R_OrderDetail>()
                                        .Where(p => orderTableIds.Contains(p.R_OrderTable_Id)).ToList();
                    var orderPayRecords = db.Queryable <R_OrderPayRecord>()
                                          .Where(p => p.R_OrderMainPay_Id == mainPayModel.Id).ToList();
                    if (orderPayRecords.Any(p => p.CyddJzStatus == CyddJzStatus.已结 && p.CyddJzType != CyddJzType.定金))
                    {
                        throw new Exception(string.Format("该主结单已经做过反结操作,不能重复反结"));
                    }
                    db.BeginTran();
                    //db.Delete<R_OrderPayRecord>(p => p.R_OrderMainPay_Id == mainPayModel.Id);

                    //db.Delete<R_OrderMainPay>(p => p.Id == mainPayModel.Id);
                    //db.Update<R_OrderPayRecord>(new { CyddJzStatus = (int)CyddJzStatus.已付 }, p => p.R_Order_Id == orderModel.Id);
                    //db.Delete<R_OrderPayRecord>(p=>p.R_Order_Id == orderModel.Id && p.PayAmount<=0 && p.CyddJzType==CyddJzType.定金);

                    var depositReverAll = db.Queryable <R_OrderPayRecord>().Where(p => p.R_Order_Id == orderModel.Id && p.R_OrderMainPay_Id == 0 &&
                                                                                  p.CyddJzType == CyddJzType.定金).ToList();
                    var depositRePids   = depositReverAll.Where(p => p.CyddJzStatus == CyddJzStatus.已退).Select(p => p.PId).ToList();
                    var depositReverIds = depositReverAll.Where(p => !depositRePids.Contains(p.Id) && p.CyddJzStatus == CyddJzStatus.已结)
                                          .Select(p => p.Id).ToList();
                    db.Update <R_OrderPayRecord>(new { CyddJzStatus = (int)CyddJzStatus.已付 }, p => depositReverIds.Contains(p.Id));
                    db.Update <R_OrderPayRecord>(new { CyddJzStatus = (int)CyddJzStatus.已结 }, p => p.R_OrderMainPay_Id == mainPayModel.Id);
                    db.Delete <R_OrderPayRecord>(p => p.R_Order_Id == orderModel.Id && p.CyddJzType == CyddJzType.定金 &&
                                                 p.CyddJzStatus == CyddJzStatus.已结 && p.R_OrderMainPay_Id > 0);
                    db.Update <R_OrderDetail>(new { PayableTotalPrice = 0, DiscountRate = 1 }, p => orderTableIds.Contains(p.R_OrderTable_Id));
                    db.Update <R_OrderTable>(new { IsCheckOut = 0, IsOpen = 1, R_OrderMainPay_Id = 0 }, p => orderTableIds.Contains(p.Id));
                    db.Update <R_Order>(new { RealAmount = 0, CyddStatus = (int)CyddStatus.反结, OriginalAmount = 0, ConAmount = 0, DiscountRate = 0, DiscountAmount = 0, GiveAmount = 0, ClearAmount = 0 }, p => p.Id == orderModel.Id);
                    db.Update <R_Table>(new { CythStatus = (int)CythStatus.在用 }, p => tableIds.Contains(p.Id));
                    db.Insert <R_OrderRecord>(new R_OrderRecord()
                    {
                        CreateDate       = DateTime.Now,
                        CreateUser       = req.UserId,
                        CyddCzjlStatus   = CyddStatus.反结,
                        CyddCzjlUserType = CyddCzjlUserType.员工,
                        Remark           = string.Format("执行了反结操作,台号:({0})", reverTableNames),
                        R_OrderTable_Id  = 0,
                        R_Order_Id       = orderModel.Id
                    });

                    List <R_OrderPayRecord> reverseRecords = new List <R_OrderPayRecord>();
                    #region 反写应收账
                    foreach (var item in orderPayRecords)
                    {
                        if (item.CyddPayType == (int)CyddPayType.挂账 || item.CyddPayType == (int)CyddPayType.转客房 ||
                            item.CyddPayType == (int)CyddPayType.会员卡)
                        {
                            if (item.CyddPayType == (int)CyddPayType.会员卡)
                            {
                                if (EnabelGroupFlag)
                                {
                                    try
                                    {
                                        var dto = AutoMapper.Mapper.Map <OrderPayRecordDTO>(item);
                                        dto.Remark = string.Format("{0} {1}", "反结会员卡", item.Remark);
                                        List <OrderPayRecordDTO> dtoList = new List <OrderPayRecordDTO>
                                        {
                                            dto
                                        };
                                        SaveMemberConsumeInfo(dtoList, req.UserCode, false, orderModel.R_Restaurant_Id);
                                        //ApplyChangeMemberToDb(item.SourceId, item.SourceName, req.UserCode,
                                        //    -item.PayAmount, string.Format("{0} {1}", "反结会员卡", item.Remark), false, new SqlSugarClient(ConnentionGroup));
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception("反结集团库记录会员卡消费信息操作失败:" + ex.Message);
                                    }
                                }
                                else
                                {
                                    try
                                    {
                                        ApplyChangeMemberToDb(item.SourceId, item.SourceName, req.UserCode,
                                                              -item.PayAmount, string.Format("{0} {1}", "反结会员卡", item.Remark), false, db, orderModel.R_Restaurant_Id);
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception("反结本地库记录会员卡消费信息操作失败:" + ex.Message);
                                    }
                                }
                                //if (!EnabelGroupFlag)
                                //{
                                //    //若已启用集团会员库,里面则不再执行,本地库会员消费记录已在插入集团库时一并插入到本地库
                                //}
                            }
                            else if (item.CyddPayType == (int)CyddPayType.挂账)
                            {
                                var verifyInfo = new VerifySourceInfoDTO();
                                verifyInfo.SourceId     = item.SourceId;
                                verifyInfo.SourceName   = item.SourceName;
                                verifyInfo.RestaruantId = orderModel.R_Restaurant_Id;
                                verifyInfo.PayMethod    = (int)CyddPayType.挂账;
                                verifyInfo.OperateValue = item.PayAmount;
                                string        remark     = string.Format("反结挂账客户【{0}】- 代码:({1})", item.SourceName, item.SourceId);
                                List <string> resultList = SearchVerifyOutsideInfo(verifyInfo, db);
                                try
                                {
                                    var paras = SqlSugarTool.GetParameters(new
                                    {
                                        xh   = orderModel.Id,                                    //餐饮单序号
                                        dh   = orderModel.R_Restaurant_Id + "." + orderModel.Id, //餐厅代码+'.'+餐饮单单号
                                        lx   = resultList[0].Trim(),                             //协议单位代码(lxdmdm00)
                                        je   = -item.PayAmount,                                  //金额
                                        cz   = req.UserCode,                                     //操作员代码
                                        ctmc = orderModel.R_Restaurant_Id,                       //餐厅名称
                                        fsmc = "",                                               //分市名称
                                        th   = orderModel.Id,
                                        rs   = orderModel.PersonNum,
                                        bz   = remark,
                                        mz   = "",
                                        atr  = 0
                                    });
                                    db.CommandType = System.Data.CommandType.StoredProcedure; //指定为存储过程可比上面少写EXEC和参数
                                    db.ExecuteCommand("p_po_toys_newCY", paras);
                                    db.CommandType = System.Data.CommandType.Text;            //还原回默认
                                }
                                catch (Exception ex)
                                {
                                    throw new Exception("反结挂账操作失败:" + ex.Message);
                                }
                            }
                            else if (item.CyddPayType == (int)CyddPayType.转客房)
                            {
                                #region 转客房处理

                                var verifyInfo = new VerifySourceInfoDTO();
                                verifyInfo.SourceId     = item.SourceId;
                                verifyInfo.SourceName   = item.SourceName;
                                verifyInfo.RestaruantId = orderModel.R_Restaurant_Id;
                                verifyInfo.PayMethod    = (int)CyddPayType.转客房;
                                verifyInfo.OperateValue = item.PayAmount;

                                List <string> resultList = SearchVerifyOutsideInfo(verifyInfo, db);
                                try
                                {
                                    var paras = SqlSugarTool.GetParameters(new
                                    {
                                        zh00 = Convert.ToInt32(resultList[1]), //客人账号(krzlzh00)
                                        zwdm = resultList[0],                  //账项代码
                                        hsje = -item.PayAmount,                //金额
                                        ckhm = item.SourceName,                //房号(krzlfh00)
                                        czdm = req.UserCode,                   //操作员代码
                                        xfje = 1,
                                        bz00 = "反结餐厅转客房",
                                        bc00 = "",
                                    });
                                    db.CommandType = System.Data.CommandType.StoredProcedure; //指定为存储过程可比上面少写EXEC和参数
                                    db.ExecuteCommand("p_zw_addx", paras);
                                    db.CommandType = System.Data.CommandType.Text;            //还原回默认
                                }
                                catch (Exception ex)
                                {
                                    throw new Exception("反结转客房操作失败:" + ex.Message);
                                }
                                #endregion
                            }
                        }

                        if (item.PayAmount != 0 && (item.CyddJzStatus != CyddJzStatus.已退 || item.CyddJzStatus != CyddJzStatus.已结) && item.CyddJzType != CyddJzType.定金)
                        {
                            item.PayAmount    = -item.PayAmount;
                            item.CreateDate   = DateTime.Now;
                            item.BillDate     = accDate;
                            item.R_Market_Id  = req.CurrentMarketId;
                            item.CreateUser   = req.UserId;
                            item.CyddJzStatus = CyddJzStatus.已结;
                            if (item.CyddJzType == CyddJzType.找零)
                            {
                                item.Remark = string.Format("反结找零纪录 {0}", item.SourceName);
                            }
                            else
                            {
                                item.Remark = string.Format("反结付款纪录 {0}", item.SourceName);
                            }
                            reverseRecords.Add(item);
                        }

                        //if (item.CyddJzType==CyddJzType.转结 && item.CyddJzStatus==CyddJzStatus.已结)
                        //{
                        //    reverseRecords.Add(new R_OrderPayRecord()
                        //    {
                        //        PayAmount = -item.PayAmount,
                        //        CreateDate = DateTime.Now,
                        //        BillDate = accDate,
                        //        R_Market_Id = req.CurrentMarketId,
                        //        CreateUser = req.UserId,
                        //        CyddJzStatus = CyddJzStatus.已付,
                        //        CyddJzType = CyddJzType.定金,
                        //        CyddPayType=item.CyddPayType,
                        //        SourceId=0,
                        //        R_OrderMainPay_Id= mainPayModel.Id,
                        //        Remark = string.Format("反结重置定金纪录")
                        //    });
                        //}
                    }
                    db.InsertRange <R_OrderPayRecord>(reverseRecords);
                    #endregion
                    db.CommitTran();
                    res = new CheckOutResultDTO()
                    {
                        OrderId         = orderModel.Id,
                        OrderMainPayId  = mainPayModel.Id,
                        OrderTables     = orderTableIds.ToList(),
                        ReverTableNames = reverTableNames
                    };
                }
                catch (Exception ex)
                {
                    db.RollbackTran();
                    throw ex;
                }
                return(res);
            }
        }