public async Task <IActionResult> Post([FromBody] cw_cusaccount value) { value.CreatedAt = DateTime.Now; value.IsValid = true; string createBy = string.Empty; if (User.Identity is ClaimsIdentity identity) { createBy = identity.Name ?? "test"; } value.CreatedBy = createBy; using (var tran = _context.Database.BeginTransaction()) { try { _cwCusaccountRpt.Add(value); _cwCusaccountRpt.Commit(); var orderDetail = _yxOrderlistRpt.FindBy(f => f.HouseCode == value.HouseCode && f.IsValid).OrderByDescending(f => f.Id) .First(); //更改订单状态 var order = _yxOrderRpt.GetSingle(f => f.Id == orderDetail.OrderId); order.Status = "已结算"; order.UpdatedAt = DateTime.Now; _yxOrderRpt.Commit(); var orderDetailList = _yxOrderlistRpt.FindBy(f => f.OrderId == order.Id); foreach (var ordd in orderDetailList) { //更新房态 var house = _fwHouseinfoRpt.GetSingle(f => f.Code == ordd.HouseCode); house.State = 1002;//空脏 _fwHouseinfoRpt.Commit(); //新增房态日志 _fwStatelogRepository.Add(new fw_statelog() { HouseCode = orderDetail.HouseCode, OldState = house.State, NewState = 1002, OrderNo = order.OrderNo, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, IsValid = true, CreatedBy = createBy }); _fwStatelogRepository.Commit(); } tran.Commit(); } catch (Exception e) { return(BadRequest(e.Message)); } } return(new OkObjectResult(value)); }
public async Task <IActionResult> PostClear([FromBody] fw_clean value) { int oldState = int.Parse(value.CreatedBy); string createBy = string.Empty; if (User.Identity is ClaimsIdentity identity) { createBy = identity.Name ?? "test"; } value.CreatedBy = createBy; value.IsValid = true; value.CleanTime = DateTime.Now; value.IsOverStay = false; using (var tran = _context.Database.BeginTransaction()) { try { //增加扫房日志 _cleanRepository.Add(value); _cleanRepository.Commit(); //新增房态日志 _fwStatelogRepository.Add(new fw_statelog() { HouseCode = value.HouseCode, OldState = oldState, NewState = 1001, OrderNo = string.Empty, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, IsValid = true, CreatedBy = createBy }); _fwStatelogRepository.Commit(); //修改房屋状态 var house = _fwHouseinfoRpt.GetSingle(f => f.Code == value.HouseCode); if (house != null) { house.State = 1001; } _fwHouseinfoRpt.Commit(); tran.Commit(); } catch (Exception ex) { tran.Rollback(); return(new BadRequestResult()); } } 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 ?? "admin"; } 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 }); if (houseInfo != null) { 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 { CustomerName = orderDetail.CusName, IDCardNo = orderDetail.IdCard, Mobile = order.CusPhone, IsValid = true, CreatedBy = createBy, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; _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(); } _yxCustomerRpt.Commit(); _fwStatelogRepository.Commit(); _fwHouseinfoRpt.Commit(); _yxOrderlistRpt.Commit(); tran.Commit(); } catch (Exception e) { tran.Rollback(); return(BadRequest(e.Message)); } } return(new OkObjectResult(value)); }