public BaseResponse <IList <SerOrdSerItModel> > SavePaymentByRsId(SerOrdSerItModelList baseRequest)
        {
            BaseResponse <IList <SerOrdSerItModel> > response = new BaseResponse <IList <SerOrdSerItModel> >();
            SerOrdSerItModelList sosiml = new SerOrdSerItModelList();
            DateTime             dtnow  = DateTime.Now;
            decimal preamount           = 0;

            try
            {
                unitOfWork.BeginTransaction();
                if (baseRequest.SerOrdSerItModelLists != null && baseRequest.PaymentInfos != null)
                {
                    #region 订单服务记录
                    foreach (var item in baseRequest.SerOrdSerItModelLists)
                    {
                        PaymentsServiceOrderModel psom = new PaymentsServiceOrderModel();
                        var serorderserit = unitOfWork.GetRepository <DC_SerOrdSerIt>().dbSet.Where(m => m.ServiceOrderSIID == item.ServiceOrderSIID).ToList();
                        if (serorderserit != null)
                        {
                            if (serorderserit.Count > 0)
                            {
                                //订单服务关联
                                serorderserit[0].ChargeStatus = 1;
                                serorderserit[0].ModifiedBy   = SecurityHelper.CurrentPrincipal.EmpId;
                                serorderserit[0].ModifiedTime = dtnow;
                                unitOfWork.GetRepository <DC_SerOrdSerIt>().Update(serorderserit[0]);
                            }
                        }

                        if (item.ResidentServicePlanItemID != 0 && item.ResidentServicePlanItemID != null)
                        {
                            var dc_rspi = unitOfWork.GetRepository <DC_ResidentServicePlanItem>().dbSet.Where(m => m.ResidentServicePlanItemID == item.ResidentServicePlanItemID).ToList();

                            if (dc_rspi != null)
                            {
                                if (dc_rspi.Count > 0)
                                {
                                    //套餐表
                                    dc_rspi[0].RestTimes    = dc_rspi[0].RestTimes - (int)item.Qty;
                                    dc_rspi[0].ModifiedBy   = SecurityHelper.CurrentPrincipal.EmpId;
                                    dc_rspi[0].ModifiedTime = dtnow;
                                    unitOfWork.GetRepository <DC_ResidentServicePlanItem>().Update(dc_rspi[0]);
                                }
                            }
                        }

                        psom.ServiceOrderID = item.ServiceOrderID;
                        psom.SumPrice       = item.SumPrice;
                        sosiml.PaymentsServiceOrderModelLists.Add(psom);
                    }

                    var deposit = unitOfWork.GetRepository <DC_Deposit>().dbSet.Where(m => m.ResidentID == baseRequest.PaymentInfos.ResidentID).ToList();
                    if (deposit != null)
                    {
                        if (deposit.Count > 0)
                        {
                            //更新预收款余额表
                            preamount                   = deposit[0].Amount;
                            deposit[0].Amount           = deposit[0].Amount - baseRequest.PaymentInfos.PreAmount;
                            deposit[0].TotalConSpeMonth = deposit[0].TotalConSpeMonth + baseRequest.PaymentInfos.PreAmount;
                            deposit[0].ModifiedBy       = SecurityHelper.CurrentPrincipal.EmpId;
                            deposit[0].ModifiedTime     = dtnow;
                            unitOfWork.GetRepository <DC_Deposit>().Update(deposit[0]);
                        }
                    }
                    var ls = sosiml.PaymentsServiceOrderModelLists.GroupBy(a => a.ServiceOrderID).Select(g => (new { ServiceOrderID = g.Key, SumPrice = g.Sum(item => item.SumPrice) })).ToList();

                    foreach (var psoml in ls)
                    {
                        var serviceorderchargerecid = String.Format("{0}{1}{2}", "C", SecurityHelper.CurrentPrincipal.OrgId, DateTime.Now.ToString("yyyyMMddHHmmss"));
                        //服务订单收费记录表
                        DC_ServiceOrderCharge serviceordercharge = new DC_ServiceOrderCharge();
                        serviceordercharge.ServiceOrderChargeRecId = serviceorderchargerecid;
                        serviceordercharge.ServiceOrderID          = psoml.ServiceOrderID;
                        serviceordercharge.Price          = psoml.SumPrice;
                        serviceordercharge.Payer          = baseRequest.PaymentInfos.Payer;
                        serviceordercharge.FrontPreAmount = preamount;
                        serviceordercharge.PreAmount      = baseRequest.PaymentInfos.PreAmount;
                        serviceordercharge.ReceiveAmount  = baseRequest.PaymentInfos.CurAmount;
                        serviceordercharge.PaymentType    = baseRequest.PaymentInfos.PaymentType;
                        serviceordercharge.PayTime        = dtnow;
                        serviceordercharge.InvoiceNo      = baseRequest.PaymentInfos.InvoiceNo;
                        serviceordercharge.ChargeStatus   = 1;
                        serviceordercharge.Operator       = SecurityHelper.CurrentPrincipal.EmpId;
                        serviceordercharge.CreatedBy      = SecurityHelper.CurrentPrincipal.EmpId;
                        serviceordercharge.CreatedTime    = dtnow;
                        serviceordercharge.IsDeleted      = false;

                        var dc_soc = unitOfWork.GetRepository <DC_ServiceOrderCharge>().dbSet.Where(m => m.ServiceOrderChargeRecId == serviceorderchargerecid).ToList();
                        if (dc_soc.Count > 0)
                        {
                            unitOfWork.GetRepository <DC_ServiceOrderCharge>().Update(serviceordercharge);
                        }
                        else
                        {
                            unitOfWork.GetRepository <DC_ServiceOrderCharge>().Insert(serviceordercharge);
                        }

                        foreach (var sosml in baseRequest.SerOrdSerItModelLists)
                        {
                            if (sosml.ServiceOrderID == psoml.ServiceOrderID)
                            {
                                //订单收费明细
                                DC_ServiceOrderChargeDtl dc_serviceorderchargedtl = new DC_ServiceOrderChargeDtl();
                                dc_serviceorderchargedtl.ServiceOrderChargeRecId = serviceorderchargerecid;
                                dc_serviceorderchargedtl.ServiceOrderID          = sosml.ServiceOrderID;
                                dc_serviceorderchargedtl.ServiceItemID           = sosml.ServiceItemID;
                                dc_serviceorderchargedtl.UnitPrice     = sosml.UnitPrice;
                                dc_serviceorderchargedtl.Qty           = sosml.Qty;
                                dc_serviceorderchargedtl.DiscountPrice = sosml.DiscountPrice;
                                dc_serviceorderchargedtl.SumPrice      = sosml.SumPrice;
                                dc_serviceorderchargedtl.CreatedBy     = SecurityHelper.CurrentPrincipal.EmpId;
                                dc_serviceorderchargedtl.CreatedTime   = dtnow;
                                unitOfWork.GetRepository <DC_ServiceOrderChargeDtl>().Insert(dc_serviceorderchargedtl);
                            }
                        }
                    }

                    var org_org = unitOfWork.GetRepository <ORG_Organization>().dbSet.Where(m => m.OrganizationID == SecurityHelper.CurrentPrincipal.OrgId).ToList();
                    if (org_org != null)
                    {
                        if (org_org.Count > 0)
                        {
                            //先付费,需要生成排号记录和实时排号数据
                            if (org_org[0].IsPayFirstFlag == true)
                            {
                                var serviceordersiid_list = new List <int>();
                                foreach (var sosimls in baseRequest.SerOrdSerItModelLists)
                                {
                                    serviceordersiid_list.Add(sosimls.ServiceOrderSIID);
                                }

                                if (serviceordersiid_list.Count > 0)
                                {
                                    var queueresponse = new BaseResponse();
                                    //to-do Queue Api -- wait for zhangyoujun
                                    queueresponse = service.SyncToCheckQueue(serviceordersiid_list, SecurityHelper.CurrentPrincipal.EmpId);
                                    if (queueresponse.IsSuccess == false)
                                    {
                                        response.ResultCode    = -1;
                                        response.ResultMessage = queueresponse.ResultMessage;
                                        return(response);
                                    }
                                }
                            }
                        }
                    }

                    unitOfWork.Save();
                    unitOfWork.Commit();
                    response.ResultCode = 1001;
                    #endregion
                }
                else
                {
                    response.ResultCode    = -1;
                    response.ResultMessage = "未查询到有效订单服务项目数据!";
                }
            }
            catch (Exception ex)
            {
                response.ResultCode    = -1;
                response.ResultMessage = "保存异常,请联系管理员!";
            }

            return(response);
        }
