示例#1
0
        public ApiPageResultModel ShopList([FromUri] ShopSearchModel model)
        {
            ApiPageResultModel resultModel = new ApiPageResultModel();

            try
            {
                //根据用户ID查找业主
                IUserBLL ownerBll = BLLFactory <IUserBLL> .GetBLL("UserBLL");

                T_User owner = ownerBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                //如果业主存在
                if (owner != null)
                {
                    //如果验证Token不通过或已过期
                    if (DateTime.Now > owner.TokenInvalidTime || model.Token != owner.Token)
                    {
                        resultModel.Msg = APIMessage.TOKEN_INVALID;
                        return(resultModel);
                    }
                    //更新最近登录时间和Token失效时间
                    owner.LatelyLoginTime  = DateTime.Now;
                    owner.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                    ownerBll.Update(owner);

                    IShopBLL shopBll = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

                    Expression <Func <T_Shop, bool> > where = u => u.Type.Contains(model.Type.ToString());
                    //如果是生活小卖店或五金店
                    if (model.Type == 2 || model.Type == 3)
                    {
                        var placeList = owner.UserPlaces.Select(m => m.PropertyPlaceId);
                        where = PredicateBuilder.And(where, u => u.ShopPlaces.Count(p => placeList.Contains(p.PropertyPlaceId)) > 0);
                    }
                    resultModel.Total  = shopBll.Count(where);
                    resultModel.result = shopBll.GetPageList(where, "Id", false, model.PageIndex).ToList().Select(s => new
                    {
                        Id       = s.Id,
                        ShopName = s.ShopName,
                        Content  = s.MainSale,
                        Phone    = string.IsNullOrEmpty(s.Phone) ? "" : s.Phone,
                        Img      = string.IsNullOrEmpty(s.ImgThumbnail) ? "" : s.ImgThumbnail.Split(';')[0]
                    });
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }
            return(resultModel);
        }