Esempio n. 1
0
        public APIResult GetPagedList([FromBody] GetPagedListArgsModel args)
        {
            args.OrderName = args.OrderName ?? "";
            if (args.PageSize <= 0)
            {
                args.PageSize = 10;
            }
            if (args.PageIndex == 0)
            {
                args.PageIndex = 1;
            }
            var query = db.Query <CommercialDistrict>()
                        .Where(m => !m.IsDel);

            if (args.Latitude.HasValue && args.Longitude.HasValue)
            {
                //6 范围在±0.61KM
                if (!args.Precision.HasValue)
                {
                    args.Precision = 6;
                }
                var geohash = Geohash.Encode(args.Latitude.Value, args.Longitude.Value, args.Precision.Value);
                var areas   = GetGeoHashExpand(geohash);
                query = query.Where(m => m.GeoHash.StartsWith(areas[0]) ||
                                    m.GeoHash.StartsWith(areas[1]) ||
                                    m.GeoHash.StartsWith(areas[2]) ||
                                    m.GeoHash.StartsWith(areas[3]) ||
                                    m.GeoHash.StartsWith(areas[4]) ||
                                    m.GeoHash.StartsWith(areas[5]) ||
                                    m.GeoHash.StartsWith(areas[6]) ||
                                    m.GeoHash.StartsWith(areas[7])
                                    );
            }

            var list = query
                       .Select(m => new RowItem()
            {
                AddIp     = m.AddIp,
                AddTime   = m.AddTime,
                AddUser   = m.AddUser,
                Flag      = m.Flag,
                Id        = m.Id,
                Address   = m.Address,
                Detail    = m.Detail,
                IsDel     = m.IsDel,
                Latitude  = m.Latitude,
                Longitude = m.Longitude,
                Name      = m.Name
            })
                       .ToPagedList(args.PageIndex, args.PageSize);

            return(Success(new GetPagedListModel()
            {
                PageIndex = list.PageIndex,
                PageSize = list.PageSize,
                TotalCount = list.TotalItemCount,
                Items = list.ToList()
            }));
        }
Esempio n. 2
0
        /// <summary>
        /// lat = latutude
        /// lng = longitude
        /// IsActive = Flag to indicate if node is active [default=true].
        /// </summary>
        public Node(double lat, double lng, bool IsActive = true)
        {
            LeftChild  = null;
            RightChild = null;

            id = Geohash.Encode(lat, lng, precision);

            Lat = lat;
            Lng = lng;

            isActive = IsActive;
        }
Esempio n. 3
0
        public APIResult Update([FromBody] UpdateArgsModel args)
        {
            if (string.IsNullOrEmpty(args.Name))
            {
                throw new ArgumentNullException("Name");
            }
            if (string.IsNullOrEmpty(args.Flag))
            {
                args.Flag = System.Guid.NewGuid().ToString();
            }
            var model = db.Query <Shop>()
                        .Where(m => m.Id == args.Id)
                        .FirstOrDefault();

            if (model == null)
            {
                throw new Exception("数据库记录不存在");
            }

            var brand = db.GetSingle <ShopBrand>(args.ShopBrandId);

            if (brand == null)
            {
                throw new Exception("指定的商铺品牌不存在");
            }
            model.ShopBrand = brand;

            model.Flag          = args.Flag;
            model.Address       = args.Address;
            model.AddressGuide  = args.AddressGuide;
            model.Detail        = args.Detail;
            model.Latitude      = args.Latitude;
            model.Longitude     = args.Longitude;
            model.Name          = args.Name;
            model.OpenTime      = args.OpenTime;
            model.ScoreValue    = args.ScoreValue;
            model.Tel           = args.Tel;
            model.UsePerUser    = args.UsePerUser;
            model.Logo          = args.Logo;
            model.IsShowApplets = args.IsShowApplets;
            model.Phone         = args.Phone;
            if (model.Latitude.HasValue && model.Longitude.HasValue)
            {
                model.GeoHash = Geohash.Encode(model.Latitude.Value, model.Longitude.Value);
            }
            else
            {
                model.GeoHash = string.Empty;
            }
            db.SaveChanges();
            return(Success());
        }
