|
@@ -59,6 +59,19 @@ fn get_cached_steam_card_ratio(selection_request_id: i64) -> f64 {
|
|
|
.unwrap_or(7.5) // 默认卡价比例 7.5
|
|
.unwrap_or(7.5) // 默认卡价比例 7.5
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// 根据账号名获取对应的卡价比例
|
|
|
|
|
+/// 优先使用账号自己的充值卡价比例,如果没有则使用全局配置的卡价比例
|
|
|
|
|
+fn get_account_card_rate(account_name: &str, account_card_rate_map: &std::collections::HashMap<String, f64>, selection_request_id: i64) -> f64 {
|
|
|
|
|
+ // 优先使用账号自己的卡价比例
|
|
|
|
|
+ if let Some(&rate) = account_card_rate_map.get(account_name) {
|
|
|
|
|
+ if rate > 0.0 {
|
|
|
|
|
+ return rate;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 兜底使用全局配置的卡价比例
|
|
|
|
|
+ get_cached_steam_card_ratio(selection_request_id)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/// 存储选品配置到缓存
|
|
/// 存储选品配置到缓存
|
|
|
fn store_selection_config_cache(selection_request_id: i64, steam_card_ratio: f64) {
|
|
fn store_selection_config_cache(selection_request_id: i64, steam_card_ratio: f64) {
|
|
|
let mut cache = SELECTION_CONFIG_CACHE.lock().unwrap();
|
|
let mut cache = SELECTION_CONFIG_CACHE.lock().unwrap();
|
|
@@ -2345,6 +2358,9 @@ struct SweepShared {
|
|
|
selected_accounts: Vec<String>,
|
|
selected_accounts: Vec<String>,
|
|
|
/// selected_accounts 的长度(用于计算)
|
|
/// selected_accounts 的长度(用于计算)
|
|
|
selected_accounts_len: usize,
|
|
selected_accounts_len: usize,
|
|
|
|
|
+ /// 账号充值卡价比例映射(key: 账号名, value: 卡价比例)
|
|
|
|
|
+ /// 如果账号没有单独的比例,使用全局默认比例
|
|
|
|
|
+ account_card_rate_map: std::collections::HashMap<String, f64>,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fn sweep_proxy_slot(s: Option<&SweepShared>) -> Option<&Arc<Mutex<Option<String>>>> {
|
|
fn sweep_proxy_slot(s: Option<&SweepShared>) -> Option<&Arc<Mutex<Option<String>>>> {
|
|
@@ -2966,9 +2982,9 @@ async fn purchase_ready_with_account_rotation(
|
|
|
.and_then(|v| v.as_str())
|
|
.and_then(|v| v.as_str())
|
|
|
.map(|s| s.to_string());
|
|
.map(|s| s.to_string());
|
|
|
|
|
|
|
|
- // 计算成交价格人民币
|
|
|
|
|
|
|
+ // 计算成交价格人民币(优先使用账号自己的充值卡价比例)
|
|
|
let purchase_price_cny = purchase_price.map(|price_usd| {
|
|
let purchase_price_cny = purchase_price.map(|price_usd| {
|
|
|
- let ratio = get_cached_steam_card_ratio(shared.selection_request_id);
|
|
|
|
|
|
|
+ let ratio = get_account_card_rate(&used_account, &shared.account_card_rate_map, shared.selection_request_id);
|
|
|
price_usd * ratio
|
|
price_usd * ratio
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -3130,9 +3146,9 @@ async fn purchase_ready(shared: Arc<SweepShared>, ready: PurchaseReady) {
|
|
|
.and_then(|v| v.as_str())
|
|
.and_then(|v| v.as_str())
|
|
|
.map(|s| s.to_string());
|
|
.map(|s| s.to_string());
|
|
|
|
|
|
|
|
- // 计算成交价格人民币
|
|
|
|
|
|
|
+ // 计算成交价格人民币(优先使用账号自己的充值卡价比例)
|
|
|
let purchase_price_cny = purchase_price.map(|price_usd| {
|
|
let purchase_price_cny = purchase_price.map(|price_usd| {
|
|
|
- let ratio = get_cached_steam_card_ratio(shared.selection_request_id);
|
|
|
|
|
|
|
+ let ratio = get_account_card_rate(&used_account, &shared.account_card_rate_map, shared.selection_request_id);
|
|
|
price_usd * ratio
|
|
price_usd * ratio
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -3276,6 +3292,7 @@ async fn run_sweep_inner(
|
|
|
selection_request_id: i64,
|
|
selection_request_id: i64,
|
|
|
sweep_worker_count: u32,
|
|
sweep_worker_count: u32,
|
|
|
selected_accounts: Vec<String>,
|
|
selected_accounts: Vec<String>,
|
|
|
|
|
+ account_card_rate_map: std::collections::HashMap<String, f64>,
|
|
|
) {
|
|
) {
|
|
|
app_log::info(&format!(
|
|
app_log::info(&format!(
|
|
|
"[RUN-SWEEP-INNER] 扫货任务线程启动: sweep_request_id={}, selection_request_id={}, worker_count={}, selected_accounts={:?}",
|
|
"[RUN-SWEEP-INNER] 扫货任务线程启动: sweep_request_id={}, selection_request_id={}, worker_count={}, selected_accounts={:?}",
|
|
@@ -3654,6 +3671,7 @@ async fn run_sweep_inner(
|
|
|
purchase_failed_total: Arc::clone(&purchase_failed_total),
|
|
purchase_failed_total: Arc::clone(&purchase_failed_total),
|
|
|
selected_accounts: selected_accounts_vec.clone(),
|
|
selected_accounts: selected_accounts_vec.clone(),
|
|
|
selected_accounts_len,
|
|
selected_accounts_len,
|
|
|
|
|
+ account_card_rate_map: account_card_rate_map.clone(),
|
|
|
})
|
|
})
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -3686,6 +3704,7 @@ async fn run_sweep_inner(
|
|
|
purchase_failed_total: Arc::clone(&purchase_failed_total),
|
|
purchase_failed_total: Arc::clone(&purchase_failed_total),
|
|
|
selected_accounts: selected_accounts_vec.clone(),
|
|
selected_accounts: selected_accounts_vec.clone(),
|
|
|
selected_accounts_len,
|
|
selected_accounts_len,
|
|
|
|
|
+ account_card_rate_map: account_card_rate_map.clone(),
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
let init_line = json!({
|
|
let init_line = json!({
|
|
@@ -3894,6 +3913,7 @@ pub async fn spawn_runner(
|
|
|
selection_request_id: i64,
|
|
selection_request_id: i64,
|
|
|
sweep_worker_count: u32,
|
|
sweep_worker_count: u32,
|
|
|
selected_accounts: Vec<String>,
|
|
selected_accounts: Vec<String>,
|
|
|
|
|
+ account_card_rate_map: std::collections::HashMap<String, f64>,
|
|
|
) -> Result<(), String> {
|
|
) -> Result<(), String> {
|
|
|
// 任务启动时记录完整资源状态
|
|
// 任务启动时记录完整资源状态
|
|
|
app_log::log_resource_diagnostics("spawn-start");
|
|
app_log::log_resource_diagnostics("spawn-start");
|
|
@@ -3924,6 +3944,7 @@ pub async fn spawn_runner(
|
|
|
let mid = machine_code.clone();
|
|
let mid = machine_code.clone();
|
|
|
let wc = sweep_worker_count.max(1);
|
|
let wc = sweep_worker_count.max(1);
|
|
|
let sel_accs = selected_accounts.clone();
|
|
let sel_accs = selected_accounts.clone();
|
|
|
|
|
+ let acc_card_rates = account_card_rate_map.clone();
|
|
|
|
|
|
|
|
app_log::log_sweep_start(sweep_request_id, selection_request_id, wc);
|
|
app_log::log_sweep_start(sweep_request_id, selection_request_id, wc);
|
|
|
|
|
|
|
@@ -3939,7 +3960,7 @@ pub async fn spawn_runner(
|
|
|
app_log::log_resource_diagnostics("tokio-task-start");
|
|
app_log::log_resource_diagnostics("tokio-task-start");
|
|
|
|
|
|
|
|
// 直接调用(async 函数中的 panic 会被 tokio 捕获并记录)
|
|
// 直接调用(async 函数中的 panic 会被 tokio 捕获并记录)
|
|
|
- run_sweep_inner(sid, mid, sweep_request_id, selection_request_id, wc, sel_accs).await;
|
|
|
|
|
|
|
+ run_sweep_inner(sid, mid, sweep_request_id, selection_request_id, wc, sel_accs, acc_card_rates).await;
|
|
|
|
|
|
|
|
app_log::info(&format!("[SPAWN-RUNNER] run_sweep_inner 执行完毕(正常返回)"));
|
|
app_log::info(&format!("[SPAWN-RUNNER] run_sweep_inner 执行完毕(正常返回)"));
|
|
|
app_log::log_sweep_end(sweep_request_id, "completed");
|
|
app_log::log_sweep_end(sweep_request_id, "completed");
|