CashOutData.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /** 常规提现数据类 */
  2. import Main from "../Main"
  3. import AdM from "../manager/AdM"
  4. import GameM from "../manager/GameM"
  5. import UiM, { PANEL_NAME } from "../manager/UiM"
  6. import CashOut from "../ui/CashOut"
  7. import EffectNode from "../ui/EffectNode"
  8. import OfficialNode from "../ui/OfficialNode"
  9. import LogUtil from "../utils/LogUtil"
  10. import { HTTP_TYPE } from "./CommonData"
  11. export default class CashOutData {
  12. private static instance: CashOutData = null
  13. static get Instance(): CashOutData {
  14. if (!CashOutData.instance) {
  15. CashOutData.instance = new CashOutData()
  16. }
  17. return CashOutData.instance
  18. }
  19. /** 提现配置 (包括每日提现金额配置)*/
  20. cashCft: any = null
  21. /** 提现状态 */
  22. cashStatus = []
  23. /** 当前可以提现index -1 为没有*/
  24. canCashIndex = -1
  25. /** 检查是否可以提现 */
  26. checkCanCash() {
  27. if (!GameM.commonData.redSwitch) {
  28. return
  29. }
  30. if (!cc.isValid(UiM.Instance) || !cc.isValid(UiM.Instance.hallNode)) {
  31. return
  32. }
  33. let main = UiM.Instance.hallNode.getComponent(Main)
  34. if (this.canCashIndex != -1 || main.hasHand || main.buyHand.active || GameM.commonData.maxCarLevel < this.cashCft[0].type_value) {
  35. return
  36. }
  37. let cfg = this.cashCft
  38. let num = 0
  39. let desIndex = -1
  40. for (var i = 0; i < cfg.length; i++) {
  41. if (cfg[i].num == 1 && this.getCashStatus(cfg[i].index) == 1) {
  42. }
  43. else {
  44. if (num == 3 && desIndex == -1) {
  45. for (var j = i; j < cfg.length; j++) {
  46. if (cfg[j].money == 100) {
  47. if (this.checkCan(cfg[j])) {
  48. this.canCashIndex = cfg[j].index
  49. main.showCashHand()
  50. }
  51. break
  52. }
  53. }
  54. break
  55. }
  56. else {
  57. if (this.checkCan(cfg[i])) {
  58. this.canCashIndex = cfg[i].index
  59. main.showCashHand()
  60. break
  61. }
  62. }
  63. num++
  64. if (cfg[i].money == 100) {
  65. desIndex = cfg[i].index
  66. }
  67. if (num == 4) {
  68. break
  69. }
  70. }
  71. }
  72. }
  73. private checkCan(data) {
  74. let state = false
  75. if (data.money_type == 1) {
  76. state = (data.money * 10000) <= GameM.commonData.redMoney && GameM.commonData.videoTimes >= data.type_value && Number(data.time) <= GameM.commonData.loginDays
  77. }
  78. else if (data.money_type == 2) {
  79. state = (data.money * 10000) <= GameM.commonData.redMoney && GameM.commonData.roleData.lv >= data.type_value && Number(data.time) <= GameM.commonData.loginDays
  80. }
  81. else if (data.money_type == 3) {
  82. state = (data.money * 10000) <= GameM.commonData.redMoney && GameM.commonData.maxCarLevel >= data.type_value && Number(data.time) <= GameM.commonData.loginDays
  83. }
  84. else if (data.money_type == 4) {
  85. state = (data.money * 10000) <= GameM.commonData.redMoney && GameM.commonData.loginDays >= data.type_value && Number(data.time) <= GameM.commonData.loginDays
  86. }
  87. return state
  88. }
  89. /** 提现返回 */
  90. resultCash(data, param) {
  91. LogUtil.logV('resultCash ', this.cashStatus)
  92. this.cashStatus = data.CashStatusList
  93. if (UiM.Instance.hallNode) {
  94. UiM.Instance.hallNode.getComponent(Main).checkTixianPro(true)
  95. }
  96. GameM.commonData.checkCanShowSplash()
  97. //获取当前提现金额
  98. let tmoney = 0
  99. for (var i = 0; i < this.cashStatus.length; i++) {
  100. if (this.cashStatus[i].index == param.index) {
  101. tmoney = this.cashStatus[i].amount * 0.01
  102. break
  103. }
  104. }
  105. //更新显示红包币
  106. GameM.commonData.redMoney -= (tmoney * 10000)
  107. let paramT = {}
  108. paramT['totalNumber'] = GameM.commonData.redMoney
  109. GameM.commonData.resultRedMoney(null, paramT)
  110. AdM.setTAEventUser(1, 'cashTime_total', 1)
  111. AdM.setTAEventUser(1, 'cashMoney_total', tmoney)
  112. AdM.onSendEvent(`cash_${tmoney}`, `第${tmoney}个常规提现成功`, 'cash')
  113. if (UiM.Instance.cashNode) {
  114. UiM.Instance.cashNode.getComponent(CashOut).tiXianSuccess(data.CashMode != 2, tmoney)
  115. }
  116. GameM.commonData.richbank_noSave = 1
  117. if (data.CashMode == 2) {
  118. if (UiM.Instance.cashNode) {
  119. UiM.Instance.cashNode.getComponent(CashOut).setRedCode(param.index, data.withdrawalCode)
  120. }
  121. UiM.Instance.onPanel(PANEL_NAME.OfficialNode, false, () => {
  122. UiM.Instance.officialNode.getComponent(OfficialNode).init(tmoney, data.withdrawalCode);
  123. AdM.onSendEvent('publicmoney_1', '公众号提现-常规', 'publicmoney')
  124. })
  125. }
  126. GameM.httpM.sendDatas(HTTP_TYPE.bankCashRecord, null, GameM.commonData.updateBankPacket.bind(GameM.commonData))
  127. }
  128. resultCashFail(errmsg) {
  129. if (errmsg) {
  130. let tip = ''
  131. if (errmsg.startsWith('errTip')) {
  132. tip = GameM.commonData.TxtCft[0][errmsg]
  133. }
  134. else {
  135. tip = errmsg
  136. }
  137. EffectNode.instance.PlayTip(tip)
  138. }
  139. if (UiM.Instance.cashNode) {
  140. UiM.Instance.cashNode.getComponent(CashOut).tixianFail()
  141. }
  142. }
  143. /** 获取取现状态 */
  144. getCashStatus(index: number) {
  145. let status = 0
  146. let len = this.cashStatus.length
  147. for (var i = 0; i < len; i++) {
  148. if (this.cashStatus[i].index == index) {
  149. status = this.cashStatus[i].status
  150. break
  151. }
  152. }
  153. return status
  154. }
  155. /** 获取提现状态对象 */
  156. getCashStatusByIndex(index: number) {
  157. let obj = null
  158. let len = this.cashStatus.length
  159. for (var i = 0; i < len; i++) {
  160. if (this.cashStatus[i].index == index) {
  161. obj = this.cashStatus[i]
  162. break
  163. }
  164. }
  165. return obj
  166. }
  167. /** 获取提现配置 */
  168. getCashByIndex(index) {
  169. for (var i = 0; i < this.cashCft.length; i++) {
  170. if (index == this.cashCft[i].index) {
  171. return this.cashCft[i]
  172. }
  173. }
  174. return null
  175. }
  176. curCfg = null
  177. /** 检查是否杀死boss */
  178. checkDefeatBoss(cfg) {
  179. this.curCfg = cfg
  180. let data = {
  181. bossCode: this.curCfg.type_value
  182. }
  183. GameM.httpM.sendDatas(HTTP_TYPE.checkDefeatBoss, data, CashOutData.Instance.checkDefeatBossBack.bind(this))
  184. }
  185. checkDefeatBossBack(data) {
  186. LogUtil.logV('checkDefeatBossBack ', data)
  187. let cfg = this.getCashByIndex(this.curCfg.index)
  188. if (data.result == 1) {
  189. UiM.Instance.cashNode.getComponent(CashOut).onTixian(cfg)
  190. }
  191. else {
  192. let monsterName = GameM.commonData.fightRoleCfg[this.curCfg.type_value.toString()].name;
  193. EffectNode.instance.PlayTip(`降服“${monsterName}”后才可提现`)
  194. UiM.Instance.cashNode.getComponent(CashOut).showHand()
  195. }
  196. }
  197. /** 点击怪物返回
  198. * @param cfg 怪物配置
  199. * @returns true 可提现 false 不可提现
  200. */
  201. checkShowTip(cfg) {
  202. let canCash = false
  203. if (GameM.commonData.maxCarLevel < cfg.type_value) {
  204. // let monsterName = GameM.commonData.fightRoleCfg[cfg.type_value.toString()].name;
  205. EffectNode.instance.PlayTip(`合成${cfg.type_value}级武将才可提现`)
  206. // UiM.Instance.cashNode.getComponent(CashOut).showHand()
  207. canCash = false
  208. }
  209. else {
  210. //是否已提现
  211. let hasCashed = false
  212. for (var i = 0; i < this.cashStatus.length; i++) {
  213. if (this.cashStatus[i].index == cfg.index) {
  214. hasCashed = true
  215. break
  216. }
  217. }
  218. if (hasCashed) {
  219. EffectNode.instance.PlayTip(`已提现`)
  220. canCash = false
  221. }
  222. else {
  223. canCash = true
  224. }
  225. }
  226. return canCash
  227. }
  228. }