/// <summary>
        /// 下单验证接口--单个产品
        /// </summary>
        /// <param name="request"></param>
        /// <param name="business"></param>
        /// <returns></returns>
        private PageResult VerifySingleOrder(OrderSingleCreateRequest request, Tbl_OTABusiness business)
        {
            var orderInfo = request.Body.OrderInfo;
            OrderSingleCreateResponse result = new OrderSingleCreateResponse
            {
                Head = HeadResult.V1,
                Body = new OrderSingleCreateInfo
                {
                    Inventory = 0
                }
            };
            var validResult = _orderService.ValidDataForVerifyOrderRequest(request);

            if (!validResult.Status)
            {
                result.Head.Code     = validResult.Code;
                result.Head.Describe = validResult.Message;
                return(PageDataResult.Data(result, business.Saltcode.ToString()));
            }
            var tbl_Ticket      = _ticketService.GetTicket(orderInfo.Ticket.ProductId, business.ScenicId, orderInfo.VisitDate.ToDataTime());
            var validDataResult = _ticketService.ValidDataForOrderSingleCreateRequest(request, business, tbl_Ticket, result);

            if (!validDataResult.Status)
            {
                result.Head.Code     = validDataResult.Code;
                result.Head.Describe = validDataResult.Message;
                return(PageDataResult.Data(result, business.Saltcode.ToString()));
            }
            result.Head.Code        = "000000";
            result.Head.Describe    = "成功";
            result.Body.OrderStatus = "OREDER_SUCCESS";
            return(PageDataResult.Data(result, business.Saltcode.ToString()));
        }
        /// <summary>
        /// 验证单个订单数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public DataValidResult ValidDataForOrderSingleCreateRequest(
            OrderSingleCreateRequest request,
            Tbl_OTABusiness business,
            Tbl_Ticket tbl_Ticket,
            OrderSingleCreateResponse response)
        {
            var result = new DataValidResult {
                Status = false
            };
            var ticket = request.Body.OrderInfo.Ticket;

            if (tbl_Ticket == null)
            {
                result.Code    = "113019";
                result.Message = "创建订单失败,选择的游玩日期超出选购产品的有效期或者选购的产品无效";
                return(result);
            }
            var existence = _otaTicketRelationService.CheckIsTicketId(business.Id, tbl_Ticket.TicketId);

            if (!existence)
            {
                result.Code    = "113019";
                result.Message = "创建订单失败,选择的游玩日期超出选购产品的有效期或者选购的产品无效";
                return(result);
            }
            if (tbl_Ticket.SalePrice != ticket.SellPrice)
            {
                result.Code    = "113020";
                result.Message = "创建订单失败,价格不一致";
                return(result);
            }
            //日销售限额为空或者0  为不限制
            if (tbl_Ticket.StockCount.HasValue && tbl_Ticket.StockCount.Value > 0)
            {
                if (!tbl_Ticket.LastUpdateTime.HasValue || tbl_Ticket.LastUpdateTime.Value.Date != DateTime.Now.Date)
                {
                    tbl_Ticket.SellCount = 0;
                }
                var sellCount = tbl_Ticket.SellCount.HasValue ? tbl_Ticket.SellCount.Value : 0;//库存
                response.Body.Inventory = tbl_Ticket.StockCount.Value - sellCount;
                if (sellCount + ticket.Quantity > tbl_Ticket.StockCount.Value)
                {
                    //开启了库存限制,购买数量超过了库存
                    result.Code    = "113026";
                    result.Message = "创建订单失败,库存不足";
                    return(result);
                }
            }
            else
            {
                response.Body.Inventory = 50000;
            }

            result.Status = true;
            return(result);
        }
        /// <summary>
        /// 创建单个产品订单并支付
        /// </summary>
        /// <param name="request"></param>
        /// <param name="business"></param>
        /// <returns></returns>
        private PageResult PaySingleOrder(OrderSingleCreateRequest request, Tbl_OTABusiness business)
        {
            var orderInfo = request.Body.OrderInfo;
            OrderSingleCreateResponse result = new OrderSingleCreateResponse
            {
                Head = HeadResult.V1,
                Body = new OrderSingleCreateInfo
                {
                    Inventory = 0
                }
            };
            var validResult = _orderService.ValidDataForOrderSingleCreateRequest(request, result);

            if (!validResult.Status)
            {
                result.Head.Code     = validResult.Code;
                result.Head.Describe = validResult.Message;
                return(PageDataResult.Data(result, business.Saltcode.ToString()));
            }
            var tbl_Ticket      = _ticketService.GetTicket(orderInfo.Ticket.ProductId, business.ScenicId, orderInfo.VisitDate.ToDataTime());
            var validDataResult = _ticketService.ValidDataForOrderSingleCreateRequest(request, business, tbl_Ticket, result);

            if (!validDataResult.Status)
            {
                result.Head.Code     = validDataResult.Code;
                result.Head.Describe = validDataResult.Message;
                return(PageDataResult.Data(result, business.Saltcode.ToString()));
            }
            var tbl_Order       = _orderService.AddOrder(orderInfo, business);
            var tbl_OrderDetail = _orderDetailService.AddOrderDetail(orderInfo, tbl_Order, tbl_Ticket);

            _orderService.UpdateOrder(tbl_Order, tbl_OrderDetail);
            var tbl_Ticket_Testing = _ticketTestingService.AddTicketTesting(tbl_Order, tbl_OrderDetail);

            try
            {
                _orderService.BeginTran();
                _orderService.Add(tbl_Order);
                _orderDetailService.Add(tbl_OrderDetail);
                _ticketTestingService.Add(tbl_Ticket_Testing);
                _ticketService.UpdateTicketBySellCount(tbl_Ticket, tbl_OrderDetail);
                _noticeOrderConsumedService.Add(tbl_Order, tbl_OrderDetail, business);
                _saleLogService.Add(tbl_Order);
                _orderService.CommitTran();
            }
            catch (Exception ex)
            {
                _orderService.RollbackTran();
                result.Head.Code     = "113021";
                result.Head.Describe = "订单创建异常,订单创建失败";
                return(PageDataResult.Data(result, business.Saltcode.ToString()));
            }
            result.Head.Code          = "000000";
            result.Head.Describe      = "成功";
            result.Body.OrderId       = tbl_Order.OrderNo;
            result.Body.OtaOrderId    = tbl_Order.OTAOrderNo;
            result.Body.CertificateNo = tbl_OrderDetail.CertificateNO;
            result.Body.Code          = tbl_OrderDetail.QRcode;
            result.Body.OrderStatus   = "OREDER_SUCCESS";
            return(PageDataResult.Data(result, business.Saltcode.ToString()));
        }
