Commit 75a85249 by guanzhenshan

增加SKU产品类型利润统计报表

parent 3b860edd
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.Models.Sku
{
/// <summary>
/// 百伦新分类
/// </summary>
public class dc_base_bailuncategory
{
public int id { get; set; }
public int c_id { get; set; }
public int c_parentid { get; set; }
public string c_ename { get; set; }
public string c_cname { get; set; }
public int c_sort { get; set; }
public int c_level { get; set; }
public string path { get; set; }
public string c_name { get; set; }
public DateTime gmt_create { get; set; }
public DateTime gmt_modified { get; set; }
public int has_delete { get; set; }
public List<dc_base_bailuncategory> childern { get; set; }
}
}
......@@ -454,6 +454,82 @@ namespace Bailun.DC.Services
}
/// <summary>
/// 获取百伦新分类
/// </summary>
/// <param name="level">等级</param>
/// <param name="parentid">父级id</param>
/// <returns></returns>
public static List<Models.Sku.dc_base_bailuncategory> ListBailunNewCategory(int? level,List<int> parentid)
{
var sql = "select c_id,c_parentid,c_name,c_sort,c_level from dc_base_bailuncategory t1 where has_delete=0 ";
if (level.HasValue)
{
sql += " and c_level="+level.Value;
}
if (parentid != null && parentid.Count > 0)
{
sql += " and c_parentid in ("+string.Join(",",parentid)+")";
}
sql += " order by c_sort ";
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
var obj = cn.Query<Models.Sku.dc_base_bailuncategory>(sql);
return obj.ToList();
}
}
/// <summary>
/// 根据分类id获取所有子级id
/// </summary>
/// <param name="parentid">父级分类id</param>
/// <returns></returns>
public static string BailunNewCategory(int parentid, List<Models.Sku.dc_base_bailuncategory> list)
{
var str = "";
if (list.Count==0)
{
list = ListBailunNewCategory(null, null);
}
var obj = list.Where(a => a.c_parentid == parentid);
foreach (var item in obj)
{
str += item.c_id+",";
GetChildrenCategory(list, item.c_id,ref str);
}
if (str.Length > 0)
{
str = str.Substring(0, str.Length - 1);
}
return str;
}
private static void GetChildrenCategory(List<Models.Sku.dc_base_bailuncategory> list,int parentid,ref string s)
{
var obj = list.Where(a => a.c_parentid == parentid);
foreach (var item in obj)
{
s += item.c_id + ",";
GetChildrenCategory(list, item.c_id, ref s);
}
}
}
#region 汇率实体 ExchangeRate
......
......@@ -1653,13 +1653,13 @@ namespace Bailun.DC.Services
/// <param name="start">付款开始时间</param>
/// <param name="end">付款结束时间</param>
/// <returns></returns>
public List<Models.Orders.dc_base_oms_sku> ListPlatformProfit(string platform, string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, bool isUSD, int? companyid, string skucategoryids, int[] producttype, int? skusource, int? shippingstrategy,int statistictype, DateTime? createstart = null, DateTime? createend = null)
public List<Models.Orders.dc_base_oms_sku> ListPlatformProfit(string platform, string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, bool isUSD, int? companyid, string skucategoryids, int[] producttype, int? skusource, int? shippingstrategy,int statistictype,int? skunewcategoryid,DateTime? createstart = null, DateTime? createend = null)
{
var str_statistic_col = "tb.platform_type";
if(statistictype==1) //sku品类
{
str_statistic_col = "t60.bailun_category_id as platform_type";
}
else if(statistictype==2) //sku来源
{
......@@ -1769,7 +1769,12 @@ namespace Bailun.DC.Services
if (statistictype == 1) //sku品类
{
sql += " join dc_base_sku t60 on tb.bailun_sku=t60.bailun_sku ";
if (skunewcategoryid.HasValue)
{
sql += " join dc_base_bailuncategory t70 on t60.bailun_category_id=t70.c_id and t70.c_level=1 and t70.has_delete=0 and t70.c_id in (" + Services.CommonServices.BailunNewCategory(skunewcategoryid.Value,null) + ")";
}
}
else if (statistictype == 2) //sku来源
{
......@@ -1852,7 +1857,7 @@ namespace Bailun.DC.Services
}
else if (statistictype == 1) //sku品类
{
sql += " group by t60.bailun_category_id";
}
else if (statistictype == 2)
{
......@@ -1884,13 +1889,13 @@ namespace Bailun.DC.Services
/// <param name="shipstart">发货开始时间</param>
/// <param name="shipend">发货结束时间</param>
/// <returns></returns>
public List<Models.Orders.dc_base_oms_sku> ListPlatformProfitByShipTime(string platform, string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, bool isUSD, int? companyid, string skucategoryids, int[] producttype, int? skusource, int? shippingstrategy,int statistictype)
public List<Models.Orders.dc_base_oms_sku> ListPlatformProfitByShipTime(string platform, string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, bool isUSD, int? companyid, string skucategoryids, int[] producttype, int? skusource, int? shippingstrategy,int statistictype, int? skunewcategoryid)
{
var str_statistic_col = "t2.platform_type";
if (statistictype == 1) //sku品类
{
str_statistic_col = "t60.bailun_category_id as platform_type";
}
else if (statistictype == 2) //sku来源
{
......@@ -1948,6 +1953,12 @@ namespace Bailun.DC.Services
//Add by Allan at 20200325
if (statistictype == 1) //sku品类
{
sql += " join dc_base_sku t60 on t2.bailun_sku=t60.bailun_sku ";
if (skunewcategoryid.HasValue)
{
sql += " join dc_base_bailuncategory t70 on t60.bailun_category_id=t70.c_id and t70.c_level=1 and t70.has_delete=0 and t70.c_id in ("+Services.CommonServices.BailunNewCategory(skunewcategoryid.Value,null)+")";
}
}
else if (statistictype == 2) //sku来源
......@@ -2029,7 +2040,7 @@ namespace Bailun.DC.Services
}
else if (statistictype == 1) //sku品类
{
sql += " group by t60.bailun_category_id";
}
else if (statistictype == 2) //sku来源
{
......
......@@ -1575,7 +1575,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
/// <returns></returns>
[BailunAuthentication(LoginMode.Enforce)]
[HttpPost]
public JsonResult PlatformProfitCountJson(string platform,string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, string currency, string skucategoryids,string product_type,int? skusource,int? shippingstrategy,string skunewcategory,int statistictype=0)
public JsonResult PlatformProfitCountJson(string platform,string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, string currency, string skucategoryids,string product_type,int? skusource,int? shippingstrategy,int? skunewcategory,int statistictype=0)
{
var _service = new Services.OrdersServices();
var companyid = HttpContextHelper.Current?.User?.GetCompanyId().ToInt32();
......@@ -1624,14 +1624,23 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
}
//Add by Allan at 20200327
var listbailunnewcategory = new List<Models.Sku.dc_base_bailuncategory>();
if (statistictype == 1)
{
listbailunnewcategory = Services.CommonServices.ListBailunNewCategory(null, null);
}
//Add by Allan at 20200320,for 增加sku级别的利润统计
if (producttype.Length>0 || skusource.HasValue || shippingstrategy.HasValue)
{
if (shipstart.HasValue || shipend.HasValue)
{
result = _service.ListPlatformProfitByShipTime(platform, website, start, end, shipstart, shipend, currency.ToUpper() == "USD", companyid, skucategoryids, producttype, skusource, shippingstrategy,statistictype);
result = _service.ListPlatformProfitByShipTime(platform, website, start, end, shipstart, shipend, currency.ToUpper() == "USD", companyid, skucategoryids, producttype, skusource, shippingstrategy,statistictype,skunewcategory);
var fbaResult = _service.ListPlatformProfit(string.IsNullOrEmpty(platform) ? "FBA" : "", website, null, null, null, null, currency.ToUpper() == "USD", companyid, skucategoryids, producttype, skusource, shippingstrategy,statistictype,shipstart, shipend);
var fbaResult = _service.ListPlatformProfit(string.IsNullOrEmpty(platform) ? "FBA" : "", website, null, null, null, null, currency.ToUpper() == "USD", companyid, skucategoryids, producttype, skusource, shippingstrategy,statistictype, skunewcategory, shipstart, shipend);
dtstart = shipstart;
......@@ -1707,7 +1716,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
}
else
{
result = _service.ListPlatformProfit(platform, website, start, end, shipstart, shipend, currency.ToUpper() == "USD", companyid, skucategoryids, producttype, skusource, shippingstrategy,statistictype);
result = _service.ListPlatformProfit(platform, website, start, end, shipstart, shipend, currency.ToUpper() == "USD", companyid, skucategoryids, producttype, skusource, shippingstrategy,statistictype, skunewcategory);
listRefund = _service.ListPlatformRefund(dtstart, dtend, companyid, platform, website, currency.ToUpper() == "USD", true, producttype, skusource, shippingstrategy,statistictype); //包含未发货的退款金额
//针对SKU FJH-L-2 做特殊处理
......@@ -1769,7 +1778,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
{
if (shipstart.HasValue || shipend.HasValue)
{
result = _service.ListPlatformProfitByShipTime(platform, website, start, end, shipstart, shipend, currency.ToUpper() == "USD", companyid, skucategoryids, null, null, null,statistictype);
result = _service.ListPlatformProfitByShipTime(platform, website, start, end, shipstart, shipend, currency.ToUpper() == "USD", companyid, skucategoryids, null, null, null,statistictype, skunewcategory);
var fbaResult = _service.ListPlatformProfit(string.IsNullOrEmpty(platform) ? "FBA" : "", website, null, null, null, null, currency.ToUpper() == "USD", companyid, skucategoryids, shipstart, shipend);
......@@ -1781,7 +1790,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
}
else
{
result = _service.ListPlatformProfit(platform, website, start, end, shipstart, shipend, currency.ToUpper() == "USD", companyid, skucategoryids,null,null,null,statistictype);
result = _service.ListPlatformProfit(platform, website, start, end, shipstart, shipend, currency.ToUpper() == "USD", companyid, skucategoryids,null,null,null,statistictype, skunewcategory);
listRefund = _service.ListPlatformRefund(dtstart, dtend, companyid, platform, website, currency.ToUpper() == "USD", true, null, null, null,statistictype); //包含未发货的退款金额
}
......@@ -1793,6 +1802,84 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
aliexpressAD = _service.ListAliexpressADCount(companyid, "", dtstart, dtend, currency.ToUpper() == "USD");
}
if (statistictype == 1) //按产品类型统计时,格式化数据
{
var listshowcategorty = new List<Models.Sku.dc_base_bailuncategory>();
if (skunewcategory.HasValue)
{
listshowcategorty = listbailunnewcategory.Where(a => a.c_parentid == skunewcategory.Value).ToList();
}
else
{
listshowcategorty = listbailunnewcategory.Where(a => a.c_level == 1).ToList();
}
var newresult = new List<Models.Orders.dc_base_oms_sku>();
foreach (var item in listshowcategorty)
{
var arrcategory = Services.CommonServices.BailunNewCategory(item.c_id, listbailunnewcategory).Split(",").ToList();
var children = result.Where(a => arrcategory.Contains(a.platform_type)).ToList();
var m = result.Where(a => a.platform_type == item.c_id.ToString()).FirstOrDefault();
if (children.Count > 0)
{
if (m == null)
{
m = new Models.Orders.dc_base_oms_sku {
platform_type= item.c_name,
cost_platform_fee = 0,
profit_total = 0,
amount_refund = 0,
amount_sales = 0,
cost_first = 0,
cost_handle_bailun = 0,
cost_handle_platform = 0,
cost_tail = 0,
amount_prepaid = 0,
cost_product = 0,
cost_fba_fee = 0,
cost_paypal_fee = 0,
order_count = 0,
customerprice = 0,
};
}
m.order_count += children.Sum(a => a.order_count);
m.customerprice += children.Sum(a => a.customerprice);
m.cost_platform_fee += children.Sum(a => a.cost_platform_fee);
m.profit_total += children.Sum(a => a.profit_total);
m.amount_refund += children.Sum(a => a.amount_refund);
m.amount_sales += children.Sum(a => a.amount_sales);
m.cost_first += children.Sum(a => a.cost_first);
m.cost_handle_bailun += children.Sum(a => a.cost_handle_bailun);
m.cost_handle_platform += children.Sum(a => a.cost_handle_platform);
m.cost_tail += children.Sum(a => a.cost_tail);
m.amount_prepaid += children.Sum(a => a.amount_prepaid);
m.cost_product += children.Sum(a => a.cost_product);
m.cost_fba_fee += children.Sum(a => a.cost_fba_fee);
m.cost_paypal_fee += children.Sum(a => a.cost_paypal_fee);
}
if (m != null)
{
newresult.Add(m);
}
}
//把格式化后的数据赋值给返回的集合
result = newresult;
}
foreach (var item in result)
{
......@@ -1849,9 +1936,9 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
{
item.platform_type = Enum.GetName(typeof(SkuSource), int.Parse(item.platform_type));
}
}
if (result.Count > 0)
{
var m = new Models.Orders.dc_base_oms_sku
......
......@@ -108,9 +108,13 @@
{
<th style="width:110px;">平台</th>
}
else if (ViewBag.statistictype == 1)
{
<th style="width:160px;">产品类型</th>
}
else
{
<th style="width:160px;">平台</th>
<th style="width:160px;">SKU来源</th>
}
......@@ -297,7 +301,31 @@
s += '<td>' + result[i].amount_refund_rate + '</td>';
$('#tb').append(s);
}
else {
else if('@ViewBag.statistictype' == 1){
var s = '<tr><td class="platform" ><div style="width:220px;" class="mules" title="' + result[i].platform_type + '">' + result[i].platform_type + '</div></td>';
s += '<td>' + result[i].order_count + '</td>';
s += '<td> ' + result[i].amount_sales + '</td>';
s += '<td>' + result[i].cost_product + '</td>';
s += '<td>' + result[i].customerprice + '</td>';
s += '<td>' + result[i].cost_platform_fee + '</td>';
s += '<td>' + result[i].cost_fba_fee + '</td>';
s += '<td>' + result[i].cost_paypal_fee + '</td>';
s += '<td>' + result[i].cost_first + '</td>';
s += '<td>' + result[i].cost_tail + '</td>';
s += '<td>' + result[i].cost_handle_bailun + '</td>';
s += '<td>' + result[i].cost_handle_platform + '</td>';
s += '<td>' + result[i].adfee + '</td>';
s += '<td>' + result[i].putawayfee + '</td>';
s += '<td>' + result[i].amount_prepaid + '</td>';
s += '<td>' + result[i].noshippingcount + '</td>';
s += '<td>' + result[i].profit_total + '</td>';
s += '<td>' + result[i].profit_rate + '</td>';
//s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'退款金额\',\'amount_refund\',1)" title="查看订单明细">' + result[i].amount_refund + '</td>';
s += '<td>' + result[i].amount_refund + '</td>';
s += '<td>' + result[i].amount_refund_rate + '</td>';
$('#tb').append(s);
}
else if('@ViewBag.statistictype' == 2){
var s = '<tr><td class="platform">' + result[i].platform_type + '</td>';
s += '<td>' + result[i].order_count + '</td>';
s += '<td> ' + result[i].amount_sales + '</td>';
......@@ -356,7 +384,31 @@
foot_s += '</tr>';
$('#footer').append(foot_s);
}
else if ('@ViewBag.statistictype' == 2) {
else if('@ViewBag.statistictype' == 2) {
var foot_s = '<tr><td class="platform">' + result[i].platform_type + '</td>';
foot_s += '<td>' + result[i].order_count + '</td>';
foot_s += '<td> ' + result[i].amount_sales + '</td>';
foot_s += '<td>' + result[i].cost_product + '</td>';
foot_s += '<td>' + result[i].customerprice + '</td>';
foot_s += '<td>' + result[i].cost_platform_fee + '</td>';
foot_s += '<td>' + result[i].cost_fba_fee + '</td>';
foot_s += '<td>' + result[i].cost_paypal_fee + '</td>';
foot_s += '<td>' + result[i].cost_first + '</td>';
foot_s += '<td>' + result[i].cost_tail + '</td>';
foot_s += '<td>' + result[i].cost_handle_bailun + '</td>';
foot_s += '<td>' + result[i].cost_handle_platform + '</td>';
foot_s += '<td>' + result[i].adfee + '</td>';
foot_s += '<td>' + result[i].putawayfee + '</td>';
foot_s += '<td>' + result[i].amount_prepaid + '</td>';
foot_s += '<td>' + result[i].noshippingcount + '</td>';
foot_s += '<td>' + result[i].profit_total + '</td>';
foot_s += '<td>' + result[i].profit_rate + '</td>';
//s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'退款金额\',\'amount_refund\',1)" title="查看订单明细">' + result[i].amount_refund + '</td>';
foot_s += '<td>' + result[i].amount_refund + '</td>';
foot_s += '<td>' + result[i].amount_refund_rate + '</td>';
$('#footer').append(foot_s);
}
else if('@ViewBag.statistictype' == 1) {
var foot_s = '<tr><td class="platform">' + result[i].platform_type + '</td>';
foot_s += '<td>' + result[i].order_count + '</td>';
foot_s += '<td> ' + result[i].amount_sales + '</td>';
......
......@@ -29,8 +29,8 @@
<body class="fixed-sidebar full-height-layout gray-bg" style="overflow:hidden">
<script type="text/javascript">
//login_localhost();
login();
login_localhost();
//login();
window.location = "@Url.Content("~/Home/Main")";
</script>
</body>
......
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