From e2bdd75db4a9ace2096506250ce05daac2b6224d Mon Sep 17 00:00:00 2001 From: renhaoting <370797079@qq.com> Date: Wed, 7 Jan 2026 15:28:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=A4=84=E7=90=86=E6=8F=90?= =?UTF-8?q?=E7=8E=B0=E6=B5=81=E7=A8=8B=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gamedog/vididin/VididinEvents.kt | 2 +- .../com/gamedog/vididin/beans/RecordCash.kt | 50 ++- .../features/withdraw/WithDrawActivity.kt | 127 +------ .../features/withdraw/WithDrawSubActivity.kt | 126 +------ .../withdrawrecord/RecordCashRvAdapter.kt | 4 - .../gamedog/vididin/manager/RecordsManager.kt | 4 +- .../vididin/manager/WithdrawManager.kt | 329 ++++++++++++++---- 7 files changed, 305 insertions(+), 337 deletions(-) diff --git a/app/src/main/java/com/gamedog/vididin/VididinEvents.kt b/app/src/main/java/com/gamedog/vididin/VididinEvents.kt index 7e16937..30259ab 100644 --- a/app/src/main/java/com/gamedog/vididin/VididinEvents.kt +++ b/app/src/main/java/com/gamedog/vididin/VididinEvents.kt @@ -50,7 +50,7 @@ object VididinEvents { // Withdraw related const val EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED = 500 const val EVENT_WITHDRAW_SELECTED_SUB_ITEM_CHANGED = 501 - const val EVENT_WITHDRAW_CHECK_RESULT_UPDATED = 502 + const val EVENT_WITHDRAW_RESULT_UPDATED = 502 const val EVENT_WITHDRAW_ITEM_LIST_CHANGED = 503 const val EVENT_WITHDRAW_BANK_ACCOUNT_CHANGED = 504 diff --git a/app/src/main/java/com/gamedog/vididin/beans/RecordCash.kt b/app/src/main/java/com/gamedog/vididin/beans/RecordCash.kt index cf1036b..7cbe3c9 100644 --- a/app/src/main/java/com/gamedog/vididin/beans/RecordCash.kt +++ b/app/src/main/java/com/gamedog/vididin/beans/RecordCash.kt @@ -3,7 +3,9 @@ package com.gamedog.vididin.beans import com.ama.core.architecture.util.AndroidUtil import com.ama.core.architecture.util.DateUtil import com.gamedog.vididin.manager.WithdrawManager +import com.gamedog.vididin.manager.WithdrawManager.Companion.TRANSACTION_STATE_FAIL import com.gamedog.vididin.manager.WithdrawManager.Companion.TRANSACTION_STATE_ONGOING +import com.gamedog.vididin.manager.WithdrawManager.Companion.TRANSACTION_STATE_SUCCESS import com.viddin.videos.free.R @@ -11,9 +13,8 @@ import com.viddin.videos.free.R const val RECORD_CASH_PLUS_GOLD_CONVERT: Int = 1 const val RECORD_CASH_PLUS_BOX_TASK: Int = 2 const val RECORD_CASH_PLUS_WITHDRAW_ONGOING: Int = 3 -const val RECORD_CASH_PLUS_WITHDRAW_FAIL: Int = 4 -const val RECORD_CASH_WITHDRAW: Int = 5 -const val RECORD_CASH_ZERO_WITHDRAW_SUCCESS: Int = 6 +const val RECORD_CASH_WITHDRAW: Int = 4 +const val RECORD_CASH_ZERO_WITHDRAW_SUCCESS: Int = 5 abstract class BaseRecord { var dateMs: Long = DateUtil.getCurTimeMs() @@ -27,11 +28,13 @@ open class RecordCash (var recordType: Int = 0, var payOutReplyId: String = "" var payOutReplyNo: String = "" var withdrawState: Int = TRANSACTION_STATE_ONGOING // 提现状态 1:提现中,2:提现成功,3:提现失败 - var failReason: Int = WithdrawManager.INIT_OK - var withdrawFailType: Int = 0 - var withdrawItemIndex: Int = 0 - var withdrawItemSubIndex: Int = 0 + var withdrawFailType: Int = WithdrawManager.INIT_OK + var withdrawItemIndex: Int = -1 + var withdrawItemLoopIndex: Int = -1 + var withdrawItemSubIndex: Int = -1 + var withdrawInitUUID: String = "" var hasShowResultDialog: Boolean = false + } class RecordCashShow: RecordCash() { @@ -71,18 +74,29 @@ fun RecordCash.toShowBean(): RecordCashShow { textColor = R.color.red_28 } - RECORD_CASH_PLUS_WITHDRAW_FAIL -> { - title = R.string.record_cash_title_withdraw_failed - description = WithdrawManager.instance().getFailHintStrRes(withdrawFailType) - iconRes = R.mipmap.icon_fail - textColor = R.color.gray3 - } - RECORD_CASH_WITHDRAW -> { - title = R.string.record_cash_title_withdraw_success - description = R.string.record_cash_descr_withdraw_success - iconRes = R.mipmap.icon_check - textColor = R.color.green_39 + when (withdrawState) { + TRANSACTION_STATE_ONGOING -> { + title = R.string.record_cash_title_withdraw_ongoing + description = R.string.record_cash_descr_withdraw_onging + iconRes = R.mipmap.icon_withdraw_ongoing + textColor = R.color.green_39 + } + + TRANSACTION_STATE_SUCCESS -> { + title = R.string.record_cash_title_withdraw_success + description = R.string.record_cash_descr_withdraw_success + iconRes = R.mipmap.icon_check + textColor = R.color.green_39 + } + + TRANSACTION_STATE_FAIL -> { + title = R.string.record_cash_title_withdraw_failed + description = WithdrawManager.instance().getFailHintStrRes(withdrawFailType) + iconRes = R.mipmap.icon_fail + textColor = R.color.gray3 + } + } } RECORD_CASH_ZERO_WITHDRAW_SUCCESS -> { diff --git a/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawActivity.kt b/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawActivity.kt index 03abb00..93473f1 100644 --- a/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawActivity.kt +++ b/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawActivity.kt @@ -3,10 +3,8 @@ package com.gamedog.vididin.features.withdraw import android.app.Activity import android.content.Intent import android.view.LayoutInflater -import androidx.activity.viewModels import androidx.core.graphics.toColorInt import androidx.core.view.isVisible -import androidx.lifecycle.lifecycleScope import com.ama.core.architecture.appBase.AppViewsEmptyViewModelActivity import com.ama.core.architecture.highlightpro.HighlightPro import com.ama.core.architecture.highlightpro.parameter.Constraints @@ -18,12 +16,9 @@ import com.ama.core.architecture.util.ResUtil.dp import com.ama.core.architecture.util.SpUtil import com.ama.core.architecture.util.setOnClickBatch import com.gamedog.statisticreporter.StatisticUtil -import com.gamedog.vididin.VidiConst import com.viddin.videos.free.R import com.gamedog.vididin.VididinEvents -import com.gamedog.vididin.beans.RECORD_CASH_WITHDRAW import com.gamedog.vididin.beans.RecordCash -import com.gamedog.vididin.beans.resp.PayoutReply import com.gamedog.vididin.core.login.login.AccountManager import com.gamedog.vididin.features.withdraw.dialogs.WithdrawBindBankDialog import com.gamedog.vididin.features.withdraw.dialogs.WithdrawFailDialog @@ -35,19 +30,14 @@ import com.gamedog.vididin.manager.WithdrawManager import com.gamedog.vididin.manager.WithdrawManager.Companion.TRANSACTION_STATE_FAIL import com.gamedog.vididin.manager.WithdrawManager.Companion.TRANSACTION_STATE_ONGOING import com.gamedog.vididin.manager.WithdrawManager.Companion.TRANSACTION_STATE_SUCCESS -import com.gamedog.vididin.netbase.Result import com.gamedog.vididin.router.Router import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch -import kotlin.getValue import com.viddin.videos.free.databinding.ActivityWithdrawBinding as ViewBinding @AndroidEntryPoint class WithDrawActivity : AppViewsEmptyViewModelActivity() { - - private val viewModel: WithdrawViewModel by viewModels() private val mItemViewList: MutableList = mutableListOf() @@ -138,8 +128,10 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { StatisticUtil.reportEvents(StatisticUtil.KEY_Withdrawal_finsh, mapOf("Withdrawal_Position" to cashNum)) } + private fun startRealWithdraw(cashNum: Double) { - requestInit(cashNum) + // payCashNum: Double, payItemId: Int, paySubItemId: Int, payItemLoopIndex: Int + WithdrawManager.instance().startWithdrawReal(cashNum, 0, 0, 1) WithdrawManager.instance().setItemStarted(0) } @@ -171,7 +163,7 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { requestInit(notifyData.extraData)*/ } - VididinEvents.EVENT_WITHDRAW_CHECK_RESULT_UPDATED -> { + VididinEvents.EVENT_WITHDRAW_RESULT_UPDATED -> { try { val record = data.mData as RecordCash if (record.withdrawItemIndex == 0) { @@ -195,7 +187,7 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { }, VididinEvents.Event_Account_Cash_Changed, VididinEvents.EVENT_AD_WATCHED_FOR_WITHDRAW_SMALL, - VididinEvents.EVENT_WITHDRAW_CHECK_RESULT_UPDATED, + VididinEvents.EVENT_WITHDRAW_RESULT_UPDATED, VididinEvents.EVENT_WITHDRAW_ITEM_LIST_CHANGED, VididinEvents.EVENT_BANK_INFO_CHANGED) @@ -213,101 +205,6 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { //TODO("Not yet implemented") } - - private fun requestInit(withdrawNum: Double) { - lifecycleScope.launch { - viewModel.InitData.collect { result -> - when (result) { - is Result.Loading -> { - - } - is Result.Success -> { - val reqInitBean = result.data.data - - reqInitBean?.let { - var failType = 0 - - if (it.error == 0 && !it.uuid.isNullOrEmpty() && !it.items.isNullOrEmpty()) { - val itemId = if (withdrawNum <= VidiConst.WITHDRAW_SMALL_NUM) 0 else 1 - val withDrawItem = it.items?.get(itemId)!! - if (withDrawItem.status == WithdrawManager.INIT_OK) { - requestPayout(it.uuid!!, withDrawItem.id, withdrawNum) - } else { - failType = withDrawItem.status - } - - } else { - // 0成功,1失败,2签名验证失败,3客户端版本过低,4 ts长度错误 - failType = it.error + 10 - } - - if (failType > 0) { - showFailDialog(WithdrawManager.instance().getFailHintStrRes(failType)) - - StatisticUtil.reportEvents(StatisticUtil.KEY_Withdrawal_Reason, mapOf( - "Reason_Type" to "Fail", - "Fail_Reason" to failType, - "Withdrawal_Position" to withdrawNum, - "Withdrawal_Day" to 1, - )) - } - } - - } - is Result.Error -> { - showFailDialog(R.string.withdraw_fail_unkown_error) - } - } - } - } - - viewModel.withdrawInit() - } - - private fun requestPayout(initUUID: String, payItemId: Int, payCashNum: Double) { - val currentTimeMs = System.currentTimeMillis() - - lifecycleScope.launch { - viewModel.PayoutResult.collect { result -> - when (result) { - is Result.Loading -> { - } - is Result.Success -> { - var failType: Int? = 0 - - if (result.data?.data?.error == 0) { - saveNewRecord(result.data.data!!, payCashNum, currentTimeMs) - } else { - /* 错误码, - 0成功,1失败,2签名验证失败,3客户端版本过低,4uuid错误,5所在地国家或地区不在提现限制内,6提现金额不符对应的产品id,7提现产品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 = result.data?.data?.error - if (failType != null && failType > 0) { - failType += 20 - showFailDialog(WithdrawManager.instance().getFailHintStrRes(failType)) - - StatisticUtil.reportEvents(StatisticUtil.KEY_Withdrawal_Reason, mapOf( - "Reason_Type" to "Fail", - "Fail_Reason" to failType, - "Withdrawal_Position" to payCashNum, - "Withdrawal_Day" to 1, - )) - } - } - } - is Result.Error -> { - showFailDialog(R.string.withdraw_fail_unkown_error) - } - } - } - } - - - viewModel.withdrawPayout(initUUID, payItemId, payCashNum) - } - private fun showSuccessDialog(cashNum: Double) { WithdrawSuccessDialog(this@WithDrawActivity, cashNum).show() } @@ -340,25 +237,13 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { } TRANSACTION_STATE_FAIL -> { - showFailDialog(WithdrawManager.instance().getFailHintStrRes(record.failReason)) + showFailDialog(WithdrawManager.instance().getFailHintStrRes(record.withdrawFailType)) WithdrawManager.instance().updateRecordHasNotifyState(record.payOutReplyNo) } } } } - private fun saveNewRecord(payoutReply: PayoutReply, payCashNum: Double, timeMsNow: Long) { - val newRecord = RecordCash(RECORD_CASH_WITHDRAW, payCashNum).apply { - payOutReplyId = payoutReply.id!! - payOutReplyNo = payoutReply.record_no - dateMs = timeMsNow - withdrawState = TRANSACTION_STATE_ONGOING - failReason = 0 - } - - WithdrawManager.instance().saveNewRecord(newRecord) - } - private fun needShowGuide(): Boolean { return SpUtil.instance().getInt(SpUtil.KEY_GUIDE_HAS_SHOW) < 5 } diff --git a/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawSubActivity.kt b/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawSubActivity.kt index 5f52d13..6a74788 100644 --- a/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawSubActivity.kt +++ b/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawSubActivity.kt @@ -9,7 +9,6 @@ import android.text.style.ForegroundColorSpan import android.view.LayoutInflater import androidx.activity.viewModels import androidx.core.view.isVisible -import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import com.ama.core.architecture.appBase.AppViewsEmptyViewModelActivity import com.ama.core.architecture.util.AndroidUtil @@ -20,10 +19,8 @@ import com.ama.core.architecture.util.setOnClickBatch import com.gamedog.statisticreporter.StatisticUtil import com.gamedog.vididin.VidiConst import com.gamedog.vididin.VididinEvents -import com.gamedog.vididin.beans.RECORD_CASH_WITHDRAW import com.gamedog.vididin.beans.RecordCash import com.gamedog.vididin.beans.WatchAdNotifyBean -import com.gamedog.vididin.beans.resp.PayoutReply import com.gamedog.vididin.core.login.login.AccountManager import com.gamedog.vididin.features.withdraw.dialogs.WithdrawBindBankDialog import com.gamedog.vididin.features.withdraw.dialogs.WithdrawFailDialog @@ -31,15 +28,12 @@ import com.gamedog.vididin.features.withdraw.dialogs.WithdrawInfoConfirmDialog import com.gamedog.vididin.features.withdraw.dialogs.WithdrawSuccessDialog import com.gamedog.vididin.manager.WithdrawItem import com.gamedog.vididin.manager.WithdrawManager -import com.gamedog.vididin.manager.WithdrawManager.Companion.INIT_OK import com.gamedog.vididin.manager.WithdrawManager.Companion.TRANSACTION_STATE_FAIL import com.gamedog.vididin.manager.WithdrawManager.Companion.TRANSACTION_STATE_ONGOING import com.gamedog.vididin.manager.WithdrawManager.Companion.TRANSACTION_STATE_SUCCESS import com.gamedog.vididin.router.Router -import com.gamedog.vididin.router.Router.WithdrawRecord import com.viddin.videos.free.R import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch import kotlin.getValue import com.viddin.videos.free.databinding.ActivityWithdrawSubBinding as ViewBinding @@ -47,8 +41,6 @@ import com.viddin.videos.free.databinding.ActivityWithdrawSubBinding as ViewBind @AndroidEntryPoint class WithDrawSubActivity : AppViewsEmptyViewModelActivity() { - private val viewModel: WithdrawViewModel by viewModels() - private lateinit var mCurItem: WithdrawItem private var mSelectingIndex: Int = 0 private var mType: Int = 0 @@ -102,116 +94,18 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity() { private fun tryRequestWithdraw() { val subBean = mCurItem.subItemList[mSelectingIndex] if (AccountManager.isBankAccountExist()) { - WithdrawInfoConfirmDialog(this@WithDrawSubActivity, { cashNum -> requestInit(cashNum) }).setWithDrawCashNum(subBean.cashTotal).show() + WithdrawInfoConfirmDialog(this@WithDrawSubActivity, { cashNum -> startRealWithdraw(cashNum) }).setWithDrawCashNum(subBean.cashTotal).show() } else { - WithdrawBindBankDialog(this@WithDrawSubActivity, { cashNum -> requestInit(cashNum) }).setWithDrawCashNum(subBean.cashTotal).show() + WithdrawBindBankDialog(this@WithDrawSubActivity, { cashNum -> startRealWithdraw(cashNum) }).setWithDrawCashNum(subBean.cashTotal).show() } } - private fun saveNewRecord(payoutReply: PayoutReply, payCashNum: Double, timeMs: Long) { - val newRecord = RecordCash(RECORD_CASH_WITHDRAW, payCashNum).apply { - payOutReplyId = payoutReply.id!! - payOutReplyNo = payoutReply.record_no - dateMs = timeMs - withdrawState = TRANSACTION_STATE_ONGOING - failReason = 0 - - withdrawItemIndex = mCurItem.index - withdrawItemSubIndex = mSelectingIndex - } - WithdrawManager.instance().saveNewRecord(newRecord) - } - - private fun requestInit(withdrawNum: Double) { - lifecycleScope.launch { - viewModel.InitData.collect { result -> - when (result) { - is com.gamedog.vididin.netbase.Result.Loading -> { - - } - is com.gamedog.vididin.netbase.Result.Success -> { - val reqInitBean = result.data.data - - reqInitBean?.let { - var errorHintRes = 0 - - if (it.error == 0 && !it.uuid.isNullOrEmpty() && !it.items.isNullOrEmpty()) { - val itemId = if (withdrawNum <= VidiConst.WITHDRAW_SMALL_NUM) 0 else 1 - val withDrawItem = it.items?.get(itemId)!! - if (withDrawItem.status == INIT_OK) { - requestPayout(it.uuid!!, withDrawItem.id, withdrawNum) - } else { - errorHintRes = R.string.withdraw_fail_reach_day_limit - } - - } else { - // 0成功,1失败,2签名验证失败,3客户端版本过低,4 ts长度错误 - when (it.error) { - 3-> errorHintRes = R.string.withdraw_fail_version_toolow - } - } - - if (errorHintRes > 0) { - showFailDialog(errorHintRes) - } - } - - } - is com.gamedog.vididin.netbase.Result.Error -> { - showFailDialog(R.string.withdraw_fail_unkown_error) - } - } - } - } - - viewModel.withdrawInit() - } - - private fun requestPayout(initUUID: String, payItemId: Int, payCashNum: Double) { - val currentTimeMs = System.currentTimeMillis() - - lifecycleScope.launch { - viewModel.PayoutResult.collect { result -> - when (result) { - is com.gamedog.vididin.netbase.Result.Loading -> { - } - is com.gamedog.vididin.netbase.Result.Success -> { - var errHintRes = 0 - - when (result.data?.data?.error) { - /* 错误码, - 0成功,1失败,2签名验证失败,3客户端版本过低,4uuid错误,5所在地国家或地区不在提现限制内,6提现金额不符对应的产品id,7提现产品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就提现其它的 - */ - 0 -> { - saveNewRecord(result.data.data!!, payCashNum, currentTimeMs) - } - 5-> { - errHintRes = R.string.withdraw_fail_region_restricit - } - 8-> { - errHintRes = R.string.withdraw_fail_amount_limit - } - 9-> { - errHintRes = R.string.withdraw_fail_amount_limit - } - } - - if (errHintRes > 0) { - showFailDialog(errHintRes) - } - } - is com.gamedog.vididin.netbase.Result.Error -> { - showFailDialog(R.string.withdraw_fail_unkown_error) - } - } - } - } - - - viewModel.withdrawPayout(initUUID, payItemId, payCashNum) + private fun startRealWithdraw(cashNum: Double) { + val withdrawItemIndex = mCurItem.index + val withdrawSubItemIndex = mCurItem.subItemList[mSelectingIndex].dayIndex + WithdrawManager.instance().startWithdrawReal(cashNum, withdrawItemIndex, withdrawSubItemIndex, mCurItem.loopIndex) + WithdrawManager.instance().setItemStarted(0) } @@ -252,7 +146,7 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity() { updateUI() } - VididinEvents.EVENT_WITHDRAW_CHECK_RESULT_UPDATED -> { + VididinEvents.EVENT_WITHDRAW_RESULT_UPDATED -> { try { val record = data.mData as RecordCash if (record.withdrawItemIndex > 0) { @@ -266,7 +160,7 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity() { }, VididinEvents.EVENT_AD_WATCHED_FOR_WITHDRAW_BIG, VididinEvents.EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED, VididinEvents.EVENT_WITHDRAW_SELECTED_SUB_ITEM_CHANGED, - VididinEvents.EVENT_WITHDRAW_CHECK_RESULT_UPDATED ) + VididinEvents.EVENT_WITHDRAW_RESULT_UPDATED ) mCurItem = WithdrawManager.instance().getItem(mType) @@ -286,7 +180,7 @@ class WithDrawSubActivity : AppViewsEmptyViewModelActivity() { } TRANSACTION_STATE_FAIL -> { - showFailDialog(WithdrawManager.instance().getFailHintStrRes(record.failReason)) + showFailDialog(WithdrawManager.instance().getFailHintStrRes(record.withdrawFailType)) WithdrawManager.instance().updateRecordHasNotifyState(record.payOutReplyNo) } } diff --git a/app/src/main/java/com/gamedog/vididin/features/withdrawrecord/RecordCashRvAdapter.kt b/app/src/main/java/com/gamedog/vididin/features/withdrawrecord/RecordCashRvAdapter.kt index 80be153..f1f4390 100644 --- a/app/src/main/java/com/gamedog/vididin/features/withdrawrecord/RecordCashRvAdapter.kt +++ b/app/src/main/java/com/gamedog/vididin/features/withdrawrecord/RecordCashRvAdapter.kt @@ -8,9 +8,7 @@ import androidx.recyclerview.widget.RecyclerView import com.ama.core.architecture.util.ResUtil import com.gamedog.vididin.VidiConst import com.gamedog.vididin.beans.RECORD_CASH_PLUS_GOLD_CONVERT -import com.gamedog.vididin.beans.RECORD_CASH_PLUS_WITHDRAW_FAIL import com.gamedog.vididin.beans.RecordCashShow -import com.gamedog.vididin.manager.WithdrawManager import com.viddin.videos.free.R import java.text.SimpleDateFormat import com.viddin.videos.free.databinding.FragmentWithdrawRecordCashItemBinding as ViewBinding @@ -37,8 +35,6 @@ class RecordCashRvAdapter : ListAdapter() { try { mRecordLocker.lock() mRecordList.add(newRecord) + saveRecordList2Sp() } finally { mRecordLocker.unlock() } - saveRecordList2Sp() } fun updateRecord(recordNo: String, newState: Int, failType: Int): Int { @@ -203,7 +203,7 @@ class CashRecordHelper() : BaseRecordHelper() { if (record.withdrawState != newState) { withdrawItemIndex = record.withdrawItemIndex record.withdrawState = newState - record.failReason = failType + record.withdrawFailType = failType } return@forEachIndexed } diff --git a/app/src/main/java/com/gamedog/vididin/manager/WithdrawManager.kt b/app/src/main/java/com/gamedog/vididin/manager/WithdrawManager.kt index 35f1e8a..00fe1a5 100644 --- a/app/src/main/java/com/gamedog/vididin/manager/WithdrawManager.kt +++ b/app/src/main/java/com/gamedog/vididin/manager/WithdrawManager.kt @@ -10,9 +10,13 @@ import com.ama.core.architecture.util.eventbus.NotifyMan import com.gamedog.statisticreporter.StatisticUtil import com.gamedog.vididin.VidiConst import com.gamedog.vididin.VididinEvents +import com.gamedog.vididin.beans.RECORD_CASH_WITHDRAW import com.gamedog.vididin.beans.RecordCash import com.gamedog.vididin.beans.req.PayInitReq import com.gamedog.vididin.beans.req.PayoutCheckReq +import com.gamedog.vididin.beans.req.PayoutReq +import com.gamedog.vididin.beans.resp.PayInit +import com.gamedog.vididin.beans.resp.PayoutData import com.gamedog.vididin.core.login.login.AccountManager import com.gamedog.vididin.manager.WithdrawManager.Companion.STATE_NEED_WATCH_AD import com.gamedog.vididin.netbase.NetworkUtil @@ -47,14 +51,15 @@ class WithdrawManager private constructor() { // init接口 status // 1可提现 2:条件未达成 3:已提现, 4:禁止提现, 5:提现中 const val INIT_OK = 1 - const val ERROR_NOT_REACH_CONDITION = 2 - const val ERROR_ALREADY_WITHDRAWED = 3 - const val ERROR_FORBID = 4 - const val ERROR_WITHDRAWING = 5 + 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 // init接口 服务器 error 字段 // 0成功,1失败,2签名验证失败,3客户端版本过低,4 ts长度错误 - const val ERROR_FAILED_UNKNOW = 1 + 10 - const val ERROR_APP_VERSION_LOW = 3 + 10 + const val ERROR_INIT_FAILED_UNKNOW = ERROR_COMMON_UNKNOW + const val ERROR_INIT_APP_VERSION_LOW = 3 + 10 /* payout接口: 错误码, 0成功,1失败,2签名验证失败,3客户端版本过低,4uuid错误,5所在地国家或地区不在提现限制内,6提现金额不符对应的产品id,7提现产品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 错误, @@ -181,6 +186,10 @@ class WithdrawManager private constructor() { NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_ITEM_LIST_CHANGED, null) } + private fun notifyWithdrawResult2(withdrawRecord: RecordCash) { + NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_RESULT_UPDATED, NotifyMan.NotifyData(withdrawRecord)) + } + private fun calculateSubBeanProgress(subBean: WithdrawSubItem) { val needEarnProgress = 100 - subBean.startAdProgress @@ -217,6 +226,10 @@ class WithdrawManager private constructor() { loopCheckTransactionState() } + fun saveNewRecord2(newRecord: RecordCash) { + RecordsManager.instance().saveNewWithdrawRecord(newRecord) + } + fun updateRecord(recordNo: String, newState: Int, failType: Int = 0) { val withdrawItemIndex = RecordsManager.instance().withdrawUpdateRecord(recordNo, newState, failType) @@ -237,7 +250,6 @@ class WithdrawManager private constructor() { return@forEach } } - needReset = allSubItemFinish } @@ -252,6 +264,7 @@ class WithdrawManager private constructor() { totalProgress = 0 startMs = 0L hasStarted = false + loopIndex++ subItemList.forEach { subItem -> subItem.apply { @@ -281,12 +294,13 @@ class WithdrawManager private constructor() { private fun loopCheckTransactionState() { val ongoingList = getOngoingRecordList() - if (ongoingList.isNotEmpty()) { try { ongoingList.forEachIndexed { index, record -> mBgScope.launch { - requestCheck(record.payOutReplyNo) + if (!record.payOutReplyNo.isEmpty()) { + requestCheck(record) + } } } } catch (e: Exception) { @@ -295,24 +309,26 @@ class WithdrawManager private constructor() { } } - private suspend fun requestCheck(recordNo: String) { - val requestParam = applyInitFields(PayoutCheckReq()).apply { + private suspend fun requestCheck(withdrawRecord: RecordCash) { + val recordNo = withdrawRecord.payOutReplyNo + val checkReqParam = applyInitFields(PayoutCheckReq()).apply { record_no = recordNo } - val reqResult = NetworkUtil.callApi { - NetworkUtil.apiservice().withdrawCheck(requestParam) + val checkReqResult = NetworkUtil.callApi { + NetworkUtil.apiservice().withdrawCheck(checkReqParam) } - when (reqResult) { + when (checkReqResult) { is Result.Loading -> { + } + is Result.Error -> { } is Result.Success -> { - val checkResult = reqResult.data.data - var failedType = ERROR_FAILED_UNKNOW - + val checkResult = checkReqResult.data.data + var failedType = -1 when (checkResult?.error) { 0 -> { when (checkResult.status) { @@ -322,59 +338,31 @@ class WithdrawManager private constructor() { loopCheckTransactionState() } 2 -> { - handleTransactionSuccess(recordNo) + handleLoopCheckWithdrawSuccess(withdrawRecord) } 3 -> { - failedType = ERROR_FAILED_UNKNOW + failedType = ERROR_COMMON_UNKNOW } } } 1 -> { - failedType = ERROR_FAILED_UNKNOW + failedType = ERROR_COMMON_UNKNOW } 3 -> { - failedType = ERROR_APP_VERSION_LOW + failedType = ERROR_PAYOUT_APP_VERSION_LOW } } if (failedType > 0) { - handleTransactionFailed(recordNo, failedType) + handleWithdrawFailed(failedType, withdrawRecord) } } - is Result.Error -> { - - } } } - private fun handleTransactionSuccess(recordNo: String) { - updateRecord(recordNo, TRANSACTION_STATE_SUCCESS) - notifyWithdrawCheckResult(recordNo) - val recordBean = getRecord(recordNo) - recordBean?.let { - RecordsManager.instance().withdrawUpdateRecord(recordNo, TRANSACTION_STATE_SUCCESS, 0) - updateFirstWithdraw01Task(it) - sendWithdrawResultStatistic(it.amountNum, true, 0) - } - } - - private fun updateFirstWithdraw01Task(recordBean: RecordCash) { - if (recordBean.amountNum == 0.1 && !TaskManager.instance().newbieFirstWithdrawStatus().getStatusBean().hasClaimReward) { - TaskManager.instance().newbieFirstWithdrawStatus().claimReward() - } - } - - private fun handleTransactionFailed(recordNo: String, failedType: Int) { - updateRecord(recordNo, TRANSACTION_STATE_FAIL, failedType) - notifyWithdrawCheckResult(recordNo) - val recordBean = getRecord(recordNo) - recordBean?.let { - sendWithdrawResultStatistic(it.amountNum, false, failedType) - } - } private fun sendWithdrawResultStatistic(cashNum: Double, isSuccess: Boolean, failType: Int) { StatisticUtil.reportEvents(StatisticUtil.KEY_Withdrawal_Reason, @@ -387,27 +375,31 @@ class WithdrawManager private constructor() { fun getFailHintStrRes(failType: Int) : Int { var failTextRes = R.string.withdraw_normal_fail when (failType) { - ERROR_NOT_REACH_CONDITION -> { - failTextRes = R.string.withdraw_fail_not_reach_condition - } - - ERROR_ALREADY_WITHDRAWED -> { - failTextRes = R.string.withdraw_fail_already_withdraw - } - - ERROR_FORBID -> { - failTextRes = R.string.withdraw_fail_forbidden - } - - ERROR_WITHDRAWING -> { - failTextRes = R.string.withdraw_fail_withdrawing - } - - ERROR_FAILED_UNKNOW -> { + ERROR_COMMON_UNKNOW -> { failTextRes = R.string.withdraw_normal_fail } - ERROR_APP_VERSION_LOW -> { + ERROR_INIT_NOT_REACH_CONDITION -> { + failTextRes = R.string.withdraw_fail_not_reach_condition + } + + ERROR_INIT_ALREADY_WITHDRAWED -> { + failTextRes = R.string.withdraw_fail_already_withdraw + } + + ERROR_INIT_FORBID -> { + failTextRes = R.string.withdraw_fail_forbidden + } + + ERROR_INIT_WITHDRAWING -> { + failTextRes = R.string.withdraw_fail_withdrawing + } + + ERROR_INIT_FAILED_UNKNOW -> { + failTextRes = R.string.withdraw_normal_fail + } + + ERROR_INIT_APP_VERSION_LOW -> { failTextRes = R.string.withdraw_fail_version_toolow } @@ -454,12 +446,6 @@ class WithdrawManager private constructor() { return failTextRes } - private fun notifyWithdrawCheckResult(recordNo: String) { - val recordBean = getRecord(recordNo) - recordBean.let { - NotifyMan.instance().sendEvent(VididinEvents.EVENT_WITHDRAW_CHECK_RESULT_UPDATED, NotifyMan.NotifyData(it)) - } - } fun applyInitFields(dataBean: T): T { dataBean.apply { @@ -506,6 +492,198 @@ class WithdrawManager private constructor() { } + + + + // ------------------------------- 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 + } + saveNewRecord2(withdrawRecord) + + 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 -> { + 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 -> { + 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提现金额不符对应的产品id,7提现产品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 + notifyWithdrawResult2(withdrawRecord) + + // 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 通知 + notifyWithdrawResult2(withdrawRecord) + + // 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)) + } + + } @@ -516,7 +694,8 @@ data class WithdrawItem( val subItemList: List = emptyList(), var startMs: Long = 0L, var hasStarted: Boolean = false, - var isBigWithDraw: Boolean = true + var isBigWithDraw: Boolean = true, + var loopIndex: Int = 1 ) data class WithdrawSubItem(