public int Update(TraAddressEntity t, string[] properties = null) { using (BrightourDbContext db = new BrightourDbContext()) { return(db.Update(t, properties)); } }
public int Insert(TraAddressEntity t) { using (BrightourDbContext db = new BrightourDbContext()) { var log = db.TraAddress.Add(t); db.SaveChanges(); return(log.Aid); } }
public int AddTraOrder(TraAddOrderModel newOrder) { newOrder.Order.TrainPlace = "代售点"; newOrder.Order.OrderRoot = 0; newOrder.Order.CreateTime = DateTime.Now; if (newOrder.Order.PayAmount == 0) { newOrder.Order.PayAmount = newOrder.Order.TotalMoney; } newOrder.Order.OpeartorId = newOrder.Order.CreateOid; newOrder.Order.OrderSource = newOrder.OrderSource; if (newOrder.AddOrderType == 1)//手动 { newOrder.Order.OrderType = 0; } else { newOrder.Order.OrderType = 1; } if (newOrder.Customer != null && !string.IsNullOrEmpty(newOrder.Customer.Category) && newOrder.Customer.Category.ToUpper() == "D") { newOrder.Order.BalanceType = 1; newOrder.Order.TravelType = 0; } else { newOrder.Order.BalanceType = 0; newOrder.Order.TravelType = 1; } //如果存在项目名称 if (newOrder.ProjectName != null && newOrder.ProjectName.ProjectId > 0) { newOrder.Order.ProjectId = newOrder.ProjectName.ProjectId; } if (newOrder.CostCenter != null && newOrder.CostCenter.Cid > 0) { newOrder.Order.CostCenter = newOrder.CostCenter.Depart; } if (string.IsNullOrEmpty(newOrder.Order.CostCenter)) { newOrder.Order.CostCenter = ""; } if (newOrder.AddOrderType == 0) { newOrder.Order.OrderFrom = TraOrderFromEnum.Interface.ToString(); } else { newOrder.Order.OrderFrom = TraOrderFromEnum.Hand.ToString(); } if (newOrder.Order.OrderSource == "O") { newOrder.Order.IsOnline = "F"; } else { newOrder.Order.IsOnline = "T"; } TraOrderEntity orderEntity = Mapper.Map <TraOrderModel, TraOrderEntity>(newOrder.Order); orderEntity.CorpPolicy = string.Empty; orderEntity.ChoiceReason = string.Empty; foreach (var traOrderDetailModel in newOrder.OrderDetailList) { if (!string.IsNullOrEmpty(traOrderDetailModel.CorpPolicy)) { orderEntity.CorpPolicy += "|" + traOrderDetailModel.CorpPolicy; } if (!string.IsNullOrEmpty(traOrderDetailModel.ChoiceReason)) { orderEntity.ChoiceReason += "|" + traOrderDetailModel.ChoiceReason; } } orderEntity = _traOrderDal.Insert(orderEntity); if (newOrder.OrderStatus == null) { newOrder.OrderStatus = new TraOrderStatusModel(); } newOrder.OrderStatus.OrderId = orderEntity.OrderId; if (newOrder.Order.CreateOid != "sys" && (newOrder.OrderStatus.ProccessStatus & 64) != 64) { newOrder.OrderStatus.ProccessStatus = newOrder.OrderStatus.ProccessStatus + 64; } TraOrderStatusEntity orderStatusEntity = Mapper.Map <TraOrderStatusModel, TraOrderStatusEntity>(newOrder.OrderStatus); orderStatusEntity = _traOrderStatusDal.Insert(orderStatusEntity); foreach (var detail in newOrder.OrderDetailList) { detail.OrderId = orderEntity.OrderId; detail.TicketNum = detail.PassengerList.Count; detail.TotalPrice = detail.PassengerList.Sum(n => (n.FacePrice ?? 0)) + detail.PassengerList.Sum(n => (n.ServiceFee ?? 0));//乘客面价+乘客服务费 detail.ServiceFee = (detail.PassengerList?[0].ServiceFee ?? 0); var childPerson = detail.PassengerList.Find(n => n.AgeType == AgeTypeEnum.E); //儿童 var person = detail.PassengerList.Find(n => n.AgeType == AgeTypeEnum.C); //成人 detail.FacePrice = (person?.FacePrice ?? 0); detail.TrainChdSalePrice = (childPerson?.FacePrice ?? 0); detail.PlaceGrade = detail.PassengerList?[0].PlaceGrade; detail.PlaceType = GetPlaceType(detail.PlaceGrade); detail.TrainNoRemark = string.IsNullOrEmpty(detail.TrainNoRemark) ? "" : detail.TrainNoRemark; detail.TrainNoStatus = string.IsNullOrEmpty(detail.TrainNoStatus) ? "" : detail.TrainNoStatus; detail.OnTrainTimeTemp = detail.StartTime; detail.OnTrainTime = detail.StartTime; TraAddressEntity startAddressEntity = _traAddressDal.Query <TraAddressEntity>(n => n.Addr_Name == detail.StartName).FirstOrDefault(); if (startAddressEntity == null) { startAddressEntity = new TraAddressEntity(); startAddressEntity.Addr_Name = detail.StartName; startAddressEntity.Addr_Type = 0; startAddressEntity.Addr_S = detail.StartCode; startAddressEntity = _traAddressDal.Insert <TraAddressEntity>(startAddressEntity); } detail.StartNameId = startAddressEntity.Aid; TraAddressEntity endAddressEntity = _traAddressDal.Query <TraAddressEntity>(n => n.Addr_Name == detail.EndName) .FirstOrDefault(); if (endAddressEntity == null) { endAddressEntity = new TraAddressEntity(); endAddressEntity.Addr_Name = detail.EndName; endAddressEntity.Addr_Type = 0; endAddressEntity.Addr_S = detail.EndCode; endAddressEntity = _traAddressDal.Insert <TraAddressEntity>(endAddressEntity); } detail.EndNameId = endAddressEntity.Aid; TraOrderDetailEntity traOrderDetailEntity = Mapper.Map <TraOrderDetailModel, TraOrderDetailEntity>(detail); traOrderDetailEntity = _traOrderDetailDal.Insert(traOrderDetailEntity); foreach (var p in detail.PassengerList) { p.OdId = traOrderDetailEntity.OdId; TraPassengerEntity traPassengerEntity = Mapper.Map <TraPassengerModel, TraPassengerEntity>(p); traPassengerEntity.Name = traPassengerEntity.Name.Replace("/", " "); _traPassengerDal.Insert(traPassengerEntity); } } string logContent = newOrder.Log?.LogContent; if (string.IsNullOrEmpty(logContent)) { logContent = $"{(newOrder.Order.IsOnline == "T" ? "线上" : "线下")}添加火车订单"; } _traOrderLogDal.Insert <TraOrderLogEntity>(new TraOrderLogEntity() { OrderId = orderEntity.OrderId, CreateOid = orderEntity.CreateOid, CreateTime = DateTime.Now, LogType = "OI", LogContent = logContent }); return(orderEntity.OrderId); }
/// <summary> /// 获取抢票异步成功通知,并做处理 /// 则自动生成火车订单,通知抢票发起者 /// </summary> public void GetGrabTicketSuccessNotice(GrabTicketSuccessedDataAsyncResponseModel successedData) { int orderid = Convert.ToInt32(successedData.orderid); #region 1.更新抢票信息状态 TraGrabTicketEntity traGrabTicketEntity = _traGrabTicketDal.Query <TraGrabTicketEntity>(n => n.OrderId == orderid).FirstOrDefault(); if (traGrabTicketEntity == null) { throw new Exception("未找到对应的系统订单"); } traGrabTicketEntity.GrabStatus = TrainGrabStatusEnum.S.ToString(); _traGrabTicketDal.Update(traGrabTicketEntity, new string[] { "GrabStatus" }); #endregion #region 2.1 根据订单获取预设订单信息 TraOrderEntity traOrderEntity = _traOrderDal.Find <TraOrderEntity>(orderid); if (traOrderEntity == null) { throw new Exception("订单信息异常"); } if (traOrderEntity.OrderType == 0) { throw new Exception("该订单已经回调"); } TraOrderDetailEntity traOrderDetailEntity = _traOrderDetailDal.Query <TraOrderDetailEntity>(n => n.OrderId == traOrderEntity.OrderId) .FirstOrDefault(); if (traOrderDetailEntity == null) { throw new Exception("订单信息异常"); } TraOrderStatusEntity traOrderStatusEntity = _traOrderStatusDal.Query <TraOrderStatusEntity>(n => n.OrderId == traOrderEntity.OrderId) .FirstOrDefault(); if (traOrderStatusEntity == null) { throw new Exception("订单信息异常"); } List <TraPassengerEntity> traPassengerEntities = _traPassengerDal.Query <TraPassengerEntity>(n => n.OdId == traOrderDetailEntity.OdId).ToList(); if (traPassengerEntities.Count == 0) { throw new Exception("订单信息异常"); } #endregion #region 2.2根据返回结果,更新预设订单信息 traOrderEntity.TransactionId = successedData.transactionid; traOrderEntity.OrderType = 0; if (successedData.refund_online == "1") { traOrderEntity.IsRefundBy12306 = false; } else { traOrderEntity.IsRefundBy12306 = true; } traOrderDetailEntity.OrderId12306 = successedData.ordernumber; traOrderDetailEntity.StartName = successedData.from_station_name; traOrderDetailEntity.StartCode = successedData.from_station_code; traOrderDetailEntity.StartTime = Convert.ToDateTime(successedData.start_time); TraAddressEntity startAddressEntity = _traAddressDal.Query <TraAddressEntity>(n => n.Addr_Name == traOrderDetailEntity.StartName) .FirstOrDefault(); if (startAddressEntity != null) { traOrderDetailEntity.StartNameId = startAddressEntity.Aid; } traOrderDetailEntity.EndName = successedData.to_station_name; traOrderDetailEntity.EndCode = successedData.to_station_code; traOrderDetailEntity.EndTime = Convert.ToDateTime(successedData.arrive_time); TraAddressEntity endAddressEntity = _traAddressDal.Query <TraAddressEntity>(n => n.Addr_Name == traOrderDetailEntity.EndName) .FirstOrDefault(); if (endAddressEntity != null) { traOrderDetailEntity.EndNameId = endAddressEntity.Aid; } traOrderDetailEntity.TrainNo = successedData.checi; traOrderDetailEntity.FacePrice = Convert.ToDecimal(successedData.orderamount) / 2; traOrderDetailEntity.TotalPrice = traOrderDetailEntity.FacePrice + traOrderDetailEntity.ServiceFee; foreach (TraPassengerEntity traPassengerEntity in traPassengerEntities) { GrabTicketSuccessedPassengerAsyncResponseModel grabTicketPassenger = successedData.passengers.Find( n => n.passengersename == traPassengerEntity.Name && n.passportseno == traPassengerEntity.CardNo); traPassengerEntity.FacePrice = Convert.ToDecimal(grabTicketPassenger.price); List <string> cxinList = grabTicketPassenger.cxin.Split(',').ToList(); if (cxinList.Count == 2) { traPassengerEntity.PlaceCar = cxinList[0]; traPassengerEntity.PlaceSeatNo = cxinList[1]; } traPassengerEntity.PlaceGrade = grabTicketPassenger.zwname; traPassengerEntity.TicketNo = grabTicketPassenger.ticket_no; _traPassengerDal.Update(traPassengerEntity, new string[] { "FacePrice", "PlaceCar", "PlaceSeatNo", "PlaceGrade", "TicketNo" }); } traOrderEntity.TotalMoney = traPassengerEntities.Sum(n => (n.ServiceFee ?? 0) + (n.FacePrice ?? 0)); traOrderEntity.PayAmount = traOrderEntity.TotalMoney; traOrderStatusEntity.IsBuy = 1; traOrderStatusEntity.ProccessStatus = traOrderStatusEntity.ProccessStatus + 1 + 8 + 64; //已付款,已预定 traOrderStatusEntity.RealPayOid = "sys"; traOrderStatusEntity.RealPayDatetime = DateTime.Now; //更新订单 _traOrderDal.Update(traOrderEntity, new string[] { "TransactionId", "IsRefundBy12306", "TotalMoney", "PayAmount", "OrderType" }); //更新行程 _traOrderDetailDal.Update(traOrderDetailEntity, new string[] { "OrderId12306", "StartName", "StartCode", "StartTime", "EndName", "EndCode", "EndTime", "TrainNo", "FacePrice", "TotalPrice" }); //更新订单状态 _traOrderStatusDal.Update(traOrderStatusEntity, new[] { "IsBuy", "ProccessStatus", "RealPayOid", "RealPayDatetime" }); #endregion #region 2.3 设置付款信息,并记录日志 PaySupplierEvent?.Invoke(this, new CommonEventArgs <AccountDetailModel>(new AccountDetailModel() { Aid = 81, Amount = traPassengerEntities.Sum(n => (n.FacePrice ?? 0)) + 5, //抢票订单+5块 Detailtype = "火车票付票款", Oid = "sys", CreateTime = DateTime.Now, Source = "火车票付票款", OrderId = traOrderEntity.OrderId, OrderType = "Tra", Provider = 0, CollectionRemark = "", EstimateId = 0 })); _traOrderLogDal.Insert(new TraOrderLogEntity() { OrderId = traOrderEntity.OrderId, CreateOid = "sys", CreateTime = DateTime.Now, LogContent = "抢票出票回调,自动勾已预定、已付票款、已采购", LogType = "修改" }); #endregion #region 2.3插入Tra_InterFaceOrder表,以便退改签流程 TraInterFaceOrderEntity traInterFaceOrderEntity = _traInterFaceOrderDal.Insert <TraInterFaceOrderEntity>(new TraInterFaceOrderEntity() { OrderId = traOrderEntity.OrderId.ToString(), CreateTime = DateTime.Now, Status = (int)OrderTypeEnum.TicketSuccess, Transactionid = traOrderEntity.TransactionId, OrderNumber = traOrderDetailEntity.OrderId12306 }); _traOrderOperateDal.Insert(new TraOrderOperateEntity() { InterfaceId = traInterFaceOrderEntity.InterfaceId, AfterOperateStatus = (int)OrderTypeEnum.TicketSuccess, BeforOperateStatus = 0, OperateTime = DateTime.Now }); #endregion }
public int Delete(TraAddressEntity t) { throw new NotImplementedException(); }