376 lines
18 KiB
C#
376 lines
18 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Wx;
|
|
using WX.CRM.WebHelper;
|
|
|
|
namespace WX.CRM.WEB.Controllers.WeiXin
|
|
{
|
|
public class OrderResourceReportController : BaseController
|
|
{
|
|
private readonly IWX_WORKACCOUNT _wxWorkaccount;
|
|
public OrderResourceReportController(IWX_WORKACCOUNT wxWorkaccount)
|
|
{
|
|
_wxWorkaccount = wxWorkaccount;
|
|
}
|
|
|
|
[HttpGet]
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_微信推广资源统计)]
|
|
public ActionResult Index()
|
|
{
|
|
Table tab = new Table("tablist");
|
|
tab.AddHiddenHeadCol("sourcetag", "资源标签");
|
|
tab.AddHeadCol("", "35px", " ");
|
|
tab.AddHeadCol("sourcetagName", "", "资源名称");
|
|
tab.AddHeadCol("totalCount", "", "订单数量");
|
|
tab.AddHeadCol("totalCountRate", "", "订单数量比例");
|
|
tab.AddHeadCol("totalArrivalpay", "", "订单业绩");
|
|
tab.AddHeadCol("totalArrivalpayRate", "", "订单业绩比例");
|
|
tab.AddHeadCol("firstCount", "", "新开单数量");
|
|
tab.AddHeadCol("firstCountRate", "", "新开单数量比例");
|
|
tab.AddHeadCol("firstArrivalpay", "", "新开单业绩");
|
|
tab.AddHeadCol("firstArrivalpayRate", "", "新开单业绩比例");
|
|
tab.AddHeadCol("moreCount", "", "升级订单数量");
|
|
tab.AddHeadCol("moreCountRate", "", "升级订单数量比例");
|
|
tab.AddHeadCol("moreArrivalpay", "", "升级订单业绩");
|
|
tab.AddHeadCol("moreArrivalpayRate", "", "升级订单业绩比例");
|
|
tab.AddHeadRow();
|
|
ViewBag.RptList = tab.GetHead();
|
|
|
|
//ViewBag.inneruserid = UserId;
|
|
//ViewBag.userGroupId = userGroupId;
|
|
//ViewBag.saleDeptId = saleDeptId;
|
|
//ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId);
|
|
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_微信推广资源统计)]
|
|
public JsonResult Index(string month, string columns)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(month))
|
|
return JsonHandler.ManageMessage("参数错误,请确认!", false);
|
|
DateTime m1;
|
|
if (!DateTime.TryParse(month, out m1))
|
|
{
|
|
return JsonHandler.ManageMessage("参数错误,请确认!", false);
|
|
}
|
|
Table table = new Table(columns, true);
|
|
var m2 = m1.AddMonths(1);
|
|
var list = _wxWorkaccount.GetOrderResourceReport(m1, m2);
|
|
|
|
var tags = from q in list group q by new { q.sourcetag, q.sourcetagName } into g select new { g.Key.sourcetag, g.Key.sourcetagName };
|
|
|
|
var style1 = "text-align:left;padding-left:10px;";
|
|
var style2 = "text-align:left;padding-left:30px;";
|
|
var style3 = "text-align:left;padding-left:10px;color:red;font-weight:bold";
|
|
|
|
var allCount = list.Sum(p => p.totalCount);
|
|
var allArrivalpay = list.Sum(p => p.totalArrivalpay);
|
|
|
|
foreach (var tag in tags)
|
|
{
|
|
var tagList = list.Where(p => p.sourcetag == tag.sourcetag);
|
|
table.AddHiddenCol(tag.sourcetag);
|
|
table.AddCol("<span class='expand-activity txt-expand' title='" + tag.sourcetag + "'> </span>");
|
|
table.AddCol(style1, "", tag.sourcetagName);
|
|
table.AddCol(style1, "btr", "", tagList.Sum(p => p.totalCount));
|
|
table.AddCol(style1, "btr", "", string.Format("{0:p}", tagList.Sum(p => p.totalCount) / allCount));
|
|
table.AddCol(style1, "btr", "", tagList.Sum(p => p.totalArrivalpay));
|
|
table.AddCol(style1, "btr", "", string.Format("{0:p}", tagList.Sum(p => p.totalArrivalpay) / allArrivalpay));
|
|
table.AddCol(style1, "btr2", "", tagList.Sum(p => p.firstCount));
|
|
table.AddCol(style1, "btr2", "", string.Format("{0:p}", tagList.Sum(p => p.firstCount) / allCount));
|
|
table.AddCol(style1, "btr2", "", tagList.Sum(p => p.firstArrivalpay));
|
|
table.AddCol(style1, "btr2", "", string.Format("{0:p}", tagList.Sum(p => p.firstArrivalpay) / allArrivalpay));
|
|
table.AddCol(style1, "", tagList.Sum(p => p.moreCount));
|
|
table.AddCol(style1, "", string.Format("{0:p}", tagList.Sum(p => p.moreCount) / allCount));
|
|
table.AddCol(style1, "", tagList.Sum(p => p.moreArrivalpay));
|
|
table.AddCol(style1, "", string.Format("{0:p}", tagList.Sum(p => p.moreArrivalpay) / allArrivalpay));
|
|
table.AddRow();
|
|
foreach (var item in tagList)
|
|
{
|
|
table.AddHiddenCol(item.sourcetag);
|
|
table.AddCol("");
|
|
table.AddCol(style2, "", item.sourcemonth.ToString("yyyy-MM"));
|
|
table.AddCol(style2, "btr", "", item.totalCount);
|
|
table.AddCol(style2, "btr", "", string.Format("{0:p}", item.totalCount / allCount));
|
|
table.AddCol(style2, "btr", "", item.totalArrivalpay);
|
|
table.AddCol(style2, "btr", "", string.Format("{0:p}", item.totalArrivalpay / allArrivalpay));
|
|
table.AddCol(style2, "btr2", "", item.firstCount);
|
|
table.AddCol(style2, "btr2", "", string.Format("{0:p}", item.firstCount / allCount));
|
|
table.AddCol(style2, "btr2", "", item.firstArrivalpay);
|
|
table.AddCol(style2, "btr2", "", string.Format("{0:p}", item.firstArrivalpay / allArrivalpay));
|
|
table.AddCol(style2, "", item.moreCount);
|
|
table.AddCol(style2, "", string.Format("{0:p}", item.moreCount / allCount));
|
|
table.AddCol(style2, "", item.moreArrivalpay);
|
|
table.AddCol(style2, "", string.Format("{0:p}", item.moreArrivalpay / allArrivalpay));
|
|
table.AddRow("style='display:none' typeName='" + tag.sourcetag + "'");
|
|
}
|
|
}
|
|
if (list.Count > 0)
|
|
{
|
|
table.AddHiddenCol("0");
|
|
table.AddCol("<span class='expand-activity txt-expand' title='0'> </span>");
|
|
table.AddCol(style3, "", "全部");
|
|
table.AddCol("", "btr", "", allCount);
|
|
table.AddCol("", "btr", "", string.Format("{0:p}", allCount / allCount));
|
|
table.AddCol("", "btr", "", allArrivalpay);
|
|
table.AddCol("", "btr", "", string.Format("{0:p}", allArrivalpay / allArrivalpay));
|
|
table.AddCol("", "btr2", "", list.Sum(p => p.firstCount));
|
|
table.AddCol("", "btr2", "", string.Format("{0:p}", list.Sum(p => p.firstCount) / allCount));
|
|
table.AddCol("", "btr2", "", list.Sum(p => p.firstArrivalpay));
|
|
table.AddCol("", "btr2", "", string.Format("{0:p}", list.Sum(p => p.firstArrivalpay) / allArrivalpay));
|
|
table.AddCol(list.Sum(p => p.moreCount));
|
|
table.AddCol(string.Format("{0:p}", list.Sum(p => p.moreCount) / allCount));
|
|
table.AddCol(list.Sum(p => p.moreArrivalpay));
|
|
table.AddCol(string.Format("{0:p}", list.Sum(p => p.moreArrivalpay) / allArrivalpay));
|
|
|
|
table.AddFootRow();
|
|
//var monthList = list.OrderBy(p => p.sourcemonth);
|
|
var monthList = (from q in list group q by q.sourcemonth into g select g).OrderBy(p => p.Key);
|
|
foreach (var m in monthList)
|
|
{
|
|
var item = list.Where(p => p.sourcemonth == m.Key);
|
|
table.AddHiddenCol("0");
|
|
table.AddCol("");
|
|
table.AddCol(style2, "", m.Key.ToString("yyyy-MM"));
|
|
table.AddCol(style2, "btr", "", item.Sum(p => p.totalCount));
|
|
table.AddCol(style2, "btr", "", string.Format("{0:p}", item.Sum(p => p.totalCount) / allCount));
|
|
table.AddCol(style2, "btr", "", item.Sum(p => p.totalArrivalpay));
|
|
table.AddCol(style2, "btr", "", string.Format("{0:p}", item.Sum(p => p.totalArrivalpay) / allArrivalpay));
|
|
table.AddCol(style2, "btr2", "", item.Sum(p => p.firstCount));
|
|
table.AddCol(style2, "btr2", "", string.Format("{0:p}", item.Sum(p => p.firstCount) / allCount));
|
|
table.AddCol(style2, "btr2", "", item.Sum(p => p.firstArrivalpay));
|
|
table.AddCol(style2, "btr2", "", string.Format("{0:p}", item.Sum(p => p.firstArrivalpay) / allArrivalpay));
|
|
table.AddCol(style2, "", item.Sum(p => p.moreCount));
|
|
table.AddCol(style2, "", string.Format("{0:p}", item.Sum(p => p.moreCount) / allCount));
|
|
table.AddCol(style2, "", item.Sum(p => p.moreArrivalpay));
|
|
table.AddCol(style2, "", string.Format("{0:p}", item.Sum(p => p.moreArrivalpay) / allArrivalpay));
|
|
table.AddFootRow("style='display:none' typeName='0'");
|
|
}
|
|
}
|
|
var json = new
|
|
{
|
|
rowsList = table.GetRows(),
|
|
foot = table.GetFoot()
|
|
};
|
|
return Json(json, JsonRequestBehavior.AllowGet);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error("OrderResourceReportController:Index" + ex.Message + ex.StackTrace);
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
}
|
|
|
|
public JsonResult Chart(string month)
|
|
{
|
|
if (string.IsNullOrEmpty(month))
|
|
return JsonHandler.ManageMessage("参数错误,请确认!", false);
|
|
DateTime m1;
|
|
if (!DateTime.TryParse(month, out m1))
|
|
{
|
|
return JsonHandler.ManageMessage("参数错误,请确认!", false);
|
|
}
|
|
var m2 = m1.AddMonths(1);
|
|
var list = _wxWorkaccount.GetOrderResourceReport(m1, m2);
|
|
|
|
var tags = (from q in list group q by new { q.sourcetag, q.sourcetagName } into g select new { g.Key.sourcetag, g.Key.sourcetagName }).ToList();
|
|
tags.Insert(0, new { sourcetag = "0", sourcetagName = "全部" });
|
|
|
|
var chartList = new List<ChartDto>();
|
|
|
|
#region
|
|
var chart = new ChartDto();
|
|
var legendArr = new string[] { "新开单数量", "升级订单数量" };
|
|
chart.title = new ChartDto.ChartTitle() { text = "订单来源统计销量" };
|
|
chart.tooltip = new ChartDto.ChartTooltip() { };
|
|
chart.legend = new ChartDto.ChartLegend() { data = legendArr };
|
|
chart.xAxis = new ChartDto.ChartXAxis() { data = tags.Select(p => p.sourcetagName).ToArray() };
|
|
chart.yAxis = new ChartDto.ChartYAxis() { };
|
|
var series = new List<ChartDto.ChartSeries>();
|
|
var dataArr = new List<object>();
|
|
var dataArr2 = new List<object>();
|
|
foreach (var tag in tags)
|
|
{
|
|
if (tag.sourcetag == "0")
|
|
{
|
|
dataArr.Add(list.Sum(p => p.firstCount));
|
|
dataArr2.Add(list.Sum(p => p.moreCount));
|
|
}
|
|
else
|
|
{
|
|
var tagList = list.Where(p => p.sourcetag == tag.sourcetag);
|
|
dataArr.Add(tagList.Sum(p => p.firstCount));
|
|
dataArr2.Add(tagList.Sum(p => p.moreCount));
|
|
}
|
|
//var tagList = list.Where(p => p.sourcetag == tag.sourcetag);
|
|
//dataArr.Add(new { value = tagList.Sum(p => p.totalCount), name = tag.sourcetagName });
|
|
//dataArr2.Add(new { value = tagList.Sum(p => p.firstCount), name = tag.sourcetagName + "新单" });
|
|
//dataArr2.Add(new { value = tagList.Sum(p => p.moreCount), name = tag.sourcetagName + "升级单" });
|
|
}
|
|
var info = new ChartDto.ChartSeries()
|
|
{
|
|
name = "新开单数量",
|
|
type = "bar",
|
|
stack = "销量",
|
|
data = dataArr.ToArray()
|
|
};
|
|
var info2 = new ChartDto.ChartSeries()
|
|
{
|
|
name = "升级订单数量",
|
|
type = "bar",
|
|
stack = "销量",
|
|
data = dataArr2.ToArray()
|
|
};
|
|
series.Add(info);
|
|
series.Add(info2);
|
|
chart.series = series;
|
|
#endregion
|
|
|
|
#region
|
|
var chart2 = new ChartDto();
|
|
var legendArr2 = new string[] { "新开单业绩", "升级订单业绩" };
|
|
chart2.title = new ChartDto.ChartTitle() { text = "订单来源统计业绩" };
|
|
chart2.tooltip = new ChartDto.ChartTooltip() { };
|
|
chart2.legend = new ChartDto.ChartLegend() { data = legendArr2 };
|
|
chart2.xAxis = new ChartDto.ChartXAxis() { data = tags.Select(p => p.sourcetagName).ToArray() };
|
|
chart2.yAxis = new ChartDto.ChartYAxis() { };
|
|
var series2 = new List<ChartDto.ChartSeries>();
|
|
var dataArr12 = new List<object>();
|
|
var dataArr22 = new List<object>();
|
|
foreach (var tag in tags)
|
|
{
|
|
if (tag.sourcetag == "0")
|
|
{
|
|
dataArr12.Add(list.Sum(p => p.firstArrivalpay));
|
|
dataArr22.Add(list.Sum(p => p.moreArrivalpay));
|
|
}
|
|
else
|
|
{
|
|
var tagList = list.Where(p => p.sourcetag == tag.sourcetag);
|
|
dataArr12.Add(tagList.Sum(p => p.firstArrivalpay));
|
|
dataArr22.Add(tagList.Sum(p => p.moreArrivalpay));
|
|
}
|
|
}
|
|
var info12 = new ChartDto.ChartSeries()
|
|
{
|
|
name = "新开单业绩",
|
|
type = "bar",
|
|
stack = "业绩",
|
|
data = dataArr12.ToArray()
|
|
};
|
|
var info22 = new ChartDto.ChartSeries()
|
|
{
|
|
name = "升级订单业绩",
|
|
type = "bar",
|
|
stack = "业绩",
|
|
data = dataArr22.ToArray()
|
|
};
|
|
series2.Add(info12);
|
|
series2.Add(info22);
|
|
chart2.series = series2;
|
|
#endregion
|
|
|
|
chartList.Add(chart);
|
|
chartList.Add(chart2);
|
|
|
|
return Json(chartList, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_微信推广资源统计)]
|
|
public FileResult Export(string month)
|
|
{
|
|
if (string.IsNullOrEmpty(month))
|
|
return null;
|
|
//return JsonHandler.ManageMessage("参数错误,请确认!", false);
|
|
DateTime m1;
|
|
if (!DateTime.TryParse(month, out m1))
|
|
{
|
|
//return JsonHandler.ManageMessage("参数错误,请确认!", false);
|
|
return null;
|
|
}
|
|
//var checkedFilds = PageRequest.GetQueryString("checkedFilds");
|
|
//var checkedTitle = PageRequest.GetQueryString("checkedTitles");
|
|
var checkedFilds = "[sourcetagName][sourcemonth][totalCount][totalArrivalpay][firstCount][firstArrivalpay][moreCount][moreArrivalpay]";
|
|
var checkedTitle = "资源名称,资源分布月份,订单数量,订单业绩,新开单数量,新开单业绩,升级订单数量,升级订单业绩";
|
|
var m2 = m1.AddMonths(1);
|
|
var list = _wxWorkaccount.GetOrderResourceReport(m1, m2);
|
|
var data = new List<OrderResourceReportExport>();
|
|
foreach (var item in list)
|
|
{
|
|
data.Add(new OrderResourceReportExport()
|
|
{
|
|
sourcetag = item.sourcetag,
|
|
sourcetagName = item.sourcetagName,
|
|
sourcemonth = item.sourcemonth.ToString("yyyy-MM"),
|
|
totalCount = item.totalCount,
|
|
totalArrivalpay = item.totalArrivalpay,
|
|
firstCount = item.firstCount,
|
|
firstArrivalpay = item.firstArrivalpay,
|
|
moreCount = item.moreCount,
|
|
moreArrivalpay = item.moreArrivalpay
|
|
});
|
|
}
|
|
return File(ExcelHelper.ExportListModelToExcel<OrderResourceReportExport>(data, "订单来源统计", 60000, checkedFilds, checkedTitle, null), "application/ms-excel", PageRequest.GetDlownLoadName("订单来源统计.xls"));
|
|
|
|
}
|
|
|
|
public class OrderResourceReportExport
|
|
{
|
|
public string sourcetag { get; set; }
|
|
public string sourcetagName { get; set; }
|
|
public string sourcemonth { get; set; }
|
|
public decimal totalCount { get; set; }
|
|
public decimal totalArrivalpay { get; set; }
|
|
public decimal firstCount { get; set; }
|
|
public decimal firstArrivalpay { get; set; }
|
|
public decimal moreCount { get; set; }
|
|
public decimal moreArrivalpay { get; set; }
|
|
}
|
|
|
|
public class ChartDto
|
|
{
|
|
public ChartTitle title { get; set; }
|
|
public ChartTooltip tooltip { get; set; }
|
|
public ChartLegend legend { get; set; }
|
|
public ChartXAxis xAxis { get; set; }
|
|
public ChartYAxis yAxis { get; set; }
|
|
public List<ChartSeries> series { get; set; }
|
|
|
|
public class ChartTitle
|
|
{
|
|
public string text { get; set; }
|
|
}
|
|
public class ChartTooltip
|
|
{
|
|
}
|
|
public class ChartLegend
|
|
{
|
|
public string[] data { get; set; }
|
|
}
|
|
public class ChartXAxis
|
|
{
|
|
public string[] data { get; set; }
|
|
}
|
|
public class ChartYAxis
|
|
{
|
|
|
|
}
|
|
public class ChartSeries
|
|
{
|
|
public string name { get; set; }
|
|
public string type { get; set; }
|
|
public string stack { get; set; }
|
|
public object[] data { get; set; }
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|