初始提交
This commit is contained in:
54
Services/Hncore.Pass.Vpn/Controllers/AgentController.cs
Normal file
54
Services/Hncore.Pass.Vpn/Controllers/AgentController.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Request.Product;
|
||||
using Hncore.Pass.Vpn.Response.Product;
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/course/v{version:apiVersion}/agent/[action]")]
|
||||
public class AgentController : HncoreControllerBase
|
||||
{
|
||||
private AgentService m_AgentService;
|
||||
IConfiguration m_Configuration;
|
||||
public AgentController(AgentService _AgentService,IConfiguration configuration)
|
||||
{
|
||||
m_AgentService = _AgentService;
|
||||
m_Configuration = configuration;
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Login([FromBody] AgentLoginRequest request)
|
||||
{
|
||||
return await m_AgentService.Login(request);
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> GetCode([FromQuery] int productId)
|
||||
{
|
||||
var ret = await m_AgentService.GetCode(productId);
|
||||
if (ret.Item1 != null)
|
||||
{
|
||||
var file = $"codes/{Guid.NewGuid().ToString("N")}.jpg";
|
||||
var wwwrootFile = $"wwwroot/{file}";
|
||||
using (FileStream fs = new FileStream(wwwrootFile, FileMode.Create))
|
||||
{
|
||||
await fs.WriteAsync(ret.Item1, 0, ret.Item1.Length);
|
||||
}
|
||||
return Success(new CodeResponse()
|
||||
{
|
||||
Key = ret.Item2,
|
||||
CodeImage = $"{m_Configuration["Service_BaseUrl"]}{file}"
|
||||
});
|
||||
}
|
||||
return Success(new CodeResponse()
|
||||
{
|
||||
Key = "",
|
||||
CodeImage = ""
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
108
Services/Hncore.Pass.Vpn/Controllers/ArticleController.cs
Normal file
108
Services/Hncore.Pass.Vpn/Controllers/ArticleController.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using Hncore.Infrastructure.EntitiesExtension;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Domain;
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/course/v{version:apiVersion}/article/[action]")]
|
||||
public class ArticleController : HncoreControllerBase
|
||||
{
|
||||
private ArticleService m_ArticleService;
|
||||
|
||||
public ArticleController(ArticleService _ArticleService)
|
||||
{
|
||||
m_ArticleService = _ArticleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Post([FromBody]ArticleEntity request)
|
||||
{
|
||||
request.TenantId = this.Request.GetManageUserInfo().TenantId;
|
||||
await m_ArticleService.Add(request);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Put([FromBody]ArticleEntity request)
|
||||
{
|
||||
await m_ArticleService.Update(request);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Delete([FromQuery]int id)
|
||||
{
|
||||
var flag = await m_ArticleService.DeleteById(id);
|
||||
if (flag)
|
||||
return Success();
|
||||
else
|
||||
return Error("删除失败");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 详情
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Get([FromQuery]int id)
|
||||
{
|
||||
var data = await m_ArticleService.GetById(id);
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Page([FromQuery]PageRequestBase request)
|
||||
{
|
||||
Expression<Func<ArticleEntity, bool>> expr = m => 1 == 1;
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m => m.Title.Contains(request.KeyWord)
|
||||
|| m.SubTitle.Contains(request.KeyWord)
|
||||
|| m.Keyword.Contains(request.KeyWord));
|
||||
}
|
||||
var ret = await m_ArticleService.Page(request.PageIndex, request.PageSize, expr,true);
|
||||
var data = ret.ToApiResult();
|
||||
return data;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Audit([FromQuery] int id)
|
||||
{
|
||||
var entity = await m_ArticleService.GetById(id);
|
||||
|
||||
entity.Publish = entity.Publish == 1 ? 0 : 1;
|
||||
|
||||
await m_ArticleService.Update(entity);
|
||||
return Success(entity.Publish);
|
||||
}
|
||||
}
|
||||
}
|
||||
397
Services/Hncore.Pass.Vpn/Controllers/ProductAccountController.cs
Normal file
397
Services/Hncore.Pass.Vpn/Controllers/ProductAccountController.cs
Normal file
@@ -0,0 +1,397 @@
|
||||
using Hncore.Infrastructure.Common;
|
||||
using Hncore.Infrastructure.EntitiesExtension;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Domain;
|
||||
using Hncore.Pass.Vpn.Model;
|
||||
using Hncore.Pass.Vpn.Request.Product;
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/course/v{version:apiVersion}/productaccount/[action]")]
|
||||
public class ProductAccountController : HncoreControllerBase
|
||||
{
|
||||
private ProductAccountService m_AccountService;
|
||||
private UserService m_UserService;
|
||||
private AgentService m_agentService;
|
||||
private ProductPackageService m_PackageService;
|
||||
private ProductService m_ProductService;
|
||||
public ProductAccountController(ProductAccountService _AccountServic
|
||||
, UserService _UserService
|
||||
, AgentService _agentService
|
||||
, ProductPackageService _PackageService
|
||||
, ProductService _ProductService)
|
||||
{
|
||||
m_AccountService = _AccountServic;
|
||||
m_UserService = _UserService;
|
||||
m_agentService = _agentService;
|
||||
m_PackageService = _PackageService;
|
||||
m_ProductService = _ProductService;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Post([FromBody]ProductAccountEntity request)
|
||||
{
|
||||
request.TenantId = this.Request.GetManageUserInfo().TenantId;
|
||||
await m_AccountService.Add(request);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Put([FromBody]ProductAccountEntity request)
|
||||
{
|
||||
await m_AccountService.Update(request);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Delete([FromQuery]int id)
|
||||
{
|
||||
var flag = await m_AccountService.DeleteById(id);
|
||||
if (flag)
|
||||
return Success();
|
||||
else
|
||||
return Error("删除失败");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Deletes([FromBody] List<int> ids)
|
||||
{
|
||||
var data= m_AccountService.Query(m => ids.Contains(m.Id));
|
||||
var flag = await m_AccountService.Deletes(data);
|
||||
if (flag)
|
||||
return Success();
|
||||
else
|
||||
return Error("删除失败");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 详情
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Get([FromQuery]int id)
|
||||
{
|
||||
var data = await m_AccountService.GetById(id);
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Page([FromQuery]AccountPageRequest request)
|
||||
{
|
||||
Expression<Func<ProductAccountEntity, bool>> expr = m => 1 == 1;
|
||||
if (request.UserId > 0)
|
||||
{
|
||||
expr = expr.And(m => m.UserId == request.UserId);
|
||||
}
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m => m.UserCode.Contains(request.KeyWord)
|
||||
|| m.ProductName.Contains(request.KeyWord)
|
||||
|| m.PackageName.Contains(request.KeyWord)
|
||||
|| m.Account.Contains(request.KeyWord));
|
||||
}
|
||||
if (request.ProductId.HasValue)
|
||||
{
|
||||
expr = expr.And(m =>m.ProductId == request.ProductId);
|
||||
}
|
||||
if (request.PackageId.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.PackageId == request.PackageId);
|
||||
}
|
||||
if (request.AccountTypes!=null&&request.AccountTypes.Count>0)
|
||||
{
|
||||
expr = expr.And(m => request.AccountTypes.Contains(m.AccountType));
|
||||
}
|
||||
if (request.BTime.HasValue && request.ETime.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.EndTime>=request.BTime&&m.EndTime<=request.ETime);
|
||||
}
|
||||
if (request.ExpirdDay > -1)
|
||||
{
|
||||
if (request.ExpirdDay == 0)
|
||||
{
|
||||
expr = expr.And(m => m.EndTime.Value < DateTime.Now);
|
||||
}
|
||||
else
|
||||
{
|
||||
var startTime = DateTime.Now.Begin().AddDays(request.ExpirdDay);
|
||||
startTime = startTime < DateTime.Now ? DateTime.Now : startTime;
|
||||
var EndTime = DateTime.Now.End().AddDays(request.ExpirdDay);
|
||||
expr = expr.And(m => m.EndTime >= startTime && m.EndTime <= EndTime);
|
||||
}
|
||||
// expr = expr.And(m => Math.Ceiling((m.EndTime - DateTime.Now).Value.TotalDays) == request.ExpirdDay);
|
||||
}
|
||||
var ret = await m_AccountService.PageDesc(request.PageIndex, request.PageSize, expr,true,m=>m.Id);
|
||||
var data = ret.ToApiResult();
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Search([FromQuery]AccountPageRequest request)
|
||||
{
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
Expression<Func<ProductAccountEntity, bool>> expr = m => m.Account== request.KeyWord||m.UserCode== request.KeyWord;
|
||||
var ret = await m_AccountService.PageDesc(request.PageIndex, request.PageSize, expr, true, m => m.Id);
|
||||
var data = ret.ToApiResult();
|
||||
return data;
|
||||
}
|
||||
return Error("请输入关键字");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 迁移
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> BindUser([FromBody]BindUserRequest request)
|
||||
{
|
||||
var entityList = await m_AccountService.Query(m => request.AccountIds.Contains(m.Id)).ToListAsync();
|
||||
if (entityList == null|| entityList.Count==0)
|
||||
return Error("没有选择账号");
|
||||
var userEntity= await m_UserService.GetById(request.UserId);
|
||||
if (userEntity == null)
|
||||
return Error("会员不存在");
|
||||
|
||||
entityList.ForEach(entity =>
|
||||
{
|
||||
entity.UserId = request.UserId;
|
||||
entity.UserCode = userEntity.LoginCode;
|
||||
entity.UserPhone = userEntity.Phone;
|
||||
});
|
||||
|
||||
await m_AccountService.Update(entityList);
|
||||
return Success();
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> GetOrginAccount([FromQuery]string accounts)
|
||||
{
|
||||
var accountList = await m_AccountService.GetAccounts(string.Join(",", accounts));
|
||||
var originModel = await m_agentService.GetOriginAccounts(accountList);
|
||||
return Success(originModel);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> UpdateOrginPwd([FromQuery]int productId, string account, string pwd)
|
||||
{
|
||||
var flag = await m_agentService.UpdateAccountPwd(productId, account, pwd);
|
||||
if (flag)
|
||||
return Success();
|
||||
else
|
||||
return Error("修改密码失败");
|
||||
}
|
||||
[HttpGet, UserAuth]
|
||||
public async Task<ApiResult> ExistAccount([FromQuery]int productId, [FromQuery]string accounts)
|
||||
{
|
||||
var flag =await m_AccountService.CheckAccountExist(productId, accounts.Split(',').ToList());
|
||||
if (flag)
|
||||
{
|
||||
return Error("账号已经存在");
|
||||
}
|
||||
return Success();
|
||||
}
|
||||
|
||||
[HttpPost, UserAuth]
|
||||
public async Task<ApiResult> CreateTestAccount([FromBody]CreateTestAccountRequest request)
|
||||
{
|
||||
if (request.Account.NotHas() || request.Pwd.NotHas())
|
||||
{
|
||||
return Error("账户和密码不能为空");
|
||||
}
|
||||
var userId = this.Request.GetUserInfo().UserId;
|
||||
var packageEntity = await m_PackageService.GetById(request.PackageId);
|
||||
if (packageEntity==null|| packageEntity.Status==0)
|
||||
{
|
||||
return Error("套餐不存在");
|
||||
}
|
||||
if (packageEntity.IsTest == 0)
|
||||
{
|
||||
return Error("非测试套餐");
|
||||
}
|
||||
|
||||
var flag = await m_AccountService.CheckAccountExist(packageEntity.ProductId, new List<string> { request.Account });
|
||||
if (flag)
|
||||
{
|
||||
return Error("账号已经存在");
|
||||
}
|
||||
var restTimes = await m_AccountService.GetRestTestCount(userId);
|
||||
|
||||
if (restTimes <= 0)
|
||||
{
|
||||
return Error("没有测试次数了");
|
||||
}
|
||||
|
||||
|
||||
var ret= await m_agentService.NewAccount(0, request.PackageId, request.Account, request.Pwd, accountType: 0);
|
||||
|
||||
if (ret.Code == ResultCode.C_SUCCESS)
|
||||
{
|
||||
var ProductEntity = await m_ProductService.GetById(packageEntity.ProductId);
|
||||
var accountEntity = new ProductAccountEntity()
|
||||
{
|
||||
Account = request.Account,
|
||||
AccountType = (int)AccountType.Test,
|
||||
ConnectCount = 1,
|
||||
StartTime = DateTime.Now,
|
||||
EndTime = DateTime.Now.AddHours(packageEntity.DayCount),
|
||||
PackageId = packageEntity.Id,
|
||||
PackageName = packageEntity.Name,
|
||||
ProductId = packageEntity.ProductId,
|
||||
ProductName = ProductEntity.Name,
|
||||
Pwd = request.Pwd,
|
||||
ChargeStatus = AccountChargeStatus.Normal,
|
||||
UserId = this.Request.GetUserInfo().UserId,
|
||||
UserCode = this.Request.GetUserInfo().LoginName,
|
||||
};
|
||||
await m_AccountService.Add(accountEntity);
|
||||
|
||||
var userEntity = await m_UserService.GetById(userId);
|
||||
userEntity.UseTestCount++;
|
||||
await m_UserService.Update(userEntity);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否在线
|
||||
/// </summary>
|
||||
/// <param name="productId"></param>
|
||||
/// <param name="account"></param>
|
||||
/// <returns></returns>
|
||||
// [UserAuth]
|
||||
[AllowAnonymous]
|
||||
public virtual async Task<ApiResult<List<OriginAccountOnlineModel>>> OnLine(int productId, string account)
|
||||
{
|
||||
return await m_agentService.OnLine(productId, account);
|
||||
}
|
||||
/// <summary>
|
||||
/// 踢号
|
||||
/// </summary>
|
||||
/// <param name="productId"></param>
|
||||
/// <param name="account"></param>
|
||||
/// <returns></returns>
|
||||
// [UserAuth]
|
||||
[AllowAnonymous]
|
||||
public virtual async Task<ApiResult> KillOut(int productId, string id)
|
||||
{
|
||||
return Success(await m_agentService.KillOut(productId, id));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Export([FromQuery]AccountPageRequest request)
|
||||
{
|
||||
|
||||
Expression<Func<ProductAccountEntity, bool>> expr = m => 1 == 1;
|
||||
if (request.UserId > 0)
|
||||
{
|
||||
expr = expr.And(m => m.UserId == request.UserId);
|
||||
}
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m => m.Account.Contains(request.KeyWord));
|
||||
}
|
||||
if (request.ProductId.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.ProductId == request.ProductId);
|
||||
}
|
||||
if (request.PackageId.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.PackageId == request.PackageId);
|
||||
}
|
||||
if (request.AccountTypes != null && request.AccountTypes.Count > 0)
|
||||
{
|
||||
expr = expr.And(m => request.AccountTypes.Contains(m.AccountType));
|
||||
}
|
||||
if (request.ExpirdDay > -1)
|
||||
{
|
||||
if (request.ExpirdDay == 0)
|
||||
{
|
||||
expr = expr.And(m => m.EndTime.Value < DateTime.Now);
|
||||
}
|
||||
else
|
||||
{
|
||||
var startTime = DateTime.Now.Begin().AddDays(request.ExpirdDay);
|
||||
startTime = startTime < DateTime.Now ? DateTime.Now : startTime;
|
||||
var EndTime = DateTime.Now.End().AddDays(request.ExpirdDay);
|
||||
expr = expr.And(m => m.EndTime >= startTime && m.EndTime <= EndTime);
|
||||
}
|
||||
// expr = expr.And(m => Math.Ceiling((m.EndTime - DateTime.Now).Value.TotalDays) == request.ExpirdDay);
|
||||
}
|
||||
var ret = await m_AccountService.PageDesc(request.PageIndex,10000, expr, true, m => m.Id);
|
||||
|
||||
var data = new ExcelData<ProductAccountEntity>
|
||||
{
|
||||
SheetName = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
Data = ret.List
|
||||
};
|
||||
|
||||
var title = new List<ExcelTitle>(){
|
||||
new ExcelTitle { Property = "UserCode", Title = "用户" },
|
||||
new ExcelTitle { Property = "ProductName", Title = "产品" },
|
||||
new ExcelTitle { Property = "PackageName", Title = "套餐" },
|
||||
new ExcelTitle { Property = "Account", Title = "账号" },
|
||||
new ExcelTitle { Property = "AccountType", Title = "类型" , Format=(val)=>((AccountType)val).GetEnumDisplayName() },
|
||||
new ExcelTitle { Property = "ConnectCount", Title = "连接数"},
|
||||
new ExcelTitle { Property = "StartTime", Title = "开通时间" , Format=(val)=>((DateTime) val).ToString("yyyy-MM-dd hh:mm:ss")},
|
||||
new ExcelTitle { Property = "EndTime", Title = "到期时间" ,Format=(val)=>((DateTime) val).ToString("yyyy-MM-dd hh:mm:ss")},
|
||||
new ExcelTitle { Property = "RestTime", Title = "剩余时间" },
|
||||
};
|
||||
var fileBytes = ExcelHelper.ExportListToExcel(data, title);
|
||||
|
||||
var fileName = $"{DateTime.Now.ToString("yyyyMMdd")}账号明细.xlsx";
|
||||
Response.Headers.Add("X-Suggested-Filename", fileName.UrlEncode());
|
||||
return File(fileBytes, "application/octet-stream", fileName);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
277
Services/Hncore.Pass.Vpn/Controllers/ProductController.cs
Normal file
277
Services/Hncore.Pass.Vpn/Controllers/ProductController.cs
Normal file
@@ -0,0 +1,277 @@
|
||||
using Hncore.Infrastructure.EntitiesExtension;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Domain;
|
||||
using Hncore.Pass.Vpn.Request.Product;
|
||||
using Hncore.Pass.Vpn.Response.Product;
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/course/v{version:apiVersion}/product/[action]")]
|
||||
public class ProductController : HncoreControllerBase
|
||||
{
|
||||
private ProductService m_ProductService;
|
||||
private ProductPackageService m_ProductPackageService;
|
||||
private ProductUserPriceService m_ProductUserPriceService;
|
||||
public ProductController(ProductService _ProductServic, ProductPackageService _ProductPackageService, ProductUserPriceService m_ProductUserPriceService)
|
||||
{
|
||||
m_ProductService = _ProductServic;
|
||||
m_ProductPackageService = _ProductPackageService;
|
||||
this.m_ProductUserPriceService = m_ProductUserPriceService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Post([FromBody]ProductEntity request)
|
||||
{
|
||||
request.TenantId = this.Request.GetManageUserInfo().TenantId;
|
||||
await m_ProductService.Add(request);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Put([FromBody]ProductEntity request)
|
||||
{
|
||||
var entity = await m_ProductService.GetById(request.Id);
|
||||
entity.Name = request.Name;
|
||||
entity.Profile = request.Profile;
|
||||
entity.Image = request.Image;
|
||||
entity.RefundDayPrice = request.RefundDayPrice;
|
||||
entity.DayLimitPrice = request.DayLimitPrice;
|
||||
await m_ProductService.Update(entity);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> PutConfig([FromBody]ProductEntity request)
|
||||
{
|
||||
var entity = await m_ProductService.GetById(request.Id);
|
||||
entity.Account = request.Account;
|
||||
entity.Pwd = request.Pwd;
|
||||
entity.BaseUrl = request.BaseUrl;
|
||||
entity.Token = "";
|
||||
await m_ProductService.Update(entity);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> PutSoft([FromBody]ProductEntity request)
|
||||
{
|
||||
var entity = await m_ProductService.GetById(request.Id);
|
||||
entity.PcClientDownloadUrl = request.PcClientDownloadUrl;
|
||||
entity.SimulatorDownloadUrl = request.SimulatorDownloadUrl;
|
||||
entity.DroidDownloadUrl = request.DroidDownloadUrl;
|
||||
entity.IosDownloadUrl = request.IosDownloadUrl;
|
||||
await m_ProductService.Update(entity);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Delete([FromQuery]int id)
|
||||
{
|
||||
var flag = await m_ProductService.DeleteById(id);
|
||||
if (flag)
|
||||
return Success();
|
||||
else
|
||||
return Error("删除失败");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 详情
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Get([FromQuery]int id)
|
||||
{
|
||||
var data = await m_ProductService.GetById(id);
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Page([FromQuery]PageRequestBase request)
|
||||
{
|
||||
Expression<Func<ProductEntity, bool>> expr = m => 1 == 1;
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m => m.Name.Contains(request.KeyWord));
|
||||
}
|
||||
var ret = await m_ProductService.Page(request.PageIndex, request.PageSize, expr,true);
|
||||
var data = ret.ToApiResult();
|
||||
return data;
|
||||
}
|
||||
|
||||
[HttpGet,AllowAnonymous]
|
||||
public async Task<ApiResult> OpenPage([FromQuery]PageRequestBase request)
|
||||
{
|
||||
Expression<Func<ProductEntity, bool>> expr = m => 1 == 1;
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m => m.Name.Contains(request.KeyWord));
|
||||
}
|
||||
var ret = await m_ProductService.Page(request.PageIndex, request.PageSize, expr, true);
|
||||
var data = ret.ToApiResult();
|
||||
return data;
|
||||
}
|
||||
|
||||
[HttpGet, AllowAnonymous]
|
||||
public async Task<ApiResult> ProductWithPackage()
|
||||
{
|
||||
var respList = await m_ProductService.ProductWithPackage();
|
||||
return Success(respList);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> ProductUserPrice(int userId)
|
||||
{
|
||||
var ret = await this.m_ProductUserPriceService.GetPackageUserPrice(userId);
|
||||
return Success(ret);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> SetProductLine([FromQuery]int id)
|
||||
{
|
||||
var productEntity = await m_ProductService.GetById(id);
|
||||
if (productEntity == null)
|
||||
{
|
||||
return Error("产品不存在");
|
||||
}
|
||||
productEntity.Status = productEntity.OnLine == 0 ? 1 : 0;
|
||||
await m_ProductService.Update(productEntity);
|
||||
|
||||
return Success(productEntity.Status);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> SetPackageLine([FromQuery]int id)
|
||||
{
|
||||
var packageEntity = await m_ProductPackageService.GetById(id);
|
||||
if (packageEntity == null)
|
||||
{
|
||||
return Error("套餐不存在");
|
||||
}
|
||||
packageEntity.Status = packageEntity.Status == 0 ? 1 : 0;
|
||||
await m_ProductPackageService.Update(packageEntity);
|
||||
|
||||
return Success(packageEntity.Status);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> SetUserPriceStatus([FromQuery]int id)
|
||||
{
|
||||
var userPriceEntity = await m_ProductUserPriceService.GetById(id);
|
||||
if (userPriceEntity == null)
|
||||
{
|
||||
return Error("请设置会员价");
|
||||
}
|
||||
userPriceEntity.Status = userPriceEntity.Status == 0 ? 1 : 0;
|
||||
await m_ProductUserPriceService.Update(userPriceEntity);
|
||||
return Success(userPriceEntity.Status);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> PutPackage([FromBody]ProductPackageEntity request)
|
||||
{
|
||||
var packageEntity = await m_ProductPackageService.GetById(request.Id);
|
||||
if (packageEntity == null)
|
||||
{
|
||||
return Error("套餐不存在");
|
||||
}
|
||||
packageEntity.LinePrice = request.LinePrice;
|
||||
packageEntity.MinPrice = request.MinPrice;
|
||||
packageEntity.Name = request.Name;
|
||||
packageEntity.Price = request.Price;
|
||||
packageEntity.Profile = request.Profile;
|
||||
packageEntity.Title = request.Title;
|
||||
await m_ProductPackageService.Update(packageEntity);
|
||||
return Success(packageEntity);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> PutUserPrice([FromBody]PutUserPriceRequest request)
|
||||
{
|
||||
var userPriceEntity = await m_ProductUserPriceService.Query(m => m.PackageId == request.PackageId && m.UserId == request.UserId).FirstOrDefaultAsync();
|
||||
|
||||
var price = request.UserPrice;
|
||||
var packageEntity =await m_ProductPackageService.GetById(request.PackageId);
|
||||
// var product = await m_ProductService.GetById(packageEntity.ProductId);
|
||||
if (request.UserPrice < packageEntity.MinPrice && packageEntity.MinPrice > 0)
|
||||
{
|
||||
return Error($"不能低于最低限额[{ packageEntity.MinPrice}]");
|
||||
}
|
||||
|
||||
var productEntity = await m_ProductService.GetById(packageEntity.ProductId);
|
||||
|
||||
if (productEntity.DayLimitPrice>0&&request.RefundDayPrice < productEntity.DayLimitPrice)
|
||||
{
|
||||
return Error($"退款单价不能低于[{ productEntity.DayLimitPrice}]");
|
||||
}
|
||||
|
||||
//toto
|
||||
if (userPriceEntity == null)
|
||||
{
|
||||
userPriceEntity =new ProductUserPriceEntity()
|
||||
{
|
||||
PackageId = request.PackageId,
|
||||
ProductId = request.ProductId,
|
||||
UserId = request.UserId,
|
||||
UserPrice = request.UserPrice,
|
||||
Status = 1,
|
||||
DeleteTag = 0,
|
||||
Remark=request.Remark,
|
||||
RefundDayPrice= request.RefundDayPrice
|
||||
};
|
||||
await m_ProductUserPriceService.Add(userPriceEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
userPriceEntity.UserPrice = request.UserPrice;
|
||||
userPriceEntity.RefundDayPrice = request.RefundDayPrice;
|
||||
userPriceEntity.Remark = request.Remark;
|
||||
await m_ProductUserPriceService.Update(userPriceEntity);
|
||||
}
|
||||
return Success(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
752
Services/Hncore.Pass.Vpn/Controllers/ProductOrderController.cs
Normal file
752
Services/Hncore.Pass.Vpn/Controllers/ProductOrderController.cs
Normal file
@@ -0,0 +1,752 @@
|
||||
using Hncore.Infrastructure.Common;
|
||||
using Hncore.Infrastructure.EntitiesExtension;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.BaseInfo.Service;
|
||||
using Hncore.Pass.Vpn.Domain;
|
||||
using Hncore.Pass.Vpn.Model;
|
||||
using Hncore.Pass.Vpn.Request.Product;
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using BaseUserService = Hncore.Pass.BaseInfo.Service.UserService;
|
||||
namespace Hncore.Pass.Vpn.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/course/v{version:apiVersion}/order/[action]")]
|
||||
public class ProductOrderController : HncoreControllerBase
|
||||
{
|
||||
private ProductService m_ProductService;
|
||||
private ProductOrderService m_ProductOrderService;
|
||||
private BaseUserService m_BaseUserService;
|
||||
|
||||
private ManageService m_ManageService;
|
||||
public ProductOrderController(ProductService _ProductServic
|
||||
, ProductOrderService _ProductOrderService
|
||||
, BaseUserService _BaseUserService
|
||||
, ManageService _ManageService)
|
||||
{
|
||||
m_ProductService = _ProductServic;
|
||||
m_ProductOrderService = _ProductOrderService;
|
||||
m_BaseUserService=_BaseUserService;
|
||||
m_ManageService = _ManageService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 详情
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Get([FromQuery]int id)
|
||||
{
|
||||
var data = await m_ProductService.GetById(id);
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Page([FromQuery]OrderQueryRequest request)
|
||||
{
|
||||
Expression<Func<ProductOrderEntity, bool>> expr = m =>( m.OrderState == OrderStatus.PayOk || m.OrderState == OrderStatus.Complete) && m.OrderType != OrderType.Refund;
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m =>
|
||||
m.ProductName.Contains(request.KeyWord)
|
||||
||m.Accounts.Contains(request.KeyWord)
|
||||
||m.OrderNo.Contains(request.KeyWord)
|
||||
||m.UserName.Contains(request.KeyWord)
|
||||
||m.PackageName.Contains(request.KeyWord));
|
||||
}
|
||||
if (request.ProductId.HasValue)
|
||||
{
|
||||
expr = expr.And(m =>m.ProductId==request.ProductId);
|
||||
}
|
||||
if (request.PackageId.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.PackageId == request.PackageId);
|
||||
}
|
||||
if (request.OrderTypes != null && request.OrderTypes.Count > 0)
|
||||
{
|
||||
expr = expr.And(m => request.OrderTypes.Contains((int)m.OrderType));
|
||||
}
|
||||
if (request.BTime.HasValue && request.ETime.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.CreateTime >= request.BTime && m.CreateTime <= request.ETime);
|
||||
}
|
||||
var ret = await m_ProductOrderService.PageDesc(request.PageIndex, request.PageSize, expr, true,m=>m.Id);
|
||||
var data = ret.ToApiResult();
|
||||
return data;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ApiResult Statistics([FromQuery]OrderQueryRequest request)
|
||||
{
|
||||
var ret = m_ProductOrderService.Statistics(request.BTime, request.ETime);
|
||||
return Success(ret);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public ApiResult SellerStatistics([FromQuery]OrderQueryRequest request)
|
||||
{
|
||||
var ret = m_ProductOrderService.SellerStatistics(request.BTime, request.ETime);
|
||||
return Success(ret);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> UserConsumeStatistics([FromQuery]UserConsumeRequest request)
|
||||
{
|
||||
|
||||
var loginInfo = this.Request.GetManageUserInfo();
|
||||
int id = loginInfo.OperaterId;
|
||||
var managerInfo =await m_ManageService.GetById(loginInfo.OperaterId);
|
||||
if (managerInfo.IsRoot == 1) id = 0;
|
||||
var ret = m_ProductOrderService.UserConsumeStatistics(request.PageIndex, request.PageSize, request.KeyWord, request.bTime1, request.eTime1, request.bTime2, request.eTime2, id, request.SortLable, request.SortOrder,request.Profile);
|
||||
return ret.ToApiResult();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> RefundOrders([FromQuery]OrderQueryRequest request)
|
||||
{
|
||||
Expression<Func<ProductOrderEntity, bool>> expr = m => m.OrderType == OrderType.Refund;
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m => m.Accounts.Contains(request.KeyWord)
|
||||
|| m.OrderNo.Contains(request.KeyWord)
|
||||
|| m.UserName.Contains(request.KeyWord)
|
||||
|| m.PackageName.Contains(request.KeyWord));
|
||||
}
|
||||
if (request.ProductId.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.ProductId == request.ProductId);
|
||||
}
|
||||
if (request.OrderTypes != null && request.OrderTypes.Count > 0)
|
||||
{
|
||||
expr = expr.And(m => request.OrderTypes.Contains((int)m.OrderType));
|
||||
}
|
||||
if (request.BTime.HasValue && request.ETime.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.CreateTime >= request.BTime && m.CreateTime <= request.ETime);
|
||||
}
|
||||
var ret = await m_ProductOrderService.PageDesc(request.PageIndex, request.PageSize, expr, true,m=>m.Id);
|
||||
var data = ret.ToApiResult();
|
||||
return data;
|
||||
}
|
||||
|
||||
[HttpGet,AllowAnonymous]
|
||||
public async Task<ApiResult> OpenRefundOrders([FromQuery]RefundOrderQueryRequest request)
|
||||
{
|
||||
Expression<Func<ProductOrderEntity, bool>> expr = m => m.OrderType == OrderType.Refund;
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m => m.Accounts.Contains(request.KeyWord)
|
||||
|| m.OrderNo.Contains(request.KeyWord)
|
||||
|| m.UserName.Contains(request.KeyWord)
|
||||
|| m.PackageName.Contains(request.KeyWord));
|
||||
}
|
||||
if (request.ProductIds!=null&& request.ProductIds.Count>0)
|
||||
{
|
||||
expr = expr.And(m => request.ProductIds.Contains(m.ProductId));
|
||||
}
|
||||
|
||||
if (request.BTime.HasValue && request.ETime.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.CreateTime > request.BTime && m.CreateTime < request.ETime);
|
||||
}
|
||||
|
||||
var ret = await m_ProductOrderService.PageDesc(request.PageIndex, request.PageSize, expr, true, m => m.Id);
|
||||
var data = ret.ToApiResult();
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[UserAuth]
|
||||
public async Task<ApiResult> CreateOrder(CreateOrderRequest request)
|
||||
{
|
||||
var userInfo = this.Request.GetUserInfo();
|
||||
var ret = await m_ProductOrderService.CreateOrder(request, userInfo.UserId);
|
||||
if (ret.Code != ResultCode.C_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
return Success();
|
||||
}
|
||||
|
||||
[UserAuth]
|
||||
public async Task<ApiResult> Refund(string account)
|
||||
{
|
||||
var userInfo = this.Request.GetUserInfo();
|
||||
return await m_ProductOrderService.Refund(userInfo.UserId, account);
|
||||
}
|
||||
|
||||
[UserAuth]
|
||||
public async Task<ApiResult> CaclRefund(string account)
|
||||
{
|
||||
var userInfo = this.Request.GetUserInfo();
|
||||
return await m_ProductOrderService.CaclRefund(userInfo.UserId, account);
|
||||
}
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// 支付(微信公众号、小程序支付,创建流水记录。)
|
||||
///// </summary>
|
||||
///// <param name="param"></param>
|
||||
///// <returns></returns>
|
||||
//[HttpPost, UserAuth]
|
||||
//public async Task<ApiResult> CreatePayOrder([FromBody] CreateOrderRequest request)
|
||||
//{
|
||||
|
||||
// var userInfo = this.Request.GetUserInfo();
|
||||
// var ret = await m_ProductOrderService.CreateOrder(request, userInfo.UserId);
|
||||
// if (ret.Code != ResultCode.C_SUCCESS)
|
||||
// {
|
||||
// return ret;
|
||||
// }
|
||||
// var req = new PayRequest()
|
||||
// {
|
||||
// OrderNO = ret.Data.OrderNo,
|
||||
// PayEnvironment = request.PayEnvironment,
|
||||
// PaymentType = request.PaymentType
|
||||
// };
|
||||
|
||||
// return await CreatePaymentOrder(req, ret.Data, userInfo);
|
||||
//}
|
||||
|
||||
//[UserAuth]
|
||||
//public async Task<ApiResult> Pay(PayRequest request)
|
||||
//{
|
||||
// var order = await m_CourseOrderService.GetByOrderNo(request.OrderNO);
|
||||
// var userInfo = this.Request.GetUserInfo();
|
||||
// return await CreatePaymentOrder(request, order, userInfo);
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 支付部分
|
||||
/// </summary>
|
||||
/// <param name="param"></param>
|
||||
/// <param name="UserInfo"></param>
|
||||
/// <param name="OpenId"></param>
|
||||
/// <returns></returns>
|
||||
//private async Task<ApiResult> CreatePaymentOrder(PayRequest request, ProductOrderEntity orderData, AppUserInfo UserInfo)
|
||||
//{
|
||||
// string callBackUrl = $"{m_Configuration["Service_BaseUrl"]}/api/courseOrder/v1/WxOrderCallBack?orderId={orderData.OrderNo}&payType={(int)request.PaymentType}";
|
||||
// string attach = orderData.ToJson();
|
||||
// decimal payAmount = orderData.OrderAmount * 100.0M;
|
||||
// string orderDesc = "购买课程支付";
|
||||
// var resp = new CreatePaymentOrderResponse<CourseOrderEntity>()
|
||||
// {
|
||||
// OrderInfo = orderData
|
||||
// };
|
||||
// var weChatPayRequest = new WechatJsPayCreateOrderRequest()
|
||||
// {
|
||||
// Attach = attach,
|
||||
// Body = orderDesc,
|
||||
// CallbackUrl = callBackUrl + "&paymentType=" + (int)Payment.Enum.PaymentType.OnlinePayWechart,
|
||||
// OrderId = orderData.OrderNo,
|
||||
// OrderType = orderData.OrderType,
|
||||
// TenantId = orderData.TenantId,
|
||||
// PayEnvironment = request.PayEnvironment,
|
||||
// PaymentType = request.PaymentType,
|
||||
// TotalFee = Convert.ToInt32(payAmount),
|
||||
// UserOpenId = UserInfo.OpenId,
|
||||
// AppId = UserInfo.AppId,
|
||||
// StoreId = UserInfo.StoreId
|
||||
// };
|
||||
|
||||
// var wechatJsPayResp = await m_ServiceHttpClient.WechatJsPayCreateOrder(weChatPayRequest);
|
||||
// if (wechatJsPayResp.Code == ResultCode.C_SUCCESS)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// //{"tradeNO":"2019102522001433001406080254","status":"0"}
|
||||
// var payOrderInfo = wechatJsPayResp.Data.ToString().FromJsonToOrDefault<WxPayOrderInfo>();
|
||||
|
||||
// if (payOrderInfo != null && payOrderInfo.package.Has())
|
||||
// {
|
||||
// string[] tmp2param = payOrderInfo.package.Split('=');
|
||||
// if (tmp2param != null && tmp2param.Length == 2)
|
||||
// {
|
||||
// orderData.TradeNo = tmp2param[1];
|
||||
// await m_CourseOrderService.Update(orderData);
|
||||
// }
|
||||
// }
|
||||
// resp.PayInfo = wechatJsPayResp.Data.ToString();
|
||||
// return Success(resp);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// LogHelper.Error("课程支付获取微信支付订单信息转换出错:" + ex.Message, ex);
|
||||
// return new ApiResult(ResultCode.C_UNKNOWN_ERROR, "交易失败");
|
||||
// }
|
||||
// }
|
||||
// return new ApiResult(ResultCode.C_UNKNOWN_ERROR, wechatJsPayResp.Message);
|
||||
//}
|
||||
|
||||
//[InternalApiAuth]
|
||||
//public async Task<string> WxOrderCallBack([FromQuery]string orderId = "", [FromQuery] int paymentType = 0)
|
||||
//{
|
||||
// if (string.IsNullOrWhiteSpace(orderId) || paymentType <= 0)
|
||||
// {
|
||||
// return "faild";
|
||||
// }
|
||||
// var order = await m_CourseOrderService.GetByOrderNo(orderId);
|
||||
// if (order == null)
|
||||
// return "faild";
|
||||
|
||||
// order.OrderState = OrderStatus.PayOk;
|
||||
// order.PayType = paymentType;
|
||||
// await m_CourseOrderService.Update(order);
|
||||
// return "faild";
|
||||
//}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Export([FromQuery]OrderQueryRequest request)
|
||||
{
|
||||
Expression<Func<ProductOrderEntity, bool>> expr = m => (m.OrderState == OrderStatus.PayOk || m.OrderState == OrderStatus.Complete) && m.OrderType != OrderType.Refund;
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m =>
|
||||
m.OrderName.Contains(request.KeyWord)
|
||||
|| m.OrderNo.Contains(request.KeyWord)
|
||||
|| m.UserName.Contains(request.KeyWord)
|
||||
|| m.PackageName.Contains(request.KeyWord));
|
||||
}
|
||||
if (request.OrderTypes != null && request.OrderTypes.Count > 0)
|
||||
{
|
||||
expr = expr.And(m => request.OrderTypes.Contains((int)m.OrderType));
|
||||
}
|
||||
if (request.BTime.HasValue && request.ETime.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.CreateTime >= request.BTime && m.CreateTime <= request.ETime);
|
||||
}
|
||||
var ret = await m_ProductOrderService.PageDesc(request.PageIndex, 10000, expr, true,m=>m.Id);
|
||||
|
||||
|
||||
var data = new ExcelData<ProductOrderEntity>
|
||||
{
|
||||
SheetName = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
Data = ret.List
|
||||
};
|
||||
|
||||
var title = new List<ExcelTitle>(){
|
||||
new ExcelTitle { Property = "CreateTime", Title = "创建日期" , Format=(val)=>((DateTime) val).ToString("yyyy-MM-dd hh:mm:ss") },
|
||||
new ExcelTitle { Property = "OrderNo", Title = "订单号" },
|
||||
new ExcelTitle { Property = "OrderType", Title = "类型", Format=(val)=>((OrderType)val).GetEnumDisplayName() },
|
||||
new ExcelTitle { Property = "UserName", Title = "用户" },
|
||||
new ExcelTitle { Property = "ProductName", Title = "产品" },
|
||||
new ExcelTitle { Property = "PackageName", Title = "套餐" },
|
||||
new ExcelTitle { Property = "DayPrice", Title = "单价" },
|
||||
new ExcelTitle { Property = "ConnectCount", Title = "连接数",Expr=(p)=>((ProductOrderEntity)p).ConnectCount*((ProductOrderEntity)p).AccountCount},
|
||||
new ExcelTitle { Property = "Accounts", Title = "账号" },
|
||||
new ExcelTitle { Property = "OrderAmount", Title = "订单金额" },
|
||||
new ExcelTitle { Property = "CouponAmount", Title = "优惠金额" },
|
||||
new ExcelTitle { Property = "AccountPayAmount", Title = "余额支付" },
|
||||
new ExcelTitle { Property = "OtherPayAmount", Title = "在线支付" },
|
||||
new ExcelTitle { Property = "PaymentAmount", Title = "实付" },
|
||||
new ExcelTitle { Property = "PayType", Title = "付款方式" , Format=(val)=>((PayType)val).GetEnumDisplayName() },
|
||||
new ExcelTitle { Property = "TradeNo", Title = "支付流水号" },
|
||||
};
|
||||
var fileBytes = ExcelHelper.ExportListToExcel(data, title);
|
||||
|
||||
var fileName = $"{DateTime.Now.ToString("yyyyMMdd")}订单明细.xlsx";
|
||||
Response.Headers.Add("X-Suggested-Filename", fileName.UrlEncode());
|
||||
return File(fileBytes, "application/octet-stream", fileName);
|
||||
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> ExportRefundOrders([FromQuery]OrderQueryRequest request)
|
||||
{
|
||||
Expression<Func<ProductOrderEntity, bool>> expr = m => m.OrderType == OrderType.Refund;
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m =>
|
||||
m.OrderName.Contains(request.KeyWord)
|
||||
|| m.OrderNo.Contains(request.KeyWord)
|
||||
|| m.UserName.Contains(request.KeyWord)
|
||||
|| m.PackageName.Contains(request.KeyWord));
|
||||
}
|
||||
if (request.OrderTypes != null && request.OrderTypes.Count > 0)
|
||||
{
|
||||
expr = expr.And(m => request.OrderTypes.Contains((int)m.OrderType));
|
||||
}
|
||||
if (request.BTime.HasValue && request.ETime.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.CreateTime >= request.BTime && m.CreateTime <= request.ETime);
|
||||
}
|
||||
var ret = await m_ProductOrderService.Page(request.PageIndex, 10000, expr, true);
|
||||
|
||||
|
||||
var data = new ExcelData<ProductOrderEntity>
|
||||
{
|
||||
SheetName = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
Data = ret.List
|
||||
};
|
||||
|
||||
|
||||
Func<ProductOrderEntity, object> refundTypeFormat = (order) =>
|
||||
{
|
||||
switch (order.OrderState)
|
||||
{
|
||||
case OrderStatus.RequestRefund:
|
||||
return "未自动退款";
|
||||
case OrderStatus.UserRefundOver:
|
||||
return "已人工处理";
|
||||
case OrderStatus.AutoRefundOver:
|
||||
return "已自动退款";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
var title = new List<ExcelTitle>(){
|
||||
new ExcelTitle { Property = "CreateTime", Title = "创建日期" ,Format=(val)=>((DateTime) val).ToString("yyyy-MM-dd hh:mm:ss") },
|
||||
//new ExcelTitle { Property = "OrderNo", Title = "订单号" },
|
||||
// new ExcelTitle { Property = "OrderType", Title = "类型", Format=(val)=>((OrderType)val).GetEnumDisplayName() },
|
||||
// new ExcelTitle { Property = "UserName", Title = "用户" },
|
||||
new ExcelTitle { Property = "ProductName", Title = "产品" },
|
||||
new ExcelTitle { Property = "PackageName", Title = "套餐" },
|
||||
new ExcelTitle { Property = "ConnectCount", Title = "连接数",Expr=(p)=>((ProductOrderEntity)p).ConnectCount*((ProductOrderEntity)p).AccountCount},
|
||||
new ExcelTitle { Property = "Accounts", Title = "账号" },
|
||||
new ExcelTitle { Property = "PaymentAmount", Title = "实付金额" },
|
||||
new ExcelTitle { Property = "RefundAmount", Title = "退款金额" },
|
||||
new ExcelTitle { Property = "RefundRestTime", Title = "剩余时间" },
|
||||
new ExcelTitle { Property = "RefundRestTime", Title = "自动退款",Expr=(p)=>((ProductOrderEntity)p).IsAutoRefund.HasValue&&((ProductOrderEntity)p).IsAutoRefund==1?"是":"否" },
|
||||
new ExcelTitle { Property = "RefundRestTime", Title = "退款状态",Expr=(p)=>refundTypeFormat((ProductOrderEntity)p) },
|
||||
|
||||
};
|
||||
var fileBytes = ExcelHelper.ExportListToExcel(data, title);
|
||||
|
||||
var fileName = $"{DateTime.Now.ToString("yyyyMMdd")}退款明细.xlsx";
|
||||
Response.Headers.Add("X-Suggested-Filename", fileName.UrlEncode());
|
||||
return File(fileBytes, "application/octet-stream", fileName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
[HttpGet,AllowAnonymous]
|
||||
public async Task<IActionResult> OpenExportRefundOrders([FromQuery]OrderQueryRequest request)
|
||||
{
|
||||
Expression<Func<ProductOrderEntity, bool>> expr = m => m.OrderType == OrderType.Refund;
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m =>
|
||||
m.OrderName.Contains(request.KeyWord)
|
||||
|| m.OrderNo.Contains(request.KeyWord)
|
||||
|| m.UserName.Contains(request.KeyWord)
|
||||
|| m.PackageName.Contains(request.KeyWord));
|
||||
}
|
||||
if (request.OrderTypes != null && request.OrderTypes.Count > 0)
|
||||
{
|
||||
expr = expr.And(m => request.OrderTypes.Contains((int)m.OrderType));
|
||||
}
|
||||
if (request.BTime.HasValue && request.ETime.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.CreateTime >= request.BTime && m.CreateTime <= request.ETime);
|
||||
}
|
||||
var ret = await m_ProductOrderService.Page(request.PageIndex, 10000, expr, true);
|
||||
|
||||
|
||||
var data = new ExcelData<ProductOrderEntity>
|
||||
{
|
||||
SheetName = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
Data = ret.List
|
||||
};
|
||||
|
||||
|
||||
Func<ProductOrderEntity, object> refundTypeFormat = (order) =>
|
||||
{
|
||||
switch (order.OrderState)
|
||||
{
|
||||
case OrderStatus.RequestRefund:
|
||||
return "未自动退款";
|
||||
case OrderStatus.UserRefundOver:
|
||||
return "已人工处理";
|
||||
case OrderStatus.AutoRefundOver:
|
||||
return "已自动退款";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
var title = new List<ExcelTitle>(){
|
||||
new ExcelTitle { Property = "CreateTime", Title = "创建日期" ,Format=(val)=>((DateTime) val).ToString("yyyy-MM-dd hh:mm:ss") },
|
||||
//new ExcelTitle { Property = "OrderNo", Title = "订单号" },
|
||||
//new ExcelTitle { Property = "OrderType", Title = "类型", Format=(val)=>((OrderType)val).GetEnumDisplayName() },
|
||||
//new ExcelTitle { Property = "UserName", Title = "用户" },
|
||||
new ExcelTitle { Property = "ProductName", Title = "产品" },
|
||||
new ExcelTitle { Property = "PackageName", Title = "套餐" },
|
||||
new ExcelTitle { Property = "ConnectCount", Title = "连接数",Expr=(p)=>((ProductOrderEntity)p).ConnectCount*((ProductOrderEntity)p).AccountCount},
|
||||
new ExcelTitle { Property = "Accounts", Title = "账号" },
|
||||
new ExcelTitle { Property = "RefundRestTime", Title = "剩余时间" }
|
||||
};
|
||||
var fileBytes = ExcelHelper.ExportListToExcel(data, title);
|
||||
|
||||
var fileName = $"{DateTime.Now.ToString("yyyyMMdd")}退款明细.xlsx";
|
||||
Response.Headers.Add("X-Suggested-Filename", fileName.UrlEncode());
|
||||
return File(fileBytes, "application/octet-stream", fileName);
|
||||
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> RefundProcess([FromBody]RefundProcessRequest request)
|
||||
{
|
||||
var entity=await m_ProductOrderService.GetById(request.Id);
|
||||
if (entity.OrderState != OrderStatus.RequestRefund)
|
||||
{
|
||||
return Error("无需处理");
|
||||
}
|
||||
entity.Remark += request.Remark;
|
||||
entity.OrderState = OrderStatus.UserRefundOver;
|
||||
await m_ProductOrderService.Update(entity);
|
||||
return Success();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> CouponOrders([FromQuery] CouponOrderQueryRequest request)
|
||||
{
|
||||
var data = await this.m_ProductOrderService
|
||||
.Query(m => m.CouponId == request.CouponId
|
||||
&& m.OrderState == OrderStatus.Complete)
|
||||
.ListPagerAsync(request.PageSize, request.PageIndex, true);
|
||||
return data.ToApiResult();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> TakeOrder([FromQuery]string phone, [FromQuery] decimal amount)
|
||||
{
|
||||
var manager = this.Request.GetManageUserInfo();
|
||||
|
||||
var datas = await this.m_ProductOrderService
|
||||
.Query(m => m.UserName == phone
|
||||
&& m.OrderState == OrderStatus.Complete
|
||||
&& m.OrderAmount == amount
|
||||
&& string.IsNullOrEmpty(m.Channel))
|
||||
.OrderByDescending(m => m.Id)
|
||||
.ToListAsync();
|
||||
var data = datas.Where(m => (DateTime.Now - m.UpdateTime).TotalMinutes < 30).FirstOrDefault();
|
||||
if (data != null)
|
||||
{
|
||||
data.Channel = manager.LoginName;
|
||||
await m_ProductOrderService.Update(data);
|
||||
return Success();
|
||||
}
|
||||
return Error("没有订单");
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> SellerOrders([FromQuery]OrderQueryRequest request)
|
||||
{
|
||||
var manager = this.Request.GetManageUserInfo();
|
||||
|
||||
var managerEntity = await m_ManageService.GetById(manager.OperaterId);
|
||||
Expression<Func<ProductOrderEntity, bool>> expr = m => !string.IsNullOrEmpty(m.Channel);
|
||||
if (managerEntity != null && managerEntity.IsRoot == 0)
|
||||
{
|
||||
expr = m => m.Channel == manager.LoginName;
|
||||
}
|
||||
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m => m.Accounts.Contains(request.KeyWord)|| m.OrderNo.Contains(request.KeyWord)|| m.UserName.Contains(request.KeyWord));
|
||||
}
|
||||
if (request.ProductId.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.ProductId == request.ProductId);
|
||||
}
|
||||
if (request.OrderTypes != null && request.OrderTypes.Count > 0)
|
||||
{
|
||||
expr = expr.And(m => request.OrderTypes.Contains((int)m.OrderType));
|
||||
}
|
||||
if (request.BTime.HasValue && request.ETime.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.CreateTime >= request.BTime && m.CreateTime <= request.ETime);
|
||||
}
|
||||
|
||||
var ret = await this.m_ProductOrderService.PageDesc(request.PageIndex, request.PageSize, expr, true, m => m.Id);
|
||||
|
||||
return ret.ToApiResult();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> ExportSellerOrders([FromQuery]OrderQueryRequest request)
|
||||
{
|
||||
var manager = this.Request.GetManageUserInfo();
|
||||
|
||||
var managerEntity = await m_ManageService.GetById(manager.OperaterId);
|
||||
Expression<Func<ProductOrderEntity, bool>> expr = m => !string.IsNullOrEmpty(m.Channel);
|
||||
if (managerEntity != null && managerEntity.IsRoot == 0)
|
||||
{
|
||||
expr = m => m.Channel == manager.LoginName;
|
||||
}
|
||||
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m => m.Accounts.Contains(request.KeyWord) || m.OrderNo.Contains(request.KeyWord) || m.UserName.Contains(request.KeyWord));
|
||||
}
|
||||
if (request.ProductId.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.ProductId == request.ProductId);
|
||||
}
|
||||
if (request.OrderTypes != null && request.OrderTypes.Count > 0)
|
||||
{
|
||||
expr = expr.And(m => request.OrderTypes.Contains((int)m.OrderType));
|
||||
}
|
||||
if (request.BTime.HasValue && request.ETime.HasValue)
|
||||
{
|
||||
expr = expr.And(m => m.CreateTime >= request.BTime && m.CreateTime <= request.ETime);
|
||||
}
|
||||
|
||||
var ret = await this.m_ProductOrderService.PageDesc(request.PageIndex,10000, expr, true, m => m.Id);
|
||||
|
||||
var data = new ExcelData<ProductOrderEntity>
|
||||
{
|
||||
SheetName = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
Data = ret.List
|
||||
};
|
||||
|
||||
|
||||
Func<ProductOrderEntity, object> refundTypeFormat = (order) =>
|
||||
{
|
||||
switch (order.OrderState)
|
||||
{
|
||||
case OrderStatus.RequestRefund:
|
||||
return "未自动退款";
|
||||
case OrderStatus.UserRefundOver:
|
||||
return "已人工处理";
|
||||
case OrderStatus.AutoRefundOver:
|
||||
return "已自动退款";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
var title = new List<ExcelTitle>(){
|
||||
new ExcelTitle { Property = "CreateTime", Title = "创建日期" ,Format=(val)=>((DateTime) val).ToString("yyyy-MM-dd hh:mm:ss") },
|
||||
new ExcelTitle { Property = "OrderNo", Title = "订单号" },
|
||||
new ExcelTitle { Property = "OrderType", Title = "类型", Format=(val)=>((OrderType)val).GetEnumDisplayName() },
|
||||
new ExcelTitle { Property = "UserName", Title = "用户" },
|
||||
new ExcelTitle { Property = "ProductName", Title = "产品" },
|
||||
new ExcelTitle { Property = "PackageName", Title = "套餐" },
|
||||
new ExcelTitle { Property = "ConnectCount", Title = "连接数",Expr=(p)=>((ProductOrderEntity)p).ConnectCount*((ProductOrderEntity)p).AccountCount},
|
||||
new ExcelTitle { Property = "DayPrice", Title = "单价" },
|
||||
new ExcelTitle { Property = "Accounts", Title = "账号" },
|
||||
new ExcelTitle { Property = "OrderAmount", Title = "订单金额" },
|
||||
new ExcelTitle { Property = "CouponAmount", Title = "优惠金额" },
|
||||
new ExcelTitle { Property = "AccountPayAmount", Title = "余额支付" },
|
||||
new ExcelTitle { Property = "OtherPayAmount", Title = "在线支付" },
|
||||
new ExcelTitle { Property = "PaymentAmount", Title = "实付" },
|
||||
new ExcelTitle { Property = "PayType", Title = "付款方式", Format=(val)=>((PayType)val).GetEnumDisplayName() },
|
||||
new ExcelTitle { Property = "PaymentAmount", Title = "支付流水号" },
|
||||
new ExcelTitle { Property = "Channel", Title = "销售人" },
|
||||
|
||||
};
|
||||
var fileBytes = ExcelHelper.ExportListToExcel(data, title);
|
||||
|
||||
var fileName = $"{DateTime.Now.ToString("yyyyMMdd")}销售明细.xlsx";
|
||||
Response.Headers.Add("X-Suggested-Filename", fileName.UrlEncode());
|
||||
return File(fileBytes, "application/octet-stream", fileName);
|
||||
}
|
||||
|
||||
public async Task<ApiResult> UserCountStatistics(DateTime? bTime, DateTime? eTime)
|
||||
{
|
||||
|
||||
var manager = this.Request.GetManageUserInfo();
|
||||
|
||||
var managerInfo = await m_ManageService.GetById(manager.OperaterId);
|
||||
|
||||
var countInfo = m_ProductOrderService.UserCountStatistics(bTime, eTime);
|
||||
|
||||
var totalCountInfo = m_ProductOrderService.UserCountStatistics(null, null);
|
||||
|
||||
var amountInfo = m_ProductOrderService.SellAmountStatistics(bTime, eTime);
|
||||
|
||||
var query = from count in totalCountInfo
|
||||
join amount in amountInfo on count.RealName equals amount.RealName
|
||||
join newCount in countInfo on count.RealName equals newCount.RealName
|
||||
select new ManagerSellStatisticModel { RealName = count.RealName, Amount = amount.Amount, UserCount = count.UserCount, NewUserCount = newCount.UserCount };
|
||||
|
||||
|
||||
if (managerInfo.IsRoot != 1)
|
||||
{
|
||||
query = query.Where(m => m.RealName == managerInfo.RealName);
|
||||
}
|
||||
|
||||
var totalOrderAmount = m_ProductOrderService.Query(true).Where(m => m.OrderState == OrderStatus.PayOk || m.OrderState == OrderStatus.Complete).Sum(m => m.OrderAmount);
|
||||
|
||||
var totalUser = m_BaseUserService.Query(true).Count();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
OrderAmount = totalOrderAmount,
|
||||
UserTotal = totalUser,
|
||||
List = query.ToList()
|
||||
};
|
||||
|
||||
return Success(ret);
|
||||
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> ExportUserConsumeStatistics([FromQuery]UserConsumeRequest request)
|
||||
{
|
||||
|
||||
var loginInfo = this.Request.GetManageUserInfo();
|
||||
int id = loginInfo.OperaterId;
|
||||
var managerInfo = await m_ManageService.GetById(loginInfo.OperaterId);
|
||||
if (managerInfo.IsRoot == 1) id = 0;
|
||||
var ret = m_ProductOrderService.ExportUserConsumeStatisticsData(request.KeyWord, request.bTime1, request.eTime1, request.bTime2, request.eTime2, id, request.SortLable, request.SortOrder, request.Profile);
|
||||
|
||||
|
||||
var data = new ExcelData<UserConsumeStatisticsModel>
|
||||
{
|
||||
SheetName = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
Data = ret
|
||||
};
|
||||
|
||||
var title = new List<ExcelTitle>(){
|
||||
new ExcelTitle { Property = "Profile", Title = "状态" , Expr=(p)=>((UserConsumeStatisticsModel)p).UserInfo.Profile},
|
||||
new ExcelTitle { Property = "UserName", Title = "用户" },
|
||||
new ExcelTitle { Property = "CreateTime", Title = "注册时间", Format=(val)=>((DateTime)val).ToString("yyyy-MM-dd") },
|
||||
new ExcelTitle { Property = "PrevMonthAmount", Title = "消费金额A" },
|
||||
new ExcelTitle { Property = "MonthAmount", Title = "消费金额B" },
|
||||
new ExcelTitle { Property = "AddAmount", Title = "对比增长金额" },
|
||||
new ExcelTitle { Property = "TotalAccountCount", Title = "账户总数" },
|
||||
new ExcelTitle { Property = "UsingAccountCount", Title = "过期个数" },
|
||||
new ExcelTitle { Property = "UserName", Title = "联系信息" , Expr=(p)=>{
|
||||
var user=((UserConsumeStatisticsModel)p).UserInfo;
|
||||
var subret=new List<string>();
|
||||
if(user.Wx.Has()) subret.Add($"微信:{user.Wx}");
|
||||
if(user.QQ.Has()) subret.Add($"QQ:{user.QQ}");
|
||||
if(user.Wx.Has()) subret.Add($"淘宝:{user.TaoBao}");
|
||||
if(user.Wx.Has()) subret.Add($"旺旺:{user.WangWang}");
|
||||
return string.Join(",",subret);
|
||||
} }
|
||||
};
|
||||
var fileBytes = ExcelHelper.ExportListToExcel(data, title);
|
||||
|
||||
var fileName = $"{DateTime.Now.ToString("yyyyMMdd")}消费统计.xlsx";
|
||||
Response.Headers.Add("X-Suggested-Filename", fileName.UrlEncode());
|
||||
return File(fileBytes, "application/octet-stream", fileName);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
149
Services/Hncore.Pass.Vpn/Controllers/ProductRouteController.cs
Normal file
149
Services/Hncore.Pass.Vpn/Controllers/ProductRouteController.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using Hncore.Infrastructure.Common;
|
||||
using Hncore.Infrastructure.EntitiesExtension;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Domain;
|
||||
using Hncore.Pass.Vpn.Request.Product;
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/course/v{version:apiVersion}/productroute/[action]")]
|
||||
public class ProductRouteController : HncoreControllerBase
|
||||
{
|
||||
private ProductRouteService m_ProductRouteService;
|
||||
|
||||
private ProductService m_ProductService;
|
||||
|
||||
public ProductRouteController(ProductRouteService _ProductRouteService, ProductService _ProductService)
|
||||
{
|
||||
m_ProductRouteService = _ProductRouteService;
|
||||
m_ProductService = _ProductService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Post([FromBody]ProductRouteEntity request)
|
||||
{
|
||||
var product = await m_ProductService.GetById(request.ProductId);
|
||||
request.ProductName = product?.Name;
|
||||
await m_ProductRouteService.Add(request);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Put([FromBody]ProductRouteEntity request)
|
||||
{
|
||||
var product = await m_ProductService.GetById(request.ProductId);
|
||||
request.ProductName = product?.Name;
|
||||
await m_ProductRouteService.Update(request);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Delete([FromQuery]int id)
|
||||
{
|
||||
var flag = await m_ProductRouteService.DeleteById(id);
|
||||
if (flag)
|
||||
return Success();
|
||||
else
|
||||
return Error("删除失败");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 详情
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Get([FromQuery]int id)
|
||||
{
|
||||
var data = await m_ProductRouteService.GetById(id);
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Page([FromQuery]RoutePageRequest request)
|
||||
{
|
||||
Expression<Func<ProductRouteEntity, bool>> expr = m => 1 == 1;
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m => m.Province.Contains(request.KeyWord) || m.Name.Contains(request.KeyWord) || m.City.Contains(request.KeyWord) || m.ServerUrl.Contains(request.KeyWord));
|
||||
}
|
||||
if (request.ProductId.HasValue&& request.ProductId>0)
|
||||
{
|
||||
expr = expr.And(m => m.ProductId==request.ProductId);
|
||||
}
|
||||
var ret = await m_ProductRouteService.PageAsc(request.PageIndex, request.PageSize, expr, true,m=>m.Sort);
|
||||
var data = ret.ToApiResult();
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost, AllowAnonymous]
|
||||
public async Task<ApiResult> Import(IFormFile file)
|
||||
{
|
||||
// var file = this.Request.Form.Files.First();
|
||||
var stream = file.OpenReadStream();// this.Request.Body;
|
||||
//stream.Position = 0;
|
||||
var data = ExcelHelper.ReadFromStream(stream);
|
||||
|
||||
var products = await m_ProductService.GetAll();
|
||||
|
||||
var list = new List<ProductRouteEntity>();
|
||||
|
||||
var dataRows = data.Skip(1);
|
||||
foreach (var row in dataRows)
|
||||
{
|
||||
var model = new ProductRouteEntity();
|
||||
model.ProductName = row[0];
|
||||
model.Province = row[1];
|
||||
model.Name = row[2];
|
||||
model.ServerUrl = row[3];
|
||||
model.Status = row[4];
|
||||
model.LineType = row[5];
|
||||
model.BandWidth = row[6];
|
||||
model.IpRemark = row[7];
|
||||
model.ProductId = products.FirstOrDefault(m => m.Name == model.ProductName)?.Id;
|
||||
}
|
||||
if (list.Count > 1)
|
||||
{
|
||||
await m_ProductRouteService.Adds(list);
|
||||
}
|
||||
return Success();
|
||||
}
|
||||
}
|
||||
}
|
||||
188
Services/Hncore.Pass.Vpn/Controllers/ProductSchemeController.cs
Normal file
188
Services/Hncore.Pass.Vpn/Controllers/ProductSchemeController.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
using Hncore.Infrastructure.EntitiesExtension;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Domain;
|
||||
using Hncore.Pass.Vpn.Request.Product;
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/course/v{version:apiVersion}/scheme/[action]")]
|
||||
public class ProductSchemeController : HncoreControllerBase
|
||||
{
|
||||
private ProductService m_ProductService;
|
||||
private ProductPackageService m_ProductPackageService;
|
||||
private ProductUserPriceService m_ProductUserPriceService;
|
||||
private ProductPriceSchemeService m_PriceSchemeService;
|
||||
private ProductPriceDiscountService m_PriceDiscountService;
|
||||
public ProductSchemeController(ProductService _ProductServic
|
||||
, ProductPackageService _ProductPackageService
|
||||
, ProductUserPriceService _ProductUserPriceService
|
||||
,ProductPriceSchemeService _PriceSchemeService
|
||||
,ProductPriceDiscountService _PriceDiscountService
|
||||
)
|
||||
{
|
||||
m_ProductService = _ProductServic;
|
||||
m_ProductPackageService = _ProductPackageService;
|
||||
m_ProductUserPriceService = _ProductUserPriceService;
|
||||
m_PriceSchemeService = _PriceSchemeService;
|
||||
m_PriceDiscountService = _PriceDiscountService;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Post([FromBody]ProductPriceSchemeEntity request)
|
||||
{
|
||||
await m_PriceSchemeService.Add(request);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Put([FromBody]ProductPriceSchemeEntity request)
|
||||
{
|
||||
var entity = await m_PriceSchemeService.GetById(request.Id);
|
||||
entity.Name = request.Name;
|
||||
entity.Remark = request.Remark;
|
||||
entity.UpdateTime = DateTime.Now;
|
||||
await m_PriceSchemeService.Update(entity);
|
||||
return Success();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Delete([FromQuery]int id)
|
||||
{
|
||||
var flag = await m_PriceSchemeService.DeleteById(id);
|
||||
if (flag)
|
||||
return Success();
|
||||
else
|
||||
return Error("删除失败");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 详情
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Get([FromQuery]int id)
|
||||
{
|
||||
var data = await m_PriceSchemeService.GetById(id);
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Page([FromQuery]PageRequestBase request)
|
||||
{
|
||||
Expression<Func<ProductPriceSchemeEntity, bool>> expr = m => 1 == 1;
|
||||
if (request.KeyWord.Has())
|
||||
{
|
||||
expr = expr.And(m => m.Name.Contains(request.KeyWord));
|
||||
}
|
||||
var ret = await m_PriceSchemeService.Page(request.PageIndex, request.PageSize, expr,true);
|
||||
var data = ret.ToApiResult();
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> GetProductDiscount(int id)
|
||||
{
|
||||
var ret = await this.m_PriceDiscountService.GetPriceDiscount(id);
|
||||
return Success(ret);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> PutProductDiscount([FromBody]ProductPriceDiscountEntity request)
|
||||
{
|
||||
var priceDiscountEntity = await m_PriceDiscountService.Query(m => m.PackageId == request.PackageId && m.SchemeId == request.SchemeId).FirstOrDefaultAsync();
|
||||
|
||||
if (priceDiscountEntity == null)
|
||||
{
|
||||
await m_PriceDiscountService.Add(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
priceDiscountEntity.BuyPriceDiscount = request.BuyPriceDiscount;
|
||||
priceDiscountEntity.RefundDayPriceDiscount = request.RefundDayPriceDiscount;
|
||||
await m_PriceDiscountService.Update(priceDiscountEntity);
|
||||
}
|
||||
return Success(1);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> SetUserDiscount([FromBody] SetUserDiscountRequest request)
|
||||
{
|
||||
var priceDiscountEntitys = await m_PriceDiscountService.Query(m => m.SchemeId == request.SchemeId).ToListAsync();
|
||||
var schemaEntity = await m_PriceSchemeService.GetById(request.SchemeId);
|
||||
var produccts = await m_ProductService.GetAll(true);
|
||||
var packages = await m_ProductPackageService.GetAll(true);
|
||||
|
||||
var userPrices = await m_ProductUserPriceService.GetPackageUserPrice(request.UserId);
|
||||
foreach (var item in priceDiscountEntitys)
|
||||
{
|
||||
var product = produccts.FirstOrDefault(m => m.Id == item.ProductId);
|
||||
var package = packages.FirstOrDefault(m => m.Id == item.PackageId);
|
||||
var userPakcagePrices = userPrices.FirstOrDefault(m => m.Product.Id == item.ProductId)?.PackageUserPrices;
|
||||
var userPrice = userPakcagePrices?.FirstOrDefault(uPrice => uPrice.Package.Id == item.PackageId && uPrice.UserPrice.UserId == request.UserId)?.UserPrice;
|
||||
if (userPrice != null && userPrice.Id > 0)
|
||||
{
|
||||
userPrice.Status = 1;
|
||||
userPrice.UserPrice = item.BuyPriceDiscount / 100m * package.Price;
|
||||
userPrice.RefundDayPrice = item.RefundDayPriceDiscount / 100m * product.RefundDayPrice;
|
||||
userPrice.Remark = schemaEntity.Name;
|
||||
userPrice.UserPrice = Math.Max(userPrice.UserPrice, package.MinPrice);
|
||||
userPrice.RefundDayPrice = Math.Max(userPrice.RefundDayPrice.Value, product.DayLimitPrice.Value);
|
||||
await m_ProductUserPriceService.Update(userPrice);
|
||||
}
|
||||
else
|
||||
{
|
||||
userPrice = new ProductUserPriceEntity()
|
||||
{
|
||||
PackageId = item.PackageId,
|
||||
ProductId = item.ProductId,
|
||||
Status = 1,
|
||||
Remark = schemaEntity.Name,
|
||||
TenantId = 0,
|
||||
UserId = request.UserId,
|
||||
UserPrice = item.BuyPriceDiscount / 100m * package.Price,
|
||||
RefundDayPrice = item.RefundDayPriceDiscount / 100m * product.RefundDayPrice,
|
||||
};
|
||||
userPrice.UserPrice = Math.Max(userPrice.UserPrice, package.MinPrice);
|
||||
userPrice.RefundDayPrice = Math.Max(userPrice.RefundDayPrice.Value, product.DayLimitPrice.Value);
|
||||
await m_ProductUserPriceService.Add(userPrice);
|
||||
}
|
||||
}
|
||||
return Success(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user