Commit ce71387f by guanzhenshan
parents 88813d78 0b564433
using Bailun.DC.Models.Common.Page;
namespace Bailun.DC.Models.Dtos.Finance
{
public class MonthProfitOrderDetailPageInputDto : PageRequest
{
/// <summary>
/// 月份
/// </summary>
public string Month { get; set; }
/// <summary>
/// 平台类型
/// </summary>
public string PlatformType { get; set; }
/// <summary>
/// 产品类型
/// </summary>
public string FinanceCategory { get; set; }
/// <summary>
/// 发货时间
/// </summary>
public string[] ShippingTimes { get; set; }
/// <summary>
/// 是否分页
/// </summary>
public bool IsPages { get; set; } = true;
}
}
using Bailun.DC.Models.Common.Page;
using System.Collections.Generic;
namespace Bailun.DC.Models.Dtos.Finance
{
public class MonthProfitOrderDetailPageOutputDto
{
public MonthProfitOrderDetailPageOutputDto()
{
Pages = new PageResponse();
Items = new List<dc_month_sales_profit_orderdetail>();
}
/// <summary>
///
/// </summary>
public List<dc_month_sales_profit_orderdetail> Items { get; set; }
/// <summary>
///
/// </summary>
public PageResponse Pages { get; set; }
}
}
namespace Bailun.DC.Models.WebApiModels
{
/// <summary>
/// 月销售利润平台统计
/// </summary>
public class PlatformTypeMonthlyStatisticsDto
{
/// <summary>
///
/// </summary>
public string platform_type { get; set; }
/// <summary>
/// 对应平台总销售额
/// </summary>
public decimal total_amount_sales { get; set; }
}
}
......@@ -59,7 +59,7 @@ namespace Bailun.DC.Services.WebApiService
}
}
}
var jsonStr = GenerateStr(Col, listValue);
var jsonStr = GenerateStr(Col, listValue);
//dtos.Col.Add(new columnsObj
//{
// key = "key",
......@@ -172,7 +172,7 @@ namespace Bailun.DC.Services.WebApiService
sqlText.Append(" AND t1.type_name = @CostTypeName ");
parameters.Add("CostTypeName", input.CostTypeName);
}
if (input.CreateTime != null && input.CreateTime.Length == 2&& !string.IsNullOrWhiteSpace(input.CreateTime[0]) && !string.IsNullOrWhiteSpace(input.CreateTime[1]))
if (input.CreateTime != null && input.CreateTime.Length == 2 && !string.IsNullOrWhiteSpace(input.CreateTime[0]) && !string.IsNullOrWhiteSpace(input.CreateTime[1]))
{
sqlText.Append(" AND t1.create_time >= @StartCreateTime AND t1.create_time < @EndCreateTime ");
parameters.Add("StartCreateTime", Convert.ToDateTime(input.CreateTime[0]));
......@@ -329,20 +329,20 @@ and s2.company_type = @CorporateEntity ";
private List<ManagementCost> GetManagementCostList(GetCashFlowStatementInput input)
{
// var sql = $@"select *
//from dc_base_finance_management_cost s1
//LEFT JOIN dc_base_finance_fee s2
//ON s1.management_cost_type = s2.cost_form
//and s1.management_cost_category = s2.accounting_subject_name
//and s1.management_cost_title = s2.type_name
//LEFT JOIN dc_base_finance_company s3
//ON s3.company_name = s2.company_name
//where s2.cost_status = 4
//and (s2.is_lend is null or s2.is_lend = 1
//or (s2.is_lend = 2 and s2.lend_balance > 0) or (s2.is_lend = 2 and s2.cost_form = 1))
//and s2.pay_time >= @paytimeStrat
//and s2.pay_time < @paytimeEnd
//and s3.company_type = @companyType ";
// var sql = $@"select *
//from dc_base_finance_management_cost s1
//LEFT JOIN dc_base_finance_fee s2
//ON s1.management_cost_type = s2.cost_form
//and s1.management_cost_category = s2.accounting_subject_name
//and s1.management_cost_title = s2.type_name
//LEFT JOIN dc_base_finance_company s3
//ON s3.company_name = s2.company_name
//where s2.cost_status = 4
//and (s2.is_lend is null or s2.is_lend = 1
//or (s2.is_lend = 2 and s2.lend_balance > 0) or (s2.is_lend = 2 and s2.cost_form = 1))
//and s2.pay_time >= @paytimeStrat
//and s2.pay_time < @paytimeEnd
//and s3.company_type = @companyType ";
var sql = @"SELECT
s2.amount,s2.cost_form,s2.amount_rmb,
s2.is_lend,s2.lend_balance,
......@@ -404,7 +404,7 @@ and s1.management_cost_name = @managementcostname";
/// <param name="Col"></param>
/// <param name="listValue"></param>
/// <returns></returns>
private (List<columnsObj>,string) GenerateStr(List<string> Col, List<Tuple<string, List<decimal>>> listValue)
private (List<columnsObj>, string) GenerateStr(List<string> Col, List<Tuple<string, List<decimal>>> listValue)
{
var colList = new List<columnsObj>();
colList.Add(new columnsObj
......@@ -455,5 +455,90 @@ and s1.management_cost_name = @managementcostname";
var data = SimpleCRUD.Query<MonthSalesProfitDto>(sql, null, GlobalConfig.ConnectionString).ToList();
return data;
}
#region 月利润销售表
/// <summary>
/// 查询月销售平台统计数据
/// </summary>
/// <param name="month"></param>
/// <param name="financecategory"></param>
/// <returns></returns>
public List<PlatformTypeMonthlyStatisticsDto> GetPlatformTypeMonthlyStatistics(string month, string financecategory)
{
StringBuilder sql = new StringBuilder();
sql.Append("SELECT t1.platform_type, SUM(t1.amount_sales)AS total_amount_sales FROM dc_month_sales_profit_orderdetail AS t1 ");
sql.Append("INNER JOIN dc_base_oms_sku AS t2 ON t1.orderskuid = t2.id ");
sql.Append($"WHERE t1.`month` ='{month}' ");
if (!string.IsNullOrEmpty(financecategory) && financecategory != "其他")
{
sql.Append($"AND t1.financecategoryname LIKE '{financecategory.Replace("产品", "")}%'");
}
else if (financecategory == "其他")
{
sql.Append($" AND t1.financecategoryname ='' ");
}
sql.Append(" GROUP BY t1.platform_type;");
var data = SimpleCRUD.Query<PlatformTypeMonthlyStatisticsDto>(sql.ToString(), null, GlobalConfig.ConnectionString).ToList();
return data;
}
/// <summary>
/// 分页查询月销售明细
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public CommonApiResponseDto<MonthProfitOrderDetailPageOutputDto> GetMonthProfitOrderDetailPage(MonthProfitOrderDetailPageInputDto input)
{
var result = new CommonApiResponseDto<MonthProfitOrderDetailPageOutputDto> { Data = new MonthProfitOrderDetailPageOutputDto() };
var sqlWhere = BuildMonthSalesProfitOrderdetailPageQuerySqlWhere(input, out DynamicParameters parameters);
if (!input.IsPages)
{
result.Data.Items = SimpleCRUD.Query<dc_month_sales_profit_orderdetail>(sqlWhere, parameters, GlobalConfig.ConnectionString).ToList();
return result;
}
using (var cn = new MySqlConnection(GlobalConfig.ConnectionString))
{
int total = 0;
result.Data.Items = cn.Page<dc_month_sales_profit_orderdetail>(input.PageIndex, input.PageNumber, sqlWhere, ref total, parameters).AsList();
result.Data.Pages.CurrentPage = input.PageIndex;
result.Data.Pages.PageSize = input.PageNumber;
result.Data.Pages.Total = total;
}
return result;
}
private string BuildMonthSalesProfitOrderdetailPageQuerySqlWhere(MonthProfitOrderDetailPageInputDto input, out DynamicParameters parameters)
{
parameters = new DynamicParameters();
StringBuilder sqlText = new StringBuilder();
sqlText.Append($@"SELECT t1.*, t2.origin_order_id, t2.bailun_order_id
FROM dc_month_sales_profit_orderdetail t1
JOIN dc_base_oms_sku t2 ON t1.orderskuid = t2.id
WHERE
t1. MONTH = @Month ");
parameters.Add("Month", input.Month);
if (!string.IsNullOrWhiteSpace(input.PlatformType))
{
sqlText.Append(" AND t1.platform_type = @PlatformType ");
parameters.Add("PlatformType", input.PlatformType);
}
if (!string.IsNullOrWhiteSpace(input.FinanceCategory) && (input.FinanceCategory != "其他" || input.FinanceCategory != "其它"))
{
sqlText.Append($" AND t1.financecategoryname like '{input.FinanceCategory.Replace("产品", "")}%' ");
}
else if (input.FinanceCategory == "其他" || input.FinanceCategory != "其它")
{
sqlText.Append(" and t1.financecategoryname = '' ");
}
if (input.ShippingTimes != null && input.ShippingTimes.Length == 2 && !string.IsNullOrWhiteSpace(input.ShippingTimes[0]) && !string.IsNullOrWhiteSpace(input.ShippingTimes[1]))
{
sqlText.Append(" AND t1.shipping_time >= @StartLastModifyDate AND t1.shipping_time < @EndLastModifyDate ");
parameters.Add("StartLastModifyDate", Convert.ToDateTime(input.ShippingTimes[0]));
parameters.Add("EndLastModifyDate", Convert.ToDateTime(input.ShippingTimes[1]));
}
sqlText.Append(" ORDER BY t1.createtime DESC ");
return sqlText.ToString();
}
#endregion
}
}
......@@ -311,6 +311,60 @@ namespace Bailun.DC.WebApi.Controllers
ms.Position = 0;
return File(ms, "text/csv", $"{filename}.csv");
}
/// <summary>
/// 查询月销售平台统计数据
/// </summary>
/// <param name="month"></param>
/// <param name="financecategory"></param>
/// <returns></returns>
[HttpGet("getPlatformTypeMonthlyStatistics")]
public CommonApiResponseDto<List<PlatformTypeMonthlyStatisticsDto>> GetPlatformTypeMonthlyStatistics(string month, string financecategory)
{
var result = new CommonApiResponseDto<List<PlatformTypeMonthlyStatisticsDto>> { Data = new List<PlatformTypeMonthlyStatisticsDto>()};
result.Data = new FinanceService().GetPlatformTypeMonthlyStatistics(month, financecategory);
return result;
}
/// <summary>
/// 分页查询月销售明细
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("getMonthProfitOrderDetailPage")]
public CommonApiResponseDto<MonthProfitOrderDetailPageOutputDto> GetMonthProfitOrderDetailPage([FromBody]MonthProfitOrderDetailPageInputDto input)
{
return new FinanceService().GetMonthProfitOrderDetailPage(input);
}
/// <summary>
/// 导出月销售利润明细
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("exportMonthProfitOrderDetail")]
public ActionResult ExportMonthProfitOrderDetail([FromBody] MonthProfitOrderDetailPageInputDto input)
{
input.IsPages = false;
var dataList = new FinanceService().GetMonthProfitOrderDetailPage(input).Data.Items;
var colNames = new List<string> {"财务分类","平台类型","订单号", "SKU", "销售额","发货量","发货时间","创建时间"};
var list = new List<string>();
foreach (var item in dataList)
{
list.Add($"{item.financecategoryname}|{item.platform_type}|{item.origin_order_id}|{item.bailun_sku}|{item.amount_sales}|{item.quantity_shipped}|{item.shipping_time.ToString("yyyy-MM-dd HH:mm:ss")}|{item.createtime.ToString("yyyy-MM-dd HH:mm:ss")}");
}
var guid = Guid.NewGuid().ToString();
var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
ToCSV(list, colNames, guid, filepath);
var ms = new System.IO.MemoryStream();
using (var f = new System.IO.FileStream(filepath + guid + ".csv", System.IO.FileMode.Open))
{
f.CopyTo(ms);
}
ms.Position = 0;
return File(ms, "text/csv", "月销售利润表明细.csv");
}
#endregion
}
}
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