310 lines
11 KiB
C#
310 lines
11 KiB
C#
using Newtonsoft.Json;
|
|
using Ninject;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.Common.Layui;
|
|
using WX.CRM.IBLL.Res;
|
|
using WX.CRM.IBLL.Util;
|
|
using WX.CRM.Model.MAP;
|
|
using WX.CRM.WebHelper;
|
|
|
|
namespace WX.CRM.WEB.Controllers.Res
|
|
{
|
|
public class SalesRuleController : BaseController
|
|
{
|
|
[Inject]
|
|
public ICACHE_Q _cache { get; set; }
|
|
|
|
[Inject]
|
|
public IRES_SALES_RULE _salesRule { get; set; }
|
|
|
|
[Inject]
|
|
public IRES_SALESGROUP_Q _salesGroup { get; set; }
|
|
|
|
[HttpGet]
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_客服分配规则列表)]
|
|
public ActionResult Index()
|
|
{
|
|
//ToolBar
|
|
ToolBar tool = new ToolBar();
|
|
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.客服分配规则列表, userRightId);
|
|
tool.AllowButton(toolbtn);
|
|
tool.AddOtherButton("Other1", "编辑状态", "icon-detail", "Set_Click", true);
|
|
ViewBag.ToolBar = tool;
|
|
|
|
var salesGroup = _cache.GetValue_Parameter("SaleGroup");
|
|
|
|
var salesGroupList = new List<SaleGroupView>();
|
|
if (!string.IsNullOrWhiteSpace(salesGroup))
|
|
{
|
|
salesGroupList = salesGroup.ToObject<List<SaleGroupView>>();
|
|
}
|
|
|
|
ViewBag.SalesGroup = salesGroupList;
|
|
|
|
var level = _cache.GetValue_Parameter("SaleLevel");
|
|
|
|
var levelList = new List<ResSalesLevelView>();
|
|
if (!string.IsNullOrWhiteSpace(level))
|
|
{
|
|
levelList = level.ToObject<List<ResSalesLevelView>>();
|
|
}
|
|
foreach (var item in levelList)
|
|
{
|
|
item.LevelName = $"{item.LevelName}({item.LevelNum})";
|
|
}
|
|
ViewBag.Level = levelList;
|
|
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_客服分配规则列表)]
|
|
public JsonResult GetResSalesRule(string columns, Laypage pager, QueryUserComboDto usercomboDto, ResSalesRuleQueryDto dto)
|
|
{
|
|
var layUidata = new LayuiData<ResSalesRuleListView>();
|
|
var list = _salesRule.GetResSalesRule(ref pager, usercomboDto, UserId, dto);
|
|
layUidata.msg = "数据加载成功";
|
|
layUidata.code = 0;
|
|
layUidata.data = list;
|
|
layUidata.count = pager.count;
|
|
return Json(layUidata);
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult List()
|
|
{
|
|
var level = _cache.GetValue_Parameter("SaleLevel");
|
|
|
|
ViewBag.Level = level.ToObject<List<ResSalesLevelView>>();
|
|
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult List(QueryUserComboDto usercomboDto, ResSalesRuleQueryDto dto)
|
|
{
|
|
var pager = new Laypage() { page = 1, limit = int.MaxValue };
|
|
|
|
var list = _salesRule.GetResSalesRule(ref pager, usercomboDto, UserId, dto);
|
|
|
|
var data = new LayuiData<ResSalesRuleListView>()
|
|
{
|
|
msg = "数据加载成功!",
|
|
count = 0,
|
|
code = 0,
|
|
data = list
|
|
};
|
|
return Json(data, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult Add()
|
|
{
|
|
var salesGroup = _cache.GetValue_Parameter("SaleGroup");
|
|
|
|
var salesGroupList = new List<SaleGroupView>();
|
|
if (!string.IsNullOrWhiteSpace(salesGroup))
|
|
{
|
|
salesGroupList = salesGroup.ToObject<List<SaleGroupView>>();
|
|
}
|
|
|
|
ViewBag.SalesGroup = salesGroupList;
|
|
|
|
var level = _cache.GetValue_Parameter("SaleLevel");
|
|
|
|
var levelList = new List<ResSalesLevelView>();
|
|
if (!string.IsNullOrWhiteSpace(level))
|
|
{
|
|
levelList = level.ToObject<List<ResSalesLevelView>>();
|
|
}
|
|
foreach (var item in levelList)
|
|
{
|
|
item.LevelName = $"{item.LevelName}({item.LevelNum})";
|
|
}
|
|
ViewBag.Level = levelList;
|
|
|
|
var isMoreGroup = _cache.GetValue_Parameter("IsMoreGroup");
|
|
ViewBag.IsMoreGroup = isMoreGroup;
|
|
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult notSet(QueryUserComboDto usercomboDto, int? sgid, string name)
|
|
{
|
|
var list = _salesRule.GetResSalesUnRule(usercomboDto, sgid, name, UserId);
|
|
|
|
var data = new LayuiData<ResSaleUnRuleListView>()
|
|
{
|
|
msg = "数据加载成功!",
|
|
count = 0,
|
|
code = 0,
|
|
data = list
|
|
};
|
|
return Json(data, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult Add(string eids, int level, int sgid, int islimit)
|
|
{
|
|
try
|
|
{
|
|
//LogHelper.Info("eids:" + eids + "--level:" + level.ToString());
|
|
|
|
var arr = eids.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select<string, int>(x => Convert.ToInt32(x)).ToArray();
|
|
//LogHelper.Info("eids:" + string.Join(",", eids) + "--level:" + level.ToString());
|
|
var result = _salesRule.Batch(arr, level, sgid, islimit);
|
|
if (result)
|
|
{
|
|
return Json(new { result = true }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
else
|
|
{
|
|
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex);
|
|
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult NewAdd(string selectData, int level, int sgid, int islimit)
|
|
{
|
|
try
|
|
{
|
|
//LogHelper.Info("eids:" + eids + "--level:" + level.ToString());
|
|
var data = JsonConvert.DeserializeObject<List<ResSaleUnRuleListView>>(selectData);
|
|
//LogHelper.Info("eids:" + string.Join(",", eids) + "--level:" + level.ToString());
|
|
var result = _salesRule.Create(data, level, sgid, islimit);
|
|
if (result)
|
|
{
|
|
return Json(new { result = true }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
else
|
|
{
|
|
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Json(new { result = false, msg = ex.Message }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
|
|
public JsonResult Update(string ids, int? level, int? islimit, int? isvalid, DateTime? startTime, DateTime? endTime, int? type = 2)
|
|
{
|
|
try
|
|
{
|
|
var result = _salesRule.Update(ids, level, islimit, isvalid, startTime, endTime, type);
|
|
if (result)
|
|
{
|
|
return Json(new { result = true }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
else
|
|
{
|
|
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex);
|
|
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
|
|
public JsonResult Delete(string ids)
|
|
{
|
|
try
|
|
{
|
|
var result = _salesRule.Delete(ids);
|
|
if (result)
|
|
{
|
|
return Json(new { result = true }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
else
|
|
{
|
|
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex);
|
|
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult Assign()
|
|
{
|
|
var tab = new Table("tablist");
|
|
tab.AddHeadCol("rname", "", "规则组");
|
|
tab.AddHeadCol("eid", "", "工号");
|
|
tab.AddHeadCol("uname", "", "姓名");
|
|
tab.AddHeadCol("gname", "", "组别");
|
|
tab.AddHeadCol("total", "", "实际分配资源数");
|
|
tab.AddHeadCol("isnew", "", "新资源");
|
|
tab.AddHeadCol("isold", "", "老资源");
|
|
tab.AddHeadCol("allocations", "", "当前分配权重数");
|
|
tab.AddHeadCol("quantity", "", "当天实际分配权重数");
|
|
tab.AddHeadCol("todayallocations", "", "当天分配资源量");
|
|
tab.AddHeadCol("tgquantity", "", "推广资源量");
|
|
tab.AddHeadRow();
|
|
|
|
ViewBag.gridTable = tab.GetHead();
|
|
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult Assign(string columns, QueryUserComboDto usercomboDto)
|
|
{
|
|
var tab = new Table(columns, true);
|
|
|
|
var list = _salesRule.GetAssignLists(usercomboDto);
|
|
|
|
if (list != null)
|
|
{
|
|
foreach (var item in list)
|
|
{
|
|
tab.AddCol(item.rname);
|
|
tab.AddCol(item.eid);
|
|
tab.AddCol(item.uname);
|
|
tab.AddCol(item.gname);
|
|
tab.AddCol(item.total);
|
|
tab.AddCol(item.isnew);
|
|
tab.AddCol(item.isold);
|
|
tab.AddCol(item.allocations);
|
|
tab.AddCol(item.quantity);
|
|
tab.AddCol(item.todayallocations);
|
|
tab.AddCol(item.tgquantity);
|
|
tab.AddRow();
|
|
}
|
|
if (list.Any())
|
|
{
|
|
tab.AddCol("合计:");
|
|
tab.AddCol("");
|
|
tab.AddCol("");
|
|
tab.AddCol("");
|
|
tab.AddCol(list.Sum(p => p.total));
|
|
tab.AddCol(list.Sum(p => p.isnew));
|
|
tab.AddCol(list.Sum(p => p.isold));
|
|
tab.AddCol(list.Sum(p => p.allocations));
|
|
tab.AddCol(list.Sum(p => p.quantity));
|
|
tab.AddCol(list.Sum(p => p.todayallocations));
|
|
tab.AddCol(list.Sum(p => p.tgquantity));
|
|
tab.AddRow();
|
|
}
|
|
}
|
|
|
|
var json = new { rowsList = tab.GetRows() };
|
|
return Json(json, JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
} |