コード例 #1
0
        /// <summary>
        /// 喜玩订单
        /// </summary>
        /// <param name="createrequset"></param>
        /// <param name="orderseriald"></param>
        /// <param name="ruleid"></param>
        /// <param name="qlhotelid"></param>
        /// <returns></returns>
        public DataResult XiWanOrder(CreateRequset createrequset, string orderseriald, int ruleid, int qlhotelid)
        {
            var result = new DataResult();

            result.Code = DataResultType.Fail;
            var item    = createrequset.orderModel;
            var request = new XiWanOrderRequest();

            request.DistributeOrderNo = !string.IsNullOrWhiteSpace(item.thirdOrderNo) ? item.thirdOrderNo : orderseriald;
            request.HotelId           = item.hotelId;
            request.RoomId            = item.outCode.ToString();
            request.RoomName          = GetXiWanRoomName(item.roomTypeId.ToString());
            request.ProductSerial     = item.productSerial;
            request.ComeDate          = Convert.ToDateTime(item.arrival).Date;
            request.RoomNum           = item.roomNum;
            request.LeaveDate         = Convert.ToDateTime(item.departure).Date;
            request.LastArriveTime    = "18:00";
            request.TotalPrice        = Convert.ToDecimal(item.roomPrice);
            request.ContactName       = item.contactName;
            request.ContactMobile     = item.mobile;
            request.GuestNames        = item.guestName.Split(',');
            request.NoteToHotel       = !string.IsNullOrWhiteSpace(item.remark) ? item.remark : "无";
            var rtn = XiWanAPI.XiWanPost <XiWanOrderResponse, XiWanOrderRequest>(request, HotelOrderUrl);
            //日志
            var logmodel = new HO_HotelOrderLogModel
            {
                HOLOrderId       = orderseriald,
                HOLLogType       = 1,//订单日志
                HOLAddId         = 0,
                HOLAddName       = "系统",
                HOLAddDepartId   = 0,
                HOLAddDepartName = "系统",
                HOLAddTime       = DateTime.Now
            };

            logmodel.HOLRemark = "喜玩下单请求:" + JsonConvert.SerializeObject(request) + "||喜玩下单接口返回:" + JsonConvert.SerializeObject(rtn);
            OrderLogBll.AddOrderModel(logmodel);
            result.Message = JsonConvert.SerializeObject(rtn);
            var order = rtn?.Result;
            var price = OrderBll.GetHotelPriceList(ruleid, Convert.ToDateTime(item.arrival), Convert.ToDateTime(item.departure));

            if (rtn.Code == "0" && !string.IsNullOrWhiteSpace(order.OrderNo))
            {
                result.Code        = DataResultType.Sucess;
                result.Data        = orderseriald;
                logmodel.HOLRemark = "喜玩更新供应商订单流水号:流水号=" + order.OrderNo;
                var upserialid = OrderBll.UpdatesSupplier(orderseriald, order.OrderNo, 0);
                logmodel.HOLRemark = "更新结果:" + (upserialid > 0 ? "更新成功" : "更新失败");
                OrderLogBll.AddOrderModel(logmodel);
                if (price != null && price.Any())
                {
                    foreach (var i in price)
                    {
                        logmodel.HOLRemark = "喜玩更新库存:原有库存=" + i.HRPCount;
                        i.HRPCount         = i.HRPCount - 1 >= 0 ? i.HRPCount - 1 : 0;
                        var up = HotelRoomRuleBll.UpdateCount(i);
                        logmodel.HOLRemark += ",更新后库存=" + i.HRPCount + ",更新结果:" + up.Msg;
                        OrderLogBll.AddOrderModel(logmodel);
                    }
                }
            }
            else
            {
                if (rtn.Msg.Contains("存在日期满房") || rtn.Msg.Contains("总价应为") || rtn.Msg.Contains("已关闭"))
                {
                    var upstock = XiWanApiService.Xw_HotelPrice(qlhotelid);
                    logmodel.HOLRemark = "满房或价格变动更新酒店库存和价格:酒店id:" + qlhotelid + ",更新结果:" + upstock.Code;
                    OrderLogBll.AddOrderModel(logmodel);
                    if (rtn.Msg.Contains("存在日期满房"))
                    {
                        if (price != null && price.Any())
                        {
                            var i = price.OrderBy(s => s.HRPDate).FirstOrDefault();
                            i.HRPCount = 0;
                            var up = HotelRoomRuleBll.UpdateCount(i);
                            logmodel.HOLRemark = "满房更新库存:待更新信息:" + JsonConvert.SerializeObject(i) + ",更新结果:" + up.IsSuccess;
                            OrderLogBll.AddOrderModel(logmodel);
                        }
                        result.Code    = DataResultType.Fail;
                        result.Message = JsonConvert.SerializeObject(rtn);
                        OrderBll.UpdatesSupplier(orderseriald, "", 2);
                    }
                    if (rtn.Msg.Contains("总价应为"))
                    {
                        var neworder = OrderBll.GetModel(orderseriald);
                        var newprice = OrderBll.GetHotelPriceList(neworder.HRRId, neworder.HOCheckInDate, neworder.HOCheckOutDate);
                        if (price != null && price.Any())
                        {
                            var total = price.Sum(s => s.HRPContractPrice) * neworder.HORoomCount;
                            createrequset.orderModel.roomPrice = total.ToString();
                            if (createrequset.supplierSourceId == 1)
                            {
                                total = total * 0.94M;
                            }
                            if (neworder.HOSellPrice >= total)
                            {
                                XiWanOrder(createrequset, orderseriald, ruleid, qlhotelid);
                            }
                            else
                            {
                                result.Code    = DataResultType.Fail;
                                result.Message = JsonConvert.SerializeObject(rtn);
                                OrderBll.UpdatesSupplier(orderseriald, "", 2);
                            }
                        }
                    }
                    if (rtn.Msg.Contains("已关闭"))
                    {
                        var up = HotelBll.SetValid(qlhotelid, 0, "system");
                        logmodel.HOLRemark = "已关闭更新酒店状态:待更新酒店Id:" + qlhotelid + ",更新结果:" + up.IsSuccess;
                        OrderLogBll.AddOrderModel(logmodel);
                        result.Code    = DataResultType.Fail;
                        result.Message = JsonConvert.SerializeObject(rtn);
                        OrderBll.UpdatesSupplier(orderseriald, "", 2);
                    }
                }
            }
            return(result);
        }
