Ejemplo n.º 1
0
        /// <summary>
        /// 获得经纬度
        /// </summary>
        /// <returns></returns>
        public ActionResult GetLocal()
        {
            JsonSMsg msg = new JsonSMsg();

            string lo = Request["LO"];

            string ln = Request["LN"];

            string code = Request["CODE"];

            List <BCJ_CITY> citys = new List <BCJ_CITY>();


            //如果城市编码是空表示顾客自己定位刚进入页面需要加载城市等信息
            if (string.IsNullOrEmpty(code))
            {
                TenAPI model     = Utility.GetLocal(lo, ln);
                string citymodel = model.result.formatted_address;

                logger.Info(citymodel + "====" + lo + "===" + ln);

                //citys.AddRange(_book.GetCity());
                citys.AddRange(_book.GetAvalibleCity());

                BCJ_CITY one = citys.Where(a => citymodel.Contains(a.CITY_NAME)).ToList().FirstOrDefault();

                code = one == null ? "110100" : one.CITY_CODE;
            }

            //加载门店列表
            List <BCJ_STORES_EX> stores = _bcjStore.GetStoresByCityCode(code);


            //如果不是定位则计算距离城市中心点的位置
            foreach (BCJ_STORES_EX storeM in stores)
            {
                Poin beigin = new Poin(double.Parse(ln), double.Parse(lo));
                Poin end    = new Poin(double.Parse(storeM.LONGITUDE), double.Parse(storeM.LATITUDE));
                storeM.Distance = Utility.GetDistance(beigin, end).ToString();
                storeM.NAME     = storeM.NAME.Trim();
            }


            msg.Data = new
            {
                CIRY_CODE = code,
                CIRYS     = citys,
                STORES    = stores.OrderBy(a => a.Distance)
            };
            return(Json(msg));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取城市信息
        /// </summary>
        /// <returns></returns>
        public ActionResult GetCity()
        {
            JsonSMsg msg = new JsonSMsg();

            string lo = Request["LO"];

            string ln = Request["LN"];

            string city_code = Request["city_code"];

            List <BCJ_CITY> citys = new List <BCJ_CITY>();
            BCJ_CITY        one   = null;

            if (string.IsNullOrEmpty(city_code))
            {
                citys = _book.GetCity();

                if (citys.Count() <= 0)
                {
                    msg.Status = 0;
                    return(Json(msg));
                }

                TenAPI model = Utility.GetLocal(lo, ln);

                string cityname         = model.result.formatted_address;
                JavaScriptSerializer js = new JavaScriptSerializer();

                logger.Info(js.Serialize(model) + lo + "====" + ln);
                one = citys.Where(a => cityname.Contains(a.CITY_NAME)).ToList().FirstOrDefault();

                city_code = one == null ? "110100" : one.CITY_CODE;
            }

            //加载门店列表
            List <BCJ_STORES_EX> stores = _store.GetStoresByCityCode(city_code);

            msg.Data = new
            {
                CITYS  = citys,
                STORES = stores
            };

            msg.Status  = 1;
            msg.Message = one == null ? "110100" : one.CITY_CODE;
            return(Json(msg));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获得经纬度
        /// </summary>
        /// <returns></returns>
        public dynamic GetLocalStore(dynamic arg)
        {
            MapRequest request = base.BindObject <MapRequest>();
            string     lo      = request.LO;
            string     ln      = request.LN;
            string     code    = request.CODE;

            List <BCJ_CITY> citys = new List <BCJ_CITY>();


            //如果城市编码是空表示顾客自己定位刚进入页面需要加载城市等信息
            if (string.IsNullOrEmpty(code))
            {
                TenAPI model     = Utility.GetLocal(lo, ln);
                string citymodel = model.result.formatted_address;

                logger.Info(citymodel + "====" + lo + "===" + ln);

                citys.AddRange(_hmjCommonService.GetCity());

                BCJ_CITY one = citys.Where(a => citymodel.Contains(a.CITY_NAME)).ToList().FirstOrDefault();

                code = one == null ? "110100" : one.CITY_CODE;
            }

            //加载门店列表
            List <BCJ_STORES_EX> stores = _hmjCommonService.GetStoresByCityCode(code);


            //如果不是定位则计算距离城市中心点的位置
            foreach (BCJ_STORES_EX storeM in stores)
            {
                Poin beigin = new Poin(double.Parse(ln), double.Parse(lo));
                Poin end    = new Poin(double.Parse(storeM.LONGITUDE), double.Parse(storeM.LATITUDE));
                storeM.Distance = Utility.GetDistance(beigin, end).ToString();
                storeM.NAME     = storeM.NAME.Trim();
            }
            return(ResponseJson(false, "添加失败", new
            {
                CIRY_CODE = code,
                CIRYS = citys,
                STORES = stores.OrderBy(a => a.Distance)
            }));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 加载城市信息
        /// </summary>
        /// <returns></returns>
        public int InsertCity()
        {
            List <BCJ_CITY> citys = _book.GetCity();

            JavaScriptSerializer js = new JavaScriptSerializer();

            foreach (var city in citys)
            {
                Thread.Sleep(1000);
                string json = NetHelper.HttpRequest("http://apis.map.qq.com/ws/geocoder/v1/?key=MYVBZ-AO3R3-KVS3G-3OBPF-VNHE5-7VF7M&address=" +
                                                    city.CITY_NAME + "", "",
                                                    "GET", 2000, Encoding.UTF8, "application/json");
                TenAPI api = null;
                if (!json.Contains("查询无结果"))
                {
                    api = js.Deserialize <TenAPI>(json);

                    if (api.status != 0)
                    {
                        api = null;
                    }
                }
                else
                {
                }

                _book.Update(new BCJ_CITY()
                {
                    ID        = city.ID,
                    CITY_CODE = city.CITY_CODE,
                    CITY_NAME = city.CITY_NAME,
                    LATITUDE  = api == null ? "无" : api.result.location.lat,
                    LONGITUDE = api == null ? "无" : api.result.location.lng
                });
            }

            return(1);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 插入门店
        /// </summary>
        /// <returns></returns>
        public int InsertStore()
        {
            try
            {
                dt_GetMd_req req = new dt_GetMd_req();

                TVKO[] ko = new TVKO[]
                {
                    new TVKO()
                    {
                        VKORG = "C004"
                    },
                    new TVKO()
                    {
                        VKORG = "C024"
                    }
                };

                req.ZTVKO = ko;

                dt_GetMd_res resStore = WebApiHelp.GetMd(req);

                JavaScriptSerializer js = new JavaScriptSerializer();

                foreach (ZSAL_MD stroeModel in resStore.INFO_MD)
                {
                    Thread.Sleep(100);
                    //如果门店是激活状态
                    if (stroeModel.VTWEG != "28" && stroeModel.VTWEG != "11")
                    {
                        int id = _repo.CheckStore(stroeModel.ZMD_ID);
                        if (id < 1)
                        {
                            TenAPI api = null;

                            if (!string.IsNullOrEmpty(stroeModel.STRAS))
                            {
                                string json = NetHelper.HttpRequest("http://apis.map.qq.com/ws/geocoder/v1/?key=MYVBZ-AO3R3-KVS3G-3OBPF-VNHE5-7VF7M&address=" +
                                                                    stroeModel.STRAS + "", "",
                                                                    "GET", 2000, Encoding.UTF8, "application/json");

                                if (!json.Contains("查询无结果"))
                                {
                                    api = js.Deserialize <TenAPI>(json);

                                    if (api.status != 0)
                                    {
                                        api = null;
                                    }
                                }
                            }

                            BCJ_STORES model = new BCJ_STORES()
                            {
                                ADDRESS    = stroeModel.STRAS,
                                CITY       = stroeModel.CITY_CODE,
                                CITY_CATE  = stroeModel.ZCITY_TYPE,
                                NAME       = stroeModel.ZMD_MC,
                                POS_CODE   = stroeModel.ZMD_ID,
                                KUNNR_SH   = stroeModel.ZKUNNR_SH,
                                TEL        = stroeModel.TELF1,
                                STORE_TYPE = stroeModel.ZMD_TYPE,
                                LONGITUDE  = api == null ? "无" : api.result.location.lng,
                                LATITUDE   = api == null ? "无" : api.result.location.lat,
                                STATUS     = string.IsNullOrEmpty(stroeModel.ZSTATUS) ? -1 : int.Parse(stroeModel.ZSTATUS)
                            };

                            _repo.Insert(model);
                        }
                        //更新门店信息
                        else
                        {
                            BCJ_STORES model = new BCJ_STORES()
                            {
                                ID        = id,
                                ADDRESS   = stroeModel.STRAS,
                                CITY      = stroeModel.CITY_CODE,
                                CITY_CATE = stroeModel.ZCITY_TYPE,
                                NAME      = stroeModel.ZMD_MC,
                                POS_CODE  = stroeModel.ZMD_ID,
                                KUNNR_SH  = stroeModel.ZKUNNR_SH,
                                TEL       = stroeModel.TELF1,
                                STATUS    = string.IsNullOrEmpty(stroeModel.ZSTATUS) ? -1 : int.Parse(stroeModel.ZSTATUS)
                            };
                            _repo.Update(model);
                        }
                    }
                }

                return(1);
            }
            catch (Exception ex)
            {
                throw;
            }
        }