diff --git a/rust-src/api/src/controller/live_prize_pool_item_controller.rs b/rust-src/api/src/controller/live_prize_pool_item_controller.rs index 2100d2a..328a5fe 100644 --- a/rust-src/api/src/controller/live_prize_pool_item_controller.rs +++ b/rust-src/api/src/controller/live_prize_pool_item_controller.rs @@ -4,7 +4,7 @@ use common::error::MyError; use common::r::JsonResult; use common::state::AppState; use entity::live_prize_pool_item; -use model::prize::LivePrizePoolItemPage; +use model::prize::{ImportPoolItemCdk, LivePrizePoolItemPage}; use service::live_prize_pool_item_service; #[get("/api/live_prize_pool_item/list")] @@ -49,3 +49,17 @@ async fn delete(app_state: web::Data, Ok(HttpResponse::Ok().json(JsonResult::ok(res))) } +#[post("/api/live_prize_pool_item/import_cdk")] +async fn import_cdk(app_state: web::Data, + params: web::Json, ) -> Result { + let res = live_prize_pool_item_service::import_cdk(&app_state.db, params.into_inner()).await?; + Ok(HttpResponse::Ok().json(JsonResult::ok(res))) +} + +#[get("/api/live_prize_pool_item/clean_cdk/{live_id}/{item_id}")] +async fn clean_cdk(app_state: web::Data, + params: web::Path<(i64, i64)>, ) -> Result { + let param = params.into_inner(); + let res = live_prize_pool_item_service::clean_cdk(&app_state.db, param.0,param.1).await?; + Ok(HttpResponse::Ok().json(JsonResult::ok(res))) +} \ No newline at end of file diff --git a/rust-src/api/src/routes.rs b/rust-src/api/src/routes.rs index 1c647db..0fc9fa4 100644 --- a/rust-src/api/src/routes.rs +++ b/rust-src/api/src/routes.rs @@ -47,7 +47,9 @@ pub fn live_prize_pool_item_routes(cfg: &mut web::ServiceConfig) { .service(live_prize_pool_item_controller::info) .service(live_prize_pool_item_controller::page) .service(live_prize_pool_item_controller::delete) - .service(live_prize_pool_item_controller::add); + .service(live_prize_pool_item_controller::add) + .service(live_prize_pool_item_controller::import_cdk) + .service(live_prize_pool_item_controller::clean_cdk); } pub fn live_prize_pool_routes(cfg: &mut web::ServiceConfig) { diff --git a/rust-src/entity/src/live_prize_history.rs b/rust-src/entity/src/live_prize_history.rs index 06a8af3..b67fc7f 100644 --- a/rust-src/entity/src/live_prize_history.rs +++ b/rust-src/entity/src/live_prize_history.rs @@ -31,7 +31,7 @@ pub struct TopDraw { pub user_name: Option, } -#[derive(FromQueryResult,Serialize, Deserialize)] +#[derive(Clone, FromQueryResult,Serialize, Deserialize)] pub struct DrawHistory { pub action: Option, pub user_id: Option, diff --git a/rust-src/entity/src/live_prize_pool_item.rs b/rust-src/entity/src/live_prize_pool_item.rs index 3c5b5bc..91eb44a 100644 --- a/rust-src/entity/src/live_prize_pool_item.rs +++ b/rust-src/entity/src/live_prize_pool_item.rs @@ -17,6 +17,7 @@ pub struct Model { pub level_name: Option, pub probability: Option, pub remaining_quantity: Option, + pub cdk_quantity: Option, pub status: Option, pub guarantees: Option, pub create_time: Option, @@ -40,4 +41,18 @@ pub struct PoolItemList { pub level_name: Option, pub icon: Option, pub remaining_quantity: Option, +} + +#[derive(Clone,FromQueryResult,Serialize, Deserialize)] +pub struct DrawPoolItemList { + pub id: i64, + pub live_id: Option, + pub prize_id: Option, + pub prize_name: Option, + pub level: Option, + pub level_name: Option, + pub icon: Option, + pub remaining_quantity: Option, + pub cdk_id: Option, + pub cdk: Option, } \ No newline at end of file diff --git a/rust-src/entity/src/live_prize_pool_item_cdk.rs b/rust-src/entity/src/live_prize_pool_item_cdk.rs new file mode 100644 index 0000000..6b997c8 --- /dev/null +++ b/rust-src/entity/src/live_prize_pool_item_cdk.rs @@ -0,0 +1,22 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.15 + +use sea_orm::entity::prelude::*; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[sea_orm(table_name = "live_prize_pool_item_cdk")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i64, + pub live_id: Option, + pub prize_id: Option, + pub cdk: Option, + pub status: Option, + pub create_time: Option, + pub update_time: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/rust-src/entity/src/mod.rs b/rust-src/entity/src/mod.rs index b92fe15..7b1b016 100644 --- a/rust-src/entity/src/mod.rs +++ b/rust-src/entity/src/mod.rs @@ -13,4 +13,5 @@ pub mod live_prize_pool; pub mod live_prize_pool_item; pub mod live_prize_history; pub mod cdk; -pub mod live_prize_pool_user; \ No newline at end of file +pub mod live_prize_pool_user; +pub mod live_prize_pool_item_cdk; \ No newline at end of file diff --git a/rust-src/entity/src/prelude.rs b/rust-src/entity/src/prelude.rs index 56cb152..f5a2dab 100644 --- a/rust-src/entity/src/prelude.rs +++ b/rust-src/entity/src/prelude.rs @@ -12,4 +12,4 @@ pub use super::role::Entity as Role; pub use super::role_resource::Entity as RoleResource; pub use super::user::Entity as User; pub use super::user_role::Entity as UserRole; - +pub use super::live_prize_pool_item_cdk::Entity as LivePrizePoolItemCdk; diff --git a/rust-src/migration/src/lib.rs b/rust-src/migration/src/lib.rs index 39a602e..d30bfb7 100644 --- a/rust-src/migration/src/lib.rs +++ b/rust-src/migration/src/lib.rs @@ -19,7 +19,7 @@ mod m20240722_000001_create_table; mod m20240805_000001_create_table; mod m20241015_000001_create_table; mod m20241015_000002_create_table; - +mod m20241019_000001_create_table; pub struct Migrator; @@ -45,6 +45,7 @@ impl MigratorTrait for Migrator { Box::new(m20240805_000001_create_table::Migration), Box::new(m20241015_000001_create_table::Migration), Box::new(m20241015_000002_create_table::Migration), + Box::new(m20241019_000001_create_table::Migration), ] } } diff --git a/rust-src/migration/src/m20241019_000001_create_table.rs b/rust-src/migration/src/m20241019_000001_create_table.rs new file mode 100644 index 0000000..bcf1bc4 --- /dev/null +++ b/rust-src/migration/src/m20241019_000001_create_table.rs @@ -0,0 +1,61 @@ +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .create_table( + Table::create() + .table(LivePrizePoolItemCdk::Table) + .if_not_exists() + .comment("活动奖池奖品CDK信息") + .col( + ColumnDef::new(LivePrizePoolItemCdk::Id) + .big_integer() + .not_null() + .auto_increment() + .primary_key(), + ) + .col(ColumnDef::new(LivePrizePoolItemCdk::LiveId).big_integer().comment("活动奖池ID")) + .col(ColumnDef::new(LivePrizePoolItemCdk::PrizeId).big_integer().comment("奖品ID")) + .col(ColumnDef::new(LivePrizePoolItemCdk::Cdk).string().char_len(64).comment("CDK")) + .col(ColumnDef::new(LivePrizePoolItemCdk::Status).boolean().default(1).comment("状态")) + .col(ColumnDef::new(LivePrizePoolItemCdk::CreateTime).date_time().comment("创建时间")) + .col(ColumnDef::new(LivePrizePoolItemCdk::UpdateTime).date_time().comment("更新时间")) + .to_owned(), + ) + .await?; + manager.alter_table( + Table::alter() + .table(LivePrizePoolItem::Table) + .add_column(ColumnDef::new(LivePrizePoolItem::CdkQuantity).big_integer().default(0).comment("CDK数量")) + .to_owned() + ).await?; + Ok(()) + } + + async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> { + Ok(()) + } +} + +#[derive(DeriveIden)] +enum LivePrizePoolItemCdk { + Table, + Id, + LiveId, + PrizeId, + Cdk, + Status, + CreateTime, + UpdateTime, +} + +#[derive(DeriveIden)] +enum LivePrizePoolItem { + Table, + CdkQuantity, +} diff --git a/rust-src/model/src/prize.rs b/rust-src/model/src/prize.rs index 0d006b4..9107bff 100644 --- a/rust-src/model/src/prize.rs +++ b/rust-src/model/src/prize.rs @@ -91,3 +91,10 @@ pub struct UserDrawHistoryPage { pub live_id: Option, pub create_time: Option>, } + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct ImportPoolItemCdk { + pub live_id: i64, + pub prize_id: i64, + pub cdk: Vec, +} diff --git a/rust-src/security/src/wtt.rs b/rust-src/security/src/wtt.rs index ad03af2..15c0deb 100644 --- a/rust-src/security/src/wtt.rs +++ b/rust-src/security/src/wtt.rs @@ -115,7 +115,7 @@ fn has_permission(req: &ServiceRequest) -> Result { } else { let empty_method_conf = &auth_conf.empty_method; //如果没有根据请求方法鉴权的规则就遍历所有规则 - for api_auth_path_conf_model in empty_method_conf { + while let Some(api_auth_path_conf_model) = empty_method_conf { //路径匹配 let api_path_check_res = api_path_check(request_path, Some(api_auth_path_conf_model), token_auth_cache)?; //表达式匹配 diff --git a/rust-src/service/src/live_prize_pool_item_service.rs b/rust-src/service/src/live_prize_pool_item_service.rs index 710f272..1ca73b0 100644 --- a/rust-src/service/src/live_prize_pool_item_service.rs +++ b/rust-src/service/src/live_prize_pool_item_service.rs @@ -3,9 +3,9 @@ use sea_orm::DbConn; use common::error::MyError; use common::page::PageResult; use entity::live_prize_pool_item; -use model::prize::LivePrizePoolItemPage; +use model::prize::{ImportPoolItemCdk, LivePrizePoolItemPage}; -use crate::manager::live_prize_pool_item_manager; +use crate::manager::{live_prize_pool_item_cdk_manager, live_prize_pool_item_manager}; pub async fn list(db: &DbConn) -> Result, MyError> { Ok(live_prize_pool_item_manager::get_prize_pool_item_list(db).await?) @@ -32,3 +32,15 @@ pub async fn add(db: &DbConn, live_id: i64, item_id: i64) -> Result Result { Ok(live_prize_pool_item_manager::delete(db, id).await?) } + +pub async fn clean_cdk(db: &DbConn, live_id: i64, prize_id: i64) -> Result { + live_prize_pool_item_cdk_manager::clean_cdk(db, live_id,prize_id).await?; + live_prize_pool_item_manager::update_cdk_quantity(db, live_id, prize_id, 0).await?; + Ok(true) +} + +pub async fn import_cdk(db: &DbConn, form: ImportPoolItemCdk) -> Result { + let res= live_prize_pool_item_cdk_manager::import_cdk(db, form.clone()).await?; + live_prize_pool_item_manager::update_cdk_quantity(db, form.live_id, form.prize_id, res).await?; + Ok(res) +} \ No newline at end of file diff --git a/rust-src/service/src/live_prize_pool_service.rs b/rust-src/service/src/live_prize_pool_service.rs index b43b3f7..5fa7694 100644 --- a/rust-src/service/src/live_prize_pool_service.rs +++ b/rust-src/service/src/live_prize_pool_service.rs @@ -12,7 +12,7 @@ use entity::{live_prize_history, live_prize_pool, live_prize_pool_item, live_pri use model::prize::{LivePrizePoolPage, PoolDrawCount}; use security::state::AuthState; -use crate::manager::{live_prize_history_manager, live_prize_pool_item_manager, live_prize_pool_manager, live_prize_pool_user_manager}; +use crate::manager::{live_prize_history_manager, live_prize_pool_item_cdk_manager, live_prize_pool_item_manager, live_prize_pool_manager, live_prize_pool_user_manager}; pub async fn list(db: &DbConn) -> Result, MyError> { Ok(live_prize_pool_manager::get_live_prize_pool_list(db).await?) @@ -36,7 +36,7 @@ pub async fn page(db: &DbConn, page: LivePrizePoolPage) -> Result Result, MyError> { +pub async fn draw(db: &DbConn, live_id: i64, draw_num: i32, token: &str, req: HttpRequest) -> Result, MyError> { let auth_state = req.app_data::>>().ok_or(MyError::ServerError("get auth_state fail".to_string()))?; let auth_state = auth_state.lock().unwrap(); let uid = auth_state.token_auth_cache.get(token).ok_or(MyError::UnauthorizedError("no auth cache".to_string()))?.uid; @@ -145,10 +145,14 @@ pub async fn draw(db: &DbConn, live_id: i64, draw_num: i32, token: &str, req: Ht } live_prize_pool_item_manager::update_remaining_quantity(db, item_map).await?; + + //抽奖结果 let mut result = Vec::new(); for item in &draw_item { - result.push(live_prize_pool_item::PoolItemList { + //消费cdk + let cdk = live_prize_pool_item_cdk_manager::consumer_cdk(db,live_id,item.prize_id).await?; + result.push(live_prize_pool_item::DrawPoolItemList { id: item.id.clone(), live_id: None, prize_id: item.prize_id, @@ -157,6 +161,22 @@ pub async fn draw(db: &DbConn, live_id: i64, draw_num: i32, token: &str, req: Ht level_name: item.level_name.clone(), icon: item.icon.clone(), remaining_quantity: None, + cdk_id: match cdk.clone() { + None => { + None + } + Some(c) => { + Option::from(c.id) + } + }, + cdk: match cdk.clone() { + None => { + None + } + Some(c) => { + Option::from(c.cdk) + } + }, }); } diff --git a/rust-src/service/src/manager/live_prize_history_manager.rs b/rust-src/service/src/manager/live_prize_history_manager.rs index 31a7312..2b0e90e 100644 --- a/rust-src/service/src/manager/live_prize_history_manager.rs +++ b/rust-src/service/src/manager/live_prize_history_manager.rs @@ -1,16 +1,17 @@ +use std::hash::Hash; use std::str::FromStr; use chrono::Local; -use sea_orm::{ActiveModelTrait, ColumnTrait, DbConn, EntityTrait, JoinType, NotSet, Order, PaginatorTrait, QueryFilter, QueryOrder, QuerySelect}; -use sea_orm::ActiveValue::Set; - use common::error::MyError; use common::page::PageResult; -use entity::{live_prize_history, live_prize_pool_item, user}; use entity::prelude::LivePrizeHistory; +use entity::{live_prize_history, live_prize_pool_item, user}; use model::prize::UserDrawHistoryPage; +use sea_orm::ActiveValue::Set; +use sea_orm::{ActiveModelTrait, ColumnTrait, DbConn, EntityTrait, JoinType, NotSet, Order, PaginatorTrait, QueryFilter, QueryOrder, QuerySelect}; +use serde_json::Value; -pub async fn create_live_prize_history_data(db: &DbConn, live_id:i64, pool_id:i64, user_id:i64, action :i64, items: Vec) -> Result { +pub async fn create_live_prize_history_data(db: &DbConn, live_id: i64, pool_id: i64, user_id: i64, action: i64, items: Vec) -> Result { let model = live_prize_history::ActiveModel { id: NotSet, live_id: Set(Some(live_id)), @@ -31,46 +32,73 @@ pub async fn top_draw(db: &DbConn) -> Result, M user::Entity::belongs_to(live_prize_history::Entity) .from(user::Column::Id) .to(live_prize_history::Column::UserId) - .into() + .into(), ) - .column_as(live_prize_history::Column::Action.sum(),"action") + .column_as(live_prize_history::Column::Action.sum(), "action") .column(live_prize_history::Column::UserId) .column(user::Column::UserName) .group_by(live_prize_history::Column::UserId) - .order_by(live_prize_history::Column::Action,Order::Desc) + .order_by(live_prize_history::Column::Action, Order::Desc) .into_model::() .all(db).await?; Ok(a) } pub async fn draw_history(db: &DbConn) -> Result, MyError> { - let a = LivePrizeHistory::find() + let list = LivePrizeHistory::find() .join_rev( JoinType::LeftJoin, user::Entity::belongs_to(live_prize_history::Entity) .from(user::Column::Id) .to(live_prize_history::Column::UserId) - .into() + .into(), ) .column(live_prize_history::Column::Action) .column(live_prize_history::Column::UserId) .column(live_prize_history::Column::PrizeIds) .column(live_prize_history::Column::PrizeItems) .column(user::Column::UserName) - .order_by(live_prize_history::Column::CreateTime,Order::Desc) + .order_by(live_prize_history::Column::CreateTime, Order::Desc) .into_model::() .paginate(db, 50).fetch_page(0).await?; - Ok(a) + let mut result = Vec::new(); + for history in list { + let prize_items = history.prize_items.clone(); + match prize_items { + None => {} + Some(prize_items) => { + let mut json_value = serde_json::from_str::(prize_items.as_str()).unwrap(); + if let Value::Array(ref mut array) = json_value { + let mut items = Vec::new(); + // 检查是否是一个对象并获取可变的 Map 引用 + for a in array { + if let Value::Object(ref mut map) = a { + // 修改字段值 + if map.contains_key("cdk") { + map["cdk"] = Value::String("".to_string()); + } + items.push(map); + } + } + let mut new_history = history.clone(); + new_history.prize_items = Some(serde_json::to_string(&items).unwrap()); + result.push(new_history); + } + + } + } + } + Ok(result) } -pub async fn pool_draw_cation_count(db: &DbConn, live_id: i64) -> Result { +pub async fn pool_draw_cation_count(db: &DbConn, live_id: i64) -> Result { let res = LivePrizeHistory::find() - .column_as(live_prize_history::Column::Action.sum(),"action") + .column_as(live_prize_history::Column::Action.sum(), "action") .filter(live_prize_history::Column::LiveId.eq(live_id)) .group_by(live_prize_history::Column::LiveId) .all(db).await?; if res.is_empty() { Ok(0) - }else { + } else { match res.get(0) { None => { Ok(0) @@ -82,7 +110,7 @@ pub async fn pool_draw_cation_count(db: &DbConn, live_id: i64) -> Result Result, MyError> { +pub async fn user_draw_history_page(db: &DbConn, page: UserDrawHistoryPage, uid: i64) -> Result, MyError> { let mut page_data = page.page_data; //校验分页数据是否合法 page_data = page_data.check(); @@ -98,16 +126,16 @@ pub async fn user_draw_history_page(db: &DbConn, page: UserDrawHistoryPage, uid: let create_time = page.create_time; if create_time.is_some() { let create_time = create_time.unwrap(); - find = find.filter(live_prize_history::Column::CreateTime.between(create_time[0].clone(),create_time[1].clone())) + find = find.filter(live_prize_history::Column::CreateTime.between(create_time[0].clone(), create_time[1].clone())) } let sorter = page_data.sorter; if sorter.is_some() { let sorter = sorter.unwrap(); let field = live_prize_history::Column::from_str(sorter.field.as_str()).or_else(|e| { - Err(MyError::DBError(format!("获取排序字段失败:{}",e.to_string()))) + Err(MyError::DBError(format!("获取排序字段失败:{}", e.to_string()))) })?; - find = find.order_by(field,sorter.order()); + find = find.order_by(field, sorter.order()); } let paginator = find diff --git a/rust-src/service/src/manager/live_prize_pool_item_cdk_manager.rs b/rust-src/service/src/manager/live_prize_pool_item_cdk_manager.rs new file mode 100644 index 0000000..d97dabe --- /dev/null +++ b/rust-src/service/src/manager/live_prize_pool_item_cdk_manager.rs @@ -0,0 +1,63 @@ +use chrono::Local; +use common::error::MyError; +use entity::prelude::LivePrizePoolItemCdk; +use entity::live_prize_pool_item_cdk; +use model::prize::ImportPoolItemCdk; +use sea_orm::ActiveValue::Set; +use sea_orm::{ActiveModelTrait, ColumnTrait, DbConn, EntityTrait, NotSet, Order, PaginatorTrait, QueryFilter, QueryOrder}; + + +pub async fn import_cdk(db: &DbConn, form: ImportPoolItemCdk) -> Result { + let live_id = form.live_id; + let prize_id = form.prize_id; + let mut entities: Vec= Vec::new(); + let mut sum=0; + for c in form.cdk { + if !c.is_empty() { + entities.push(live_prize_pool_item_cdk::ActiveModel{ + id: NotSet, + live_id: Set(Some(live_id)), + prize_id: Set(Some(prize_id)), + cdk: Set(Some(c)), + status: Set(Some(true)), + create_time: Set(Some(Local::now().naive_local())), + update_time: NotSet + }); + sum += 1; + } + } + LivePrizePoolItemCdk::insert_many(entities).exec(db).await?; + Ok(sum) +} + + +pub async fn clean_cdk(db: &DbConn, live_id: i64, prize_id: i64) -> Result { + let res = LivePrizePoolItemCdk::delete_many() + .filter(live_prize_pool_item_cdk::Column::LiveId.eq(live_id)) + .filter(live_prize_pool_item_cdk::Column::PrizeId.eq(prize_id)) + .exec(db) + .await?; + Ok(res.rows_affected > 0) +} + +pub async fn consumer_cdk(db: &DbConn, live_id: i64, prize_id: Option) -> Result, MyError> { + let res = LivePrizePoolItemCdk::find() + .filter(live_prize_pool_item_cdk::Column::LiveId.eq(live_id)) + .filter(live_prize_pool_item_cdk::Column::PrizeId.eq(prize_id)) + .filter(live_prize_pool_item_cdk::Column::Status.eq(true)) + .order_by(live_prize_pool_item_cdk::Column::CreateTime,Order::Asc) + .paginate(db, 1).fetch_page(1).await?; + let result = res.get(0); + match result { + None => { + Ok(None) + } + Some(model) => { + let mut entity: live_prize_pool_item_cdk::ActiveModel = model.clone().into(); + entity.status=Set(Option::from(false)); + entity.update(db).await?; + Ok(Option::from(model.clone())) + } + } + +} \ No newline at end of file diff --git a/rust-src/service/src/manager/live_prize_pool_item_manager.rs b/rust-src/service/src/manager/live_prize_pool_item_manager.rs index 7cd27f0..18db58f 100644 --- a/rust-src/service/src/manager/live_prize_pool_item_manager.rs +++ b/rust-src/service/src/manager/live_prize_pool_item_manager.rs @@ -9,7 +9,6 @@ use sea_orm::QueryFilter; use common::error::MyError; use common::page::PageResult; use entity::{live_prize_pool_item, prize_pool_item}; -use entity::live_prize_pool_item::Model; use entity::prelude::LivePrizePoolItem; use model::prize::LivePrizePoolItemPage; @@ -29,6 +28,7 @@ pub async fn create_live_item(db: &DbConn, live_id : i64, items: Vec R Ok(res) } -pub async fn update_remaining_quantity(db: &DbConn, map: HashMap>) -> Result { +pub async fn update_remaining_quantity(db: &DbConn, map: HashMap>) -> Result { for item in map{ let entity = LivePrizePoolItem::find_by_id(item.0).one(db).await?; match entity { @@ -198,6 +198,23 @@ pub async fn update_remaining_quantity(db: &DbConn, map: HashMap Ok(true) } +pub async fn update_cdk_quantity(db: &DbConn, live_id:i64, prize_id:i64, num:i32) -> Result { + let entity = LivePrizePoolItem::find() + .filter(live_prize_pool_item::Column::LiveId.eq(live_id)) + .filter(live_prize_pool_item::Column::PrizeId.eq(prize_id)) + .one(db).await?; + match entity { + None => {} + Some(entity) => { + let mut entity: live_prize_pool_item::ActiveModel = entity.into(); + entity.cdk_quantity = Set(if num == 0 {Some(0)}else{Some(entity.cdk_quantity.unwrap().unwrap() + num)}); + entity.update_time = Set(Some(Local::now().naive_local())); + entity.update(db).await?; + } + } + Ok(true) +} + pub async fn pool_item_remaining_quantity_count(db: &DbConn, live_id: i64) -> Result { let res = LivePrizePoolItem::find() .column_as(live_prize_pool_item::Column::RemainingQuantity.sum(),"remaining_quantity") diff --git a/rust-src/service/src/manager/mod.rs b/rust-src/service/src/manager/mod.rs index 40fceb3..a2bfb56 100644 --- a/rust-src/service/src/manager/mod.rs +++ b/rust-src/service/src/manager/mod.rs @@ -8,3 +8,4 @@ pub mod live_prize_pool_item_manager; pub mod live_prize_history_manager; pub mod cdk_manager; pub mod live_prize_pool_user_manager; +pub mod live_prize_pool_item_cdk_manager; diff --git a/rust-src/static/home.html b/rust-src/static/home.html new file mode 100644 index 0000000..72087d6 --- /dev/null +++ b/rust-src/static/home.html @@ -0,0 +1,8 @@ + + + +
+ home +
+ + \ No newline at end of file diff --git a/rust-src/static/index.html b/rust-src/static/index.html new file mode 100644 index 0000000..9dd213b --- /dev/null +++ b/rust-src/static/index.html @@ -0,0 +1,8 @@ + + + +
+ hello word +
+ + \ No newline at end of file diff --git a/web/next.config.js b/web/next.config.js index 7069cfd..8355849 100644 --- a/web/next.config.js +++ b/web/next.config.js @@ -45,11 +45,11 @@ module.exports = withLess( return [ { source: '/api/:path*', - destination: 'http://localhost:8080/api/:path*', + destination: 'http://127.0.0.1:8080/api/:path*', }, { source: '/un-auth-api/:path*', - destination: 'http://localhost:8080/un-auth-api/:path*', + destination: 'http://127.0.0.1:8080/un-auth-api/:path*', }, ]; }, diff --git a/web/src/api/livePrizePoolItem.js b/web/src/api/livePrizePoolItem.js index 23f4608..ca762d7 100644 --- a/web/src/api/livePrizePoolItem.js +++ b/web/src/api/livePrizePoolItem.js @@ -7,4 +7,5 @@ export const getLivePrizePoolItemPage = (param) => postRequestBody("/api/live_pr export const updateLivePrizePoolItem = (param) => postRequestBody("/api/live_prize_pool_item/update", param); export const removeLivePrizePoolItem = (id) => get("/api/live_prize_pool_item/delete/" + id); export const addLivePrizePoolItem = (live_id,item_id) => get("/api/live_prize_pool_item/add/"+live_id+"/"+item_id); - +export const cleanLivePrizePoolItemCdk = (live_id,item_id) => get("/api/live_prize_pool_item/clean_cdk/"+live_id+"/"+item_id); +export const importLivePrizePoolItemCdk = (param) => postRequestBody("/api/live_prize_pool_item/import_cdk", param); diff --git a/web/src/pages/systemManager/cdkManager/addPage.tsx b/web/src/pages/systemManager/cdkManager/addPage.tsx index cef464c..df5e7b8 100644 --- a/web/src/pages/systemManager/cdkManager/addPage.tsx +++ b/web/src/pages/systemManager/cdkManager/addPage.tsx @@ -28,20 +28,22 @@ function AddPage(props: { visible; setVisible; callback: () => void }) { const [poolSelectData, setPoolSelectData] = useState([]); useEffect(() => { - getLivePrizePoolSelectList().then((res) => { - const { success, data } = res.data; - if (success && data.length > 0) { - setPoolSelectData( - data.map((item) => { - return { - label: item.pool_name, - value: item.id, - }; - }) - ); - } - }); - }, []); + if(props.visible){ + getLivePrizePoolSelectList().then((res) => { + const { success, data } = res.data; + if (success && data.length > 0) { + setPoolSelectData( + data.map((item: { pool_name: any; id: any; }) => { + return { + label: item.pool_name, + value: item.id, + }; + }) + ); + } + }); + } + }, [props.visible]); const handleSubmit = () => { formRef.current.validate().then((values) => { diff --git a/web/src/pages/systemManager/livePrizePoolManager/index.tsx b/web/src/pages/systemManager/livePrizePoolManager/index.tsx index b483b55..1f2cc8b 100644 --- a/web/src/pages/systemManager/livePrizePoolManager/index.tsx +++ b/web/src/pages/systemManager/livePrizePoolManager/index.tsx @@ -183,7 +183,7 @@ function SearchTable() { /> setItemManagerVisibled(false)} footer={null} diff --git a/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/constants.tsx b/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/constants.tsx index 24d67dd..465b4ab 100644 --- a/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/constants.tsx +++ b/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/constants.tsx @@ -46,6 +46,11 @@ export function getColumns( dataIndex: 'remaining_quantity', ellipsis: true, }, + { + title: t['searchTable.columns.cdk_quantity'], + dataIndex: 'cdk_quantity', + ellipsis: true, + }, { title: t['searchTable.columns.status'], dataIndex: 'status', @@ -89,6 +94,7 @@ export function getColumns( title: t['searchTable.columns.operations'], dataIndex: 'operations', headerCellStyle: { paddingLeft: '15px' }, + with:500, render: (_, record) => [ , - { - callback(record, 'delete'); - }} + key={'delete'} + requiredPermissions={[ + { + resource: 'live_prize_pool_item_manager', + actions: ['api_live_prize_pool_item_delete'], + }, + ]} + > + { + callback(record, 'delete'); + }} + > + + + , + - - - , + , + + { + callback(record, 'clean_cdk'); + }} + > + + + , ], }, ]; } -export default function Constants () { +export default function Constants() { return (<>) } \ No newline at end of file diff --git a/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/index.tsx b/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/index.tsx index e4e98a9..fa29a6c 100644 --- a/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/index.tsx +++ b/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/index.tsx @@ -6,13 +6,16 @@ import { Typography, Notification, Space, - Button + Button, + Modal, + Form, + Input } from '@arco-design/web-react'; import useLocale from '@/utils/useLocale'; import SearchForm from './form'; import locale from './locale'; import { DefaultSorter, getColumns } from './constants'; -import { getLivePrizePoolItemPage, removeLivePrizePoolItem } from '@/api/livePrizePoolItem'; +import { cleanLivePrizePoolItemCdk, getLivePrizePoolItemPage, importLivePrizePoolItemCdk, removeLivePrizePoolItem } from '@/api/livePrizePoolItem'; import { v4 } from 'uuid'; import InfoPage from './infoPage'; @@ -45,6 +48,14 @@ function PrizePoolItemPage(props: { livePrizePoolId: number }) { if (type === 'delete') { deleteData(record.id); } + //删除 + if (type === 'import_cdk') { + importCdk(record.id); + } + //删除 + if (type === 'clean_cdk') { + cleanCdk(record.id); + } }; //添加 @@ -83,6 +94,29 @@ function PrizePoolItemPage(props: { livePrizePoolId: number }) { }); } + //导入cdk + const [importCdkVisible, setImportCdkVisibled] = useState(false); + const [importCdkId, setImportCdkId] = useState(); + const [cdktValues, setCdktValues] = useState(''); + function importCdk(id) { + setImportCdkId(id); + setImportCdkVisibled(true); + } + + //清空cdk + function cleanCdk(id) { + cleanLivePrizePoolItemCdk(props.livePrizePoolId,id).then((res) => { + const { success, message } = res.data; + if (success) { + Notification.success({ content: message, duration: 1000 }); + fetchData(); + } else { + Notification.error({ content: message, duration: 1000 }); + fetchData(); + } + }); + } + const columns = useMemo(() => getColumns(t, tableCallback), [t]); const [data, setData] = useState([]); @@ -211,6 +245,27 @@ function PrizePoolItemPage(props: { livePrizePoolId: number }) { setVisible={setUpdateVisibled} callback={fetchData} /> + setImportCdkVisibled(false)} + onConfirm={() => { + importLivePrizePoolItemCdk({ + live_id: props.livePrizePoolId, + prize_id: importCdkId, + cdk: cdktValues.split('\n'), + }).then((res) => { + const { success, data } = res.data; + if (success) { + setImportCdkVisibled(false); + Notification.success({ content: "成功导入"+data+"个", duration: 1000 }); + fetchData(); + } + }); + }} + > + setCdktValues(value)} placeholder='每行一个' allowClear /> + ); } diff --git a/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/locale/index.ts b/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/locale/index.ts index 889695c..56476e1 100644 --- a/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/locale/index.ts +++ b/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/locale/index.ts @@ -13,6 +13,7 @@ const i18n = { 'searchTable.columns.level_name': 'Level Name', 'searchTable.columns.probability': 'Probability', 'searchTable.columns.remaining_quantity': 'Remaining Quantity', + 'searchTable.columns.cdk_quantity': 'CDK Quantity', 'searchTable.columns.create_time': 'Create Time', 'searchTable.columns.update_time': 'Update Time', 'searchTable.columns.pool_desc': 'Description', @@ -25,11 +26,13 @@ const i18n = { 'searchTable.columns.operations.view': 'View', 'searchTable.columns.operations.update': 'Edit', 'searchTable.columns.operations.delete': 'Delete', - 'searchTable.columns.operations.set_role_resource': 'Set Resource', + 'searchTable.columns.operations.import_cdk': 'Import CDK', + 'searchTable.columns.operations.clean_cdk': 'Clean CDK', 'searchTable.operations.add': 'New', 'searchForm.id.placeholder': 'Please enter the ID', 'searchForm.placeholder': 'Please enter ', 'option.delete.confirm.title': 'Are you sure you want to delete it ?', + 'option.clean_cdk.confirm.title': 'Are you sure you want to clear CDK it ?', 'searchForm.disable': 'Disable', 'searchForm.enable': 'Enable', }, @@ -48,6 +51,7 @@ const i18n = { 'searchTable.columns.level_name': '等级名称', 'searchTable.columns.probability': '概率', 'searchTable.columns.remaining_quantity': '剩余数量', + 'searchTable.columns.cdk_quantity': 'CDK数量', 'searchTable.columns.create_time': '创建时间', 'searchTable.columns.update_time': '更新时间', 'searchTable.columns.prize_desc': '描述', @@ -60,10 +64,12 @@ const i18n = { 'searchTable.columns.operations.view': '查看', 'searchTable.columns.operations.update': '修改', 'searchTable.columns.operations.delete': '删除', - 'searchTable.columns.operations.set_role_resource': '授权资源', + 'searchTable.columns.operations.import_cdk': '导入cdk', + 'searchTable.columns.operations.clean_cdk': '清空cdk', 'searchTable.operations.add': '新建', 'searchForm.placeholder': '请输入', 'option.delete.confirm.title': '您确认要删除吗?', + 'option.clean_cdk.confirm.title': '您确认要清空CDK吗?', 'searchForm.disable': '禁用', 'searchForm.enable': '开启', }, diff --git a/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/updatePage.tsx b/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/updatePage.tsx index c4fb8b4..d5d08a2 100644 --- a/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/updatePage.tsx +++ b/web/src/pages/systemManager/livePrizePoolManager/livePrizePoolItem/updatePage.tsx @@ -170,7 +170,7 @@ function UpdatePage(props: { id: number; visible; setVisible; callback }) { label={t['searchTable.columns.remaining_quantity']} field={'remaining_quantity'} > - + {value}, }, - // { - // title: t['searchTable.columns.live_id'], - // dataIndex: 'live_id', - // ellipsis: true, - // }, { width: '150px', title: t['searchTable.columns.action'], @@ -45,31 +40,20 @@ export function getColumns( }, }, { - title: t['searchTable.columns.prize_ids'], - dataIndex: 'prize_items', - ellipsis: true, - render: (value) => value? JSON.parse(value).map((item, index) => ( - <> - [{item.level_name}] - {item.prize_name}  - - )) : '' + title: t['searchTable.columns.operations'], + dataIndex: 'operations', + headerCellStyle: { paddingLeft: '15px' }, + render: (_, record) => [ + + ], }, - // { - // title: t['searchTable.columns.operations'], - // dataIndex: 'operations', - // headerCellStyle: { paddingLeft: '15px' }, - // render: (_, record) => [ - // - // ], - // }, ]; } export default function Constants () { diff --git a/web/src/pages/user/drawHistory/index.tsx b/web/src/pages/user/drawHistory/index.tsx index f2a759b..d706909 100644 --- a/web/src/pages/user/drawHistory/index.tsx +++ b/web/src/pages/user/drawHistory/index.tsx @@ -23,16 +23,16 @@ function PrizePoolItemPage(props: { prizePoolId: number }) { const tableCallback = async (record, type) => { //查看 if (type === 'view') { - viewInfo(record.id); + viewInfo(record); } }; //查看 const [viewVisible, setViewVisibled] = useState(false); - const [viewInfoId, setViewInfoId] = useState(); - function viewInfo(id) { - setViewInfoId(id); + const [viewInfoData, setViewInfoData] = useState(); + function viewInfo(record) { + setViewInfoData(record); setViewVisibled(true); } @@ -125,7 +125,7 @@ function PrizePoolItemPage(props: { prizePoolId: number }) { data={data} /> diff --git a/web/src/pages/user/drawHistory/infoPage.tsx b/web/src/pages/user/drawHistory/infoPage.tsx index f6e3fb5..69d7bbb 100644 --- a/web/src/pages/user/drawHistory/infoPage.tsx +++ b/web/src/pages/user/drawHistory/infoPage.tsx @@ -5,30 +5,14 @@ import useLocale from '@/utils/useLocale'; import { getPrizePoolItemInfo } from '@/api/prizePoolItem'; import dayjs from 'dayjs'; -function InfoPage(props: { id: number; visible; setVisible }) { +function InfoPage(props: { info: any; visible; setVisible }) { const [loading, setLoading] = useState(false); const [infoData, setInfoData] = useState(); - function fetchData() { - setLoading(true); - if (props.id !== undefined) { - getPrizePoolItemInfo(props.id) - .then((res) => { - const { success, data } = res.data; - if (success) { - setInfoData(data); - } - }) - .finally(() => { - setLoading(false); - }); - } - } - useEffect(() => { - fetchData(); - }, [props.id]); + setInfoData(props.info); + }, [JSON.stringify(props.info)]); const t = useLocale(locale); @@ -57,48 +41,15 @@ function InfoPage(props: { id: number; visible; setVisible }) { value: infoData ? infoData.id : '', }, { - label: t['searchTable.columns.pool_id'], - value: infoData ? infoData.pool_id : '', - }, - { - label: t['searchTable.columns.prize_name'], - value: infoData ? infoData.prize_name : '', - }, - { - label: t['searchTable.columns.icon'], - value: infoData ? infoData.icon : '', - }, - { - label: t['searchTable.columns.level'], - value: infoData ? infoData.level : '', - }, - { - label: t['searchTable.columns.level_name'], - value: infoData ? infoData.level_name : '', - }, - { - label: t['searchTable.columns.probability'], - value: infoData ? infoData.probability : '', - }, - { - label: t['searchTable.columns.quantity'], - value: infoData ? infoData.quantity : '', - }, - { - label: t['searchTable.columns.status'], - value: infoData - ? infoData.status - ? t['searchForm.enable'] - : t['searchForm.disable'] - : '', - }, - { - label: t['searchTable.columns.guarantees'], - value: infoData - ? infoData.guarantees - ? t['searchTable.columns.yes'] - : t['searchTable.columns.no'] - : '', + label: t['searchTable.columns.prize_ids'], + value: infoData && infoData.prize_items ? JSON.parse(infoData.prize_items).map((item, index) => ( + <> + [{item.level_name}] + {item.prize_name} + [cdk:{item.cdk}] +

+ + )) : '' }, { label: t['searchTable.columns.create_time'], diff --git a/web/src/pages/user/drawHistory/locale/index.ts b/web/src/pages/user/drawHistory/locale/index.ts index fcbcba0..9687eec 100644 --- a/web/src/pages/user/drawHistory/locale/index.ts +++ b/web/src/pages/user/drawHistory/locale/index.ts @@ -9,6 +9,7 @@ const i18n = { 'searchTable.columns.action': 'Draw Count', 'searchTable.columns.prize_ids': 'Prize', 'searchTable.columns.prize_items': 'Prize', + 'searchTable.columns.cdk': 'CDK', 'searchTable.columns.create_time': 'Drawn Time', 'searchTable.columns.operations': 'Operation', 'searchTable.columns.operations.view': 'View', @@ -29,6 +30,7 @@ const i18n = { 'searchTable.columns.action': '抽奖数', 'searchTable.columns.prize_ids': '奖品', 'searchTable.columns.prize_items': '奖品', + 'searchTable.columns.cdk': 'CDK信息', 'searchTable.columns.create_time': '抽奖时间', 'searchTable.columns.operations': '操作', 'searchTable.columns.operations.view': '查看',