Ejemplo n.º 1
0
        /// <summary>
        /// 城市
        /// </summary>
        /// <param name="code"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Sys_AreaInfoModel AddCityCode(string code, string name)
        {
            var city      = new Sys_AreaInfoModel();
            var oldList   = new Sys_AreaInfoAccess2().Query().Where(x => x.type == 3).ToList();
            var modellist = new List <Sys_AreaMatchModel>();
            var matchDb   = new Sys_AreaMatchAccess();
            var cityMatch = matchDb.Query().Where(x => x.OutType == 2 && x.OutCityCode == code).FirstOrDefault();

            if (cityMatch == null || cityMatch.Id <= 0)
            {
                city      = oldList.FirstOrDefault(x => x.name == name);
                cityMatch = new Sys_AreaMatchModel
                {
                    OutCityCode = code,
                    OutCityName = name,
                    OutType     = 2,
                    HbId        = city?.id ?? 0
                };
                matchDb.Add(cityMatch);
            }
            else
            {
                city = oldList.FirstOrDefault(x => x.id == cityMatch.HbId);
            }
            return(city);
        }
Ejemplo n.º 2
0
        //库存 baoku/hotel/getRoomInventoryList、

        #region 城市匹配


        /// <summary>
        /// 获取城市列表
        /// </summary>
        /// <returns></returns>

        public static DataResult GetCityList()
        {
            var result = new DataResult();
            var url    = AtourSignUtil.AtourAuth_URL + "city/getCityList";
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("appId", AtourSignUtil.AtourAuth_APPID);
            var sign     = AtourSignUtil.GetSignUtil(dic);
            var citylist = ApiHelper.HttpGet(url + "?appId=" + AtourSignUtil.AtourAuth_APPID + "&sign=" + sign);

            if (string.IsNullOrWhiteSpace(citylist))
            {
                result = new DataResult {
                    Code = DataResultType.Fail, Message = "系统异常"
                };
            }

            var oldList   = new Sys_AreaInfoAccess2().Query().Where(x => x.type == 3).ToList();
            var modellist = new List <Sys_AreaMatchModel>();
            var data      = citylist.ToObject <AtourCityResponse>();

            data?.result?.ForEach(n =>
            {
                var old   = oldList.FirstOrDefault(x => x.name == n.cityName.Replace("市", ""));
                var model = new Sys_AreaMatchModel
                {
                    OutProvId   = 0,
                    OutProvName = n.provinceName,
                    OutCityId   = n.cityId,
                    OutCityName = n.cityName,
                    HbId        = old?.id ?? 0,
                    OutType     = 1
                };
                var db = new Sys_AreaMatchAccess();
                var m  = db.Query().Where(x => x.OutType == 1 && x.OutCityId == n.cityId).FirstOrDefault();
                if (m == null || m.Id <= 0)
                {
                    db.Add(model);
                    result.Data += $"{old?.id}:{n.cityName};";
                }
                else
                {
                }
            });

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取酒店列表
        /// </summary>
        /// <returns></returns>
        public static DataResult GetHotelList(int maxId, int top)
        {
            var result = new DataResult()
            {
                Data = $"{maxId + top};"
            };

            var citylist = new Sys_AreaMatchAccess().Query().Where(x => x.OutType == 1 && x.HbId > maxId).ToList();

            if (citylist == null || !citylist.Any())
            {
                result.Message = $"{maxId}未查询到数据";
                result.Data    = $"{maxId + top}";
                return(result);
            }
            var log = string.Empty;

            foreach (var item in citylist)
            {
                result.Data += $"[{item.OutCityId}]:";
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("appId", AtourSignUtil.AtourAuth_APPID);
                dic.Add("cityId", item.OutCityId.ToString());
                var sign = AtourSignUtil.GetSignUtil(dic);
                var url  = AtourSignUtil.AtourAuth_URL + "baoku/hotel/getHotelList";
                url += "?appId=" + AtourSignUtil.AtourAuth_APPID + "&cityId=" + item.OutCityId.ToString() + "&sign=" + sign;
                var hotellst = ApiHelper.HttpGet(url);
                if (!string.IsNullOrWhiteSpace(hotellst))
                {
                    var baseCity = new Sys_AreaInfoAccess2().Query().FirstOrDefault(x => x.id == item.HbId);
                    var baseProv = new Sys_AreaInfoAccess2().Query().FirstOrDefault(x => x.id == baseCity.pid);
                    var data     = hotellst.ToObject <AtourHotelResponse>();
                    result.Data += $"{baseCity.name}酒店数量:{data?.result?.Count};";
                    data?.result?.ForEach(x =>
                    {
                        var hDb   = new H_HotelInfoAccess();
                        var model = hDb.Query().Where(h => h.HIOutId == x.hotelId && h.HIOutType == 1).FirstOrDefault();
                        int id    = model?.Id ?? 0;
                        if (model == null || id <= 0)
                        {
                            model = new H_HotelInfoModel()
                            {
                                HIOutId             = x.hotelId,
                                HIOutType           = 1,
                                HIName              = x.name ?? String.Empty,
                                HIAddress           = x.address ?? String.Empty,
                                HILinkPhone         = x.tel ?? string.Empty,
                                HICity              = baseCity.name,
                                HICityId            = baseCity.id,
                                HIProvince          = baseProv.name,
                                HIProvinceId        = baseCity.pid,
                                HIAddName           = "",
                                HIAddTime           = DateTime.Now,
                                HICheckIn           = string.Empty,
                                HICheckOut          = string.Empty,
                                HIChildRemark       = string.Empty,
                                HICounty            = string.Empty,
                                HICountyId          = 0,
                                HIFacilities        = string.Empty,
                                HIHotelIntroduction = string.Empty,
                                HIIsValid           = 1,
                                HIPetRemark         = string.Empty,
                                HIShoppingArea      = string.Empty,
                                HIShoppingAreaId    = 0,
                                HIUpdateName        = string.Empty,
                                HIUpdateTime        = DateTime.Now,
                                HIGdLonLat          = $"{x.longitude},{x.latitude}"
                            };
                            id = (int)(hDb.Add(model));
                            //OpenApi.SysInfo(id);
                            OpenApi.HotelOffline(id, 1);
                            logDb.AddLog(id, $"亚朵新增酒店:{x.hotelId}:{x.name}", ResourceLogType.HotelAdd);
                        }
                        else
                        { //更新
                          //hDb.Update().Where(h=>h.Id==id)
                          //.Set(h=>h.);
                        }
                        if (id > 0)
                        {
                            PidInit(x, id);
                        }
                    });
                }
                else
                {
                    result.Data += $"无数据;";
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 酒店详情
        /// </summary>
        /// <param name="maxId"></param>
        /// <param name="top"></param>
        /// <returns></returns>
        public static DataResult GetHotelDetail(int maxId, int top)
        {
            var result = new DataResult();

            var hDb       = new H_HotelInfoAccess();
            var hotelList = hDb.Query().Where(h => h.Id >= maxId && h.HIOutType == 2).Top(top).OrderBy(h => h.HIOutId)?.ToList();

            if (hotelList == null || hotelList.Count == 0)
            {
                result.Message = "无数据";
                return(result);
            }
            var provList = new Sys_AreaInfoAccess2().Query().Where(x => x.type == 2).ToList();
            var msgList  = new List <string>();

            Parallel.ForEach(hotelList, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 3
            }, (x, loopstate) =>
            {
                try
                {
                    var request = new XiWanHotelDetailRequest {
                        HotelId = x.HIOutId
                    };
                    var rtn   = XiWanAPI.XiWanPost <XiWanHotelDetail, XiWanHotelDetailRequest>(request, HotelDetailUrl);
                    var hotel = rtn?.Result;
                    if (hotel?.HotelId > 0)
                    {
                        var city = AddCityCode(hotel.CityCode, hotel.CityName) ?? new Sys_AreaInfoModel();
                        var prov = new Sys_AreaInfoModel();
                        if (city.pid > 0)
                        {
                            prov = provList.FirstOrDefault(p => p.id == city.pid) ?? new Sys_AreaInfoModel();
                        }
                        hDb.Update().Set(h =>
                                         h.HIGdLonLat == hotel.Position &&
                                         h.HIName == hotel.HotelName &&
                                         h.HIHotelIntroduction == hotel.Intro &&
                                         h.HIAddress == hotel.Address &&
                                         h.HILinkPhone == hotel.Tel &&
                                         h.HICityId == city.id &&
                                         h.HICity == (city.name ?? string.Empty) &&
                                         h.HIProvinceId == prov.id &&
                                         h.HIProvince == (prov.name ?? string.Empty) &&
                                         h.HIUpdateName == "喜玩详情接口更新" &&
                                         h.HIUpdateTime == DateTime.Now
                                         ).Where(h => h.Id == x.Id).Execute();
                        //会员 暂时未开发
                        logDb.AddLog(x.Id, $"喜玩详情接口更新:{hotel.HotelId}:{hotel.HotelName}", ResourceLogType.HotelUpdate);
                    }
                    else
                    {
                        msgList.Add(rtn?.Msg ?? "系统异常");
                    }

                    //房型等
                    var d1 = Xw_HotelPrice(x.Id);
                    msgList.Add($"||{x.Id}:{d1.Message}");
                    Thread.Sleep(10);
                }
                catch (Exception ex)
                {
                    var log = $"{ex.Message}--{x.Id}---{ex.ToString()}";
                    LogHelper.Error(log);
                }
            });
            result.Data = msgList;
            return(result);
        }