public async Task <IActionResult> Post([FromBody] yx_orderservice value) { value.CreatedAt = DateTime.Now; value.UpdatedAt = DateTime.Now; value.IsValid = true; if (User.Identity is ClaimsIdentity identity) { value.CreatedBy = identity.Name ?? "test"; } _yxOrderserviceRpt.Add(value); _yxOrderserviceRpt.Commit(); return(new OkObjectResult(value)); }
public async Task <IActionResult> Post([FromBody] CheckInOrderDto value) { //订单信息 string createBy = string.Empty; var order = value.YxOrder; order.CreatedAt = DateTime.Now; order.UpdatedAt = DateTime.Now; order.IsValid = true; if (User.Identity is ClaimsIdentity identity) { createBy = identity.Name ?? "test"; } order.CreatedBy = createBy; order.Status = "未结账"; order.OrderNo = GetOrderNo(order.InType); _yxOrderRpt.Add(order); //事务处理 using (var tran = _context.Database.BeginTransaction()) { try { _yxOrderRpt.Commit(); //订单明细 foreach (var orderDetail in value.YxOrderList) { orderDetail.OrderId = order.Id; orderDetail.CreatedAt = DateTime.Now; orderDetail.UpdatedAt = DateTime.Now; orderDetail.IsValid = true; orderDetail.CreatedBy = createBy; //计算预计退房时间 orderDetail.PreLeaveTime = DateTime.Today.AddDays(orderDetail.Days + 1).AddHours(12); _yxOrderlistRpt.Add(orderDetail); //修改房屋状态 var houseInfo = _fwHouseinfoRpt.FindBy(f => f.Code == orderDetail.HouseCode).FirstOrDefault(); //新增房态日志 _fwStatelogRepository.Add(new fw_statelog() { HouseCode = orderDetail.HouseCode, OldState = houseInfo.State, NewState = 1003, OrderNo = order.OrderNo, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, IsValid = true, CreatedBy = createBy }); houseInfo.State = 1003; //住人净 houseInfo.OrderNo = order.OrderNo; houseInfo.CusName = value.YxOrderList.Count == 1 && orderDetail.CusName != order.CusName ? order.CusName + "," + orderDetail.CusName : orderDetail.CusName; //添加到客户资料表中 if (!_yxCustomerRpt.Exist(f => f.IDCardNo == order.IdCard)) { var customer = new yx_customer { Name = orderDetail.CusName, IDCardNo = orderDetail.IdCard, Mobile = order.CusPhone, IsValid = true, CreatedBy = createBy, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, IsCard = false }; _yxCustomerRpt.Add(customer); } } if (order.PayType == 1) { //预授权支付 _cwPreauthRepository.Add(new cw_preauth() { HouseCode = value.YxOrderList.First().HouseCode, CusName = order.CusName, AuthNo = order.BillNo, Amount = order.HouseFee, OrderNo = order.OrderNo, Remark = order.Remark, CreatedBy = order.CreatedBy, CreatedAt = DateTime.Now, IsValid = true }); _cwPreauthRepository.Commit(); } else { //预定金 _cwPrefeeRepository.Add(new cw_prefee() { HouseCode = value.YxOrderList.First().HouseCode, CusName = order.CusName, PayType = order.PayType, Amount = order.HouseFee, OrderNo = order.OrderNo, Remark = order.Remark, CreatedBy = order.CreatedBy, CreatedAt = DateTime.Now, IsValid = true }); _cwPrefeeRepository.Commit(); } if (!string.IsNullOrEmpty(order.BookOrderNo)) { var book = _bookRepository.GetSingle(f => f.OrderNo == order.BookOrderNo); book.Status = "已完成"; _bookRepository.Commit(); var bookServices = _yxBookserviceRepository.FindBy(f => f.OrderNo == order.BookOrderNo); foreach (var bs in bookServices) { var orderSer = new yx_orderservice() { OrderNo = order.OrderNo, TypeId = bs.TypeId, ItemCode = bs.ItemCode, ServiceTime = bs.ServiceTime, Times = bs.Times, Price = bs.Price, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, IsValid = true, CreatedBy = order.CreatedBy }; _yxOrderserviceRepository.Add(orderSer); } _yxOrderserviceRepository.Commit(); } _yxCustomerRpt.Commit(); _fwStatelogRepository.Commit(); _fwHouseinfoRpt.Commit(); _yxOrderlistRpt.Commit(); tran.Commit(); } catch (Exception e) { tran.Rollback(); return(BadRequest(e.Message)); } } return(new OkObjectResult(value)); }