Exemplo n.º 1
0
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <returns></returns>
        public DataResult CreateAtourOrder([FromBody] string jsonvalue, string orderseridid = "")
        {
            var  result        = new DataResult();
            var  createrequset = new CreateRequset();
            bool issned        = false;
            var  ruleid        = 0;
            var  qlhotelid     = 0;

            try
            {
                using (StreamReader sr = new StreamReader(HttpContext.Current.Request.GetBufferedInputStream()))
                {
                    sr.ReadToEnd();
                }
                using (StreamReader sr = new StreamReader(HttpContext.Current.Request.InputStream))
                {
                    jsonvalue     = sr.ReadToEnd();
                    createrequset = JsonConvert.DeserializeObject <CreateRequset>(jsonvalue);
                }
                if (createrequset != null)
                {
                    var item = createrequset.orderModel;
                    //需要推送的订单
                    if (createrequset.supplierSourceId == 1 || createrequset.supplierSourceId == 2)//1 亚朵 2喜玩
                    {
                        issned = true;
                        //createrequset.orderModel.outCode = createrequset.supplierSourceId.ToString();
                    }
                    var hotelinfo = OrderBll.GetSupplierHotelList(item.roomTypeId);
                    if (hotelinfo != null)
                    {
                        #region
                        var newmodel = new HO_HotelOrderModel
                        {
                            HOCustomerSerialId = ExtOrderNum.Gener("Z", 1),
                            HIId                  = hotelinfo.HotelId,
                            HName                 = hotelinfo.HotelName,
                            HRId                  = hotelinfo.HotelRoomId,
                            HRName                = hotelinfo.HotelRoomName,
                            HRRId                 = hotelinfo.HotelRoomRuleId,
                            HRRName               = hotelinfo.HotelRoomRuleName,
                            HOSupplierId          = hotelinfo.HotelSupplierId,
                            HOSupperlierName      = hotelinfo.HotelSupplierName,
                            HODistributorId       = createrequset.distribuorSourceId,
                            HODistributorName     = createrequset.distribuorSource,
                            HOSupplierSourceId    = hotelinfo.HotelSupplierSourceId,
                            HOSupplierSourceName  = hotelinfo.HotelSupplierSourceName,
                            HODistributorSerialId = item.thirdOrderNo,
                            HORoomCount           = item.roomNum,
                            HONight               = GetNight(Convert.ToDateTime(item.departure), Convert.ToDateTime(item.arrival), item.roomNum),
                            HOLinkerName          = item.contactName,
                            HOCustomerName        = item.guestName,
                            HOContractPrice       = Convert.ToDecimal(item.roomPrice),
                            HOSellPrice           = Convert.ToDecimal(item.basePrice),
                            HOCheckInDate         = Convert.ToDateTime(item.arrival),
                            HOCheckOutDate        = Convert.ToDateTime(item.departure),
                            HOLastCheckInTime     = item.assureTime,
                            HOAddId               = 0,
                            HOAddName             = "system",
                            HOAddDepartId         = 0,
                            HOAddDepartName       = "system",
                            HOAddTime             = DateTime.Now,
                            HORemark              = item.remark,
                            HOUpdateId            = 0,
                            HOUpdateName          = "系统",
                            HOUpdateTime          = DateTime.MinValue
                        };
                        //日志
                        var logmodel = new HO_HotelOrderLogModel
                        {
                            HOLOrderId       = newmodel.HOCustomerSerialId,
                            HOLLogType       = 1,//订单日志
                            HOLRemark        = "创建订单:" + newmodel.HOCustomerSerialId,
                            HOLAddId         = 0,
                            HOLAddName       = "系统",
                            HOLAddDepartId   = 0,
                            HOLAddDepartName = "系统",
                            HOLAddTime       = DateTime.Now
                        };
                        ruleid    = newmodel.HRRId;
                        qlhotelid = newmodel.HIId;
                        var price = OrderBll.GetHotelPriceList(newmodel.HRRId, newmodel.HOCheckInDate, newmodel.HOCheckOutDate);
                        if (price != null && price.Any())
                        {
                            var newtotal = 0.00M;
                            var total    = price.Sum(s => s.HRPContractPrice) * newmodel.HORoomCount;
                            if (createrequset.supplierSourceId == 1 || createrequset.supplierSourceId == 2)
                            {
                                newtotal = createrequset.supplierSourceId == 1 ? total * 0.94M : total;
                                if (newmodel.HOSellPrice >= newtotal)
                                {
                                    issned = true;
                                    newmodel.HOContractPrice = total;
                                }
                                else
                                {
                                    issned            = false;
                                    newmodel.HOStatus = 2;
                                }
                            }
                        }
                        OrderLogBll.AddOrderModel(logmodel);
                        var response = OrderBll.AddOrderModel(newmodel);
                        orderseridid = newmodel.HOCustomerSerialId;
                        #endregion
                    }
                }
                if (!string.IsNullOrWhiteSpace(orderseridid) && issned)
                {
                    Stopwatch sw1   = new Stopwatch();
                    var       order = OrderBll.GetModel(orderseridid);
                    if (order.Id > 0)
                    {
                        var search = new OrderPriceSearchRequest
                        {
                            HotelId = order.HIId,
                            RoomId  = order.HRId,
                            RuleId  = order.HRRId,
                            BDate   = order.HOCheckInDate,
                            EDate   = order.HOCheckOutDate
                        };
                        var roomRateList = new List <RateList>();
                        sw1.Start();
                        var pricelist = HotelPriceBll.GetOrderList(search);
                        if (pricelist != null && pricelist.Any())
                        {
                            foreach (var price in pricelist)
                            {
                                var ite = new RateList
                                {
                                    accDate  = price.PriceDate,
                                    roomRate = price.ContractPrice
                                };
                                roomRateList.Add(ite);
                            }
                        }
                        sw1.Stop();
                        LogHelper.Info("查询订单和价格耗时:" + sw1.ElapsedMilliseconds);
                        createrequset.orderModel = new OrderModel
                        {
                            hotelId        = Convert.ToInt32(order.OutHotelId),
                            mebId          = 0,
                            roomTypeId     = Convert.ToInt32(order.OutRoomId),
                            roomNum        = order.HORoomCount,
                            roomRateList   = roomRateList,
                            arrival        = order.HOCheckInDate.ToString("yyyy-MM-dd"),
                            assureTime     = "",
                            departure      = order.HOCheckOutDate.ToString("yyyy-MM-dd"),
                            mobile         = order.HOLinkerMobile,
                            contactName    = order.HOLinkerName,
                            guestName      = order.HOCustomerName,
                            source         = 0,
                            subSource      = 0,
                            roomRateTypeId = 41,
                            thirdOrderNo   = order.HODistributorSerialId,
                            basePrice      = "",
                            couponsList    = "",
                            remark         = order.HORemark,
                            roomPrice      = order.HOContractPrice.ToString(),
                            productSerial  = order.OutProductSerial,
                            outCode        = order.OutRoomCode
                        };
                    }
                }
                if (issned)
                {
                    switch (createrequset.supplierSourceId)
                    {
                    case 1:
                        result = AtourOrder(createrequset, orderseridid, ruleid, qlhotelid);
                        break;

                    case 2:
                        result = XiWanOrder(createrequset, orderseridid, ruleid, qlhotelid);
                        break;
                    }
                    return(result);
                }
                else
                {
                    result.Data = orderseridid;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("异常" + ex.ToString());
            }
            return(result);
        }