예제 #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);
        }
예제 #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);
        }