feat: 搭建商城基础业务
This commit is contained in:
@@ -6,7 +6,7 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
|||||||
public class DiscussGetListInputVo : PagedAndSortedResultRequestDto
|
public class DiscussGetListInputVo : PagedAndSortedResultRequestDto
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>
|
/// 创建者的用户名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? UserName { get; set; }
|
public string? UserName { get; set; }
|
||||||
public Guid? UserId { 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 Guid? PlateId { get; set; }
|
||||||
|
|
||||||
//Ĭ<EFBFBD>ϲ<EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD>
|
//默认查询非置顶
|
||||||
public bool? IsTop { get; set; }
|
public bool? IsTop { get; set; }
|
||||||
|
|
||||||
|
|
||||||
//<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD>ʽ
|
//查询方式
|
||||||
public QueryDiscussTypeEnum Type { get; set; } = QueryDiscussTypeEnum.New;
|
public QueryDiscussTypeEnum Type { get; set; } = QueryDiscussTypeEnum.New;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Shop;
|
||||||
|
|
||||||
|
public class BuyShopInputDto
|
||||||
|
{
|
||||||
|
public Guid GoodsId { get; set; }
|
||||||
|
public string ContactInformation { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Shop;
|
||||||
|
|
||||||
|
public class ShopGetListOutput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 上架时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime CreationTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 商品类型
|
||||||
|
/// </summary>
|
||||||
|
public GoodsTypeEnum GoodsType{ get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下架时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? EndTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 商品名称
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 每人限购数量
|
||||||
|
/// </summary>
|
||||||
|
public int LimitNumber { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前库存数量
|
||||||
|
/// </summary>
|
||||||
|
public int StockNumber { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 商品图片url
|
||||||
|
/// </summary>
|
||||||
|
public string ImageUrl { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述
|
||||||
|
/// </summary>
|
||||||
|
public string Describe { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 编号
|
||||||
|
/// </summary>
|
||||||
|
public string Code { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 所需钱钱
|
||||||
|
/// </summary>
|
||||||
|
public decimal NeedMoney { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 所需价值
|
||||||
|
/// </summary>
|
||||||
|
public decimal NeedValue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 所需积分
|
||||||
|
/// </summary>
|
||||||
|
public decimal NeedPoints { get; set; }
|
||||||
|
|
||||||
|
public int OrderNum { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否已限制
|
||||||
|
/// </summary>
|
||||||
|
public bool IsLimit { get; set; }
|
||||||
|
}
|
||||||
@@ -1,12 +1,82 @@
|
|||||||
using Volo.Abp.Application.Services;
|
using 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;
|
namespace Yi.Framework.Bbs.Application.Services.Shop;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// bbs商城服务
|
/// bbs商城服务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BbsShopService : ApplicationService
|
public class BbsShopService : ApplicationService
|
||||||
{
|
{
|
||||||
//获取商城列表
|
private readonly ISqlSugarRepository<BbsGoodsAggregateRoot> _repository;
|
||||||
//购买道具
|
private readonly ISqlSugarRepository<BbsGoodsApplyAggregateRoot> _applyRepository;
|
||||||
//获取用户的商城信息
|
private readonly BbsShopManager _bbsShopManager;
|
||||||
|
|
||||||
|
public BbsShopService(ISqlSugarRepository<BbsGoodsAggregateRoot> repository,
|
||||||
|
ISqlSugarRepository<BbsGoodsApplyAggregateRoot> applyRepository, BbsShopManager bbsShopManager)
|
||||||
|
{
|
||||||
|
_repository = repository;
|
||||||
|
_applyRepository = applyRepository;
|
||||||
|
_bbsShopManager = bbsShopManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
//商城列表
|
||||||
|
[Authorize]
|
||||||
|
public async Task<PagedResultDto<ShopGetListOutput>> GetListAsync(PagedAndSortedResultRequestDto input)
|
||||||
|
{
|
||||||
|
var output = new List<ShopGetListOutput>();
|
||||||
|
var userId = CurrentUser.GetId();
|
||||||
|
RefAsync<int> 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<ShopGetListOutput>();
|
||||||
|
if (entity.GoodsType == GoodsTypeEnum.Apply)
|
||||||
|
{
|
||||||
|
//大于限购数量
|
||||||
|
if (applyEntities.Count(x => x.GoodsId == entity.Id) >= entity.LimitNumber)
|
||||||
|
{
|
||||||
|
dto.IsLimit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output.Add(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PagedResultDto<ShopGetListOutput>(total, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 购买商品
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
public async Task PostBuyAsync([FromBody] BuyShopInputDto input)
|
||||||
|
{
|
||||||
|
var userId = CurrentUser.GetId();
|
||||||
|
await _bbsShopManager.BuyAsync(userId, input.GoodsId, input.ContactInformation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取该用户汇总信息(钱钱、积分、价值)
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
public async Task GetAccountAsync()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
using Volo.Abp.Auditing;
|
using Volo.Abp.Auditing;
|
||||||
using Volo.Abp.Domain.Entities;
|
using Volo.Abp.Domain.Entities;
|
||||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||||
|
using Yi.Framework.Core.Data;
|
||||||
|
|
||||||
namespace Yi.Framework.Bbs.Domain.Entities.Shop;
|
namespace Yi.Framework.Bbs.Domain.Entities.Shop;
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ namespace Yi.Framework.Bbs.Domain.Entities.Shop;
|
|||||||
/// 商品定义表
|
/// 商品定义表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarTable("BbsGoods")]
|
[SugarTable("BbsGoods")]
|
||||||
public class BbsGoodsAggregateRoot: AggregateRoot<Guid>, IHasCreationTime
|
public class BbsGoodsAggregateRoot: AggregateRoot<Guid>, IHasCreationTime,IOrderNum
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 上架时间
|
/// 上架时间
|
||||||
@@ -70,4 +71,6 @@ public class BbsGoodsAggregateRoot: AggregateRoot<Guid>, IHasCreationTime
|
|||||||
/// 所需积分
|
/// 所需积分
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public decimal NeedPoints { get; set; }
|
public decimal NeedPoints { get; set; }
|
||||||
|
|
||||||
|
public int OrderNum { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
using Volo.Abp.Domain.Services;
|
|
||||||
|
|
||||||
namespace Yi.Framework.Bbs.Domain.Managers;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// bbs商品领域
|
|
||||||
/// </summary>
|
|
||||||
public class BbsShopManager: DomainService
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,55 @@
|
|||||||
using Volo.Abp.Domain.Services;
|
using 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;
|
namespace Yi.Framework.Bbs.Domain.Managers.Shop;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// bbs商城领域服务
|
/// bbs商城领域服务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BbsShopManager: DomainService
|
public class BbsShopManager : DomainService
|
||||||
{
|
{
|
||||||
|
private readonly ISqlSugarRepository<BbsGoodsAggregateRoot> _repository;
|
||||||
|
private readonly ISqlSugarRepository<BbsGoodsApplyAggregateRoot> _applyRepository;
|
||||||
|
|
||||||
|
public BbsShopManager(ISqlSugarRepository<BbsGoodsAggregateRoot> repository,
|
||||||
|
ISqlSugarRepository<BbsGoodsApplyAggregateRoot> applyRepository)
|
||||||
|
{
|
||||||
|
_repository = repository;
|
||||||
|
_applyRepository = applyRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 申请购买商品
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <param name="goodsId"></param>
|
||||||
|
/// <param name="contactInformation"></param>
|
||||||
|
/// <exception cref="UserFriendlyException"></exception>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,8 @@ public class InvitationCodeManager : DomainService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task SetAsync(Guid writeUserId, string invitationCode)
|
public async Task SetAsync(Guid writeUserId, string invitationCode)
|
||||||
{
|
{
|
||||||
|
//统一大写
|
||||||
|
invitationCode= invitationCode.ToUpper();
|
||||||
var entityOrNull = await _repository.GetFirstAsync(x => x.InvitationCode == invitationCode);
|
var entityOrNull = await _repository.GetFirstAsync(x => x.InvitationCode == invitationCode);
|
||||||
if (entityOrNull is null)
|
if (entityOrNull is null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user