304 lines
9.5 KiB
C#
304 lines
9.5 KiB
C#
/***********************************************************************
|
|
* Project: CoreCms
|
|
* ProjectName: 核心内容管理系统
|
|
* Web: https://www.corecms.net
|
|
* Author: 大灰灰
|
|
* Email: jianweie@163.com
|
|
* CreateTime: 2025/12/7
|
|
* Description: 提现管理
|
|
***********************************************************************/
|
|
|
|
using CoreCms.Net.Configuration;
|
|
using CoreCms.Net.Filter;
|
|
using CoreCms.Net.IServices;
|
|
using CoreCms.Net.Model.Entities;
|
|
using CoreCms.Net.Model.Entities.Expression;
|
|
using CoreCms.Net.Model.FromBody;
|
|
using CoreCms.Net.Model.ViewModels.UI;
|
|
using CoreCms.Net.Utility.Extensions;
|
|
using CoreCms.Net.Web.Admin.Infrastructure;
|
|
using CoreCms.Net.IRepository;
|
|
using CoreCms.Net.IRepository.UnitOfWork;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using SqlSugar;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CoreCms.Net.Web.Admin.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 提现管理
|
|
/// </summary>
|
|
[Description("提现管理")]
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
[RequiredErrorForAdmin]
|
|
[Authorize]
|
|
public class SQWithdrawController : ControllerBase
|
|
{
|
|
private readonly IWebHostEnvironment _webHostEnvironment;
|
|
private readonly ISQEarningsServices _sQEarningsServices;
|
|
private readonly ICoreCmsUserServices _userServices;
|
|
private readonly ISQWithdrawRecordRepository _withdrawRecordRepository;
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
public SQWithdrawController(
|
|
IWebHostEnvironment webHostEnvironment,
|
|
ISQEarningsServices sQEarningsServices,
|
|
ICoreCmsUserServices userServices,
|
|
ISQWithdrawRecordRepository withdrawRecordRepository,
|
|
IUnitOfWork unitOfWork)
|
|
{
|
|
_webHostEnvironment = webHostEnvironment;
|
|
_sQEarningsServices = sQEarningsServices;
|
|
_userServices = userServices;
|
|
_withdrawRecordRepository = withdrawRecordRepository;
|
|
_unitOfWork = unitOfWork;
|
|
}
|
|
|
|
#region 获取列表
|
|
|
|
/// <summary>
|
|
/// 获取提现记录列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Description("获取提现记录列表")]
|
|
public async Task<AdminUiCallBack> GetPageList()
|
|
{
|
|
var jm = new AdminUiCallBack();
|
|
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
|
|
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
|
|
var where = PredicateBuilder.True<SQWithdrawRecord>();
|
|
|
|
// 获取排序字段
|
|
var orderField = Request.Form["orderField"].FirstOrDefault();
|
|
Expression<Func<SQWithdrawRecord, object>> orderEx = orderField switch
|
|
{
|
|
"id" => p => p.id,
|
|
"user_id" => p => p.user_id,
|
|
"amount" => p => p.amount,
|
|
"status" => p => p.status,
|
|
"apply_time" => p => p.apply_time,
|
|
_ => p => p.id
|
|
};
|
|
|
|
// 设置排序方式
|
|
var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
|
|
var orderBy = orderDirection switch
|
|
{
|
|
"asc" => OrderByType.Asc,
|
|
"desc" => OrderByType.Desc,
|
|
_ => OrderByType.Desc
|
|
};
|
|
|
|
// 查询筛选
|
|
var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
|
|
if (id > 0)
|
|
{
|
|
where = where.And(p => p.id == id);
|
|
}
|
|
|
|
var userId = Request.Form["user_id"].FirstOrDefault().ObjectToInt(0);
|
|
if (userId > 0)
|
|
{
|
|
where = where.And(p => p.user_id == userId);
|
|
}
|
|
|
|
var status = Request.Form["status"].FirstOrDefault();
|
|
if (!string.IsNullOrEmpty(status))
|
|
{
|
|
var statusInt = status.ObjectToInt(-1);
|
|
if (statusInt >= 0)
|
|
{
|
|
where = where.And(p => p.status == statusInt);
|
|
}
|
|
}
|
|
|
|
// 获取数据
|
|
var list = await _withdrawRecordRepository.QueryPageAsync(where, orderEx, orderBy, pageCurrent, pageSize, true);
|
|
|
|
// 关联查询用户昵称
|
|
var userIds = list.Select(p => p.user_id).Distinct().ToList();
|
|
var userDict = new Dictionary<int, string>();
|
|
if (userIds.Any())
|
|
{
|
|
var users = await _userServices.QueryListByClauseAsync(p => userIds.Contains(p.id));
|
|
userDict = users.ToDictionary(p => p.id, p => p.nickName ?? p.mobile ?? $"用户{p.id}");
|
|
}
|
|
|
|
// 组装返回数据
|
|
var resultList = list.Select(p => new
|
|
{
|
|
p.id,
|
|
p.user_id,
|
|
p.amount,
|
|
p.status,
|
|
statusName = GetStatusName(p.status),
|
|
p.apply_time,
|
|
p.process_time,
|
|
p.operator_id,
|
|
p.remark,
|
|
nickName = userDict.ContainsKey(p.user_id) ? userDict[p.user_id] : $"用户{p.user_id}"
|
|
}).ToList();
|
|
|
|
jm.data = resultList;
|
|
jm.code = 0;
|
|
jm.count = list.TotalCount;
|
|
jm.msg = "数据调用成功!";
|
|
return jm;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取状态名称
|
|
/// </summary>
|
|
private string GetStatusName(int status)
|
|
{
|
|
return status switch
|
|
{
|
|
0 => "提现中",
|
|
1 => "已到账",
|
|
2 => "已拒绝",
|
|
_ => "未知"
|
|
};
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 首页数据
|
|
|
|
/// <summary>
|
|
/// 首页数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Description("首页数据")]
|
|
public AdminUiCallBack GetIndex()
|
|
{
|
|
var jm = new AdminUiCallBack { code = 0 };
|
|
return jm;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 处理提现申请
|
|
|
|
/// <summary>
|
|
/// 同意提现(标记为已打款)
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Description("同意提现")]
|
|
public async Task<AdminUiCallBack> DoApprove([FromBody] ProcessWithdrawRequest entity)
|
|
{
|
|
var jm = new AdminUiCallBack();
|
|
|
|
// 获取当前登录管理员ID
|
|
var operatorId = HttpContext.User.Claims.FirstOrDefault(c => c.Type == "id")?.Value.ObjectToInt(0) ?? 0;
|
|
|
|
var result = await _sQEarningsServices.ProcessWithdrawAsync(entity.id, 1, operatorId, entity.remark);
|
|
|
|
jm.code = result.status ? 0 : 1;
|
|
jm.msg = result.msg;
|
|
|
|
return jm;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拒绝提现
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Description("拒绝提现")]
|
|
public async Task<AdminUiCallBack> DoReject([FromBody] ProcessWithdrawRequest entity)
|
|
{
|
|
var jm = new AdminUiCallBack();
|
|
|
|
if (string.IsNullOrEmpty(entity.remark))
|
|
{
|
|
jm.code = 1;
|
|
jm.msg = "请填写拒绝原因";
|
|
return jm;
|
|
}
|
|
|
|
// 获取当前登录管理员ID
|
|
var operatorId = HttpContext.User.Claims.FirstOrDefault(c => c.Type == "id")?.Value.ObjectToInt(0) ?? 0;
|
|
|
|
var result = await _sQEarningsServices.ProcessWithdrawAsync(entity.id, 2, operatorId, entity.remark);
|
|
|
|
jm.code = result.status ? 0 : 1;
|
|
jm.msg = result.msg;
|
|
|
|
return jm;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 删除数据
|
|
|
|
/// <summary>
|
|
/// 删除数据
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Description("删除数据")]
|
|
public async Task<AdminUiCallBack> DoDelete([FromBody] FMIntId entity)
|
|
{
|
|
var jm = new AdminUiCallBack();
|
|
var result = await _withdrawRecordRepository.DeleteByIdAsync(entity.id);
|
|
jm.code = result.code;
|
|
jm.msg = result.msg;
|
|
return jm;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 批量删除
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Description("批量删除")]
|
|
public async Task<AdminUiCallBack> DoBatchDelete([FromBody] FMArrayIntIds entity)
|
|
{
|
|
var jm = new AdminUiCallBack();
|
|
var result = await _withdrawRecordRepository.DeleteByIdsAsync(entity.id);
|
|
jm.code = result.code;
|
|
jm.msg = result.msg;
|
|
return jm;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理提现请求
|
|
/// </summary>
|
|
public class ProcessWithdrawRequest
|
|
{
|
|
/// <summary>
|
|
/// 提现记录ID
|
|
/// </summary>
|
|
public int id { get; set; }
|
|
|
|
/// <summary>
|
|
/// 备注(拒绝原因等)
|
|
/// </summary>
|
|
public string remark { get; set; }
|
|
}
|
|
}
|