RQPlaceBuyItemViewModel.m 4.6 KB

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