Exemple #4
0
        /// <summary>
        /// 创建单个订单基础数据验证
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public DataValidResult ValidDataForOrderSingleCreateRequest(OrderSingleCreateRequest request, OrderSingleCreateResponse response)
        {
            var orderInfo = request.Body.OrderInfo;
            var result    = new DataValidResult {
                Status = false
            };

            if (orderInfo.ContactPerson == null)
            {
                result.Code    = "113001";
                result.Message = "创建订单异常,取票人信息为空";
                return(result);
            }
            if (string.IsNullOrEmpty(orderInfo.ContactPerson.Name))
            {
                result.Code    = "113002";
                result.Message = "创建订单异常,取票人姓名不能为空";
                return(result);
            }
            if (string.IsNullOrEmpty(orderInfo.ContactPerson.Mobile))
            {
                result.Code    = "113003";
                result.Message = "创建订单异常,取票人手机号码不能为空";
                return(result);
            }
            if (!RegexValidation.IsCellPhone(orderInfo.ContactPerson.Mobile))
            {
                result.Code    = "113004";
                result.Message = "创建订单异常,取票人手机号码异常";
                return(result);
            }
            if (!string.IsNullOrEmpty(orderInfo.ContactPerson.CardType))
            {
                switch (orderInfo.ContactPerson.CardType.ToUpper())
                {
                case "ID_CARD":
                    if (!string.IsNullOrEmpty(orderInfo.ContactPerson.CardNo))
                    {
                        if (!RegexValidation.IsIdCard(orderInfo.ContactPerson.CardNo))
                        {
                            result.Code    = "113005";
                            result.Message = "创建订单异常,游客身份证信息输入有误";
                            return(result);
                        }
                    }
                    break;

                case "HUZHAO":
                case "TAIBAO":
                case "GANGAO":
                case "OTHER":
                    break;
                }
            }

            if (string.IsNullOrEmpty(orderInfo.OrderOtaId))
            {
                result.Code    = "113006";
                result.Message = "创建订单异常,OTA订单id不能为空";
                return(result);
            }

            if (orderInfo.OrderQuantity <= 0)
            {
                result.Code    = "113008";
                result.Message = "创建订单异常,订票总数量不能小于1";
                return(result);
            }
            if (!orderInfo.VisitDate.IsDataTime())
            {
                result.Code    = "113009";
                result.Message = "创建订单异常,游玩日期格式不合法";
                return(result);
            }
            if (orderInfo.VisitDate.ToDataTime() < DateTime.Now.Date)
            {
                result.Code    = "113009";
                result.Message = "创建订单异常,游玩日期不合法";
                return(result);
            }
            if (orderInfo.Ticket == null)
            {
                result.Code    = "113015";
                result.Message = "创建订单异常,购买产品的数据不合法";
                return(result);
            }
            if (orderInfo.Ticket.Quantity != orderInfo.OrderQuantity)
            {
                result.Code    = "113011";
                result.Message = "创建订单异常,购买产品的总数量和订票总数量不符";
                return(result);
            }

            if (orderInfo.Ticket.Quantity <= 0)
            {
                result.Code    = "113013";
                result.Message = "创建订单异常,购买产品的游客人数不能小于1";
                return(result);
            }
            if (orderInfo.Ticket.ProductId <= 0)
            {
                result.Code    = "113014";
                result.Message = "创建订单异常,购买产品的id不合法";
                return(result);
            }
            //验证OTA订单id是否已存在
            var tbl_Order = GetOrderBy(request.Body.OrderInfo.OrderOtaId);

            if (tbl_Order != null)
            {
                var tbl_OrderDetail = _orderDetailService.Get(tbl_Order.OrderNo);
                result.Code                 = "000000";
                result.Message              = "成功,重复提交订单";
                response.Body.OrderId       = tbl_Order.OrderNo;
                response.Body.OtaOrderId    = tbl_Order.OTAOrderNo;
                response.Body.CertificateNo = tbl_OrderDetail.CertificateNO;
                response.Body.Code          = tbl_OrderDetail.QRcode;
                response.Body.OrderStatus   = "OREDER_SUCCESS";
                return(result);
            }
            result.Status = true;
            return(result);
        }