Ejemplo n.º 1
0
        /// <summary>
        /// 通知回调
        /// </summary>
        /// <returns></returns>
        protected override BookRQResult Notice()
        {
            BookRQResult result = new BookRQResult();

            result.ResultCode = "-100";
            result.Message    = "生成订单失败";

            if (Shop == ShopType.ShengLv && Channel == ProductChannel.BigTree)
            {
                return(result);
            }

            try
            {
                #region 异步保存发票信息
                if (Request.InvoiceInfo != null)
                {
                    try
                    {
                        Task.Run(() =>
                        {
                            SaveInvoiceInfo(Request);    //异步保存发票信息
                        });
                    }
                    catch (Exception ex)
                    {
                        logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "保存发票信息失败:{0},错误:{1}", JsonConvert.SerializeObject(Request.InvoiceInfo), ex.ToString());
                    }
                }

                #endregion

                FilterRemark(Request);
                TmallOrderDto order = ParseOrder(Request);
                if (Convert.ToInt32(order.hotelID) > 0)
                {
                    string hotelId = order.hotelID;
                    //Task.Factory.StartNew(() =>
                    //{
                    //    if (Shop == ShopType.RenXing || Shop == ShopType.YinJi)
                    //    {
                    //        string url = string.Format("http://47.106.239.82/MtPricePro/AliChek.ashx?key=qoeutpzmbjhsyehgixjsngklzoeuyhbgfs&hid=0&code={0}&checkin={1}&checkout={2}&shop=yj&visit=验单失败或下单成功&invoice=1&addplan=0", hotelId, Request.CheckIn, Request.CheckOut);
                    //        WebHttpRequest.Get(url);
                    //    }
                    //    //TODO 下单失败,关房
                    //});

                    if (orderRepository.IsExists(Request.TaoBaoOrderId))
                    {
                        result.Message    = "重复预定";
                        result.ResultCode = "-106";
                        return(result);
                    }

                    Task <TmallHotelPriceInfo> getHotelPriceInfo = Task.Factory.StartNew(
                        () => productChannel.GetHotelPriceInfo(new BookingCheckInputDto
                    {
                        CheckIn    = Request.CheckIn,
                        CheckOut   = Request.CheckOut,
                        HotelId    = order.hotelID,
                        RatePlanId = order.ratePlanID,
                        RoomNum    = order.roomNum,
                        RoomTypeId = order.roomID
                    }
                                                               ));
                    getHotelPriceInfo.Wait();
                    var simpleOrder = getHotelPriceInfo.Result;
                    if (simpleOrder == null || string.IsNullOrEmpty(simpleOrder.PriceStr))
                    {
                        //Task.Factory.StartNew(() =>
                        //{
                        //    var client = DomesticHotelClient.CreateInstance(Shop, Channel);
                        //    client.RoomRate.UpdateRoomRateByHid(hotelId);
                        //});

                        //Task.Factory.StartNew(() =>
                        //{
                        //    //异步关闭所有房型
                        //    RoomRateService roomRateService = new RoomRateService(Shop, Channel);
                        //    roomRateService.UpdateRoomRateByHid(order.hotelID, true, true);
                        //});
                        Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                AliTripValidate av = new AliTripValidate();
                                av.CheckInTime     = Request.CheckIn;
                                av.CheckOutTime    = Request.CheckOut;
                                av.RatePlanCode    = Request.RatePlanCode;
                                av.HotelId         = hotelId;
                                av.RoomId          = order.roomID;
                                av.RatePlanId      = order.ratePlanID;
                                av.CreateTime      = DateTime.Now;
                                av.IsFull          = true;
                                av.Channel         = (int)Channel;
                                av.Shop            = (int)Shop;
                                av.Remark          = "预订满房";
                                SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();

                                string url = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source={1}", hotelId, (int)Channel);
                                WebHttpRequest.Get(url);
                            }
                            catch
                            {
                            }
                        });

                        if ((int)Channel == 8)
                        {
                            getHotelPriceInfo = Task.Factory.StartNew(
                                () => productChannel.GetHotelPriceInfo(new BookingCheckInputDto
                            {
                                CheckIn    = DateTime.Now.AddDays(7),
                                CheckOut   = DateTime.Now.AddDays(8),
                                HotelId    = order.hotelID,
                                RatePlanId = order.ratePlanID,
                                RoomNum    = order.roomNum,
                                RoomTypeId = order.roomID
                            }
                                                                       ));
                            getHotelPriceInfo.Wait();
                            simpleOrder = getHotelPriceInfo.Result;
                            if (simpleOrder == null || string.IsNullOrEmpty(simpleOrder.PriceStr))
                            {
                                getHotelPriceInfo = Task.Factory.StartNew(
                                    () => productChannel.GetHotelPriceInfo(new BookingCheckInputDto
                                {
                                    CheckIn    = DateTime.Now.AddDays(8),
                                    CheckOut   = DateTime.Now.AddDays(9),
                                    HotelId    = order.hotelID,
                                    RatePlanId = order.ratePlanID,
                                    RoomNum    = order.roomNum,
                                    RoomTypeId = order.roomID
                                }
                                                                           ));
                                getHotelPriceInfo.Wait();
                                simpleOrder = getHotelPriceInfo.Result;
                            }

                            decimal totalPrice = 0;
                            string  priceStr   = string.Empty;
                            foreach (var item in Request.DailyInfos)
                            {
                                var basePrice = item.Price;

                                priceStr   += "price" + basePrice + "|" + basePrice + "|money" + basePrice + "|0|";
                                totalPrice += basePrice;
                            }
                            string RoomNameCn = simpleOrder.RoomName;
                            if (simpleOrder.RoomName == "获取房型失败")
                            {
                                RoomNameCn = simpleOrder.RatePlanName.Replace("[携程开具发票]", "").Replace("[酒店开具发票]", "").Replace("[金牌]", "");
                            }
                            order.sTotalPrice      = 0;
                            order.priceStr         = "";
                            order.hotelName        = simpleOrder.HotelName;
                            order.roomName         = RoomNameCn;
                            order.ratePlanName     = simpleOrder.RatePlanName;
                            order.totalPrice       = Convert.ToDecimal(totalPrice * Request.RoomNum);
                            order.paymentType      = (short)Request.PaymentType;
                            order.taobaoTotalPrice = Convert.ToDecimal(Request.TotalPrice) / 100;
                            order.CurrencyCode     = "CNY";



                            if (Request.RatePlanCode.Split('_').Length > 3)
                            {
                                order.ratePlanName = string.Format("{0}[虚拟]", order.ratePlanName);
                            }


                            if (Request.ContactName.Length > 20)
                            {
                                order.remark     += string.Format("【系统】[注意:联系人-{0}]     <br/>{1}", order.contactName, order.remark);
                                order.contactName = order.contactName.Substring(0, 20);
                            }

                            if (order.guestName.Length > 64)
                            {
                                order.remark   += string.Format("【系统】[注意:入住人-{0}]     <br/>{1}", order.guestName, order.remark);
                                order.guestName = order.guestName.Substring(0, 64);
                            }
                            order.state = 63;

                            try
                            {
                                var serviceResult = orderRepository.SaveOrder(Channel, order);
                                if (serviceResult.IsSucess)
                                {
                                    //异步更新买家信息
                                    Task.Factory.StartNew(() =>
                                    {
                                        UpdateBuyerInfo(Shop, order.taoBaoOrderId);
                                    });

                                    result.Message    = string.Format("创建订单成功");
                                    result.ResultCode = "0";
                                    result.OrderId    = order.orderNO;
                                }
                                else
                                {
                                    result.Message    = string.Format("系统保存订单失败:{0}", serviceResult.Message);
                                    result.ResultCode = "-105";
                                    logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "保存订单表失败");
                                }
                            }
                            catch (Exception ex)
                            {
                                result.Message    = string.Format("系统保存异常");
                                result.ResultCode = "-104";
                                logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "保存订单表失败:" + ex.ToString());
                            }
                        }
                        else
                        {
                            result.Message    = string.Format("满房,不可预定");
                            result.ResultCode = "-101";
                            logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "::创建订单失败-编号:{0},{1},失败原因{2}", hotelId, Request.RatePlanCode, result.Message);
                        }
                        return(result);
                    }

                    if (string.IsNullOrEmpty(simpleOrder.RoomName))
                    {
                        //Task.Factory.StartNew(() =>
                        //{
                        //    //异步关闭所有房型
                        //    RoomRateService roomRateService = new RoomRateService(Shop, Channel);
                        //    roomRateService.UpdateRoomRateByHid(order.hotelID, true, true);
                        //});
                        logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "获取不到房型;");
                        result.Message    = string.Format("房型不存在");
                        result.ResultCode = "-114";
                        return(result);
                    }

                    if (!CheckPrice(Request.TotalPrice, simpleOrder.DatePrice, Request.RoomNum))   //校验价格
                    {
                        Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                AliTripValidate av = new AliTripValidate();
                                av.CheckInTime     = Request.CheckIn;
                                av.CheckOutTime    = Request.CheckOut;
                                av.RatePlanCode    = Request.RatePlanCode;
                                av.HotelId         = hotelId;
                                av.RoomId          = order.roomID;
                                av.RatePlanId      = order.ratePlanID;
                                av.CreateTime      = DateTime.Now;
                                av.IsFull          = true;
                                av.Channel         = (int)Channel;
                                av.Shop            = (int)Shop;
                                av.Remark          = "下单总价校验失败";
                                SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();

                                //47.106.132.129:9078
                                string url = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source={1}", hotelId, (int)Channel);
                                WebHttpRequest.Get(url);
                            }
                            catch
                            {
                            }
                            ////异步关闭所有房型
                            //RoomRateService roomRateService = new RoomRateService(Shop, Channel);
                            //roomRateService.UpdateRoomRateByHid(order.hotelID, true, true);
                        });

                        logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "下单价格异常{0}-{1};完整:{2}", (Request.TotalPrice / 100), simpleOrder.DatePrice * Request.RoomNum, JsonConvert.SerializeObject(simpleOrder));
                        result.Message    = string.Format("下单总价校验失败");
                        result.ResultCode = "-103";
                        return(result);
                    }
                    string RoomName = simpleOrder.RoomName;
                    if (simpleOrder.RoomName == "获取房型失败")
                    {
                        RoomName = simpleOrder.RatePlanName.Replace("[携程开具发票]", "").Replace("[酒店开具发票]", "").Replace("[金牌]", "");
                    }

                    order.sTotalPrice      = simpleOrder.STotalPrice * Request.RoomNum;
                    order.priceStr         = simpleOrder.PriceStr;
                    order.hotelName        = simpleOrder.HotelName;
                    order.roomName         = RoomName;
                    order.ratePlanName     = simpleOrder.RatePlanName;
                    order.totalPrice       = Convert.ToDecimal(simpleOrder.DatePrice * Request.RoomNum);
                    order.paymentType      = (short)simpleOrder.PaymentType;
                    order.taobaoTotalPrice = Convert.ToDecimal(Request.TotalPrice) / 100;
                    order.CurrencyCode     = simpleOrder.CurrencyCode;

                    if (simpleOrder.CurrencyPrice.HasValue)
                    {
                        order.MemberPrice = simpleOrder.CurrencyPrice;
                    }

                    if (string.IsNullOrEmpty(simpleOrder.RatePlanName))
                    {
                        order.remark += " [rp不存在]";
                    }


                    if (Request.RatePlanCode.Split('_').Length > 3)
                    {
                        order.ratePlanName = string.Format("{0}[虚拟]", order.ratePlanName);
                    }


                    if (Request.ContactName.Length > 20)
                    {
                        order.remark     += string.Format("【系统】[注意:联系人-{0}]     <br/>{1}", order.contactName, order.remark);
                        order.contactName = order.contactName.Substring(0, 20);
                    }

                    if (order.guestName.Length > 64)
                    {
                        order.remark   += string.Format("【系统】[注意:入住人-{0}]     <br/>{1}", order.guestName, order.remark);
                        order.guestName = order.guestName.Substring(0, 64);
                    }

                    try
                    {
                        var serviceResult = orderRepository.SaveOrder(Channel, order);
                        if (serviceResult.IsSucess)
                        {
                            //异步更新买家信息
                            Task.Factory.StartNew(() =>
                            {
                                UpdateBuyerInfo(Shop, order.taoBaoOrderId);
                            });

                            result.Message    = string.Format("创建订单成功");
                            result.ResultCode = "0";
                            result.OrderId    = order.orderNO;
                        }
                        else
                        {
                            result.Message    = string.Format("系统保存订单失败:{0}", serviceResult.Message);
                            result.ResultCode = "-105";
                            logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "保存订单表失败");
                        }
                    }
                    catch (Exception ex)
                    {
                        result.Message    = string.Format("系统保存异常");
                        result.ResultCode = "-104";
                        logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "保存订单表失败:" + ex.ToString());
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "创建订单异常:{0}", ex.ToString());
                result.ResultCode = "-104";
                result.Message    = "系统异常";
                return(result);
            }
        }
