VidiDin-Android/app/src/main/java/com/gamedog/vididin/manager/WithdrawManager.kt

677 lines
26 KiB
Kotlin
Raw Normal View History

2025-12-12 07:27:30 +00:00
package com.gamedog.vididin.manager
import com.ama.core.architecture.util.AndroidUtil
2025-12-15 04:37:51 +00:00
import com.ama.core.architecture.util.DateUtil
import com.ama.core.architecture.util.DeviceUtil
import com.ama.core.architecture.util.MD5Util
import com.ama.core.architecture.util.NetUtil
2025-12-12 07:27:30 +00:00
import com.ama.core.architecture.util.SpUtil
2025-12-15 02:47:58 +00:00
import com.ama.core.architecture.util.eventbus.NotifyMan
import com.gamedog.statisticreporter.StatisticUtil
import com.gamedog.vididin.VidiConst
2025-12-15 02:47:58 +00:00
import com.gamedog.vididin.VididinEvents
2026-01-07 07:28:24 +00:00
import com.gamedog.vididin.beans.RECORD_CASH_WITHDRAW
2025-12-24 08:31:38 +00:00
import com.gamedog.vididin.beans.RecordCash
import com.gamedog.vididin.beans.req.PayInitReq
import com.gamedog.vididin.beans.req.PayoutCheckReq
2026-01-07 07:28:24 +00:00
import com.gamedog.vididin.beans.req.PayoutReq
import com.gamedog.vididin.beans.resp.PayInit
import com.gamedog.vididin.beans.resp.PayoutData
2025-12-15 09:30:16 +00:00
import com.gamedog.vididin.core.login.login.AccountManager
2025-12-15 03:39:03 +00:00
import com.gamedog.vididin.manager.WithdrawManager.Companion.STATE_NEED_WATCH_AD
import com.gamedog.vididin.netbase.NetworkUtil
import com.gamedog.vididin.netbase.Result
2025-12-31 07:11:21 +00:00
import com.viddin.videos.free.R
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
2025-12-12 07:27:30 +00:00
class WithdrawManager private constructor() {
2026-01-06 11:14:24 +00:00
private val mBgScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
2025-12-12 07:27:30 +00:00
2026-01-06 11:14:24 +00:00
private val mWithdrawItemList: MutableList<WithdrawItem> by lazy {
val itemList = SpUtil.instance().getList<WithdrawItem>(SpUtil.KEY_WITHDRAW_ITEM_LIST).toMutableList()
2025-12-12 07:27:30 +00:00
if (itemList.isEmpty()) {
itemList.addAll(generateItemList())
2025-12-15 02:47:58 +00:00
saveInfos2Sp(itemList)
2025-12-12 07:27:30 +00:00
}
itemList
}
companion object {
const val EACH_SUB_ITEM_CASH_NUM: Double = 1.0
2025-12-12 07:27:30 +00:00
2026-01-05 08:22:02 +00:00
//----------------------- FROM pagsmile.proto ------------------------------
// init接口 status
// 1可提现 2:条件未达成 3:已提现, 4:禁止提现, 5:提现中
const val INIT_OK = 1
2026-01-07 07:28:24 +00:00
const val ERROR_COMMON_UNKNOW = 999
const val ERROR_INIT_NOT_REACH_CONDITION = 2
const val ERROR_INIT_ALREADY_WITHDRAWED = 3
const val ERROR_INIT_FORBID = 4
const val ERROR_INIT_WITHDRAWING = 5
2026-01-05 08:22:02 +00:00
// init接口 服务器 error 字段
// 0成功1失败2签名验证失败3客户端版本过低4 ts长度错误
2026-01-07 07:28:24 +00:00
const val ERROR_INIT_FAILED_UNKNOW = ERROR_COMMON_UNKNOW
const val ERROR_INIT_APP_VERSION_LOW = 3 + 10
2026-01-05 08:22:02 +00:00
/* payout接口 错误码
0成功1失败2签名验证失败3客户端版本过低4uuid错误5所在地国家或地区不在提现限制内6提现金额不符对应的产品id7提现产品id不对8达到提现金额限制9提现次数超过限制10今日没有提现机会11提现账号达到次数限制12身份审核条件不满足不能提现13巴西提现参数 document_type 错误
14巴西提现参数 document_id 错误15 巴西提现参数 AccountType 错误16 巴西提现参数 Name 错误17巴西提现参数 Account DocumentId 不同18巴西提现参数account_type为CPF时 对应的 account 错误19巴西提现参数account_type为CNPJ时 对应的 account 错误20巴西提现参数 account_type 错误
21巴西提现参数 document_type 错误22巴西提现参数account_type为CPF时 对应的 document_id 错误23巴西提现参数account_type为CNPJ时 对应的 document_id 错误24 ts长度错误25 没提0.1就提现其它的
*/
const val ERROR_PAYOUT_UNKNOW = 1 + 20
const val ERROR_PAYOUT_APP_VERSION_LOW = 3 + 20
const val ERROR_PAYOUT_COUNTRY_RESTRICTION = 5 + 20
const val ERROR_PAYOUT_REACH_TOTAL_LIMIT = 8 + 20
const val ERROR_PAYOUT_REACH_TIMES_LIMIT = 9 + 20
const val ERROR_PAYOUT_TODAY_NO_CHANCE = 10 + 20
const val ERROR_PAYOUT_ACCOUNT_REACH_TIMES_LIMIT = 11 + 20
2026-01-05 11:19:03 +00:00
const val ERROR_PAYOUT_ACCOUNT_INVALID = 18 + 20
2026-01-05 08:22:02 +00:00
const val ERROR_PAYOUT_USER_IDENTITY_LIMIT = 12 + 20
const val ERROR_PAYOUT_MUST_WITHDRAW01_FIRST = 25 + 20
2025-12-22 09:00:22 +00:00
// subBean 状态
2025-12-15 03:39:03 +00:00
const val STATE_NEED_WATCH_AD: Int = 0
const val STATE_COULD_WITHDRAW: Int = 1
const val STATE_WITHDRAWING: Int = 2
const val STATE_HAS_WITHDRAWED: Int = 3
2025-12-25 08:24:33 +00:00
// 提现交易状态 提现状态 0: 未启动 1:提现中,2:提现成功,3:提现失败
const val TRANSACTION_STATE_UNSTART : Int = 0
const val TRANSACTION_STATE_ONGOING : Int = 1
const val TRANSACTION_STATE_SUCCESS : Int = 2
const val TRANSACTION_STATE_FAIL : Int = 3
2025-12-15 03:39:03 +00:00
2025-12-12 07:27:30 +00:00
@Volatile
private var instance: WithdrawManager? = null
fun instance(): WithdrawManager {
return instance ?: synchronized(this) {
instance ?: WithdrawManager().also {
instance = it
}
}
}
}
init {
loopCheckTransactionState()
}
2026-01-06 11:14:24 +00:00
private fun generateItemList(): MutableList<WithdrawItem> {
val itemList = mutableListOf<WithdrawItem>()
itemList.add(WithdrawItem(0, 0.1, isBigWithDraw = false))
itemList.add(WithdrawItem(1, 10.0, AndroidUtil.randomInt(50, 70), generateSubItemList(10.0)))
itemList.add(WithdrawItem(2, 20.0, AndroidUtil.randomInt(50, 70), generateSubItemList(20.0)))
itemList.add(WithdrawItem(3, 50.0, AndroidUtil.randomInt(50, 70), generateSubItemList(50.0)))
itemList.add(WithdrawItem(4, 100.0, AndroidUtil.randomInt(50, 70), generateSubItemList(100.0)))
itemList.add(WithdrawItem(5, 300.0, AndroidUtil.randomInt(50, 70), generateSubItemList(300.0)))
2025-12-12 07:27:30 +00:00
return itemList
}
2026-01-06 09:12:26 +00:00
private fun generateSubItemList(totalCashInItem: Double): List<WithdrawSubItem> {
2025-12-12 07:27:30 +00:00
val subItemList = mutableListOf<WithdrawSubItem>()
val subItemCount: Int = (totalCashInItem/EACH_SUB_ITEM_CASH_NUM).toInt()
for (i in 0..subItemCount-1) {
2025-12-15 02:47:58 +00:00
val initProgress = AndroidUtil.randomInt(50, 70)
subItemList.add(WithdrawSubItem(i, EACH_SUB_ITEM_CASH_NUM, initProgress, initProgress, 0.0))
2025-12-12 07:27:30 +00:00
}
return subItemList
}
2026-01-06 11:14:24 +00:00
private fun saveInfos2Sp(itemList: MutableList<WithdrawItem>) {
2025-12-12 07:27:30 +00:00
SpUtil.instance().putList(SpUtil.KEY_WITHDRAW_ITEM_LIST, itemList)
}
2026-01-06 11:14:24 +00:00
fun getItem(itemIndex: Int): WithdrawItem {
return mWithdrawItemList[itemIndex]
2025-12-12 07:27:30 +00:00
}
2025-12-15 02:47:58 +00:00
fun getHasWithdrawSuccessCashCount(): Double {
return RecordsManager.instance().getHasWithdrawSuccessCashCount()
2025-12-22 06:32:16 +00:00
}
2026-01-06 09:12:26 +00:00
fun addAdEarnForSubBean(itemIndex: Int, selectedSubIndex: Int, earnMoneyNum: Double) : Boolean {
2026-01-06 11:14:24 +00:00
if (itemIndex >= 0 && itemIndex < mWithdrawItemList.size) {
2025-12-15 02:47:58 +00:00
try {
2026-01-06 11:14:24 +00:00
val subBean = mWithdrawItemList[itemIndex].subItemList[selectedSubIndex]
2025-12-15 02:47:58 +00:00
subBean.hasEarnMoneyByAd += earnMoneyNum * 5 // dollar 2 bariz
calculateSubBeanProgress(subBean) //传入 itembean 更新 selectedIndex为下一个
2026-01-06 11:14:24 +00:00
saveInfos2Sp(mWithdrawItemList)
2025-12-15 02:47:58 +00:00
notifyProgressUpdated(subBean)
return true
} catch (e: Exception) {
e.printStackTrace()
}
}
return false
}
private fun notifyProgressUpdated(subBean: WithdrawSubItem) {
NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED,
2026-01-06 11:14:24 +00:00
NotifyMan.NotifyData(subBean.dayIndex))
2025-12-15 02:47:58 +00:00
}
private fun notifySelectedSubBeanChanged(subBean: WithdrawSubItem) {
2026-01-06 11:14:24 +00:00
NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_SELECTED_SUB_ITEM_CHANGED, NotifyMan.NotifyData(subBean.dayIndex))
2025-12-15 02:47:58 +00:00
}
private fun notifyItemListChanged() {
NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_ITEM_LIST_CHANGED, null)
}
2026-01-07 07:35:21 +00:00
private fun notifyWithdrawResult(withdrawRecord: RecordCash) {
2026-01-07 07:28:24 +00:00
NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_RESULT_UPDATED, NotifyMan.NotifyData(withdrawRecord))
}
2025-12-15 02:47:58 +00:00
private fun calculateSubBeanProgress(subBean: WithdrawSubItem) {
val needEarnProgress = 100 - subBean.startAdProgress
2025-12-15 02:47:58 +00:00
if (subBean.hasEarnMoneyByAd >= subBean.cashTotal) {
subBean.currentAdProgress = 100
2025-12-15 03:39:03 +00:00
// update state
if (subBean.withdrawState == STATE_NEED_WATCH_AD) {
subBean.withdrawState = STATE_COULD_WITHDRAW
}
2025-12-15 02:47:58 +00:00
} else {
val newProgress = subBean.startAdProgress + (needEarnProgress * (subBean.hasEarnMoneyByAd / subBean.cashTotal)).toInt()
subBean.currentAdProgress = if (newProgress >= 100) 100 else newProgress
2025-12-15 02:47:58 +00:00
}
2025-12-12 07:27:30 +00:00
}
2025-12-15 03:39:03 +00:00
fun updateSubBeanState(subBean: WithdrawSubItem, newState: Int) {
subBean.withdrawState = newState
2026-01-06 11:14:24 +00:00
saveInfos2Sp(mWithdrawItemList)
2025-12-15 03:39:03 +00:00
}
2026-01-06 11:14:24 +00:00
fun startItem(curItem: WithdrawItem) {
2025-12-15 04:37:51 +00:00
if (curItem.startMs <= 0L) {
curItem.startMs = DateUtil.getCurTimeMs() - (if (curItem.totalCashNum == 50.0) 24 * 3600000 * 4 else 0)
2026-01-06 11:14:24 +00:00
saveInfos2Sp(mWithdrawItemList)
2025-12-15 04:37:51 +00:00
}
}
fun updateRecordHasNotifyState(recordNo: String) {
RecordsManager.instance().updateRecordHasNotifyState(recordNo)
}
2026-01-07 07:30:26 +00:00
fun saveNewWithdrawRecord(newRecord: RecordCash) {
2026-01-07 07:28:24 +00:00
RecordsManager.instance().saveNewWithdrawRecord(newRecord)
}
2025-12-15 09:30:16 +00:00
private fun checkIfItemFinishAndReset(itemIndex: Int) {
var needReset = false
if (itemIndex == 0) {
needReset = true
} else {
var allSubItemFinish = true
2026-01-06 11:14:24 +00:00
mWithdrawItemList[itemIndex].subItemList.forEach {
if (it.withdrawState != STATE_HAS_WITHDRAWED) {
allSubItemFinish = false
return@forEach
}
}
needReset = allSubItemFinish
}
if (needReset) {
2026-01-07 07:30:26 +00:00
resetWithdrawItem(itemIndex)
}
}
2026-01-07 07:30:26 +00:00
private fun resetWithdrawItem(itemIndex: Int) {
2026-01-06 11:14:24 +00:00
val needResetItem = mWithdrawItemList[itemIndex]
needResetItem.apply {
totalProgress = 0
startMs = 0L
hasStarted = false
2026-01-07 07:28:24 +00:00
loopIndex++
subItemList.forEach { subItem ->
subItem.apply {
currentAdProgress = startAdProgress
hasEarnMoneyByAd = 0.0
withdrawState = STATE_NEED_WATCH_AD
}
}
}
notifyItemListChanged()
}
fun getClonedRecordList(): List<RecordCash> {
return RecordsManager.instance().getWithdrawRecordList()
}
private fun getOngoingRecordList(): List<RecordCash> {
return RecordsManager.instance().getOngoingRecordList()
}
private fun loopCheckTransactionState() {
val ongoingList = getOngoingRecordList()
if (ongoingList.isNotEmpty()) {
try {
ongoingList.forEachIndexed { index, record ->
mBgScope.launch {
2026-01-07 07:28:24 +00:00
if (!record.payOutReplyNo.isEmpty()) {
requestCheck(record)
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}
2026-01-07 07:28:24 +00:00
private suspend fun requestCheck(withdrawRecord: RecordCash) {
val recordNo = withdrawRecord.payOutReplyNo
val checkReqParam = applyInitFields(PayoutCheckReq()).apply {
record_no = recordNo
}
2026-01-07 07:28:24 +00:00
val checkReqResult = NetworkUtil.callApi {
NetworkUtil.apiservice().withdrawCheck(checkReqParam)
}
2026-01-07 07:28:24 +00:00
when (checkReqResult) {
is Result.Loading -> {
2026-01-07 07:28:24 +00:00
}
2026-01-07 07:28:24 +00:00
is Result.Error -> {
}
is Result.Success -> {
2026-01-07 07:28:24 +00:00
val checkResult = checkReqResult.data.data
var failedType = -1
when (checkResult?.error) {
0 -> {
when (checkResult.status) {
// 提现状态 1:提现中,2:提现成功,3:提现失败
1 -> {
delay(10000)
loopCheckTransactionState()
}
2 -> {
2026-01-07 07:28:24 +00:00
handleLoopCheckWithdrawSuccess(withdrawRecord)
}
3 -> {
2026-01-07 07:28:24 +00:00
failedType = ERROR_COMMON_UNKNOW
}
}
}
1 -> {
2026-01-07 07:28:24 +00:00
failedType = ERROR_COMMON_UNKNOW
}
2026-01-05 08:22:02 +00:00
3 -> {
2026-01-07 07:28:24 +00:00
failedType = ERROR_PAYOUT_APP_VERSION_LOW
}
}
if (failedType > 0) {
2026-01-07 07:28:24 +00:00
handleWithdrawFailed(failedType, withdrawRecord)
}
}
}
}
2026-01-05 08:22:02 +00:00
fun getFailHintStrRes(failType: Int) : Int {
var failTextRes = R.string.withdraw_normal_fail
2026-01-05 07:26:00 +00:00
when (failType) {
2026-01-07 07:28:24 +00:00
ERROR_COMMON_UNKNOW -> {
failTextRes = R.string.withdraw_normal_fail
}
ERROR_INIT_NOT_REACH_CONDITION -> {
2026-01-05 08:22:02 +00:00
failTextRes = R.string.withdraw_fail_not_reach_condition
}
2026-01-05 07:26:00 +00:00
2026-01-07 07:28:24 +00:00
ERROR_INIT_ALREADY_WITHDRAWED -> {
2026-01-05 08:22:02 +00:00
failTextRes = R.string.withdraw_fail_already_withdraw
}
2026-01-07 07:28:24 +00:00
ERROR_INIT_FORBID -> {
2026-01-05 08:22:02 +00:00
failTextRes = R.string.withdraw_fail_forbidden
}
2026-01-07 07:28:24 +00:00
ERROR_INIT_WITHDRAWING -> {
2026-01-05 08:22:02 +00:00
failTextRes = R.string.withdraw_fail_withdrawing
}
2026-01-07 07:28:24 +00:00
ERROR_INIT_FAILED_UNKNOW -> {
2026-01-05 08:22:02 +00:00
failTextRes = R.string.withdraw_normal_fail
}
2026-01-07 07:28:24 +00:00
ERROR_INIT_APP_VERSION_LOW -> {
2026-01-05 08:22:02 +00:00
failTextRes = R.string.withdraw_fail_version_toolow
}
ERROR_PAYOUT_UNKNOW -> {
failTextRes = R.string.withdraw_normal_fail
}
ERROR_PAYOUT_APP_VERSION_LOW -> {
failTextRes = R.string.withdraw_fail_version_toolow
}
ERROR_PAYOUT_COUNTRY_RESTRICTION -> {
failTextRes = R.string.withdraw_fail_country_restriction
}
ERROR_PAYOUT_REACH_TOTAL_LIMIT -> {
failTextRes = R.string.withdraw_fail_reach_amount_limit
}
ERROR_PAYOUT_REACH_TIMES_LIMIT -> {
failTextRes = R.string.withdraw_fail_reach_times_limit
}
ERROR_PAYOUT_TODAY_NO_CHANCE -> {
failTextRes = R.string.withdraw_fail_today_no_chance
}
ERROR_PAYOUT_ACCOUNT_REACH_TIMES_LIMIT -> {
failTextRes = R.string.withdraw_account_times_limit
}
2026-01-05 11:19:03 +00:00
ERROR_PAYOUT_ACCOUNT_INVALID -> {
failTextRes = R.string.withdraw_account_invalid
}
2026-01-05 08:22:02 +00:00
ERROR_PAYOUT_USER_IDENTITY_LIMIT -> {
failTextRes = R.string.withdraw_fail_user_identity_limit
}
ERROR_PAYOUT_MUST_WITHDRAW01_FIRST -> {
failTextRes = R.string.withdraw_fail_must_withdraw_01_first
}
2026-01-05 07:26:00 +00:00
}
2026-01-05 08:22:02 +00:00
return failTextRes
2026-01-05 07:26:00 +00:00
}
fun <T : PayInitReq> applyInitFields(dataBean: T): T {
dataBean.apply {
platform = "Android"
deviceid = DeviceUtil.generateDeviceId()
version = AndroidUtil.getAppVersionInfo()
ip = NetUtil.getLocalIpAddress()
ts = (System.currentTimeMillis()/1000).toString()
val signOrigin = "${VidiConst.WITHDRAW_MD5KEY}platform=${platform}deviceid=${deviceid}version=${version}ip=${ip}ts=$ts"
sign = MD5Util.md5ForWithDraw(signOrigin)
}
return dataBean
}
2025-12-22 09:00:22 +00:00
fun getItemProgress(itemIndex: Int): Double {
var itemProgress = 0.0
2025-12-22 09:00:22 +00:00
2026-01-06 11:14:24 +00:00
if (itemIndex in 0..mWithdrawItemList.size-1) {
val curItem = mWithdrawItemList[itemIndex]
val userCashTotal = AccountManager.getCash()
if (curItem.hasStarted) {
return 1.0
} else {
itemProgress = if ((userCashTotal / curItem.totalCashNum) > 1.0) 1.0 else userCashTotal / curItem.totalCashNum
2025-12-22 09:00:22 +00:00
}
}
return itemProgress
}
fun setItemStarted(itemIndex: Int) {
2026-01-06 11:14:24 +00:00
if (itemIndex in 0..mWithdrawItemList.size-1) {
val curItem = mWithdrawItemList[itemIndex]
if (!curItem.hasStarted) {
curItem.hasStarted = true
curItem.startMs = System.currentTimeMillis()
AccountManager.adjustCash(-1 * curItem.totalCashNum)
2026-01-06 11:14:24 +00:00
saveInfos2Sp(mWithdrawItemList)
notifyItemListChanged()
}
}
}
2026-01-07 07:28:24 +00:00
// ------------------------------- Withdraw Init and Payout -----------------------------------
fun startWithdrawReal(payCashNum: Double, withdrawItemId: Int, withdrawSubItemId: Int, payItemLoopIndex: Int) {
mBgScope.launch {
val withdrawRecord = RecordCash(RECORD_CASH_WITHDRAW, payCashNum).apply {
uuid = AndroidUtil.randomUUid()
withdrawState = TRANSACTION_STATE_ONGOING
withdrawItemIndex = withdrawItemId
withdrawItemSubIndex = withdrawSubItemId
withdrawItemLoopIndex = payItemLoopIndex
}
2026-01-07 07:30:26 +00:00
saveNewWithdrawRecord(withdrawRecord)
2026-01-07 07:28:24 +00:00
val initReqParam = applyInitFields( PayInitReq())
val initReqResult = NetworkUtil.callApi {
NetworkUtil.apiservice().withdrawInit(initReqParam)
}
when (initReqResult) {
is Result.Loading -> {
}
is Result.Error -> {
handleWithdrawFailed(ERROR_COMMON_UNKNOW, withdrawRecord)
}
is Result.Success<PayInit> -> {
val initResp = initReqResult.data.data
initResp?.let {
var failType = 0
if (it.error == 0 && !it.uuid.isNullOrEmpty() && !it.items.isNullOrEmpty()) {
val isSmallWithdraw = withdrawRecord.amountNum <= VidiConst.WITHDRAW_SMALL_NUM
val withDrawItem = it.items?.get(if (isSmallWithdraw) 0 else 1)!!
if (withDrawItem.status == INIT_OK) {
withdrawRecord.withdrawInitUUID = it.uuid!!
requestPayout(withdrawRecord)
} else {
failType = withDrawItem.status
}
} else {
// 0成功1失败2签名验证失败3客户端版本过低4 ts长度错误
failType = it.error + 10
}
if (failType > 0) {
handleWithdrawFailed(failType, withdrawRecord)
}
}
}
}
}
}
private fun requestPayout(withdrawRecord: RecordCash) {
mBgScope.launch {
val payoutReqParam = applyInitFields(PayoutReq()).apply {
val bankAccount = AccountManager.getAccount().bankInfo?.bankAccount
val accountType = "CPF"
account = bankAccount
item_id = withdrawRecord.withdrawItemIndex
amount = withdrawRecord.amountNum.toString()
additional_remark = "communnyboneycashmoneyrewardfastrealgame"
uuid = withdrawRecord.withdrawInitUUID
account_type = accountType
document_type = accountType
document_id = bankAccount
name = "CapyBucks"
clientName = AndroidUtil.getPackageId()
dataAdjust.gps_adid = "gaid"
dataAdjust.android_id = "androidid"
dataAdjust.adid = "adid"
dataAdjust.user_agent = "GetUerAgent"
dataAdjust.price = amount
dataAdjust.currency = "USD"
dataShuShu.gps_gaid = "gaid"
dataShuShu.android_id = "androidid"
dataShuShu.adid = "adid"
dataShuShu.user_agent = "GetUerAgent"
dataShuShu.price = amount
dataShuShu.currency = "USD"
dataShuShu.payment_method = "Pix"
dataShuShu.payment_type = accountType
dataShuShu.payment_number = account
dataShuShu.iap_name = "100br"
dataShuShu.gamecoin_number = "100"
dataShuShu.gamecoin_type = "gold"
dataShuShu.ss_account_id = "GetSSAccountId"
dataShuShu.ss_distinct_id = "GetSSDistinctId"
dataShuShu.ss_super_properties = "GetSSSuper Properties"
}
val payoutReqResult = NetworkUtil.callApi {
NetworkUtil.apiservice().withdrawPayout(payoutReqParam)
}
when (payoutReqResult) {
Result.Loading -> {
}
is Result.Error -> {
handleWithdrawFailed(ERROR_COMMON_UNKNOW, withdrawRecord)
}
is Result.Success<PayoutData> -> {
val payoutResultData = payoutReqResult.data.data
payoutResultData?.let {
withdrawRecord.payOutReplyId = payoutResultData.id?:""
withdrawRecord.payOutReplyNo = payoutResultData.record_no
if (payoutResultData.error == 0) {
// 1 更新 record并保存
RecordsManager.instance().updateCashRecord(withdrawRecord)
// 2 loop check 最终结果
loopCheckTransactionState()
} else {
var failType: Int? = 0
/* 错误码
0成功1失败2签名验证失败3客户端版本过低4uuid错误5所在地国家或地区不在提现限制内6提现金额不符对应的产品id7提现产品id不对8达到提现金额限制9提现次数超过限制10今日没有提现机会11提现账号达到次数限制12身份审核条件不满足不能提现13巴西提现参数 document_type 错误
14巴西提现参数 document_id 错误15 巴西提现参数 AccountType 错误16 巴西提现参数 Name 错误17巴西提现参数 Account DocumentId 不同18巴西提现参数account_type为CPF时 对应的 account 错误19巴西提现参数account_type为CNPJ时 对应的 account 错误20巴西提现参数 account_type 错误
21巴西提现参数 document_type 错误22巴西提现参数account_type为CPF时 对应的 document_id 错误23巴西提现参数account_type为CNPJ时 对应的 document_id 错误24 ts长度错误25 没提0.1就提现其它的
*/
failType = payoutResultData?.error
if (failType != null && failType > 0) {
failType += 20
handleWithdrawFailed(failType, withdrawRecord)
}
}
}
}
}
}
}
/**
* 统一的失败处理
*/
private fun handleWithdrawFailed(failReasonType: Int, withdrawRecord: RecordCash) {
mBgScope.launch {
// 1. 更新保存 提现记录状态
withdrawRecord.withdrawState = TRANSACTION_STATE_FAIL
withdrawRecord.withdrawFailType = failReasonType
withdrawRecord.hasShowResultDialog = false
RecordsManager.instance().updateCashRecord(withdrawRecord)
// 2. 事件通知以便更新UI
2026-01-07 07:35:21 +00:00
notifyWithdrawResult(withdrawRecord)
2026-01-07 07:28:24 +00:00
// 3. Statistics
StatisticUtil.reportEvents(StatisticUtil.KEY_Withdrawal_Reason, mapOf(
"Reason_Type" to "Fail",
"Fail_Reason" to failReasonType.toString() + " : " + getFailHintStrRes(failReasonType),
"Withdrawal_Position" to withdrawRecord.amountNum,
"Withdrawal_Day" to 1,
))
}
}
private fun handleLoopCheckWithdrawSuccess(withdrawRecord: RecordCash) {
// 1. 更新record 并保存
withdrawRecord.withdrawState = TRANSACTION_STATE_SUCCESS
RecordsManager.instance().updateCashRecord(withdrawRecord)
// 2. 更新取现 条目状态
if (withdrawRecord.withdrawItemIndex >= 0) {
checkIfItemFinishAndReset(withdrawRecord.withdrawItemIndex)
}
// 3. event 通知
2026-01-07 07:35:21 +00:00
notifyWithdrawResult(withdrawRecord)
2026-01-07 07:28:24 +00:00
// 4. Statistic
StatisticUtil.reportEvents(StatisticUtil.KEY_Withdrawal_Reason,
mapOf("Reason_Type" to "Success",
"Fail_Reason" to 0,
"Withdrawal_Position" to withdrawRecord.amountNum,
"Withdrawal_Day" to 1))
}
2025-12-12 07:27:30 +00:00
}
2026-01-06 11:14:24 +00:00
data class WithdrawItem(
2025-12-12 07:27:30 +00:00
val index: Int,
val totalCashNum: Double,
2025-12-12 07:27:30 +00:00
var totalProgress: Int = 0,
2025-12-15 02:47:58 +00:00
val subItemList: List<WithdrawSubItem> = emptyList(),
2025-12-15 04:37:51 +00:00
var startMs: Long = 0L,
2025-12-22 09:00:22 +00:00
var hasStarted: Boolean = false,
2026-01-07 07:28:24 +00:00
var isBigWithDraw: Boolean = true,
var loopIndex: Int = 1
2025-12-12 07:27:30 +00:00
)
data class WithdrawSubItem(
2026-01-06 11:14:24 +00:00
val dayIndex: Int,
val cashTotal: Double,
val startAdProgress: Int = 0,
var currentAdProgress: Int = 0,
var hasEarnMoneyByAd: Double = 0.0,
2025-12-15 03:39:03 +00:00
var withdrawState: Int = STATE_NEED_WATCH_AD,
2025-12-12 07:27:30 +00:00
)