276 lines
14 KiB
C#
276 lines
14 KiB
C#
using Ninject;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Web.Mvc;
|
||
using WX.CRM.BLL.Util;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.IBLL.Wx;
|
||
using WX.CRM.Model.Entity;
|
||
using WX.CRM.WebHelper;
|
||
|
||
namespace WX.CRM.WEB.Controllers.WeiXin
|
||
{
|
||
public class CommissionUserMonthController : BaseController
|
||
{
|
||
[Inject]
|
||
public CACHE_BL cache_BL { get; set; }
|
||
private readonly IWX_COMMISSION _wxCommission;
|
||
private readonly IWX_SZZYSUBPRODUCT wx_SzzySubProduct_BL;
|
||
private readonly IWX_SZZYORDER _wx_SzzyOrder_BL;
|
||
|
||
public CommissionUserMonthController(IWX_COMMISSION wxCommission, IWX_SZZYSUBPRODUCT wx_SzzySubProduct_BL, IWX_SZZYORDER wx_SzzyOrder_BL)
|
||
{
|
||
_wxCommission = wxCommission;
|
||
this.wx_SzzySubProduct_BL = wx_SzzySubProduct_BL;
|
||
this._wx_SzzyOrder_BL = wx_SzzyOrder_BL;
|
||
}
|
||
|
||
[HttpGet]
|
||
public ActionResult Index()
|
||
{
|
||
ToolBar tool = new ToolBar();
|
||
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.订单分成导出, userRightId);
|
||
tool.AllowButton(toolbtn);
|
||
tool.AddOtherButton("Other2", "导出", "icon-export", "ExportAllPage_Click", true);
|
||
ViewBag.ToolBar = tool;
|
||
|
||
var m = int.Parse(cache_BL.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.MonthCommission));
|
||
|
||
var tab = new Table("tablist");
|
||
tab.AddHeadCol("groupid", "40px", "组别");
|
||
tab.AddHeadCol("eid", "40px", "工号");
|
||
tab.AddHeadCol("name", "40px", "姓名");
|
||
tab.AddHeadCol("isdismiss", "50px", "在/离职");
|
||
int x = 5;
|
||
for (int i = 0; i < m; i++)
|
||
{
|
||
var fieldMonth = DateTime.Now.AddMonths(-m + i + 1).ToString("yyyyMM");
|
||
tab.AddHeadCol("Num" + fieldMonth, "", "数量", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
||
x++;
|
||
tab.AddHeadCol("Price" + fieldMonth, "", fieldMonth + "¥", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
||
x++;
|
||
}
|
||
tab.AddHeadCol("numtotal", "", "总数量", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
||
x++;
|
||
tab.AddHeadCol("commissiontotal", "", "总金额", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
||
tab.AddHeadRow();
|
||
ViewBag.gridTable = tab.GetHead();
|
||
|
||
ViewBag.inneruserid = UserId;
|
||
ViewBag.userGroupId = userGroupId;
|
||
ViewBag.saleDeptId = saleDeptId;
|
||
ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId).Replace("[ZJZG]", "") + ((Eid == 6118 || Eid == 6189) ? "[FZJ]" : "");
|
||
return View();
|
||
}
|
||
|
||
|
||
[HttpPost]
|
||
//[AuthorizeToolBar(InitRights.CONST_订单分成, InitToolBar.CONST_Add)]
|
||
public JsonResult SaleUserReportHtml(Pager pager, string columns, string groupId, string userId, decimal? saleEid, decimal? isDismiss)
|
||
{
|
||
try
|
||
{
|
||
var ds = _wxCommission.GetSaleUserMonthReport(groupId, userId, saleEid ?? 0, isDismiss ?? 0);
|
||
var groupLeader = cache_BL.GetGroupleaders();
|
||
Table tb = new Table(columns, true);
|
||
List<CommissoinMonth> subProductCountList = new List<CommissoinMonth>();
|
||
if (ds.Tables[1] != null && ds.Tables[1].Rows.Count > 0)
|
||
{
|
||
subProductCountList = ds.Tables[1].ToList<CommissoinMonth>();
|
||
}
|
||
var m = int.Parse(cache_BL.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.MonthCommission));
|
||
decimal gId = 0;
|
||
foreach (DataRow model in ds.Tables[0].Rows)
|
||
{
|
||
decimal c = 0;
|
||
var entrydate = DateTime.Parse(model["entrydate"].ToString());
|
||
if (groupLeader.Any(p => p.INNERUSERID == InnerUserHelper.Instance.GetUserIdByEid(decimal.Parse(model["eid"].ToString()))))
|
||
{
|
||
tb.AddCol("color:#390", "", decimal.TryParse(model["groupid"].ToString(), out gId) ? InnerUserHelper.Instance.GetGroupName(decimal.Parse(model["groupid"].ToString())) : model["groupid"].ToString());
|
||
tb.AddCol("color:#390", "", model["eid"].ToString());
|
||
tb.AddCol("color:#390", "", model["name"].ToString());
|
||
}
|
||
else
|
||
{
|
||
tb.AddCol(decimal.TryParse(model["groupid"].ToString(), out gId) ? InnerUserHelper.Instance.GetGroupName(decimal.Parse(model["groupid"].ToString())) : model["groupid"].ToString());
|
||
tb.AddCol(model["eid"].ToString());
|
||
tb.AddCol(model["name"].ToString());
|
||
}
|
||
if (model["isdismiss"] == null)
|
||
tb.AddCol(string.Format("在职{0}月", (DateTime.Now.Year - entrydate.Year) * 12 + (DateTime.Now.Month + 1) - entrydate.Month));
|
||
else
|
||
tb.AddCol(model["isdismiss"].ToString() == "1" ? "离职" : string.Format("在职{0}月", (DateTime.Now.Year - entrydate.Year) * 12 + (DateTime.Now.Month + 1) - entrydate.Month));
|
||
|
||
for (int i = 0; i < m; i++)
|
||
{
|
||
var fieldMonth = DateTime.Now.AddMonths(-m + i + 1).ToString("yyyyMM");
|
||
var uId = Convert.ToDecimal(model["pkid"].ToString());
|
||
var info = subProductCountList.FirstOrDefault(p => p.SaleUserId == uId && p.ArrivalTime == fieldMonth);
|
||
if (info != null)
|
||
{
|
||
|
||
tb.AddCol(c % 2 == 1 ? "color:#060bff" : "", "", info.Total);
|
||
tb.AddCol(c % 2 == 1 ? "color:#060bff" : "", "", info.TotalCommission);
|
||
}
|
||
else
|
||
{
|
||
tb.AddCol("");
|
||
tb.AddCol("");
|
||
}
|
||
c++;
|
||
}
|
||
tb.AddCol("color:#f90", "", model["total"]);
|
||
tb.AddCol("color:#f90", "", model["commissiontotal"].ToString());
|
||
tb.AddRow();
|
||
}
|
||
if (ds.Tables[0].Rows.Count > 0)
|
||
{
|
||
var totalNum = subProductCountList.Sum(p => p.Total);
|
||
var totalSum = subProductCountList.Sum(p => p.TotalCommission);
|
||
tb.AddCol("合计:");
|
||
tb.AddCol("");
|
||
tb.AddCol("");
|
||
tb.AddCol("");
|
||
for (int i = 0; i < m; i++)
|
||
{
|
||
var fieldMonth = DateTime.Now.AddMonths(-m + i + 1).ToString("yyyyMM");
|
||
tb.AddCol(subProductCountList.Where(p => p.ArrivalTime == fieldMonth).Sum(p => p.Total));
|
||
tb.AddCol(subProductCountList.Where(p => p.ArrivalTime == fieldMonth).Sum(p => p.TotalCommission));
|
||
}
|
||
tb.AddCol("color:red;", "", totalNum);
|
||
tb.AddCol("color:red;", "", totalSum);
|
||
tb.AddFootRow();
|
||
}
|
||
var json = new
|
||
{
|
||
rowsList = tb.GetRows(),
|
||
foot = tb.GetFoot()
|
||
};
|
||
return Json(json, JsonRequestBehavior.AllowGet);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("SaleUserReportController:" + ex.Message + ex.StackTrace);
|
||
return JsonHandler.ManageMessage(ex.Message, false);
|
||
}
|
||
}
|
||
|
||
#region 导出
|
||
public FileResult Export(string groupId, string userId, decimal? saleEid, decimal? isDismiss)
|
||
{
|
||
var m = int.Parse(cache_BL.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.MonthCommission));
|
||
//var checkedFilds = PageRequest.GetQueryString("checkedFilds").Replace("groupid", "组别").Replace("isbalance", "是否结算");
|
||
//var checkedTitle = PageRequest.GetQueryString("checkedTitles");
|
||
string checkedFilds = Server.UrlDecode(Request.Cookies["checkedFilds"].Value).Replace("groupid", "组别").Replace("isdismiss", "在/离职");
|
||
string checkedTitle = Server.UrlDecode(Request.Cookies["checkedTitles"].Value);
|
||
Request.Cookies.Remove("checkedFilds");//用完后删除cookies
|
||
Request.Cookies.Remove("checkedTitles");//用完后删除cookies
|
||
var ds = _wxCommission.GetSaleUserMonthReport(groupId, userId, saleEid ?? 0, isDismiss ?? 0);
|
||
var dt = ds.Tables[0];
|
||
foreach (DataColumn dc in dt.Columns)
|
||
{
|
||
//if (dc.ColumnName == "groupid")
|
||
// dc.ColumnName = "组别";
|
||
//else
|
||
if (dc.ColumnName == "eid")
|
||
dc.ColumnName = "工号";
|
||
else if (dc.ColumnName == "name")
|
||
dc.ColumnName = "姓名";
|
||
else if (dc.ColumnName == "commissiontotal")
|
||
dc.ColumnName = "分成金额";
|
||
}
|
||
dt.Columns.Add(new DataColumn("组别"));
|
||
dt.Columns.Add(new DataColumn("在/离职"));
|
||
//dt.Columns.Add(new DataColumn("numtotal", typeof(decimal)));
|
||
for (int i = 0; i < m; i++)
|
||
{
|
||
var fieldMonth = DateTime.Now.AddMonths(-m + i + 1).ToString("yyyyMM");
|
||
dt.Columns.Add(new DataColumn("Num" + fieldMonth, typeof(decimal)));
|
||
dt.Columns.Add(new DataColumn("Price" + fieldMonth, typeof(decimal)));
|
||
}
|
||
List<CommissoinMonth> subProductCountList = new List<CommissoinMonth>();
|
||
if (ds.Tables[1] != null && ds.Tables[1].Rows.Count > 0)
|
||
{
|
||
subProductCountList = ds.Tables[1].ToList<CommissoinMonth>();
|
||
}
|
||
|
||
decimal gId = 0;
|
||
foreach (DataRow dataRow in dt.Rows)
|
||
{
|
||
if (decimal.TryParse(dataRow["groupid"].ToString(), out gId))
|
||
{
|
||
var entrydate = DateTime.Parse(dataRow["entrydate"].ToString());
|
||
dataRow["组别"] = InnerUserHelper.Instance.GetGroupName(decimal.Parse(dataRow["groupid"].ToString()));
|
||
if (dataRow["isdismiss"] == null)
|
||
dataRow["在/离职"] = string.Format("在职{0}月", (DateTime.Now.Year - entrydate.Year) * 12 + (DateTime.Now.Month + 1) - entrydate.Month);
|
||
else
|
||
dataRow["在/离职"] = dataRow["isdismiss"].ToString() == "1" ? "离职" : string.Format("在职{0}月", (DateTime.Now.Year - entrydate.Year) * 12 + (DateTime.Now.Month + 1) - entrydate.Month);
|
||
for (int i = 0; i < m; i++)
|
||
{
|
||
var fieldMonth = DateTime.Now.AddMonths(-m + i + 1).ToString("yyyyMM");
|
||
var info = subProductCountList.FirstOrDefault(p => p.SaleUserId == Convert.ToDecimal(dataRow["pkid"].ToString()) && p.ArrivalTime == fieldMonth);
|
||
dataRow["Num" + fieldMonth] = info != null ? info.Total : 0;
|
||
dataRow["Price" + fieldMonth] = info != null ? info.TotalCommission : 0;
|
||
|
||
}
|
||
//dataRow["numtotal"] = dataRow["total"];
|
||
}
|
||
}
|
||
//foreach (var item in list)
|
||
//{
|
||
// if (checkedFilds.Contains("[Price" + item.SUBPRODUCTID + "]"))
|
||
// {
|
||
// checkedFilds = checkedFilds.Replace("[Price" + item.SUBPRODUCTID + "]", "[Price" + item.SUBPRODUCTID + "][Num" + item.SUBPRODUCTID + "]");
|
||
// checkedTitle = checkedTitle.Replace(item.PRODUCTALIAS + "金额(数量)", item.PRODUCTALIAS + "金额," + item.PRODUCTALIAS + "数量");
|
||
// }
|
||
//}
|
||
//if (checkedFilds.Contains("[PriceOther]"))
|
||
//{
|
||
// checkedFilds = checkedFilds.Replace("[PriceOther]", "[PriceOther][NumOther]");
|
||
// checkedTitle = checkedTitle.Replace("其它金额(数量)", "其它金额,其它数量");
|
||
//}
|
||
//LogHelper.Info("checkedFilds:" + checkedFilds);
|
||
//LogHelper.Info("checkedTitle:" + checkedTitle);
|
||
return File(ExcelHelper.ExportDataTableToExcel(ds.Tables[0], "个人订单分成", checkedFilds, checkedTitle, DataFormart), "application/ms-excel", PageRequest.GetDlownLoadName("个人订单分成.xls"));
|
||
}
|
||
#endregion
|
||
|
||
private List<WX_SZZYSUBPRODUCT> getConfigSubProductList()
|
||
{
|
||
List<WX_SZZYSUBPRODUCT> list = new List<WX_SZZYSUBPRODUCT>();
|
||
var subProductIds = cache_BL.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.WeiXin_OrderCountShowColumn);
|
||
if (subProductIds != null)
|
||
{
|
||
subProductIds = subProductIds.Trim().Trim(',');
|
||
string[] idArr = subProductIds.Split(',');
|
||
decimal[] ids = idArr.Select(m => Convert.ToDecimal(m)).ToArray();
|
||
list = wx_SzzySubProduct_BL.GetList(ids);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
private string DataFormart(string key, object value)
|
||
{
|
||
string formartValue;
|
||
switch (key)
|
||
{
|
||
case "LAST7COMMISSION2":
|
||
formartValue = string.Format("{0}", value);
|
||
break;
|
||
default: formartValue = string.Format("{0}", value); break;
|
||
}
|
||
return formartValue;
|
||
}
|
||
|
||
private class CommissoinMonth
|
||
{
|
||
public decimal Total { get; set; }
|
||
public decimal TotalCommission { get; set; }
|
||
public decimal SaleUserId { get; set; }
|
||
public string ArrivalTime { get; set; }
|
||
}
|
||
}
|
||
}
|