Commit 1642e8f9 by zhouminghui

fix

parent 2bcf8d22
......@@ -5,16 +5,21 @@
/// </summary>
public class PlatformTypeMonthlyStatisticsDto
{
public string month { get; set; }
/// <summary>
///
/// </summary>
public string platform_type { get; set; }
/// <summary>
/// 对应平台总销售额
/// 对应平台总销售额(计算汇率的)
/// </summary>
public decimal total_amount_sales { get; set; }
/// <summary>
/// 原币
/// </summary>
public decimal original_amount { get; set; }
/// <summary>
/// 订单数
/// </summary>
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.Models
{
public class dc_month_sales_profit_order_summary
{
public int id { get; set; }
public string month { get; set; }
/// <summary>
///
/// </summary>
public string platform_type { get; set; }
/// <summary>
/// 对应平台总销售额
/// </summary>
public decimal total_amount_sales { get; set; }
public decimal original_amount { get; set; }
/// <summary>
/// 订单数
/// </summary>
public decimal total_order { get; set; }
/// <summary>
/// 0销售额,1成本
/// </summary>
public int summary_type { get; set; }
public string financecategoryname { get; set; }
public DateTime createdate { get; set; }
}
}
......@@ -43,6 +43,16 @@ namespace Bailun.DC.Models
/// 产品销售额 原币
/// </summary>
public decimal amount_sales { get; set; }
/// <summary>
/// 产品销售额 人民币
/// </summary>
public decimal amount_sales_rmb
{
get
{
return amount_sales * seller_order_exchange_rate * quantity_shipped;
}
}
/// <summary>
......
......@@ -465,15 +465,31 @@ and s1.management_cost_name = @managementcostname";
/// <param name="month"></param>
/// <param name="financecategory"></param>
/// <returns></returns>
public List<PlatformTypeMonthlyStatisticsDto> GetPlatformTypeMonthlyStatistics(string month, string financecategory)
public List<PlatformTypeMonthlyStatisticsDto> GetPlatformTypeMonthlyStatistics(string month, string financecategory,bool isCost = false,bool falg = false)
{
StringBuilder sql = new StringBuilder();
sql.Append("SELECT t1.platform_type, SUM(t1.amount_sales)AS total_amount_sales,COUNT(0)AS total_order FROM dc_month_sales_profit_orderdetail AS t1 ");
if (isCost)
{
sql.Append(@"SELECT t1.platform_type, SUM(t1.cost_product) AS original_amount,
SUM(t1.cost_product * t1.quantity_shipped) AS total_amount_sales,COUNT(0) total_order FROM dc_month_sales_profit_orderdetail AS t1 ");
}
else
{
sql.Append(@"SELECT t1.platform_type, SUM(t1.amount_sales) AS original_amount,
SUM(t1.amount_sales * t1.seller_order_exchange_rate * t1.quantity_shipped) AS total_amount_sales,COUNT(0)AS total_order 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("产品", "")}%'");
if (falg)
{
sql.Append($"AND t1.financecategoryname LIKE '{financecategory}%'");
}
else
{
sql.Append($"AND t1.financecategoryname LIKE '{financecategory.Replace("产品", "")}%'");
}
}
else if (financecategory == "其他")
{
......@@ -486,12 +502,13 @@ and s1.management_cost_name = @managementcostname";
/// <summary>
/// 分页查询月销售明细
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public CommonApiResponseDto<MonthProfitOrderDetailPageOutputDto> GetMonthProfitOrderDetailPage(MonthProfitOrderDetailPageInputDto input)
/// <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);
......@@ -745,8 +762,11 @@ from dc_base_finance_fee where cost_status=4 and (is_lend is null or is_lend=1 o
or (is_lend=2 and cost_form=1)) and pay_time>= @start and pay_time< @end ");
parameters.Add("start", start);
parameters.Add("end", end);
if (feeName.Contains("广州歌戈儿生活科技有限公司"))
if (feeName.Contains("其中:歌戈儿收入"))
{
sql.Append(" and company_name like '%歌戈儿%' and type_name ='销售收入' ");
}
else if (feeName.Contains("广州歌戈儿生活科技有限公司"))
{
sql.Append(" and company_name like '%歌戈儿%' ");
//sql.Append(" and (company_name like '%歌戈儿%' and (type_name!='销售收入' and type_name!='出口退税款')) ");
......@@ -830,14 +850,18 @@ JOIN order_fee_config s2
ON s2.id = s1.order_fee_config_id WHERE s1.amountval != 0 AND s1.month = @month ");
}
parameters.Add("month", input.Month);
//if (input.FeeName == "FBA费")
//{
// sql.Append("AND s2.datacenter_col LIKE '%佣金及平台费-亚马逊FBA%'");
//}
//else
//{
if (input.FeeName.Contains("加:营业外收入"))
{
sql.Append("AND s2.datacenter_col LIKE '%营业外收入'");
}
else if (input.FeeName.Contains("减:营业外支出"))
{
sql.Append("AND s2.datacenter_col LIKE '%营业外支出'");
}
else
{
sql.Append($"AND s2.datacenter_col LIKE '%{input.FeeName}'");
//}
}
if (isPage)
{
//sql.Append($" LIMIT {input.PageNumber} OFFSET {(input.PageIndex - 1) * input.PageNumber}");
......@@ -1007,6 +1031,25 @@ ORDER BY t1.createtime DESC ";
result = result.ToPageResult(input.PageIndex, total, data);
return new CommonApiResponseDto<PageResult<List<dc_month_sales_profit_orderdetail>>> { Data = result };
}
public List<PlatformTypeMonthlyStatisticsDto> GetMonthSalesProfiOrderSummary(string month, string financecategory, string isCost = "")
{
var param = new DynamicParameters();
var sql = $@"SELECT * FROM dc_month_sales_profit_order_summary WHERE month = @month
AND summary_type = @cost
AND financecategoryname LIKE '{financecategory.Replace("产品", "")}%' ";
param.Add("month", month);
if (isCost.Contains("成本"))
{
param.Add("cost", 1);
}
else
{
param.Add("cost", 0);
}
var data = SimpleCRUD.Query<PlatformTypeMonthlyStatisticsDto>(sql.ToString(), param, GlobalConfig.ConnectionString).ToList();
return data;
}
#endregion
#region 同步数据
......@@ -1030,21 +1073,26 @@ ORDER BY t1.createtime DESC ";
//var field = new MonthSalesProfitDto();
//var name = field.amount_sales_jingyou.GetType().GetCustomAttribute<System.ComponentModel.DisplayNameAttribute>().DisplayName;
//销售额
oldData.amount_sales_jingyou = Math.Round(GetPlatformTypeMonthlyStatistics(time, "精油产品").Sum(x => x.total_amount_sales), 2);
oldData.amount_sales_dianzi = Math.Round(GetPlatformTypeMonthlyStatistics(time, "电子产品").Sum(x => x.total_amount_sales), 2);
oldData.amount_sales_jiaju = Math.Round(GetPlatformTypeMonthlyStatistics(time, "家居产品").Sum(x => x.total_amount_sales), 2);
oldData.amount_sales_meirongmj = Math.Round(GetPlatformTypeMonthlyStatistics(time, "美容美甲产品").Sum(x => x.total_amount_sales), 2);
oldData.amount_sales_fuzhuang = Math.Round(GetPlatformTypeMonthlyStatistics(time, "服装").Sum(x => x.total_amount_sales), 2);
oldData.amount_sales_other = Math.Round(GetPlatformTypeMonthlyStatistics(time, "其他").Sum(x => x.total_amount_sales), 2);
oldData.fee_refund = Math.Round(GetMonthProfitPlatformPlatformSummary(new GetMonthProfitPlatformDetailInput { Month = time }).Data.Sum(x => x.RefundRmb.Value), 2);//取数待定
//成本
oldData.cost_jingyou = Math.Round(GetPlatformTypeMonthlyStatistics(time, "精油产品").Sum(x => x.total_amount_sales), 2);
oldData.cost_dianzi = Math.Round(GetPlatformTypeMonthlyStatistics(time, "电子产品").Sum(x => x.total_amount_sales), 2);
oldData.cost_jiaju = Math.Round(GetPlatformTypeMonthlyStatistics(time, "家居产品").Sum(x => x.total_amount_sales), 2);
oldData.cost_meirongmj = Math.Round(GetPlatformTypeMonthlyStatistics(time, "美容美甲产品").Sum(x => x.total_amount_sales), 2);
oldData.cost_fuzhuang = Math.Round(GetPlatformTypeMonthlyStatistics(time, "服装").Sum(x => x.total_amount_sales), 2);
oldData.cost_other = Math.Round(GetPlatformTypeMonthlyStatistics(time, "其他").Sum(x => x.total_amount_sales), 2);
oldData.amount_sales_jingyou = Math.Round(GetMonthSalesProfiOrderSummary(time, "精油产品").Sum(x => x.total_amount_sales), 2);
oldData.amount_sales_dianzi = Math.Round(GetMonthSalesProfiOrderSummary(time, "电子产品").Sum(x => x.total_amount_sales), 2);
oldData.amount_sales_jiaju = Math.Round(GetMonthSalesProfiOrderSummary(time, "家居产品").Sum(x => x.total_amount_sales), 2);
oldData.amount_sales_meirongmj = Math.Round(GetMonthSalesProfiOrderSummary(time, "美容美甲产品").Sum(x => x.total_amount_sales), 2);
oldData.amount_sales_fuzhuang = Math.Round(GetMonthSalesProfiOrderSummary(time, "服装").Sum(x => x.total_amount_sales), 2);
oldData.amount_sales_other = Math.Round(GetMonthSalesProfiOrderSummary(time, "其他").Sum(x => x.total_amount_sales), 2);
oldData.fee_refund = Math.Round(GetMonthProfitPlatformPlatformSummary(new GetMonthProfitPlatformDetailInput { Month = time }).Data.Sum(x => x.RefundRmb.Value), 2);
//总销售额
oldData.amount_sales = Math.Round((oldData.amount_sales_dianzi + oldData.amount_sales_fuzhuang + oldData.amount_sales_jiaju
+ oldData.amount_sales_jingyou + oldData.amount_sales_meirongmj + oldData.amount_sales_other) - oldData.fee_refund, 2);
//成本
oldData.cost_jingyou = Math.Round(GetMonthSalesProfiOrderSummary(time, "精油产品","成本").Sum(x => x.total_amount_sales), 2);
oldData.cost_dianzi = Math.Round(GetMonthSalesProfiOrderSummary(time, "电子产品", "成本").Sum(x => x.total_amount_sales), 2);
oldData.cost_jiaju = Math.Round(GetMonthSalesProfiOrderSummary(time, "家居产品", "成本").Sum(x => x.total_amount_sales), 2);
oldData.cost_meirongmj = Math.Round(GetMonthSalesProfiOrderSummary(time, "美容美甲产品", "成本").Sum(x => x.total_amount_sales), 2);
oldData.cost_fuzhuang = Math.Round(GetMonthSalesProfiOrderSummary(time, "服装", "成本").Sum(x => x.total_amount_sales), 2);
oldData.cost_other = Math.Round(GetMonthSalesProfiOrderSummary(time, "其他", "成本").Sum(x => x.total_amount_sales), 2);
//总成本
oldData.cost = Math.Round(oldData.amount_sales_dianzi + oldData.amount_sales_fuzhuang + oldData.amount_sales_jiaju
+ oldData.amount_sales_jingyou + oldData.amount_sales_meirongmj + oldData.amount_sales_other, 2);
//平台费用
oldData.fee_ad = Math.Round(ExportMonthProfitFeePlatformFeeDetail(
new GetMonthProfitPlatformDetailInput { Month = time, FeeName = "广告及宣传费" })
......@@ -1061,6 +1109,8 @@ ORDER BY t1.createtime DESC ";
oldData.fee_ohtre = Math.Round(ExportMonthProfitFeePlatformFeeDetail(
new GetMonthProfitPlatformDetailInput { Month = time, FeeName = "佣金及平台费-其他平台" })
.Where(m => m.AmountValRmb != null).Sum(x => x.AmountValRmb.Value), 2);
//总平台费
oldData.fee_platform = Math.Round(oldData.fee_ad + oldData.fee_fba + oldData.fee_nofba + oldData.fee_ebay + oldData.fee_ohtre, 2);
//物流仓储费用
oldData.fee_logistics_first = Math.Round(ExportMonthProfitFeePlatformFeeDetail(
new GetMonthProfitPlatformDetailInput { Month = time, FeeName = "头程运输-平台" })
......@@ -1086,6 +1136,9 @@ ORDER BY t1.createtime DESC ";
oldData.fee_nostorage = Math.Round(ExportMonthProfitFeePlatformFeeDetail(
new GetMonthProfitPlatformDetailInput { Month = time, FeeName = "仓储费-非平台" })
.Where(m => m.AmountValRmb != null).Sum(x => x.AmountValRmb.Value), 2);
//总物流仓储费
oldData.fee_logistics_storage = Math.Round(oldData.fee_logistics_first + oldData.fee_nologistics_first + oldData.fee_logistics_tail + oldData.fee_nologistics_tail
+ oldData.fee_logistics_direct + oldData.fee_nologistics_direct + oldData.fee_storage + oldData.fee_nostorage, 2);
//加:营业外收入
oldData.incoming_non_operating = Math.Round(ExportMonthProfitFeePlatformFeeDetail(
......@@ -1101,6 +1154,9 @@ ORDER BY t1.createtime DESC ";
oldData.fee_sales_taxes = Math.Round(ExportMonthProfitFeePlatformFeeDetail(
new GetMonthProfitPlatformDetailInput { Month = time, FeeName = "税金" })
.Where(m => m.AmountValRmb != null).Sum(x => x.AmountValRmb.Value), 2);
//其中:歌戈儿收入
var operating = GetMonthProfitFeeManagementCostDetail(time, "其中:歌戈儿收入").Data;
oldData.incoming_gogirl = Math.Round(operating.Count == 0 ? 0 : operating.Last().AmountRmb.Value, 2);
//管理成本
var bl_xg = GetMonthProfitFeeManagementCostDetail(time, "香港百伦科技有限公司").Data;
......@@ -1124,10 +1180,28 @@ ORDER BY t1.createtime DESC ";
oldData.managercost_dizhi = Math.Round(dizhi.Count == 0 ? 0 : dizhi.Last().AmountRmb.Value, 2);
oldData.managercost_gzlk = Math.Round(gzlk.Count == 0 ? 0 : gzlk.Last().AmountRmb.Value, 2);
oldData.managercost_gzcy = Math.Round(gzcy.Count == 0 ? 0 : gzcy.Last().AmountRmb.Value, 2);
//总管理成本
oldData.managercost_count = Math.Round(oldData.managecost_bl_xg + oldData.managecost_bl_gz + oldData.managecost_meijia + oldData.managercost_yangshan
+ oldData.managercost_xinhuilan + oldData.managercost_gzdz + oldData.managercost_ys + oldData.managercost_dizhi + oldData.managercost_gzlk
+ oldData.managercost_gzcy, 2);
oldData.profit_sales = Math.Round(GetMonthSalesProfitDetail(new MonthProfitOrderDetailPageInputDto { Month = time }, false)
.Data.Data.Sum(x => x.sale_profit), 2);
//oldData.profit_sales = Math.Round(GetMonthSalesProfitDetail(new MonthProfitOrderDetailPageInputDto { Month = time }, false)
//.Data.Data.Sum(x => x.sale_profit), 2);
//销售费用合计》平台费用+物流仓储费+税金
oldData.fee_sales_count = Math.Round(oldData.fee_platform + oldData.fee_logistics_storage + oldData.fee_sales_taxes, 2);
//销售利润》总销售额-总成本-销售费用合计
oldData.profit_sales = Math.Round(oldData.amount_sales - oldData.cost - oldData.fee_sales_count, 2);
//销售毛利润》销售利润/总销售额
oldData.rate_profit_sales = Math.Round(oldData.profit_sales / oldData.amount_sales, 2);
//营业利润》销售利润-总管理成本
oldData.profit = Math.Round(oldData.profit_sales - oldData.managercost_count, 2);
//营业毛利率》营业利润/总销售额
oldData.rate_profit = Math.Round(oldData.profit / oldData.amount_sales, 2);
//实际利润》营业利润+加:其他收入+加:营业外收入+减:营业外支出
oldData.actual_profit = Math.Round(oldData.profit + oldData.incoming_other + oldData.incoming_non_operating + oldData.pay_non_operating, 2);
//净利润》实际利润/总销售额
oldData.rate_profit_actual = Math.Round(oldData.actual_profit / oldData.amount_sales, 2);
//保存
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
......@@ -1145,6 +1219,72 @@ ORDER BY t1.createtime DESC ";
return false;
}
}
/// <summary>
/// 同步生成销售额和成本的汇总数据
/// </summary>
public bool SyncMonthSalesProfiOrderDetail(DateTime date)
{
try
{
var time = string.Empty;
#if DEBUG
time = date.ToString("yyyy-MM");
#else
time = DateTime.Now.AddMonths(-1).ToString("yyyy-MM");
#endif
var list = new List<dc_month_sales_profit_order_summary>();
var sql = "select financecategoryname from dc_month_sales_profit_orderdetail group by financecategoryname";
var categoryName = SimpleCRUD.Query<string>(sql, null, GlobalConfig.ConnectionString_read).ToList();
foreach (var item in categoryName)
{
var name = item;
if (string.IsNullOrWhiteSpace(name))
{
name = "其他";
}
list.AddRange(GetPlatformTypeMonthlyStatistics(time, name, false, true).Select(x => new dc_month_sales_profit_order_summary
{
month = time,
total_amount_sales = Math.Round(x.total_amount_sales, 2),
original_amount = Math.Round(x.original_amount, 2),
platform_type = x.platform_type,
total_order = x.total_order,
createdate = DateTime.Now,
financecategoryname = name,
summary_type = 0
}));
list.AddRange(GetPlatformTypeMonthlyStatistics(time, name, true, true).Select(x => new dc_month_sales_profit_order_summary
{
month = time,
total_amount_sales = Math.Round(x.total_amount_sales, 2),
original_amount = Math.Round(x.original_amount, 2),
platform_type = x.platform_type,
total_order = x.total_order,
createdate = DateTime.Now,
financecategoryname = name,
summary_type = 1
}));
}
foreach (var item in list)
{
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == ConnectionState.Closed)
{
cn.Open();
}
cn.Insert(item);
}
}
return true;
}
catch (Exception e)
{
Console.WriteLine($"错误信息:{ e.Message}");
return false;
}
}
#endregion
}
}
......@@ -336,10 +336,10 @@ namespace Bailun.DC.WebApi.Controllers
/// <param name="financecategory"></param>
/// <returns></returns>
[HttpGet("getPlatformTypeMonthlyStatistics")]
public CommonApiResponseDto<List<PlatformTypeMonthlyStatisticsDto>> GetPlatformTypeMonthlyStatistics(string month, string financecategory)
public CommonApiResponseDto<List<PlatformTypeMonthlyStatisticsDto>> GetPlatformTypeMonthlyStatistics(string month, string financecategory,string isCost)
{
var result = new CommonApiResponseDto<List<PlatformTypeMonthlyStatisticsDto>> { Data = new List<PlatformTypeMonthlyStatisticsDto>()};
result.Data = new FinanceService().GetPlatformTypeMonthlyStatistics(month, financecategory);
result.Data = new FinanceService().GetMonthSalesProfiOrderSummary(month, financecategory,isCost);
return result;
}
......@@ -364,11 +364,11 @@ namespace Bailun.DC.WebApi.Controllers
{
input.IsPages = false;
var dataList = new FinanceService().GetMonthProfitOrderDetailPage(input).Data.Items;
var colNames = new List<string> {"财务分类","平台类型","订单号", "SKU", "销售额","发货量","发货时间","创建时间"};
var colNames = new List<string> {"财务分类","平台类型","订单号", "SKU", "销售额(原币)", "销售额RMB", "汇率", "发货量","发货时间","创建时间"};
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")}");
list.Add($"{item.financecategoryname}|{item.platform_type}|{item.origin_order_id}|{item.bailun_sku}|{item.amount_sales}|{item.amount_sales_rmb}|{item.seller_order_exchange_rate}|{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") + "\\";
......@@ -508,7 +508,7 @@ namespace Bailun.DC.WebApi.Controllers
return File(ms, "text/csv", $"{input.Month}_月销售费用合计》费用利润表明细.csv");
}
[HttpGet("getReFundTest")]
[HttpGet("syncMonthSalesProfit")]
public object GetReFundTest(DateTime time)
{
return new FinanceService().SyncMonthSalesProfit(time);
......@@ -516,6 +516,10 @@ namespace Bailun.DC.WebApi.Controllers
//var data = Dapper.SimpleCRUD.Query<dc_month_sales_profit_orderdetail>(sql, null, Common.GlobalConfig.ConnectionString).FirstOrDefault();
//return data;
}
[HttpGet("syncMonthSalesProfiOrderDetail")]
public object SyncMonthSalesProfiOrderDetail(DateTime date)
=>new FinanceService().SyncMonthSalesProfiOrderDetail(date);
#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