/// <summary> /// 下单验证 /// </summary> /// <param name="request"></param> /// <returns></returns> public string VerifyOrder(string request) { var requestBody = _ctripGateway.CheckVerifyOrder(request); var data = requestBody.Data; int productId = 0; decimal price = data.price.HasValue ? data.price.Value : 0; if (!int.TryParse(data.productId, out productId)) { return(_ctripGateway.ErrorResult(ResultCode.CreateOrderForProductNotExist, "产品Id不存在/错误")); } var response = _ticketGateway.VerifyOrder(new OrderSingleCreateRequest { Body = new OrderSingleCreateBody { OrderInfo = new OrderSingleInfo { OrderOtaId = "", OrderPayStatus = 1, OrderPrice = price * data.count, OrderQuantity = data.count, Ticket = new ProductItem { ProductId = productId, Quantity = data.count, ProductName = "", SellPrice = price }, VisitDate = data.useDate, ContactPerson = new ContactPerson { BuyName = data.contactName, Name = data.contactName, Mobile = data.contactMobile, CardType = data.contactIdCardType == "1" ? "ID_CARD" : "", CardNo = data.contactIdCardType == "1" ? data.contactIdCardNo : "" } } } }); if (response.Head.Code == "000000") { var responseBody = new VerifyOrderBodyRespose { inventory = response.Body.Inventory }; return(_ctripGateway.VerifyOrder(responseBody)); } else if (response.Head.Code == "113019") { return(_ctripGateway.ErrorResult(ResultCode.CreateOrderForProductDownline, response.Head.Describe)); } else if (response.Head.Code == "113026") { var responseBody = new VerifyOrderBodyRespose { inventory = response.Body.Inventory }; return(_ctripGateway.ErrorResult(ResultCode.CreateOrderForLowStocks, response.Head.Describe, responseBody)); } else if (response.Head.Code == "113021") { return(_ctripGateway.ErrorResult(ResultCode.SystemError, "系统出错")); } return(_ctripGateway.ErrorResult(ResultCode.CreateOrderForParameterIllegality, response.Head.Describe)); }
/// <summary> /// 下单验证 /// </summary> /// <param name="request"></param> /// <returns></returns> public object VerifyOrder(string request) { var requestBody = _ctripGateway.CheckVerifyOrder(request); if (requestBody == null) { return(_ctripGateway.ErrorResult(ResultCode.JsonParsingFailure, "报文解析失败")); } var data = requestBody.Data; bool isProduct = true; bool isDate = true; //判断游玩时间是否是同一天 bool isCard = true; string useStartDate = data.Items[0].useStartDate; //游玩时间 var productItems = new List <ProductItem>(); foreach (var row in data.Items) { foreach (var item in row.passengers) { if (item.cardType == "0") { isCard = false; } } if (useStartDate != row.useStartDate) { isDate = false; } int productId = 0; if (!int.TryParse(row.PLU, out productId)) { isProduct = false; } productItems.Add(new ProductItem { ProductId = productId, Quantity = row.quantity, ProductName = "", SellPrice = row.price }); } if (!isCard) { return(_ctripGateway.ErrorResult(ResultCode.CreateOrderForParameterEmpty, "缺失证件")); } if (!isProduct) { return(_ctripGateway.ErrorResult(ResultCode.CreateOrderForProductNotExist, "产品Id不存在/错误")); } if (!isDate) { return(_ctripGateway.ErrorResult(ResultCode.CreateOrderForDate, "不同的产品,游玩时间不一致")); } var response = _ticketGateway.VerifyOrder(new OrderCreateRequest { Body = new OrderCreateBody { OrderInfo = new OrderInfo { OrderOtaId = "", OrderPayStatus = 1, OrderPrice = productItems.Sum(a => a.SellPrice * a.Quantity), OrderQuantity = productItems.Sum(a => a.Quantity), TicketList = productItems, VisitDate = useStartDate, ContactPerson = new ContactPerson { BuyName = data.Contacts[0].name, Name = data.Contacts[0].name, Mobile = data.Contacts[0].mobile, CardType = data.Items[0].passengers[0].cardType == "1" ? "ID_CARD" : "", CardNo = data.Items[0].passengers[0].cardType == "1" ? data.Items[0].passengers[0].cardNo : "" } } } }); if (response.Head.Code == "000000") { var responseBody = new VerifyOrderBodyRespose { Items = new List <VerifyOrderItemRespose>() }; foreach (var row in response.Body.Item) { responseBody.Items.Add(new VerifyOrderItemRespose { PLU = row.ProductId, inventorys = new VerifyOrderInventoryRespose { quantity = row.quantity, useDate = row.useDate } }); } return(_ctripGateway.VerifyOrder(responseBody)); } else if (response.Head.Code == "113019") { return(_ctripGateway.ErrorResult(ResultCode.CreateOrderForProductDownline, response.Head.Describe)); } else if (response.Head.Code == "113026") { var responseBody = new VerifyOrderBodyRespose { Items = new List <VerifyOrderItemRespose>() }; foreach (var row in response.Body.Item) { responseBody.Items.Add(new VerifyOrderItemRespose { PLU = row.ProductId, inventorys = new VerifyOrderInventoryRespose { quantity = row.quantity, useDate = row.useDate } }); } return(_ctripGateway.ErrorResult(ResultCode.CreateOrderForLowStocks, response.Head.Describe)); } else if (response.Head.Code == "113021") { return(_ctripGateway.ErrorResult(ResultCode.SystemError, "系统出错")); } return(_ctripGateway.ErrorResult(ResultCode.CreateOrderForParameterIllegality, response.Head.Describe)); }