From fe7211860f4142a3abdcc76e69161a4895f0c6ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Sun, 3 Nov 2024 15:27:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=90=AD=E5=BB=BA=E5=95=86=E5=9F=8E?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E4=B8=9A=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/Discuss/DiscussGetListInputVo.cs | 6 +- .../Dtos/Shop/BuyShopInputDto.cs | 7 ++ .../Dtos/Shop/ShopGetListOutput.cs | 73 +++++++++++++++++ .../Services/Shop/BbsShopService.cs | 78 ++++++++++++++++++- .../Entities/Shop/BbsGoodsAggregateRoot.cs | 5 +- .../Managers/BbsShopManager.cs | 11 --- .../Managers/Shop/BbsShopManager.cs | 48 +++++++++++- .../Managers/InvitationCodeManager.cs | 2 + 8 files changed, 209 insertions(+), 21 deletions(-) create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Shop/BuyShopInputDto.cs create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Shop/ShopGetListOutput.cs delete mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/BbsShopManager.cs diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Discuss/DiscussGetListInputVo.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Discuss/DiscussGetListInputVo.cs index 4d420318..9c93e93d 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Discuss/DiscussGetListInputVo.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Discuss/DiscussGetListInputVo.cs @@ -6,7 +6,7 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss public class DiscussGetListInputVo : PagedAndSortedResultRequestDto { /// - /// 创建者的用户名 + /// 鍒涘缓鑰呯殑鐢ㄦ埛鍚 /// public string? UserName { get; set; } public Guid? UserId { get; set; } @@ -15,11 +15,11 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss public Guid? PlateId { get; set; } - //默认查询非置顶 + //榛樿鏌ヨ闈炵疆椤 public bool? IsTop { get; set; } - //查询方式 + //鏌ヨ鏂瑰紡 public QueryDiscussTypeEnum Type { get; set; } = QueryDiscussTypeEnum.New; } } diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Shop/BuyShopInputDto.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Shop/BuyShopInputDto.cs new file mode 100644 index 00000000..321e23a4 --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Shop/BuyShopInputDto.cs @@ -0,0 +1,7 @@ +锘縩amespace Yi.Framework.Bbs.Application.Contracts.Dtos.Shop; + +public class BuyShopInputDto +{ + public Guid GoodsId { get; set; } + public string ContactInformation { get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Shop/ShopGetListOutput.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Shop/ShopGetListOutput.cs new file mode 100644 index 00000000..349d7fe6 --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Shop/ShopGetListOutput.cs @@ -0,0 +1,73 @@ +锘縰sing Yi.Framework.Bbs.Domain.Shared.Enums; + +namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Shop; + +public class ShopGetListOutput +{ + /// + /// 涓婃灦鏃堕棿 + /// + public DateTime CreationTime { get; set; } + + /// + /// 鍟嗗搧绫诲瀷 + /// + public GoodsTypeEnum GoodsType{ get; set; } + + /// + /// 涓嬫灦鏃堕棿 + /// + public DateTime? EndTime { get; set; } + + /// + /// 鍟嗗搧鍚嶇О + /// + public string Name { get; set; } + + /// + /// 姣忎汉闄愯喘鏁伴噺 + /// + public int LimitNumber { get; set; } + + /// + /// 褰撳墠搴撳瓨鏁伴噺 + /// + public int StockNumber { get; set; } + + /// + /// 鍟嗗搧鍥剧墖url + /// + public string ImageUrl { get; set; } + + /// + /// 鎻忚堪 + /// + public string Describe { get; set; } + + /// + /// 缂栧彿 + /// + public string Code { get; set; } + + /// + /// 鎵闇閽遍挶 + /// + public decimal NeedMoney { get; set; } + + /// + /// 鎵闇浠峰 + /// + public decimal NeedValue { get; set; } + + /// + /// 鎵闇绉垎 + /// + public decimal NeedPoints { get; set; } + + public int OrderNum { get; set; } + + /// + /// 鏄惁宸查檺鍒 + /// + public bool IsLimit { get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Shop/BbsShopService.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Shop/BbsShopService.cs index 8e8d38d1..482e5f5d 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Shop/BbsShopService.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Shop/BbsShopService.cs @@ -1,12 +1,82 @@ -锘縰sing Volo.Abp.Application.Services; +锘縰sing Mapster; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; +using Volo.Abp.Users; +using Yi.Framework.Bbs.Application.Contracts.Dtos.Shop; +using Yi.Framework.Bbs.Domain.Entities.Shop; +using Yi.Framework.Bbs.Domain.Managers; +using Yi.Framework.Bbs.Domain.Managers.Shop; +using Yi.Framework.Bbs.Domain.Shared.Enums; +using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.Bbs.Application.Services.Shop; + /// /// bbs鍟嗗煄鏈嶅姟 /// public class BbsShopService : ApplicationService { - //鑾峰彇鍟嗗煄鍒楄〃 - //璐拱閬撳叿 - //鑾峰彇鐢ㄦ埛鐨勫晢鍩庝俊鎭 + private readonly ISqlSugarRepository _repository; + private readonly ISqlSugarRepository _applyRepository; + private readonly BbsShopManager _bbsShopManager; + + public BbsShopService(ISqlSugarRepository repository, + ISqlSugarRepository applyRepository, BbsShopManager bbsShopManager) + { + _repository = repository; + _applyRepository = applyRepository; + _bbsShopManager = bbsShopManager; + } + + //鍟嗗煄鍒楄〃 + [Authorize] + public async Task> GetListAsync(PagedAndSortedResultRequestDto input) + { + var output = new List(); + var userId = CurrentUser.GetId(); + RefAsync total = 0; + var entities = await _repository._DbQueryable + .Where(x => x.EndTime > DateTime.Now) + .OrderBy(x => x.OrderNum) + .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); + var applyEntities = await _applyRepository.GetListAsync(x => x.UserId == userId); + + foreach (var entity in entities) + { + var dto = entity.Adapt(); + if (entity.GoodsType == GoodsTypeEnum.Apply) + { + //澶т簬闄愯喘鏁伴噺 + if (applyEntities.Count(x => x.GoodsId == entity.Id) >= entity.LimitNumber) + { + dto.IsLimit = true; + } + } + + output.Add(dto); + } + + return new PagedResultDto(total, output); + } + + /// + /// 璐拱鍟嗗搧 + /// + [Authorize] + public async Task PostBuyAsync([FromBody] BuyShopInputDto input) + { + var userId = CurrentUser.GetId(); + await _bbsShopManager.BuyAsync(userId, input.GoodsId, input.ContactInformation); + } + + /// + /// 鑾峰彇璇ョ敤鎴锋眹鎬讳俊鎭紙閽遍挶銆佺Н鍒嗐佷环鍊硷級 + /// + [Authorize] + public async Task GetAccountAsync() + { + } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Shop/BbsGoodsAggregateRoot.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Shop/BbsGoodsAggregateRoot.cs index c576d306..8b2e99b6 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Shop/BbsGoodsAggregateRoot.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Shop/BbsGoodsAggregateRoot.cs @@ -2,6 +2,7 @@ using Volo.Abp.Auditing; using Volo.Abp.Domain.Entities; using Yi.Framework.Bbs.Domain.Shared.Enums; +using Yi.Framework.Core.Data; namespace Yi.Framework.Bbs.Domain.Entities.Shop; @@ -9,7 +10,7 @@ namespace Yi.Framework.Bbs.Domain.Entities.Shop; /// 鍟嗗搧瀹氫箟琛 /// [SugarTable("BbsGoods")] -public class BbsGoodsAggregateRoot: AggregateRoot, IHasCreationTime +public class BbsGoodsAggregateRoot: AggregateRoot, IHasCreationTime,IOrderNum { /// /// 涓婃灦鏃堕棿 @@ -70,4 +71,6 @@ public class BbsGoodsAggregateRoot: AggregateRoot, IHasCreationTime /// 鎵闇绉垎 /// public decimal NeedPoints { get; set; } + + public int OrderNum { get; set; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/BbsShopManager.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/BbsShopManager.cs deleted file mode 100644 index a86a3aa9..00000000 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/BbsShopManager.cs +++ /dev/null @@ -1,11 +0,0 @@ -锘縰sing Volo.Abp.Domain.Services; - -namespace Yi.Framework.Bbs.Domain.Managers; - -/// -/// bbs鍟嗗搧棰嗗煙 -/// -public class BbsShopManager: DomainService -{ - -} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/Shop/BbsShopManager.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/Shop/BbsShopManager.cs index 27a6552c..6dbd5e70 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/Shop/BbsShopManager.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/Shop/BbsShopManager.cs @@ -1,11 +1,55 @@ 锘縰sing Volo.Abp.Domain.Services; +using Yi.Framework.Bbs.Domain.Entities.Shop; +using Yi.Framework.Bbs.Domain.Shared.Enums; +using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.Bbs.Domain.Managers.Shop; /// /// bbs鍟嗗煄棰嗗煙鏈嶅姟 /// -public class BbsShopManager: DomainService +public class BbsShopManager : DomainService { - + private readonly ISqlSugarRepository _repository; + private readonly ISqlSugarRepository _applyRepository; + + public BbsShopManager(ISqlSugarRepository repository, + ISqlSugarRepository applyRepository) + { + _repository = repository; + _applyRepository = applyRepository; + } + + /// + /// 鐢宠璐拱鍟嗗搧 + /// + /// + /// + /// + /// + public async Task BuyAsync(Guid userId, Guid goodsId,string contactInformation) + { + var goods = await _repository.GetFirstAsync(x => x.Id == goodsId); + + if (goods.GoodsType==GoodsTypeEnum.Apply) + { + var count= await _applyRepository.CountAsync(x => x.UserId == userId); + if (count>=goods.LimitNumber) + { + throw new UserFriendlyException("浣犲凡缁忚揪璇ュ晢鍝佹渶澶ч檺璐鏁"); + } + + await _applyRepository.InsertAsync(new BbsGoodsApplyAggregateRoot + { + GoodsId = goodsId, + UserId = userId, + ContactInformation = contactInformation + }); + + //鏇存柊搴撳瓨 + goods.StockNumber -= 1; + await _repository.UpdateAsync(goods); + } + + } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/InvitationCodeManager.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/InvitationCodeManager.cs index 4bd436cb..a58503d2 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/InvitationCodeManager.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/InvitationCodeManager.cs @@ -22,6 +22,8 @@ public class InvitationCodeManager : DomainService /// public async Task SetAsync(Guid writeUserId, string invitationCode) { + //缁熶竴澶у啓 + invitationCode= invitationCode.ToUpper(); var entityOrNull = await _repository.GetFirstAsync(x => x.InvitationCode == invitationCode); if (entityOrNull is null) {