using NCC.Common.Core.Manager; using NCC.Common.Enum; using NCC.Common.Extension; using NCC.Common.Filter; using NCC.Dependency; using NCC.DynamicApiController; using NCC.FriendlyException; using NCC.Extend.Interfaces.UavWalletWithdrawApply; using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using NCC.Extend.Entitys; using NCC.Extend.Entitys.Dto.UavWalletWithdrawApply; using Yitter.IdGenerator; using NCC.Common.Helper; using NCC.JsonSerialization; using NCC.Extend.Entitys.Enums; namespace NCC.Extend.UavWalletWithdrawApply { /// /// 提现申请服务 /// [ApiDescriptionSettings(Tag = "提现申请服务", Name = "UavWalletWithdrawApply", Order = 200)] [Route("api/Extend/[controller]")] public class UavWalletWithdrawApplyService : IUavWalletWithdrawApplyService, IDynamicApiController, ITransient { private readonly ISqlSugarRepository _uavWalletWithdrawApplyRepository; private readonly SqlSugarScope _db; private readonly IUserManager _userManager; /// /// 初始化一个类型的新实例 /// public UavWalletWithdrawApplyService( ISqlSugarRepository uavWalletWithdrawApplyRepository, IUserManager userManager) { _uavWalletWithdrawApplyRepository = uavWalletWithdrawApplyRepository; _db = _uavWalletWithdrawApplyRepository.Context; _userManager = userManager; } /// /// 获取提现申请 /// /// 参数 /// [HttpGet("{id}")] public async Task GetInfo(string id) { var entity = await _db.Queryable().FirstAsync(p => p.Id == id); var output = entity.Adapt(); return output; } /// /// 获取提现申请列表 /// /// 请求参数 /// [HttpGet("")] public async Task GetList([FromQuery] UavWalletWithdrawApplyListQueryInput input) { var sidx = input.sidx == null ? "id" : input.sidx; var data = await _db.Queryable() .WhereIF(!string.IsNullOrEmpty(input.bankAccountNumber), p => p.BankAccountNumber.Contains(input.bankAccountNumber)) .WhereIF(!string.IsNullOrEmpty(input.walletNo), p => p.WalletNo.Contains(input.walletNo)) .Select(it => new UavWalletWithdrawApplyListOutput { id = it.Id, amount = it.Amount, bankAccountName = it.BankAccountName, bankAccountNumber = it.BankAccountNumber, bankName = it.BankName, walletNo = it.WalletNo, }).MergeTable().OrderBy(sidx + " " + input.sort).ToPagedListAsync(input.currentPage, input.pageSize); return PageResult.SqlSugarPageResult(data); } /// /// 新建提现申请 /// /// 参数 /// [HttpPost("")] public async Task Create([FromBody] UavWalletWithdrawApplyCrInput input) { var userInfo = await _userManager.GetUserInfo(); var entity = input.Adapt(); entity.Id = YitIdHelper.NextId().ToString(); entity.UserId = _userManager.UserId; entity.Amount = -input.amount; entity.WalletNo = "TX" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); entity.ApplyTime = DateTime.Now; entity.AuditStatus = AuditStatusEnum.待审核.GetHashCode(); entity.TransferStatus = TransferStatusEnum.未转账.GetHashCode(); entity.CreateTime = DateTime.Now; entity.CreateUser = _userManager.UserId; var isOk = await _db.Insertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync(); if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000); } /// /// 更新提现申请 /// /// 主键 /// 参数 /// [HttpPut("{id}")] public async Task Update(string id, [FromBody] UavWalletWithdrawApplyUpInput input) { var entity = input.Adapt(); var isOk = await _db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1001); } /// /// 删除提现申请 /// /// [HttpDelete("{id}")] public async Task Delete(string id) { var entity = await _db.Queryable().FirstAsync(p => p.Id == id); _ = entity ?? throw NCCException.Oh(ErrorCode.COM1005); var isOk = await _db.Deleteable().Where(d => d.Id == id).ExecuteCommandAsync(); if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1002); } } }