Beispiel #2
0
        public BaseResponse <IList <SerOrdSerItModel> > SaveRefundByRsId(SerOrdSerItModelList baseRequest)
        {
            BaseResponse <IList <SerOrdSerItModel> > response = new BaseResponse <IList <SerOrdSerItModel> >();
            SerOrdSerItModelList sosiml = new SerOrdSerItModelList();
            DateTime             dtnow  = DateTime.Now;
            var NoRefundCount           = 0;
            var NoRefundMessage         = "";

            try
            {
                unitOfWork.BeginTransaction();
                if (baseRequest.SerOrdSerItModelLists != null && baseRequest.RefundInfos != null)
                {
                    //--------------判断检查状态--------------
                    //3.就检中和5.完检不能取消退费
                    foreach (var soitem in baseRequest.SerOrdSerItModelLists)
                    {
                        var dc_crqr = unitOfWork.GetRepository <DC_CheckRoomQueueRec>().dbSet.Where(m => m.CheckRoomQueueRecID == soitem.CheckRoomQueueRecID &&
                                                                                                    m.OrganizationID == SecurityHelper.CurrentPrincipal.OrgId && (m.CheckStatus == 3 || m.CheckStatus == 5)).ToList();
                        if (dc_crqr != null)
                        {
                            if (dc_crqr.Count > 0)
                            {
                                NoRefundCount++;
                                NoRefundMessage = NoRefundMessage + "订单编号:" + soitem.SONo + " " + "服务名称:" + soitem.SIName + ",";
                            }
                        }
                    }
                    if (NoRefundCount > 0)
                    {
                        response.ResultCode    = -1;
                        response.ResultMessage = NoRefundMessage + "," + NoRefundCount + "个服务项目" + "就检中或已完检,无法退费!";
                        return(response);
                    }
                    //-------------------------------------

                    #region 退费
                    foreach (var item in baseRequest.SerOrdSerItModelLists)
                    {
                        PaymentsServiceOrderModel psom = new PaymentsServiceOrderModel();
                        var serorderserit = unitOfWork.GetRepository <DC_SerOrdSerIt>().dbSet.Where(m => m.ServiceOrderSIID == item.ServiceOrderSIID).ToList();
                        if (serorderserit != null)
                        {
                            if (serorderserit.Count > 0)
                            {
                                //订单服务关联
                                serorderserit[0].ChargeStatus = 2;
                                serorderserit[0].ModifiedBy   = SecurityHelper.CurrentPrincipal.EmpId;
                                serorderserit[0].ModifiedTime = dtnow;
                                unitOfWork.GetRepository <DC_SerOrdSerIt>().Update(serorderserit[0]);
                            }
                        }

                        var dc_crqr = unitOfWork.GetRepository <DC_CheckRoomQueueRec>().dbSet.Where(m => m.CheckRoomQueueRecID == item.CheckRoomQueueRecID).ToList();
                        if (dc_crqr != null)
                        {
                            if (dc_crqr.Count > 0)
                            {
                                if (dc_crqr[0].CheckStatus != 3 && dc_crqr[0].CheckStatus != 5)
                                {
                                    //排号记录
                                    dc_crqr[0].CheckStatus  = 6;
                                    dc_crqr[0].ModifiedBy   = SecurityHelper.CurrentPrincipal.EmpId;
                                    dc_crqr[0].ModifiedTime = dtnow;
                                    unitOfWork.GetRepository <DC_CheckRoomQueueRec>().Update(dc_crqr[0]);

                                    var dc_crq = unitOfWork.GetRepository <DC_CheckRoomQueue>().dbSet.Where(m => m.CheckRoomQueueRecID == item.CheckRoomQueueRecID).ToList();
                                    if (dc_crq != null)
                                    {
                                        if (dc_crq.Count > 0)
                                        {
                                            var queueid = dc_crq[0].QueueID;
                                            var dc_crqs = unitOfWork.GetRepository <DC_CheckRoomQueue>().dbSet.Where(m => m.QueueID == queueid).ToList();
                                            //实时排号
                                            if (dc_crqs != null)
                                            {
                                                if (dc_crqs.Count > 0)
                                                {
                                                    unitOfWork.GetRepository <DC_CheckRoomQueue>().Delete(p => p.QueueID == queueid);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (item.ResidentServicePlanItemID != 0 && item.ResidentServicePlanItemID != null)
                        {
                            var dc_rspi = unitOfWork.GetRepository <DC_ResidentServicePlanItem>().dbSet.Where(m => m.ResidentServicePlanItemID == item.ResidentServicePlanItemID).ToList();

                            if (dc_rspi != null)
                            {
                                if (dc_rspi.Count > 0)
                                {
                                    //套餐表
                                    dc_rspi[0].RestTimes    = dc_rspi[0].RestTimes + (int)item.Qty;
                                    dc_rspi[0].ModifiedBy   = SecurityHelper.CurrentPrincipal.EmpId;
                                    dc_rspi[0].ModifiedTime = dtnow;
                                    unitOfWork.GetRepository <DC_ResidentServicePlanItem>().Update(dc_rspi[0]);
                                }
                            }
                        }

                        psom.ServiceOrderID = item.ServiceOrderID;
                        psom.SumPrice       = item.SumPrice;
                        sosiml.PaymentsServiceOrderModelLists.Add(psom);
                    }
                    var ls = sosiml.PaymentsServiceOrderModelLists.GroupBy(a => a.ServiceOrderID).Select(g => (new { ServiceOrderID = g.Key, SumPrice = g.Sum(item => item.SumPrice) })).ToList();

                    foreach (var psoml in ls)
                    {
                        var serviceorderchargerecid = String.Format("{0}{1}{2}", "R", SecurityHelper.CurrentPrincipal.OrgId, DateTime.Now.ToString("yyyyMMddHHmmss"));
                        //服务订单收费记录表
                        DC_ServiceOrderCharge serviceordercharge = new DC_ServiceOrderCharge();
                        serviceordercharge.ServiceOrderChargeRecId = serviceorderchargerecid;
                        serviceordercharge.ServiceOrderID          = psoml.ServiceOrderID;
                        serviceordercharge.Price         = psoml.SumPrice;
                        serviceordercharge.Payer         = baseRequest.RefundInfos.Payer;
                        serviceordercharge.PaymentType   = baseRequest.RefundInfos.PaymentType;
                        serviceordercharge.ReceiveAmount = baseRequest.RefundInfos.RefundAmt;
                        serviceordercharge.PayTime       = dtnow;
                        serviceordercharge.RefundReason  = baseRequest.RefundInfos.RefundReason;
                        serviceordercharge.ChargeStatus  = 2;
                        serviceordercharge.Operator      = SecurityHelper.CurrentPrincipal.EmpId;
                        serviceordercharge.CreatedBy     = SecurityHelper.CurrentPrincipal.EmpId;
                        serviceordercharge.CreatedTime   = dtnow;
                        serviceordercharge.IsDeleted     = false;

                        var dc_soc = unitOfWork.GetRepository <DC_ServiceOrderCharge>().dbSet.Where(m => m.ServiceOrderChargeRecId == serviceorderchargerecid).ToList();
                        if (dc_soc.Count > 0)
                        {
                            unitOfWork.GetRepository <DC_ServiceOrderCharge>().Update(serviceordercharge);
                        }
                        else
                        {
                            unitOfWork.GetRepository <DC_ServiceOrderCharge>().Insert(serviceordercharge);
                        }

                        foreach (var sosml in baseRequest.SerOrdSerItModelLists)
                        {
                            if (sosml.ServiceOrderID == psoml.ServiceOrderID)
                            {
                                //订单收费明细
                                DC_ServiceOrderChargeDtl dc_serviceorderchargedtl = new DC_ServiceOrderChargeDtl();
                                dc_serviceorderchargedtl.ServiceOrderChargeRecId = serviceorderchargerecid;
                                dc_serviceorderchargedtl.ServiceOrderID          = sosml.ServiceOrderID;
                                dc_serviceorderchargedtl.ServiceItemID           = sosml.ServiceItemID;
                                dc_serviceorderchargedtl.UnitPrice     = sosml.UnitPrice;
                                dc_serviceorderchargedtl.Qty           = sosml.Qty;
                                dc_serviceorderchargedtl.DiscountPrice = sosml.DiscountPrice;
                                dc_serviceorderchargedtl.SumPrice      = sosml.SumPrice;
                                dc_serviceorderchargedtl.CreatedBy     = SecurityHelper.CurrentPrincipal.EmpId;
                                dc_serviceorderchargedtl.CreatedTime   = dtnow;
                                unitOfWork.GetRepository <DC_ServiceOrderChargeDtl>().Insert(dc_serviceorderchargedtl);
                            }
                        }
                    }

                    unitOfWork.Save();
                    unitOfWork.Commit();
                    response.ResultCode = 1001;
                    #endregion
                }
                else
                {
                    response.ResultCode    = -1;
                    response.ResultMessage = "未查询到有效订单服务项目数据!";
                }
            }
            catch (Exception ex)
            {
                response.ResultCode    = -1;
                response.ResultMessage = "保存异常,请联系管理员!";
            }

            return(response);
        }