Commit f4f41915 authored by liudong1993's avatar liudong1993

vip购买返佣分页列表+Excel下载

parent e1a65b56
......@@ -38,6 +38,10 @@ namespace Mall.Model.Extend.User
/// 返佣ids
/// </summary>
public string VipIds { get; set; }
/// <summary>
/// 订单ids
/// </summary>
public string OrderIds { get; set; }
}
}
......@@ -17,5 +17,15 @@ namespace Mall.Model.Extend.User
/// 购买人姓名
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 返佣用户id
/// </summary>
public int? DistributionUserId { get; set; }
/// <summary>
/// 返佣列表
/// </summary>
public List<RB_VipBuy_Commission_Extend> CommissionList { get; set; }
}
}
......@@ -768,7 +768,7 @@ namespace Mall.Module.User
//可以升级咯
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_Distributor_Info.FXGradeId),fxNext.Id},
{ nameof(RB_Distributor_Info.Remark),dispmodel.Remark+" 分销商满足升级条件:"+(fxNext.UpgradeNum ?? 0)+"位"+(gmodel.GradeName??"")+"下线,已自动升级为"+(fxNext.GradeName??"")},
{ nameof(RB_Distributor_Info.Remark),dispmodel.Remark+" ;分销商满足升级条件:"+(fxNext.UpgradeNum ?? 0)+"位"+(gmodel.GradeName??"")+"下线,已自动升级为"+(fxNext.GradeName??"")},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
......@@ -815,13 +815,13 @@ namespace Mall.Module.User
{
//上级可以升级咯
Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
{ nameof(RB_Distributor_Info.FXGradeId),fxNext.Id},
{ nameof(RB_Distributor_Info.Remark),dispmodel.Remark+" 分销商满足升级条件:"+(fxpNext.UpgradeNum ?? 0)+"位"+(gpmodel.GradeName??"")+"下线,已自动升级为"+(fxpNext.GradeName??"")},
{ nameof(RB_Distributor_Info.FXGradeId),fxpNext.Id},
{ nameof(RB_Distributor_Info.Remark),disppmodel.Remark+" ;分销商满足升级条件:"+(fxpNext.UpgradeNum ?? 0)+"位"+(gpmodel.GradeName??"")+"下线,已自动升级为"+(fxpNext.GradeName??"")},
};
List<WhereHelper> wheres1 = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Distributor_Info.Id),
FiledValue=dispmodel.Id,
FiledValue=disppmodel.Id,
OperatorEnum=OperatorEnum.Equal
}
};
......
......@@ -36,6 +36,20 @@ namespace Mall.Module.User
/// vip购买仓储层
/// </summary>
private readonly RB_Vip_BuyRepository vipBuyRepository = new RB_Vip_BuyRepository();
/// <summary>
/// vip购买返佣
/// </summary>
private readonly RB_VipBuy_CommissionRepository vipBuy_CommissionRepository = new RB_VipBuy_CommissionRepository();
/// <summary>
/// 粉象等级
/// </summary>
private readonly RB_Distributor_FXGradeRepository distributor_FXGradeRepository = new RB_Distributor_FXGradeRepository();
/// <summary>
/// 用户
/// </summary>
private readonly RB_Member_UserRepository member_UserRepository = new RB_Member_UserRepository();
#region vip购买自定义
......@@ -138,5 +152,42 @@ namespace Mall.Module.User
#endregion
#region vip购买返佣
/// <summary>
/// 获取返佣分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="count"></param>
/// <param name="demodel"></param>
/// <returns></returns>
public List<RB_Vip_Buy_Extend> GetVipBuyCommissionPageList(int pageIndex, int pageSize, out long count, RB_Vip_Buy_Extend demodel)
{
var list = vipBuyRepository.GetVipBuyCommissionPageList(pageIndex, pageSize, out count, demodel);
if (list.Any()) {
string OrderIds = string.Join(",", list.Select(x => x.Id));
var clist = vipBuy_CommissionRepository.GetList(new RB_VipBuy_Commission_Extend() { OrderIds = OrderIds, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
var FXList = distributor_FXGradeRepository.GetList(new RB_Distributor_FXGrade_Extend() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
//获取用户
var ulist = new List<RB_Member_User_Extend>();
if (clist.Any())
{
ulist = member_UserRepository.GetList(new RB_Member_User_Extend() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId, UserIds = string.Join(",", clist.Select(x => x.UserId).Distinct()) });
}
foreach (var item in list) {
item.CommissionList = clist.Where(x => x.OrderId == item.Id).ToList();
foreach (var qitem in item.CommissionList) {
var fxmodel = FXList.Where(x => x.Id == qitem.Grade).FirstOrDefault();
qitem.GradeDescription = fxmodel.GradeName;
qitem.UserName = ulist.Where(x => x.Id == qitem.UserId).FirstOrDefault()?.Name ?? "";
}
}
}
return list;
}
#endregion
}
}
......@@ -82,6 +82,10 @@ where {where} order by v.Id desc";
{
where += $@" and v.{nameof(RB_VipBuy_Commission.OrderId)}={dmodel.OrderId}";
}
if (!string.IsNullOrEmpty(dmodel.OrderIds))
{
where += $@" and v.{nameof(RB_VipBuy_Commission.OrderId)} in({dmodel.OrderIds})";
}
if (dmodel.UserId > 0)
{
where += $@" and v.{nameof(RB_VipBuy_Commission.UserId)}={dmodel.UserId}";
......@@ -96,7 +100,7 @@ where {where} order by v.Id desc";
string sql = $@"select v.*,vb.OrderNo from RB_VipBuy_Commission v
inner join rb_vip_buy vb on v.OrderId = vb.Id
where {where} order by v.Id desc";
where {where} order by v.Id asc";
return Get<RB_VipBuy_Commission_Extend>(sql).ToList();
}
......
......@@ -70,5 +70,51 @@ namespace Mall.Repository.User
}
return Get<RB_Vip_Buy_Extend>(builder.ToString()).ToList();
}
/// <summary>
/// 获取vip购买返佣分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="rowCount"></param>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Vip_Buy_Extend> GetVipBuyCommissionPageList(int pageIndex, int pageSize, out long rowCount, RB_Vip_Buy_Extend query)
{
StringBuilder builder = new StringBuilder();
builder.Append($@" SELECT a.*,b.`Name` as UserName
FROM rb_vip_buy as a
INNER JOIN rb_member_user as b on a.UserId=b.Id
INNER JOIN rb_vipbuy_commission c on a.Id = c.OrderId
WHERE a.{nameof(RB_Vip_Buy_Extend.Status)}=0 group by a.Id");
if (query != null)
{
if (query.TenantId > 0)
{
builder.Append($" AND a.{nameof(RB_Vip_Buy_Extend.TenantId)}={query.TenantId}");
}
if (query.MallBaseId > 0)
{
builder.Append($" AND a.{nameof(RB_Vip_Buy_Extend.MallBaseId)}={query.MallBaseId}");
}
if (query.Id > 0)
{
builder.Append($" AND a.{nameof(RB_Vip_Buy_Extend.Id)}={query.Id}");
}
if (query.UserId > 0)
{
builder.Append($" AND a.{nameof(RB_Vip_Buy_Extend.UserId)}={query.UserId}");
}
if (query.DistributionUserId > 0)
{
builder.Append($" AND c.{nameof(RB_VipBuy_Commission.UserId)}={query.DistributionUserId}");
}
if (!string.IsNullOrEmpty(query.OrderNo))
{
builder.Append($" AND a.{nameof(RB_Vip_Buy_Extend.OrderNo)} like '%{query.OrderNo}%'");
}
}
return GetPage<RB_Vip_Buy_Extend>(pageIndex, pageSize, out rowCount, builder.ToString()).ToList();
}
}
}
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Mall.Common.API;
using Mall.Common.Plugin;
using Mall.Model.Extend.User;
using Mall.Module.User;
using Mall.WebApi.Filter;
......@@ -123,6 +124,7 @@ namespace Mall.WebApi.Controllers.User
pagelist.pageData = list.Select(x => new
{
x.Id,
x.OrderNo,
x.UserName,
x.Money,
ExpiryDateStr = x.ExpiryDate.HasValue ? x.ExpiryDate.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
......@@ -134,5 +136,148 @@ namespace Mall.WebApi.Controllers.User
return ApiResult.Success("", pagelist);
}
#endregion
#region Vip购买返佣
/// <summary>
/// vip购买返佣分页列表
/// </summary>
/// <param name="requestMsg"></param>
/// <returns></returns>
[HttpPost]
public ApiResult GetVipBuyCommissionPageList()
{
var requestParm = RequestParm;
ResultPageModel pagelist = JsonConvert.DeserializeObject<ResultPageModel>(requestParm.msg.ToString());
RB_Vip_Buy_Extend demodel = JsonConvert.DeserializeObject<RB_Vip_Buy_Extend>(requestParm.msg.ToString());
demodel.TenantId = requestParm.TenantId;
demodel.MallBaseId = requestParm.MallBaseId;
var list = userVipModule.GetVipBuyCommissionPageList(pagelist.pageIndex, pagelist.pageSize, out long count, demodel);
pagelist.count = Convert.ToInt32(count);
pagelist.pageData = list.Select(x => new
{
x.Id,
x.OrderNo,
x.UserName,
x.Money,
x.GradeName,
PayTimeStr = x.PayTime.HasValue ? x.PayTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
CommissionList = x.CommissionList.Select(z => new {
z.Id,
z.Grade,
z.GradeDescription,
z.Commission,
z.UserName
})
});
return ApiResult.Success("", pagelist);
}
/// <summary>
/// vip购买返佣 Excel下载
/// </summary>
/// <param name="requestMsg"></param>
/// <returns></returns>
[HttpPost]
public FileContentResult GetVipBuyCommissionPageListToExcel()
{
var requestParm = RequestParm;
RB_Vip_Buy_Extend demodel = JsonConvert.DeserializeObject<RB_Vip_Buy_Extend>(requestParm.msg.ToString());
string ExcelName = "分销订单" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
List<ExcelDataSource> slist = new List<ExcelDataSource>();
ExcelDataSource header = new ExcelDataSource()
{
ExcelRows = new List<ExcelColumn>(30) {
new ExcelColumn(value: "序号") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
new ExcelColumn(value: "订单号") { CellWidth = 25, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
new ExcelColumn(value: "购买用户") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
new ExcelColumn(value: "购买金额") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
new ExcelColumn(value: "等级名称") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
new ExcelColumn(value: "购买时间") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
new ExcelColumn(value: "返利级别") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
new ExcelColumn(value: "昵称") { CellWidth = 25, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
new ExcelColumn(value: "佣金") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
}
};
slist.Add(header);
try
{
demodel.TenantId = requestParm.TenantId;
demodel.MallBaseId = requestParm.MallBaseId;
var list = userVipModule.GetVipBuyCommissionPageList(1, 10000, out long count, demodel);
int Num = 0;
foreach (var item in list)
{
Num++;
var ocList = item.CommissionList;
int OCCount = ocList.Count();
OCCount = OCCount == 0 ? 1 : OCCount;
ExcelDataSource datarow = new ExcelDataSource()
{
ExcelRows = new List<ExcelColumn>(30) {
new ExcelColumn(value:Num.ToString()){ Rowspan = OCCount},
},
ColumnHight = 30
};
datarow.ExcelRows.Add(new ExcelColumn(value: item.OrderNo) { Rowspan = OCCount });
datarow.ExcelRows.Add(new ExcelColumn(value: item.UserName) { Rowspan = OCCount });
datarow.ExcelRows.Add(new ExcelColumn(value: (item.Money).ToString()) { Rowspan = OCCount });
datarow.ExcelRows.Add(new ExcelColumn(value: item.GradeName) { Rowspan = OCCount });
datarow.ExcelRows.Add(new ExcelColumn(value: item.PayTime.HasValue ? item.PayTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "") { Rowspan = OCCount });
bool IsOCFirst = true;
if (item.CommissionList.Any())
{
foreach (var qitem in item.CommissionList)
{
if (!IsOCFirst)
{
datarow = new ExcelDataSource()
{
ExcelRows = new List<ExcelColumn>(30) {
new ExcelColumn(value:Num.ToString()){ },
},
ColumnHight = 30
};
for (var i = 0; i < 6; i++)
{
datarow.ExcelRows.Add(new ExcelColumn(value: "") { });
}
}
datarow.ExcelRows.Add(new ExcelColumn(value: qitem.GradeDescription) { });
datarow.ExcelRows.Add(new ExcelColumn(value: qitem.UserName) { });
datarow.ExcelRows.Add(new ExcelColumn(value: (qitem.Commission ?? 0).ToString()) { });
slist.Add(datarow);
IsOCFirst = false;
}
}
else {
datarow.ExcelRows.Add(new ExcelColumn(value: "") { });
datarow.ExcelRows.Add(new ExcelColumn(value: "") { });
datarow.ExcelRows.Add(new ExcelColumn(value: "") { });
slist.Add(datarow);
}
}
var byteData = ExcelTempLateHelper.ToExcelExtend(slist);
return File(byteData, "application/octet-stream", ExcelName);
}
catch (Exception ex)
{
LogHelper.Write(ex, string.Format("GetVipBuyCommissionPageListToExcel: {0}", JsonHelper.Serialize(RequestParm)));
var byteData1 = ExcelTempLateHelper.ToExcelExtend(slist);
return File(byteData1, "application/octet-stream", ExcelName);
}
}
#endregion
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment