SPSBPurchaserOrderListPayViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. //
  2. // SPSBPurchaserOrderListPayViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/6/21.
  6. //
  7. #import "SPSBPurchaserOrderListPayViewController.h"
  8. #import "SPSBTransferOrderListModel.h"
  9. #import "SPSBPurchaseOrderListModel.h"
  10. #import "UIViewController+SPSBNetworkManager.h"
  11. #import "SPSBBusinessManager.h"
  12. #import "SPSBConstantProfile.h"
  13. #import "SPSBAppDifferenceProfile.h"
  14. #import "SPSBQueryListViewController.h"
  15. #import "SPSBPurchasersModel.h"
  16. #import "SPSBBusinessManager.h"
  17. #import "SPSBGeneralManager.h"
  18. #import <JXHGeneralTools.h>
  19. @interface SPSBPurchaserOrderListPayViewController () {
  20. bool _canShowAnimation;
  21. bool _isHaveCardCharge;
  22. }
  23. @end
  24. @implementation SPSBPurchaserOrderListPayViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self judgeData];
  28. }
  29. #pragma mark - Action
  30. - (void)showAnimation {
  31. if (_canShowAnimation) {
  32. [super showAnimation];
  33. }
  34. }
  35. - (void)judgeData {
  36. _canShowAnimation = true;
  37. switch (_spsb_type) {
  38. case SPSBPurchaserOrderListPayTypePay: {
  39. if (_spsb_data.spsba_orderListModelType == SPSBOrderListModelTypePurchase) {
  40. [self setOrderBaseWithOrderType:SPSBOrderTypePurchase totalFee:((SPSBPurchaseOrderListModel *)_spsb_data).spsb_total_fee.floatValue discountCount:_spsb_discountCount orderNumber:((SPSBPurchaseOrderListModel *)_spsb_data).spsb_nums.integerValue showData:nil buttonType:SPSBOrderListPayButtonTypePay];
  41. } else {
  42. [self setOrderBaseWithOrderType:SPSBOrderTypeTransfer totalFee:((SPSBTransferOrderListModel *)_spsb_data).spsb_charge.floatValue discountCount:_spsb_discountCount orderNumber:1 showData:nil buttonType:SPSBOrderListPayButtonTypePay];
  43. }
  44. [self createPayView];
  45. }
  46. break;
  47. case SPSBPurchaserOrderListPayTypeDetails: {
  48. if (_spsb_data.spsba_orderListModelType == SPSBOrderListModelTypePurchase) {
  49. if (_spsb_data.spsba_status.integerValue == 1) {
  50. _canShowAnimation = false;
  51. [self payPurchaseOrderWithshowDetails:true];
  52. } else {
  53. [self setOrderBaseWithOrderType:SPSBOrderTypePurchase totalFee:((SPSBPurchaseOrderListModel *)_spsb_data).spsb_total_fee.floatValue discountCount:_spsb_discountCount orderNumber:((SPSBPurchaseOrderListModel *)_spsb_data).spsb_nums.integerValue showData:_spsb_data.spsba_detailsData buttonType:SPSBOrderListPayButtonTypeQuery];
  54. [self createPayView];
  55. }
  56. } else {
  57. if (_spsb_data.spsba_status.integerValue == 1) {
  58. [self setOrderBaseWithOrderType:SPSBOrderTypeTransfer totalFee:((SPSBTransferOrderListModel *)_spsb_data).spsb_charge.floatValue discountCount:_spsb_discountCount orderNumber:1 showData:_spsb_data.spsba_detailsData buttonType:SPSBOrderListPayButtonTypePay];
  59. } else {
  60. [self setOrderBaseWithOrderType:SPSBOrderTypeTransfer totalFee:((SPSBTransferOrderListModel *)_spsb_data).spsb_charge.floatValue discountCount:_spsb_discountCount orderNumber:1 showData:_spsb_data.spsba_detailsData buttonType:SPSBOrderListPayButtonTypeNone];
  61. }
  62. [self createPayView];
  63. }
  64. }
  65. break;
  66. default:
  67. break;
  68. }
  69. }
  70. - (void)payAction {
  71. switch (_spsb_type) {
  72. case SPSBPurchaserOrderListPayTypePay: {
  73. if (_spsb_data.spsba_orderListModelType == SPSBOrderListModelTypePurchase) {
  74. [self payPurchaseOrderWithshowDetails:false];
  75. } else {
  76. [self payTransferOrder];
  77. }
  78. }
  79. break;
  80. case SPSBPurchaserOrderListPayTypeDetails: {
  81. if (_spsb_data.spsba_orderListModelType == SPSBOrderListModelTypePurchase) {
  82. [self purchasePay];
  83. } else {
  84. [self payTransferOrder];
  85. }
  86. }
  87. break;
  88. default:
  89. break;
  90. }
  91. }
  92. - (void)queryAction {
  93. @weakify(self)
  94. [self dismissContentViewCompletion:^{
  95. @strongify(self)
  96. [self toQueryListView];
  97. }];
  98. }
  99. - (void)toQueryListView {
  100. SPSBPurchaseOrderListModel *model = (SPSBPurchaseOrderListModel *)_spsb_data;
  101. SPSBQueryListViewController *vc = SPSBQueryListViewController.new;
  102. if ([model.spsb_pay_for isEqualToString:SPSBBuyBusinessTypeSocialInsurance] || [model.spsb_pay_for isEqualToString:SPSBBuyBusinessTypeSocialInsurancePack]) {
  103. vc.spsb_isQueryAccumulationFund = false;
  104. } else {
  105. vc.spsb_isQueryAccumulationFund = true;
  106. }
  107. SPSBPurchasersModel *purchasers = SPSBPurchasersModel.new;
  108. purchasers.spsb_id = model.spsb_sbuId;
  109. purchasers.spsb_user_name = model.spsb_u_name;
  110. purchasers.spsb_id_card = model.spsb_id_card;
  111. vc.spsb_purchasers = purchasers;
  112. vc.spsb_year = [model.spsb_start_month substringWithRange:NSMakeRange(0, 4)];
  113. UIViewController *v = jxh_findPresentedViewControllerStartingFrom(spsb_keyWindow().rootViewController);
  114. if (v.navigationController) {
  115. [v.navigationController pushViewController:vc animated:true];
  116. }
  117. }
  118. #pragma mark - Network Action
  119. - (void)payPurchaseOrderWithshowDetails:(bool)showDetails {
  120. SPSBPurchaseOrderListModel *model = (SPSBPurchaseOrderListModel *)_spsb_data;
  121. NSString *path = [model.SPSBPurchaseOrderListModel_isSupplementaryPay isEqualToString:@"1"] ? spsb_appUrl(SPSBUrlGetTotalSupplementaryPayFee) : spsb_appUrl(SPSBUrlGetTotalFee);
  122. @weakify(self)
  123. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:showDetails ? @"正在加载" : @"正在支付" isLogin:true url:path urlParameters:nil parameters:^NSDictionary * _Nonnull{
  124. return @{@"sbuId" : model.spsb_sbuId,
  125. @"cid" : model.spsb_cid,
  126. @"shebao_card" : model.spsb_new_card,
  127. @"hukou_type" : model.spsb_hukou_type,
  128. @"month" : spsb_changeTimeToNumber(model.spsb_start_month),
  129. @"fund" : [NSString stringWithFormat:@"%.2f", [model.spsb_fund floatValue] / [model.SPSBPurchaseOrderListModel_numOfMonth integerValue]],
  130. @"nums" : model.SPSBPurchaseOrderListModel_numOfMonth,
  131. @"pay_for" : model.spsb_pay_for,
  132. @"flow_force": model.spsb_flow_force.length == 0 ? @0 : model.spsb_flow_force,
  133. @"sb_wage": model.spsb_sb_wage
  134. };
  135. } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  136. @strongify(self)
  137. [self getPurchaseBuyTotalFeeNetworkGetData:data showDetails:showDetails];
  138. return showDetails ? @"" : nil;
  139. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  140. @strongify(self)
  141. if (showDetails) {
  142. [self dismissContentViewCompletion:nil];
  143. return @"加载失败";
  144. } else {
  145. if (self.spsb_orderBase.spsb_payFailure) {
  146. self.spsb_orderBase.spsb_payFailure(error);
  147. }
  148. return nil;
  149. }
  150. }];
  151. }
  152. - (void)getPurchaseBuyTotalFeeNetworkGetData:(id)data showDetails:(bool)showDetails {
  153. _isHaveCardCharge = [data[@"data"][@"card_charge"] floatValue] > 0;
  154. if (showDetails) {
  155. SPSBPurchaseOrderListModel *model = (SPSBPurchaseOrderListModel *)_spsb_data;
  156. NSMutableString *titles = [@"" mutableCopy];
  157. NSMutableString *contents = [@"" mutableCopy];
  158. NSInteger lines = 0;
  159. if (![model.spsb_pay_for isEqualToString:SPSBBuyBusinessTypeAccumulationFund]) {
  160. [titles appendString:@"\n社保"];
  161. [contents appendFormat:@"\n¥%.2f", [data[@"data"][@"shebao"] floatValue]];
  162. lines ++;
  163. }
  164. if (![model.spsb_pay_for isEqualToString:SPSBBuyBusinessTypeSocialInsurance]) {
  165. [titles appendString:@"\n公积金"];
  166. [contents appendFormat:@"\n¥%.2f", [data[@"data"][@"fund"] floatValue]];
  167. lines ++;
  168. }
  169. if (model.spsb_flow_force.boolValue) {
  170. [titles appendString:@"\n社保流水"];
  171. [contents appendFormat:@"\n¥%.2f", [data[@"data"][@"flow"] floatValue]];
  172. lines ++;
  173. }
  174. if ([model.spsb_new_card boolValue]) {
  175. [titles appendString:@"\n社保卡"];
  176. [contents appendFormat:@"\n¥%.2f", [data[@"data"][@"card_charge"] floatValue]];
  177. lines ++;
  178. }
  179. [titles appendString:@"\n服务费"];
  180. [contents appendFormat:@"\n¥%.2f", [data[@"data"][@"s_charge"] floatValue] + [data[@"data"][@"f_charge"] floatValue] + [data[@"data"][@"flow_charge"] floatValue]];
  181. lines ++;
  182. if (![titles isEqualToString:@""]) {
  183. [titles deleteCharactersInRange:NSMakeRange(0, 1)];
  184. }
  185. if (![contents isEqualToString:@""]) {
  186. [contents deleteCharactersInRange:NSMakeRange(0, 1)];
  187. }
  188. model.spsba_detailsData.spsb_title = titles;
  189. model.spsba_detailsData.spsb_content = contents;
  190. model.spsba_detailsData.spsb_lines = lines;
  191. model.spsba_detailsData.spsb_amount = [NSString stringWithFormat:@"%.2f元", [data[@"data"][@"total_fee"] floatValue]];
  192. _canShowAnimation = true;
  193. [self setOrderBaseWithOrderType:SPSBOrderTypePurchase totalFee:[data[@"data"][@"total_fee"] floatValue] discountCount:_spsb_discountCount orderNumber:model.spsb_nums.integerValue showData:model.spsba_detailsData buttonType:SPSBOrderListPayButtonTypePay];
  194. [self createPayView];
  195. [self showAnimation];
  196. return;
  197. }
  198. [self purchasePay];
  199. }
  200. - (void)purchasePay {
  201. if (_spsb_data.spsba_orderListBusinessType == SPSBOrderListBusinessTypeSB) {
  202. [self createPurchaseSocialInsuranceOrderWithModel:(SPSBPurchaseOrderListModel *)_spsb_data];
  203. } else if (_spsb_data.spsba_orderListBusinessType == SPSBOrderListBusinessTypeAF) {
  204. [self createPurchaseAccumulationFundOrderWithModel:(SPSBPurchaseOrderListModel *)_spsb_data];
  205. }
  206. }
  207. - (void)createPurchaseSocialInsuranceOrderWithModel:(SPSBPurchaseOrderListModel *)model {
  208. NSString *path = [model.SPSBPurchaseOrderListModel_isSupplementaryPay isEqualToString:@"1"] ? spsb_appUrl(SPSBUrlCreateShebaoSupplementaryPayOrder) : spsb_appUrl(SPSBUrlCreateShebaoOrder);
  209. bool isPack = [model.spsb_pay_for isEqualToString:SPSBBuyBusinessTypeSocialInsurance] || [model.spsb_pay_for isEqualToString:SPSBBuyBusinessTypeAccumulationFund] ? false : true;
  210. @weakify(self)
  211. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在支付" isLogin:true url:path urlParameters:nil parameters:^NSDictionary * _Nonnull{
  212. NSString *fund = [NSString stringWithFormat:@"%.2f", [model.spsb_fund floatValue] / [model.SPSBPurchaseOrderListModel_numOfMonth integerValue]];
  213. return [self getParametersWithParameters:@{@"fund" : isPack == true ? fund : @"0"} model:model];
  214. } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  215. @strongify(self)
  216. SPSBResultServeyType type;
  217. if (isPack) {
  218. type = SPSBResultServeyTypePack;
  219. } else {
  220. type = SPSBResultServeyTypeSB;
  221. }
  222. if (model.spsb_sb_wage.integerValue > 0) {
  223. self.spsb_isNeedSalary = true;
  224. }
  225. [self payActionWithOrderType:self->_isHaveCardCharge ? SPSBOrderTypePurchaseWithSSCard : SPSBOrderTypePurchase serveyType:type payData:data[@"data"] argumentData:nil];
  226. return nil;
  227. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  228. if (self.spsb_orderBase.spsb_payFailure) {
  229. self.spsb_orderBase.spsb_payFailure(error);
  230. }
  231. return nil;
  232. }];
  233. }
  234. - (void)createPurchaseAccumulationFundOrderWithModel:(SPSBPurchaseOrderListModel *)model {
  235. bool isPack = [model.spsb_pay_for isEqualToString:SPSBBuyBusinessTypeSocialInsurance] || [model.spsb_pay_for isEqualToString:SPSBBuyBusinessTypeAccumulationFund] ? false : true;
  236. NSString *path = [model.SPSBPurchaseOrderListModel_isSupplementaryPay isEqualToString:@"1"] ? spsb_appUrl(SPSBUrlCreateFundSupplementaryPayOrder) : spsb_appUrl(SPSBUrlCreateFundOrder);
  237. @weakify(self)
  238. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在支付" isLogin:true url:path urlParameters:nil parameters:^NSDictionary * _Nonnull{
  239. NSString *fund = [NSString stringWithFormat:@"%.2f", [model.spsb_fund floatValue] / [model.SPSBPurchaseOrderListModel_numOfMonth integerValue]];
  240. return [self getParametersWithParameters:@{@"buyShebao" : isPack == true ? @"1" : @"0", @"fund" : fund} model:model];
  241. } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  242. @strongify(self)
  243. SPSBResultServeyType type;
  244. if (isPack) {
  245. type = SPSBResultServeyTypePack;
  246. } else {
  247. type = SPSBResultServeyTypeAF;
  248. }
  249. if (model.spsb_sb_wage.integerValue > 0) {
  250. self.spsb_isNeedSalary = true;
  251. }
  252. [self payActionWithOrderType:self->_isHaveCardCharge ? SPSBOrderTypePurchaseWithSSCard : SPSBOrderTypePurchase serveyType:type payData:data[@"data"] argumentData:nil];
  253. return nil;
  254. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  255. if (self.spsb_orderBase.spsb_payFailure) {
  256. self.spsb_orderBase.spsb_payFailure(error);
  257. }
  258. return nil;
  259. }];
  260. }
  261. - (NSDictionary *)getParametersWithParameters:(NSDictionary *)parameters model:(SPSBPurchaseOrderListModel *)model {
  262. NSMutableDictionary *narmolParameters = [@{@"sbuId" : model.spsb_sbuId,
  263. @"sb_wage": model.spsb_sb_wage,
  264. @"flow_force": model.spsb_flow_force.length == 0 ? @0 : model.spsb_flow_force,
  265. @"working": model.spsb_working,
  266. @"cid" : model.spsb_cid,
  267. @"shebao_card" : model.spsb_new_card,
  268. @"hukou_type" : model.spsb_hukou_type,
  269. @"month" : spsb_changeTimeToNumber(model.spsb_start_month),
  270. @"nums" : model.SPSBPurchaseOrderListModel_numOfMonth,
  271. @"pay_for" : model.spsb_pay_for,
  272. @"first_sb" : model.SPSBPurchaseOrderListModel_isFirstPurchaseShebao,
  273. @"first_fund" : model.SPSBPurchaseOrderListModel_isFirstPurchaseFund,
  274. @"pay_channel" : self.spsb_orderBase.spsb_chosePay == 0 ? SPSBAlipayChannel : SPSBWeChatPayChannel, @"pay_platform": self.spsb_orderBase.spsb_chosePay == 0 ? SPSBAlipayChannel : SPSBWeChatPayChannel,
  275. @"couponuser_id" : self.spsb_orderBase.spsb_cashCouponIds} mutableCopy];
  276. [narmolParameters setValuesForKeysWithDictionary:parameters];
  277. return narmolParameters;
  278. }
  279. - (void)payTransferOrder {
  280. SPSBTransferOrderListModel *model = (SPSBTransferOrderListModel *)_spsb_data;
  281. @weakify(self)
  282. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在支付" isLogin:true url:spsb_appUrl(SPSBUrlCreateTransferOrder) urlParameters:nil parameters:^NSDictionary * _Nonnull{
  283. NSMutableDictionary *parameters = [@{@"user_name" : model.spsb_user_name, @"move_type" : model.spsb_move_type, @"pay_channel" : self.spsb_orderBase.spsb_chosePay == 0 ? SPSBAlipayChannel : SPSBWeChatPayChannel, @"couponuser_id" : self.spsb_orderBase.spsb_cashCouponIds} mutableCopy];
  284. if (![model.spsb_out_city isEqualToString:@""]) {
  285. [parameters setObject:model.spsb_out_city forKey:@"out_city"];
  286. }
  287. if (![model.spsb_into_city isEqualToString:@""]) {
  288. [parameters setObject:model.spsb_into_city forKey:@"into_city"];
  289. }
  290. return parameters;
  291. } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  292. @strongify(self)
  293. [self payActionWithOrderType:SPSBOrderTypeTransfer serveyType:SPSBResultServeyTypeNo payData:data[@"data"] argumentData:nil];
  294. return nil;
  295. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  296. if (self.spsb_orderBase.spsb_payFailure) {
  297. self.spsb_orderBase.spsb_payFailure(error);
  298. }
  299. return nil;
  300. }];
  301. }
  302. #pragma mark - UI
  303. @end