Esempio n. 4
0
        public APIResult Add([FromBody] AddArgsModel args)
        {
            if (string.IsNullOrEmpty(args.Name))
            {
                throw new ArgumentNullException("Name");
            }
            if (string.IsNullOrEmpty(args.Flag))
            {
                args.Flag = System.Guid.NewGuid().ToString();
            }
            var brand = db.GetSingle <ShopBrand>(args.ShopBrandId);

            if (brand == null)
            {
                throw new Exception("指定的商铺品牌不存在");
            }

            var model = new Shop()
            {
                Flag          = args.Flag,
                ShopBrand     = brand,
                AddIp         = GetIp(),
                AddTime       = DateTime.Now,
                AddUser       = GetUsername(),
                Address       = args.Address,
                AddressGuide  = args.AddressGuide,
                Detail        = args.Detail,
                Latitude      = args.Latitude,
                Longitude     = args.Longitude,
                Name          = args.Name,
                OpenTime      = args.OpenTime,
                ScoreValue    = args.ScoreValue,
                Tel           = args.Tel,
                UsePerUser    = args.UsePerUser,
                Logo          = args.Logo,
                IsShowApplets = args.IsShowApplets
            };

            if (model.Latitude.HasValue && model.Longitude.HasValue)
            {
                model.GeoHash = Geohash.Encode(model.Latitude.Value, model.Longitude.Value);
            }
            else
            {
                model.GeoHash = string.Empty;
            }
            db.Add <Shop>(model);
            db.SaveChanges();

            return(Success());
        }
Esempio n. 5
0
        public APIResult Add([FromBody] AddArgsModel args)
        {
            if (string.IsNullOrEmpty(args.Name))
            {
                throw new ArgumentNullException("Name");
            }
            if (string.IsNullOrEmpty(args.Flag))
            {
                args.Flag = System.Guid.NewGuid().ToString();
            }
            if (!args.Status.HasValue)
            {
                args.Status = CommercialDistrictStatus.正常;
            }

            var model = new CommercialDistrict()
            {
                Flag      = args.Flag,
                AddIp     = GetIp(),
                AddTime   = DateTime.Now,
                AddUser   = GetUsername(),
                Address   = args.Address,
                Name      = args.Name,
                Status    = args.Status.Value,
                Detail    = args.Detail,
                Longitude = args.Longitude,
                Latitude  = args.Latitude
            };

            if (model.Latitude.HasValue && model.Longitude.HasValue)
            {
                model.GeoHash = Geohash.Encode(model.Latitude.Value, model.Longitude.Value);
            }
            else
            {
                model.GeoHash = string.Empty;
            }
            db.Add <CommercialDistrict>(model);
            db.SaveChanges();

            return(Success());
        }
Esempio n. 6
0
        public APIResult Update([FromBody] UpdateArgsModel args)
        {
            if (string.IsNullOrEmpty(args.Name))
            {
                throw new ArgumentNullException("Name");
            }
            if (string.IsNullOrEmpty(args.Flag))
            {
                args.Flag = System.Guid.NewGuid().ToString();
            }
            if (!args.Status.HasValue)
            {
                args.Status = CommercialDistrictStatus.正常;
            }

            var model = db.Query <CommercialDistrict>()
                        .Where(m => m.Id == args.Id)
                        .FirstOrDefault();

            if (model == null)
            {
                throw new Exception("数据库记录不存在");
            }
            model.Flag      = args.Flag;
            model.Name      = args.Name;
            model.Status    = args.Status.Value;
            model.Detail    = args.Detail;
            model.Address   = args.Address;
            model.Longitude = args.Longitude;
            model.Latitude  = args.Latitude;
            if (model.Latitude.HasValue && model.Longitude.HasValue)
            {
                model.GeoHash = Geohash.Encode(model.Latitude.Value, model.Longitude.Value);
            }
            else
            {
                model.GeoHash = string.Empty;
            }
            db.SaveChanges();
            return(Success());
        }
        private void update(HttpContext context, JObject httpObject)
        {
            #region
            HttpReSultMode resultMode = new HttpReSultMode();
            TS_ClientUser  Rmodel2    = JsonHelper.FromJson <TS_ClientUser>(httpObject["jsonEntity"].ToString());

            var           Loginmql   = TS_ClientUserSet.SelectAll().Where(TS_ClientUserSet.Id.Equal(Rmodel2.Id));
            TS_ClientUser Loginmodel = OPBiz.GetEntity(Loginmql);

            Rmodel2.WhereExpression    = TS_ClientUserSet.Id.Equal(Rmodel2.Id);
            Rmodel2.UpdateTime         = DateTime.Now;
            Rmodel2.LocationUpdateTime = DateTime.Now;
            Rmodel2.isDeleted          = Loginmodel.isDeleted;;
            Rmodel2.isValid            = Loginmodel.isValid;
            Rmodel2.States             = Loginmodel.States;

            if (Rmodel2.Longitude != null && Rmodel2.Latitude != null)//geohash编码
            {
                double Latitude  = double.Parse(Rmodel2.Latitude.ToString());
                double Longitude = double.Parse(Rmodel2.Longitude.ToString());
                Rmodel2.geohash = Geohash.Encode(Latitude, Longitude);
            }

            if (OPBiz.Update(Rmodel2) > 0)
            {
                resultMode.Code = 11;
                resultMode.Msg  = "更新成功";
                resultMode.Data = "";
            }
            else
            {
                resultMode.Code = -13;
                resultMode.Msg  = "更新失败";
                resultMode.Data = "";
            }
            #endregion
            context.Response.Write(JsonHelper.ToJson(resultMode, true));
            context.Response.End();
        }
