123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- //
- // RQPlaceBuyItemViewModel.m
- // JiaPei
- //
- // Created by 张嵘 on 2023/4/19.
- //
- #import "RQPlaceBuyItemViewModel.h"
- @interface RQPlaceBuyItemViewModel ()
- @property (nonatomic, readwrite, strong) RQPlaceListModel *placeListModel;
- @property (nonatomic, readwrite, assign) BOOL isBuy;
- @property (nonatomic, readwrite, assign) BOOL chooseAgree;
- @end
- @implementation RQPlaceBuyItemViewModel
- - (instancetype)initWithPlaceListModel:(RQPlaceListModel *)placeListModel {
- if (self = [super init]) {
- @weakify(self)
- self.placeListModel = placeListModel;
- CGFloat width = RQ_SCREEN_WIDTH - 32.f;
- self.rowHeight = (width * (56.f / 345.f)) + 16 + 20 + 16;
- RAC(self, isBuy) = [[RACObserve(placeListModel, isCheckVip) deliverOnMainThread] takeUntil:self.rac_willDeallocSignal];
- [[[[RACObserve(RQ_COMMON_MANAGER, vipListArr) deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] skip:1] subscribeNext:^(id _Nullable x) {
- BOOL isBuy = [RQ_COMMON_MANAGER.vipListArr containsObject:placeListModel.name];
- placeListModel.isCheckVip = isBuy;
- }];
- self.operation = ^{
- @strongify(self)
-
- if (self.isAgree) {
- if (self.isBuy) {
-
- } else {
- [QMUITips showLoading:@"下单中..." inView:DefaultTipsParentView];
- [[RQ_HTTP_Service postPrepareOrderWithGoodsId:[NSString qmui_stringWithNSInteger:placeListModel.id] userId:RQ_USER_MANAGER.currentUser._id goodsType:RQGoodsType_Place] subscribeNext:^(RQPrepareOrderModel *prepareOrderModel) {
- [QMUITips hideAllTips];
- // 发起微信支付,设置参数
- //需要创建这个支付对象
- PayReq *req = [[PayReq alloc] init];
- //由用户微信号和AppID组成的唯一标识,用于校验微信用户
- req.openID = RQ_WECHAT_MANAGER.appID;
- // 商家id,在注册的时候给的
- req.partnerId = prepareOrderModel.partnerId;
- // 预支付订单这个是后台跟微信服务器交互后,微信服务器传给你们服务器的,你们服务器再传给你
- req.prepayId = prepareOrderModel.prepayId;
- // 根据财付通文档填写的数据和签名
- req.package = prepareOrderModel.packageValue;
- // 随机编码,为了防止重复的,在后台生成
- req.nonceStr = prepareOrderModel.nonceStr;
- // 这个是时间戳,也是在后台生成的,为了验证支付的
- NSString * stamp = prepareOrderModel.timeStamp;
- req.timeStamp = (UInt32)stamp.intValue;
- // 这个签名也是后台做的
- req.sign = prepareOrderModel.sign;
- [RQWechatManager hangleWechatPayWith:req];
- } error:^(NSError * _Nullable error) {
- [QMUITips hideAllTips];
- [QMUITips showError:[NSError rq_tipsFromError:error]];
- }];
- }
- } else {
- [[RACScheduler mainThreadScheduler] schedule:^{
- [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"请阅读用户协议!才能购买考场会员哦!" confirmTitle:@"立即阅读" cancelTitle:@"取消" confirmAction:^{
- @strongify(self)
- self.chooseAgree = YES;
- NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://ys.zzxcx.net/jsjp-sf.html"]];
- RQWebViewModel *viewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey : request,RQViewModelWebViewTypeKey:@(RQWebViewType_VIP)}];
- RQWebViewViewController *viewController = [[RQWebViewViewController alloc] initWithViewModel:viewModel];
- RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:viewController];
- [RQControllerHelper.currentViewController presentViewController:nav animated:YES completion:nil];
- } cancelAction:nil];
- }];
- }
-
-
-
- };
- }
- return self;
- }
- - (NSString *)itemClassName {
- return @"RQPlaceBuyCell";
- }
- @end
|