/// <summary> /// 获取分页商品列表 /// </summary> /// <param name="pageIndex">页码0-...</param> /// <param name="goodsPayType">商品交易类型:0.2人拼团,1.2-6人拼团,2.1分夺宝</param> /// <returns></returns> public string GetGoodsList(int pageIndex, int goodsPayType) { BaseResponseModel <List <GoodsModel> > responseModel = new BaseResponseModel <List <GoodsModel> >(); responseModel.StatusCode = (int)ActionParams.code_ok; try { var filter = Builders <GoodsModel> .Filter.Eq(x => x.GoodsPayType, goodsPayType); var find = new MongoDBTool().GetMongoCollection <GoodsModel>().Find(filter).Skip(pageIndex * pageSize); var count = find.Count(); var pageSum = (count / pageSize) + (count % pageSize == 0 ? 0 : 1); List <GoodsModel> GoodsModelList = null; if (pageSum >= pageIndex + 1) { GoodsModelList = find.Skip(pageIndex * pageSize).Limit(pageSize).ToList(); if (GoodsModelList == null || GoodsModelList.Count == 0) { responseModel.StatusCode = (int)ActionParams.code_error_null; } } else { responseModel.StatusCode = (int)ActionParams.code_null; } responseModel.JsonData = GoodsModelList; } catch (Exception) { responseModel.StatusCode = (int)ActionParams.code_error; } JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings(); jsonSerializerSettings.ContractResolver = new LimitPropsContractResolver(new string[] { "StatusCode", "JsonData", "GoodsID", "GoodsTitle", "GoodsPrice", "GoodsSales", "GoodsListImage", "FileUrlData" }); return(JsonConvert.SerializeObject(responseModel, jsonSerializerSettings)); }