Esempio n. 8
0
        public JsonResult EditInfo(TS_Shop DitModle)
        {
            HttpReSultMode ReSultMode = new HttpReSultMode();
            bool           IsAdd      = false;

            if (DitModle.Details != null)
            {
                DitModle.Details = DitModle.Details.Replace("&lt", "<").Replace("&gt", ">");
            }
            else
            {
                DitModle.Details = "";
            }
            DitModle.UpdateTime = DateTime.Now;
            if (DitModle.Longitude != null && DitModle.Latitude != null)//geohash编码
            {
                double Latitude  = double.Parse(DitModle.Latitude.ToString());
                double Longitude = double.Parse(DitModle.Longitude.ToString());
                DitModle.geohash = Geohash.Encode(Latitude, Longitude);
            }
            if (!(DitModle.Id != null && !DitModle.Id.ToString().Equals("00000000-0000-0000-0000-000000000000")))//id为空,是添加
            {
                IsAdd = true;
            }
            if (IsAdd)
            {
                #region 初始化
                DitModle.Id = Guid.NewGuid();

                DitModle.CreateTime  = DateTime.Now;
                DitModle.CreateManId = UserData.Id;
                DitModle.Praises     = 0;
                DitModle.CallCount   = 0;
                DitModle.Clicks      = 0;
                DitModle.States      = 0;
                DitModle.isDeleted   = false;
                DitModle.isValid     = 1;
                DitModle.Star        = 1;
                #endregion
                try
                {
                    OPBiz.Add(DitModle);

                    ReSultMode.Code = 11;
                    ReSultMode.Data = DitModle.Id.ToString();
                    ReSultMode.Msg  = "添加成功";
                }
                catch (Exception e) {
                    ReSultMode.Code = -11;
                    ReSultMode.Data = e.ToString();
                    ReSultMode.Msg  = "添加失败";
                }
            }
            else
            {
                DitModle.WhereExpression = TS_ShopSet.Id.Equal(DitModle.Id);
                var     mqlO     = TS_ShopSet.SelectAll().Where(TS_ShopSet.Id.Equal(DitModle.Id));
                TS_Shop modelOld = OPBiz.GetEntity(mqlO);//旧数据

                #region   能修改的数据
                DitModle.CreateTime  = modelOld.CreateTime;
                DitModle.CreateManId = modelOld.CreateManId;
                DitModle.Praises     = modelOld.Praises;
                DitModle.CallCount   = modelOld.CallCount;
                DitModle.Clicks      = modelOld.Clicks;
                DitModle.States      = modelOld.States;
                DitModle.isDeleted   = modelOld.isDeleted;
                DitModle.isValid     = modelOld.isValid;
                DitModle.Star        = modelOld.Star;
                #endregion
                //TS_ShopModle.ChangedMap.Remove("doctorid");//移除主键值
                if (OPBiz.Update(DitModle) > 0)
                {
                    ReSultMode.Code = 11;
                    ReSultMode.Data = "";
                    ReSultMode.Msg  = "修改成功";
                }
                else
                {
                    ReSultMode.Code = -13;
                    ReSultMode.Data = "";
                    ReSultMode.Msg  = "修改失败";
                }
            }

            return(Json(ReSultMode, JsonRequestBehavior.AllowGet));
        }