コード例 #2
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);
        }
コード例 #3
0
        /// <summary>
        /// 亚朵订单
        /// </summary>
        /// <param name="createrequset"></param>
        /// <param name="orderseridid"></param>
        /// <param name="ruleid"></param>
        /// <param name="qlhotelid"></param>
        /// <returns></returns>
        public DataResult AtourOrder(CreateRequset createrequset, string orderseridid, int ruleid, int qlhotelid)
        {
            var result       = new DataResult();
            var item         = createrequset.orderModel;
            var orderrequest = new OrderRequest
            {
                appId = AtourAuth_APPID,
                //sign = sign,
                hotelId        = item.hotelId,
                mebId          = Convert.ToInt32(AtourAuth_MebId),
                roomTypeId     = item.roomTypeId,
                roomNum        = item.roomNum,
                roomRateList   = JsonConvert.SerializeObject(item.roomRateList),
                arrival        = item.arrival,
                assureTime     = item.assureTime,
                departure      = item.departure,
                mobile         = "18962529773",
                contactName    = item.contactName,
                guestName      = item.guestName,
                source         = 10,
                subSource      = 85,
                roomRateTypeId = item.roomRateTypeId,
                thirdOrderNo   = item.thirdOrderNo,
                couponsList    = item.couponsList,
                remark         = item.remark,
            };
            Dictionary <string, string> dic = new Dictionary <string, string>();
            //dic.Add("appId", AtourAuth_APPID);
            Type entityType = orderrequest.GetType();

            PropertyInfo[] properties = entityType.GetProperties();
            for (int i = 0; i < properties.Length; i++)
            {
                if (properties[i].GetValue(orderrequest, null) != null)
                {
                    dic.Add(properties[i].Name, properties[i].GetValue(orderrequest, null).ToString());
                }
            }
            var sign = AtourSignUtil.GetSignUtil(dic);

            orderrequest.sign = sign;

            var           url  = AtourAuth_URL + "baoku/order/createOrder";
            StringBuilder parm = new StringBuilder();

            PropertyInfo[] request = orderrequest.GetType().GetProperties();
            int            j       = 0;

            foreach (var t in request)
            {
                if (j > 0)
                {
                    parm.Append("&");
                }
                parm.AppendFormat("{0}={1}", t.Name, t.GetValue(orderrequest, null));
                j++;
            }
            var orderresponse = ApiHelper.HttpPost(url, parm.ToString(), "application/x-www-form-urlencoded");
            //日志
            var logmodel = new HO_HotelOrderLogModel
            {
                HOLOrderId       = orderseridid,
                HOLLogType       = 1,//订单日志
                HOLAddId         = 0,
                HOLAddName       = "系统",
                HOLAddDepartId   = 0,
                HOLAddDepartName = "系统",
                HOLAddTime       = DateTime.Now
            };

            logmodel.HOLRemark = "亚朵下单请求:" + url + "||parm:" + parm.ToString() + "|| 接口返回:" + orderresponse;
            OrderLogBll.AddOrderModel(logmodel);
            if (!string.IsNullOrWhiteSpace(orderresponse))
            {
                var data  = JsonConvert.DeserializeObject <JObject>(orderresponse);
                var price = OrderBll.GetHotelPriceList(ruleid, Convert.ToDateTime(item.arrival), Convert.ToDateTime(item.departure));
                if (data["msg"].ToString().ToLower() == "success")
                {
                    var serialid = data["result"]["atourOrderNo"].ToString();

                    result.Code        = DataResultType.Sucess;
                    result.Data        = orderseridid;
                    logmodel.HOLRemark = "亚朵更新供应商订单流水号:流水号=" + serialid;
                    var upserialid = OrderBll.UpdatesSupplier(orderseridid, serialid, 0);
                    logmodel.HOLRemark = "更新结果:" + (upserialid > 0 ? "更新成功" : "更新失败");
                    OrderLogBll.AddOrderModel(logmodel);
                    if (price != null && price.Any())
                    {
                        foreach (var i in price)
                        {
                            logmodel.HOLRemark = "亚朵更新库存:原有库存=" + i.HRPCount;
                            i.HRPCount         = i.HRPCount - 1 >= 0 ? i.HRPCount - 1 : 0;
                            var up = HotelRoomRuleBll.UpdateCount(i);
                            logmodel.HOLRemark += ",更新后库存=" + i.HRPCount + ",更新结果:" + up.Msg;
                            OrderLogBll.AddOrderModel(logmodel);
                        }
                    }
                    //下单成功通知
                    //OpenApi.HotelOrderStatus(orderseridid, 2);
                }
                else
                {
                    if (data["level"].ToString() == "80034")//满房
                    {
                        var upstock = YaDuoApiService.GetRoomRate(item.hotelId, Convert.ToDateTime(item.arrival), 100000);
                        logmodel.HOLRemark = "满房更新酒店库存和价格:酒店id:" + qlhotelid + ",更新结果:" + upstock.Code;
                        OrderLogBll.AddOrderModel(logmodel);
                        if (price != null && price.Any())
                        {
                            var i = price.OrderBy(s => s.HRPDate).FirstOrDefault();
                            i.HRPCount = 0;
                            var up = HotelRoomRuleBll.UpdateCount(i);
                            logmodel.HOLRemark = "满房更新库存:待更新信息:" + JsonConvert.SerializeObject(i) + ",更新结果:" + up.IsSuccess;
                            OrderLogBll.AddOrderModel(logmodel);
                        }
                        //满房通知
                        //OpenApi.HotelOrderStatus(orderseridid, 1);
                    }
                    //if (data["level"].ToString() == "1006")//报价不存在或者不可订
                    //{
                    //    if (data["msg"].ToString().Contains("报价不可订"))
                    //    {
                    //        var neworder = OrderBll.GetModel(orderseridid);
                    //        var newprice = OrderBll.GetHotelPriceList(neworder.HRRId, neworder.HOCheckInDate, neworder.HOCheckOutDate);
                    //        if (price != null && price.Any())
                    //        {
                    //            var total = price.Sum(s => s.HRPContractPrice) * neworder.HORoomCount;
                    //            createrequset.orderModel.roomPrice = total.ToString();
                    //            if (createrequset.supplierSourceId == 1)
                    //            {
                    //                total = total * 0.97M;
                    //            }
                    //            if (neworder.HOSellPrice >= total)
                    //            {
                    //                AtourOrder(createrequset, orderseridid, ruleid, qlhotelid);
                    //            }
                    //        }
                    //    }
                    //}
                    result.Code    = DataResultType.Fail;
                    result.Message = data["msg"].ToString();
                    OrderBll.UpdatesSupplier(orderseridid, "", 2);
                }
            }
            return(result);
        }