mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Implement exchange shop
This commit is contained in:
parent
7fcae95ded
commit
b7d4f21e25
4 changed files with 80 additions and 0 deletions
|
@ -235,6 +235,12 @@ async fn shop(req: HttpRequest) -> HttpResponse { router::shop::shop(req) }
|
||||||
#[post("/api/shop/buy")]
|
#[post("/api/shop/buy")]
|
||||||
async fn shop_buy(req: HttpRequest, body: String) -> HttpResponse { router::shop::buy(req, body) }
|
async fn shop_buy(req: HttpRequest, body: String) -> HttpResponse { router::shop::buy(req, body) }
|
||||||
|
|
||||||
|
#[get("/api/exchange")]
|
||||||
|
async fn exchange(req: HttpRequest) -> HttpResponse { router::exchange::exchange(req) }
|
||||||
|
|
||||||
|
#[post("/api/exchange")]
|
||||||
|
async fn exchange_post(req: HttpRequest, body: String) -> HttpResponse { router::exchange::exchange_post(req, body) }
|
||||||
|
|
||||||
|
|
||||||
#[post("/api/webui/login")]
|
#[post("/api/webui/login")]
|
||||||
async fn webui_login(req: HttpRequest, body: String) -> HttpResponse { router::webui::login(req, body) }
|
async fn webui_login(req: HttpRequest, body: String) -> HttpResponse { router::webui::login(req, body) }
|
||||||
|
@ -288,6 +294,8 @@ async fn main() -> std::io::Result<()> {
|
||||||
println!("Request: {}", req.path());
|
println!("Request: {}", req.path());
|
||||||
srv.call(req)
|
srv.call(req)
|
||||||
})
|
})
|
||||||
|
.service(exchange_post)
|
||||||
|
.service(exchange)
|
||||||
.service(serial_code)
|
.service(serial_code)
|
||||||
.service(shop)
|
.service(shop)
|
||||||
.service(shop_buy)
|
.service(shop_buy)
|
||||||
|
|
|
@ -22,3 +22,4 @@ pub mod card;
|
||||||
pub mod shop;
|
pub mod shop;
|
||||||
pub mod webui;
|
pub mod webui;
|
||||||
pub mod clear_rate;
|
pub mod clear_rate;
|
||||||
|
pub mod exchange;
|
||||||
|
|
70
src/router/exchange.rs
Normal file
70
src/router/exchange.rs
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
use crate::encryption;
|
||||||
|
use json::{JsonValue, object};
|
||||||
|
use crate::router::global;
|
||||||
|
use crate::router::userdata;
|
||||||
|
use actix_web::{HttpResponse, HttpRequest};
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref EXCHANGE_LIST: JsonValue = {
|
||||||
|
let mut info = object!{};
|
||||||
|
let items = json::parse(include_str!("json/exchange_item.json")).unwrap();
|
||||||
|
for (_i, data) in items.members().enumerate() {
|
||||||
|
info[data["id"].to_string()] = data.clone();
|
||||||
|
}
|
||||||
|
info
|
||||||
|
};
|
||||||
|
static ref EXCHANGE_REWARD: JsonValue = {
|
||||||
|
let mut info = object!{};
|
||||||
|
let items = json::parse(include_str!("json/exchange_item_reward.json")).unwrap();
|
||||||
|
for (_i, data) in items.members().enumerate() {
|
||||||
|
info[data["id"].to_string()] = data.clone();
|
||||||
|
}
|
||||||
|
info
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn exchange(_req: HttpRequest) -> HttpResponse {
|
||||||
|
let resp = object!{
|
||||||
|
"code": 0,
|
||||||
|
"server_time": global::timestamp(),
|
||||||
|
"data": {"exchange_list":[]}
|
||||||
|
};
|
||||||
|
global::send(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn exchange_post(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), &body);
|
||||||
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
|
let mut user = userdata::get_acc(&key);
|
||||||
|
|
||||||
|
let item = &EXCHANGE_LIST[body["master_exchange_item_id"].to_string()];
|
||||||
|
|
||||||
|
if item["consumeType"].as_i32().unwrap() == 4 {
|
||||||
|
global::use_item(item["value"].as_i64().unwrap(), item["amount"].as_i64().unwrap() * body["count"].as_i64().unwrap(), &mut user);
|
||||||
|
} else {
|
||||||
|
println!("Unknown consume type {}", item["consumeType"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut gift = EXCHANGE_REWARD[item["masterExchangeItemRewardId"].to_string()].clone();
|
||||||
|
gift["reward_type"] = gift["type"].clone();
|
||||||
|
gift["amount"] = (gift["amount"].as_i64().unwrap() * body["count"].as_i64().unwrap()).into();
|
||||||
|
global::give_gift(&gift, &mut user);
|
||||||
|
|
||||||
|
userdata::save_acc(&key, user.clone());
|
||||||
|
|
||||||
|
let resp = object!{
|
||||||
|
"code": 0,
|
||||||
|
"server_time": global::timestamp(),
|
||||||
|
"data": {
|
||||||
|
"exchange": body,
|
||||||
|
"updated_value_list": {
|
||||||
|
"card_list": user["card_list"].clone(),
|
||||||
|
"item_list": user["item_list"].clone(),
|
||||||
|
"point_list": user["point_list"].clone()
|
||||||
|
},
|
||||||
|
"clear_mission_ids": []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
global::send(resp)
|
||||||
|
}
|
|
@ -213,6 +213,7 @@ pub fn lottery_post(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
}
|
}
|
||||||
lottery_list.push(to_push).unwrap();
|
lottery_list.push(to_push).unwrap();
|
||||||
}
|
}
|
||||||
|
global::give_gift_basic(3, 15540034, 10, &mut user);
|
||||||
} else if lottery_type == 2 {
|
} else if lottery_type == 2 {
|
||||||
for (_i, data) in cardstogive.members().enumerate() {
|
for (_i, data) in cardstogive.members().enumerate() {
|
||||||
let info = get_card(data["master_lottery_item_id"].to_string(), data["master_lottery_item_number"].to_string());
|
let info = get_card(data["master_lottery_item_id"].to_string(), data["master_lottery_item_number"].to_string());
|
||||||
|
|
Loading…
Add table
Reference in a new issue