529 lines
20 KiB
C#
529 lines
20 KiB
C#
using Ninject;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Base;
|
|
using WX.CRM.IBLL.Res;
|
|
using WX.CRM.Model.Entity;
|
|
using WX.CRM.WebHelper;
|
|
|
|
namespace WX.CRM.WEB.Controllers.Res
|
|
{
|
|
public class SalesGroupController : BaseController
|
|
{
|
|
IRES_SALESGROUP _Ibll;
|
|
IRES_SALESGROUP_Q _Ibll_Q;
|
|
private IBAS_INNERUSER_Q inneruserBiz_Q;
|
|
IRES_SALESGROUP_DETAIL_Q _saleGroup_detail_Q;
|
|
IRES_SALESGROUP_DETAIL _saleGroup_detail;
|
|
[Inject]
|
|
public CACHE_BL cache_BL { get; set; }
|
|
|
|
[Inject]
|
|
public IBAS_PARAMETER _parameter { get; set; }
|
|
[Inject]
|
|
public IRES_RESETRULELOG _resetRuleLog { get; set; }
|
|
public SalesGroupController(IBAS_INNERUSER_Q _inneruserBiz_Q, IRES_SALESGROUP Ibll, IRES_SALESGROUP_Q Ibll_Q, IRES_SALESGROUP_DETAIL_Q saleGroup_detail_Q, IRES_SALESGROUP_DETAIL saleGroup_detail)
|
|
{
|
|
this._Ibll = Ibll;
|
|
this._Ibll_Q = Ibll_Q;
|
|
this.inneruserBiz_Q = _inneruserBiz_Q;
|
|
this._saleGroup_detail_Q = saleGroup_detail_Q;
|
|
this._saleGroup_detail = saleGroup_detail;
|
|
}
|
|
ValidationErrors errors = new ValidationErrors();
|
|
|
|
|
|
#region 首页
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_客服资源分组配置)]
|
|
public ActionResult Index()
|
|
{
|
|
ToolBar tb = new ToolBar();
|
|
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.客服资源分组配置, userRightId);
|
|
tb.AllowButton(toolbtn);
|
|
ViewBag.ToolBar = tb;
|
|
|
|
Pager gp = new Pager() { page = 1, rows = 10 };
|
|
string tableId = "tablist";
|
|
Table tab = new Table(tableId);
|
|
tab.AddHeadCol("GROUPID", "20%", "分组ID");
|
|
tab.AddHeadCol("NAME", "", "分组名称", true);
|
|
tab.AddHeadCol("MEMO", "", "备注");
|
|
tab.AddHeadCol("CTIME", "20%", "创建时间", true);
|
|
tab.AddHeadCol("CREATEUSER", "20%", "创建人");
|
|
tab.AddHeadRow();
|
|
ViewBag.GroupList = tab.GetTable() + Pagination.GetPage(gp, tableId, "10,15,20");
|
|
|
|
return View();
|
|
}
|
|
#endregion
|
|
|
|
#region 查询数据
|
|
[HttpPost]
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_客服资源分组配置)]
|
|
public JsonResult GetHtmlList(Pager pg, string columns)
|
|
{
|
|
string name = Request.Form["Name"];
|
|
string stime = Request.Form["STime"];
|
|
string etime = Request.Form["ETime"];
|
|
|
|
List<RES_SALESGROUP> list = _Ibll_Q.GetList_ResSalesGroup(ref pg, name, stime, etime);
|
|
|
|
Table tb = new Table(columns, true);
|
|
tb.gridPager = pg;
|
|
foreach (RES_SALESGROUP model in list)
|
|
{
|
|
tb.AddCol(model.GROUPID);
|
|
tb.AddCol(model.NAME);
|
|
tb.AddCol(model.MEMO);
|
|
tb.AddCol(model.CTIME.ToUnityString(1));
|
|
tb.AddCol(InnerUserHelper.Instance.EidAndName(model.CREATEUSER));
|
|
tb.AddRow();
|
|
}
|
|
var json = new
|
|
{
|
|
totalPages = pg.totalPages,
|
|
totalRows = pg.totalRows,
|
|
rowsList = tb.GetRows()
|
|
};
|
|
return Json(json, JsonRequestBehavior.AllowGet);
|
|
}
|
|
#endregion
|
|
|
|
#region 显示修改页面
|
|
[HttpGet]
|
|
[AuthorizeToolBar(InitRights.CONST_客服资源分组配置, InitToolBar.CONST_Edit)]
|
|
public ActionResult Edit(string id)
|
|
{
|
|
RES_SALESGROUP model = new RES_SALESGROUP();
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
model = _Ibll_Q.GetModel_ResSalesGroup(Convert.ToDecimal(id));
|
|
}
|
|
return View(model);
|
|
}
|
|
#endregion
|
|
|
|
#region 提交 新增/修改
|
|
[HttpPost]
|
|
[AuthorizeToolBar(InitRights.CONST_客服资源分组配置, InitToolBar.CONST_Edit)]
|
|
public JsonResult Edit(RES_SALESGROUP model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
if (model.GROUPID <= 0)
|
|
{
|
|
model.CREATEUSER = UserId;
|
|
model.CTIME = DateTime.Now;
|
|
return JsonHandler.InsertMessage(errors, _Ibll.Create_ResSalesGroup(ref errors, model));
|
|
}
|
|
else
|
|
{
|
|
return JsonHandler.UpdateMessage(errors, _Ibll.Update_ResSalesGroup(ref errors, model));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return JsonHandler.ValidateFailMessage();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 详细
|
|
[AuthorizeToolBar(InitRights.CONST_客服资源分组配置, InitToolBar.CONST_Details)]
|
|
public ActionResult Details(string id)
|
|
{
|
|
RES_SALESGROUP model = new RES_SALESGROUP();
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
model = _Ibll_Q.GetModel_ResSalesGroup(Convert.ToDecimal(id));
|
|
}
|
|
return View(model);
|
|
}
|
|
#endregion
|
|
|
|
#region 删除
|
|
[AuthorizeToolBar(InitRights.CONST_客服资源分组配置, InitToolBar.CONST_Delete)]
|
|
public JsonResult Delete(string id)
|
|
{
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
return JsonHandler.DeleteMessage(errors, _Ibll.Delete_ResSalesGroup(ref errors, Convert.ToDecimal(id)));
|
|
}
|
|
else
|
|
{
|
|
return JsonHandler.ManageMessage("删除失败!", false);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 员工分组明细
|
|
[AuthorizeToolBar(InitRights.CONST_客服资源分组配置, InitToolBar.CONST_Details)]
|
|
public ActionResult SalesGroupDetails(decimal id, string strategy)
|
|
{
|
|
//ToolBar
|
|
|
|
|
|
Pager pager = new Pager() { page = 1, rows = 50 };
|
|
string tableId = "tablist";
|
|
Table tab = new Table(tableId);
|
|
tab.isCheckbox = true;
|
|
tab.AddHiddenHeadCol("pkid", "ID");//影藏列
|
|
tab.AddHeadCol("map_eID", "", "工号", true);
|
|
tab.AddHeadCol("map_uName", "", "姓名", true);
|
|
tab.AddHeadCol("map_trueName", "", "真实姓名");
|
|
tab.AddHeadCol("gName", "", "销售组");
|
|
tab.AddHeadRow();
|
|
ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "50,100");
|
|
|
|
|
|
Table tab2 = new Table("tablis2");
|
|
tab2.isCheckbox = true;
|
|
tab2.AddHiddenHeadCol("pkid", "ID");//影藏列
|
|
tab2.AddHeadCol("map_eID", "65px", "工号");
|
|
tab2.AddHeadCol("map_uName", "", "姓名");
|
|
tab2.AddHeadCol("resrate", "", "比例");
|
|
tab2.AddHeadRow();
|
|
|
|
//添加分割线
|
|
tab2.AddTHeadAndTbodySplit();
|
|
|
|
|
|
var list = _saleGroup_detail_Q.GetRES_SALESGROUP_DETAIL_List(id, strategy);
|
|
foreach (var model in list)
|
|
{
|
|
tab2.AddHiddenCol(model.INNERUSERID);
|
|
tab2.AddCol(model.EID);
|
|
tab2.AddCol(model.UserName);
|
|
tab2.AddCol(string.Format("<input type='text' value='{0}' style='width:50px' onchange='setrate(this)' rate='{1}' />%", (model.RESRATE * 100).Value.ToString("f2"), (model.RESRATE * 100).Value.ToString("f2")));
|
|
tab2.AddRow();
|
|
}
|
|
//ViewBag.gridTable2Rows = tab2.GetRows();
|
|
ViewBag.gridTable2 = tab2.GetTable();
|
|
|
|
|
|
return View();
|
|
}
|
|
#endregion
|
|
|
|
#region 显示员工
|
|
/// <summary>
|
|
/// 按照条件获取数据
|
|
/// </summary>
|
|
/// <param name="pager"></param>
|
|
/// <param name="queryStr"></param>
|
|
/// <returns></returns>
|
|
[AuthorizeToolBar(InitRights.CONST_客服资源分组配置, InitToolBar.CONST_Details)]
|
|
|
|
public JsonResult SalesGroupDetailsGetHtmlList(Pager pager, string columns)
|
|
{
|
|
///System.Threading.Thread.Sleep(1000*60*10);
|
|
string innerGroupId = Request.Form["innerGroupId"];
|
|
string innerDeptId = Request.Form["innerDeptId"];
|
|
string eId = Request.Form["eId"];
|
|
string uName = Request.Form["uName"];
|
|
string gender = "";
|
|
string isDismiss = "0";
|
|
string dismissType = "-1";
|
|
string dismissTime1 = "";
|
|
string dismissTime2 = "";
|
|
string EntryDate1 = "";
|
|
string EntryDate2 = "";
|
|
string isfutures = "";
|
|
string istrader = "";
|
|
string istutor = "";
|
|
string isManager = "";
|
|
string positiveTime1 = "";
|
|
string positiveTime2 = "";
|
|
|
|
Table table = new Table(columns, true);
|
|
table.isCheckbox = true;
|
|
table.gridPager = pager;
|
|
List<WX.CRM.Model.Entity.BAS_INNERUSER_Extend> list = inneruserBiz_Q.GetList(ref pager, innerGroupId, innerDeptId, eId, uName, gender, isDismiss, dismissType, dismissTime1, dismissTime2, EntryDate1, EntryDate2, isfutures, istrader, istutor, isManager, positiveTime1, positiveTime2);
|
|
foreach (WX.CRM.Model.Entity.BAS_INNERUSER_Extend model in list)
|
|
{
|
|
table.AddHiddenCol(model.INNERUSER.PKID.ToString());
|
|
table.AddCol(model.INNERUSER.EID);
|
|
table.AddCol(model.INNERUSER.UNAME);
|
|
table.AddCol(model.INNERUSER.TRUENAME);
|
|
table.AddCol(model.GNAME);
|
|
table.AddRow();
|
|
}
|
|
|
|
var json = new
|
|
{
|
|
totalPages = pager.totalPages,
|
|
totalRows = pager.totalRows,
|
|
rowsList = table.GetRows()
|
|
};
|
|
return Json(json, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
[AuthorizeToolBar(InitRights.CONST_客服资源分组配置, InitToolBar.CONST_Details)]
|
|
|
|
public JsonResult SalesGroupDetailsGetHtmlList2(Pager pager, string isDismiss, bool isLeader, string columns)
|
|
{
|
|
|
|
Table table = new Table(columns, true);
|
|
table.isCheckbox = true;
|
|
table.gridPager = pager;
|
|
List<WX.CRM.Model.Entity.BAS_INNERUSER_Extend> list = inneruserBiz_Q.GetList(isDismiss, isLeader);
|
|
foreach (WX.CRM.Model.Entity.BAS_INNERUSER_Extend model in list)
|
|
{
|
|
table.AddHiddenCol(model.INNERUSER.PKID.ToString());
|
|
table.AddCol(model.INNERUSER.EID);
|
|
table.AddCol(model.INNERUSER.UNAME);
|
|
table.AddCol(model.INNERUSER.TRUENAME);
|
|
table.AddCol(model.GNAME);
|
|
table.AddRow();
|
|
}
|
|
|
|
var json = new
|
|
{
|
|
//totalPages = pager.totalPages,
|
|
//totalRows = pager.totalRows,
|
|
rowsList = table.GetRows()
|
|
};
|
|
return Json(json, JsonRequestBehavior.AllowGet);
|
|
}
|
|
#endregion
|
|
|
|
|
|
public JsonResult SaveSalesGroupDetial(decimal id, string userIds, string groups, int usertype, int grouptype, string acttype, string ratetype, string strategy)
|
|
{
|
|
//LogHelper.Info("userIds:" + userIds);
|
|
//LogHelper.Info("groups:" + groups);
|
|
bool result = _saleGroup_detail.SaveSalesGroupDetial(ref errors, id, userIds, groups, usertype, grouptype, acttype, ratetype, strategy);
|
|
return JsonHandler.ManageMessage(errors, result);
|
|
//return null;
|
|
}
|
|
|
|
public ActionResult Set(decimal id, string strategy)
|
|
{
|
|
|
|
Table tab = new Table("tablist");
|
|
tab.AddHeadCol("gid", "", "ID");
|
|
tab.AddHeadCol("gname", "", "组名");
|
|
tab.AddHeadCol("groupratio", "", "");
|
|
//tab.AddHiddenHeadCol("action", "操作");
|
|
tab.AddHeadRow();
|
|
|
|
tab.AddTHeadAndTbodySplit();
|
|
|
|
var userGroup = cache_BL.GetList_InnerUserGroup();
|
|
var users = cache_BL.GetUserList();
|
|
var groupleader = cache_BL.GetGroupleaders().Select(p => p.INNERUSERID);
|
|
var group = cache_BL.GetGroupList();
|
|
|
|
var list = _saleGroup_detail_Q.GetRES_SALESGROUP_DETAIL_List(id, strategy);
|
|
var subList = list.GroupBy(p => new { p.GID, p.GNAME, p.GROUPRATIO }).Select(p => new { gid = p.Key.GID, gname = p.Key.GNAME, ratio = p.Key.GROUPRATIO });
|
|
decimal userType = 1;
|
|
var actType = "user";
|
|
if (list.Any())
|
|
{
|
|
userType = list.First().USERTYPE.Value;
|
|
actType = list.First().ACTTYPE;
|
|
}
|
|
|
|
foreach (var item in group)
|
|
{
|
|
tab.AddCol(item.GID);
|
|
tab.AddCol(item.GNAME);
|
|
if (subList.Any(p => p.gid == item.GID))
|
|
{
|
|
//tab.AddCol(string.Format("<input type='text' value='{0}' style='width:50px' id='{2}' onchange='setratio(this,{1})' />", (subList.First(p => p.gid == item.GID).ratio * 100).Value.ToString("f2"), item.GID, "GRate" + item.GID));
|
|
tab.AddCol(string.Format("<input type='text' value='{0}' style='width:50px' id='{2}' onchange='setratio(this,{1})' />", subList.First(p => p.gid == item.GID).ratio.Value, item.GID, "GRate" + item.GID));
|
|
}
|
|
else
|
|
{
|
|
tab.AddCol(string.Format("<input type='text' value='{0}' style='width:50px' id='{2}' onchange='setratio(this,{1})' />", "", item.GID, "GRate" + item.GID));
|
|
}
|
|
//tab.AddHiddenCol("设置成员");
|
|
tab.AddRow();
|
|
}
|
|
|
|
var confUser = (from a in list
|
|
join u in cache_BL.GetUserList() on a.INNERUSERID equals u.PKID
|
|
select new confUserView() { Eid = u.EID, UserId = u.PKID, UName = u.UNAME, Rate = a.RESRATE, Gid = a.GID, RateType = a.RATETYPE }).ToList();
|
|
|
|
foreach (var item in confUser)
|
|
{
|
|
if (item.RateType == "rate")
|
|
item.Rate = item.Rate * 100;
|
|
}
|
|
|
|
//var unconfUser = from ug in userGroup
|
|
// join u in users on ug.INNERUSERID equals u.PKID
|
|
// where confUser.Select(p => p.Gid).Contains(ug.GID) && u.ISDISMISS == 0 && !groupleader.Contains(u.PKID) && !(confUser.Select(p => p.Eid)).Contains(u.EID)
|
|
// select new { Eid = u.EID, UserId = u.PKID, UName = u.UNAME, Gid = ug.GID };
|
|
var unconfUser = from ug in userGroup
|
|
join u in users on ug.INNERUSERID equals u.PKID
|
|
where confUser.Select(p => p.Gid).Contains(ug.GID) && u.ISDISMISS == 0 && !(confUser.Select(p => p.Eid)).Contains(u.EID)
|
|
select new confUserView() { Eid = u.EID, UserId = u.PKID, UName = u.UNAME, Rate = 0, Gid = ug.GID, RateType = "num" };
|
|
|
|
//confUser.Union(unconfUser);
|
|
|
|
foreach (var item in unconfUser)
|
|
{
|
|
// //LogHelper.Info(item.ToJson());
|
|
if (!confUser.Any(p => p.Eid == item.Eid && p.Gid == item.Gid))
|
|
{
|
|
confUser.Add(item);
|
|
}
|
|
}
|
|
|
|
ViewBag.gridTable = tab.GetTable();
|
|
ViewBag.UserType = userType;
|
|
ViewBag.Users = confUser.ToJson();
|
|
//ViewBag.unconfUsers = unconfUser.ToJson();
|
|
ViewBag.ActType = actType;
|
|
|
|
return View();
|
|
}
|
|
|
|
public JsonResult GetGroupUser(decimal gid)
|
|
{
|
|
var userGroup = cache_BL.GetList_InnerUserGroup();
|
|
var users = cache_BL.GetUserList();
|
|
var group = cache_BL.GetGroupList();
|
|
//var groupleader = cache_BL.GetGroupleaders().Select(p => p.INNERUSERID);
|
|
|
|
//var data = from ug in userGroup
|
|
// join u in users on ug.INNERUSERID equals u.PKID
|
|
// where ug.GID == gid && u.ISDISMISS == 0 && !groupleader.Contains(u.PKID)
|
|
// select new { Eid = u.EID, UserId = u.PKID, UName = u.UNAME };
|
|
var data = from ug in userGroup
|
|
join u in users on ug.INNERUSERID equals u.PKID
|
|
where ug.GID == gid && u.ISDISMISS == 0
|
|
select new { Eid = u.EID, UserId = u.PKID, UName = u.UNAME };
|
|
|
|
return Json(new { result = true, data = data }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
public ActionResult Guide(decimal id)
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public class confUserView
|
|
{
|
|
public decimal Eid { get; set; }
|
|
public decimal UserId { get; set; }
|
|
public string UName { get; set; }
|
|
public decimal? Rate { get; set; }
|
|
public decimal? Gid { get; set; }
|
|
public string RateType { get; set; }
|
|
|
|
}
|
|
|
|
//[HttpGet]
|
|
//public ActionResult Rate()
|
|
//{
|
|
// string tableId = "tablist";
|
|
// Table tab = new Table(tableId);
|
|
// tab.AddHeadCol("EID", "", "工号");
|
|
// tab.AddHeadCol("UNAME", "", "姓名");
|
|
// tab.AddHeadCol("TRUENAME", "", "真实姓名");
|
|
// tab.AddHeadCol("GNAME", "", "销售组");
|
|
// tab.AddHeadCol("ISDISMISS", "", "是否在职");
|
|
// tab.AddHeadCol("Rate", "", "自动分配比例(%)");
|
|
// tab.AddHeadCol("Rate2", "", "调整后比例(%)");
|
|
// tab.AddHeadCol("TotalCommission", "", "成交数量");
|
|
// tab.AddHeadCol("Rate3", "", "开单率(%)");
|
|
// tab.AddHeadCol("DIV_PERCENT", "", "微调比例(调整后的所有客服的值之和必须为0)");
|
|
|
|
// tab.AddHeadRow();
|
|
// ViewBag.gridTable = tab.GetTable();
|
|
// var list = wx_GroupPercent_BL.GetGroupPercentList();
|
|
// var selectList = new List<SelectListItem>();
|
|
// if (list != null)
|
|
// {
|
|
// selectList.Add(new SelectListItem { Value = "", Text = "全部" });
|
|
// foreach (var item in list)
|
|
// {
|
|
// selectList.Add(new SelectListItem { Value = item.GID.ToString(), Text = item.GNAME });
|
|
// }
|
|
// }
|
|
|
|
// return View();
|
|
//}
|
|
|
|
//[HttpPost]
|
|
//public JsonResult Rate(string rate)
|
|
//{
|
|
// return null;
|
|
//}
|
|
|
|
|
|
[HttpGet]
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_客服分配规则组)]
|
|
public ActionResult List()
|
|
{
|
|
var SaleGroup = cache_BL.GetValue_Parameter("SaleGroup");
|
|
|
|
var list = new List<SaleGroupView>();
|
|
|
|
if (SaleGroup != null)
|
|
{
|
|
list = SaleGroup.ToObject<List<SaleGroupView>>();
|
|
}
|
|
|
|
ViewBag.SaleGroup = list;
|
|
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult Add(int id, string groupname)
|
|
{
|
|
var SaleGroup = cache_BL.GetValue_Parameter("SaleGroup");
|
|
|
|
if (string.IsNullOrEmpty(SaleGroup))
|
|
{
|
|
return Json(new { result = false, msg = "notExists" }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
var list = SaleGroup.ToObject<List<SaleGroupView>>();
|
|
list.Add(new SaleGroupView() { ID = id, GroupName = groupname });
|
|
|
|
_parameter.Update_ParameterValueByKey("SaleGroup", list.ToJson());
|
|
|
|
CacheHelper.Remove("cache_Parameter_getList");
|
|
|
|
return Json(new { result = true }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult ReSet()
|
|
{
|
|
var model = _resetRuleLog.GetReSetTime();
|
|
ViewBag.ExeTime = _resetRuleLog.GetExeTime();
|
|
return View(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult ReSet(ResReSetRuleLogDto dto)
|
|
{
|
|
var ret = _resetRuleLog.Save(dto);
|
|
if (ret)
|
|
return Json(new { result = true }, JsonRequestBehavior.AllowGet);
|
|
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
[HttpGet]
|
|
public JsonResult Exec(int? sid)
|
|
{
|
|
var ret = _resetRuleLog.Exec(sid);
|
|
if (ret)
|
|
return Json(new { result = true }, JsonRequestBehavior.AllowGet);
|
|
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
}
|
|
|
|
}
|