/// <summary> /// 退保 /// </summary> /// <param name="insuranceNo">保单号</param> /// <param name="serailNumebr">中介方流水号</param> /// <returns>成功则返回保单号,否则-1</returns> public static string Refund_Insurance(string insuranceNo, string serailNumebr) { Tuple <string, string> tuple = null; var collect = InsuranceSection.GetInsuranceConfigurationSection().CtrlInsuranceCollection; if (!collect.IsEnabled) { throw new CustomException(100012, "保险平台未启用"); } var curInsChanel = ""; foreach (var m in from InsuranceElement m in collect where m.IsCurrent select m) { curInsChanel = m.Value; break; } if (curInsChanel == "中科") { var iInsurancePlatform = new _ZKInsurancePlatform(); tuple = iInsurancePlatform.Refund_Insurance(insuranceNo); } else if (curInsChanel == "中国太平") { var iInsurancePlatform = new _TPRSInsurancePlatform(); tuple = iInsurancePlatform.Refund_Insurance(insuranceNo, serailNumebr); } else { throw new CustomException(100013, "当前启用的保险通道有误"); } return(tuple == null ? "-1" : tuple.Item2); }
/// <summary> /// 投保 /// </summary> /// <param name="serialNumber">流水号</param> /// <param name="beginDate">保险生效时间,格式:yyyy-MM-dd HH:mm:ss</param> /// <param name="endDate">保险截止时间,格式:yyyy-MM-dd HH:mm:ss</param> /// <param name="name">投保人姓名</param> /// <param name="idType">投保人证件类型</param> /// <param name="idNo">被保险人证件号</param> /// <param name="sexType">投保人性别</param> /// <param name="birthDay">投保人生日(yyyyMMdd)</param> /// <param name="mobile">投保人手机</param> /// <param name="insuranceCount">投保份数(默认1份)</param> /// <param name="fligthNumber">航班号(如:3U8823)</param> /// <param name="flightStartDate">航班日期</param> /// <param name="toCityName">到达城市</param> /// <returns>成功则返回保单号,否则-1</returns> public static string Buy_Insurance(string serialNumber, DateTime beginDate, DateTime endDate, string name, EnumIDType idType, string idNo, EnumSexType sexType, DateTime?birthDay, string mobile, int insuranceCount = 1, string fligthNumber = null, DateTime?flightStartDate = null, string toCityName = null) { Tuple <string, string> tuple = null; var collect = InsuranceSection.GetInsuranceConfigurationSection().CtrlInsuranceCollection; if (!collect.IsEnabled) { throw new CustomException(100012, "保险平台未启用"); } var curInsChanel = ""; foreach (var m in from InsuranceElement m in collect where m.IsCurrent select m) { curInsChanel = m.Value; break; } if (curInsChanel == "中科") { var idTypeStr = idType == EnumIDType.NormalId ? "I" : "O"; var sexTypeStr = sexType == EnumSexType.Male ? "M" : "F"; var iInsurancePlatform = new _ZKInsurancePlatform(); tuple = iInsurancePlatform.Buy_Insurance(serialNumber, beginDate, endDate, name, idTypeStr, idNo, sexTypeStr, birthDay, mobile, insuranceCount); } else if (curInsChanel == "中国太平") { var idTypeStr = ""; if (idType == EnumIDType.NormalId) { idTypeStr = "1"; } else if (idType == EnumIDType.MilitaryId) { idTypeStr = "2"; } else if (idType == EnumIDType.Passport) { idTypeStr = "3"; } else { idTypeStr = "9"; } var sexTypeStr = sexType == EnumSexType.Male ? "1" : "2"; var iInsurancePlatform = new _TPRSInsurancePlatform(); tuple = iInsurancePlatform.Buy_Insurance(serialNumber, beginDate, endDate, name, idTypeStr, idNo, sexTypeStr, birthDay, mobile, insuranceCount, fligthNumber, flightStartDate, toCityName); } else { throw new CustomException(100013, "当前启用的保险通道有误"); } return(tuple == null ? "-1" : tuple.Item2); }
/// <summary> /// 运营商批发保险 /// </summary> /// <param name="buyCount">购买保险的数量</param> /// <param name="pwd"></param> /// <param name="carrierCode"></param> /// <param name="carrierName"></param> /// <param name="payUser"></param> public void BuyInsuranceByCashByCarrier(int buyCount, string pwd, string carrierCode, string carrierName, string operatorCode, string operatorName, CurrentUserInfo payUser, string remark = "") { //获取保险配置 var cfg = InsuranceSection.GetInsuranceConfigurationSection(); if (!cfg.CtrlInsuranceCollection.IsEnabled) { throw new CustomException(11112, "保险功能未开启"); } //最大能够购买的数量 var canBuyMaxCount = (from InsuranceElement ctrl in cfg.CtrlInsuranceCollection select ctrl).Where(m => m.IsCurrent).FirstOrDefault().LeaveCount; if (buyCount > canBuyMaxCount) { string type = payUser == null ? "赠送" : "购买"; throw new CustomException(11113, "最多仅可" + type + canBuyMaxCount + "份保险。"); } //获取当前运营商保险信息 var model = this._iInsuranceConfigRepository.FindAll(p => p.BusinessmanCode == carrierCode).FirstOrDefault(); //获取单价 decimal singlePrice = payUser == null ? 0 : cfg.CtrlInsuranceCollection.SinglePrice; //运营商购买记录 var logBuiler = AggregationFactory.CreateBuiler <InsuranceDepositLogBuilder>(); var log = logBuiler.CreateInsuranceDepositLog(); log.PayNo = log.GetPayNo(); log.BeforeLeaveCount = model == null ? 0 : model.LeaveCount; //购买前剩余 log.AfterLeaveCount = log.BeforeLeaveCount + buyCount; //购买后剩余 log.DepositCount = buyCount; //购买数量 log.TotalPrice = Math.Round((singlePrice * buyCount), 2); //总价 log.SinglePrice = singlePrice; //单价 log.BusinessmanCode = carrierCode; //商户号 log.BusinessmanName = carrierName; //商户名称 log.PayWay = EnumPayMethod.Account; //支付类别 log.Remark = remark; log.RecordType = payUser == null ? EnumInsuranceDepositType.Offer : EnumInsuranceDepositType.Normal; //记录类别 log.OperatorAccount = operatorCode; log.OperatorName = operatorName; log.PayFee = Math.Round(SystemConsoSwitch.Rate * log.TotalPrice, 2); if (_iPayMentClientProxy == null) { _iPayMentClientProxy = new CashbagPaymentClientProxy(); } var payResult = string.Empty; if (payUser != null) { //现金账户 //payResult = _iPayMentClientProxy.PaymentByCashAccount(payUser.CashbagCode, payUser.CashbagKey, // log.PayNo, "购买保险", log.TotalPrice, pwd); var resultc = _iPayMentClientProxy.PaymentByCashAccount(payUser.CashbagCode, payUser.CashbagKey, log.PayNo, "购买保险", log.TotalPrice, pwd); if (resultc.Item1) { //该订单已经被在线支付时写入日志 Logger.WriteLog(LogType.INFO, "订单已经支付,交易号为" + resultc.Item2 + "支付方式为" + resultc.Item3); throw new CustomException(0001, "订单已经支付,交易号为" + resultc.Item2 + "支付方式为" + resultc.Item3); } payResult = resultc.Item2; } //如果存在交易号,即支付成功 if (!string.IsNullOrEmpty(payResult)) { log.OutTradeNo = payResult; //设置交易号 log.BuyState = EnumInsurancePayStatus.OK; //设置交易状态 //设置剩余数量 foreach (var m in (from InsuranceElement ctrl in cfg.CtrlInsuranceCollection select ctrl).Where(m => m.IsCurrent)) { m.LeaveCount -= buyCount; break; } //保存配置信息 InsuranceSection.Save(); //保存当前分销商商户保险配置 if (model != null) { model.LeaveCount = log.AfterLeaveCount; this.unitOfWorkRepository.PersistUpdateOf(model); } else { var builder = AggregationFactory.CreateBuiler <InsuranceConfigBuilder>(); var m = builder.CreateInsuranceConfig(); m.BusinessmanCode = carrierCode; m.BusinessmanName = carrierName; m.IsOpen = true; m.SinglePrice = singlePrice; m.LeaveCount = buyCount; m.ConfigType = EnumInsuranceConfigType.Carrier; this.unitOfWorkRepository.PersistCreationOf(m); } } else if (payUser == null) { log.BuyState = EnumInsurancePayStatus.Offer; //设置剩余数量 foreach (var m in (from InsuranceElement ctrl in cfg.CtrlInsuranceCollection select ctrl).Where(m => m.IsCurrent)) { m.LeaveCount -= buyCount; break; } //保存配置信息 InsuranceSection.Save(); //保存当前分销商商户保险配置 if (model != null) { model.LeaveCount = log.AfterLeaveCount; this.unitOfWorkRepository.PersistUpdateOf(model); } else { var builder = AggregationFactory.CreateBuiler <InsuranceConfigBuilder>(); var m = builder.CreateInsuranceConfig(); m.BusinessmanCode = carrierCode; m.BusinessmanName = carrierName; m.IsOpen = true; m.SinglePrice = singlePrice; m.LeaveCount = buyCount; m.ConfigType = EnumInsuranceConfigType.Carrier; this.unitOfWorkRepository.PersistCreationOf(m); } } //否则交易失败 else { log.BuyState = EnumInsurancePayStatus.NoPay; } log.BuyTime = DateTime.Now; this.unitOfWorkRepository.PersistCreationOf(log); }
/// <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); }