Example #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);
        }
Example #2
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);
        }