YOUPAILZGameAccompanyListVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. //
  2. // YOUPAILZGameAccompanyListVC.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/4/26.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZGameAccompanyListVC.h"
  9. #import "YOUPAILZGameAccompanyModel.h"
  10. #import "YOUPAILZGameAccompanyListCell.h"
  11. #import "UIScrollView+LZRefresh.h"
  12. #import "YOUPAILCIMTool.h"
  13. #import "NIMMessageMaker.h"
  14. #import "YOUPAILCIMSessionVC.h"
  15. #import "LZAlertWindow.h"
  16. #import "UIViewController+TFPresent.h"
  17. #import "YOUPAILZApplyRefundWindow.h"
  18. @interface YOUPAILZGameAccompanyListVC ()<UITableViewDataSource,UITableViewDelegate,LZGameAccompanyListCellDelegate>
  19. @property (nonatomic, weak)UITableView *youpaiptableView;
  20. @property (nonatomic, assign)NSInteger youpaippage;
  21. @property (nonatomic, strong)NSMutableArray <YOUPAILZGameAccompanyModel *>*youpaipdataSource;
  22. @end
  23. @implementation YOUPAILZGameAccompanyListVC
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. self.title = @"陪练订单";
  27. [self youpaifsetupUI];
  28. [self.youpaiptableView.mj_header beginRefreshing];
  29. }
  30. - (void)youpaifsetupUI{
  31. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  32. tableView.dataSource = self;
  33. tableView.delegate = self;
  34. tableView.rowHeight = 150.0f;
  35. tableView.estimatedRowHeight = 150.0f;
  36. tableView.estimatedSectionHeaderHeight = 0.0f;
  37. tableView.estimatedSectionFooterHeight = 0.0f;
  38. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  39. [self.view addSubview:tableView];
  40. self.youpaiptableView = tableView;
  41. [tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  42. make.left.bottom.right.offset(0.0f);
  43. make.top.offset(NavBarHeight);
  44. }];
  45. __weak typeof(self) weakSelf = self;
  46. [tableView setRefreshHeaderWithBlock:^{
  47. [weakSelf youpaifrequestGameAccompanyList:kRefreshHeader];
  48. }];
  49. }
  50. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  51. return self.youpaipdataSource.count;
  52. }
  53. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  54. return 1;
  55. }
  56. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  57. NSString *cellID = @"GameListCell";
  58. YOUPAILZGameAccompanyListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  59. if (cell == nil) {
  60. cell = [[YOUPAILZGameAccompanyListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  61. }
  62. cell.delegate = self;
  63. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.section]];
  64. return cell;
  65. }
  66. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  67. return 5.0f;
  68. }
  69. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  70. return CGFLOAT_MIN;
  71. }
  72. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  73. NSString *userId = self.youpaipdataSource[indexPath.section].youpaipuser_id;
  74. if ([self.youpaipdataSource[indexPath.section].youpaipuser_id isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  75. userId = self.youpaipdataSource[indexPath.section].youpaipto_uid;
  76. }
  77. NIMSession *session = [NIMSession session:userId type:NIMSessionTypeP2P];
  78. @weakify(self);
  79. [ZCHUDHelper show];
  80. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  81. @strongify(self);
  82. [ZCHUDHelper dismiss];
  83. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  84. [self.navigationController pushViewController:vc animated:YES];
  85. }];
  86. }
  87. #pragma mark - LZGameAccompanyListCellDelegate
  88. // 同意接单
  89. - (void)youpaifagreeTakeOrderWithCell:(YOUPAILZGameAccompanyListCell *)cell model:(YOUPAILZGameAccompanyModel *)model{
  90. __weak typeof(self) weakSelf = self;
  91. [self youpaifsubmitOrderStatus:1 text:nil model:model success:^{
  92. model.youpaipstatus = @"1";
  93. model.youpaipstatus_text = @"进行中";
  94. [weakSelf.youpaiptableView reloadData];
  95. [ZCHUDHelper showTitle:@"已成功接单"];
  96. }];
  97. }
  98. // 完成订单
  99. - (void)youpaiffinishOrderWithCell:(YOUPAILZGameAccompanyListCell *)cell model:(YOUPAILZGameAccompanyModel *)model{
  100. __weak typeof(self) weakSelf = self;
  101. LZAlertAction *action = [LZAlertAction actionWithTitle:@"我已完成陪玩任务" handler:^(LZAlertAction *action) {
  102. [self youpaifsubmitOrderStatus:5 text:nil model:model success:^{
  103. model.youpaipstatus = @"5";
  104. model.youpaipstatus_text = @"服务已完成";
  105. [weakSelf.youpaiptableView reloadData];
  106. LZAlertAction *cAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) {
  107. }];
  108. LZAlertWindow *cAlert = [LZAlertWindow alertWithTitle:nil content:@"系统已收到你的声明,若买家在12小时内没有异议,相应的钻石将会自动存入到你的账号中。" action:@[cAction]];
  109. cAlert.isTouchDismiss = YES;
  110. [self TFPresentVC:cAlert completion:^{}];
  111. }];
  112. }];
  113. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:nil content:@"请确保你已经完成了本次游戏陪玩任务,若未完成陪玩任务就声明服务完成,将导致买家投诉,你可能会获得相应惩罚。" action:@[action]];
  114. alert.isTouchDismiss = YES;
  115. [self TFPresentVC:alert completion:^{}];
  116. }
  117. // 处理退款
  118. - (void)youpaifhandleRefundWithCell:(YOUPAILZGameAccompanyListCell *)cell model:(YOUPAILZGameAccompanyModel *)model{
  119. __weak typeof(self) weakSelf = self;
  120. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"不同意" handler:^(LZAlertAction *action) {
  121. [self youpaifsubmitOrderStatus:3 text:nil model:model success:^{
  122. model.youpaipstatus = @"3";
  123. model.youpaipstatus_text = @"拒绝退款";
  124. [weakSelf.youpaiptableView reloadData];
  125. }];
  126. }];
  127. cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
  128. LZAlertAction *agreeAction = [LZAlertAction actionWithTitle:@"同意退款" handler:^(LZAlertAction *action) {
  129. [self youpaifsubmitOrderStatus:4 text:nil model:model success:^{
  130. model.youpaipstatus = @"4";
  131. model.youpaipstatus_text = @"已退款";
  132. [weakSelf.youpaiptableView reloadData];
  133. }];
  134. }];
  135. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:nil content:[NSString stringWithFormat:@"买家的退款理由:%@",model.youpaiprefund_cause] action:@[cancelAction,agreeAction]];
  136. alert.isTouchDismiss = YES;
  137. [self TFPresentVC:alert completion:^{}];
  138. }
  139. // 申请退款
  140. - (void)youpaifapplyRefundWithCell:(YOUPAILZGameAccompanyListCell *)cell model:(YOUPAILZGameAccompanyModel *)model{
  141. __weak typeof(self) weakSelf = self;
  142. YOUPAILZApplyRefundWindow *vc = [[YOUPAILZApplyRefundWindow alloc] init];
  143. vc.isTouchDismiss = YES;
  144. [vc setConfirmClickBlock:^(NSString * _Nonnull text) {
  145. [self youpaifsubmitOrderStatus:2 text:text model:model success:^{
  146. model.youpaipstatus = @"2";
  147. model.youpaipstatus_text = @"买家申请退款中";
  148. [weakSelf.youpaiptableView reloadData];
  149. }];
  150. }];
  151. [self TFPresentVC:vc completion:^{}];
  152. }
  153. // 申诉
  154. - (void)youpaifcomplaintWithCell:(YOUPAILZGameAccompanyListCell *)cell model:(YOUPAILZGameAccompanyModel *)model{
  155. NIMSession *session = [NIMSession session:@"4" type:NIMSessionTypeP2P];
  156. NIMMessage *imMessage = [NIMMessageMaker msgWithText:[NSString stringWithFormat:@"申诉\n日期:%@\n订单号:%@",model.youpaipcreate_time_text,model.youpaiporder_no]];
  157. [YOUPAILCIMTool sendMessage:imMessage sessionid:session.sessionId completion:^(NIMMessage *resultMsg,NSInteger filter,NSString *contentStr) {
  158. if (filter==0) {
  159. [[[NIMSDK sharedSDK] chatManager] sendMessage:resultMsg toSession:session error:nil];
  160. }else{
  161. resultMsg.text = contentStr;
  162. [[[NIMSDK sharedSDK] chatManager] sendMessage:resultMsg toSession:session error:nil];
  163. }
  164. }];
  165. @weakify(self);
  166. [ZCHUDHelper show];
  167. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  168. @strongify(self);
  169. [ZCHUDHelper dismiss];
  170. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  171. [self.navigationController pushViewController:vc animated:YES];
  172. }];
  173. }
  174. /// 游戏陪玩订单处理
  175. - (void)youpaifsubmitOrderStatus:(NSInteger)status text:(NSString *)text model:(YOUPAILZGameAccompanyModel *)model success:(void (^)(void))successBlock{
  176. NSMutableDictionary *params = @{
  177. @"type":@(status),
  178. @"order_id":model.youpaipid}.mutableCopy;
  179. if (text.length != 0) {
  180. [params setValue:text forKey:@"refund_cause"];
  181. }
  182. [LCHttpHelper requestWithURLString:GameOrderOperate parameters:params.copy needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  183. [self.youpaiptableView endRefreshing:kRefreshAll];
  184. NSDictionary* dict = (NSDictionary*)responseObject;
  185. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  186. if (code == 0) {//成功
  187. if(successBlock!=nil){
  188. successBlock();
  189. }
  190. }else{
  191. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  192. }
  193. } failure:^(NSError *error) {
  194. [ZCHUDHelper showTitle:error.localizedDescription];
  195. }];
  196. }
  197. /// 获取预约列表数据
  198. - (void)youpaifrequestGameAccompanyList:(kRefreshStatus)status{
  199. if (status == kRefreshFooter) {
  200. self.youpaippage ++;
  201. }else{
  202. self.youpaippage = 1;
  203. }
  204. [LCHttpHelper requestWithURLString:GameOrderList parameters:@{@"page":@(self.youpaippage)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  205. [self.youpaiptableView endRefreshing:kRefreshAll];
  206. NSDictionary* dict = (NSDictionary*)responseObject;
  207. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  208. if (code == 0) {//成功
  209. if (status != kRefreshFooter) {
  210. [self.youpaipdataSource removeAllObjects];
  211. }
  212. NSDictionary *data = [dict objectForKey:@"data"];
  213. NSArray <YOUPAILZGameAccompanyModel *>*list = [YOUPAILZGameAccompanyModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
  214. [self.youpaipdataSource addObjectsFromArray:list];
  215. [self.youpaiptableView reloadData];
  216. NSInteger totalPage = [[data objectForKey:@"total_page"] integerValue];
  217. [self youpaifrefreshFooterWithHidden:self.youpaippage >= totalPage];
  218. }
  219. } failure:^(NSError *error) {
  220. [self.youpaiptableView endRefreshing:kRefreshAll];
  221. }];
  222. }
  223. /// 设置加载更多
  224. - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
  225. __weak typeof(self) weakSelf = self;
  226. [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
  227. [weakSelf youpaifrequestGameAccompanyList:kRefreshFooter];
  228. }];
  229. }
  230. - (NSMutableArray<YOUPAILZGameAccompanyModel *> *)youpaipdataSource{
  231. if (_youpaipdataSource == nil) {
  232. _youpaipdataSource = [NSMutableArray array];
  233. }
  234. return _youpaipdataSource;
  235. }
  236. @end