You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aku_new_community/lib/ui/community/community_func.dart

194 lines
6.4 KiB

3 years ago
import 'package:aku_new_community/constants/api.dart';
import 'package:aku_new_community/model/community/activity_item_model.dart';
import 'package:aku_new_community/model/community/board_model.dart';
import 'package:aku_new_community/model/community/community_topic_model.dart';
import 'package:aku_new_community/model/community/hot_news_model.dart';
import 'package:aku_new_community/model/community/my_event_item_model.dart';
3 years ago
import 'package:aku_new_community/model/community/swiper_model.dart';
import 'package:aku_new_community/model/good/category_model.dart';
import 'package:aku_new_community/model/good/market_swiper_model.dart';
import 'package:aku_new_community/models/market/goods_classification.dart';
import 'package:aku_new_community/models/market/goods_popular_model.dart';
import 'package:aku_new_community/models/market/order/goods_home_model.dart';
import 'package:aku_new_community/utils/network/base_list_model.dart';
import 'package:aku_new_community/utils/network/base_model.dart';
import 'package:aku_new_community/utils/network/net_util.dart';
class CommunityFunc {
///查询热门话题
static Future<List<CommunityTopicModel>> getListGambit() async {
BaseListModel model = await NetUtil().getList(
API.community.listGambit,
3 years ago
params: {'pageNum': 1, 'size': 8},
);
if (model.tableList!.length == 0) return [];
3 years ago
return model.tableList!
.map((e) => CommunityTopicModel.fromJson(e))
.toList();
}
///我的动态
static Future<List<MyEventItemModel>> getMyEventItem() async {
BaseListModel model = await NetUtil().getList(
API.community.myEvent,
params: {'pageNum': 1, 'size': 8},
);
if (model.tableList!.length == 0) return [];
return model.tableList!.map((e) => MyEventItemModel.fromJson(e)).toList();
}
///查询热门资讯
static Future<List<HotNewsModel>> getHotNews() async {
BaseListModel model = await NetUtil().getList(
API.community.findHotNews,
params: {'pageNum': 1, 'size': 4},
);
if (model.tableList!.length == 0) return [];
return model.tableList!.map((e) => HotNewsModel.fromJson(e)).toList();
}
///给单个资讯增加浏览量
static Future<String> addViews(int newsId) async {
BaseModel model = await NetUtil().get(
API.community.addViews,
3 years ago
params: {
'newsId': newsId,
},
);
if (model.msg == null) return '';
return (model.msg as String).toString();
}
///查询当天上架的商品数量
static Future<String> getNewProductsTodayNum() async {
BaseModel model = await NetUtil().get(
API.market.newProductsTodayNum,
);
3 years ago
if (model.data! == null) return '0';
return (model.data as int).toString();
}
///查询当前所有的品牌数量
static Future<String> getSettledBrandsNum() async {
BaseModel model = await NetUtil().get(
API.market.settledBrandsNum,
);
3 years ago
if (model.data! == null) return '0';
return (model.data as int).toString();
}
///查询SKU总数
static Future<String> getSkuTotal() async {
BaseModel model = await NetUtil().get(
API.market.skuTotal,
);
3 years ago
if (model.data! == null) return '0';
return (model.data as int).toString();
}
///获取商品分类
3 years ago
static Future<List<GoodsClassification>> getGoodsClassificationList(
int parentId) async {
BaseListModel model = await NetUtil().getList(
API.market.findAllCategoryByParentId,
3 years ago
params: {'pageNum': 1, 'size': 9, 'parentId': parentId},
);
if (model.tableList!.length == 0) return [];
3 years ago
return model.tableList!
.map((e) => GoodsClassification.fromJson(e))
.toList();
}
///商场首页的商品列表
static Future<List<GoodsHomeModel>> getGoodsHomeModelList(
3 years ago
int PageNum,
int size,
int orderBySalesVolume,
int orderByPrice,
) async {
BaseListModel model = await NetUtil().getList(
API.market.findRecommendGoodsList,
3 years ago
params: {
'pageNum': PageNum,
'size': size,
'orderBySalesVolume': orderBySalesVolume,
'orderByPrice': orderByPrice,
},
);
if (model.tableList!.length == 0) return [];
return model.tableList!.map((e) => GoodsHomeModel.fromJson(e)).toList();
}
///查询爆款推荐
3 years ago
static Future<List<GoodsPopularModel>> getGoodsPopularModel(int num) async {
BaseModel model = await NetUtil().get(
API.market.findMaxPopularity,
3 years ago
params: {'num': num},
);
3 years ago
if (model.data!.length == 0) return [];
return (model.data as List)
.map((e) => GoodsPopularModel.fromJson(e))
.toList();
}
3 years ago
///获取所有商品的分类
static Future<List<CategoryModel>> getCategory() async {
BaseModel model = await NetUtil().get(
API.market.findAllCategoryInfo,
);
3 years ago
if (model.data!.length == 0)
return [];
else {
3 years ago
return (model.data as List)
.map((e) => CategoryModel.fromJson(e))
.toList();
}
}
3 years ago
///获取商城的轮播图
static Future<List<MarketSwiperModel>> marketSwiper() async {
BaseModel model = await NetUtil().get(
API.market.findRotationList,
);
3 years ago
if (model.data!.length == 0) return [];
return (model.data as List)
.map((e) => MarketSwiperModel.fromJson(e))
.toList();
}
3 years ago
3 years ago
static Future<ActivityItemModel?> activity() async {
BaseListModel model = await NetUtil().getList(
API.community.activityList,
params: {'pageNum': 1, 'size': 5},
);
3 years ago
if (model.tableList!.length == 0) return null;
return ActivityItemModel.fromJson(model.tableList!.first);
}
static Future<List<ActivityItemModel>> activityList() async {
BaseListModel model = await NetUtil().getList(
API.community.activityList,
params: {'pageNum': 1, 'size': 5},
);
if (model.tableList!.length == 0) return [];
return model.tableList!.map((e) => ActivityItemModel.fromJson(e)).toList();
}
static Future<List<BoardItemModel>> board() async {
BaseListModel model = await NetUtil().getList(
API.community.boardList,
params: {'pageNum': 1, 'size': 5},
);
3 years ago
if (model.tableList!.length == 0) return [];
return model.tableList!.map((e) => BoardItemModel.fromJson(e)).toList();
}
static Future<List<SwiperModel>> swiper() async {
BaseModel model = await NetUtil().get(
API.community.getSwiper,
);
3 years ago
if (model.data!.length == 0) return [];
return (model.data as List).map((e) => SwiperModel.fromJson(e)).toList();
}
}