Commit 4541dcc5 authored by liudong1993's avatar liudong1993
parents 34790e63 9d977657
using Mall.Common.AOP;
using Mall.Common.Enum.Goods;
using System;
using System.Collections.Generic;
using System.Text;
......@@ -12,5 +13,146 @@ namespace Mall.Model.Extend.Statistics
[DB(ConnectionName = "DefaultConnection")]
public class MallIndexStatistics
{
/// <summary>
/// 用户数量
/// </summary>
public int UserTotalNum { get; set; }
/// <summary>
/// 商品数量
/// </summary>
public int GoodsTotalNum { get; set; }
/// <summary>
/// 总订单数量
/// </summary>
public int TotalOrderNum { get; set; }
/// <summary>
/// 代发货数量
/// </summary>
public int NoSendOrderNum { get; set; }
/// <summary>
/// 维权订单数量
/// </summary>
public int ActivistOrderNum { get; set; }
}
/// <summary>
/// 订单数量统计
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class OrderNum
{
/// <summary>
/// 订单状态 枚举
/// </summary>
public OrderStatusEnum? OrderStatus
{
get;
set;
}
/// <summary>
/// 订单数量
/// </summary>
public int OrderCount { get; set; }
}
/// <summary>
/// 销售情况统计
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class MallSalesStatistics
{
/// <summary>
/// 时间类型
/// </summary>
public string TimeStr { get; set; }
/// <summary>
/// 支付订单数
/// </summary>
public int OrderCount { get; set; }
/// <summary>
/// 支付金额
/// </summary>
public decimal Income { get; set; }
/// <summary>
/// 用户数量
/// </summary>
public int UserCount { get; set; }
/// <summary>
/// 购买商品件数
/// </summary>
public int GoodCount { get; set; }
}
/// <summary>
/// 商品购买力TOP排行
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class MallSalesGoodsTop
{
/// <summary>
/// 排名
/// </summary>
public int Num { get; set; }
/// <summary>
/// 商品名称
/// </summary>
public string GoodsName { get; set; }
/// <summary>
/// 销售额
/// </summary>
public decimal Income { get; set; }
/// <summary>
/// 销量
/// </summary>
public int SaleCount { get; set; }
}
/// <summary>
/// 用户购买力TOP排行
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class MallSalesUserTop
{
/// <summary>
/// 排名
/// </summary>
public int Num { get; set; }
/// <summary>
/// 用户头像
/// </summary>
public string Photo { get; set; }
/// <summary>
/// 用户名称
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 支付金额
/// </summary>
public decimal Income { get; set; }
/// <summary>
/// 支付件数
/// </summary>
public int SaleCount { get; set; }
}
}
using System;
using Mall.Common.Enum.User;
using System;
using System.Collections.Generic;
using System.Text;
......@@ -9,5 +10,49 @@ namespace Mall.Model.Query
/// </summary>
public class StatisticsQuery
{
/// <summary>
/// 商户号Id
/// </summary>
public int TenantId
{
get;
set;
}
/// <summary>
/// 小程序Id
/// </summary>
public int MallBaseId
{
get;
set;
}
/// <summary>
/// 来源 1微信 2支付宝【见枚举】
/// </summary>
public UserSourceEnum? Source
{
get;
set;
}
/// <summary>
/// 开始时间
/// </summary>
public string StartDate { get; set; }
/// <summary>
/// 结束时间
/// </summary>
public string EndDate { get; set; }
/// <summary>
/// 销售查询【1-昨日,7-七日】
/// </summary>
public int SalesTimeType { get; set; }
}
}
......@@ -11,6 +11,8 @@ using Newtonsoft.Json;
using Mall.Common.Plugin;
using NPOI.SS.Formula.Functions;
using Mall.Repository.User;
using Mall.Model.Extend.Statistics;
using Mall.Model.Query;
namespace Mall.Module.User
{
......@@ -62,6 +64,11 @@ namespace Mall.Module.User
/// </summary>
private readonly UserCommonModule userCommonModule = new UserCommonModule();
/// <summary>
/// 首页统计
/// </summary>
private readonly MallStatisticsRepository mallStatisticsRepository = new MallStatisticsRepository();
#region 轮播图管理
/// <summary>
......@@ -1890,5 +1897,93 @@ namespace Mall.Module.User
}
}
#endregion
#region 首页统计
/// <summary>
/// 订单数量、商品、用户统计
/// </summary>
/// <param name="query">查询条件</param>
/// <returns></returns>
public MallIndexStatistics MallIndexStatisticsModule(StatisticsQuery query)
{
return mallStatisticsRepository.MallIndexStatisticsRepository(query);
}
/// <summary>
/// 销售情况统计
/// </summary>
/// <param name="query"></param>
public object MallIndexSalesStatisticsModule(StatisticsQuery query)
{
var list = mallStatisticsRepository.MallIndexSalesStatisticsRepository(query);
List<object> resultList = new List<object>();
List<MallSalesStatistics> subList = new List<MallSalesStatistics>();
if (query.SalesTimeType == 1)
{
for (var i = 0; i <= 23; i++)
{
var subModel = list?.Where(qitem => qitem.TimeStr == i.ToString())?.FirstOrDefault();
subList.Add(new MallSalesStatistics()
{
TimeStr = i.ToString(),
GoodCount = subModel?.GoodCount ?? 0,
Income = subModel?.Income ?? 0,
OrderCount = subModel?.OrderCount ?? 0,
UserCount = subModel?.UserCount ?? 0,
});
}
}
else
{
var startDate = DateTime.Now.AddDays(-7);
for (var i = 0; i <= 7; i++)
{
var subModel = list?.Where(qitem => qitem.TimeStr == startDate.AddDays(i).ToString("yyyy-MM-dd"))?.FirstOrDefault();
subList.Add(new MallSalesStatistics()
{
TimeStr = startDate.AddDays(i).ToString("yyyy-MM-dd"),
GoodCount = subModel?.GoodCount ?? 0,
Income = subModel?.Income ?? 0,
OrderCount = subModel?.OrderCount ?? 0,
UserCount = subModel?.UserCount ?? 0,
});
}
}
var obj = new
{
//支付订单数
OrderCount = list?.Sum(qitem=>qitem.OrderCount)??0,
//支付金额
Income = list?.Sum(qitem => qitem.Income) ?? 0,
//支付人数
UserCount = list?.Sum(qitem => qitem.UserCount) ?? 0,
//支付件数
GoodCount = list?.Sum(qitem => qitem.GoodCount) ?? 0,
subList,
};
return obj;
}
/// <summary>
/// 商品购买力TOP排行
/// </summary>
/// <param name="query"></param>
public List<MallSalesGoodsTop> MallIndesSalesIncomeStatisticsModule(StatisticsQuery query)
{
return mallStatisticsRepository.MallIndesSalesIncomeStatisticsRepository(query);
}
/// <summary>
/// 用户购买力TOP排行
/// </summary>
/// <param name="query"></param>
public List<MallSalesUserTop> MallIndesSalesUserStatisticsModule(StatisticsQuery query)
{
return mallStatisticsRepository.MallIndesSalesUserStatisticsRepository(query);
}
#endregion
}
}
......@@ -21,6 +21,7 @@ using Mall.Common.Enum.MallBase;
using Mall.Model.Entity.User;
using Mall.Module.Product;
using Microsoft.AspNetCore.Authorization;
using Mall.Model.Query;
namespace Mall.WebApi.Controllers.User
{
......@@ -1357,5 +1358,61 @@ namespace Mall.WebApi.Controllers.User
return flag ? ApiResult.Success() : ApiResult.Failed();
}
#endregion
#region 商城首页统计
/// <summary>
/// 首页基础数据统计
/// </summary>
/// <returns></returns>
public ApiResult MallIndexStatistics()
{
var query = JsonConvert.DeserializeObject<StatisticsQuery>(RequestParm.msg.ToString());
query.MallBaseId = RequestParm.MallBaseId;
query.TenantId = RequestParm.TenantId;
var list = programModule.MallIndexStatisticsModule(query);
return ApiResult.Success(data: list);
}
/// <summary>
/// 销售情况统计
/// </summary>
/// <returns></returns>
public ApiResult MallIndexSalesStatistics()
{
var query = JsonConvert.DeserializeObject<StatisticsQuery>(RequestParm.msg.ToString());
query.MallBaseId = RequestParm.MallBaseId;
query.TenantId = RequestParm.TenantId;
var list = programModule.MallIndexSalesStatisticsModule(query);
return ApiResult.Success(data: list);
}
/// <summary>
/// 商品购买力TOP排行
/// </summary>
/// <returns></returns>
public ApiResult MallIndesSalesIncomeStatistics()
{
var query = JsonConvert.DeserializeObject<StatisticsQuery>(RequestParm.msg.ToString());
query.MallBaseId = RequestParm.MallBaseId;
query.TenantId = RequestParm.TenantId;
var list = programModule.MallIndesSalesIncomeStatisticsModule(query);
return ApiResult.Success(data: list);
}
/// <summary>
/// 用户购买力TOP排行
/// </summary>
/// <returns></returns>
public ApiResult MallIndesSalesUserStatistics()
{
var query = JsonConvert.DeserializeObject<StatisticsQuery>(RequestParm.msg.ToString());
query.MallBaseId = RequestParm.MallBaseId;
query.TenantId = RequestParm.TenantId;
var list = programModule.MallIndesSalesUserStatisticsModule(query);
return ApiResult.Success(data: list);
}
#endregion
}
}
\ No newline at end of file
......@@ -98,20 +98,20 @@ namespace Mall.WebApi.Filter
string cachedKey = SecurityHelper.MD5(string.Format("cmd={0}&token={1}", controllerName + "/" + actionName, token));
try
{
if (UserReidsCache.Exists(cachedKey))//判断表单是否重复提交
{
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(new ApiResult
{
resultCode = (int)ResultCode.FormRepeatSubmit,
message = "表单重复提交,请稍后再试",
data = null
});
}
else
{
//默认2秒钟之内不能重复提交
UserReidsCache.Set(cachedKey, 1, 2);
}
//if (UserReidsCache.Exists(cachedKey))//判断表单是否重复提交
//{
// actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(new ApiResult
// {
// resultCode = (int)ResultCode.FormRepeatSubmit,
// message = "表单重复提交,请稍后再试",
// data = null
// });
//}
//else
//{
// //默认2秒钟之内不能重复提交
// UserReidsCache.Set(cachedKey, 1, 2);
//}
}
catch
{
......
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