ClubData.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. import AdM from "../manager/AdM";
  2. import GameM from "../manager/GameM";
  3. import UiM, { PANEL_NAME } from "../manager/UiM";
  4. import CashRecordNode from "../ui/CashRecordNode";
  5. import ClubActiveNode from "../ui/club/ClubActiveNode";
  6. import ClubInviteNode from "../ui/club/ClubInviteNode";
  7. import ClubLevelAward from "../ui/club/ClubLevelAward";
  8. import ClubMemberList from "../ui/club/ClubMemberList";
  9. import ClubMineNode from "../ui/club/ClubMineNode";
  10. import ClubShouquShanggong from "../ui/club/ClubShouquShanggong";
  11. import ClubShouyiInfo from "../ui/club/ClubShouyiInfo";
  12. import ClubTixianNode from "../ui/club/ClubTixianNode";
  13. import ClubTopNode from "../ui/club/ClubTopNode";
  14. import ClubMain from "../ui/ClubMain";
  15. import EffectNode from "../ui/EffectNode";
  16. import OfficialNode from "../ui/OfficialNode";
  17. import RedCodeNode from "../ui/RedCodeNode";
  18. import LogUtil from "../utils/LogUtil";
  19. // import CaiDanData from "./CaiDanData";
  20. import { HTTP_TYPE } from "./CommonData";
  21. // import FissionCaidanData from "./FissionCaidanData";
  22. const { ccclass, property } = cc._decorator;
  23. export default class ClubData {
  24. private static instance: ClubData = null
  25. static get Instance(): ClubData {
  26. if (!this.instance) {
  27. this.instance = new ClubData()
  28. }
  29. return this.instance
  30. }
  31. localTest = false
  32. inviteUin: string = "";
  33. /**基础信息 */
  34. clubBaseInfo = null
  35. /**活跃信息 */
  36. clubActiveInfo = null
  37. /**提现档位信息 */
  38. activeTixianInfo = null
  39. /**已到账金额 */
  40. currentGetMoney: number = 0
  41. /**提现加成 */
  42. invitePersons: number = 0
  43. /**总邀请 */
  44. getMoneyAddition: number = 0
  45. /**成员列表 */
  46. memberInfo: any = null
  47. /**俱乐部提现记录 */
  48. clubCashRecord: any = null
  49. /**招募进度信息 */
  50. clubInviteInfo = null
  51. /**是否授权之后上报inviteCode */
  52. clubAuthPushInviteIn = false
  53. /** 分享链接信息 */
  54. clubShowShareInfo: any = null
  55. shareUrlWeixin = "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/west/JourneyToTheWest/index.html"
  56. shareUrlBrowser = "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/west/JourneyToTheWest/index.html"
  57. // shareUrlRedPocket = "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/club/web_mobile/carClubPlay3/index.html"
  58. clubRecordAwardTypeArr = ['每日提现', '累计提现', '招募提现']
  59. /**招募进度 */
  60. requestClubRecruitProgress() {
  61. if (this.localTest) {
  62. let data = [{}, {}, {}]
  63. this.getClubRecruitProgress(data)
  64. } else {
  65. GameM.httpM.sendDatas(HTTP_TYPE.clubRecruitProgress, null, GameM.ClubData.getClubRecruitProgress.bind(this));
  66. }
  67. }
  68. getClubRecruitProgress(data) {
  69. LogUtil.logV("getClubRecruitProgress", "start");
  70. LogUtil.logV("getClubRecruitProgress", data)
  71. this.clubInviteInfo = data
  72. if (UiM.Instance.clubMainNode)
  73. UiM.Instance.clubMainNode.getComponent(ClubMain).inviteNode.getComponent(ClubInviteNode).updateList()
  74. }
  75. /**获取短地址 */
  76. requestClubShorturl(data: string) {
  77. if (this.localTest) {
  78. this.getClubShorturl(null)
  79. } else {
  80. GameM.httpM.sendDatas(HTTP_TYPE.clubShorturl, { url: data }, GameM.ClubData.getClubShorturl.bind(this));
  81. }
  82. }
  83. getClubShorturl(data) {
  84. if (data == null || data == undefined || data == "") {
  85. return
  86. }
  87. this.shortUrl = data
  88. this.sendInviteInfo()
  89. // AdM.shareClubInstallUrl(data)
  90. // GameM.httpM.sendDatas(HTTP_TYPE.clubRecruitProgress,{});
  91. //to do
  92. }
  93. /**招募完成提现广播 */
  94. requestClubRecruitBroadcast() {
  95. if (this.localTest) {
  96. let data = [{}, {}, {}]
  97. this.getClubRecruitBroadcast(data)
  98. } else {
  99. GameM.httpM.sendDatas(HTTP_TYPE.clubRecruitBroadcast, null, GameM.ClubData.getClubRecruitBroadcast.bind(this));
  100. }
  101. }
  102. getClubRecruitBroadcast(data) {
  103. LogUtil.logV("getClubRecruitBroadcast", "start");
  104. // data = [{
  105. // "name": "张三",
  106. // "peopleCount": "12",
  107. // "amount": 100
  108. // }, {
  109. // "name": "张四",
  110. // "peopleCount": "9",
  111. // "amount": 1000
  112. // }, {
  113. // "name": "张五",
  114. // "peopleCount": "6",
  115. // "amount": 10000
  116. // }]
  117. // data = []
  118. // data.push({"name":"张三","peopleCount":12,})
  119. if (UiM.Instance.clubMainNode)
  120. UiM.Instance.clubMainNode.getComponent(ClubMain).inviteNode.getComponent(ClubInviteNode).updateGonggao(data)
  121. }
  122. /**会员个人基础信息 */
  123. requestClubGetBaseInfo() {
  124. if (this.localTest) {
  125. let data = [{}, {}, {}]
  126. this.getClubGetBaseInfo(data)
  127. } else {
  128. GameM.httpM.sendDatas(HTTP_TYPE.clubGetBaseInfo, null, GameM.ClubData.getClubGetBaseInfo.bind(this));
  129. }
  130. }
  131. getClubGetBaseInfo(data) {
  132. LogUtil.logV("getClubGetBaseInfo", "start");
  133. this.clubBaseInfo = data
  134. if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).topNode)) {
  135. UiM.Instance.clubMainNode.getComponent(ClubMain).topNode.getComponent(ClubTopNode).updateView(data)
  136. }
  137. if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).activeNode)) {
  138. UiM.Instance.clubMainNode.getComponent(ClubMain).activeNode.getComponent(ClubActiveNode).updateMoney()
  139. }
  140. }
  141. /**活跃奖励气泡 */
  142. requestClubMyBubbleData() {
  143. if (this.localTest) {
  144. let data = [{}, {}, {}]
  145. this.getClubMyBubbleData(data)
  146. } else {
  147. GameM.httpM.sendDatas(HTTP_TYPE.clubMyBubbleData, null, GameM.ClubData.getClubMyBubbleData.bind(this));
  148. }
  149. }
  150. getClubMyBubbleData(data) {
  151. LogUtil.logV("getClubMyBubbleData", "start");
  152. this.clubActiveInfo = data
  153. if (UiM.Instance.clubMainNode)
  154. UiM.Instance.clubMainNode.getComponent(ClubMain).activeNode.getComponent(ClubActiveNode).updateView(this.clubActiveInfo)
  155. }
  156. /**等级奖励规则 */
  157. requestClubLevelRewardRule() {
  158. if (this.localTest) {
  159. let data = [{}, {}, {}]
  160. this.getClubMyBubbleData(data)
  161. } else {
  162. GameM.httpM.sendDatas(HTTP_TYPE.clubLevelRewardRule, null, GameM.ClubData.getClubLevelRewardRule.bind(this));
  163. }
  164. }
  165. getClubLevelRewardRule(data) {
  166. LogUtil.logV("getClubLevelRewardRule", "start");
  167. if (UiM.Instance.clubMainNode)
  168. UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode.getChildByName("clubLevelAward").getComponent(ClubLevelAward).updateView(data)
  169. }
  170. /**我招募的后代成员 */
  171. requestClubMyRecruitMembers() {
  172. if (this.localTest) {
  173. let data = [{}, {}, {}]
  174. this.getClubMyRecruitMembers(data)
  175. } else {
  176. GameM.httpM.sendDatas(HTTP_TYPE.clubMyRecruitMembers, null, GameM.ClubData.getClubMyRecruitMembers.bind(this));
  177. }
  178. }
  179. getClubMyRecruitMembers(data) {
  180. LogUtil.logV("getClubMyRecruitMembers", "start");
  181. this.memberInfo = data
  182. // LogUtil.logV('caidan ', this.memberInfo)
  183. if (this.memberInfo) {
  184. let num = 0
  185. if (this.memberInfo.g1Members) {
  186. num = this.memberInfo.g1Members.length
  187. }
  188. // CaiDanData.Instance.addProgress(1, false, num)
  189. // FissionCaidanData.Instance.addFissionProgress(1, false, num, 0)
  190. let valid = 0
  191. for (const member of this.memberInfo.g1Members) {
  192. if (member.validStatus == 1) {
  193. valid++
  194. }
  195. }
  196. GameM.commonData.roleData.inviteTotal++
  197. GameM.commonData.updateRoleData()
  198. // FissionCaidanData.Instance.addFissionProgress(1, false, valid, 1)
  199. }
  200. if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).mineNode)) {
  201. UiM.Instance.clubMainNode.getComponent(ClubMain).mineNode.getComponent(ClubMineNode).updateView(data)
  202. }
  203. if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode.getChildByName("clubMemberList"))) {
  204. if (GameM.ClubData.memberInfo) {
  205. let node = UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode.getChildByName("clubMemberList")
  206. node.getComponent(ClubMemberList).intiViewByIndex(0)
  207. }
  208. }
  209. if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).inviteNode)) {
  210. UiM.Instance.clubMainNode.getComponent(ClubMain).inviteNode.getComponent(ClubInviteNode).updateFirstChildInfo()
  211. }
  212. }
  213. /**收取泡泡/确定过期泡泡 */
  214. requestClubCollectBubbles(date: string, generation = 0) {
  215. if (this.localTest) {
  216. let data = [{}, {}, {}]
  217. this.getClubCollectBubbles(data)
  218. } else {
  219. let data = {}
  220. data["date"] = date
  221. if (generation != 0) {
  222. data["generation"] = generation
  223. }
  224. GameM.httpM.sendDatas(HTTP_TYPE.clubCollectBubbles, data, GameM.ClubData.getClubCollectBubbles.bind(this));
  225. }
  226. }
  227. getClubCollectBubbles(data) {
  228. LogUtil.logV("getClubCollectBubbles", "start");
  229. if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode.getChildByName("clubShouquShanggong"))) {
  230. UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode.getChildByName("clubShouquShanggong").getComponent(ClubShouquShanggong).sendSuccess()
  231. }
  232. }
  233. /**预估收益 */
  234. requestClubPredictRevenue() {
  235. if (this.localTest) {
  236. let data = [{}, {}, {}]
  237. this.getClubPredictRevenue(data)
  238. } else {
  239. GameM.httpM.sendDatas(HTTP_TYPE.clubPredictRevenue, null, GameM.ClubData.getClubPredictRevenue.bind(this));
  240. }
  241. }
  242. getClubPredictRevenue(data) {
  243. LogUtil.logV("getClubPredictRevenue", "start");
  244. if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode.getChildByName("clubShouyiInfo"))) {
  245. UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode.getChildByName("clubShouyiInfo").getComponent(ClubShouyiInfo).updateView(data)
  246. }
  247. }
  248. /**活跃奖励提现档位 */
  249. requestClubWithdrawDenominations() {
  250. if (this.localTest) {
  251. let data = [{}, {}, {}]
  252. this.getClubWithdrawDenominations(data)
  253. } else {
  254. GameM.httpM.sendDatas(HTTP_TYPE.clubWithdrawDenominations, null, GameM.ClubData.getClubWithdrawDenominations.bind(this));
  255. }
  256. }
  257. getClubWithdrawDenominations(data) {
  258. LogUtil.logV("getClubWithdrawDenominations", "start");
  259. this.activeTixianInfo = data
  260. if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).activeNode)) {
  261. UiM.Instance.clubMainNode.getComponent(ClubMain).activeNode.getComponent(ClubActiveNode).initTixianBtn(data)
  262. }
  263. }
  264. //提现金额
  265. private clubCashMoney = 0
  266. private peopleNum = 0
  267. private clubCashIndex = -1
  268. /**提现
  269. * appVersion 应用版本号
  270. * applyType 1每日提现,2累计提现,3招募提现
  271. * peopleNum 招募进度(3人,6人,12人,20人)
  272. * index 档位,取招募和累计提现档位下标,每日为-1
  273. */
  274. requestClubDoWithdraw(appVersion: string, applyType: string, peopleNum: number, cashMoney: number, index: number) {
  275. this.clubCashMoney = cashMoney
  276. this.peopleNum = peopleNum
  277. this.clubCashIndex = index
  278. if (this.localTest) {
  279. let data = Number(applyType)
  280. this.getClubDoWithdraw({ "isCashSuccess": 1 }, data)
  281. } else {
  282. if (applyType == "1" || applyType == "2") {
  283. GameM.httpM.sendDatas(HTTP_TYPE.clubDoWithdraw, { "appVersion": appVersion, "applyType": applyType }, GameM.ClubData.getClubDoWithdraw.bind(this));
  284. } else {
  285. GameM.httpM.sendDatas(HTTP_TYPE.clubDoWithdraw, { "appVersion": appVersion, "applyType": applyType, "peopleNum": peopleNum }, GameM.ClubData.getClubDoWithdraw.bind(this));
  286. }
  287. }
  288. }
  289. getClubDoWithdraw(data, applyType) {
  290. LogUtil.logV("getClubDoWithdraw", "start");
  291. if (data.isCashSuccess == 0) {
  292. EffectNode.instance.PlayTip(data.message)
  293. if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode.getChildByName("ClubTixianNode"))) {
  294. UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode.getChildByName("ClubTixianNode").getComponent(ClubTixianNode).tixianFail()
  295. }
  296. return
  297. }
  298. if (Number(applyType) == 1 || Number(applyType) == 2) {
  299. if (Number(applyType) == 1) {
  300. AdM.onSendEvent('club_DailyCashSuccess', '每日提现-成功', 'club')
  301. } else {
  302. AdM.onSendEvent('club_LeijiCashSuccess' + this.clubCashIndex, '累计提现-成功', 'club')
  303. }
  304. if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).activeNode)) {
  305. this.clubBaseInfo.balance = this.clubBaseInfo.balance + (this.clubCashMoney)
  306. this.clubBaseInfo.pool = this.clubBaseInfo.pool - this.clubCashMoney * 10000
  307. // if (Number(applyType) == 2) {
  308. // GameM.commonData.roleData.clubLeijiTixian++
  309. // GameM.commonData.updateRoleData()
  310. // }
  311. this.requestClubWithdrawDenominations()
  312. }
  313. } else if (Number(applyType) == 3) {
  314. AdM.onSendEvent('club_InviteCashSuccess' + this.clubCashIndex, '招募提现-成功', 'club')
  315. for (let i = 0; i < this.clubInviteInfo.progressRecord.length; i++) {
  316. if (this.clubInviteInfo.progressRecord[i].peopleNum == this.peopleNum) {
  317. this.clubInviteInfo.progressRecord[i].status = 1
  318. if (this.clubBaseInfo) {
  319. this.clubBaseInfo.balance = this.clubBaseInfo.balance + (this.clubInviteInfo.progressRecord[i].rewardAmount / 10000)
  320. this.clubBaseInfo.pool = this.clubBaseInfo.pool - this.clubInviteInfo.progressRecord[i].rewardAmount
  321. }
  322. break
  323. }
  324. }
  325. }
  326. this.requestClubGetBaseInfo()
  327. if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode.getChildByName("ClubTixianNode"))) {
  328. UiM.Instance.clubMainNode.getComponent(ClubMain).alertNode.getChildByName("ClubTixianNode").getComponent(ClubTixianNode).tixianSuccess(data.withdrawalCode == null || data.withdrawalCode == undefined)
  329. }
  330. if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).inviteNode)) {
  331. UiM.Instance.clubMainNode.getComponent(ClubMain).inviteNode.getComponent(ClubInviteNode).updateList()
  332. }
  333. // if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).topNode)) {
  334. // UiM.Instance.clubMainNode.getComponent(ClubMain).topNode.getComponent(ClubTopNode).updateView(this.clubBaseInfo)
  335. // }
  336. if (UiM.Instance.clubMainNode && cc.isValid(UiM.Instance.clubMainNode.getComponent(ClubMain).activeNode)) {
  337. UiM.Instance.clubMainNode.getComponent(ClubMain).activeNode.getComponent(ClubActiveNode).updateView(this.clubActiveInfo)
  338. }
  339. if (data.withdrawalCode) {
  340. UiM.Instance.onPanel(PANEL_NAME.OfficialNode, false, () => {
  341. UiM.Instance.officialNode.getComponent(OfficialNode).init(this.clubCashMoney, data.withdrawalCode);
  342. AdM.onSendEvent('publicmoney_4', '公众号提现-裂变', 'publicmoney')
  343. })
  344. }
  345. }
  346. /**提现记录*/
  347. requestClubWithDrawRecords() {
  348. if (this.localTest) {
  349. this.getRequestClubWithDrawRecords(null)
  350. } else {
  351. GameM.httpM.sendDatas(HTTP_TYPE.clubWithDrawRecords, null, GameM.ClubData.getRequestClubWithDrawRecords.bind(this));
  352. }
  353. }
  354. getRequestClubWithDrawRecords(data) {
  355. LogUtil.logV("getRequestClubWithDrawRecords", "start");
  356. this.clubCashRecord = data
  357. if (cc.isValid(UiM.Instance.cashRecordNode)) {
  358. UiM.Instance.cashRecordNode.getComponent(CashRecordNode).freshRecord()
  359. }
  360. if (UiM.Instance.redCodeNode) {
  361. UiM.Instance.redCodeNode.getComponent(RedCodeNode).freshRecord()
  362. }
  363. }
  364. //获取裂变红包码
  365. getRedCodeByClubCashType() {
  366. let arr = []
  367. for (var i = 0; i < this.clubCashRecord.length; i++) {
  368. if (this.clubCashRecord[i].withdrawCode) {
  369. arr.push(this.clubCashRecord[i])
  370. }
  371. }
  372. return arr
  373. }
  374. shortUrl: string = ""
  375. cashRecord: Array<any> = null
  376. inviteOtherPlayer() {
  377. AdM.onSendEvent('club_ShareInvite', '俱乐部邀请微信分享', 'club')
  378. this.shortUrl = ""
  379. this.cashRecord = null
  380. let uin = GameM.commonData.uin
  381. let url = this.shareUrlWeixin
  382. if (GameM.commonData.clubSharePageMode == 1) {
  383. url = this.shareUrlBrowser
  384. }
  385. url = url + "?inviteuin=" + uin + "&stu=" + GameM.commonData.headimgurl + "&sn=" + GameM.commonData.nickname
  386. GameM.ClubData.requestClubShorturl(url)
  387. GameM.httpM.sendDatas(HTTP_TYPE.getCashRecord, null, GameM.commonData.resultCashRecord.bind(GameM.commonData))
  388. }
  389. sendInviteInfo() {
  390. if (this.cashRecord == null || this.shortUrl == null || this.shortUrl == "") {
  391. LogUtil.logV("sendInviteInfo ", "有一个请求还没到")
  392. return
  393. }
  394. let totalMoney = 0
  395. let readConfig = null
  396. let title = ""
  397. let describe = ""
  398. let imgUrl = ""
  399. let showCfgPool = new Array<any>()
  400. let noMoneyInfoPool = new Array<any>()
  401. for (let entry of this.cashRecord) {
  402. totalMoney += entry.amount
  403. }
  404. for (let entry of this.clubShowShareInfo) {
  405. if (entry.limitMoney == 0) {
  406. noMoneyInfoPool.push(entry)
  407. } else {
  408. showCfgPool.push(entry)
  409. }
  410. }
  411. if (showCfgPool.length > 0 && showCfgPool[0].limitMoney <= totalMoney * 0.0001) {
  412. readConfig = showCfgPool
  413. } else {
  414. readConfig = noMoneyInfoPool
  415. }
  416. let index = Math.floor(Math.random() * readConfig.length)
  417. title = readConfig[index].title
  418. describe = readConfig[index].describe
  419. imgUrl = readConfig[index].imgUrl
  420. if (describe.indexOf("$") >= 0) {
  421. describe = describe.replace("$", (totalMoney * 0.0001).toFixed(2))
  422. }
  423. LogUtil.logV("sendInviteInfo title", title)
  424. LogUtil.logV("sendInviteInfo describe", describe)
  425. LogUtil.logV("sendInviteInfo imgUrl", imgUrl)
  426. let tempStr = this.shortUrl + ""
  427. this.cashRecord = null
  428. this.shortUrl = ""
  429. AdM.shareClubInstallUrl(tempStr, title, describe, imgUrl)
  430. LogUtil.logV("sendInviteInfo", "end")
  431. }
  432. autoCollectBubbles() {
  433. GameM.httpM.sendDatas(HTTP_TYPE.autoCollectBubbles, null, GameM.ClubData.autoCollectBubblesBack.bind(this))
  434. }
  435. autoCollectBubblesBack(data) {
  436. LogUtil.logV('autoCollectBubblesBack ', data)
  437. }
  438. }