123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- //
- // YOUPAILZGameAccompanyListVC.m
- // VQU
- //
- // Created by CY on 2021/4/26.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZGameAccompanyListVC.h"
- #import "YOUPAILZGameAccompanyModel.h"
- #import "YOUPAILZGameAccompanyListCell.h"
- #import "UIScrollView+LZRefresh.h"
- #import "YOUPAILCIMTool.h"
- #import "NIMMessageMaker.h"
- #import "YOUPAILCIMSessionVC.h"
- #import "LZAlertWindow.h"
- #import "UIViewController+TFPresent.h"
- #import "YOUPAILZApplyRefundWindow.h"
- @interface YOUPAILZGameAccompanyListVC ()<UITableViewDataSource,UITableViewDelegate,LZGameAccompanyListCellDelegate>
- @property (nonatomic, weak)UITableView *youpaiptableView;
- @property (nonatomic, assign)NSInteger youpaippage;
- @property (nonatomic, strong)NSMutableArray <YOUPAILZGameAccompanyModel *>*youpaipdataSource;
- @end
- @implementation YOUPAILZGameAccompanyListVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = @"陪练订单";
- [self youpaifsetupUI];
- [self.youpaiptableView.mj_header beginRefreshing];
- }
- - (void)youpaifsetupUI{
- UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- tableView.dataSource = self;
- tableView.delegate = self;
- tableView.rowHeight = 150.0f;
- tableView.estimatedRowHeight = 150.0f;
- tableView.estimatedSectionHeaderHeight = 0.0f;
- tableView.estimatedSectionFooterHeight = 0.0f;
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self.view addSubview:tableView];
- self.youpaiptableView = tableView;
- [tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.offset(0.0f);
- make.top.offset(NavBarHeight);
- }];
-
- __weak typeof(self) weakSelf = self;
- [tableView setRefreshHeaderWithBlock:^{
- [weakSelf youpaifrequestGameAccompanyList:kRefreshHeader];
- }];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return self.youpaipdataSource.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return 1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- NSString *cellID = @"GameListCell";
- YOUPAILZGameAccompanyListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
- if (cell == nil) {
- cell = [[YOUPAILZGameAccompanyListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
- }
- cell.delegate = self;
- [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.section]];
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return 5.0f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- NSString *userId = self.youpaipdataSource[indexPath.section].youpaipuser_id;
- if ([self.youpaipdataSource[indexPath.section].youpaipuser_id isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
- userId = self.youpaipdataSource[indexPath.section].youpaipto_uid;
- }
- NIMSession *session = [NIMSession session:userId type:NIMSessionTypeP2P];
- @weakify(self);
- [ZCHUDHelper show];
- [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
- @strongify(self);
- [ZCHUDHelper dismiss];
- YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
- [self.navigationController pushViewController:vc animated:YES];
- }];
- }
- #pragma mark - LZGameAccompanyListCellDelegate
- // 同意接单
- - (void)youpaifagreeTakeOrderWithCell:(YOUPAILZGameAccompanyListCell *)cell model:(YOUPAILZGameAccompanyModel *)model{
- __weak typeof(self) weakSelf = self;
- [self youpaifsubmitOrderStatus:1 text:nil model:model success:^{
- model.youpaipstatus = @"1";
- model.youpaipstatus_text = @"进行中";
- [weakSelf.youpaiptableView reloadData];
- [ZCHUDHelper showTitle:@"已成功接单"];
- }];
- }
- // 完成订单
- - (void)youpaiffinishOrderWithCell:(YOUPAILZGameAccompanyListCell *)cell model:(YOUPAILZGameAccompanyModel *)model{
- __weak typeof(self) weakSelf = self;
- LZAlertAction *action = [LZAlertAction actionWithTitle:@"我已完成陪玩任务" handler:^(LZAlertAction *action) {
- [self youpaifsubmitOrderStatus:5 text:nil model:model success:^{
- model.youpaipstatus = @"5";
- model.youpaipstatus_text = @"服务已完成";
- [weakSelf.youpaiptableView reloadData];
- LZAlertAction *cAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) {
-
- }];
- LZAlertWindow *cAlert = [LZAlertWindow alertWithTitle:nil content:@"系统已收到你的声明,若买家在12小时内没有异议,相应的钻石将会自动存入到你的账号中。" action:@[cAction]];
- cAlert.isTouchDismiss = YES;
- [self TFPresentVC:cAlert completion:^{}];
- }];
- }];
- LZAlertWindow *alert = [LZAlertWindow alertWithTitle:nil content:@"请确保你已经完成了本次游戏陪玩任务,若未完成陪玩任务就声明服务完成,将导致买家投诉,你可能会获得相应惩罚。" action:@[action]];
- alert.isTouchDismiss = YES;
- [self TFPresentVC:alert completion:^{}];
- }
- // 处理退款
- - (void)youpaifhandleRefundWithCell:(YOUPAILZGameAccompanyListCell *)cell model:(YOUPAILZGameAccompanyModel *)model{
- __weak typeof(self) weakSelf = self;
- LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"不同意" handler:^(LZAlertAction *action) {
- [self youpaifsubmitOrderStatus:3 text:nil model:model success:^{
- model.youpaipstatus = @"3";
- model.youpaipstatus_text = @"拒绝退款";
- [weakSelf.youpaiptableView reloadData];
- }];
- }];
- cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
- LZAlertAction *agreeAction = [LZAlertAction actionWithTitle:@"同意退款" handler:^(LZAlertAction *action) {
- [self youpaifsubmitOrderStatus:4 text:nil model:model success:^{
- model.youpaipstatus = @"4";
- model.youpaipstatus_text = @"已退款";
- [weakSelf.youpaiptableView reloadData];
- }];
- }];
- LZAlertWindow *alert = [LZAlertWindow alertWithTitle:nil content:[NSString stringWithFormat:@"买家的退款理由:%@",model.youpaiprefund_cause] action:@[cancelAction,agreeAction]];
- alert.isTouchDismiss = YES;
- [self TFPresentVC:alert completion:^{}];
- }
- // 申请退款
- - (void)youpaifapplyRefundWithCell:(YOUPAILZGameAccompanyListCell *)cell model:(YOUPAILZGameAccompanyModel *)model{
- __weak typeof(self) weakSelf = self;
- YOUPAILZApplyRefundWindow *vc = [[YOUPAILZApplyRefundWindow alloc] init];
- vc.isTouchDismiss = YES;
- [vc setConfirmClickBlock:^(NSString * _Nonnull text) {
- [self youpaifsubmitOrderStatus:2 text:text model:model success:^{
- model.youpaipstatus = @"2";
- model.youpaipstatus_text = @"买家申请退款中";
- [weakSelf.youpaiptableView reloadData];
- }];
- }];
- [self TFPresentVC:vc completion:^{}];
- }
- // 申诉
- - (void)youpaifcomplaintWithCell:(YOUPAILZGameAccompanyListCell *)cell model:(YOUPAILZGameAccompanyModel *)model{
- NIMSession *session = [NIMSession session:@"4" type:NIMSessionTypeP2P];
- NIMMessage *imMessage = [NIMMessageMaker msgWithText:[NSString stringWithFormat:@"申诉\n日期:%@\n订单号:%@",model.youpaipcreate_time_text,model.youpaiporder_no]];
- [YOUPAILCIMTool sendMessage:imMessage sessionid:session.sessionId completion:^(NIMMessage *resultMsg,NSInteger filter,NSString *contentStr) {
- if (filter==0) {
- [[[NIMSDK sharedSDK] chatManager] sendMessage:resultMsg toSession:session error:nil];
- }else{
- resultMsg.text = contentStr;
- [[[NIMSDK sharedSDK] chatManager] sendMessage:resultMsg toSession:session error:nil];
- }
- }];
- @weakify(self);
- [ZCHUDHelper show];
- [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
- @strongify(self);
- [ZCHUDHelper dismiss];
- YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
- [self.navigationController pushViewController:vc animated:YES];
- }];
- }
- /// 游戏陪玩订单处理
- - (void)youpaifsubmitOrderStatus:(NSInteger)status text:(NSString *)text model:(YOUPAILZGameAccompanyModel *)model success:(void (^)(void))successBlock{
- NSMutableDictionary *params = @{
- @"type":@(status),
- @"order_id":model.youpaipid}.mutableCopy;
- if (text.length != 0) {
- [params setValue:text forKey:@"refund_cause"];
- }
- [LCHttpHelper requestWithURLString:GameOrderOperate parameters:params.copy needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- [self.youpaiptableView endRefreshing:kRefreshAll];
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {//成功
- if(successBlock!=nil){
- successBlock();
- }
- }else{
- [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- /// 获取预约列表数据
- - (void)youpaifrequestGameAccompanyList:(kRefreshStatus)status{
- if (status == kRefreshFooter) {
- self.youpaippage ++;
- }else{
- self.youpaippage = 1;
- }
- [LCHttpHelper requestWithURLString:GameOrderList parameters:@{@"page":@(self.youpaippage)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- [self.youpaiptableView endRefreshing:kRefreshAll];
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {//成功
- if (status != kRefreshFooter) {
- [self.youpaipdataSource removeAllObjects];
- }
- NSDictionary *data = [dict objectForKey:@"data"];
- NSArray <YOUPAILZGameAccompanyModel *>*list = [YOUPAILZGameAccompanyModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
- [self.youpaipdataSource addObjectsFromArray:list];
- [self.youpaiptableView reloadData];
-
- NSInteger totalPage = [[data objectForKey:@"total_page"] integerValue];
- [self youpaifrefreshFooterWithHidden:self.youpaippage >= totalPage];
- }
- } failure:^(NSError *error) {
- [self.youpaiptableView endRefreshing:kRefreshAll];
- }];
- }
- /// 设置加载更多
- - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
- __weak typeof(self) weakSelf = self;
- [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
- [weakSelf youpaifrequestGameAccompanyList:kRefreshFooter];
- }];
- }
- - (NSMutableArray<YOUPAILZGameAccompanyModel *> *)youpaipdataSource{
- if (_youpaipdataSource == nil) {
- _youpaipdataSource = [NSMutableArray array];
- }
- return _youpaipdataSource;
- }
- @end
|