代理商管理
This commit is contained in:
23
Services/Hncore.Pass.Vpn/Domain/AgentPriceEntity.cs
Normal file
23
Services/Hncore.Pass.Vpn/Domain/AgentPriceEntity.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Hncore.Infrastructure.DDD;
|
||||
using System;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Domain
|
||||
{
|
||||
public partial class AgentPriceEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// <summary>
|
||||
public int id { get; set; }
|
||||
|
||||
public int product_id { get; set; }
|
||||
public int package_id { get; set; }
|
||||
|
||||
public int agent_id { get; set; }
|
||||
|
||||
public decimal price { get; set; }
|
||||
|
||||
public decimal refund { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
32
Services/Hncore.Pass.Vpn/Domain/AgentScoreEntity.cs
Normal file
32
Services/Hncore.Pass.Vpn/Domain/AgentScoreEntity.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Hncore.Infrastructure.DDD;
|
||||
using System;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Domain
|
||||
{
|
||||
public partial class AgentScoreEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// <summary>
|
||||
public int id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 代理id
|
||||
/// </summary>
|
||||
public int agent_id { get; set; }
|
||||
public int order_id { get; set; }
|
||||
|
||||
public int score_type { get; set; }
|
||||
|
||||
public decimal score_value { get; set; }
|
||||
|
||||
public string remark { get; set; }
|
||||
|
||||
public string agent_name { get; set; }
|
||||
public string op_user { get; set; }
|
||||
|
||||
public decimal rest_amount1 { get; set; }
|
||||
public decimal rest_amount2 { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
25
Services/Hncore.Pass.Vpn/Domain/AgentUserEntity.cs
Normal file
25
Services/Hncore.Pass.Vpn/Domain/AgentUserEntity.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Hncore.Infrastructure.DDD;
|
||||
using System;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Domain
|
||||
{
|
||||
public partial class AgentUserEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// <summary>
|
||||
public int id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 代理id
|
||||
/// </summary>
|
||||
public string username { get; set; }
|
||||
|
||||
public string realname { get; set; }
|
||||
|
||||
public string phone { get; set; }
|
||||
|
||||
public decimal account { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,28 @@ namespace Hncore.Pass.Vpn.Domain
|
||||
entity.HasKey(p => p.Id);
|
||||
entity.Property(e => e.Id).ValueGeneratedOnAdd();
|
||||
});
|
||||
//代理
|
||||
modelBuilder.Entity<AgentUserEntity>(entity =>
|
||||
{
|
||||
entity.ToTable("agent_user");
|
||||
|
||||
entity.HasKey(p => p.id);
|
||||
entity.Property(e => e.id).ValueGeneratedOnAdd();
|
||||
});
|
||||
modelBuilder.Entity<AgentScoreEntity>(entity =>
|
||||
{
|
||||
entity.ToTable("agent_score");
|
||||
|
||||
entity.HasKey(p => p.id);
|
||||
entity.Property(e => e.id).ValueGeneratedOnAdd();
|
||||
});
|
||||
modelBuilder.Entity<AgentPriceEntity>(entity =>
|
||||
{
|
||||
entity.ToTable("agent_price");
|
||||
|
||||
entity.HasKey(p => p.id);
|
||||
entity.Property(e => e.id).ValueGeneratedOnAdd();
|
||||
});
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
25
Services/Hncore.Pass.Vpn/Service/AgentPriceService.cs
Normal file
25
Services/Hncore.Pass.Vpn/Service/AgentPriceService.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Domain;
|
||||
using Hncore.Pass.Vpn.Request.Product;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using System;
|
||||
using Hncore.Infrastructure.Common;
|
||||
using System.Collections.Generic;
|
||||
using Hncore.Pass.BaseInfo.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
public class AgentPriceService : ServiceBase<AgentPriceEntity>, IFindService
|
||||
{
|
||||
CourseContext m_DbContext;
|
||||
public AgentPriceService(CourseContext dbContext
|
||||
,IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Services/Hncore.Pass.Vpn/Service/AgentScoreService.cs
Normal file
25
Services/Hncore.Pass.Vpn/Service/AgentScoreService.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Domain;
|
||||
using Hncore.Pass.Vpn.Request.Product;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using System;
|
||||
using Hncore.Infrastructure.Common;
|
||||
using System.Collections.Generic;
|
||||
using Hncore.Pass.BaseInfo.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
public class AgentScoreService : ServiceBase<AgentScoreEntity>, IFindService
|
||||
{
|
||||
CourseContext m_DbContext;
|
||||
public AgentScoreService(CourseContext dbContext
|
||||
,IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Services/Hncore.Pass.Vpn/Service/AgentUserService.cs
Normal file
25
Services/Hncore.Pass.Vpn/Service/AgentUserService.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Domain;
|
||||
using Hncore.Pass.Vpn.Request.Product;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using System;
|
||||
using Hncore.Infrastructure.Common;
|
||||
using System.Collections.Generic;
|
||||
using Hncore.Pass.BaseInfo.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
public class AgentUserService : ServiceBase<AgentUserEntity>, IFindService
|
||||
{
|
||||
CourseContext m_DbContext;
|
||||
public AgentUserService(CourseContext dbContext
|
||||
,IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,13 @@ namespace Hncore.Pass.Vpn.Service
|
||||
ProductUserPriceService m_ProductUserPriceService;
|
||||
CouponService m_CouponService;
|
||||
ProductUserPriceService m_UserPriceService;
|
||||
AgentUserService m_AgentUserService;
|
||||
AgentScoreService m_AgentScoreService;
|
||||
AgentPriceService m_AgentPriceService;
|
||||
public ProductOrderService(CourseContext dbContext
|
||||
, AgentUserService _AgentUserService
|
||||
, AgentScoreService _AgentScoreService
|
||||
, AgentPriceService _AgentPriceService
|
||||
, ProductService _ProductService
|
||||
, ProductPackageService _ProductPackageService
|
||||
, UserService _UserService
|
||||
@@ -49,6 +55,9 @@ namespace Hncore.Pass.Vpn.Service
|
||||
, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
m_AgentUserService = _AgentUserService;
|
||||
m_AgentScoreService = _AgentScoreService;
|
||||
m_AgentPriceService = _AgentPriceService;
|
||||
m_ProductService = _ProductService;
|
||||
m_ProductPackageService = _ProductPackageService;
|
||||
m_UserService = _UserService;
|
||||
@@ -515,9 +524,12 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
||||
var isOk = true;
|
||||
var accounts = order.Accounts.Split(',').ToList();
|
||||
accounts = accounts.Distinct().ToList();
|
||||
|
||||
|
||||
if (order.OrderType == OrderType.New || order.OrderType == OrderType.News)
|
||||
{
|
||||
var accountEntitys = new List<ProductAccountEntity>();
|
||||
|
||||
await accounts.ForEachAsync(async account =>
|
||||
{
|
||||
var accountEntity = new ProductAccountEntity()
|
||||
@@ -689,6 +701,32 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(order.agent_id != 0){
|
||||
var agentEntity = await m_AgentUserService.Query(m => m.id == order.agent_id).FirstOrDefaultAsync();
|
||||
var agentPriceEntity = await m_AgentPriceService.Query(m => m.agent_id == order.agent_id && m.package_id == order.PackageId).FirstOrDefaultAsync();
|
||||
var score_money = order.PaymentAmount - order.ConnectCount * order.AccountCount * agentPriceEntity.price;
|
||||
|
||||
var agnetScoreEntity = new AgentScoreEntity()
|
||||
{
|
||||
agent_id = order.agent_id,
|
||||
order_id = order.Id,
|
||||
score_type = 1,
|
||||
score_value = score_money,
|
||||
remark = "客户购买产品" + order.Accounts,
|
||||
agent_name = agentEntity.username,
|
||||
op_user = order.UserName,
|
||||
rest_amount1 = agentEntity.account,
|
||||
rest_amount2 = agentEntity.account + score_money
|
||||
};
|
||||
|
||||
agentEntity.account += score_money;
|
||||
|
||||
await m_AgentScoreService.Add(agnetScoreEntity);
|
||||
await m_AgentUserService.Update(agentEntity);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//public async Task ProcessOrderAccountbak(ProductOrderEntity order)
|
||||
@@ -848,6 +886,7 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
||||
RefundCount = 1,
|
||||
Remark = "退款",
|
||||
RefundReason = reason,
|
||||
agent_id = accountInfo.agent_id
|
||||
};
|
||||
var time = (accountInfo.EndTime - DateTime.Now).Value;
|
||||
order.RefundRestTime = time.ToString(@"d\天hh\时mm\分");
|
||||
@@ -876,6 +915,41 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
||||
accountInfo.Status = AccountStatus.Refund;
|
||||
await m_ProductAccountService.Update(accountInfo);
|
||||
await this.Add(order);
|
||||
|
||||
if(order.agent_id != 0){
|
||||
|
||||
var agentEntity = await m_AgentUserService.Query(m => m.id == order.agent_id).FirstOrDefaultAsync();
|
||||
var agentPriceEntity = await m_AgentPriceService.Query(m => m.agent_id == order.agent_id && m.package_id == order.PackageId).FirstOrDefaultAsync();
|
||||
var agentScoreEntity = await m_AgentScoreService.Query(m => m.agent_id == order.agent_id && m.order_id == lastOrder.Id).FirstOrDefaultAsync();
|
||||
|
||||
var deduct_money = agentScoreEntity.score_value / lastOrder.AccountCount;
|
||||
|
||||
var score_money = deduct_money - refundAmount;
|
||||
if(score_money <= 0){
|
||||
score_money = deduct_money;
|
||||
} else {
|
||||
score_money = refundAmount;
|
||||
}
|
||||
|
||||
var agnetScoreEntity = new AgentScoreEntity()
|
||||
{
|
||||
agent_id = order.agent_id,
|
||||
order_id = order.Id,
|
||||
score_type = 2,
|
||||
score_value = score_money,
|
||||
remark = "客户退款" + account,
|
||||
agent_name = agentEntity.username,
|
||||
op_user = order.UserName,
|
||||
rest_amount1 = agentEntity.account,
|
||||
rest_amount2 = agentEntity.account - score_money
|
||||
};
|
||||
|
||||
agentEntity.account -= score_money;
|
||||
|
||||
await m_AgentScoreService.Add(agnetScoreEntity);
|
||||
await m_AgentUserService.Update(agentEntity);
|
||||
}
|
||||
|
||||
return new ApiResult(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Hncore.Pass.Vpn.Service
|
||||
|
||||
public async Task<List<ProductWithPackageUserPriceResponse>> GetPackageUserPrice(int userId)
|
||||
{
|
||||
var products = await m_ProductService.Query(true).OrderBy(m=>m.Sort).ToListAsync();
|
||||
var products = await m_ProductService.Query( m=>m.OnLine == 1).OrderBy(m=>m.Sort).ToListAsync();
|
||||
|
||||
var packages = m_ProductPackageService.Query(true);
|
||||
var userPrice = this.Query(m => m.UserId == userId);
|
||||
|
||||
Reference in New Issue
Block a user