轮询查询 0元购 提现结果
This commit is contained in:
parent
3fa2c5638f
commit
03aae381b2
|
|
@ -385,8 +385,6 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val INIT_ACTIVE = 1
|
const val INIT_ACTIVE = 1
|
||||||
const val FINAL_STATE_ONGING = 1
|
|
||||||
const val CHECK_DURATION = 10*1000L
|
|
||||||
|
|
||||||
internal fun startActivity(activity: Activity) {
|
internal fun startActivity(activity: Activity) {
|
||||||
activity.startActivity(Intent(activity.applicationContext, WithDrawActivity::class.java))
|
activity.startActivity(Intent(activity.applicationContext, WithDrawActivity::class.java))
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import com.gamedog.vididin.beans.req.PayInitReq
|
||||||
import com.gamedog.vididin.beans.req.PayoutCheckReq
|
import com.gamedog.vididin.beans.req.PayoutCheckReq
|
||||||
import com.gamedog.vididin.beans.resp.WithdrawRecord
|
import com.gamedog.vididin.beans.resp.WithdrawRecord
|
||||||
import com.gamedog.vididin.core.login.login.AccountManager
|
import com.gamedog.vididin.core.login.login.AccountManager
|
||||||
import com.gamedog.vididin.features.withdraw.WithDrawActivity.Companion.FINAL_STATE_ONGING
|
|
||||||
import com.gamedog.vididin.manager.WithdrawManager.Companion.STATE_NEED_WATCH_AD
|
import com.gamedog.vididin.manager.WithdrawManager.Companion.STATE_NEED_WATCH_AD
|
||||||
import com.gamedog.vididin.netbase.NetworkUtil
|
import com.gamedog.vididin.netbase.NetworkUtil
|
||||||
import com.gamedog.vididin.netbase.Result
|
import com.gamedog.vididin.netbase.Result
|
||||||
|
|
@ -327,7 +326,7 @@ class WithdrawManager private constructor() {
|
||||||
try {
|
try {
|
||||||
mRecordLocker.lock()
|
mRecordLocker.lock()
|
||||||
mRecordList.forEach { record ->
|
mRecordList.forEach { record ->
|
||||||
if (record.state == FINAL_STATE_ONGING) {
|
if (record.state == TRANSACTION_STATE_ONGOING) {
|
||||||
unCheckCount++
|
unCheckCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -340,7 +339,7 @@ class WithdrawManager private constructor() {
|
||||||
try {
|
try {
|
||||||
mRecordLocker.lock()
|
mRecordLocker.lock()
|
||||||
mRecordList.forEachIndexed { index, record ->
|
mRecordList.forEachIndexed { index, record ->
|
||||||
if (record.state == FINAL_STATE_ONGING) {
|
if (record.state == TRANSACTION_STATE_ONGOING) {
|
||||||
doTransactionCheck(record.recordNo, record.cashNum)
|
doTransactionCheck(record.recordNo, record.cashNum)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package com.gamedog.vididin.manager
|
package com.gamedog.vididin.manager
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import com.ama.core.architecture.util.AndroidUtil
|
import com.ama.core.architecture.util.AndroidUtil
|
||||||
import com.ama.core.architecture.util.DeviceUtil
|
import com.ama.core.architecture.util.DeviceUtil
|
||||||
import com.ama.core.architecture.util.MD5Util
|
import com.ama.core.architecture.util.MD5Util
|
||||||
|
|
@ -26,6 +28,7 @@ import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import okhttp3.internal.http2.Http2Reader
|
||||||
import java.util.concurrent.locks.ReentrantLock
|
import java.util.concurrent.locks.ReentrantLock
|
||||||
import kotlin.Int
|
import kotlin.Int
|
||||||
|
|
||||||
|
|
@ -45,14 +48,25 @@ class ZeroManager private constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private val mBgScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
private val mBgScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||||
private val mWinZeroList: MutableList<WinZeroWithdrawInfoItem> by lazy {
|
private val mRecordList: MutableList<WinZeroWithdrawInfoItem> by lazy {
|
||||||
SpUtil.instance().getList<WinZeroWithdrawInfoItem>(SpUtil.KEY_ZEROBUY_WIN_ITEMS).toMutableList()
|
SpUtil.instance().getList<WinZeroWithdrawInfoItem>(SpUtil.KEY_ZEROBUY_WIN_ITEMS).toMutableList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val mRecordLocker = ReentrantLock()
|
private val mRecordLocker = ReentrantLock()
|
||||||
|
private val mLooperHandler = Handler(Looper.getMainLooper())
|
||||||
|
private val mLoopRunnable = object : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
loopCheckTransactionState()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
loopCheckTransactionState()
|
||||||
|
mLooperHandler.postDelayed(mLoopRunnable, 20 * 1000)
|
||||||
|
}
|
||||||
|
|
||||||
private fun saveWinWithdrawInfos() {
|
private fun saveWinWithdrawInfos() {
|
||||||
SpUtil.instance().putList(SpUtil.KEY_ZEROBUY_WIN_ITEMS, mWinZeroList)
|
SpUtil.instance().putList(SpUtil.KEY_ZEROBUY_WIN_ITEMS, mRecordList)
|
||||||
notifyChangeUpdate()
|
notifyChangeUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,7 +86,7 @@ class ZeroManager private constructor() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mRecordLocker.lock()
|
mRecordLocker.lock()
|
||||||
mWinZeroList.forEach {
|
mRecordList.forEach {
|
||||||
if (it.purchase_id == zeroItem.id) {
|
if (it.purchase_id == zeroItem.id) {
|
||||||
alreadyExist = true
|
alreadyExist = true
|
||||||
return@forEach
|
return@forEach
|
||||||
|
|
@ -80,7 +94,7 @@ class ZeroManager private constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!alreadyExist) {
|
if (!alreadyExist) {
|
||||||
mWinZeroList.add(WinZeroWithdrawInfoItem(zeroItem.id, zeroItem.title, zeroItem.price))
|
mRecordList.add(WinZeroWithdrawInfoItem(zeroItem.id, zeroItem.title, zeroItem.price))
|
||||||
saveWinWithdrawInfos()
|
saveWinWithdrawInfos()
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -93,7 +107,7 @@ class ZeroManager private constructor() {
|
||||||
fun getZeroWithdrawItem(zeroItem: ZeroBuyItem): WinZeroWithdrawInfoItem {
|
fun getZeroWithdrawItem(zeroItem: ZeroBuyItem): WinZeroWithdrawInfoItem {
|
||||||
try {
|
try {
|
||||||
mRecordLocker.lock()
|
mRecordLocker.lock()
|
||||||
return mWinZeroList.filter { zeroItem.id == it.purchase_id }[0]
|
return mRecordList.filter { zeroItem.id == it.purchase_id }[0]
|
||||||
} finally {
|
} finally {
|
||||||
mRecordLocker.unlock()
|
mRecordLocker.unlock()
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +119,7 @@ class ZeroManager private constructor() {
|
||||||
if (it.contains(userId) && zeroItem.completed) {
|
if (it.contains(userId) && zeroItem.completed) {
|
||||||
try {
|
try {
|
||||||
mRecordLocker.lock()
|
mRecordLocker.lock()
|
||||||
mWinZeroList.forEach {
|
mRecordList.forEach {
|
||||||
if (it.purchase_id == zeroItem.id) {
|
if (it.purchase_id == zeroItem.id) {
|
||||||
return it.withdrawState == TRANSACTION_STATE_UNSTART || it.withdrawState == TRANSACTION_STATE_FAIL
|
return it.withdrawState == TRANSACTION_STATE_UNSTART || it.withdrawState == TRANSACTION_STATE_FAIL
|
||||||
}
|
}
|
||||||
|
|
@ -123,7 +137,7 @@ class ZeroManager private constructor() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun requestWithdrawZeroReward(zeroWithdrawItem: WinZeroWithdrawInfoItem) {
|
private fun requestZeroWithdrawReward(zeroWithdrawItem: WinZeroWithdrawInfoItem) {
|
||||||
mBgScope.launch {
|
mBgScope.launch {
|
||||||
// header
|
// header
|
||||||
val operationVal = VidiConst.ZERO_WITHDRAW_OPERATION
|
val operationVal = VidiConst.ZERO_WITHDRAW_OPERATION
|
||||||
|
|
@ -153,6 +167,62 @@ class ZeroManager private constructor() {
|
||||||
requestParams.put("Sign", MD5Util.md5(signOriginStr)!!)
|
requestParams.put("Sign", MD5Util.md5(signOriginStr)!!)
|
||||||
|
|
||||||
|
|
||||||
|
val result = NetworkUtil.post("${VidiConst.URL_ZERO_BUY}/any", requestHeaders, requestParams, joinZeroBuyItemIds)
|
||||||
|
when (result) {
|
||||||
|
is Result.Success -> {
|
||||||
|
val respObj = AndroidUtil.json2Object<ZeroBuyWithdrawResp>(result.data.string())
|
||||||
|
|
||||||
|
respObj?.let {
|
||||||
|
if (it.code == 0 && it.content.isNotEmpty()) {
|
||||||
|
zeroWithdrawItem.orderId = respObj.content
|
||||||
|
zeroWithdrawItem.withdrawState = TRANSACTION_STATE_ONGOING
|
||||||
|
saveWinWithdrawInfos()
|
||||||
|
loopCheckTransactionState()
|
||||||
|
AndroidUtil.showToast(R.string.zero_withdraw_ongoing)
|
||||||
|
return@launch
|
||||||
|
} else {
|
||||||
|
zeroWithdrawItem.withdrawState = TRANSACTION_STATE_FAIL
|
||||||
|
zeroWithdrawItem.failReason = respObj.code
|
||||||
|
saveWinWithdrawInfos()
|
||||||
|
AndroidUtil.showToast(R.string.zero_withdraw_failed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is Result.Error -> {
|
||||||
|
AndroidUtil.showToast(R.string.net_error)
|
||||||
|
}
|
||||||
|
is Result.Loading -> {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun requestZeroWithdrawResult(zeroWithdrawItem: WinZeroWithdrawInfoItem) {
|
||||||
|
mBgScope.launch {
|
||||||
|
// header
|
||||||
|
val operationVal = VidiConst.ZERO_WITHDRAW_RESULT_CHECK
|
||||||
|
val curTimeSec = System.currentTimeMillis()/1000
|
||||||
|
val signStr = RequestUtil.getZeroBuyRequestSign(curTimeSec, operationVal)
|
||||||
|
val requestHeaders = mapOf("Operation" to operationVal.toString(), "Timestamp" to curTimeSec.toString(), "Sign" to signStr)
|
||||||
|
|
||||||
|
// body param
|
||||||
|
val requestParams: MutableMap<String, String> = mutableMapOf("AppId" to AndroidUtil.getPackageId())
|
||||||
|
val userId = AccountManager.getAccount().userId
|
||||||
|
if (userId > 0) {
|
||||||
|
requestParams.put("UserId", userId.toString())
|
||||||
|
}
|
||||||
|
val joinZeroBuyItemIds = SpUtil.instance().getList<Int>(SpUtil.KEY_ZEROBUY_JOINED_ACTIVITY_IDS)
|
||||||
|
requestParams.put("ActivityId", zeroWithdrawItem.purchase_id.toString())
|
||||||
|
|
||||||
|
// withdraw check result 相关参数:
|
||||||
|
requestParams.put("device_id", zeroWithdrawItem.orderId)
|
||||||
|
requestParams.put("order_id", zeroWithdrawItem.orderId)
|
||||||
|
/*val signOriginStr = "${zeroWithdrawItem.purchase_id}-${userId}-${bankCPFAccount}-${accountType}-${bankCPFAccount}-${accountType}-${ZEROBUY_SECRET}"
|
||||||
|
requestParams.put("Sign", MD5Util.md5(signOriginStr)!!)*/
|
||||||
|
|
||||||
|
|
||||||
val result = NetworkUtil.post("${VidiConst.URL_ZERO_BUY}/any", requestHeaders, requestParams, joinZeroBuyItemIds)
|
val result = NetworkUtil.post("${VidiConst.URL_ZERO_BUY}/any", requestHeaders, requestParams, joinZeroBuyItemIds)
|
||||||
when (result) {
|
when (result) {
|
||||||
is Result.Success -> {
|
is Result.Success -> {
|
||||||
|
|
@ -189,7 +259,7 @@ class ZeroManager private constructor() {
|
||||||
|
|
||||||
if (couldStartWithdraw(item)) {
|
if (couldStartWithdraw(item)) {
|
||||||
val onConfirmed: (cashNum: Float)->Unit = {
|
val onConfirmed: (cashNum: Float)->Unit = {
|
||||||
requestWithdrawZeroReward(zeroWithdrawInfoItem)
|
requestZeroWithdrawReward(zeroWithdrawInfoItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AccountManager.isBankAccountExist()) {
|
if (AccountManager.isBankAccountExist()) {
|
||||||
|
|
@ -211,6 +281,39 @@ class ZeroManager private constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private fun loopCheckTransactionState() {
|
||||||
|
var unCheckCount = 0
|
||||||
|
try {
|
||||||
|
mRecordLocker.lock()
|
||||||
|
mRecordList.forEach { record ->
|
||||||
|
if (record.withdrawState == TRANSACTION_STATE_ONGOING) {
|
||||||
|
unCheckCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
mRecordLocker.unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (unCheckCount > 0) {
|
||||||
|
try {
|
||||||
|
mRecordLocker.lock()
|
||||||
|
mRecordList.forEachIndexed { index, record ->
|
||||||
|
if (record.withdrawState == TRANSACTION_STATE_ONGOING) {
|
||||||
|
requestZeroWithdrawResult(record)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
mRecordLocker.unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mLooperHandler.postDelayed(mLoopRunnable, 20 * 1000)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -216,4 +216,5 @@
|
||||||
<string name="zero_withdraw_ongoing">The withdraw request has submitted successfully</string>
|
<string name="zero_withdraw_ongoing">The withdraw request has submitted successfully</string>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Reference in New Issue