优惠券

This commit is contained in:
“wanyongkang”
2021-03-30 21:17:43 +08:00
parent 7ede35d5cf
commit 99e6255230
15 changed files with 141 additions and 53 deletions

View File

@@ -33,11 +33,11 @@ namespace Hncore.Pass.Live.Controllers
var entity = request.MapTo<CouponEntity>();
if (entity.Name.NotHas())
{
return Error("名称不能为空");
return Error("<EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>");
}
if (m_CouponService.Exist(m => m.Name == entity.Name))
{
return Error("名称已经存在了");
return Error("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
var ret = await m_CouponService.Add(entity);
return Success();
@@ -49,15 +49,15 @@ namespace Hncore.Pass.Live.Controllers
var entity = await m_CouponService.GetById(request.Id);
if (entity == null)
{
return Error("优惠券不存在");
return Error("<EFBFBD>Ż<EFBFBD>ȯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
if (request.Name.NotHas())
{
return Error("名称不能为空");
return Error("<EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>");
}
if (m_CouponService.Exist(m => m.Id != request.Id && m.Name == request.Name))
{
return Error("名称已经存在了");
return Error("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
entity.Name = request.Name;
@@ -84,7 +84,7 @@ namespace Hncore.Pass.Live.Controllers
var redeemCode = await m_CouponService.GetById(Id);
if (redeemCode == null)
{
return Error("该优惠券不存在");
return Error("<EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD>ȯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
redeemCode.Disabled = 1;
await m_CouponService.Update(redeemCode);
@@ -113,7 +113,7 @@ namespace Hncore.Pass.Live.Controllers
}
/// <summary>
/// 查询
/// <EFBFBD><EFBFBD>ѯ
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
@@ -135,11 +135,11 @@ namespace Hncore.Pass.Live.Controllers
{
if (request.CouponId==0)
{
return Error("请选择优惠券");
return Error("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD>ȯ");
}
if (request.UserId == 0)
{
return Error("请选择用户");
return Error("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>");
}
await this.m_CouponService.Give(request.CouponId, this.Request.GetManageUserInfo().OperaterId.ToString(), request.UserId, 1);
return Success();

View File

@@ -78,7 +78,7 @@ namespace Hncore.Pass.Sells.Service
public async Task<List<UserCouponModel>> GetUserCoupon(int userId)
{
var oroginCoupons = m_CouponUserOrginService.Query(m => m.ToUser == userId);
var oroginCoupons = m_CouponUserOrginService.Query(m => m.ToUser == userId && DateTime.Now <= m.EndTime);
var hasCoupon = from orgin in oroginCoupons
join coupon in this.Query(true) on orgin.CouponId equals coupon.Id
@@ -126,8 +126,6 @@ namespace Hncore.Pass.Sells.Service
public async Task<bool> TaoBaoGive(int userId, int couponId,string taobao)
{
if (m_CouponUserOrginService.Exist(m => (m.ToUser == userId||m.ToUserRef== taobao) && m.CreateDate.Value.Month == DateTime.Now.Month))
return false;
return await this.Give(couponId, "", userId, 1, CouponOriginType.TaoBao,"系统赠送",taobao);
}

View File

@@ -247,11 +247,16 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
}
//是否已经设置会员价
var is_user_price = true;
var price = packageEntity.Price;
var userPrice = await this.m_ProductUserPriceService.Query(true).FirstOrDefaultAsync(m => m.UserId == userId && m.PackageId == packageEntity.Id && m.Status == 1);
if (userPrice != null && userPrice.UserPrice > 0)
{
price = userPrice.UserPrice;
is_user_price = false;
}
if (ProductAccountCount == 0 && request.OrderType != OrderType.News && packageEntity.DayCount == 1 && request.ConnectCount == 1 && request.OrderType!=OrderType.AgainBuy&& request.OrderType!=OrderType.AgainBuys){
price = 0.1M;
@@ -329,7 +334,7 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
await CheckRequest(order);
var ret = await CaclePaymentAmount(order, request.UseAccountAmount);
var ret = await CaclePaymentAmount(order, request.UseAccountAmount, is_user_price);
if (ret.Code != ResultCode.C_SUCCESS) return ret;
@@ -353,7 +358,7 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
return new ApiResult<ProductOrderEntity>(order);
}
public async Task<ApiResult<ProductOrderEntity>> CaclePaymentAmount(ProductOrderEntity order, int useAccountAmount)
public async Task<ApiResult<ProductOrderEntity>> CaclePaymentAmount(ProductOrderEntity order, int useAccountAmount, bool is_user_price = true)
{
using (await _mutex1.LockAsync())
{
@@ -363,16 +368,33 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
if (order.CouponId > 0)
{
var currentCoupon = await m_CouponService.GetOneUserAvailableCoupon(userEntity.Id, order.CouponId.Value);
if (currentCoupon == null)
return new ApiResult<ProductOrderEntity>(ResultCode.C_INVALID_ERROR, "没有可用的优惠券");
if (currentCoupon.Coupon.AllowMinAmount > 0 && order.OrderAmount < currentCoupon.Coupon.AllowMinAmount)
{
return new ApiResult<ProductOrderEntity>(ResultCode.C_INVALID_ERROR, $"满{currentCoupon.Coupon.AllowMinAmount}元才能使用");
if(currentCoupon.Coupon.Id<16 ){
if(is_user_price){
if (currentCoupon == null)
return new ApiResult<ProductOrderEntity>(ResultCode.C_INVALID_ERROR, "没有可用的优惠券");
if (currentCoupon.Coupon.AllowMinAmount > 0 && order.OrderAmount < currentCoupon.Coupon.AllowMinAmount)
{
return new ApiResult<ProductOrderEntity>(ResultCode.C_INVALID_ERROR, $"满{currentCoupon.Coupon.AllowMinAmount}元才能使用");
}
if (currentCoupon.Coupon.CouponType == Sells.Model.ECouponType.Minus)
couponAmount = currentCoupon.Coupon.CouponValue;
else
couponAmount = order.OrderAmount * (currentCoupon.Coupon.CouponValue * 0.1m);
} else {
return new ApiResult<ProductOrderEntity>(ResultCode.C_INVALID_ERROR, "您已经享有会员优惠价,无法与优惠券共享!如有需求,请联系客服!");
}
} else {
if (currentCoupon == null)
return new ApiResult<ProductOrderEntity>(ResultCode.C_INVALID_ERROR, "没有可用的优惠券");
if (currentCoupon.Coupon.AllowMinAmount > 0 && order.OrderAmount < currentCoupon.Coupon.AllowMinAmount)
{
return new ApiResult<ProductOrderEntity>(ResultCode.C_INVALID_ERROR, $"满{currentCoupon.Coupon.AllowMinAmount}元才能使用");
}
if (currentCoupon.Coupon.CouponType == Sells.Model.ECouponType.Minus)
couponAmount = currentCoupon.Coupon.CouponValue;
else
couponAmount = order.OrderAmount * (currentCoupon.Coupon.CouponValue * 0.1m);
}
if (currentCoupon.Coupon.CouponType == Sells.Model.ECouponType.Minus)
couponAmount = currentCoupon.Coupon.CouponValue;
else
couponAmount = order.OrderAmount * (currentCoupon.Coupon.CouponValue * 0.1m);
}
order.CouponAmount = couponAmount;