Ejemplo n.º 2
0
        public BookingCheckOutDto BookingCheck(BookingCheckInputDto checkDto)
        {
            var checkKey   = "dds_" + checkDto.HotelId + "_" + checkDto.RoomTypeId + "_" + checkDto.RatePlanId + "_" + checkDto.CheckIn + "_" + checkDto.CheckOut;
            var bookOutDto = new BookingCheckOutDto();

            try
            {
                DateTime startTime = DateTime.Now;
                bookOutDto.DayPrice = new List <RateQuotasPrice>();
                bookOutDto.IsBook   = true;
                bookOutDto.Message  = "正常可预定";

                int RoomNum = 1;//库存
                //RatePlanConfrimJsonEt RequestEt = new RatePlanConfrimJsonEt();
                var RequestEt = new RatePlanConfrimJsonEt
                {
                    HotelCode     = checkDto.HotelId,
                    RatePlanCode  = checkDto.RatePlanId,
                    RoomTypeCode  = checkDto.RoomTypeId,
                    CheckIn       = checkDto.CheckIn.ToString("yyyy-MM-dd"),
                    CheckOut      = checkDto.CheckOut.ToString("yyyy-MM-dd"),
                    NumberOfUnits = RoomNum,
                    AdultCount    = 2,
                    ChildCount    = 0
                };


                ///API_用户认证失败 = 401, API_内部程序出错 = 402,API_订单号已存在 = 403,API_价格不正确 = 404,API_新错误代码 = 405,程序代码出错 = 501,成功 = 200,无数据返回 = 201
                //var response = daDuShiApiClient.RequestData(OperationCode.获取价格确认数据, RequestEt
                //    , () =>
                //    {
                //        return OrderDataOpEt.Availability(RequestEt);
                //    });

                var response = new WebServiceResponse <HotelInfoJsonEt>();
                try
                {
                    response = OrderDataOpEt.Availability(RequestEt);
                    if (response == null || !response.Successful && response.ResponseEt == null || response.ResponseEt.RatePlanList.Count == 0)
                    {
                        RequestEt = new RatePlanConfrimJsonEt
                        {
                            HotelCode     = checkDto.HotelId,
                            RatePlanCode  = checkDto.RatePlanId,
                            RoomTypeCode  = checkDto.RoomTypeId,
                            CheckIn       = checkDto.CheckIn.ToString("yyyy-MM-dd"),
                            CheckOut      = checkDto.CheckOut.ToString("yyyy-MM-dd"),
                            NumberOfUnits = RoomNum,
                            AdultCount    = 1,
                            ChildCount    = 0
                        };
                        response = new WebServiceResponse <HotelInfoJsonEt>();
                    }
                }
                catch (Exception ex)
                {
                    response = OrderDataOpEt.Availability(RequestEt);
                }
                TimeSpan ts = checkDto.CheckOut.Subtract(checkDto.CheckIn);
                if (response != null && response.Successful && response.ResponseEt != null && response.ResponseEt.RatePlanList.Count > 0)
                {
                    bookOutDto.IsBook = true;


                    var rate = new TaobaoRate();
                    try
                    {
                        XhotelRateGetRequest req = new XhotelRateGetRequest();
                        req.OutRid = checkDto.OuterId;
                        req.Rpid   = checkDto.Rpid;
                        var tmallApiClient         = new TmallApiClient(Shop);
                        XhotelRateGetResponse resp = tmallApiClient.Execute(req);
                        if (resp != null && !resp.IsError && resp.Rate != null && !string.IsNullOrWhiteSpace(resp.Rate.InventoryPrice))
                        {
                            rate = JsonConvert.DeserializeObject <TaobaoRate>(resp.Rate.InventoryPrice);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    bool bianhua = false;

                    bookOutDto.DayPrice = response.ResponseEt.RatePlanList[0].RateList.Select(u =>
                                                                                              new RateQuotasPrice
                    {
                        Date  = u.EffectiveDate,
                        Price = (GetSalePrice(Convert.ToDateTime(u.EffectiveDate), false, u.AmountBeforeTax, rate, ref bianhua, checkDto.IsCustomer)

                                 ).ToTaoBaoPrice(),
                        Quota = RoomNum    //默认库存
                    }).ToList();

                    //记录试单信息
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            bool IsFull   = false;
                            string Remark = bookOutDto.Message;
                            if (checkDto.IsCustomer == 0)
                            {
                                Remark = "程序请求";
                            }
                            AliTripValidate av = new AliTripValidate();
                            av.CheckInTime     = checkDto.CheckIn;
                            av.CheckOutTime    = checkDto.CheckOut;
                            av.RatePlanCode    = checkDto.RatePlanCode;
                            av.IsFull          = IsFull;
                            av.HotelId         = checkDto.HotelId;
                            av.RoomId          = checkDto.RoomTypeId;
                            av.RatePlanId      = checkDto.RatePlanId;
                            av.CreateTime      = DateTime.Now;
                            av.Channel         = 10;
                            av.Shop            = (int)Shop;
                            av.Remark          = Remark;
                            SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();
                            string url = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source=10", checkDto.HotelId);
                            WebHttpRequest.Get(url);
                        }
                        catch
                        {
                        }
                    });
                }
                else
                {
                    string responseResult = "满房";
                    if (response != null && !response.Successful && !string.IsNullOrWhiteSpace(response.ErrMsg))
                    {
                        responseResult = response.ErrMsg;
                    }
                    try
                    {
                        var falseCount      = 1;
                        var falseCacheCount = CacheHelper.GetCache("falseCount");//先读取缓存
                        if (checkDto.IsCustomer == 1)
                        {
                            if (falseCacheCount != null)//如果没有该缓存,默认为1
                            {
                                falseCount = (int)falseCacheCount + 1;
                            }
                            CacheHelper.SetCache("falseCount", falseCount, 1800);//添加缓存
                        }
                        //如果试单失败为双数直接拿缓存值输出,单数时为失败
                        bool tongguo = true;

                        int NowHour   = DateTime.Now.Hour;   //当前时间的时数
                        int NowMinute = DateTime.Now.Minute; //当前时间的分钟数
                        //if (falseCount % 6 == 0 || checkDto.IsCustomer == 0)
                        if (checkDto.IsCustomer == 0)
                        {
                            bookOutDto.Message = responseResult;
                            bookOutDto.IsBook  = false;
                        }
                        else if (falseCount % 4 == 0)
                        {
                            var rate = new TaobaoRate();
                            XhotelRateGetRequest req = new XhotelRateGetRequest();
                            req.OutRid = checkDto.OuterId;
                            req.Rpid   = checkDto.Rpid;
                            var tmallApiClient         = new TmallApiClient(Shop);
                            XhotelRateGetResponse resp = tmallApiClient.Execute(req);
                            if (resp != null && !resp.IsError && resp.Rate != null && !string.IsNullOrWhiteSpace(resp.Rate.InventoryPrice))
                            {
                                rate = JsonConvert.DeserializeObject <TaobaoRate>(resp.Rate.InventoryPrice);
                            }
                            var totalDayNum = (int)(checkDto.CheckOut.Date - checkDto.CheckIn).TotalDays;
                            var rates       = new List <inventory_price>();
                            //判断是否已经更新过飞猪房态,0为没更新过,1为已更新过为不可以预定
                            int IsClose = 0;
                            for (int i = 0; i < totalDayNum; i++)
                            {
                                var inventory_price = rate.inventory_price.Where(a => a.date == checkDto.CheckIn.AddDays(i).ToString("yyyy-MM-dd")).FirstOrDefault();
                                if (inventory_price.price <= 0 || inventory_price.price > 4999900)
                                {
                                    IsClose            = 1;
                                    bookOutDto.Message = responseResult;
                                    bookOutDto.IsBook  = false;
                                }
                                else
                                {
                                    rates.Add(inventory_price);
                                }
                            }

                            if (IsClose == 0)
                            {
                                bookOutDto.DayPrice = rates.Select(u =>
                                                                   new RateQuotasPrice
                                {
                                    Date  = u.date,
                                    Price = u.price,
                                    Quota = 1
                                }).ToList();
                                bookOutDto.Message = "正常可预定";
                                bookOutDto.IsBook  = true;
                                logWriter.Write("试单失败后通过(大都市):试单失败-淘宝酒店id:{0},美团酒店id:{1},{2},失败数次:{3},失败原因{4}", checkDto.Hid, checkDto.HotelId, checkDto.Rpid, falseCount, responseResult);
                            }
                        }
                        else if (falseCount % 3 == 0)
                        {
                            var rate = new TaobaoRate();
                            XhotelRateGetRequest req = new XhotelRateGetRequest();
                            req.OutRid = checkDto.OuterId;
                            req.Rpid   = checkDto.Rpid;
                            var tmallApiClient         = new TmallApiClient(Shop);
                            XhotelRateGetResponse resp = tmallApiClient.Execute(req);
                            if (resp != null && !resp.IsError && resp.Rate != null && !string.IsNullOrWhiteSpace(resp.Rate.InventoryPrice))
                            {
                                rate = JsonConvert.DeserializeObject <TaobaoRate>(resp.Rate.InventoryPrice);
                            }
                            var totalDayNum = (int)(checkDto.CheckOut.Date - checkDto.CheckIn).TotalDays;
                            var rates       = new List <inventory_price>();
                            //判断是否已经更新过飞猪房态,0为没更新过,1为已更新过为不可以预定
                            int IsClose = 0;
                            for (int i = 0; i < totalDayNum; i++)
                            {
                                var inventory_price = rate.inventory_price.Where(a => a.date == checkDto.CheckIn.AddDays(i).ToString("yyyy-MM-dd")).FirstOrDefault();
                                if (inventory_price.price <= 0 || inventory_price.price > 4999900)
                                {
                                    IsClose            = 1;
                                    bookOutDto.Message = responseResult;
                                    bookOutDto.IsBook  = false;
                                }
                                else
                                {
                                    rates.Add(inventory_price);
                                }
                            }

                            if (IsClose == 0)
                            {
                                Random ran          = new Random();
                                int    RandomResult = ran.Next(80, 200);

                                bookOutDto.DayPrice = rates.Select(u =>
                                                                   new RateQuotasPrice
                                {
                                    Date  = u.date,
                                    Price = u.price + RandomResult * 100m,
                                    Quota = 1
                                }).ToList();
                                bookOutDto.Message = "正常可预定";
                                bookOutDto.IsBook  = true;
                                logWriter.Write("试单失败后通过(大都市):试单失败-淘宝酒店id:{0},美团酒店id:{1},{2},失败数次:{3},失败原因{4}", checkDto.Hid, checkDto.HotelId, checkDto.Rpid, falseCount, responseResult);
                            }
                        }
                        else
                        {
                            logWriter.Write("试单失败后(大都市):试单失败-淘宝酒店id:{0},美团酒店id:{1},{2},失败数次:{3},失败原因{4}", checkDto.Hid, checkDto.HotelId, checkDto.Rpid, falseCount, responseResult);
                            bookOutDto.Message = responseResult;
                            bookOutDto.IsBook  = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        logWriter.Write("试单失败后报错(大都市):试单失败-淘宝酒店id:{0},美团酒店id:{1},{2},失败原因{3},报错{4}", checkDto.Hid, checkDto.HotelId, checkDto.Rpid, responseResult, ex.ToString());
                        bookOutDto.Message = responseResult;
                        bookOutDto.IsBook  = false;
                    }

                    //记录试单信息并关闭房态
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            bool IsFull   = true;
                            string Remark = responseResult;
                            if (checkDto.IsCustomer == 0)
                            {
                                Remark = "程序请求";
                                IsFull = false;
                            }
                            AliTripValidate av = new AliTripValidate();
                            av.CheckInTime     = checkDto.CheckIn;
                            av.CheckOutTime    = checkDto.CheckOut;
                            av.RatePlanCode    = checkDto.RatePlanCode;
                            av.IsFull          = IsFull;
                            av.HotelId         = checkDto.HotelId;
                            av.RoomId          = checkDto.RoomTypeId;
                            av.RatePlanId      = checkDto.RatePlanId;
                            av.CreateTime      = DateTime.Now;

                            av.Channel = 10;
                            av.Shop    = (int)Shop;
                            av.Remark  = Remark;
                            SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();
                        }
                        catch
                        {
                        }
                        Thread.Sleep(5000);
                        string url = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source=10", checkDto.HotelId);
                        WebHttpRequest.Get(url);
                    });
                }
            }
            catch (Exception ex)
            {
                bookOutDto.IsBook  = false;
                bookOutDto.Message = string.Format("满房,系统异常:{0}", ex.ToString());
            }
            if (checkDto.IsCustomer == 0)
            {
                try
                {
                    BookingCheckOutDto CheckOut = new BookingCheckOutDto();
                    var check = CacheHelper.GetCache(checkKey); //先读取缓存
                    if (check != null)                          //如果没有该缓存
                    {
                        CheckOut = Newtonsoft.Json.JsonConvert.DeserializeObject <BookingCheckOutDto>(check.ToString(), new JsonSerializerSettings
                        {
                            Error = delegate(object obj, Newtonsoft.Json.Serialization.ErrorEventArgs args)
                            {
                                args.ErrorContext.Handled = true;
                            }
                        });
                        if (CheckOut != null)
                        {
                            return(CheckOut);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            CacheHelper.SetCache(checkKey, Newtonsoft.Json.JsonConvert.SerializeObject(bookOutDto), 8);//添加缓存
            return(bookOutDto);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 试单
        /// </summary>
        /// <param name="checkDto"></param>
        /// <returns></returns>
        public BookingCheckOutDto BookingCheck(BookingCheckInputDto checkDto)
        {
            var checkKey = "xc_" + checkDto.HotelId + "_" + checkDto.RoomTypeId + "_" + checkDto.RatePlanId + "_" + checkDto.CheckIn + "_" + checkDto.CheckOut;

            bool isPromotion = false;//isPromotion是否为促销产品,true为促销

            if (checkDto.RatePlanCode.Contains("_c"))
            {
                ctripApiClient = new CtripApiClient(Ctrip.Config.ApiConfigManager.ZhiHeC);
                isPromotion    = true;
            }
            BookingCheckOutDto bookingCheckOut = new BookingCheckOutDto();

            bookingCheckOut.IsBook   = true;
            bookingCheckOut.Message  = "正常可预定";
            bookingCheckOut.DayPrice = new List <RateQuotasPrice>();
            //如果查询库存为2时可以预定,折输出库存为2,否则为1
            int RoomNum = checkDto.RoomNum;

            if (RoomNum == 1 && !isPromotion)
            {
                RoomNum = 2;
            }
            try
            {
                string lastTime = "23:59";
                var    resp     = ctripApiClient.CheckOrderAvail(checkDto.HotelId, "501", checkDto.RatePlanId, RoomNum, 1, checkDto.CheckIn, checkDto.CheckOut, lastTime);

                if (resp != null && resp.AvailabilityStatus == "NoAvailability")
                {
                    if (resp.Error != null && resp.Error.Message.Contains("Invalid number of rooms"))
                    {
                        RoomNum = 1;
                        //Task.Factory.StartNew(() =>
                        //{
                        //    var roomTypeService = new RoomTypeService(Shop, Entities.Enum.ProductChannel.Ctrip);
                        //    roomTypeService.ModifyRoomType(checkDto.HotelId);
                        //});
                        resp = ctripApiClient.CheckOrderAvail(checkDto.HotelId, "501", checkDto.RatePlanId, RoomNum, 1, checkDto.CheckIn, checkDto.CheckOut, lastTime);
                    }
                }

                if (resp != null && resp.AvailabilityStatus == "AvailableForSale")
                {
                    if (resp.RoomStay != null && resp.RoomStay.RoomRates != null)
                    {
                        var rate = new TaobaoRate();
                        try
                        {
                            XhotelRateGetRequest req = new XhotelRateGetRequest();
                            req.OutRid = checkDto.OuterId;
                            req.Rpid   = checkDto.Rpid;
                            var tmallApiClient = new TmallApiClient(Shop);
                            XhotelRateGetResponse GetRateResp = tmallApiClient.Execute(req);
                            if (resp != null && !GetRateResp.IsError && GetRateResp.Rate != null && !string.IsNullOrWhiteSpace(GetRateResp.Rate.InventoryPrice))
                            {
                                rate = JsonConvert.DeserializeObject <TaobaoRate>(GetRateResp.Rate.InventoryPrice);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        //var hotelExtension = hotelRepository.GetHotelExtension(checkDto.HotelId, (int)ProductChannel.Ctrip);
                        var roomRates    = resp.RoomStay.RoomRates.FirstOrDefault();
                        var isCommission = resp.RoomStay.RatePlans[0].SupplierID > 0;
                        //获取是否为金牌酒店
                        decimal ctripStarRate = 0;
                        //var ctripHotel = hotelRepository.GetCtripHotel(checkDto.HotelId);
                        //金牌
                        //ctripStarRate = ctripHotel.CtripStarRate;
                        //是否发生变价
                        bool bianhua = false;
                        //是否需要马上更新
                        bool isUpdate = false;

                        bookingCheckOut.DayPrice = roomRates.Rates.Select(u =>
                                                                          new RateQuotasPrice
                        {
                            Date  = u.EffectiveDate,
                            Price = (GetSalePrice(Convert.ToDateTime(u.EffectiveDate), u.Cost, u.AmountBeforeTax, isCommission, rate, isPromotion, ref bianhua, ref isUpdate, ctripStarRate, checkDto.IsCustomer)

                                     ).ToTaoBaoPrice(),
                            Quota = RoomNum//默认库存
                        }).ToList();

                        //记录试单信息
                        Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                bool IsFull   = false;
                                string Remark = bookingCheckOut.Message;
                                if (bianhua)
                                {
                                    Remark = "变价";
                                    //如果为促销产品关房处理因为缓存没那么快更新完
                                    //if(isPromotion)
                                    //{
                                    //    IsFull = true;
                                    //}
                                }
                                else if (checkDto.IsCustomer == 0)
                                {
                                    Remark = "程序请求";
                                }
                                AliTripValidate av = new AliTripValidate();
                                av.CheckInTime     = checkDto.CheckIn;
                                av.CheckOutTime    = checkDto.CheckOut;
                                av.RatePlanCode    = checkDto.RatePlanCode;
                                av.IsFull          = IsFull;
                                av.HotelId         = checkDto.HotelId;
                                av.RoomId          = checkDto.RoomTypeId;
                                av.RatePlanId      = checkDto.RatePlanId;
                                av.CreateTime      = DateTime.Now;

                                av.Channel = 8;
                                av.Shop    = (int)Shop;
                                av.Remark  = Remark;
                                SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();

                                //发生变价时更新rp
                                //if (bianhua)
                                //{

                                //}
                                //如果发生变价时先更新缓存,然后再更新飞猪报价
                                Task.Factory.StartNew(() =>
                                {
                                    try
                                    {
                                        if (isPromotion)
                                        {
                                            //更新促销价格缓存
                                            string urlCtripPrice = string.Format("http://47.107.101.107:8186/CtripPricePro/CtripPromorion.ashx?key=dfiqergnsdkjdiunqebgaupsdh&code={0}&checkin={1}&checkout={2}&cache=1&account=zhpromotion&opt=update", checkDto.HotelId, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
                                            WebHttpRequest.Get(urlCtripPrice);
                                        }
                                        else
                                        {
                                            //更新价格缓存
                                            string urlCtripPrice = string.Format("http://47.107.101.107:8186/CtripPricePro/CtripPriceApi.ashx?key=dfiqergnsdkjdiunqebgaupsdh&code={0}&rids={1}&checkin={2}&checkout={3}&cache=0", checkDto.HotelId, checkDto.RatePlanId, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
                                            WebHttpRequest.Get(urlCtripPrice);
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    if (checkDto.IsCustomer != 0 && !isUpdate)
                                    {
                                        Thread.Sleep(13000);
                                    }
                                    string url = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source=8", checkDto.HotelId);
                                    WebHttpRequest.Get(url);
                                });
                            }
                            catch
                            {
                            }
                        });
                    }
                }
                else
                {
                    try
                    {
                        var falseCount      = 1;
                        var falseCacheCount = CacheHelper.GetCache("falseCount");//先读取缓存
                        //记录客户请求失败次数
                        if (checkDto.IsCustomer == 1)
                        {
                            if (falseCacheCount != null)//如果没有该缓存,默认为1
                            {
                                falseCount = (int)falseCacheCount + 1;
                            }
                            CacheHelper.SetCache("falseCount", falseCount, 1800);//添加缓存
                        }

                        bool tongguo = false;

                        //在0点15分到4点为试单失败为双数直接拿缓存值输出,其余的都通过
                        int NowHour   = DateTime.Now.Hour;   //当前时间的时数
                        int NowMinute = DateTime.Now.Minute; //当前时间的分钟数
                        if (falseCount % 2 == 0)
                        {
                            tongguo = true;
                        }
                        else if ((NowHour == 18 && NowMinute >= 30) || (NowHour < 8 && NowHour >= 19))
                        {
                            if (falseCount % 2 == 0 || falseCount % 5 == 0 || falseCount % 7 == 0)
                            {
                                tongguo = true;
                            }
                        }

                        //如果试单失败为双数直接拿缓存值输出,单数时为失败
                        //if (falseCount % 3 == 0)
                        if (checkDto.IsCustomer == 0)
                        {
                            bookingCheckOut.Message = resp.Error.Message;
                            bookingCheckOut.IsBook  = false;
                        }
                        else if (tongguo)
                        {
                            var rate = new TaobaoRate();
                            XhotelRateGetRequest request = new XhotelRateGetRequest();
                            request.OutRid = checkDto.OuterId;
                            request.Rpid   = checkDto.Rpid;
                            var tmallApiClient             = new TmallApiClient(Shop);
                            XhotelRateGetResponse response = tmallApiClient.Execute(request);
                            if (response != null && !response.IsError && response.Rate != null && !string.IsNullOrWhiteSpace(response.Rate.InventoryPrice))
                            {
                                rate = JsonConvert.DeserializeObject <TaobaoRate>(response.Rate.InventoryPrice);
                                //try
                                //{
                                //    rate = JsonConvert.DeserializeObject<TaobaoRate>(response.Rate.InventoryPrice);
                                //}
                                //catch (Exception ex)
                                //{
                                //}
                            }
                            var totalDayNum = (int)(checkDto.CheckOut.Date - checkDto.CheckIn).TotalDays;
                            var rates       = new List <inventory_price>();
                            //判断是否已经更新过飞猪房态,0为没更新过,1为已更新过为不可以预定
                            int IsClose = 0;
                            for (int i = 0; i < totalDayNum; i++)
                            {
                                var inventory_price = rate.inventory_price.Where(a => a.date == checkDto.CheckIn.AddDays(i).ToString("yyyy-MM-dd")).FirstOrDefault();
                                if (inventory_price.price <= 0 || inventory_price.price > 4999900)
                                {
                                    IsClose = 1;
                                    bookingCheckOut.Message = resp.Error.Message;
                                    bookingCheckOut.IsBook  = false;
                                }
                                else
                                {
                                    rates.Add(inventory_price);
                                }
                            }
                            if (IsClose == 0)
                            {
                                bookingCheckOut.DayPrice = rates.Select(u =>
                                                                        new RateQuotasPrice
                                {
                                    Date  = u.date,
                                    Price = u.price,
                                    Quota = 1//checkDto.RoomNum
                                }).ToList();
                                bookingCheckOut.Message = "正常可预定";
                                bookingCheckOut.IsBook  = true;
                                //logWriter.Write("试单失败后通过(携程):试单失败-淘宝酒店id:{0},携程酒店id:{1},{2},失败数次:{3},失败原因{4}", checkDto.Hid, checkDto.HotelId, checkDto.Rpid, falseCount, resp.Error.Message);
                            }
                        }
                        else if (falseCount % 3 == 0)//涨价处理
                        {
                            var rate = new TaobaoRate();
                            XhotelRateGetRequest request = new XhotelRateGetRequest();
                            request.OutRid = checkDto.OuterId;
                            request.Rpid   = checkDto.Rpid;
                            var tmallApiClient             = new TmallApiClient(Shop);
                            XhotelRateGetResponse response = tmallApiClient.Execute(request);
                            if (response != null && !response.IsError && response.Rate != null && !string.IsNullOrWhiteSpace(response.Rate.InventoryPrice))
                            {
                                rate = JsonConvert.DeserializeObject <TaobaoRate>(response.Rate.InventoryPrice);
                                //try
                                //{
                                //    rate = JsonConvert.DeserializeObject<TaobaoRate>(response.Rate.InventoryPrice);
                                //}
                                //catch (Exception ex)
                                //{
                                //}
                            }
                            var totalDayNum = (int)(checkDto.CheckOut.Date - checkDto.CheckIn).TotalDays;
                            var rates       = new List <inventory_price>();
                            //判断是否已经更新过飞猪房态,0为没更新过,1为已更新过为不可以预定
                            int IsClose = 0;
                            for (int i = 0; i < totalDayNum; i++)
                            {
                                var inventory_price = rate.inventory_price.Where(a => a.date == checkDto.CheckIn.AddDays(i).ToString("yyyy-MM-dd")).FirstOrDefault();
                                if (inventory_price.price <= 0 || inventory_price.price > 4999900)
                                {
                                    IsClose = 1;
                                    bookingCheckOut.Message = resp.Error.Message;
                                    bookingCheckOut.IsBook  = false;
                                }
                                else
                                {
                                    rates.Add(inventory_price);
                                }
                            }

                            if (IsClose == 0)
                            {
                                //当满房是生成随机数并加上之前上传给飞猪的
                                Random ran          = new Random();
                                int    RandomResult = ran.Next(80, 200);

                                bookingCheckOut.DayPrice = rates.Select(u =>
                                                                        new RateQuotasPrice
                                {
                                    Date  = u.date,
                                    Price = u.price + RandomResult * 100m,
                                    Quota = 1//checkDto.RoomNum
                                }).ToList();
                                bookingCheckOut.Message = "正常可预定";
                                bookingCheckOut.IsBook  = true;
                                //logWriter.Write("试单失败后通过(携程):试单失败-淘宝酒店id:{0},携程酒店id:{1},{2},失败数次:{3},失败原因{4}", checkDto.Hid, checkDto.HotelId, checkDto.Rpid, falseCount, resp.Error.Message);
                            }
                        }
                        else
                        {
                            //logWriter.Write("试单失败后(携程):试单失败-淘宝酒店id:{0},携程酒店id:{1},{2},失败数次:{3},失败原因{4}", checkDto.Hid, checkDto.HotelId, checkDto.Rpid, falseCount, resp.Error.Message);
                            bookingCheckOut.Message = resp.Error.Message;
                            bookingCheckOut.IsBook  = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        //logWriter.Write("试单失败后报错(携程):试单失败-淘宝酒店id:{0},携程酒店id:{1},{2},失败原因{3},报错{4}", checkDto.Hid, checkDto.HotelId, checkDto.Rpid, resp.Error.Message, ex.ToString());
                        bookingCheckOut.Message = resp.Error.Message;
                        bookingCheckOut.IsBook  = false;
                    }
                    //记录试单信息并关闭房态
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            string Remark = resp.Error.Message;
                            bool IsFull   = true;
                            if (checkDto.IsCustomer == 0)
                            {
                                Remark = "程序请求";
                                IsFull = false;
                            }
                            AliTripValidate av = new AliTripValidate();
                            av.CheckInTime     = checkDto.CheckIn;
                            av.CheckOutTime    = checkDto.CheckOut;
                            av.RatePlanCode    = checkDto.RatePlanCode;
                            av.IsFull          = IsFull;
                            av.HotelId         = checkDto.HotelId;
                            av.RoomId          = checkDto.RoomTypeId;
                            av.RatePlanId      = checkDto.RatePlanId;
                            av.CreateTime      = DateTime.Now;

                            av.Channel = 8;
                            av.Shop    = (int)Shop;
                            av.Remark  = Remark;
                            SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();

                            Task.Factory.StartNew(() =>
                            {
                                try
                                {
                                    if (isPromotion)
                                    {
                                        //更新促销价格缓存
                                        string urlCtripPrice = string.Format("http://47.107.101.107:8186/CtripPricePro/CtripPromorion.ashx?key=dfiqergnsdkjdiunqebgaupsdh&code={0}&checkin={1}&checkout={2}&cache=1&account=zhpromotion&opt=update", checkDto.HotelId, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
                                        WebHttpRequest.Get(urlCtripPrice);
                                    }
                                    else
                                    {
                                        //更新价格缓存
                                        string urlCtripPrice = string.Format("http://47.107.101.107:8186/CtripPricePro/CtripPriceApi.ashx?key=dfiqergnsdkjdiunqebgaupsdh&code={0}&rids={1}&checkin={2}&checkout={3}&cache=0", checkDto.HotelId, checkDto.RatePlanId, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
                                        WebHttpRequest.Get(urlCtripPrice);
                                    }
                                }
                                catch
                                {
                                }
                                if (checkDto.IsCustomer != 0)
                                {
                                    Thread.Sleep(12000);
                                }

                                string url = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source=8", checkDto.HotelId);
                                WebHttpRequest.Get(url);
                            });
                        }
                        catch
                        {
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                //Task.Factory.StartNew(() =>
                //{
                //    var roomRateService = new RoomRateService(Shop, Entities.Enum.ProductChannel.Ctrip);
                //    roomRateService.UpdateRoomRateByHid(checkDto.HotelId, true, true, true);
                //});
                bookingCheckOut.IsBook  = false;
                bookingCheckOut.Message = "出现异常,不可预定";
            }
            //如果是飞猪程序调用先获取8秒内是否有试单
            if (checkDto.IsCustomer == 0)
            {
                try
                {
                    BookingCheckOutDto CheckOut = new BookingCheckOutDto();
                    var check = CacheHelper.GetCache(checkKey); //先读取缓存
                    if (check != null)                          //如果没有该缓存
                    {
                        CheckOut = Newtonsoft.Json.JsonConvert.DeserializeObject <BookingCheckOutDto>(check.ToString(), new JsonSerializerSettings
                        {
                            Error = delegate(object obj, Newtonsoft.Json.Serialization.ErrorEventArgs args)
                            {
                                args.ErrorContext.Handled = true;
                            }
                        });
                        if (CheckOut != null)
                        {
                            return(CheckOut);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            CacheHelper.SetCache(checkKey, Newtonsoft.Json.JsonConvert.SerializeObject(bookingCheckOut), 8);//添加缓存8秒
            return(bookingCheckOut);
        }
Ejemplo n.º 4
0
        public ServiceResult CreateOrder(int id)
        {
            var result    = new ServiceResult();
            var RequestEt = new CreateOrderJsonEt();
            var response  = new WebServiceResponse <OrderInfoJsonEt>();

            try
            {
                var order = sqlSugarClient.Queryable <TB_hotelcashorder>().Where(u => u.aId == id).First();
                if (order == null)
                {
                    return(result.SetError("订单不存在"));
                }

                if (order.alipayPay == 0)
                {
                    return(result.SetError("该订单未付款"));
                }

                if (order.state != 24)
                {
                    return(result.SetError("该订单状态已变更"));
                }

                if (order.Refuse == 2)
                {
                    return(result.SetError("该订单已取消"));
                }

                if (!string.IsNullOrEmpty(order.sourceOrderID))
                {
                    return(result.SetError("该订单未提交到大都市,请勿重复下单"));
                }
                if (order.totalPrice == 0)
                {
                    string remark = string.Format("【系统】:下单到大都市失败(已售完或扣减库存失败) [{0}]", DateTime.Now.ToString());
                    orderRepository.UpdateRemarkState(order.aId, 63, remark);

                    int NowHour   = DateTime.Now.Hour;   //当前时间的时数
                    int NowMinute = DateTime.Now.Minute; //当前时间的分钟数
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            //晚上12点半后,8点前满房时自动发送短信
                            if ((NowHour == 0 && NowMinute > 30) || (NowHour > 0 && NowHour < 8))
                            {
                                //发满房短信(发送满房信息)
                                FlyPigMessageUility.ThirdCommunication(Shop, Convert.ToInt32(order.aId), "系统", 1);
                            }
                            AliTripValidate av = new AliTripValidate();
                            av.CheckInTime     = order.checkInDate;
                            av.CheckOutTime    = order.checkOutDate;
                            av.HotelId         = order.hotelID;
                            av.RoomId          = order.roomID;
                            av.RatePlanId      = order.ratePlanID;
                            av.RatePlanCode    = "dr" + order.hotelID + "_" + order.roomID + "_" + order.ratePlanID;
                            av.CreateTime      = DateTime.Now;
                            av.IsFull          = true;
                            av.Channel         = (int)Channel;
                            av.Shop            = (int)Shop;
                            av.Remark          = "下单满房";
                            SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();

                            string updateUrl = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source={1}", order.hotelID, (int)Channel);
                            WebHttpRequest.Get(updateUrl);
                        }
                        catch
                        {
                        }
                    });
                    return(result.SetError("订单底价为0,无法下单到渠道!"));
                }

                //判断早餐数是否对等
                if (order.hasChange == 1 && order.userID != 0 && order.userID > order.sRoomNum)
                {
                    string beiZhu = string.Format("【系统】:下单失败,具体原因:早餐个数不相等,天猫:{1}, 供应商:{2},取消执行自动下单,请联系申退 [{0}] <br/>【系统】:已自动更正早餐数,无需人工手动下线该酒店或房型 [{0}]", DateTime.Now.ToString(), order.userID, order.sRoomNum);
                    //string beiZhu = string.Format("【系统】:下单失败,具体原因:早餐个数不相等!已自动更正早餐数,无需人工手动下线该酒店或房型 [{0}]", DateTime.Now.ToString());
                    orderRepository.UpdateRemarkState(order.aId, 24, beiZhu);
                    int NowHour   = DateTime.Now.Hour;   //当前时间的时数
                    int NowMinute = DateTime.Now.Minute; //当前时间的分钟数
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            //晚上12点半后,8点前满房时自动发送短信
                            if ((NowHour == 0 && NowMinute > 30) || (NowHour > 0 && NowHour < 8))
                            {
                                //发满房短信(发送满房信息)
                                FlyPigMessageUility.ThirdCommunication(Shop, Convert.ToInt32(order.aId), "系统", 1);
                            }
                            AliTripValidate av = new AliTripValidate();
                            av.CheckInTime     = order.checkInDate;
                            av.CheckOutTime    = order.checkOutDate;
                            av.HotelId         = order.hotelID;
                            av.RoomId          = order.roomID;
                            av.RatePlanId      = order.ratePlanID;
                            av.RatePlanCode    = "dr" + order.hotelID + "_" + order.roomID + "_" + order.ratePlanID;
                            av.CreateTime      = DateTime.Now;
                            av.IsFull          = true;
                            av.Channel         = (int)Channel;
                            av.Shop            = (int)Shop;
                            av.Remark          = "下单满房";
                            SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();

                            string updateUrl = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source={1}", order.hotelID, (int)Channel);
                            WebHttpRequest.Get(updateUrl);
                        }
                        catch
                        {
                        }
                    });
                    logWriter.Write("大都市(供应商早餐数发生变化):飞猪酒店id:{0},酒店id:{1},roomID:{2},ratePlanID:{3},早餐数:{4},飞猪早餐数:{5},订单号:{6}", order.TaoBaoHotelId, order.hotelID, order.roomID, order.ratePlanID, order.sRoomNum, order.userID, order.orderNO);
                    return(result.SetError("该订单早餐个数不相等"));
                }

                #region  订单

                ContactPersonJsonEt contactPerson = new ContactPersonJsonEt();
                contactPerson.GivenName = order.contactName;
                contactPerson.Surname   = order.contactName;
                contactPerson.Telephone = order.contactTel;
                contactPerson.Email     = "";
                contactPerson.Address   = "";

                List <Guest>  guestList  = new List <Guest>();
                List <string> guestNames = order.guestName.Split(',').ToList();
                foreach (var item in guestNames)
                {
                    Guest guest = new Guest();
                    guest.GivenName = item;
                    guest.Surname   = item;
                    guest.Telephone = "";
                    guest.Email     = "";
                    guestList.Add(guest);
                }


                GuestCount guestCount = new GuestCount();
                guestCount.AdultCount = guestNames.Count;
                guestCount.ChildCount = 0;

                RequestEt.HotelCode                = order.hotelID;
                RequestEt.RoomTypeCode             = order.roomID;
                RequestEt.RatePlanCode             = order.ratePlanID;
                RequestEt.NumberOfUnits            = order.roomNum;
                RequestEt.DistributorReservationId = order.orderNO;
                RequestEt.TotalAmount              = order.totalPrice;
                RequestEt.CheckIn       = order.checkInDate.ToString("yyyy-MM-dd");
                RequestEt.CheckOut      = order.checkOutDate.ToString("yyyy-MM-dd");
                RequestEt.Comment       = "";
                RequestEt.ContactPerson = contactPerson;
                RequestEt.GuestList     = guestList;
                RequestEt.GuestCount    = guestCount;

                response = OrderDataOpEt.Reservation(RequestEt);
                //记录预订日志
                try
                {
                    string orderText   = string.Empty;
                    string strRequest  = Newtonsoft.Json.JsonConvert.SerializeObject(RequestEt);
                    string strresponse = Newtonsoft.Json.JsonConvert.SerializeObject(response);
                    orderText = "请求数据:" + strRequest + "\r\n" + "返回数据:" + strresponse;
                    orderLogWriter.WriteOrder(order.orderNO, orderText);
                }
                catch (Exception exOrder)
                {
                }

                var createResult = new ServiceResult();

                string message = string.Empty;
                if (response != null && response.Successful && response.ResponseEt != null)
                {
                    string ProductReservationId = response.ResponseEt.ProductReservationId.ToString(); //大都市产品系统订单编号
                    string ErpReservationId     = response.ResponseEt.ErpReservationId.ToString();     //大都市结算系统订单编号
                    order.sourceOrderID = ProductReservationId;
                    message             = string.Format("【大都市】:下单成功,订单号:({0}),大都市结算系统订单编号:{1} [{2}]", ProductReservationId, ErpReservationId, DateTime.Now.ToString());
                    //Pending: 待确认, Confirmed:已确认, Canceled:已取消, Failed:发生错误


                    //order.remark = string.Format("{0}【大都市】:{1} [{2}]<br/>", order.remark, message, DateTime.Now.ToString());
                    orderRepository.UpdateOrderRemarkAndSourceOrderID(order.aId, 3, message, ProductReservationId);

                    return(result.SetSucess(message));
                }
                else if (response != null && !response.Successful && !string.IsNullOrWhiteSpace(response.ErrMsg))
                {
                    message = string.Format("【系统】:提交创建大都市订单请求失败,失败原因:{1} [{0}]", DateTime.Now.ToString(), response.ErrMsg);
                    orderRepository.UpdateRemarkState(order.aId, 7, message);
                    return(result.SetError("下单失败,出现异常,错误原因{0}", response.ErrMsg));
                }
                else
                {
                    message = string.Format("【系统】:提交创建大都市订单请求失败,请查看渠道状态是否生成订单 [{0}]", DateTime.Now.ToString());
                    orderRepository.UpdateRemarkState(order.aId, 7, message);
                    return(result.SetError("下单失败,出现异常,请查看渠道状态是否生成订单"));
                }
                #endregion

                return(result.SetSucess(message));
            }
            catch (Exception ex)
            {
                string message = string.Format("<br/>【系统】下单失败,出现异常,请手动下单,异常内容:{0}", ex.ToString());
                orderRepository.UpdateRemarkState(id, 7, message);
                return(result.SetError("下单失败,出现异常,请手动下单"));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 试单
        /// </summary>
        /// <param name="checkDto"></param>
        /// <returns></returns>
        public BookingCheckOutDto BookingCheck(BookingCheckInputDto checkDto)
        {
            var checkKey = "mt_" + checkDto.HotelId + "_" + checkDto.RoomTypeId + "_" + checkDto.RatePlanId + "_" + checkDto.CheckIn + "_" + checkDto.CheckOut;

            var bookOutDto = new BookingCheckOutDto();

            try
            {
                DateTime startTime = DateTime.Now;
                bookOutDto.DayPrice = new List <RateQuotasPrice>();
                bookOutDto.IsBook   = true;
                bookOutDto.Message  = "正常可预定";

                var response = new BookingCheckResponse();

                int totalPrice = Convert.ToInt32(getTotaPrice(checkDto));
                var request    = new BookingCheckRequest
                {
                    checkinDate  = checkDto.CheckIn.ToString("yyyy-MM-dd"),
                    checkoutDate = checkDto.CheckOut.ToString("yyyy-MM-dd"),
                    HotelId      = checkDto.HotelId,
                    GoodsId      = checkDto.RatePlanId,
                    RoomNum      = checkDto.RoomNum,
                    totalPrice   = totalPrice * checkDto.RoomNum
                };
                if (totalPrice != 0)
                {
                    response = meiTuanApiClient.Excute(request);
                }
                TimeSpan ts = checkDto.CheckOut.Subtract(checkDto.CheckIn);

                if (response != null && response.Result.code == 0 && (response.Result.desc == null || !response.Result.desc.Contains("价格发生变化")))
                {
                    //var hotelExtension = hotelRepository.GetHotelExtension(checkDto.HotelId, (int)Channel);
                    //var invoiceInfo = GetRatePlanInvoice(checkDto.HotelId, checkDto.RatePlanId, checkDto.CheckIn, checkDto.CheckOut);
                    bookOutDto.IsBook = true;
                    int remainRoomNum = response.Result.remainRoomNum;
                    int Quota         = 5;
                    if (remainRoomNum < 1)
                    {
                        Quota = 1;
                    }
                    else if (remainRoomNum > 5)
                    {
                        Quota = 5;
                    }
                    else
                    {
                        Quota = remainRoomNum;
                    }

                    var rate = new TaobaoRate();
                    try
                    {
                        XhotelRateGetRequest req = new XhotelRateGetRequest();
                        req.OutRid = checkDto.OuterId;
                        req.Rpid   = checkDto.Rpid;
                        var tmallApiClient         = new TmallApiClient(Shop);
                        XhotelRateGetResponse resp = tmallApiClient.Execute(req);
                        if (resp != null && !resp.IsError && resp.Rate != null && !string.IsNullOrWhiteSpace(resp.Rate.InventoryPrice))
                        {
                            rate = JsonConvert.DeserializeObject <TaobaoRate>(resp.Rate.InventoryPrice);
                        }
                    }
                    catch (Exception ex)
                    {
                    }

                    List <PriceModelsItem> modelList = new List <PriceModelsItem>();

                    foreach (var item in response.Result.priceModels)
                    {
                        if (!modelList.Any(u => u.date == item.date))
                        {
                            modelList.Add(item);
                        }
                    }
                    //是否需要马上更新
                    bool isUpdate = false;
                    //是否供应商发生变价
                    bool bianhua = false;

                    foreach (var item in modelList)
                    {
                        RateQuotasPrice rqp = new RateQuotasPrice();
                        rqp.Date = item.date;
                        //checkDto.IsVirtual, invoiceInfo.IsCommission, invoiceInfo.InvoiceMode, Convert.ToDecimal(item.subRatio / 10000), item.salePrice / 100, hotelExtension, rate
                        rqp.Price = GetSalePrice(Convert.ToDateTime(item.date), checkDto.IsVirtual, Convert.ToDecimal(item.subRatio / 10000), item.salePrice / 100, rate, ref bianhua, ref isUpdate, checkDto.IsCustomer).ToTaoBaoPrice();
                        rqp.Quota = Quota;//5;
                        bookOutDto.DayPrice.Add(rqp);
                    }
                    //记录试单信息
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            bool IsFull   = false;
                            string Remark = bookOutDto.Message;
                            //当库存为0时关房
                            if (remainRoomNum == 0 && checkDto.IsCustomer == 1)
                            {
                                IsFull = true;
                            }
                            if (checkDto.IsCustomer == 0)
                            {
                                Remark = "程序请求";
                            }
                            AliTripValidate av = new AliTripValidate();
                            av.CheckInTime     = checkDto.CheckIn;
                            av.CheckOutTime    = checkDto.CheckOut;
                            av.RatePlanCode    = checkDto.RatePlanCode;
                            av.IsFull          = IsFull;
                            av.HotelId         = checkDto.HotelId;
                            av.RoomId          = checkDto.RoomTypeId;
                            av.RatePlanId      = checkDto.RatePlanId;
                            av.CreateTime      = DateTime.Now;
                            av.Channel         = 5;
                            av.Shop            = (int)Shop;
                            av.Remark          = Remark;
                            SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();
                            string url = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source=5", checkDto.HotelId);
                            if (checkDto.IsCustomer != 0 && !isUpdate)
                            {
                                Thread.Sleep(15000);
                            }
                            WebHttpRequest.Get(url);
                            //当价格改变时或库存为0时更新房态
                            //if (bianhua || remainRoomNum == 0)
                            //{
                            //    string url = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source=5", checkDto.HotelId);
                            //    WebHttpRequest.Get(url);
                            //}
                        }
                        catch
                        {
                        }
                    });
                }
                else
                {
                    //TODO 满房变价,全部关房..
                    //bookOutDto.IsBook = false;
                    //bookOutDto.Message = response.Result.desc;

                    try
                    {
                        var falseCount      = 1;
                        var falseCacheCount = CacheHelper.GetCache("falseCount");//先读取缓存
                        //当为客人请求才做记录数次
                        if (checkDto.IsCustomer == 1)
                        {
                            if (falseCacheCount != null)//如果没有该缓存,默认为1
                            {
                                falseCount = (int)falseCacheCount + 1;
                            }
                            CacheHelper.SetCache("falseCount", falseCount, 1800);//添加缓存
                        }
                        //如果试单失败为双数直接拿缓存值输出,单数时为失败
                        //if (falseCount % 2 == 0)
                        bool tongguo = false;

                        //在0点15分到4点为试单失败为双数直接拿缓存值输出,其余的都通过
                        int NowHour   = DateTime.Now.Hour;   //当前时间的时数
                        int NowMinute = DateTime.Now.Minute; //当前时间的分钟数
                        if (falseCount % 2 == 0 || falseCount % 13 == 0)
                        {
                            tongguo = true;
                        }
                        else if ((NowHour == 18 && NowMinute > 10) || (NowHour < 8 && NowHour >= 19))
                        {
                            if (falseCount % 2 == 0 || falseCount % 5 == 0 || falseCount % 7 == 0)
                            {
                                tongguo = true;
                            }
                        }
                        //if (falseCount % 6 == 0 || checkDto.IsCustomer == 0 || response.Result.desc.Contains("价格发生变化"))
                        if (checkDto.IsCustomer == 0)
                        {
                            bookOutDto.Message = response.Result.desc;
                            bookOutDto.IsBook  = false;
                        }
                        else if (tongguo || response.Result.desc.Contains("价格发生变化"))
                        {
                            var rate = new TaobaoRate();
                            XhotelRateGetRequest req = new XhotelRateGetRequest();
                            req.OutRid = checkDto.OuterId;
                            req.Rpid   = checkDto.Rpid;
                            var tmallApiClient         = new TmallApiClient(Shop);
                            XhotelRateGetResponse resp = tmallApiClient.Execute(req);
                            if (resp != null && !resp.IsError && resp.Rate != null && !string.IsNullOrWhiteSpace(resp.Rate.InventoryPrice))
                            {
                                //try
                                //{
                                //    rate = JsonConvert.DeserializeObject<TaobaoRate>(resp.Rate.InventoryPrice);
                                //}
                                //catch (Exception ex)
                                //{
                                //}
                                rate = JsonConvert.DeserializeObject <TaobaoRate>(resp.Rate.InventoryPrice);
                            }
                            var totalDayNum = (int)(checkDto.CheckOut.Date - checkDto.CheckIn).TotalDays;
                            var rates       = new List <inventory_price>();
                            //判断是否已经更新过飞猪房态,0为没更新过,1为已更新过为不可以预定
                            int IsClose = 0;
                            for (int i = 0; i < totalDayNum; i++)
                            {
                                var inventory_price = rate.inventory_price.Where(a => a.date == checkDto.CheckIn.AddDays(i).ToString("yyyy-MM-dd")).FirstOrDefault();
                                if (inventory_price.price <= 0 || inventory_price.price > 4999900)
                                {
                                    IsClose            = 1;
                                    bookOutDto.Message = response.Result.desc;
                                    bookOutDto.IsBook  = false;
                                }
                                else
                                {
                                    rates.Add(inventory_price);
                                }
                            }

                            if (IsClose == 0)
                            {
                                bookOutDto.DayPrice = rates.Select(u =>
                                                                   new RateQuotasPrice
                                {
                                    Date  = u.date,
                                    Price = u.price,
                                    Quota = 1
                                }).ToList();
                                bookOutDto.Message = "正常可预定";
                                bookOutDto.IsBook  = true;
                                //logWriter.Write("试单失败后通过(美团):试单失败-淘宝酒店id:{0},美团酒店id:{1},{2},失败数次:{3},失败原因{4}", checkDto.Hid, checkDto.HotelId, checkDto.Rpid, falseCount, response.Result.desc);
                            }
                        }
                        else if (falseCount % 3 == 0)
                        {
                            var rate = new TaobaoRate();
                            XhotelRateGetRequest req = new XhotelRateGetRequest();
                            req.OutRid = checkDto.OuterId;
                            req.Rpid   = checkDto.Rpid;
                            var tmallApiClient         = new TmallApiClient(Shop);
                            XhotelRateGetResponse resp = tmallApiClient.Execute(req);
                            if (resp != null && !resp.IsError && resp.Rate != null && !string.IsNullOrWhiteSpace(resp.Rate.InventoryPrice))
                            {
                                //try
                                //{
                                //    rate = JsonConvert.DeserializeObject<TaobaoRate>(resp.Rate.InventoryPrice);
                                //}
                                //catch (Exception ex)
                                //{
                                //}
                                rate = JsonConvert.DeserializeObject <TaobaoRate>(resp.Rate.InventoryPrice);
                            }
                            var totalDayNum = (int)(checkDto.CheckOut.Date - checkDto.CheckIn).TotalDays;
                            var rates       = new List <inventory_price>();
                            //判断是否已经更新过飞猪房态,0为没更新过,1为已更新过为不可以预定
                            int IsClose = 0;
                            for (int i = 0; i < totalDayNum; i++)
                            {
                                var inventory_price = rate.inventory_price.Where(a => a.date == checkDto.CheckIn.AddDays(i).ToString("yyyy-MM-dd")).FirstOrDefault();
                                if (inventory_price.price <= 0 || inventory_price.price > 4999900)
                                {
                                    IsClose            = 1;
                                    bookOutDto.Message = response.Result.desc;
                                    bookOutDto.IsBook  = false;
                                }
                                else
                                {
                                    rates.Add(inventory_price);
                                }
                            }

                            if (IsClose == 0)
                            {
                                Random ran          = new Random();
                                int    RandomResult = ran.Next(80, 200);

                                bookOutDto.DayPrice = rates.Select(u =>
                                                                   new RateQuotasPrice
                                {
                                    Date  = u.date,
                                    Price = u.price + RandomResult * 100m,
                                    Quota = 1
                                }).ToList();
                                bookOutDto.Message = "正常可预定";
                                bookOutDto.IsBook  = true;
                                //logWriter.Write("试单失败后通过(美团):试单失败-淘宝酒店id:{0},美团酒店id:{1},{2},失败数次:{3},失败原因{4}", checkDto.Hid, checkDto.HotelId, checkDto.Rpid, falseCount, response.Result.desc);
                            }
                        }
                        else
                        {
                            //logWriter.Write("试单失败后(美团):试单失败-淘宝酒店id:{0},美团酒店id:{1},{2},失败数次:{3},失败原因{4}", checkDto.Hid, checkDto.HotelId, checkDto.Rpid, falseCount, response.Result.desc);
                            bookOutDto.Message = response.Result.desc;
                            bookOutDto.IsBook  = false;
                        }
                        //记录试单信息并关闭房态
                        Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                string Remark = response.Result.desc;
                                bool IsFull   = true;
                                if (checkDto.IsCustomer == 0)
                                {
                                    Remark = "程序请求";
                                    IsFull = false;
                                }
                                else if (response.Result.desc.Contains("价格发生变化"))
                                {
                                    Remark = "价格发生变化";
                                    IsFull = false;
                                }
                                AliTripValidate av = new AliTripValidate();
                                av.CheckInTime     = checkDto.CheckIn;
                                av.CheckOutTime    = checkDto.CheckOut;
                                av.RatePlanCode    = checkDto.RatePlanCode;
                                av.IsFull          = IsFull;
                                av.HotelId         = checkDto.HotelId;
                                av.RoomId          = checkDto.RoomTypeId;
                                av.RatePlanId      = checkDto.RatePlanId;
                                av.CreateTime      = DateTime.Now;

                                av.Channel = 5;
                                av.Shop    = (int)Shop;
                                av.Remark  = Remark;
                                SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();
                            }
                            catch
                            {
                            }
                            if (checkDto.IsCustomer != 0)
                            {
                                Thread.Sleep(13000);
                            }
                            string url = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source=5", checkDto.HotelId);
                            WebHttpRequest.Get(url);
                        });
                    }
                    catch (Exception ex)
                    {
                        //记录试单信息并关闭房态
                        Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                bool IsFull   = true;
                                string Remark = response.Result.desc;
                                if (checkDto.IsCustomer == 0)
                                {
                                    Remark = "程序请求";
                                    IsFull = false;
                                }
                                AliTripValidate av = new AliTripValidate();
                                av.CheckInTime     = checkDto.CheckIn;
                                av.CheckOutTime    = checkDto.CheckOut;
                                av.RatePlanCode    = checkDto.RatePlanCode;
                                av.IsFull          = IsFull;
                                av.HotelId         = checkDto.HotelId;
                                av.RoomId          = checkDto.RoomTypeId;
                                av.RatePlanId      = checkDto.RatePlanId;
                                av.CreateTime      = DateTime.Now;

                                av.Channel = 5;
                                av.Shop    = (int)Shop;
                                av.Remark  = Remark;
                                SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();
                            }
                            catch
                            {
                            }
                            Thread.Sleep(6000);
                            string url = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source=5", checkDto.HotelId);
                            WebHttpRequest.Get(url);
                        });
                        //logWriter.Write("试单失败后报错(美团):试单失败-淘宝酒店id:{0},美团酒店id:{1},{2},失败原因{3},报错{4}", checkDto.Hid, checkDto.HotelId, checkDto.Rpid, response.Result.desc, ex.ToString());
                        bookOutDto.Message = response.Result.desc;
                        bookOutDto.IsBook  = false;
                    }
                }
            }
            catch (Exception ex)
            {
                bookOutDto.IsBook  = false;
                bookOutDto.Message = string.Format("满房,系统异常:{0}", ex.ToString());
            }
            if (checkDto.IsCustomer == 0)
            {
                try
                {
                    BookingCheckOutDto CheckOut = new BookingCheckOutDto();
                    var check = CacheHelper.GetCache(checkKey); //先读取缓存
                    if (check != null)                          //如果没有该缓存
                    {
                        CheckOut = Newtonsoft.Json.JsonConvert.DeserializeObject <BookingCheckOutDto>(check.ToString(), new JsonSerializerSettings
                        {
                            Error = delegate(object obj, Newtonsoft.Json.Serialization.ErrorEventArgs args)
                            {
                                args.ErrorContext.Handled = true;
                            }
                        });
                        if (CheckOut != null)
                        {
                            return(CheckOut);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            CacheHelper.SetCache(checkKey, Newtonsoft.Json.JsonConvert.SerializeObject(bookOutDto), 8);//添加缓存
            return(bookOutDto);
        }
Ejemplo n.º 6
0
        public ServiceResult CreateOrder(int id)
        {
            var result = new ServiceResult();

            try
            {
                var order = sqlSugarClient.Queryable <TB_hotelcashorder>().Where(u => u.aId == id).First();
                if (order == null)
                {
                    return(result.SetError("订单不存在"));
                }

                if (order.alipayPay == 0)
                {
                    return(result.SetError("该订单未付款"));
                }

                if (order.state != 24)
                {
                    return(result.SetError("该订单状态已变更"));
                }

                if (order.Refuse == 2)
                {
                    return(result.SetError("该订单已取消"));
                }

                if (!string.IsNullOrEmpty(order.sourceOrderID))
                {
                    return(result.SetError("该订单未提交到美团,请勿重复下单"));
                }

                //List<DailyInfo> dailyInfo = JsonConvert.DeserializeObject<List<DailyInfo>>(order.DailyInfoPrice);

                int tBreakfast = getBreakfast(order.hotelID, order.roomID, order.ratePlanID, order.orderNO);
                //logWriter.Write("美团:酒店id:{0},roomID:{1},ratePlanID:{2},早餐数:{3},飞猪早餐数:{4},订单号:{5}", order.hotelID, order.roomID, order.ratePlanID, tBreakfast,order.userID,order.orderNO);
                //判断早餐数是否对等
                if (order.userID > tBreakfast && tBreakfast != 99 && order.userID != 0)
                {
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            //当早餐数不对等时更新rp
                            string urlUpdateRp = string.Format("http://localhost:9092/ashx/rnxUpdateRaPlan.ashx?type=rp&source=5&hid={0}", order.hotelID);
                            string getBoby     = WebHttpRequest.Get(urlUpdateRp);
                            if (!getBoby.Contains("更新价格计划成功"))
                            {
                                WebHttpRequest.Get(urlUpdateRp);
                            }
                            int NowHour   = DateTime.Now.Hour;   //当前时间的时数
                            int NowMinute = DateTime.Now.Minute; //当前时间的分钟数
                            //晚上12点半后,8点前满房时自动发送短信
                            if ((NowHour == 0 && NowMinute > 30) || (NowHour > 0 && NowHour < 8))
                            {
                                //发满房短信(发送满房信息)
                                FlyPigMessageUility.ThirdCommunication(Shop, Convert.ToInt32(order.aId), "系统", 1);
                            }
                        }
                        catch
                        {
                        }
                    });
                    string beiZhu = string.Format("【系统】:下单失败,具体原因:早餐个数不相等,天猫:{1}, 供应商:{2},取消执行自动下单,请联系申退 [{0}] <br/>【系统】:已自动更正早餐数,无需人工手动下线该酒店或房型 [{0}]", DateTime.Now.ToString(), order.userID, tBreakfast);
                    orderRepository.UpdateRemarkState(order.aId, 24, beiZhu);
                    logWriter.Write("美团(供应商早餐数发生变化):飞猪酒店id:{0},酒店id:{1},roomID:{2},ratePlanID:{3},早餐数:{4},飞猪早餐数:{5},订单号:{6}", order.TaoBaoHotelId, order.hotelID, order.roomID, order.ratePlanID, tBreakfast, order.userID, order.orderNO);
                    return(result.SetError("该订单早餐个数不相等"));
                }
                else if (order.userID < tBreakfast)
                {
                    //如果供应商的早餐数大于平台的,更新rp
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            string urlUpdateRp = string.Format("http://localhost:9092/ashx/rnxUpdateRaPlan.ashx?type=rp&source=5&hid={0}", order.hotelID);
                            string getBoby     = WebHttpRequest.Get(urlUpdateRp);
                            if (!getBoby.Contains("更新价格计划成功"))
                            {
                                WebHttpRequest.Get(urlUpdateRp);
                            }
                        }
                        catch
                        {
                        }
                    });
                    logWriter.Write("美团(平台早餐数少):飞猪酒店id:{0},酒店id:{1},roomID:{2},ratePlanID:{3},早餐数:{4},飞猪早餐数:{5},订单号:{6}", order.TaoBaoHotelId, order.hotelID, order.roomID, order.ratePlanID, tBreakfast, order.userID, order.orderNO);
                }


                string message = string.Empty;
                string content = string.Empty;
                string url     = string.Empty;
                if (Shop == ShopType.LingZhong || Shop == ShopType.YinJi || Shop == ShopType.RenXing)
                {
                    var synResult = SynChannelOrder((int)order.aId);
                    if (synResult.IsSucess)
                    {
                        content = result.Message;
                        message = string.Format("【系统】:同步订单请求成功,结果:{0} [{1}]", content, DateTime.Now.ToString());

                        if (order.orderType == 11)
                        {
                            url = string.Format("http://47.96.68.32/mtservice/orderCreate.ashx?saleorderno={0}&salesource=4", order.taoBaoOrderId, RequestUrl);
                        }
                        else
                        {
                            url = string.Format("http://47.107.30.243:9000/xw/orderCreate?saleorderno={0}", order.taoBaoOrderId);
                        }
                    }
                }
                else
                {
                    if (Shop == ShopType.RenNiXing)
                    {
                        url = string.Format("http://localhost:8094/rnx/orderCreate?saleorderno={0}&salesource=32", order.taoBaoOrderId);
                    }
                    else
                    {
                        url = string.Format("http://47.96.68.32/mtservice/orderCreate.ashx?saleorderno={0}&salesource=4", order.taoBaoOrderId, RequestUrl);
                    }
                }

                content = WebHttpRequest.GetOrder(url);

                if (content.Contains("可预订接口返回不可订") || content.Contains("订单提交给美团失败") || content.Contains("已售完或扣减库存失败") ||
                    content.Contains("订单价格与产品价格不符, 可能已变价") || content.Contains("失败,已变价,请判断价格再提交"))
                {
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            AliTripValidate av = new AliTripValidate();
                            av.CheckInTime     = order.checkInDate;
                            av.CheckOutTime    = order.checkOutDate;
                            av.HotelId         = order.hotelID;
                            av.RoomId          = order.roomID;
                            av.RatePlanId      = order.ratePlanID;
                            av.RatePlanCode    = "mr" + order.hotelID + "_" + order.roomID + "_" + order.ratePlanID;
                            av.CreateTime      = DateTime.Now;
                            av.IsFull          = true;
                            av.Channel         = (int)Channel;
                            av.Shop            = (int)Shop;
                            av.Remark          = "下单满房";
                            SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();

                            string updateUrl = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source={1}", order.hotelID, (int)Channel);
                            WebHttpRequest.Get(updateUrl);

                            orderRepository.UpdateOrderStutas(order.aId, 63);

                            int NowHour   = DateTime.Now.Hour;   //当前时间的时数
                            int NowMinute = DateTime.Now.Minute; //当前时间的分钟数
                            //晚上12点半后,8点前满房时自动发送短信
                            if ((NowHour == 0 && NowMinute > 30) || (NowHour > 0 && NowHour < 8))
                            {
                                //发满房短信(发送满房信息)
                                FlyPigMessageUility.ThirdCommunication(Shop, Convert.ToInt32(order.aId), "系统", 1);
                            }
                        }
                        catch
                        {
                        }
                    });
                    //string caozuo = string.Format("<br/>【系统】已发送满房短信[{0}]", DateTime.Now.ToString());
                    ////发满房短信
                    //FlyPigMessageUility.ThirdCommunication(Shop,Convert.ToInt32(order.aId), "系统", 1);
                    ////更新状态和操作
                    //orderRepository.UpdateRemarkStateCaoZuo(order.aId, 63,"", caozuo);
                }
                message = string.Format("<br/>【系统】:提交创建美团订单请求成功,结果:{0} [{1}]", content, DateTime.Now.ToString());
                orderRepository.UpdateOrderRemark(order.aId, message);
                return(result.SetSucess(content));
            }
            catch (Exception ex)
            {
                string message = string.Format("<br/>【系统】下单失败,出现异常,请手动下单,异常内容:{0}", ex.ToString());
                orderRepository.UpdateOrderRemark(id, message);
                return(result.SetError("下单失败,出现异常,请手动下单"));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 通知回调
        /// </summary>
        /// <returns></returns>
        protected override BookRQResult Notice()
        {
            BookRQResult result = new BookRQResult();

            result.ResultCode = "-100";
            result.Message    = "生成订单失败";

            if (Shop == ShopType.ShengLv && Channel == ProductChannel.BigTree)
            {
                return(result);
            }

            try
            {
                #region 异步保存发票信息
                if (Request.InvoiceInfo != null)
                {
                    try
                    {
                        Task.Run(() =>
                        {
                            SaveInvoiceInfo(Request);    //异步保存发票信息
                        });
                    }
                    catch (Exception ex)
                    {
                        logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "保存发票信息失败:{0},错误:{1}", JsonConvert.SerializeObject(Request.InvoiceInfo), ex.ToString());
                    }
                }

                #endregion

                FilterRemark(Request);
                TmallOrderDto order = ParseOrder(Request);
                if (!string.IsNullOrWhiteSpace(order.hotelID))
                {
                    string hotelId = order.hotelID;
                    //Task.Factory.StartNew(() =>
                    //{
                    //    if (Shop == ShopType.RenXing || Shop == ShopType.YinJi)
                    //    {
                    //        string url = string.Format("http://47.106.239.82/MtPricePro/AliChek.ashx?key=qoeutpzmbjhsyehgixjsngklzoeuyhbgfs&hid=0&code={0}&checkin={1}&checkout={2}&shop=yj&visit=验单失败或下单成功&invoice=1&addplan=0", hotelId, Request.CheckIn, Request.CheckOut);
                    //        WebHttpRequest.Get(url);
                    //    }
                    //    //TODO 下单失败,关房
                    //});

                    if (orderRepository.IsExists(Request.TaoBaoOrderId))
                    {
                        result.Message    = "重复预定";
                        result.ResultCode = "-106";
                        return(result);
                    }

                    Task <TmallHotelPriceInfo> getHotelPriceInfo = Task.Factory.StartNew(
                        () => productChannel.GetHotelPriceInfo(new BookingCheckInputDto
                    {
                        CheckIn      = Request.CheckIn,
                        CheckOut     = Request.CheckOut,
                        HotelId      = order.hotelID,
                        RatePlanId   = order.ratePlanID,
                        RoomNum      = order.roomNum,
                        RoomTypeId   = order.roomID,
                        RatePlanCode = Request.RatePlanCode
                    }
                                                               ));
                    getHotelPriceInfo.Wait();
                    var simpleOrder = getHotelPriceInfo.Result;
                    if (simpleOrder == null || string.IsNullOrEmpty(simpleOrder.PriceStr))
                    {
                        //Task.Factory.StartNew(() =>
                        //{
                        //    var client = DomesticHotelClient.CreateInstance(Shop, Channel);
                        //    client.RoomRate.UpdateRoomRateByHid(hotelId);
                        //});

                        //Task.Factory.StartNew(() =>
                        //{
                        //    //异步关闭所有房型
                        //    RoomRateService roomRateService = new RoomRateService(Shop, Channel);
                        //    roomRateService.UpdateRoomRateByHid(order.hotelID, true, true);
                        //});

                        //预订时,进订为不可预订时关房
                        Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                AliTripValidate av = new AliTripValidate();
                                av.CheckInTime     = Request.CheckIn;
                                av.CheckOutTime    = Request.CheckOut;
                                av.RatePlanCode    = Request.RatePlanCode;
                                av.HotelId         = hotelId;
                                av.RoomId          = order.roomID;
                                av.RatePlanId      = order.ratePlanID;
                                av.CreateTime      = DateTime.Now;
                                av.IsFull          = true;
                                av.Channel         = (int)Channel;
                                av.Shop            = (int)Shop;
                                av.Remark          = "预订满房";
                                SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();

                                string url = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source={1}", hotelId, (int)Channel);
                                WebHttpRequest.Get(url);
                            }
                            catch
                            {
                            }
                        });

                        #region 当携程预订满房时保存数据库返回下单成功为客服提醒客户申请退款
                        if ((int)Channel == 8 || (int)Channel == 10)
                        {
                            string priceStr = string.Empty;

                            string RoomNameCn = simpleOrder.RoomName;


                            order.hotelName = simpleOrder.HotelName;
                            order.roomName  = simpleOrder.RoomName;
                            //order.ratePlanName = simpleOrder.RatePlanName;
                            //order.totalPrice = Convert.ToDecimal(Request.TotalPrice- Request.VoucherInfos[0].VoucherPomotionAmt) / 100;
                            order.paymentType      = (short)Request.PaymentType;
                            order.totalPrice       = 0;
                            order.RatePlanCode     = Request.RatePlanCode;
                            order.taobaoTotalPrice = Convert.ToDecimal(Request.TotalPrice) / 100;
                            order.CurrencyCode     = "CNY";



                            //if (Request.RatePlanCode.Split('_').Length > 3)
                            //{
                            //    order.ratePlanName = string.Format("{0}[虚拟]", order.ratePlanName);
                            //}


                            if (Request.ContactName.Length > 20)
                            {
                                order.remark     += string.Format("【系统】[注意:联系人-{0}]     <br/>{1}", order.contactName, order.remark);
                                order.contactName = order.contactName.Substring(0, 20);
                            }

                            if (order.guestName.Length > 64)
                            {
                                order.remark   += string.Format("【系统】[注意:入住人-{0}]     <br/>{1}", order.guestName, order.remark);
                                order.guestName = order.guestName.Substring(0, 64);
                            }

                            try
                            {
                                var serviceResult = orderRepository.SaveOrder(Channel, order);
                                if (serviceResult.IsSucess)
                                {
                                    result.Message    = string.Format("创建订单成功");
                                    result.ResultCode = "0";
                                    result.OrderId    = order.orderNO;
                                }
                                else
                                {
                                    result.Message    = string.Format("系统保存订单失败:{0}", serviceResult.Message);
                                    result.ResultCode = "-105";
                                    logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "保存订单表失败");
                                }
                            }
                            catch (Exception ex)
                            {
                                result.Message    = string.Format("系统保存异常");
                                result.ResultCode = "-104";
                                logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "保存订单表失败:" + ex.ToString());
                            }
                        }
                        else
                        {
                            result.Message    = string.Format("满房,不可预定");
                            result.ResultCode = "-101";
                        }
                        #endregion
                        logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "::创建订单失败(满房)-编号:{0},{1},失败原因{2}", hotelId, Request.RatePlanCode, result.Message);
                        return(result);
                    }

                    if (string.IsNullOrEmpty(simpleOrder.RoomName))
                    {
                        //Task.Factory.StartNew(() =>
                        //{
                        //    //异步关闭所有房型
                        //    RoomRateService roomRateService = new RoomRateService(Shop, Channel);
                        //    roomRateService.UpdateRoomRateByHid(order.hotelID, true, true);
                        //});
                        logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "获取不到房型;");
                        result.Message    = string.Format("房型不存在");
                        result.ResultCode = "-114";
                        return(result);
                    }

                    if (!CheckPrice(Request.TotalPrice, simpleOrder.DatePrice, Request.RoomNum))   //校验价格
                    {
                        Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                AliTripValidate av = new AliTripValidate();
                                av.CheckInTime     = Request.CheckIn;
                                av.CheckOutTime    = Request.CheckOut;
                                av.RatePlanCode    = Request.RatePlanCode;
                                av.HotelId         = hotelId;
                                av.RoomId          = order.roomID;
                                av.RatePlanId      = order.ratePlanID;
                                av.CreateTime      = DateTime.Now;
                                av.IsFull          = true;
                                av.Channel         = (int)Channel;
                                av.Shop            = (int)Shop;
                                av.Remark          = "下单总价校验失败";
                                SqlSugarContext.RenNiXingInstance.Insertable(av).ExecuteCommand();

                                //47.106.132.129:9078
                                string url = string.Format("http://localhost:8097/apiAshx/UpdateRoomRate.ashx?type=RoomRate&hid={0}&source={1}", hotelId, (int)Channel);
                                WebHttpRequest.Get(url);
                            }
                            catch
                            {
                            }
                            ////异步关闭所有房型
                            //RoomRateService roomRateService = new RoomRateService(Shop, Channel);
                            //roomRateService.UpdateRoomRateByHid(order.hotelID, true, true);
                        });

                        logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "下单价格异常{0}-{1};完整:{2}", (Request.TotalPrice / 100), simpleOrder.DatePrice * Request.RoomNum, JsonConvert.SerializeObject(simpleOrder));
                        result.Message    = string.Format("下单总价校验失败");
                        result.ResultCode = "-103";
                        return(result);
                    }
                    string RoomName = simpleOrder.RoomName;
                    if (simpleOrder.RoomName == "获取房型失败")
                    {
                        RoomName = simpleOrder.RatePlanName.Replace("[携程开具发票]", "").Replace("[酒店开具发票]", "").Replace("[金牌]", "");
                    }

                    order.sTotalPrice      = simpleOrder.STotalPrice * Request.RoomNum;
                    order.priceStr         = simpleOrder.PriceStr;
                    order.hotelName        = simpleOrder.HotelName;
                    order.roomName         = RoomName;
                    order.ratePlanName     = simpleOrder.RatePlanName;
                    order.totalPrice       = Convert.ToDecimal(simpleOrder.DatePrice * Request.RoomNum);
                    order.paymentType      = (short)simpleOrder.PaymentType;
                    order.taobaoTotalPrice = Convert.ToDecimal(Request.TotalPrice) / 100;
                    order.CurrencyCode     = simpleOrder.CurrencyCode;
                    order.RatePlanCode     = Request.RatePlanCode;
                    //保存客人预订早餐数
                    order.userID = Request.DailyInfos[0].BreakFast;


                    if (simpleOrder.CurrencyPrice.HasValue)
                    {
                        order.MemberPrice = simpleOrder.CurrencyPrice;
                    }

                    if (string.IsNullOrEmpty(simpleOrder.RatePlanName))
                    {
                        order.remark += " [rp不存在]";
                    }


                    //if (Request.RatePlanCode.Split('_').Length > 3)
                    //{
                    //    order.ratePlanName = string.Format("{0}[虚拟]", order.ratePlanName);
                    //}


                    if (Request.ContactName.Length > 20)
                    {
                        order.remark     += string.Format("【系统】[注意:联系人-{0}]     <br/>{1}", order.contactName, order.remark);
                        order.contactName = order.contactName.Substring(0, 20);
                    }

                    if (order.guestName.Length > 64)
                    {
                        order.remark   += string.Format("【系统】[注意:入住人-{0}]     <br/>{1}", order.guestName, order.remark);
                        order.guestName = order.guestName.Substring(0, 64);
                    }

                    //判断大都市早餐数与预订时的早餐数
                    if ((int)Channel == 10 && !string.IsNullOrEmpty(simpleOrder.PriceStr) && order.userID != 0 && order.userID != simpleOrder.BreakFast && simpleOrder.BreakFast != 99)
                    {
                        Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                //当早餐数不对等时更新rp
                                string urlUpdateRp = string.Format("http://localhost:9092/ashx/rnxUpdateRaPlan.ashx?type=rp&source=10&hid={0}", order.hotelID);
                                string getBoby     = WebHttpRequest.Get(urlUpdateRp);
                                if (!getBoby.Contains("更新价格计划成功"))
                                {
                                    WebHttpRequest.Get(urlUpdateRp);
                                }
                            }
                            catch
                            {
                            }
                        });
                        if (order.userID > simpleOrder.BreakFast)
                        {
                            order.hasChange = 1;
                            order.sRoomNum  = simpleOrder.BreakFast;
                            //order.remark += string.Format("【系统】:早餐个数不相等,天猫:{1}, 供应商:{2}  [{0}]<br/>", DateTime.Now.ToString(), order.userID, simpleOrder.BreakFast);
                        }
                    }
                    if ((int)Channel == 10 && simpleOrder.BreakFast != 99)
                    {
                        //保存大都市产品在预订时供应商的早餐数,为判断早餐数是否对等
                        order.sRoomNum = simpleOrder.BreakFast;
                    }

                    try
                    {
                        var serviceResult = orderRepository.SaveOrder(Channel, order);
                        if (serviceResult.IsSucess)
                        {
                            //异步更新买家信息
                            Task.Factory.StartNew(() =>
                            {
                                UpdateBuyerInfo(Shop, order.taoBaoOrderId);
                            });

                            result.Message    = string.Format("创建订单成功");
                            result.ResultCode = "0";
                            result.OrderId    = order.orderNO;
                        }
                        else
                        {
                            result.Message    = string.Format("系统保存订单失败:{0}", serviceResult.Message);
                            result.ResultCode = "-105";
                            logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "保存订单表失败");
                        }
                    }
                    catch (Exception ex)
                    {
                        result.Message    = string.Format("系统保存异常");
                        result.ResultCode = "-104";
                        logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "保存订单表失败:" + ex.ToString());
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                logWriter.WriteOrder(Request.TaoBaoOrderId.ToString(), "创建订单异常:{0}", ex.ToString());
                result.ResultCode = "-104";
                result.Message    = "系统异常";
                return(result);
            }
        }