コード例 #1
0
 public async Task <IActionResult> Post([FromBody] cw_prefee value)
 {
     value.CreatedAt = DateTime.Now;
     value.IsValid   = true;
     if (User.Identity is ClaimsIdentity identity)
     {
         value.CreatedBy = identity.Name ?? "admin";
     }
     _cwPrefeeRpt.Add(value);
     _cwPrefeeRpt.Commit();
     return(new OkObjectResult(value));
 }
コード例 #2
0
        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));
        }