XYMallAPIManager.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // XYMallAPIManager.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/8/12.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYMallAPIManager.h"
  9. // 根据星芽token登录
  10. static NSString * const MALL_LOGIN_BY_STARBUDS = @"api-common/v1/user/loginByStarbuds";
  11. // 获取商户列表
  12. static NSString * const MALL_GET_SHOP_LIST = @"api-app/v1/unit/getUnitList";
  13. // 查询所有商品列表
  14. static NSString * const MALL_GET_ALL_PRODUCT_LIST = @"api-app/v1/item/getAllProductList";
  15. // 根据商品id批量获取商品列表
  16. static NSString * const MALL_GET_PRODUCT_LIST_BY_IDS = @"api-app/v1/item/getProductsByIds";
  17. // 设置展示商品
  18. static NSString * const MALL_SET_SHOWPRODUCT = @"api-app/v1/live/setShowProduct";
  19. // 获取商品详情
  20. static NSString * const MALL_GET_PRODUCT_INFO = @"api-app/v1/item/getProductInfo";
  21. @implementation XYMallAPIManager
  22. /// 根据星芽token登录
  23. /// @param token 星芽token
  24. /// @param successHandler 请求成功
  25. /// @param failureHandler 请求失败
  26. - (NSNumber *)loginByStarbudsWithToken:(NSString *)token successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  27. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  28. config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, MALL_LOGIN_BY_STARBUDS];
  29. config.instructions = @"根据星芽token登录";
  30. config.requestParameters = @{@"token":token};
  31. return [super dispatchDataTaskWithConfiguration:config successHandler:^(ZYLResponseModel *responseModel) {
  32. if (responseModel.codeState) {
  33. NSString *userId = responseModel.data[@"xyUserId"];
  34. if ([XYUserInfoManager isUser:userId]) {
  35. [XYUserInfoManager nowUser].xkUserId = [BaseMethod toString:responseModel.data[@"xkUserId"]];
  36. [XYUserInfoManager nowUser].xkToken = [BaseMethod toString:responseModel.data[@"xkToken"]];
  37. [XYUserInfoManager commitUserData];
  38. }
  39. }
  40. successHandler ? successHandler(responseModel) : nil;
  41. } failureHandler:failureHandler];
  42. }
  43. /// 获取商户列表
  44. /// @param unitType 商户类型
  45. /// @param unitName 商户名称
  46. /// @param pageIndex 索引
  47. /// @param successHandler 请求成功
  48. /// @param failureHandler 请求失败
  49. - (NSNumber *)getShopListWitUnitType:(NSString *)unitType unitName:(NSString *)unitName pageIndex:(NSInteger)pageIndex successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  50. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  51. config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, MALL_GET_SHOP_LIST];
  52. config.instructions = @"获取商户列表";
  53. config.requestType = ZYLNetworkRequestTypeGet;
  54. NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
  55. [parameters addEntriesFromDictionary:@{@"pageIndex":@(pageIndex)}];
  56. if (StringIsNotEmpty(unitType)) {
  57. [parameters addEntriesFromDictionary:@{@"unitType":unitType}];
  58. }
  59. if (StringIsNotEmpty(unitName)) {
  60. [parameters addEntriesFromDictionary:@{@"unitName":unitName}];
  61. }
  62. config.requestParameters = parameters;
  63. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  64. }
  65. /**
  66. 获取商品列表
  67. @param pageIndex 页码
  68. @param categoryId 类目id 不是必传的
  69. @param productName 产品名称 不是必传的
  70. @param unitId 商户id 不是必传的
  71. @param isPack 是否礼包商品 1.是 0.忽略 -1.否
  72. @param successHandler 请求成功回调
  73. @param failureHandler 请求失败回调
  74. @return 请求标示
  75. */
  76. - (NSNumber *)getAllProductListWithPageIndex:(NSInteger)pageIndex categoryId:(NSString *)categoryId productName:(NSString *)productName unitId:(NSString *)unitId isPack:(NSString *)isPack successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  77. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  78. config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, MALL_GET_ALL_PRODUCT_LIST];
  79. config.instructions = @"获取商品列表";
  80. config.requestType = ZYLNetworkRequestTypeGet;
  81. NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
  82. [parameters addEntriesFromDictionary:@{@"pageIndex":@(pageIndex)}];
  83. if (StringIsNotEmpty(categoryId)) {
  84. [parameters addEntriesFromDictionary:@{@"categoryId":categoryId}];
  85. }
  86. if (StringIsNotEmpty(productName)) {
  87. [parameters addEntriesFromDictionary:@{@"productName":productName}];
  88. }
  89. if (StringIsNotEmpty(unitId)) {
  90. [parameters addEntriesFromDictionary:@{@"unitId":unitId}];
  91. }
  92. if (StringIsNotEmpty(isPack)) {
  93. [parameters addEntriesFromDictionary:@{@"isPack":isPack}];
  94. }
  95. config.requestParameters = parameters;
  96. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  97. }
  98. /// 根据商品id批量获取商品列表
  99. /// @param productIds 商品id,逗号分隔
  100. /// @param successHandler 请求成功
  101. /// @param failureHandler 请求失败
  102. - (NSNumber *)getProductsByIdsWithProductIds:(NSString *)productIds successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  103. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  104. config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, MALL_GET_PRODUCT_LIST_BY_IDS];
  105. config.instructions = @"根据商品id批量获取商品列表";
  106. config.requestType = ZYLNetworkRequestTypeGet;
  107. config.requestParameters = @{@"productIds":productIds};
  108. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  109. }
  110. /// 设置展示商品 api-app/v1/live/setShowProduct
  111. /// @param productId 展示商品 id 传 0 表示取消展示
  112. /// @param successHandler 请求成功
  113. /// @param failureHandler 请求失败
  114. - (NSNumber *)setShowProductById:(NSString *)productId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler{
  115. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  116. //config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, MALL_SET_SHOWPRODUCT];
  117. config.urlPath = [MALL_SET_SHOWPRODUCT copy];
  118. config.instructions = @"设置展示商品";
  119. config.requestType = ZYLNetworkRequestTypePost;
  120. config.requestParameters = @{@"productId":productId};
  121. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  122. }
  123. /// 获取商品详情
  124. /// @param productId 商品id
  125. /// @param successHandler 请求成功
  126. /// @param failureHandler 请求失败
  127. - (NSNumber *)getProductInfoWithProductId:(NSString *)productId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  128. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  129. config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, MALL_GET_PRODUCT_INFO];
  130. config.instructions = @"获取商品详情";
  131. config.requestType = ZYLNetworkRequestTypeGet;
  132. config.requestParameters = @{@"productId":productId};
  133. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  134. }
  135. @end