82 lines
2.6 KiB
C#
82 lines
2.6 KiB
C#
//using MediatR;
|
||
//using Store.Framework.Models;
|
||
//using Store.Shops.Contracts;
|
||
//using Store.Users.Contracts.Dtos;
|
||
//using Store.Users.Entities;
|
||
//using Store.Users.Repositories;
|
||
//using System;
|
||
//using System.Collections.Generic;
|
||
//using System.Text;
|
||
|
||
//namespace Store.Users.Commands
|
||
//{
|
||
// /// <summary>
|
||
// /// 商铺续费
|
||
// /// </summary>
|
||
// /// <param name="UserName"></param>
|
||
// /// <param name="ShopId"></param>
|
||
// /// <param name="RenewDuration"></param>
|
||
// internal record class ShopRenewCommand(string UserName, string ShopId, int RenewDuration) : IRequest<ShopRenewResponse>;
|
||
// internal class ShopRenewCommandHandler : IRequestHandler<ShopRenewCommand, ShopRenewResponse>
|
||
// {
|
||
// private readonly IUserRepository _userRepository;
|
||
// private readonly IShopQueryService _shopQueryService;
|
||
|
||
// public ShopRenewCommandHandler(IUserRepository userRepository, IShopQueryService shopQueryService)
|
||
// {
|
||
// _userRepository = userRepository;
|
||
// _shopQueryService = shopQueryService;
|
||
// }
|
||
// async Task<ShopRenewResponse> IRequestHandler<ShopRenewCommand, ShopRenewResponse>.Handle(ShopRenewCommand request, CancellationToken cancellationToken)
|
||
// {
|
||
// ShopRenewResponse response = new ShopRenewResponse();
|
||
// var user = await _userRepository.GetUser(request.UserName);
|
||
// int shopPointsPerMonth = Math.Max(30, user.ShopPointsPerMonth);
|
||
// int deltaPoints = shopPointsPerMonth * request.RenewDuration;
|
||
// int newPoints = (int)user.Points - deltaPoints;
|
||
// DateTime expireTime = _shopQueryService.GetExpireTime(request.ShopId);
|
||
|
||
|
||
// if (currentExpire != null && currentExpire.ExpireTime > 0)
|
||
// {
|
||
// DateTime currentExpireTime = TimeUtils.StampToDateTime(currentExpire.ExpireTime);
|
||
// if (currentExpireTime > expireBaseTime)
|
||
// {
|
||
// expireBaseTime = currentExpireTime;
|
||
// }
|
||
// }
|
||
|
||
// int newExpireTime = CalculateNewExpireTime(expireBaseTime, request.RenewDuration);
|
||
|
||
|
||
|
||
// response.ShopId = request.ShopId;
|
||
// response.UserPoints = newPoints;
|
||
// response.ExpireTime = newExpireTime;
|
||
// return response;
|
||
// }
|
||
// private int CalculateNewExpireTime(DateTime expireBaseTime, int renewDuration)
|
||
// {
|
||
// DateTime newExpireDateTime;
|
||
// try
|
||
// {
|
||
// newExpireDateTime = expireBaseTime.AddMonths(renewDuration);
|
||
// }
|
||
// catch (ArgumentOutOfRangeException)
|
||
// {
|
||
// throw new InvalidOperationException("续费时长超出允许范围");
|
||
// }
|
||
|
||
// if (newExpireDateTime > TimeUtils.StampToDateTime(int.MaxValue))
|
||
// {
|
||
// throw new InvalidOperationException("续费时间超出系统支持范围");
|
||
// }
|
||
|
||
// return TimeUtils.DateTimeToTimestampSeconds(newExpireDateTime);
|
||
// }
|
||
|
||
// }
|
||
|
||
|
||
//}
|