更新了解说兑换商店
This commit is contained in:
parent
0476e13241
commit
26b6308776
@ -1,4 +1,5 @@
|
||||
using asg_form.Migrations;
|
||||
using Manganese.Text;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -36,7 +37,7 @@ namespace asg_form.Controllers
|
||||
{
|
||||
TestDbContext testDb = new TestDbContext();
|
||||
string chinaname = user.chinaname;
|
||||
var teamgame = testDb.team_Games.Where(a => a.commentary.IndexOf(chinaname) >= 0).Select(a => new { a.id, a.team1_name, a.team2_name, a.bilibiliuri, a.commentary, a.referee ,a.opentime}).ToList();
|
||||
var teamgame = testDb.team_Games.Where(a => a.commentary.IndexOf(chinaname) >= 0).Select(a => new { a.id, a.team1_name, a.team2_name, a.bilibiliuri, a.commentary, a.referee, a.opentime,a.tag,a.belong}).ToList();
|
||||
|
||||
return JsonConvert.SerializeObject(teamgame);
|
||||
}
|
||||
@ -55,25 +56,16 @@ namespace asg_form.Controllers
|
||||
var user = await userManager.FindByIdAsync(id);
|
||||
if (user.officium == "Commentator")
|
||||
{
|
||||
|
||||
TestDbContext testDb = new TestDbContext();
|
||||
string chinaname = user.chinaname;
|
||||
var teamgame = await testDb.team_Games.FirstAsync(a => a.id == gameid);
|
||||
if (teamgame.commentary == "待公布")
|
||||
{
|
||||
List<string> strings = new List<string>
|
||||
{
|
||||
chinaname
|
||||
};
|
||||
teamgame.commentary = string.Join(",", strings.ToArray());
|
||||
await testDb.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var team_game = teamgame.commentary.Split(",").ToList();
|
||||
team_game.Add(chinaname);
|
||||
teamgame.commentary = string.Join(",", team_game.ToArray());
|
||||
await testDb.SaveChangesAsync();
|
||||
}
|
||||
var com = JsonConvert.DeserializeObject<List<com_json>>(teamgame.commentary);
|
||||
com.Add(new com_json { id = id.ToInt32(), chinaname = chinaname });
|
||||
teamgame.commentary = JsonConvert.SerializeObject(com);
|
||||
await testDb.SaveChangesAsync();
|
||||
user.Integral = user.Integral+10;
|
||||
await userManager.UpdateAsync(user);
|
||||
try
|
||||
{
|
||||
await MessageManager.SendGroupMessageAsync("870248618", $"解说:\r\n{chinaname}\r\n选择了比赛:\r\n{teamgame.team1_name} VS {teamgame.team2_name}");
|
||||
@ -87,6 +79,21 @@ namespace asg_form.Controllers
|
||||
return BadRequest(new error_mb { code = 400, message = $"你是{user.officium},你不是解说,无法操作" });
|
||||
}
|
||||
|
||||
public class com_json
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int id { get; set; }
|
||||
/// <summary>
|
||||
/// 老恐龙
|
||||
/// </summary>
|
||||
public string chinaname { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 取消选班
|
||||
@ -105,14 +112,17 @@ namespace asg_form.Controllers
|
||||
TestDbContext testDb = new TestDbContext();
|
||||
string chinaname = user.chinaname;
|
||||
var teamgame = await testDb.team_Games.FirstAsync(a => a.id == gameid);
|
||||
var team_game = teamgame.commentary.Split(",").ToList();
|
||||
team_game.Remove(chinaname);
|
||||
teamgame.commentary = string.Join(",", team_game.ToArray());
|
||||
if (teamgame.commentary=="")
|
||||
{
|
||||
teamgame.commentary = "待公布";
|
||||
var com = JsonConvert.DeserializeObject<List<com_json>>(teamgame.commentary);
|
||||
com.Remove(com.First(a => a.id == id.ToInt32()));
|
||||
try{
|
||||
user.Integral = cut_value((long)user.Integral);
|
||||
await userManager.UpdateAsync(user);
|
||||
}
|
||||
|
||||
catch{
|
||||
return BadRequest(new error_mb { code = 400, message = $"你的金钱无法满足你完成以下操作" });
|
||||
|
||||
}
|
||||
teamgame.commentary = JsonConvert.SerializeObject(com);
|
||||
await testDb.SaveChangesAsync();
|
||||
return "成功";
|
||||
}
|
||||
@ -125,12 +135,34 @@ namespace asg_form.Controllers
|
||||
public async Task<ActionResult<string>> Search()
|
||||
{
|
||||
TestDbContext testDb = new TestDbContext();
|
||||
var team= await testDb.team_Games.Select(a => new {a.id,a.commentary,a.opentime,a.team1_name,a.team2_name,a.belong}).ToListAsync();
|
||||
var team = await testDb.team_Games.Select(a => new { a.id, a.commentary, a.opentime, a.team1_name, a.team2_name, a.belong }).ToListAsync();
|
||||
var team1 = team.Where(a => a.commentary.Split(",").Length <= 1);
|
||||
return JsonConvert.SerializeObject(team1);
|
||||
return JsonConvert.SerializeObject(team1);
|
||||
}
|
||||
|
||||
|
||||
[Route("api/v1/com/Integral/ranking")]
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
[ResponseCache(Duration = 60)]
|
||||
public async Task<ActionResult<object>> ranking()
|
||||
{
|
||||
object user= await userManager.Users.OrderByDescending(a => a.Integral).Select(a=>new{a.Id,a.chinaname,a.Integral}).Take(10).ToListAsync();
|
||||
return user;
|
||||
}
|
||||
|
||||
public long cut_value(long value)
|
||||
{
|
||||
long _value = value;
|
||||
value = value - 10;
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentException("你已经没钱啦!");
|
||||
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
[Route("api/v1/com/")]
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
@ -141,8 +173,8 @@ namespace asg_form.Controllers
|
||||
if (user.officium == "Commentator")
|
||||
{
|
||||
var chinaname = user.chinaname;
|
||||
TestDbContext testDb=new TestDbContext();
|
||||
int a= await testDb.team_Games.CountAsync(a => a.commentary.IndexOf(chinaname) >= 0);
|
||||
TestDbContext testDb = new TestDbContext();
|
||||
int a = await testDb.team_Games.CountAsync(a => a.commentary.IndexOf(id) >= 0);
|
||||
return a;
|
||||
}
|
||||
return BadRequest(new error_mb { code = 400, message = $"你是{user.officium},你不是解说,无法操作" });
|
||||
@ -150,5 +182,5 @@ namespace asg_form.Controllers
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
|
||||
using asg_form.Controllers.Store;
|
||||
using asg_form.Model;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -52,7 +53,23 @@ namespace asg_form.Controllers
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class QueryableExtensions
|
||||
{
|
||||
public static IQueryable<T> Paginate<T>(this IQueryable<T> query, int pageIndex, int pageSize)
|
||||
{
|
||||
return query.Skip(pageIndex * pageSize).Take(pageSize);
|
||||
}
|
||||
}
|
||||
class STOREConfig : IEntityTypeConfiguration<StoreinfoDB>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<StoreinfoDB> builder)
|
||||
{
|
||||
builder.ToTable("F_Store");
|
||||
builder.HasOne<StoreDB>(c => c.Store).WithMany(a => a.buyer).IsRequired();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class newsConfig : IEntityTypeConfiguration<T_news>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<T_news> builder)
|
||||
@ -163,7 +180,9 @@ namespace asg_form.Controllers
|
||||
public DbSet<Champion.T_Champion> Champions { get; set; }
|
||||
public DbSet<comform.com_form> com_Forms { get; set; }
|
||||
public DbSet<T_Friend> T_Friends { get; set; }
|
||||
|
||||
public DbSet<StoreDB> T_Store { get; set; }
|
||||
public DbSet<StoreinfoDB> T_Storeinfo { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
string connStr = @"Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;TrustServerCertificate=true";
|
||||
|
25
asg_form/Controllers/Store/StoreDB.cs
Normal file
25
asg_form/Controllers/Store/StoreDB.cs
Normal file
@ -0,0 +1,25 @@
|
||||
namespace asg_form.Controllers.Store
|
||||
{
|
||||
public class StoreDB
|
||||
{
|
||||
public long id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public long Price { get; set; }
|
||||
|
||||
public string description { get; set; }
|
||||
|
||||
public string information { get; set; }
|
||||
public string Type { get; set; }
|
||||
public List<StoreinfoDB>? buyer { get; set; }=new List<StoreinfoDB>();
|
||||
}
|
||||
public class StoreinfoDB
|
||||
{
|
||||
public long id { get; set; }
|
||||
public long buyerid { get; set; }
|
||||
public StoreDB Store { get; set; }
|
||||
|
||||
public bool isVerification { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
169
asg_form/Controllers/Store/Storehttp.cs
Normal file
169
asg_form/Controllers/Store/Storehttp.cs
Normal file
@ -0,0 +1,169 @@
|
||||
using Masuit.Tools;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace asg_form.Controllers.Store
|
||||
{
|
||||
public class Storehttp : ControllerBase
|
||||
{
|
||||
private readonly RoleManager<Role> roleManager;
|
||||
private readonly UserManager<User> userManager;
|
||||
public Storehttp(
|
||||
RoleManager<Role> roleManager, UserManager<User> userManager)
|
||||
{
|
||||
|
||||
this.roleManager = roleManager;
|
||||
this.userManager = userManager;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Route("api/v1/admin/Store")]
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<object>> AddStore([FromBody]StoreDB storeinfo)
|
||||
{
|
||||
if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin"))
|
||||
{
|
||||
return BadRequest(new error_mb { code = 400, message = "无权访问" });
|
||||
}
|
||||
using (TestDbContext sb = new TestDbContext()) {
|
||||
sb.T_Store.Add(storeinfo);
|
||||
await sb.SaveChangesAsync();
|
||||
return Ok(storeinfo);
|
||||
}
|
||||
}
|
||||
[Route("api/v1/admin/Store")]
|
||||
[HttpDelete]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<object>> DelStore(long id)
|
||||
{
|
||||
if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin"))
|
||||
{
|
||||
return BadRequest(new error_mb { code = 400, message = "无权访问" });
|
||||
}
|
||||
using (TestDbContext sb = new TestDbContext())
|
||||
{
|
||||
sb.T_Store.Remove(sb.T_Store.Find(id));
|
||||
await sb.SaveChangesAsync();
|
||||
return Ok("ok");
|
||||
}
|
||||
}
|
||||
[Route("api/v1/admin/Store")]
|
||||
[HttpPut]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<object>> putStore([FromBody] StoreDB storeinfo)
|
||||
{
|
||||
if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin"))
|
||||
{
|
||||
return BadRequest(new error_mb { code = 400, message = "无权访问" });
|
||||
}
|
||||
using (TestDbContext sb = new TestDbContext())
|
||||
{
|
||||
var a= await sb.T_Store.FindAsync(storeinfo.id);
|
||||
a = storeinfo;
|
||||
await sb.SaveChangesAsync();
|
||||
return Ok(storeinfo);
|
||||
}
|
||||
}
|
||||
public long cut_value(long value,long money)
|
||||
{
|
||||
long _value = value;
|
||||
value = value - money;
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentException("你已经没钱啦!");
|
||||
|
||||
}
|
||||
return value;
|
||||
}
|
||||
[Route("api/v1/Store")]
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<object>> GetStore()
|
||||
{
|
||||
|
||||
using (TestDbContext sb = new TestDbContext())
|
||||
{
|
||||
var a= sb.T_Store.ToList().GroupBy(a => a.Type);
|
||||
return Ok(a);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="search"></param>
|
||||
/// <param name="pageindex"></param>
|
||||
/// <param name="pagesize"></param>
|
||||
/// <param name="showVerification">是否展示以及核销过的</param>
|
||||
/// <returns></returns>
|
||||
[Route("api/v1/admin/Storeinfo")]
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<object>> GetStoreinfo(bool showVerification,long? search_id,int pageindex=0,int pagesize=10)
|
||||
{
|
||||
if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin"))
|
||||
{
|
||||
return BadRequest(new error_mb { code = 400, message = "无权访问" });
|
||||
}
|
||||
using (TestDbContext sb = new TestDbContext())
|
||||
{
|
||||
var a = new Store_record(null,null);
|
||||
IQueryable<StoreinfoDB> b;
|
||||
if (showVerification)
|
||||
{
|
||||
b = sb.T_Storeinfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = sb.T_Storeinfo.Where(a=>a.isVerification==false);
|
||||
}
|
||||
if (search_id == null)
|
||||
{
|
||||
return Ok(await b.Paginate(pageindex, pagesize).ToListAsync()) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(await b.Where(a=>a.buyerid==search_id).Paginate(pageindex, pagesize).ToListAsync());
|
||||
}
|
||||
}
|
||||
}
|
||||
public record Store_record(long? allstort,List<StoreinfoDB>? Storeinfos);
|
||||
[Route("api/v1/Store/Buy")]
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<object>> BuyStore(long storeid)
|
||||
{
|
||||
string id = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
|
||||
var user = await userManager.FindByIdAsync(id);
|
||||
|
||||
if (user.officium != "Commentator")
|
||||
{
|
||||
return BadRequest(new error_mb { code = 400, message = $"你是{user.officium},你不是解说,无法操作" });
|
||||
|
||||
}
|
||||
|
||||
using (TestDbContext sb = new TestDbContext())
|
||||
{
|
||||
var stort= await sb.T_Store.FindAsync(storeid);
|
||||
try
|
||||
{
|
||||
user.Integral = cut_value((long)user.Integral,stort.Price);
|
||||
await userManager.UpdateAsync(user);
|
||||
await sb.T_Storeinfo.AddAsync(new StoreinfoDB { buyerid = id.ToInt64(), Store = stort });
|
||||
await sb.SaveChangesAsync();
|
||||
return Ok("购买成功,请前往背包查看");
|
||||
}
|
||||
catch
|
||||
{
|
||||
return BadRequest(new error_mb { code = 400, message = $"你的金钱无法满足你完成以下操作" });
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ using System.Text;
|
||||
Console.WriteLine("\n _____ _________ ________ \n / _ \\ / _____// _____/ \n / /_\\ \\ \\_____ \\/ \\ ___ \n/ | \\/ \\ \\_\\ \\\n\\____|__ /_______ /\\______ /\n \\/ \\/ \\/ \n__________ __ ___________ .___\n\\______ \\_____ ____ | | __\\_ _____/ ____ __| _/\n | | _/\\__ \\ _/ ___\\| |/ / | __)_ / \\ / __ | \n | | \\ / __ \\\\ \\___| < | \\ | \\/ /_/ | \n |______ /(____ /\\___ >__|_ \\/_______ /___| /\\____ | \n \\/ \\/ \\/ \\/ \\/ \\/ \\/ ");
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.AddServiceDefaults();
|
||||
//builder.AddServiceDefaults();
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
@ -137,7 +137,7 @@ services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
|
||||
|
||||
var app = builder.Build();
|
||||
app.MapDefaultEndpoints();
|
||||
//app.MapDefaultEndpoints();
|
||||
app.UseCors();
|
||||
// Configure the HTTP request pipeline.
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
|
||||
using System.ComponentModel;
|
||||
using asg_form.Controllers;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
@ -7,6 +8,9 @@ namespace asg_form
|
||||
public class User : IdentityUser<long>
|
||||
{
|
||||
public string? UserBase64 { get; set; }
|
||||
|
||||
[DefaultValue(0)]
|
||||
public long? Integral { get; set; }
|
||||
public DateTime CreationTime { get; set; }
|
||||
|
||||
public form? haveform { get; set; }
|
||||
@ -14,7 +18,10 @@ namespace asg_form
|
||||
public bool? isbooking { get; set; }
|
||||
public string? chinaname { get; set; }
|
||||
|
||||
public string? officium { get; set; }
|
||||
public string? officium { get; set; }
|
||||
|
||||
public int point { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class Role : IdentityRole<long>
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user