using Hncore.Infrastructure.Service; using Hncore.Pass.Vpn.Domain; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Hncore.Pass.Vpn.Service { public partial class ProductAccountChargeService : ServiceBase, IFindService { CourseContext m_DbContext; public ProductAccountChargeService(CourseContext dbContext , IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor) { m_DbContext = dbContext; } /// /// 记录新开操作 /// /// /// /// /// /// /// /// /// /// public async Task RecordNew(ProductPackageEntity package, int orderId, string gid, string account, string pwd, int accountType, int connCount, ChargeStatus chargeStatus = ChargeStatus.Ok) { var chargeEntity = new ProductAccountChargeEntity() { Account = account, AccountType = accountType, ConnectCount = connCount, OperationType = ChargeOperationType.New, OrderId = orderId, PackageId = package.Id, PackageOriginKey = package.OriginKey, ProductGroup = gid, ProductId = package.ProductId, Pwd = pwd, Status = chargeStatus, TryTimes = 1, }; await this.Add(chargeEntity); } /// /// 记录续费操作 /// /// /// /// /// /// /// /// /// /// public async Task RecordReNew(ProductPackageEntity package, int orderId, string gid, string account, int connCount, ChargeStatus chargeStatus = ChargeStatus.Ok) { var chargeEntity = new ProductAccountChargeEntity() { Account = account, AccountType =0, ConnectCount = connCount, OperationType = ChargeOperationType.ReNew, OrderId = orderId, PackageId = package.Id, PackageOriginKey = package.OriginKey, ProductGroup = gid, ProductId = package.ProductId, Pwd = "", Status = chargeStatus, TryTimes = 1, }; await this.Add(chargeEntity); } public async Task> GetFaildRecord(int maxTryTimes = 3, int maxTop = 100) { var query = this.Query(m => m.Status == ChargeStatus.Faild && m.TryTimes <= maxTryTimes && (DateTime.Now - m.CreateTime).Minutes <= 10); return await query.OrderBy(m => m.Id) .Take(maxTop) .ToListAsync(); } } }