SPSBCustomerServiceManager.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // SPSBCustomerServiceManager.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/4/26.
  6. //
  7. #import "SPSBCustomerServiceManager.h"
  8. #import "SPSBBusinessManager.h"
  9. #import <SobotKit/SobotKit.h>
  10. #import <JXHMacro.h>
  11. #import "SPSBAppDifferenceProfile.h"
  12. #import "SPSBKeyProfile.h"
  13. #import <JXHSystemShortcut.h>
  14. #import "SPSBGeneralManager.h"
  15. #import "SPSBConsultationViewController.h"
  16. #import "SPSBConfirmAlertViewController.h"
  17. #import "SPSBOpenPopupManager.h"
  18. #import "SPSBURLApiProfile.h"
  19. #import <UIColor+JXHHex.h>
  20. #import <JXHGeneralTools.h>
  21. #import "SPSBColorProfile.h"
  22. @implementation SPSBCustomerServiceManager
  23. + (instancetype)alloc {
  24. NSAssert(![self isMemberOfClass:[SPSBCustomerServiceManager class]], @"SPSBCustomerServiceManager is singleton, you should not instantiate it directly.");
  25. return [super alloc];
  26. }
  27. + (SPSBCustomerServiceManager *)shareManager {
  28. static SPSBCustomerServiceManager *manager = nil;
  29. static dispatch_once_t once;
  30. dispatch_once(&once, ^{
  31. manager = [[super allocWithZone:nil] init];
  32. });
  33. return manager;
  34. }
  35. + (instancetype)allocWithZone:(struct _NSZone *)zone {
  36. return [self shareManager];
  37. }
  38. - (void)delayToOnlineContact {
  39. [self pollHandleOnlineContactWithTime:0];
  40. }
  41. - (void)checkSobot {
  42. if (!spsb_isLogin()) return;
  43. _spsb_isChecking = true;
  44. ZCLibInitInfo *initInfo = [ZCLibInitInfo new];
  45. initInfo.app_key = SPSBSobotAppKey;
  46. initInfo.partnerid = [jxh_userDefaults() objectForKey:SPSBUser];
  47. [[ZCLibClient getZCLibClient] setLibInitInfo:initInfo];
  48. NSInteger i = [[ZCLibClient getZCLibClient] getUnReadMessage];
  49. _spsb_notificationNum = i;
  50. [spsb_consultationHomeVC() reloadViewTips];
  51. debugLog(@"未读消息-----------%ld", (long)i);
  52. if (i > 0) {
  53. SPSBConfirmAlertViewController *vc = [SPSBConfirmAlertViewController alertWithTitle:@"提示" content:@"你有未读客服信息"];
  54. @weakify(self)
  55. [vc setCancelButtonTitle:nil titleColor:nil action:^{
  56. self->_spsb_isChecking = false;
  57. }];
  58. [vc setConfirmButtonTitle:@"查看" titleColor:nil action:^{
  59. @strongify(self)
  60. [self toOnlineContactWithBaseController:nil];
  61. }];
  62. SPSBOpenPopupModel *model = SPSBOpenPopupModel.new;
  63. model.spsb_popup = vc;
  64. [SPSBOpenPopupManager insertPopup:model];
  65. } else {
  66. _spsb_isChecking = false;
  67. }
  68. }
  69. - (void)pollHandleOnlineContactWithTime:(NSTimeInterval)time {
  70. if (time > 10) {
  71. return;
  72. }
  73. if (![[ZCLibClient getZCLibClient] getInitState]) {
  74. [self performSelector:@selector(pollHandleOnlineContactWithTime:) withObject:@(time + 1) afterDelay:0.1];
  75. return;
  76. }
  77. [self toOnlineContactWithBaseController:nil];
  78. }
  79. - (void)toOnlineContactWithBaseController:(nullable UIViewController *)vc {
  80. debugLog(@"智齿%@", [ZCSobot getVersion]);
  81. @weakify(self)
  82. spsb_needLogin(^{
  83. @strongify(self)
  84. [self inCustomerServiceWithBaseController:vc];
  85. });
  86. }
  87. - (void)inCustomerServiceWithBaseController:(nullable UIViewController *)vc {
  88. if (_spsb_isIn) return;
  89. _spsb_isChecking = true;
  90. ZCLibInitInfo *initInfo = [ZCLibInitInfo new];
  91. initInfo.app_key = SPSBSobotAppKey;
  92. initInfo.partnerid = [jxh_userDefaults() objectForKey:SPSBUser];
  93. initInfo.user_tels = [jxh_userDefaults() objectForKey:SPSBUserName];
  94. initInfo.face = spsb_fileUrl(spsb_userAvatar());
  95. initInfo.user_nick = [jxh_userDefaults() objectForKey:SPSBUserName];
  96. // initInfo.receptionistId = @"9dc3cbd95e8645dca3f5cc6db201bbd8";
  97. ZCKitInfo *uiInfo = [ZCKitInfo new];
  98. uiInfo.navcBarHidden = true;
  99. uiInfo.topViewBgColor = HEX_COLOR(#0DAEAF);
  100. uiInfo.chatLeftLinkColor = HEX_COLOR(#0DAEAF);
  101. // uiInfo.topViewBgColor = HEX_COLOR(#28AFF0);
  102. // uiInfo.rightChatColor = HEX_COLOR(#28AFF0);
  103. // uiInfo.satisfactionSelectedBgColor = HEX_COLOR(#3296FB);
  104. // uiInfo.noSatisfactionTextColor = HEX_COLOR(#3296FB);
  105. // uiInfo.commentCommitButtonBgColor = HEX_COLOR(#3296FB);
  106. // uiInfo.commentOtherButtonBgColor = HEX_COLOR(#3296FB);
  107. // uiInfo.topBackTitle = @"";
  108. uiInfo.titleFont = spsb_font(17);
  109. // uiInfo.topViewTextColor = [UIColor redColor];
  110. // uiInfo.topBackNolColor = HEX_COLOR(#3296FB);
  111. // uiInfo.customBannerColor = HEX_COLOR(#3296FB);
  112. // ZCProductInfo *productInfo = [ZCProductInfo new];
  113. // productInfo.thumbUrl = @"";
  114. // productInfo.title = @"123";
  115. // productInfo.desc = @"345";
  116. // productInfo.label = @"&3";
  117. // productInfo.link = @"http://www.baidu.com";
  118. // uiInfo.productInfo = productInfo;
  119. [[ZCLibClient getZCLibClient] setLibInitInfo:initInfo];
  120. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  121. if (nil == vc) {
  122. vc = jxh_findPresentedViewControllerStartingFrom(spsb_keyWindow().rootViewController);
  123. }
  124. if (nil == vc) return;
  125. bool haveNav = vc.navigationController.navigationBarHidden;
  126. // 智齿SDK初始化启动事例
  127. @weakify(self)
  128. [ZCSobot startZCChatVC:uiInfo
  129. with:vc
  130. target:nil
  131. pageBlock:^(id object,ZCPageBlockType type){
  132. @strongify(self)
  133. if (type == ZCPageBlockLoadFinish) {
  134. self->_spsb_isIn = true;
  135. self->_spsb_isChecking = false;
  136. self->_spsb_notificationNum = 0;
  137. [spsb_consultationHomeVC() reloadViewTips];
  138. if (vc.navigationController) {
  139. vc.navigationController.interactivePopGestureRecognizer.enabled = false;
  140. [vc.navigationController setNavigationBarHidden:true animated:false];
  141. }
  142. }
  143. if (type == ZCPageBlockGoBack) {
  144. self->_spsb_isIn = false;
  145. self->_spsb_isClickNotification = false;
  146. if (vc.navigationController) {
  147. vc.navigationController.interactivePopGestureRecognizer.enabled = true;
  148. [vc.navigationController setNavigationBarHidden:haveNav animated:false];
  149. NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: spsb_333333_color(), NSForegroundColorAttributeName, spsb_mediumFont(16), NSFontAttributeName, nil];
  150. [vc.navigationController.navigationBar setTitleTextAttributes:attributes];
  151. }
  152. }
  153. } messageLinkClick:nil];
  154. }
  155. @end
  156. SPSBCustomerServiceManager *spsb_customerServiceManager() {
  157. return [SPSBCustomerServiceManager shareManager];
  158. }