123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- //
- // XYMallAPIManager.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/8/12.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYMallAPIManager.h"
- // 根据星芽token登录
- static NSString * const MALL_LOGIN_BY_STARBUDS = @"api-common/v1/user/loginByStarbuds";
- // 获取商户列表
- static NSString * const MALL_GET_SHOP_LIST = @"api-app/v1/unit/getUnitList";
- // 查询所有商品列表
- static NSString * const MALL_GET_ALL_PRODUCT_LIST = @"api-app/v1/item/getAllProductList";
- // 根据商品id批量获取商品列表
- static NSString * const MALL_GET_PRODUCT_LIST_BY_IDS = @"api-app/v1/item/getProductsByIds";
- // 设置展示商品
- static NSString * const MALL_SET_SHOWPRODUCT = @"api-app/v1/live/setShowProduct";
- // 获取商品详情
- static NSString * const MALL_GET_PRODUCT_INFO = @"api-app/v1/item/getProductInfo";
- @implementation XYMallAPIManager
- /// 根据星芽token登录
- /// @param token 星芽token
- /// @param successHandler 请求成功
- /// @param failureHandler 请求失败
- - (NSNumber *)loginByStarbudsWithToken:(NSString *)token successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
-
- ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
- config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, MALL_LOGIN_BY_STARBUDS];
- config.instructions = @"根据星芽token登录";
-
- config.requestParameters = @{@"token":token};
-
- return [super dispatchDataTaskWithConfiguration:config successHandler:^(ZYLResponseModel *responseModel) {
- if (responseModel.codeState) {
- NSString *userId = responseModel.data[@"xyUserId"];
- if ([XYUserInfoManager isUser:userId]) {
- [XYUserInfoManager nowUser].xkUserId = [BaseMethod toString:responseModel.data[@"xkUserId"]];
- [XYUserInfoManager nowUser].xkToken = [BaseMethod toString:responseModel.data[@"xkToken"]];
- [XYUserInfoManager commitUserData];
- }
- }
- successHandler ? successHandler(responseModel) : nil;
- } failureHandler:failureHandler];
- }
- /// 获取商户列表
- /// @param unitType 商户类型
- /// @param unitName 商户名称
- /// @param pageIndex 索引
- /// @param successHandler 请求成功
- /// @param failureHandler 请求失败
- - (NSNumber *)getShopListWitUnitType:(NSString *)unitType unitName:(NSString *)unitName pageIndex:(NSInteger)pageIndex successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
-
- ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
- config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, MALL_GET_SHOP_LIST];
- config.instructions = @"获取商户列表";
- config.requestType = ZYLNetworkRequestTypeGet;
-
- NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
- [parameters addEntriesFromDictionary:@{@"pageIndex":@(pageIndex)}];
- if (StringIsNotEmpty(unitType)) {
- [parameters addEntriesFromDictionary:@{@"unitType":unitType}];
- }
- if (StringIsNotEmpty(unitName)) {
- [parameters addEntriesFromDictionary:@{@"unitName":unitName}];
- }
- config.requestParameters = parameters;
-
- return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
- }
- /**
- 获取商品列表
-
- @param pageIndex 页码
- @param categoryId 类目id 不是必传的
- @param productName 产品名称 不是必传的
- @param unitId 商户id 不是必传的
- @param isPack 是否礼包商品 1.是 0.忽略 -1.否
- @param successHandler 请求成功回调
- @param failureHandler 请求失败回调
- @return 请求标示
- */
- - (NSNumber *)getAllProductListWithPageIndex:(NSInteger)pageIndex categoryId:(NSString *)categoryId productName:(NSString *)productName unitId:(NSString *)unitId isPack:(NSString *)isPack successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
-
- ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
- config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, MALL_GET_ALL_PRODUCT_LIST];
- config.instructions = @"获取商品列表";
- config.requestType = ZYLNetworkRequestTypeGet;
-
- NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
- [parameters addEntriesFromDictionary:@{@"pageIndex":@(pageIndex)}];
- if (StringIsNotEmpty(categoryId)) {
- [parameters addEntriesFromDictionary:@{@"categoryId":categoryId}];
- }
- if (StringIsNotEmpty(productName)) {
- [parameters addEntriesFromDictionary:@{@"productName":productName}];
- }
- if (StringIsNotEmpty(unitId)) {
- [parameters addEntriesFromDictionary:@{@"unitId":unitId}];
- }
- if (StringIsNotEmpty(isPack)) {
- [parameters addEntriesFromDictionary:@{@"isPack":isPack}];
- }
- config.requestParameters = parameters;
-
- return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
- }
- /// 根据商品id批量获取商品列表
- /// @param productIds 商品id,逗号分隔
- /// @param successHandler 请求成功
- /// @param failureHandler 请求失败
- - (NSNumber *)getProductsByIdsWithProductIds:(NSString *)productIds successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
-
- ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
- config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, MALL_GET_PRODUCT_LIST_BY_IDS];
- config.instructions = @"根据商品id批量获取商品列表";
- config.requestType = ZYLNetworkRequestTypeGet;
-
- config.requestParameters = @{@"productIds":productIds};
-
- return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
- }
- /// 设置展示商品 api-app/v1/live/setShowProduct
- /// @param productId 展示商品 id 传 0 表示取消展示
- /// @param successHandler 请求成功
- /// @param failureHandler 请求失败
- - (NSNumber *)setShowProductById:(NSString *)productId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler{
- ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
- //config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, MALL_SET_SHOWPRODUCT];
- config.urlPath = [MALL_SET_SHOWPRODUCT copy];
- config.instructions = @"设置展示商品";
- config.requestType = ZYLNetworkRequestTypePost;
-
- config.requestParameters = @{@"productId":productId};
-
- return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
- }
- /// 获取商品详情
- /// @param productId 商品id
- /// @param successHandler 请求成功
- /// @param failureHandler 请求失败
- - (NSNumber *)getProductInfoWithProductId:(NSString *)productId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
-
- ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
- config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, MALL_GET_PRODUCT_INFO];
- config.instructions = @"获取商品详情";
- config.requestType = ZYLNetworkRequestTypeGet;
-
- config.requestParameters = @{@"productId":productId};
-
- return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
- }
- @end
|