Esempio n. 9
0
        // 请求例子  /httpSever/TS_TransactionHandler.ashx?json={"jsonEntity":{"Category":"09","Longitude":"110.22587","Latitude":"25.272585"},"pageIndex":"1","pageSize":"20","action":"GetByCategory"}
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            // context.Response.Write("Hello World");
            HttpReSultMode resultMode = new HttpReSultMode();
            string         Id         = "";
            int            res        = 0;//返回结果行数

            try
            {
                JObject httpObject = JsonHelper.FromJson(context.Request["json"]);
                switch (httpObject["action"].ToString())
                {
                case "GetById":
                    #region
                    Id = FilterTools.FilterSpecial(httpObject["jsonEntity"]["Id"].ToString());
                    var            mqlG   = TS_TransactionSet.SelectAll().Where(TS_TransactionSet.Id.Equal(Id));
                    TS_Transaction modelG = OPBiz.GetEntity(mqlG);
                    if (modelG != null)
                    {
                        resultMode.Code = 11;
                        resultMode.Msg  = "获取成功";
                        resultMode.Data = JsonHelper.ToJson(modelG, true);
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Msg  = "数据不存在";
                        resultMode.Data = "";
                    }
                    #endregion

                    break;

                case "GetByCategory":
                    this.GetByCategory(context, httpObject, resultMode);
                    break;

                case "add":
                    #region
                    TS_Transaction Rmodel = JsonHelper.FromJson <TS_Transaction>(httpObject["jsonEntity"].ToString());
                    Rmodel.Id         = Guid.NewGuid();
                    Rmodel.CreateTime = DateTime.Now;
                    Rmodel.CreateTime = DateTime.Now;
                    Rmodel.isDeleted  = false;
                    Rmodel.isValid    = 1;
                    Rmodel.Clicks     = 0;
                    Rmodel.Praises    = 0;
                    Rmodel.CallCount  = 0;
                    Rmodel.States     = 0;
                    Rmodel.isTop      = 0;

                    if (Rmodel.Longitude != null && Rmodel.Latitude != null)    //geohash编码
                    {
                        double Latitude  = double.Parse(Rmodel.Latitude.ToString());
                        double Longitude = double.Parse(Rmodel.Longitude.ToString());
                        Rmodel.geohash = Geohash.Encode(Latitude, Longitude);
                    }


                    OPBiz.Add(Rmodel);
                    resultMode.Code = 11;
                    resultMode.Msg  = "添加成功";
                    resultMode.Data = Rmodel.Id.ToString();

                    #endregion
                    break;

                case "update":
                    #region
                    TS_Transaction Rmodel2 = JsonHelper.FromJson <TS_Transaction>(httpObject["jsonEntity"].ToString());
                    var            mqlu    = TS_TransactionSet.SelectAll().Where(TS_TransactionSet.Id.Equal(Rmodel2.Id));
                    TS_Transaction modelu  = OPBiz.GetEntity(mqlu);
                    Rmodel2.CreateTime = modelu.CreateTime;
                    Rmodel2.CreateTime = DateTime.Now;
                    Rmodel2.isDeleted  = modelu.isDeleted;
                    Rmodel2.isValid    = modelu.isValid;
                    Rmodel2.Clicks     = modelu.Clicks;
                    Rmodel2.Praises    = modelu.Praises;
                    Rmodel2.CallCount  = modelu.CallCount;
                    Rmodel2.States     = modelu.States;

                    if (Rmodel2.Longitude != null && Rmodel2.Latitude != null)    //geohash编码
                    {
                        double Latitude  = double.Parse(Rmodel2.Latitude.ToString());
                        double Longitude = double.Parse(Rmodel2.Longitude.ToString());
                        Rmodel2.geohash = Geohash.Encode(Latitude, Longitude);
                    }


                    Rmodel2.WhereExpression = TS_TransactionSet.Id.Equal(Rmodel2.Id);
                    Rmodel2.UpdateTime      = DateTime.Now;
                    if (OPBiz.Update(Rmodel2) > 0)
                    {
                        resultMode.Code = 11;
                        resultMode.Msg  = "更新成功";
                        resultMode.Data = "";
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Msg  = "更新失败";
                        resultMode.Data = "";
                    }
                    #endregion
                    break;

                case "ClickCount":    //点击量
                    Id  = FilterTools.FilterSpecial(httpObject["jsonEntity"]["Id"].ToString());
                    res = OPBiz.SetCout("Id", Id, "Clicks");
                    if (res > 0)
                    {
                        resultMode.Code = 11;
                        resultMode.Data = res.ToString();
                        resultMode.Msg  = "统计成功";
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Data = "0";
                        resultMode.Msg  = "统计失败!";
                    }


                    break;

                case "PraiseCount":    //点赞量加1
                    Id  = FilterTools.FilterSpecial(httpObject["jsonEntity"]["Id"].ToString());
                    res = OPBiz.SetCout("Id", Id, "Praises");
                    if (res > 0)
                    {
                        resultMode.Code = 11;
                        resultMode.Data = res.ToString();
                        resultMode.Msg  = "统计成功";
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Data = "0";
                        resultMode.Msg  = "统计失败!";
                    }


                    break;

                case "CallCount":    //呼叫量加1
                    Id  = FilterTools.FilterSpecial(httpObject["jsonEntity"]["Id"].ToString());
                    res = OPBiz.SetCout("Id", Id, "CallCount");
                    if (res > 0)
                    {
                        resultMode.Code = 11;
                        resultMode.Data = res.ToString();
                        resultMode.Msg  = "统计成功";
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Data = "0";
                        resultMode.Msg  = "统计失败!";
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                resultMode.Code = -11;
                resultMode.Data = ex.ToString();
            }
            context.Response.Write(JsonHelper.ToJson(resultMode, true));
            context.Response.End();
        }
Esempio n. 10
0
        public override SetUserPosResponseBody ExecuteCore()
        {
            SetUserPosResponseBody res = new SetUserPosResponseBody();

            //{
            //    "UserId": 1,
            //    "UserPos": {
            //        "Country": "中国",
            //        "Province": "上海市",
            //        "City": "上海市",
            //        "District": "闵行区",
            //        "Details": "上海市闵行区浦申路靠近上海闵行区金色阳光世博幼儿园",
            //        "Latitude": 31.0732898712158,
            //        "Longitude": 121.507202148438
            //    }
            //}

            using (HWLEntities db = new HWLEntities())
            {
                //检测是否存在country province city district 没有就添加
                t_country country = db.t_country.Where(c => c.name == this.request.Country).FirstOrDefault();
                if (country == null)
                {
                    country = new t_country()
                    {
                        id   = 0,
                        name = this.request.Country,
                    };
                    db.t_country.Add(country);
                    db.SaveChanges();
                }

                t_province province = db.t_province.Where(p => p.name == this.request.Province).FirstOrDefault();
                if (province == null)
                {
                    province = new t_province()
                    {
                        id         = 0,
                        country_id = country.id,
                        name       = this.request.Province,
                    };
                    db.t_province.Add(province);
                    db.SaveChanges();
                }

                t_city city = db.t_city.Where(c => c.name == this.request.City).FirstOrDefault();
                if (city == null)
                {
                    city = new t_city()
                    {
                        id          = 0,
                        province_id = province.id,
                        name        = this.request.City,
                    };
                    db.t_city.Add(city);
                    db.SaveChanges();
                }

                t_district district = db.t_district.Where(p => p.name == this.request.District).FirstOrDefault();
                if (district == null)
                {
                    district = new t_district()
                    {
                        id      = 0,
                        city_id = city.id,
                        name    = this.request.District,
                    };
                    db.t_district.Add(district);
                    db.SaveChanges();
                }

                //检测用户是否已经存在当前位置信息(条件,用户id,位置id,位置详情)
                t_user_pos upos = db.t_user_pos.Where(u => u.user_id == this.request.UserId &&
                                                      u.country_id == country.id &&
                                                      u.province_id == province.id &&
                                                      u.city_id == city.id &&
                                                      u.district_id == district.id &&
                                                      u.pos_details == this.request.Details
                                                      ).FirstOrDefault();
                if (upos == null)
                {
                    //向用户位置表中加入数据
                    upos = new t_user_pos()
                    {
                        id          = 0,
                        create_date = DateTime.Now,
                        update_date = DateTime.Now,
                        geohash_key = Geohash.Encode(this.request.Latitude, this.request.Longitude),
                        lat         = this.request.Latitude,
                        lon         = this.request.Longitude,
                        pos_details = this.request.Details,
                        user_id     = this.request.UserId,
                        city_id     = city.id,
                        country_id  = country.id,
                        district_id = district.id,
                        province_id = province.id,
                    };
                    db.t_user_pos.Add(upos);
                }
                else
                {
                    upos.update_date = DateTime.Now;
                }

                db.SaveChanges();
                res.Status    = ResultStatus.Success;
                res.UserPosId = upos.id;

                //保存用户的位置到redis
                Redis.UserAction userAction = new Redis.UserAction();
                userAction.SavePos(upos.user_id, upos.lon, upos.lat);

                //获取当前位置附近的组
                Redis.GroupAction groupAction = new Redis.GroupAction();
                res.UserGroupGuid = groupAction.GetNearGroupGuid(upos.lon, upos.lat);
                if (string.IsNullOrEmpty(res.UserGroupGuid))
                {
                    //如果没有组数据,创建一个组
                    res.UserGroupGuid = groupAction.CreateNearGroupPos(upos.lon, upos.lat);
                    //将用户加入到组中
                    groupAction.SaveGroupUser(res.UserGroupGuid, upos.user_id);
                }
                else
                {
                    if (groupAction.ExistsInGroup(res.UserGroupGuid, upos.user_id))
                    {
                        //如果用户当前所在位置与上次所在的位置不一样,则需要将用户从上次的群组里面移出来
                        if (!string.IsNullOrEmpty(this.request.LastGroupGuid) && this.request.LastGroupGuid != res.UserGroupGuid)
                        {
                            groupAction.DeleteGroupUser(this.request.LastGroupGuid, upos.user_id);
                        }

                        return(res);
                    }
                    else
                    {
                        //将用户加入到组中
                        groupAction.SaveGroupUser(res.UserGroupGuid, upos.user_id);
                    }
                }

                //如果用户当前所在位置与上次所在的位置不一样,则需要将用户从上次的群组里面移出来
                if (!string.IsNullOrEmpty(this.request.LastGroupGuid) && this.request.LastGroupGuid != res.UserGroupGuid)
                {
                    groupAction.DeleteGroupUser(this.request.LastGroupGuid, upos.user_id);
                }

                //返回组用户列表
                List <int> userIds = groupAction.GetGroupUserIds(res.UserGroupGuid);
                if (userIds == null || userIds.Count <= 0)
                {
                    return(res);
                }

                res.GroupUserInfos = db.t_user.Where(u => userIds.Contains(u.id))
                                     .Select(u => new UserSecretInfo()
                {
                    UserId    = u.id,
                    UserName  = u.name,
                    UserImage = u.head_image,
                }).ToList();
            }

            return(res);
        }
Esempio n. 11
0
        public JsonResult EditInfo(TS_ClientUser TS_ClientUserModle)
        {
            HttpReSultMode ReSultMode = new HttpReSultMode();

            if (TS_ClientUserModle.Longitude != null && TS_ClientUserModle.Latitude != null)//geohash编码
            {
                double Latitude  = double.Parse(TS_ClientUserModle.Latitude.ToString());
                double Longitude = double.Parse(TS_ClientUserModle.Longitude.ToString());
                TS_ClientUserModle.geohash = Geohash.Encode(Latitude, Longitude);
            }

            bool IsAdd = false;

            if (TS_ClientUserModle.Details != null)
            {
                TS_ClientUserModle.Details = TS_ClientUserModle.Details.Replace("&lt", "<").Replace("&gt", ">");
            }
            else
            {
                TS_ClientUserModle.Details = "";
            }
            TS_ClientUserModle.UpdateTime = DateTime.Now;
            if (!(TS_ClientUserModle.Id != null && !TS_ClientUserModle.Id.ToString().Equals("00000000-0000-0000-0000-000000000000")))//id为空,是添加
            {
                IsAdd = true;
            }
            if (IsAdd)
            {
                TS_ClientUserModle.Category           = "";
                TS_ClientUserModle.isDeleted          = false;
                TS_ClientUserModle.isValid            = 1;
                TS_ClientUserModle.Id                 = Guid.NewGuid();
                TS_ClientUserModle.AddTime            = DateTime.Now;
                TS_ClientUserModle.LocationUpdateTime = DateTime.Now;
                try
                {
                    OPBiz.Add(TS_ClientUserModle);

                    ReSultMode.Code = 11;
                    ReSultMode.Data = TS_ClientUserModle.Id.ToString();
                    ReSultMode.Msg  = "添加成功";
                }
                catch (Exception e) {
                    ReSultMode.Code = -11;
                    ReSultMode.Data = e.ToString();
                    ReSultMode.Msg  = "添加失败";
                }
            }
            else
            {
                TS_ClientUserModle.WhereExpression = TS_ClientUserSet.Id.Equal(TS_ClientUserModle.Id);
                //TS_ClientUserModle.ChangedMap.Remove("doctorid");//移除主键值
                if (OPBiz.Update(TS_ClientUserModle) > 0)
                {
                    ReSultMode.Code = 11;
                    ReSultMode.Data = "";
                    ReSultMode.Msg  = "修改成功";
                }
                else
                {
                    ReSultMode.Code = -13;
                    ReSultMode.Data = "";
                    ReSultMode.Msg  = "修改失败";
                }
            }

            return(Json(ReSultMode, JsonRequestBehavior.AllowGet));
        }
Esempio n. 12
0
        //[Authorize(AuthenticationSchemes = "jwt")]
        public APIResult GetPagedList([FromBody] GetPagedListArgsModel args)
        {
            args.OrderName = args.OrderName ?? "";
            if (args.PageSize <= 0)
            {
                args.PageSize = 10;
            }
            if (args.PageIndex == 0)
            {
                args.PageIndex = 1;
            }
            var query = db.Query <Shop>()
                        .Where(m => !m.IsDel);

            if (args.Latitude.HasValue && args.Longitude.HasValue)
            {
                //6 范围在±0.61KM
                var geohash = Geohash.Encode(args.Latitude.Value, args.Longitude.Value, 6);
                var areas   = GetGeoHashExpand(geohash);
                query = query.Where(m => m.GeoHash.StartsWith(areas[0]) ||
                                    m.GeoHash.StartsWith(areas[1]) ||
                                    m.GeoHash.StartsWith(areas[2]) ||
                                    m.GeoHash.StartsWith(areas[3]) ||
                                    m.GeoHash.StartsWith(areas[4]) ||
                                    m.GeoHash.StartsWith(areas[5]) ||
                                    m.GeoHash.StartsWith(areas[6]) ||
                                    m.GeoHash.StartsWith(areas[7])
                                    );
            }

            var list = query
                       .Select(m => new RowItem()
            {
                AddIp        = m.AddIp,
                AddTime      = m.AddTime,
                AddUser      = m.AddUser,
                Flag         = m.Flag,
                Id           = m.Id,
                Address      = m.Address,
                AddressGuide = m.AddressGuide,
                Detail       = m.Detail,
                IsDel        = m.IsDel,
                Latitude     = m.Latitude,
                Longitude    = m.Longitude,
                Name         = m.Name,
                OpenTime     = m.OpenTime,
                ScoreValue   = m.ScoreValue,
                Tel          = m.Tel,
                UsePerUser   = m.UsePerUser,
                Cover        = m.Cover,
                Logo         = m.Logo
            })
                       .ToPagedList(args.PageIndex, args.PageSize);

            return(Success(new GetPagedListModel()
            {
                PageIndex = list.PageIndex,
                PageSize = list.PageSize,
                TotalCount = list.TotalItemCount,
                Items = list.Where(r => r.IsShowApplets == true).ToList()
            }));
        }
        // 请求例子 /httpSever/TS_ClientUserHandler.ashx?json={"jsonEntity":{"UserName":"******","Pwd":"123456"},"action":"Login"}
        // 请求例子  /httpSever/TS_ClientUserHandler.ashx?json={"jsonEntity":{"UserName":"******","Pwd":"123456"},"action":"Register"}
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            // context.Response.Write("Hello World");
            HttpReSultMode resultMode = new HttpReSultMode();

            try
            {
                JObject httpObject = JsonHelper.FromJson(context.Request["json"]);
                // JObject ObjectParameter = (JObject)JsonConvert.DeserializeObject(httpObject["jsonEntity"].ObjToStr());
                string jsonData = httpObject["jsonEntity"].ToString();
                string UserName = "";
                string Pwd      = "";
                switch (httpObject["action"].ToString())
                {
                case "Register":

                    UserName = FilterTools.FilterSpecial(httpObject["jsonEntity"]["UserName"].ToString());
                    var           registermql   = TS_ClientUserSet.SelectAll().Where(TS_ClientUserSet.UserName.Equal(UserName));
                    TS_ClientUser registermodel = OPBiz.GetEntity(registermql);
                    if (registermodel != null)
                    {
                        resultMode.Code = -13;
                        resultMode.Msg  = "用户已经存在";
                        resultMode.Data = "";
                    }
                    else
                    {
                        TS_ClientUser Rmodel = JsonHelper.FromJson <TS_ClientUser>(jsonData);
                        Rmodel.Id                 = Guid.NewGuid();
                        Rmodel.AddTime            = DateTime.Now;
                        Rmodel.UpdateTime         = DateTime.Now;
                        Rmodel.LocationUpdateTime = DateTime.Now;
                        Rmodel.isDeleted          = false;
                        Rmodel.States             = 0;

                        if (Rmodel.Longitude != null && Rmodel.Latitude != null)    //geohash编码
                        {
                            double Latitude  = double.Parse(Rmodel.Latitude.ToString());
                            double Longitude = double.Parse(Rmodel.Longitude.ToString());
                            Rmodel.geohash = Geohash.Encode(Latitude, Longitude);
                        }

                        OPBiz.Add(Rmodel);

                        resultMode.Code = 11;
                        resultMode.Msg  = "注册成功";
                        resultMode.Data = Rmodel.Id.ToString();
                    }

                    break;

                case "Login":
                    UserName = FilterTools.FilterSpecial(httpObject["jsonEntity"]["UserName"].ToString());
                    Pwd      = httpObject["jsonEntity"]["Pwd"].ToString();
                    var           Loginmql   = TS_ClientUserSet.SelectAll().Where(TS_ClientUserSet.UserName.Equal(UserName).And(TS_ClientUserSet.Pwd.Equal(Pwd)));
                    TS_ClientUser Loginmodel = OPBiz.GetEntity(Loginmql);
                    if (Loginmodel != null)
                    {
                        resultMode.Code = 11;
                        resultMode.Msg  = "登录成功";
                        resultMode.Data = JsonHelper.ToJson(Loginmodel, true);
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Msg  = "用户或密码错误";
                        resultMode.Data = "";
                    }
                    break;

                case "ChangePassword":
                    UserName = FilterTools.FilterSpecial(httpObject["jsonEntity"]["UserName"].ToString());
                    Pwd      = httpObject["jsonEntity"]["Pwd"].ToString();
                    var           mqlG   = TS_ClientUserSet.SelectAll().Where(TS_ClientUserSet.UserName.Equal(UserName));
                    TS_ClientUser modelG = OPBiz.GetEntity(mqlG);
                    if (modelG != null)
                    {
                        modelG.Pwd             = Pwd;
                        modelG.UpdateTime      = DateTime.Now;
                        modelG.WhereExpression = TS_ClientUserSet.Id.Equal(modelG.Id);
                        if (OPBiz.Update(modelG) > 0)
                        {
                            resultMode.Code = 11;
                            resultMode.Msg  = "修改密码成功";
                            resultMode.Data = "";
                        }
                        else
                        {
                            resultMode.Code = -13;
                            resultMode.Msg  = "修改失败";
                            resultMode.Data = "";
                        }
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Msg  = "用户不存在";
                        resultMode.Data = "";
                    }


                    break;

                case "update":
                    this.update(context, httpObject);
                    break;
                }
            }
            catch (Exception ex)
            {
                resultMode.Code = -1;
                resultMode.Data = ex.ToString();
            }
            context.Response.Write(JsonHelper.ToJson(resultMode, true));
            context.Response.End();
        }
