示例#1
0
 /// <summary>
 /// send a new order request to the matching server through connection
 /// </summary>
 private void SendNewOrderRequest(OrderRequest req)
 {
     requestsSentByType[req.GetType()] = requestsSentByType[req.GetType()] + 1;
     statistics.IncrementOrderRequestsSend();
     try
     {
         if (connection.SendRequest(req))
         {
             statistics.IncrementSendRequestErrorCount();
         }
     }
     catch
     {
     }
 }
示例#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);
        }