This commit is contained in:
@@ -18,11 +18,13 @@ using Hncore.Pass.BaseInfo.Request.User;
|
||||
using Hncore.Pass.BaseInfo.Models;
|
||||
using ScoreType = Hncore.Pass.BaseInfo.Models.ScoreType;
|
||||
using System.Linq.Expressions;
|
||||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
public partial class ProductOrderService : ServiceBase<ProductOrderEntity>, IFindService
|
||||
{
|
||||
private static readonly AsyncLock _mutex1 = new AsyncLock();
|
||||
CourseContext m_DbContext;
|
||||
ProductService m_ProductService;
|
||||
ProductPackageService m_ProductPackageService;
|
||||
@@ -269,6 +271,7 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
||||
await CheckRequest(order);
|
||||
|
||||
var ret = await CaclePaymentAmount(order, request.UseAccountAmount);
|
||||
|
||||
if (ret.Code != ResultCode.C_SUCCESS) return ret;
|
||||
using (var tran = await m_DbContext.Database.BeginTransactionAsync())
|
||||
{
|
||||
@@ -292,38 +295,41 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
||||
|
||||
public async Task<ApiResult<ProductOrderEntity>> CaclePaymentAmount(ProductOrderEntity order, int useAccountAmount)
|
||||
{
|
||||
var userEntity = await m_UserService.GetById(order.UserId);
|
||||
//使用优惠券
|
||||
var couponAmount = 0m;
|
||||
if (order.CouponId > 0)
|
||||
using (await _mutex1.LockAsync())
|
||||
{
|
||||
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)
|
||||
var userEntity = await m_UserService.GetById(order.UserId);
|
||||
//使用优惠券
|
||||
var couponAmount = 0m;
|
||||
if (order.CouponId > 0)
|
||||
{
|
||||
return new ApiResult<ProductOrderEntity>(ResultCode.C_INVALID_ERROR, $"满{currentCoupon.Coupon.AllowMinAmount}元才能使用");
|
||||
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.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;
|
||||
order.PaymentAmount = order.OrderAmount - couponAmount;
|
||||
order.PaymentAmount = order.PaymentAmount < 0 ? 0 : order.PaymentAmount;
|
||||
//使用余额
|
||||
if (useAccountAmount == 1)
|
||||
{
|
||||
if (userEntity.RestAmount >= order.PaymentAmount)
|
||||
order.AccountPayAmount = order.PaymentAmount;
|
||||
else
|
||||
order.CouponAmount = couponAmount;
|
||||
order.PaymentAmount = order.OrderAmount - couponAmount;
|
||||
order.PaymentAmount = order.PaymentAmount < 0 ? 0 : order.PaymentAmount;
|
||||
//使用余额
|
||||
if (useAccountAmount == 1)
|
||||
{
|
||||
return new ApiResult<ProductOrderEntity>(ResultCode.C_UNKNOWN_ERROR, "余额不足");
|
||||
if (userEntity.RestAmount >= order.PaymentAmount)
|
||||
order.AccountPayAmount = order.PaymentAmount;
|
||||
else
|
||||
{
|
||||
return new ApiResult<ProductOrderEntity>(ResultCode.C_UNKNOWN_ERROR, "余额不足");
|
||||
}
|
||||
}
|
||||
order.OtherPayAmount = order.PaymentAmount - order.AccountPayAmount;
|
||||
}
|
||||
order.OtherPayAmount = order.PaymentAmount - order.AccountPayAmount;
|
||||
return new ApiResult<ProductOrderEntity>(order);
|
||||
}
|
||||
|
||||
@@ -340,7 +346,11 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
||||
AttchInfo = order.OrderNo,
|
||||
OperateUserName = order.UserName,
|
||||
};
|
||||
await m_BaseUserService.UpdateAmount(amountInfo);
|
||||
var ret = await m_BaseUserService.UpdateAmount(amountInfo);
|
||||
if (ret.Code != ResultCode.C_SUCCESS)
|
||||
{
|
||||
order.OtherPayAmount = order.PaymentAmount;
|
||||
}
|
||||
}
|
||||
//全是余额支付
|
||||
if (order.OtherPayAmount == 0)
|
||||
|
||||
Reference in New Issue
Block a user