0元购manager

This commit is contained in:
renhaoting 2025-12-25 16:24:33 +08:00
parent 5c03d0cb06
commit 461a24de94
9 changed files with 253 additions and 12 deletions

View File

@ -3,6 +3,7 @@ package com.gamedog.vididin
object VidiConst {
const val NEWBIE_GIFT_GOLD_NUM: Long = 100
/**
@ -28,6 +29,13 @@ object VidiConst {
const val WITHDRAW_MD5KEY = "eonline~#*^%$@!~0702"
/**
* zero buy related values
*/
const val ZERO_GET_PURCHASE_LIST: Int = 0
const val ZERO_JOIN_PURCHASE: Int = 10
const val ZERO_WITHDRAW_OPERATION: Int = 18
const val ZERO_WITHDRAW_RESULT_CHECK: Int = 2

View File

@ -6,6 +6,8 @@ import com.ama.core.architecture.util.AndroidUtil
import com.ama.core.architecture.util.DeviceUtil
import com.ama.core.architecture.util.SpUtil
import com.gamedog.vididin.VidiConst
import com.gamedog.vididin.VidiConst.ZERO_GET_PURCHASE_LIST
import com.gamedog.vididin.VidiConst.ZERO_JOIN_PURCHASE
import com.gamedog.vididin.beans.ZeroBuyItem
import com.gamedog.vididin.beans.ZeroBuyResp
import com.gamedog.vididin.core.login.login.AccountManager
@ -30,7 +32,7 @@ class ZeroBuyViewModel : ViewModel() {
viewModelScope.launch {
_ZeroBuyJoinResult.value = Result.Loading
val operationVal = 10
val operationVal = ZERO_JOIN_PURCHASE
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)
@ -75,7 +77,7 @@ class ZeroBuyViewModel : ViewModel() {
viewModelScope.launch {
_ZeroBuyListData.value = Result.Loading
val operationVal = 0
val operationVal = ZERO_GET_PURCHASE_LIST
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)

View File

@ -5,6 +5,7 @@ import android.app.Activity
import com.ama.core.architecture.util.setOnClickBatch
import com.ama.core.architecture.widget.BindingDialog
import com.gamedog.vididin.beans.ZeroBuyItem
import com.gamedog.vididin.manager.ZeroManager
import com.vididin.real.money.game.databinding.DialogZeroBuyWinBinding as ViewBinding
@ -22,22 +23,35 @@ class ZeroBuyWinDialog(context: Activity, private val item: ZeroBuyItem) : Bindi
setCanCancel(false)
mBinding.run {
setOnClickBatch(ivClose) {
setOnClickBatch(ivClose, rlAction) {
when (this) {
ivClose -> {
dismiss()
}
rlAction -> {
handleWithdraw(item)
dismiss()
}
}
}
tvTitleSub.text = item.title
tvPurchaseId.text = item.price
}
}
}
private fun handleWithdraw(item: ZeroBuyItem) {
ZeroManager.instance().addWinWithdrawItem(item)
if (ZeroManager.instance().couldStartWithdraw(item)) {
ZeroManager.instance().startWithdrawForWinPurchase(item)
}
}
}

View File

@ -51,12 +51,6 @@ class WithdrawManager private constructor() {
companion object {
const val EACH_SUB_ITEM_CASH_NUM: Float = 1F
// subBean 状态
const val ITEM_STATE_CANNOT_START: Int = 0
const val ITEM_STATE_CAN_START: Int = 1
const val ITEM_STATE_STARTED: Int = 2
// subBean 状态
const val STATE_NEED_WATCH_AD: Int = 0
@ -64,7 +58,8 @@ class WithdrawManager private constructor() {
const val STATE_WITHDRAWING: Int = 2
const val STATE_HAS_WITHDRAWED: Int = 3
// 提现交易状态 提现状态 1:提现中,2:提现成功,3:提现失败
// 提现交易状态 提现状态 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

View File

@ -0,0 +1,218 @@
package com.gamedog.vididin.manager
import com.ama.core.architecture.util.AndroidUtil
import com.ama.core.architecture.util.DeviceUtil
import com.ama.core.architecture.util.MD5Util
import com.ama.core.architecture.util.SpUtil
import com.gamedog.vididin.VidiConst
import com.gamedog.vididin.VidiConst.ZEROBUY_SECRET
import com.gamedog.vididin.beans.ZeroBuyItem
import com.gamedog.vididin.beans.ZeroBuyResp
import com.gamedog.vididin.core.login.login.AccountManager
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.manager.WithdrawManager.Companion.TRANSACTION_STATE_UNSTART
import com.gamedog.vididin.netbase.NetworkUtil
import com.gamedog.vididin.netbase.Result
import com.gamedog.vididin.request.RequestUtil
import com.vididin.real.money.game.R
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlin.Int
class ZeroManager private constructor() {
companion object {
@Volatile
private var instance: ZeroManager? = null
fun instance(): ZeroManager {
return instance ?: synchronized(this) {
instance ?: ZeroManager().also {
instance = it
}
}
}
}
private val backgroundScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
private val mWinZeroList: MutableList<WinZeroWithdrawInfoItem> by lazy {
SpUtil.instance().getList<WinZeroWithdrawInfoItem>(SpUtil.KEY_ZEROBUY_WIN_ITEMS).toMutableList()
}
private fun saveWinWithdrawInfos() {
SpUtil.instance().putList(SpUtil.KEY_ZEROBUY_WIN_ITEMS, mWinZeroList)
}
fun getWinItemList() : List<WinZeroWithdrawInfoItem> {
return mWinZeroList
}
fun addOrUpdateWinItem() {
}
/**
* only add new one, if already exist - then do nothing
*/
fun addWinWithdrawItem(zeroItem: ZeroBuyItem) {
val userId = AccountManager.getAccount().userId
zeroItem.winners?.let {
if (it.contains(userId) && zeroItem.completed) {
var alreadyExist = false
mWinZeroList.forEach {
if (it.purchase_id == zeroItem.id) {
alreadyExist = true
return@forEach
}
}
if (!alreadyExist) {
mWinZeroList.add(WinZeroWithdrawInfoItem(zeroItem.id, zeroItem.title, zeroItem.price))
saveWinWithdrawInfos()
}
}
}
}
fun couldStartWithdraw(zeroItem: ZeroBuyItem): Boolean {
val userId = AccountManager.getAccount().userId
zeroItem.winners?.let {
if (it.contains(userId) && zeroItem.completed) {
mWinZeroList.forEach {
if (it.purchase_id == zeroItem.id) {
return it.withdrawState == TRANSACTION_STATE_UNSTART || it.withdrawState == TRANSACTION_STATE_FAIL
}
}
addWinWithdrawItem(zeroItem)
return true
}
}
return false
}
fun startWithdrawForWinPurchase(zeroItem: ZeroBuyItem) {
if (couldStartWithdraw(zeroItem)) {
/*when (it.withdrawState) {
TRANSACTION_STATE_UNSTART -> {
}
TRANSACTION_STATE_ONGOING -> {
}
TRANSACTION_STATE_SUCCESS -> {
}
TRANSACTION_STATE_FAIL -> {
}
}*/
}
}
private fun requestWithdrawZeroReward(zeroWithdrawItem: WinZeroWithdrawInfoItem) {
backgroundScope.launch {
// header
val operationVal = VidiConst.ZERO_WITHDRAW_OPERATION
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(), "DeviceId" to DeviceUtil.generateDeviceId())
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 相关参数:
val bankCPFAccount = AccountManager.getAccount().bankInfo?.bankAccount!!
val accountType = "CPF"
requestParams.put("Account", bankCPFAccount)
requestParams.put("AccountType", accountType)
requestParams.put("Country", Country.BR.name)
requestParams.put("DocumentType", accountType)
requestParams.put("DocumentId", bankCPFAccount)
requestParams.put("BankCode", AccountManager.getAccount().bankInfo?.bankAccount!!)
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)
when (result) {
is Result.Success -> {
val respObj = AndroidUtil.json2Object<ZeroBuyResp>(result.data.string())
respObj?.contentObj?.let {
if (respObj.code == 0 && respObj.Content.isNotEmpty()) {
zeroWithdrawItem.orderId = respObj.Content
zeroWithdrawItem.withdrawState = TRANSACTION_STATE_ONGOING
saveWinWithdrawInfos()
return@launch
} else {
zeroWithdrawItem.withdrawState = TRANSACTION_STATE_FAIL
zeroWithdrawItem.failReason = respObj.code
saveWinWithdrawInfos()
}
}
}
is Result.Error -> {
AndroidUtil.showToast(R.string.net_error)
}
is Result.Loading -> {
}
}
}
}
}
data class WinZeroWithdrawInfoItem(
val purchase_id: Int = 0,
val purchase_title: String? = "",
val winCashNumStr: String? = "",
var operateMs: Long = System.currentTimeMillis(),
var withdrawState: Int = TRANSACTION_STATE_UNSTART,
var failReason: Int = 0,
var hasShowResultDialog: Boolean = false,
var orderId: String = "",
)
enum class Country(val code: Int) {
ANY(0), // 任意国家
BR(1), // 巴西
TR(2), // 土耳其
PK(3) // 巴基斯坦
}
enum class Currency(val code: Int) {
ANY(0), // 任意国家货币
BRL(1), // 巴西雷亚尔
TRY(2), // 土耳其里拉
PKR(3) // 巴基斯坦卢比
}
enum class Language(val code: Int) {
ANY(0), // 任意国家语言
PT(1), // 葡萄牙语(巴西,葡萄牙)
TR(2), // 土耳其语(土耳其)
UR(3) // 乌尔都语(巴基斯坦)
}

View File

@ -110,6 +110,7 @@
/>
<RelativeLayout
android:id="@+id/rl_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="tomorrow_sign">Volte amanhã</string>
<!-- 金币 现金记录相关文案 -->
<string name="record_cash_title_convert_from_gold">Conversão</string>

View File

@ -67,7 +67,8 @@
<string name="title_cash_record">Dinheiro</string>
<string name="sign_success_desc">Você ganhou uma recompensa!</string>
<string name="complement_hint">Recuperar 1 dia de login</string>
<string name="tomorrow_sign">Volte amanhã para fazer login</string>
<string name="tomorrow_sign">Come back tomorrow</string>
<string name="daily_sign_but_text_1">Fazer Login Agora</string>
<string name="daily_sign_but_text_2">Recuperar Login</string>

View File

@ -33,6 +33,7 @@ class SpUtil private constructor(spFileName: String) {
const val KEY_ZEROBUY_JOINED_ACTIVITY_IDS = "KEY_ZEROBUY_JOINED_ACTIVITY_IDS"
const val KEY_ZEROBUY_HAS_NOTIFY_IDS = "KEY_ZEROBUY_HAS_NOTIFY_IDS"
const val KEY_ZEROBUY_WIN_ITEMS = "KEY_ZEROBUY_WIN_ITEMS"
const val KEY_WITHDRAW_HISTORY_LIST = "KEY_WITHDRAW_HISTORY_LIST"