RQPlaceBuyItemViewModel.m 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // RQPlaceBuyItemViewModel.m
  3. // JiaPei
  4. //
  5. // Created by 张嵘 on 2023/4/19.
  6. //
  7. #import "RQPlaceBuyItemViewModel.h"
  8. @interface RQPlaceBuyItemViewModel ()
  9. @property (nonatomic, readwrite, strong) RQPlaceListModel *placeListModel;
  10. @property (nonatomic, readwrite, assign) BOOL isBuy;
  11. @property (nonatomic, readwrite, assign) BOOL chooseAgree;
  12. @end
  13. @implementation RQPlaceBuyItemViewModel
  14. - (instancetype)initWithPlaceListModel:(RQPlaceListModel *)placeListModel {
  15. if (self = [super init]) {
  16. @weakify(self)
  17. // if ([RQ_USER_MANAGER.currentUser.loginCode isEqualToString:@"350881199205290949"]) {//特殊审核账号
  18. // placeListModel.isCheckVip = YES;
  19. // }
  20. self.placeListModel = placeListModel;
  21. CGFloat width = RQ_SCREEN_WIDTH - 32.f;
  22. self.rowHeight = (width * (56.f / 345.f)) + 16 + 20 + 16;
  23. RAC(self, isBuy) = [[RACObserve(placeListModel, isCheckVip) deliverOnMainThread] takeUntil:self.rac_willDeallocSignal];
  24. [[[[RACObserve(RQ_COMMON_MANAGER, vipListArr) deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] skip:1] subscribeNext:^(id _Nullable x) {
  25. BOOL isBuy = [RQ_COMMON_MANAGER.vipListArr containsObject:placeListModel.name];
  26. placeListModel.isCheckVip = isBuy;
  27. }];
  28. self.operation = ^{
  29. @strongify(self)
  30. if (self.isAgree) {
  31. if (self.isBuy) {
  32. } else {
  33. [QMUITips showLoading:@"下单中..." inView:DefaultTipsParentView];
  34. [[RQ_HTTP_Service postPrepareOrderWithGoodsId:[NSString qmui_stringWithNSInteger:placeListModel.id] userId:RQ_USER_MANAGER.currentUser._id goodsType:RQGoodsType_Place] subscribeNext:^(RQPrepareOrderModel *prepareOrderModel) {
  35. [QMUITips hideAllTips];
  36. // 发起微信支付,设置参数
  37. //需要创建这个支付对象
  38. PayReq *req = [[PayReq alloc] init];
  39. //由用户微信号和AppID组成的唯一标识,用于校验微信用户
  40. req.openID = RQ_WECHAT_MANAGER.appID;
  41. // 商家id,在注册的时候给的
  42. req.partnerId = prepareOrderModel.partnerId;
  43. // 预支付订单这个是后台跟微信服务器交互后,微信服务器传给你们服务器的,你们服务器再传给你
  44. req.prepayId = prepareOrderModel.prepayId;
  45. // 根据财付通文档填写的数据和签名
  46. req.package = prepareOrderModel.packageValue;
  47. // 随机编码,为了防止重复的,在后台生成
  48. req.nonceStr = prepareOrderModel.nonceStr;
  49. // 这个是时间戳,也是在后台生成的,为了验证支付的
  50. NSString * stamp = prepareOrderModel.timeStamp;
  51. req.timeStamp = (UInt32)stamp.intValue;
  52. // 这个签名也是后台做的
  53. req.sign = prepareOrderModel.sign;
  54. [RQWechatManager hangleWechatPayWith:req];
  55. } error:^(NSError * _Nullable error) {
  56. [QMUITips hideAllTips];
  57. [QMUITips showError:[NSError rq_tipsFromError:error]];
  58. }];
  59. }
  60. } else {
  61. [[RACScheduler mainThreadScheduler] schedule:^{
  62. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"请阅读用户协议!才能购买考场会员哦!" confirmTitle:@"立即阅读" cancelTitle:@"取消" confirmAction:^{
  63. @strongify(self)
  64. self.chooseAgree = YES;
  65. NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://ys.zzxcx.net/jsjp-sf.html"]];
  66. RQWebViewModel *viewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey : request,RQViewModelWebViewTypeKey:@(RQWebViewType_VIP)}];
  67. RQWebViewViewController *viewController = [[RQWebViewViewController alloc] initWithViewModel:viewModel];
  68. RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:viewController];
  69. [RQControllerHelper.currentViewController presentViewController:nav animated:YES completion:nil];
  70. } cancelAction:nil];
  71. }];
  72. }
  73. };
  74. }
  75. return self;
  76. }
  77. - (NSString *)itemClassName {
  78. return @"RQPlaceBuyCell";
  79. }
  80. @end