public string ConvertCodeToCityName(string cityCode)
        {
            string city = string.Empty;

            PnrAnalysis.PnrResource pnrResource = new PnrAnalysis.PnrResource();
            var cityInfo = pnrResource.GetCityInfo(cityCode);

            if (cityInfo != null)
            {
                city = cityInfo.city.Name;
            }
            return(city);
        }
Example #2
0
        protected override string ResolveCore(BPiaoBao.DomesticTicket.Domain.Models.Orders.SkyWay source)
        {
            string city = string.Empty;

            PnrAnalysis.PnrResource pnrResource = new PnrAnalysis.PnrResource();
            var cityInfo = pnrResource.GetCityInfo(source.ToCityCode);

            if (cityInfo != null)
            {
                city = cityInfo.city.Name;
            }
            return(city);
        }
        /// <summary>
        /// 保存保险
        /// </summary>
        /// <param name="order">机票订单</param>
        /// <param name="currentUser">出保险商户</param>
        /// <param name="isAlone">是否单独购买保险而未伴随机票订单一起</param>
        /// <param name="hasTicket">是否有与之对应的机票</param>
        public void SaveInsurance(InsuranceOrder order, CurrentUserInfo currentUser, bool isAlone = false, bool hasTicket = true)
        {
            //验证机票订单号是否存在
            Order ticketOrder = null;

            if (hasTicket)
            {
                ticketOrder = this._iOrderRepository.FindAll(o => o.OrderId == order.OrderId).FirstOrDefault();
                if (ticketOrder == null)
                {
                    throw new CustomException(110001, "订单号" + order.OrderId + "不存在。");
                }
            }

            //验证保单数量是否足够
            var insuranceCfg = this._iInsuranceConfigRepository.FindAll(i => i.BusinessmanCode == currentUser.Code).FirstOrDefault();

            if (insuranceCfg == null ||
                !insuranceCfg.IsOpen)
            {
                throw new CustomException(110002, "尚未开启航意险。");
            }
            if (insuranceCfg.LeaveCount < order.InsuranceRecords.Sum(i => i.Count))
            {
                throw new CustomException(110003, "航意险仅剩余" + insuranceCfg.LeaveCount + "份。");
            }

            //数据准备
            var    carrier          = this._businessmanRepository.FindAll(b => b.Code == currentUser.CarrierCode).FirstOrDefault();
            string insuranceCompany = (from InsuranceElement ctrl in InsuranceSection.GetInsuranceConfigurationSection().CtrlInsuranceCollection
                                       where ctrl.IsCurrent
                                       select ctrl.Value).FirstOrDefault();//保险公司

            //删除之前该机票下的保险
            if (!isAlone && hasTicket)
            {
                var oldrecord = this._iInsuranceOrderRepository.FindAll(m => m.OrderId == order.OrderId);
                foreach (InsuranceOrder item in oldrecord)
                {
                    item.InsuranceRecords.Clear();
                    this.unitOfWorkRepository.PersistDeletionOf(item);
                }
            }

            //修改机票订单信息
            if (hasTicket)
            {
                foreach (var passger in ticketOrder.Passengers)
                {
                    if (order.InsuranceRecords.Count(r => r.PassengerId == passger.Id) > 0)
                    {
                        passger.BuyInsuranceCount = order.InsuranceRecords.Where(r => r.PassengerId == passger.Id).Sum(r => r.Count);
                        passger.BuyInsurancePrice = insuranceCfg.SinglePrice;
                    }
                }

                this.unitOfWorkRepository.PersistUpdateOf(ticketOrder);
            }
            //补全保险系统信息
            order.BuyTime = DateTime.Now;
            foreach (var record in order.InsuranceRecords)
            {
                record.BussinessmanCode = currentUser.Code;            //分销商号
                record.BussinessmanName = currentUser.BusinessmanName; //分销商名称
                record.CarrierCode      = carrier.Code;                //运营商号
                record.CarrierName      = carrier.Name;                //运营商名称
                record.InsuranceCompany = insuranceCompany;            //保险公司
                record.InsurancePrice   = insuranceCfg.SinglePrice;    //保险单价
                record.SerialNum        = record.GetSerialNum();       //获取流水号
                record.InsuranceStatus  = EnumInsuranceStatus.NoInsurance;
                record.PolicyAmount     = 400000;
            }
            //补全保险订单中机票订单相关信息
            if (hasTicket)
            {
                foreach (var record in order.InsuranceRecords)
                {
                    Passenger passenger = ticketOrder.Passengers.Where(p => p.Id == record.PassengerId).FirstOrDefault();
                    if (passenger == null)
                    {
                        throw new CustomException(110004, "机票订单中不存在指定的乘客。");
                    }
                    SkyWay skyway = ticketOrder.SkyWays.Where(s => s.Id == record.SkyWayId).FirstOrDefault();
                    if (skyway == null)
                    {
                        throw new CustomException(110005, "机票订单中不存在指定的航线。");
                    }
                    string fromCityName = string.Empty;
                    string toCityName   = string.Empty;
                    PnrAnalysis.PnrResource pnrResource = new PnrAnalysis.PnrResource();
                    var cityInfo = pnrResource.GetCityInfo(skyway.FromCityCode);
                    if (cityInfo != null)
                    {
                        fromCityName = cityInfo.city.Name;
                    }
                    cityInfo = pnrResource.GetCityInfo(skyway.ToCityCode);
                    if (cityInfo != null)
                    {
                        toCityName = cityInfo.city.Name;
                    }

                    //record.InsuranceLimitEndTime = skyway.ToDateTime.AddDays(7);//保险生效结束时间
                    //record.InsuranceLimitStartTime = skyway.StartDateTime;//保险生效开始时间
                    record.InsuranceLimitEndTime   = skyway.StartDateTime.Date.AddDays(1).AddSeconds(-1); //保险生效结束时间
                    record.InsuranceLimitStartTime = skyway.StartDateTime.Date;                           //保险生效开始时间
                    record.InsuredName             = passenger.PassengerName;                             //被投保人姓名
                    record.IdType        = passenger.IdType;                                              //证件类型
                    record.CardNo        = passenger.CardNo;                                              //证件号
                    record.SexType       = passenger.SexType;                                             //性别
                    record.Mobile        = passenger.Mobile;                                              //手机号
                    record.FlightNumber  = skyway.CarrayCode + skyway.FlightNumber;                       //航班号
                    record.PNR           = ticketOrder.PnrCode;                                           //PNR
                    record.ToCityName    = fromCityName;                                                  //到达城市名称
                    record.StartDateTime = skyway.StartDateTime;
                    record.ToDateTime    = skyway.ToDateTime;
                    record.FromCityCode  = skyway.FromCityCode;
                    record.FromCityName  = fromCityName;
                    record.ToCityCode    = skyway.ToCityCode;
                    record.ToCityName    = toCityName;
                    record.InsureType    = EnumInsureMethod.Auto;
                    record.PassengerType = passenger.PassengerType;
                    record.Birth         = passenger.Birth;
                }
            }
            //验证保险订单信息是否合法
            order.CheckData();

            //如果是单独购买,则立刻获得保单号
            if (isAlone)
            {
                foreach (InsuranceRecord insuranceRecord in order.InsuranceRecords)
                {
                    //获得保单号
                    string insuranceNo = this.GetInsuranceNo(insuranceRecord);
                    if (!string.IsNullOrEmpty(insuranceNo))
                    {
                        insuranceRecord.InsuranceNo     = insuranceNo;
                        insuranceRecord.InsuranceStatus = EnumInsuranceStatus.GotInsurance;
                    }
                    else
                    {
                        insuranceRecord.InsuranceStatus = EnumInsuranceStatus.Manual;
                    }
                }
            }
            this.unitOfWorkRepository.PersistCreationOf(order);

            //修改保险配置信息
            insuranceCfg.LeaveCount -= order.InsuranceRecords.Sum(i => i.Count);
            this.unitOfWorkRepository.PersistUpdateOf(insuranceCfg);
        }