private static XJ_Order PopulateOTAOrder(OtaOrderModel row, Tbl_OTABusiness business, Tbl_Ticket ticket) { var orderInfo = new XJ_Order { OrderOtaId = row.OrderNo, OTABusinessId = business.Id, OrderPrice = row.ProductPrice, OrderQuantity = row.ProductCount, TicketList = new List <XJ_ProductItem>(), VisitDate = row.StartDate.ToDataTimeFormat(), ContactPerson = new XJ_ContactPerson { BuyName = row.LinkName, Name = row.LinkName, Mobile = row.LinkPhone, CardType = "ID_CARD", CardNo = row.IdCard } }; orderInfo.TicketList.Add(new XJ_ProductItem { ProductId = ticket.TicketId, ProductName = ticket.TicketName, SellPrice = ticket.SalePrice, Quantity = row.ProductCount, OrderNo = row.OrderNo, OrderDetailId = row.OrderId, CodeStr = row.Code, StartDate = row.StartDate.ToDataTimeFormat(), EndDate = row.EndDate.ToDataTimeFormat(), State = StateAction.GetState(row.OrderState) }); return(orderInfo); }
/// <summary> /// 新增订单 /// </summary> /// <param name="orderInfo"></param> /// <param name="tbl_Tickets"></param> /// <returns></returns> private bool AddOrder(XJ_Order orderInfo, List <Tbl_Ticket> tbl_Tickets) { var tbl_Order = _orderService.AddOrder(orderInfo); var tbl_OrderDetails = _orderDetailService.AddOrderDetail(orderInfo, tbl_Order); _orderService.UpdateOrder(tbl_Order, tbl_OrderDetails); var tbl_Ticket_Testing = _ticketTestingService.XJ_addTicketTestings(tbl_Order, tbl_OrderDetails); _ticketService.UpdateTicketBySellCount(tbl_Tickets, tbl_OrderDetails); var tbl_SaleLog = _saleLogService.addSaleLog(tbl_Order); try { using (SqlConnection connection = new SqlConnection(DbConfig.TicketConnectionString)) { connection.Open(); var trans = connection.BeginTransaction(); SqlBulkInsert.Inert(tbl_Order, connection, trans); SqlBulkInsert.Inert(tbl_OrderDetails, connection, trans); SqlBulkInsert.Inert(tbl_Ticket_Testing, connection, trans); _ticketService.UpdateTicket(tbl_Tickets, connection, trans); SqlBulkInsert.Inert(tbl_SaleLog, connection, trans); trans.Commit(); } foreach (var row in tbl_OrderDetails) { for (var i = 0; i < row.Quantity; i++) { _ticketConsumeService.Add(new Tbl_TicketConsume { OrderNo = row.OrderNo, OtaOrderNo = tbl_Order.OTAOrderNo, TicketTestingId = 0, TicketCategory = row.TicketCategory, BarCode = row.BarCode, QRcode = row.QRcode, OrderDetailNumber = row.Number, OrderSource = (int)OrderSource.My, SendStatus = false, CreateTime = row.ValidityDateEnd, SendCount = 0, TicketId = row.TicketId }); } } return(true); } catch (Exception ex) { //"订单创建异常,订单创建失败"; return(false); } }
/// <summary> /// 修改订单--小径平台 /// </summary> /// <param name="tbl_Order"></param> /// <param name="request"></param> public void UpdateOrder(Tbl_Order tbl_Order, XJ_Order request) { var person = request.ContactPerson; tbl_Order.IDType = GetIdCardType(person.CardType); tbl_Order.IDCard = person.CardNo; tbl_Order.Mobile = person.Mobile; tbl_Order.Linkman = person.Name; tbl_Order.ValidityDateStart = request.VisitDate; tbl_Order.ValidityDateEnd = request.VisitDate; _orderRepository.Update(tbl_Order); }
private void AuditedAction(OrderModel row, List <Tbl_Ticket> tickets, XJ_Order orderInfo) { //验证OTA订单id是否已存在 var otaOrder = _orderService.GetOrderBy(row.OrderNo); if (otaOrder == null) { //OTA订单id已存在, 修改订单 //订单已审核 var isCreate = AddOrder(orderInfo, tickets); if (isCreate) { foreach (var orderDetail in orderInfo.TicketList) { UpdateIssuedLine(orderDetail); } } Console.Write("\n 同步旅行社订单:" + (isCreate == true ? "成功" : "失败") + " 订单号:" + orderInfo.OrderOtaId); } else { foreach (var orderDetail in orderInfo.TicketList) { if (orderDetail.State == (int)OrderDetailState.HasChange) { //G-已改签--修改订单 var result = UpdateOrderDetail(orderDetail); if (result) { UpdateIssuedLine(orderDetail); } Console.Write("\n同步旅行社订单,已改签:" + (result == true ? "成功" : "失败") + " 订单号:" + orderInfo.OrderOtaId); continue; } if (orderDetail.State == (int)OrderDetailState.FullRefund) { //全部退票 var result = RefundOrderDetail(orderDetail); if (result) { UpdateIssuedLine(orderDetail); } Console.Write("\n同步旅行社订单,全部退票:" + (result == true ? "成功" : "失败") + " 订单号:" + orderInfo.OrderOtaId); continue; } UpdateIssuedLine(orderDetail); } } }
/// <summary> /// 同步旅行社订单 /// </summary> public void SynchronizingOrder() { string timeStamp = DateTime.Now.GetTimeStamp(); var sign = Md5HashHelper.HashPassword(_merCode + _key + timeStamp); //订单类型(4 - OTA订单, 5 - 旅行社订单) var order = _orderIssuedsSoapClient.GetOrderIssuedLine(_merCode, timeStamp, sign, "", "", 5); var resultData = JsonHelper.JsonToObject <ResultData>(order); if (resultData.IsTrue && resultData.ResultCode == "200") { var orderModel = JsonConvert.DeserializeObject <List <OrderModel> >(resultData.ResultJson); var orderList = orderModel.Where(a => a.AuditState == (int)OrderAuditState.Audited || a.AuditState == (int)OrderAuditState.OrderCancellation).Take(200).OrderByDescending(a => a.CreateTime).ToList(); var channelCodeList = orderList.Select(a => a.ChannelCode).Distinct().ToList(); var businessList = _otaBusinessService.GetList(channelCodeList, 2); foreach (var row in orderList) { //判断分销商是否存在 var business = businessList.FirstOrDefault(a => a.Code == row.ChannelCode); if (business == null) { continue; } var productCodeList = row.OrderItems.Select(a => a.ProductCode).Distinct().ToList(); var tickets = _ticketService.GetListByBusiness(productCodeList); //判断产品是否存在 if (tickets.Count != productCodeList.Count) { continue; } XJ_Order orderInfo = PopulateOrder(row, business, tickets); if (row.AuditState == (int)OrderAuditState.Audited) { AuditedAction(row, tickets, orderInfo); } if (row.AuditState == (int)OrderAuditState.OrderCancellation) { OrderCancellationAction(row, orderInfo); } } } }
private static XJ_Order PopulateOrder(OrderModel row, Tbl_OTABusiness business, List <Tbl_Ticket> tickets) { var orderInfo = new XJ_Order { OrderOtaId = row.OrderNo, OTABusinessId = business.Id, OrderPrice = row.Money.ToDouble(), OrderQuantity = row.OrderItems.Sum(a => a.Number), TicketList = new List <XJ_ProductItem>(), VisitDate = row.PlayDate.ToDataTimeFormat(), ContactPerson = new XJ_ContactPerson { BuyName = row.LinkName, Name = row.LinkName, Mobile = row.LinkPhone, CardType = "ID_CARD", CardNo = row.LinkIdCard } }; foreach (var item in row.OrderItems) { var ticket = tickets.FirstOrDefault(a => a.Code == item.ProductCode); orderInfo.TicketList.Add(new XJ_ProductItem { ProductId = ticket.TicketId, ProductName = ticket.TicketName, SellPrice = ticket.SalePrice, Quantity = item.Number, OrderNo = item.OrderNo, OrderDetailId = item.ItemId, CodeStr = item.Code, StartDate = item.StartDate.ToDataTimeFormat(), EndDate = item.EndDate.ToDataTimeFormat(), State = StateAction.GetState(item.State) }); } return(orderInfo); }
/// <summary> /// 创建订单--小径平台 /// </summary> /// <param name="orderInfo"></param> /// <returns></returns> public Tbl_Order AddOrder(XJ_Order request) { //创建订单号 string orderNo = OrderHelper.GenerateOrderNo(); var order = Get(orderNo); if (order != null) { orderNo = OrderHelper.GenerateOrderNo(); } int idType = GetIdCardType(request.ContactPerson.CardType); //订单 Tbl_Order tbl_Order = new Tbl_Order { OrderNo = orderNo, OTABusinessId = request.OTABusinessId, OTAOrderNo = request.OrderOtaId, TicketSource = (int)TicketSourceStatus.Ota, PayType = (int)PayStatus.NoPayStatus, PayAccount = "", PayTradeNo = "", SellerId = 0, Price = 0, Linkman = request.ContactPerson.Name, Mobile = request.ContactPerson.Mobile, OrderStatus = (int)OrderDataStatus.NoPay, CreateTime = DateTime.Now, ValidityDateStart = request.VisitDate, ValidityDateEnd = request.VisitDate, UsedQuantity = 0, Remark = "", IDType = idType, IDCard = request.ContactPerson.CardNo, CreateUserId = 0 }; return(tbl_Order); }
/// <summary> /// 同步OTA订单 /// </summary> public void SynchronizingOtaOrder() { XJ_OrderIssuedsSoapClient client = new XJ_OrderIssuedsSoapClient(); string timeStamp = DateTime.Now.GetTimeStamp(); var sign = Md5HashHelper.HashPassword(_merCode + _key + timeStamp); //订单类型(4 - OTA订单, 5 - 旅行社订单) var order = client.GetOrderIssuedLine(_merCode, timeStamp, sign, "", "", 4); var resultData = JsonHelper.JsonToObject <ResultData>(order); if (resultData.IsTrue && resultData.ResultCode == "200") { var orderModel = JsonConvert.DeserializeObject <List <OtaOrderModel> >(resultData.ResultJson); var orderList = orderModel.Take(200).OrderByDescending(a => a.CreateTime).ToList(); var channelCodeList = orderList.Select(a => a.ChannelCode).Distinct().ToList(); var businessList = _otaBusinessService.GetList(channelCodeList, 1); var productCodeList = orderList.Select(a => a.ProductCode).Distinct().ToList(); var tickets = _ticketService.GetListByBusiness(productCodeList); foreach (var row in orderList) { //判断分销商是否存在 var business = businessList.FirstOrDefault(a => a.Code == row.ChannelCode); if (business == null) { continue; } var ticket = tickets.FirstOrDefault(a => a.Code == row.ProductCode); //判断产品是否存在 if (ticket == null) { continue; } XJ_Order orderInfo = PopulateOTAOrder(row, business, ticket); OrderOtaAction(tickets, row, orderInfo); } } }
private void OrderCancellationAction(OrderModel row, XJ_Order orderInfo) { //取消订单 //验证OTA订单id是否已存在 var otaOrder = _orderService.GetOrderBy(row.OrderNo); if (otaOrder != null) { foreach (var orderDetail in orderInfo.TicketList) { if (orderDetail.State == (int)OrderDetailState.Cancel) { //M-已退款--退款 var result = RefundOrderDetail(orderDetail); if (result) { UpdateIssuedLine(orderDetail); } Console.Write("\n取消旅行社订单:" + (result == true ? "成功" : "失败") + " 订单号:" + otaOrder.OTAOrderNo); } } } }
/// <summary> /// 创建订单详情--小径平台 /// </summary> /// <param name="order"></param> /// <param name="tbl_Order"></param> /// <returns></returns> public List <Tbl_OrderDetail> AddOrderDetail(XJ_Order order, Tbl_Order tbl_Order) { List <Tbl_OrderDetail> orderDetails = new List <Tbl_OrderDetail>(); string ticketNames = string.Empty; decimal TotalMoney = 0; int TotalCount = 0; //企业Id int EnterpriseID = 0; int ScenicID = 0; foreach (var te in order.TicketList) { var ticket = _ticketService.GetTicket(order.VisitDate, te.ProductId); var ticketRule = _ticketRuleRepository.FirstOrDefault(a => a.Id == ticket.RuleId); //二维码票: 每种门票 一个订单详情,多个数量 Tbl_OrderDetail tbl_OrderDetail = new Tbl_OrderDetail { Number = Guid.NewGuid(), OrderNo = tbl_Order.OrderNo, OtaOrderDetailId = te.OrderDetailId, EnterpriseId = ticket.EnterpriseId, ScenicId = ticket.ScenicId, WindowId = 0, SellerId = 0, SellerType = 1, OrderSource = (int)OrderSource.XiaoJing, TicketSource = (int)TicketSourceStatus.Ota, TicketCategory = (int)TicketCategoryStatus.QrCodeElectronTicket, UsedQuantity = 0, TicketId = te.ProductId, TicketName = ticket.TicketName, Price = ticket.SalePrice, SettlementPrice = ticket.SettlementPrice, Quantity = te.Quantity, BarCode = te.CodeStr, Stub = "", CertificateNO = "", OrderStatus = (int)OrderDetailsDataStatus.NoPay, CreateTime = DateTime.Now, ValidityDateStart = order.VisitDate, ValidityDateEnd = order.VisitDate, PrintCount = 0, QRcodeUrl = "", QRcode = te.CodeStr, Mobile = order.ContactPerson.Mobile, IDCard = tbl_Order.IDCard, Linkman = order.ContactPerson.Name, CanModify = ticketRule.CanModify, CanRefund = ticketRule.CanRefund }; UpdateOrderDetailRefundTimeAndModifyTime(order.VisitDate, ticket, tbl_OrderDetail, ticketRule); orderDetails.Add(tbl_OrderDetail); //有效的门票信息 EnterpriseID = ticket.EnterpriseId; ScenicID = ticket.ScenicId; ticketNames += ticket.TicketName + ","; TotalMoney += (ticket.SalePrice * te.Quantity); TotalCount += te.Quantity; } ticketNames = ticketNames.Substring(0, ticketNames.Length - 1); if (ticketNames.Length > 50) { ticketNames = ticketNames.Substring(0, 50); } tbl_Order.EnterpriseId = EnterpriseID; tbl_Order.ScenicId = ScenicID; tbl_Order.TicketName = ticketNames; tbl_Order.TotalAmount = TotalMoney; tbl_Order.BookCount = TotalCount; return(orderDetails); }
private void OrderOtaAction(List <Tbl_Ticket> tickets, OtaOrderModel row, XJ_Order orderInfo) { //验证OTA订单id是否已存在 var otaOrder = _orderService.GetOrderBy(row.OrderNo); if (otaOrder == null) { if (row.OrderState != OrderDetailState.Paid.GetDescriptionByName()) { return; } //OTA订单id已存在, 修改订单 //订单已审核 var isCreate = AddOrder(orderInfo, tickets); if (isCreate) { foreach (var orderDetail in orderInfo.TicketList) { UpdateIssuedLineForOTA(orderDetail); } } Console.Write("\n同步OTA订单,创建订单:" + (isCreate == true ? "成功" : "失败") + " 订单号:" + orderInfo.OrderOtaId); } else { foreach (var orderDetail in orderInfo.TicketList) { if (orderDetail.State == (int)OrderDetailState.HasChange) { //G-已改签--修改订单 var result = UpdateOrderDetail(orderDetail); if (result) { UpdateIssuedLineForOTA(orderDetail); } Console.Write("\n同步OTA订单,已改签:" + (result == true ? "成功" : "失败") + " 订单号:" + orderInfo.OrderOtaId); continue; } if (orderDetail.State == (int)OrderDetailState.FullRefund) { //A-全部退票 var result = RefundOrderDetail(orderDetail); if (result) { UpdateIssuedLineForOTA(orderDetail); } Console.Write("\n同步OTA订单,全部退票:" + (result == true ? "成功" : "失败") + " 订单号:" + orderInfo.OrderOtaId); continue; } if (orderDetail.State == (int)OrderDetailState.Refunded || orderDetail.State == (int)OrderDetailState.Cancel) { //取消订单 var result = RefundOrderDetail(orderDetail); if (result) { UpdateIssuedLineForOTA(orderDetail); } Console.Write("\n同步OTA订单,取消订单:" + (result == true ? "成功" : "失败") + " 订单号:" + orderInfo.OrderOtaId); continue; } UpdateIssuedLineForOTA(orderDetail); } } }