Esempio n. 14
0
        public t_user_pos SavePos()
        {
            try
            {
                #region Save t_country,t_province,t_city,t_district,t_town
                t_country country = db.t_country.Where(c => c.name == this.request.Country).FirstOrDefault();
                if (country == null)
                {
                    country = new t_country()
                    {
                        id   = 0,
                        name = this.request.Country,
                    };
                    db.t_country.Add(country);
                    db.SaveChanges();
                }

                t_province province = db.t_province.Where(p => p.name == this.request.Province).FirstOrDefault();
                if (province == null)
                {
                    province = new t_province()
                    {
                        id         = 0,
                        country_id = country.id,
                        name       = this.request.Province,
                    };
                    db.t_province.Add(province);
                    db.SaveChanges();
                }

                t_city city = db.t_city.Where(c => c.name == this.request.City).FirstOrDefault();
                if (city == null)
                {
                    city = new t_city()
                    {
                        id          = 0,
                        province_id = province.id,
                        name        = this.request.City,
                    };
                    db.t_city.Add(city);
                    db.SaveChanges();
                }

                t_district district = db.t_district.Where(p => p.name == this.request.District).FirstOrDefault();
                if (district == null)
                {
                    district = new t_district()
                    {
                        id      = 0,
                        city_id = city.id,
                        name    = this.request.District,
                    };
                    db.t_district.Add(district);
                    db.SaveChanges();
                }

                t_town town = db.t_town.Where(p => p.name == this.request.Town).FirstOrDefault();
                if (town == null)
                {
                    town = new t_town()
                    {
                        id          = 0,
                        district_id = district.id,
                        name        = this.request.Town,
                    };
                    db.t_town.Add(town);
                    db.SaveChanges();
                }
                #endregion

                //t_user_pos upos = db.t_user_pos.Where(u => u.user_id == this.request.UserId &&
                //                                            u.country_id == country.id &&
                //                                            u.province_id == province.id &&
                //                                            u.city_id == city.id &&
                //                                            u.district_id == district.id &&
                //                                            u.pos_details == this.request.Details
                //                                        ).FirstOrDefault();
                t_user_pos upos = db.t_user_pos.Where(u => u.user_id == this.request.UserId &&
                                                      u.lon == request.Longitude &&
                                                      u.lat == request.Latitude
                                                      ).FirstOrDefault();
                if (upos == null)
                {
                    upos = new t_user_pos()
                    {
                        id              = 0,
                        create_date     = DateTime.Now,
                        update_date     = DateTime.Now,
                        geohash_key     = Geohash.Encode(this.request.Latitude, this.request.Longitude),
                        lat             = this.request.Latitude,
                        lon             = this.request.Longitude,
                        pos_details     = this.request.Details,
                        user_id         = this.request.UserId,
                        city_id         = city.id,
                        country_id      = country.id,
                        district_id     = district.id,
                        province_id     = province.id,
                        coordinate_type = request.CoorType,
                        location_type   = request.LocationType,
                        Location_where  = request.LocationWhere,
                        radius          = request.Radius,
                        town_id         = town.id,
                    };
                    db.t_user_pos.Add(upos);
                }
                else
                {
                    upos.update_date = DateTime.Now;
                }

                db.SaveChanges();
                return(upos);
            }
            catch (Exception ex)
            {
                string currentParams = Newtonsoft.Json.JsonConvert.SerializeObject(request);
                LogHelper.Error(currentParams + "___" + ex.ToString(), typeof(SetUserPos));
            }
            return(null);
        }