TG.WXCRM.V4/WEB/Controllers/WeiXin/WXTsAddPiciController.cs

351 lines
13 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Ninject;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web.Mvc;
using WX.CRM.Common;
using WX.CRM.IBLL.Base;
using WX.CRM.IBLL.TS;
using WX.CRM.IBLL.Util;
using WX.CRM.IBLL.Wx;
using WX.CRM.WebHelper;
namespace WX.CRM.WEB.Controllers.WeiXin
{
public class WXTsAddPiciController : BaseController
{
ValidationErrors errors = new ValidationErrors();
[Inject]
public IWX_TSADDPICI wx_TsAddPici_BL { get; set; }
[Inject]
public IBAS_PARAMETER_Q bas_Parameter_BL { get; set; }
[Inject]
public WX.CRM.IBLL.Util.ICACHE_Q cache_q { get; set; }
[Inject]
public IBAS_INNERGROUP_Q wx_Group_BL { get; set; }
[Inject]
public IWX_RCONTACT wx_Rcontact_BL { get; set; }
[Inject]
public ICACHE_Q _cacheQ { get; set; }
public WXTsAddPiciController()
{
}
[HttpGet]
[AuthorizeRedirect(InitRights.CONST_微信助手申请日报表)]
public ActionResult DayReport()
{
string tableId = "tablist";
Table tab = new Table(tableId);
//Pager pager = new Pager() { page = 1, rows = int.MaxValue };
tab.AddHeadCol("dayTime", "", "日期");
tab.AddHeadCol("ApplyNum", "", "申请人数");
tab.AddHeadCol("UnApplyNum", "", "未申请人数");
tab.AddHeadCol("times", "", "申请批次");
tab.AddHeadCol("total", "", "申请资源数");
tab.AddHeadCol("webChatResourceCount", "", "当日添加资源数");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable();
string roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId);//获取员工角色
var list = wx_Group_BL.GetList();
var selectList = new List<SelectListItem>();
bool isSanbuzj = false;//是否是三部总监
if (roleCodes.IndexOf("[ZJ]") > -1 || roleCodes.IndexOf("[GLY]") > -1 || roleCodes.IndexOf("[ZJZL]") > -1)
{
isSanbuzj = false;
}
else if (roleCodes.IndexOf("[SDZJ]") > -1)
{
isSanbuzj = true;
}
if (list != null)
{
selectList.Add(new SelectListItem { Value = "0", Text = "全部" });
foreach (var item in list)
{
if (isSanbuzj == true && item.SALEDEPTID == saleDeptId)//三部的总监只能看到自己部门的数据
{
selectList.Add(new SelectListItem { Value = item.GID.ToString(), Text = item.GNAME });
}
else if (isSanbuzj == false)
{
selectList.Add(new SelectListItem { Value = item.GID.ToString(), Text = item.GNAME });
}
}
}
if (roleCodes.IndexOf("[ZJ]") > -1 || roleCodes.IndexOf("[GLY]") > -1 || roleCodes.IndexOf("[ZJZL]") > -1 || roleCodes.IndexOf("[SDZJ]") > -1)
{
ViewBag.showGroup = "1";
string threeDeptId = _cacheQ.GetValue_Parameter("Sys_SaleDeptId_Three");//有三部ID显示显示部门组件
if (!string.IsNullOrEmpty(threeDeptId) && roleCodes.IndexOf("[SDZJ]") > -1)
{
decimal ndeptid = Convert.ToDecimal(threeDeptId);
ViewBag.showDept = "0";
}
else if (!string.IsNullOrEmpty(threeDeptId))
{
ViewBag.showDept = "1";
}
}
ViewBag.groupList = selectList;
return View();
}
[HttpPost]
[AuthorizeRedirect(InitRights.CONST_微信助手申请日报表)]
public JsonResult DayReportHtml(string columns, string sdCTime, string edCTime, decimal? groupId, decimal? deptId)
{
try
{
if (string.IsNullOrEmpty(sdCTime) || string.IsNullOrEmpty(edCTime))
{
return JsonHandler.ManageMessage("参数有误,请确认!", false);
}
DateTime? sTime = null;
DateTime? eTime = null;
DateTime stTime;
DateTime etTime;
DateTime.TryParse(sdCTime, out stTime);
sTime = stTime;
DateTime.TryParse(edCTime, out etTime);
eTime = etTime.AddDays(1);
Table table = new Table(columns, true);
if (!groupId.HasValue)
{
groupId = userGroupId;
}
bool isSanbuzj = false;//是否是三部总监
if (!deptId.HasValue)
{
string roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId);//获取员工角色
if (roleCodes.IndexOf("[ZJ]") > -1 || roleCodes.IndexOf("[GLY]") > -1 || roleCodes.IndexOf("[ZJZL]") > -1)
{
isSanbuzj = false;
}
else if (roleCodes.IndexOf("[SDZJ]") > -1)
{
isSanbuzj = true;
}
if (isSanbuzj == true)
{
deptId = 3;
}
else
{
deptId = 0;
}
}
var dt = wx_TsAddPici_BL.TsaddpicihisByDay(sTime, eTime, groupId.Value, deptId.Value);
var dt2 = wx_TsAddPici_BL.GetSaleUserList(groupId.Value, deptId.Value);
decimal saleUserCount = 0;
if (dt2 != null && dt2.Rows.Count > 0)
{
saleUserCount = dt2.Rows.Count;
}
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow model in dt.Rows)
{
//table.AddCol(InnerUserHelper.Instance.GetEidAndTrueName(InnerUserHelper.Instance.GetUserIdByEid(Convert.ToDecimal(model["eid"]))));
table.AddCol(model["daytime"]);
var linkUrl = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>", "申请员工", "/TS/WXTsAddPici/ApplyList?type=" + deptId + "&day=" + Convert.ToDateTime(model["daytime"]).ToString("yyyy-MM-dd") + "&groupId=" + groupId, model["ApplyNum"]);
table.AddCol(linkUrl);
var unApplyNum = saleUserCount - Convert.ToDecimal(model["ApplyNum"]);
if (unApplyNum > 0)
{
var linkUrl2 = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>", "未申请员工", "/TS/WXTsAddPici/UnApplyList?type=" + deptId + "&day=" + Convert.ToDateTime(model["daytime"]).ToString("yyyy-MM-dd") + "&groupId=" + groupId, unApplyNum);
table.AddCol(linkUrl2);
}
else
{
table.AddCol(0);
}
table.AddCol(model["times"]);
table.AddCol(model["total"]);
table.AddCol(model["webChatResourceCount"]);
table.AddRow();
}
}
var json = new { rowsList = table.GetRows() };
return Json(json, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("WXTsAddPiciController:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
[HttpGet]
[AuthorizeRedirect(InitRights.CONST_微信助手申请日报表)]
public ActionResult UnApplyList(string day, decimal groupId, decimal? type)
{
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("eid", "", "员工");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable();
ViewBag.day = day;
ViewBag.groupId = groupId;
return View();
}
[HttpPost]
[AuthorizeRedirect(InitRights.CONST_微信助手申请日报表)]
public JsonResult UnApplyListHtml(string columns, decimal groupId, decimal? type)
{
try
{
var day = Request["day"];
DateTime? time = null;
if (!string.IsNullOrEmpty(day))
{
DateTime t;
DateTime.TryParse(day, out t);
time = t;
}
DateTime? time2 = null;
if (time.HasValue)
{
time2 = time.Value.AddDays(1);
}
Table table = new Table(columns, true);
var dt = wx_TsAddPici_BL.GetDismissUserList(time, time2, groupId, type.Value);
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow model in dt.Rows)
{
table.AddCol(InnerUserHelper.Instance.GetEidAndTrueName(InnerUserHelper.Instance.GetUserIdByEid(Convert.ToDecimal(model["eid"]))));
table.AddRow();
}
}
var json = new { rowsList = table.GetRows() };
return Json(json, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("DismissListHtml:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
[HttpGet]
[AuthorizeRedirect(InitRights.CONST_微信助手申请日报表)]
public ActionResult ApplyList(string day, decimal groupId)
{
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("eid", "", "员工");
tab.AddHeadCol("Alias", "", "微信号");
tab.AddHeadCol("times", "", "申请批次数");
tab.AddHeadCol("total", "", "申请资源数");
tab.AddHeadCol("total", "", day + "添加资源数");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable();
ViewBag.day = day;
ViewBag.groupId = groupId;
return View();
}
[HttpPost]
[AuthorizeRedirect(InitRights.CONST_微信助手申请日报表)]
public JsonResult ApplyListHtml(string columns, decimal groupId, decimal? type)
{
try
{
var day = Request["day"];
DateTime? time = null;
if (!string.IsNullOrEmpty(day))
{
DateTime t;
DateTime.TryParse(day, out t);
time = t;
}
DateTime? time2 = null;
if (time.HasValue)
{
time2 = time.Value.AddDays(1);
}
Table table = new Table(columns, true);
var ds = wx_Rcontact_BL.GetWebChatResourceList(time, time2, type);
var webChatList = new List<WebChatResource>();
if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
{
webChatList = ds.Tables[0].ToList<WebChatResource>();
}
var dt = wx_TsAddPici_BL.GetUserTsaddpicihisByDay(time, time2, groupId, type);
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow model in dt.Rows)
{
table.AddCol(InnerUserHelper.Instance.GetEidAndTrueName(InnerUserHelper.Instance.GetUserIdByEid(Convert.ToDecimal(model["eid"]))));
table.AddCol(model["alias"]);
table.AddCol(model["times"]);
table.AddCol(model["total"]);
var webChat = webChatList.Where(m => m.alias == model["alias"].ToString()).FirstOrDefault();
if (webChat != null)
{
var linkUrl = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>", "微信助手日资源详细", "/WeiXin/WXRcontact/WebChatResource?jobusername=" + webChat.jobusername + "&day=" + time.Value.ToString("yyyy-MM-dd"), webChat.num);
table.AddCol(linkUrl);
}
else
{
table.AddCol("0");
}
table.AddRow();
}
}
var json = new { rowsList = table.GetRows() };
return Json(json, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("DismissListHtml:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
private class WebChatResource
{
public string jobusername { get; set; }
public string alias { get; set; }
public decimal num { get; set; }
}
}
}