using BPA.KitChen.GroupMealOrder.Application.BaseDto; using BPA.KitChen.GroupMealOrder.Application.Service.Order; using BPA.KitChen.GroupMealOrder.Application.Service.Order.Dtos; using BPA.KitChen.GroupMealOrder.Application.Service.ThirdAuthorize.Dtos; using BPA.KitChen.GroupMealOrder.Core.Entity; using BPA.KitChen.GroupMealOrder.SqlSugar; using Furion.DependencyInjection; using Furion.DynamicApiController; using Furion.FriendlyException; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BPA.KitChen.GroupMealOrder.Application.Service.ThirdAuthorize { [ApiDescriptionSettings("订单管理", Tag = "第三方授权", SplitCamelCase = false)] public class ThirdAuthorize : IDynamicApiController, ITransient, IThirdAuthorize { private readonly SqlSugarScope db; public ThirdAuthorize(IWebHostEnvironment hostingEnvironment) { db = SqlSugarDb.Db; } /// /// 获取第三方 /// /// /// [HttpPost("/api/ThirdAuthorize/Page")] public async Task Page(ThirdAuthorizeInfoDto inputDto) { var total = new RefAsync(); var data = await db.Queryable() .OrderBy(a => a.CreateAt, OrderByType.Desc) .ToPageListAsync(inputDto.Current, inputDto.PageSize, total); return new PageUtil() { Data = data, Total = total }; } /// /// 创建 授权 /// /// /// [HttpPost("/api/ThirdAuthorize/Create")] public async Task Create(BPA_ShopAuthorize inputDto) { var data=await db.Queryable().Where(x=>x.StoreId==inputDto.StoreId).FirstAsync(); if (data != null) { throw Oops.Oh($"店铺已授权"); } inputDto.AuthorizeCode=Guid.NewGuid().ToString(); var res=await db.Insertable(inputDto).ExecuteCommandAsync(); return res > 0; } /// /// 修改 重新赋值授权码 /// /// /// [HttpPost("/api/ThirdAuthorize/Update")] public async Task Update(BPA_ShopAuthorize inputDto) { var data = await db.Queryable().Where(x =>x.Id==inputDto.Id).FirstAsync(); data.AuthorizeCode = Guid.NewGuid().ToString(); var res=await db.Updateable(data).ExecuteCommandAsync(); return res > 0; } /// /// 修改 重新赋值授权码 /// /// /// [HttpPost("/api/ThirdAuthorize/Del")] public async Task Del(string id) { var res = await SqlSugarDb.Db.Updateable() .SetColumns(it => new BPA_ShopAuthorize { IsDeleted = 1 })//类只能在表达示里面不能提取 .Where(it => it.Id == id) .ExecuteCommandAsync(); return res > 0; } } }