XYDeliveryAPIManager.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //
  2. // XYDeliveryAPIManager.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/8/11.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYDeliveryAPIManager.h"
  9. static NSString * const COMMON_GET_AREA_LIST = @"api-common/v1/data/getAreaList"; //获取区域列表
  10. static NSString * const COMMON_ADD_DELIVERY = @"api-common/v1/delivery/addDelivery"; //创建收货地址
  11. static NSString * const COMMON_GET_DELIVERY_LIST = @"api-common/v1/delivery/getDeliveryList"; //获取收货地址列表
  12. static NSString * const COMMON_GET_DEFAULT_DELIVERY = @"api-common/v1/delivery/getDefaultDelivery"; //获取默认收货地址
  13. static NSString * const COMMON_DELETE_DELIVERY = @"api-common/v1/delivery/delDelivery"; //删除收货地址
  14. static NSString * const COMMON_SET_DEFAULT_DELIVERY = @"api-common/v1/delivery/setDefaultDelivery"; //设默认收货地址
  15. static NSString * const COMMON_MODIFY_DELIVERY = @"api-common/v1/delivery/modifyDelivery"; //编辑收货地址
  16. @implementation XYDeliveryAPIManager
  17. /**
  18. 获取区域列表
  19. @param parentId 父区域id 不传则说明是省级列表
  20. @param successHandler 请求成功回调
  21. @param failureHandler 请求失败回调
  22. @return 请求标示
  23. */
  24. - (NSNumber *)getAreaListWithParentId:(NSString *)parentId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  25. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  26. config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, COMMON_GET_AREA_LIST];
  27. config.instructions = @"获取区域列表";
  28. config.requestType = ZYLNetworkRequestTypeGet;
  29. if (StringIsNotEmpty(parentId)) {
  30. config.requestParameters = @{@"parentId":parentId};
  31. }
  32. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  33. }
  34. /**
  35. 创建收货地址
  36. @param deliveryContactName 收件人
  37. @param deliveryContactPhone 手机号
  38. @param areaId 区域id
  39. @param deliveryAddress 详细地址
  40. @param successHandler 请求成功回调
  41. @param failureHandler 请求失败回调
  42. @return 请求标示
  43. */
  44. - (NSNumber *)addDeliveryWithDeliveryContactName:(NSString *)deliveryContactName deliveryContactPhone:(NSString *)deliveryContactPhone areaId:(NSString *)areaId deliveryAddress:(NSString *)deliveryAddress successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  45. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  46. config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, COMMON_ADD_DELIVERY];
  47. config.instructions = @"创建收货地址";
  48. config.requestParameters = @{@"deliveryContactName":deliveryContactName, @"deliveryContactPhone":deliveryContactPhone, @"areaId":areaId, @"deliveryAddress":deliveryAddress};
  49. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  50. }
  51. /**
  52. 获取收货地址列表
  53. @param pageIndex 页码
  54. @param successHandler 请求成功回调
  55. @param failureHandler 请求失败回调
  56. @return 请求标示
  57. */
  58. - (NSNumber *)getDeliveryListPageIndex:(NSInteger)pageIndex successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  59. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  60. config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, COMMON_GET_DELIVERY_LIST];
  61. config.instructions = @"获取收货地址列表";
  62. config.requestParameters = @{@"pageIndex":@(pageIndex)};
  63. config.requestType = ZYLNetworkRequestTypeGet;
  64. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  65. }
  66. /**
  67. 获取默认收货地址
  68. @param successHandler 请求成功回调
  69. @param failureHandler 请求失败回调
  70. @return 请求标示
  71. */
  72. - (NSNumber *)getDefaultDeliverySuccessHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  73. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  74. config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, COMMON_GET_DEFAULT_DELIVERY];
  75. config.instructions = @"获取默认收货地址";
  76. config.requestType = ZYLNetworkRequestTypeGet;
  77. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  78. }
  79. /**
  80. 删除收货地址
  81. @param deliveryId 要删除的收货地址id
  82. @param successHandler 请求成功回调
  83. @param failureHandler 请求失败回调
  84. @return 请求标示
  85. */
  86. - (NSNumber *)deleteDeliveryWithDeliveryId:(NSString *)deliveryId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  87. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  88. config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, COMMON_DELETE_DELIVERY];
  89. config.instructions = @"删除收货地址";
  90. config.requestParameters = @{@"deliveryId":deliveryId};
  91. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  92. }
  93. /**
  94. 设置默认收货地址
  95. @param deliveryId 收货地址id
  96. @param successHandler 请求成功回调
  97. @param failureHandler 请求失败回调
  98. @return 请求标示
  99. */
  100. - (NSNumber *)setDefaultDeliveryWithDeliveryId:(NSString *)deliveryId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  101. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  102. config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, COMMON_SET_DEFAULT_DELIVERY];
  103. config.instructions = @"设置默认收货地址";
  104. config.requestParameters = @{@"deliveryId":deliveryId};
  105. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  106. }
  107. /**
  108. 编辑收货地址
  109. @param deliveryId 收货地址id
  110. @param deliveryContactName 收件人
  111. @param deliveryContactPhone 联系电话
  112. @param areaId 区域id
  113. @param deliveryAddress 详细地址
  114. @param successHandler 请求成功回调
  115. @param failureHandler 请求失败回调
  116. @return 请求标示
  117. */
  118. - (NSNumber *)modifyDeliveryWithDeliveryId:(NSString *)deliveryId deliveryContactName:(NSString *)deliveryContactName deliveryContactPhone:(NSString *)deliveryContactPhone areaId:(NSString *)areaId deliveryAddress:(NSString *)deliveryAddress successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  119. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  120. config.urlPath = [NSString stringWithFormat:@"%@%@", [ZYLService currentService].mallBaseUrl, COMMON_MODIFY_DELIVERY];
  121. config.instructions = @"编辑收货地址";
  122. config.requestParameters = @{@"deliveryId":deliveryId,
  123. @"deliveryContactName":deliveryContactName,
  124. @"deliveryContactPhone":deliveryContactPhone,
  125. @"areaId":areaId,
  126. @"deliveryAddress":deliveryAddress};
  127. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  128. }
  129. @end