643 lines
29 KiB
C#
643 lines
29 KiB
C#
//using CRM.Core.DTO;
|
|
//using CRM.Core.DTO.Res;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using WX.CRM.BLL.Application.UserComBox;
|
|
using WX.CRM.BLL.Base;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Res;
|
|
using WX.CRM.Model.Entity;
|
|
using WX.CRM.Model.MAP;
|
|
|
|
namespace WX.CRM.BLL.Res
|
|
{
|
|
public class RES_SALES_RULE_BL : DbContextRepository<RES_SALES_RULE>, IRES_SALES_RULE
|
|
{
|
|
private CACHE_BL _cache = new CACHE_BL();
|
|
private BAS_PARAMETER_BL _para = new BAS_PARAMETER_BL();
|
|
//private IRES_MYALLOCATERES _myallocate = NinjectControllerFactory.ninjectKernel.Get<IRES_MYALLOCATERES>();
|
|
private RES_MYALLOCATERES_BL _myallocate = new RES_MYALLOCATERES_BL();
|
|
public List<ResSalesRuleListView> GetResSalesRule(ref Pager pager, QueryUserComboDto usercomboDto, int? level, int? sgid, int? isvalid)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var users = _cache.GetUserList();
|
|
var groups = _cache.GetGroupList();
|
|
var userGroups = _cache.GetList_InnerUserGroup();
|
|
var salelevel = _cache.GetValue_Parameter("SaleLevel");
|
|
var ruleGroups = _cache.GetValue_Parameter("SaleGroup");
|
|
var queryData = db.RES_SALES_RULE.AsQueryable();
|
|
if (usercomboDto.userId.HasValue)
|
|
{
|
|
queryData = queryData.Where(m => m.INNERUSERID == usercomboDto.userId.Value);
|
|
}
|
|
else if (!string.IsNullOrEmpty(usercomboDto.groupIds))
|
|
{
|
|
var _groupids = OperationUtil.ConvertToDecimal(usercomboDto.groupIds.Split(','));
|
|
queryData = (from a in queryData
|
|
join b in db.BAS_INNERUSERGROUP on a.INNERUSERID equals b.INNERUSERID
|
|
where _groupids.Contains(b.GID.Value)
|
|
select a);
|
|
}
|
|
else if (!string.IsNullOrEmpty(usercomboDto.deptId))
|
|
{
|
|
var depts = OperationUtil.ConvertToDecimal(usercomboDto.deptId.Split(','));
|
|
List<decimal> ALLdeptIDS = new List<decimal>();
|
|
List<decimal> ALLgidS = new List<decimal>();
|
|
UserServices userservice = new UserServices(_cache);
|
|
foreach (var item in depts)
|
|
{
|
|
List<decimal> deptIDS = new List<decimal>();
|
|
List<decimal> gidS = new List<decimal>();
|
|
userservice.GetAllDeptIDOrGidByDeptId(item, ref deptIDS, ref gidS);//获取所有的组别和gid
|
|
ALLdeptIDS.AddRange(deptIDS);
|
|
ALLgidS.AddRange(gidS);
|
|
}
|
|
queryData = (from a in queryData
|
|
join b in db.BAS_INNERUSERGROUP on a.INNERUSERID equals b.INNERUSERID
|
|
//join g in db.BAS_INNERGROUP on b.GID equals g.GID
|
|
//where depts.Contains(g.SALEDEPTID.Value)
|
|
where ALLdeptIDS.Contains(b.DEPTID.Value) || ALLgidS.Contains(b.GID.Value)
|
|
select a);
|
|
}
|
|
else if (usercomboDto.companyId.HasValue)
|
|
{
|
|
queryData = (from a in queryData
|
|
join b in db.BAS_INNERUSERGROUP on a.INNERUSERID equals b.INNERUSERID
|
|
join g in db.BAS_INNERGROUP on b.GID equals g.GID
|
|
join m in db.BAS_SALESDEPARTMENT on g.SALEDEPTID equals m.SALEDEPTID
|
|
where m.COMPANYID == usercomboDto.companyId.Value
|
|
select a);
|
|
}
|
|
if (level.HasValue)
|
|
{
|
|
queryData = queryData.Where(p => p.LEVELNO == level.Value);
|
|
}
|
|
if (sgid.HasValue)
|
|
{
|
|
queryData = queryData.Where(p => p.SALEGROUPID == sgid.Value);
|
|
}
|
|
if (isvalid.HasValue)
|
|
{
|
|
queryData = queryData.Where(p => p.ISVALID == isvalid.Value);
|
|
}
|
|
|
|
PagerUtil.SetPager<RES_SALES_RULE>(ref queryData, ref pager);
|
|
|
|
var data = queryData.ToList();
|
|
|
|
//var levelList = JsonConvert.DeserializeAnonymousType(salelevel, new { Level = 0, LevelNum = 0 });
|
|
var levelList = salelevel.ToObject<List<ResSalesLevelView>>();
|
|
var ruleGroupList = ruleGroups.ToObject<List<SaleGroupView>>();
|
|
|
|
var q = from a in data
|
|
join u in users on a.EID equals u.EID
|
|
join ug in userGroups on u.PKID equals ug.INNERUSERID
|
|
join g in groups on ug.GID equals g.GID
|
|
join e in levelList on a.LEVELNO equals e.Level
|
|
join r in ruleGroupList on a.SALEGROUPID equals r.ID
|
|
orderby g.SORT ascending, a.EID ascending
|
|
select new ResSalesRuleListView()
|
|
{
|
|
EID = a.EID,
|
|
GNAME = g.GNAME,
|
|
UNAME = a.UNAME,
|
|
ISLIMIT = a.ISLIMIT == 1 ? "是" : "否",
|
|
LEVEL = Convert.ToInt32(e.Level),
|
|
LEVELNAME = e.LevelName,
|
|
NUM = Convert.ToInt32(a.NUM),
|
|
ISVALID = a.ISVALID == 1 ? "是" : "否",
|
|
ISDISMISS = u.ISDISMISS == 1 ? "是" : "否",
|
|
SGNAME = r.GroupName,
|
|
SID = r.ID
|
|
};
|
|
|
|
return q.ToList();
|
|
}
|
|
}
|
|
|
|
public List<ResSaleUnRuleListView> GetResSalesUnRule(QueryUserComboDto usercomboDto, int? sgid)
|
|
{
|
|
var businessDept = _cache.GetValue_Parameter("BusinessDept");
|
|
|
|
var ruleList = new List<RES_SALES_RULE>();
|
|
var wwhhUserEidList = new List<WW_HHUSER_EID>();
|
|
using (var db = new crmContext())
|
|
{
|
|
var ruleQuery = db.RES_SALES_RULE.AsQueryable();
|
|
if (sgid.HasValue)
|
|
{
|
|
ruleQuery = ruleQuery.Where(p => p.SALEGROUPID == sgid.Value);
|
|
}
|
|
ruleList = ruleQuery.ToList();
|
|
wwhhUserEidList = db.WW_HHUSER_EID.ToList();
|
|
}
|
|
var users = _cache.GetUserList().Where(p => p.ISDISMISS == 0);
|
|
var groups = _cache.GetGroupList();
|
|
var userGroups = _cache.GetList_InnerUserGroup();
|
|
|
|
var depatment = new List<BAS_SALESDEPARTMENT>();
|
|
|
|
if (string.IsNullOrEmpty(businessDept))
|
|
{
|
|
depatment = _cache.GetList_SalesDepartMent();
|
|
}
|
|
else
|
|
{
|
|
var businessArr = businessDept.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select<string, decimal>(x => Convert.ToDecimal(x)).ToArray();
|
|
depatment = _cache.GetList_SalesDepartMent().Where(p => businessArr.Contains(p.SALEDEPTID)).ToList();
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(usercomboDto.groupIds))
|
|
{
|
|
var _groupids = OperationUtil.ConvertToDecimal(usercomboDto.groupIds.Split(','));
|
|
return (from u in users
|
|
join ug in userGroups on u.PKID equals ug.INNERUSERID
|
|
join g in groups on ug.GID equals g.GID
|
|
join m in depatment on g.SALEDEPTID equals m.SALEDEPTID
|
|
where _groupids.Contains(ug.GID.Value)
|
|
&& !ruleList.Select(p => p.EID).Contains(u.EID)
|
|
&& wwhhUserEidList.Select(p => p.EID).Distinct().Contains(u.EID)
|
|
orderby g.SORT ascending, u.EID ascending
|
|
select new ResSaleUnRuleListView()
|
|
{
|
|
EID = u.EID,
|
|
GNAME = g.GNAME,
|
|
UNAME = u.UNAME
|
|
}
|
|
).ToList();
|
|
}
|
|
else if (!string.IsNullOrEmpty(usercomboDto.deptId))
|
|
{
|
|
var depts = OperationUtil.ConvertToDecimal(usercomboDto.deptId.Split(','));
|
|
return (from u in users
|
|
join ug in userGroups on u.PKID equals ug.INNERUSERID
|
|
join g in groups on ug.GID equals g.GID
|
|
join m in depatment on g.SALEDEPTID equals m.SALEDEPTID
|
|
where depts.Contains(g.SALEDEPTID.Value)
|
|
&& !ruleList.Select(p => p.EID).Contains(u.EID)
|
|
&& wwhhUserEidList.Select(p => p.EID).Distinct().Contains(u.EID)
|
|
orderby g.SORT ascending, u.EID ascending
|
|
select new ResSaleUnRuleListView()
|
|
{
|
|
EID = u.EID,
|
|
GNAME = g.GNAME,
|
|
UNAME = u.UNAME
|
|
}
|
|
).ToList();
|
|
}
|
|
else if (usercomboDto.companyId.HasValue)
|
|
{
|
|
return (from u in users
|
|
join ug in userGroups on u.PKID equals ug.INNERUSERID
|
|
join g in groups on ug.GID equals g.GID
|
|
join m in depatment on g.SALEDEPTID equals m.SALEDEPTID
|
|
where m.COMPANYID == usercomboDto.companyId.Value
|
|
&& !ruleList.Select(p => p.EID).Contains(u.EID)
|
|
&& wwhhUserEidList.Select(p => p.EID).Distinct().Contains(u.EID)
|
|
orderby g.SORT ascending, u.EID ascending
|
|
select new ResSaleUnRuleListView()
|
|
{
|
|
EID = u.EID,
|
|
GNAME = g.GNAME,
|
|
UNAME = u.UNAME
|
|
}
|
|
).ToList();
|
|
}
|
|
else
|
|
{
|
|
return (from u in users
|
|
join ug in userGroups on u.PKID equals ug.INNERUSERID
|
|
join g in groups on ug.GID equals g.GID
|
|
join m in depatment on g.SALEDEPTID equals m.SALEDEPTID
|
|
where !ruleList.Select(p => p.EID).Contains(u.EID)
|
|
&& wwhhUserEidList.Select(p => p.EID).Distinct().Contains(u.EID)
|
|
orderby g.SORT ascending, u.EID ascending
|
|
select new ResSaleUnRuleListView()
|
|
{
|
|
EID = u.EID,
|
|
GNAME = g.GNAME,
|
|
UNAME = u.UNAME
|
|
}
|
|
).ToList();
|
|
}
|
|
|
|
}
|
|
|
|
//public IList<AssignListView> GetAssignLists(QueryUserComboDto usercomboDto)
|
|
//{
|
|
// var url = _cache.GetValue_Parameter("AssignUrl");
|
|
// var ruleGroups = _cache.GetValue_Parameter("SaleGroup");
|
|
// var channel = Utility.GetSettingOrNullByKey("Channel");
|
|
|
|
// if (string.IsNullOrEmpty(url))
|
|
// {
|
|
// LogHelper.Info("AssignUrl未配置");
|
|
// return null;
|
|
// }
|
|
|
|
// if (string.IsNullOrEmpty(channel))
|
|
// {
|
|
// LogHelper.Info("Channel未配置");
|
|
// return null;
|
|
// }
|
|
|
|
// var reqUrl = url + "?ch=" + channel;
|
|
|
|
// var rsp = Utility.PostData(reqUrl, Encoding.UTF8);
|
|
|
|
// var rspObj = JsonConvert.DeserializeAnonymousType(rsp, new { result = false, retcode = 0, retmsg = new List<AssignDto>() });
|
|
// LogHelper.Info("rsp:" + rspObj.ToJson());
|
|
// if (rspObj.result)
|
|
// {
|
|
// var data = rspObj.retmsg;
|
|
|
|
// if (data.Any())
|
|
// {
|
|
// var users = _cache.GetUserList();
|
|
// var groups = _cache.GetGroupList();
|
|
// var userGroups = _cache.GetList_InnerUserGroup();
|
|
// var depatment = _cache.GetList_SalesDepartMent();
|
|
// var ruleGroupList = ruleGroups.ToObject<List<SaleGroupView>>();
|
|
|
|
// var list = new List<AssignListView>();
|
|
// if (usercomboDto.userId.HasValue)
|
|
// {
|
|
// list = (from a in data
|
|
// join u in users on a.eid equals u.EID
|
|
// join ug in userGroups on u.PKID equals ug.INNERUSERID
|
|
// join g in groups on ug.GID equals g.GID
|
|
// join r in ruleGroupList on a.salegroupid equals r.ID
|
|
// where u.PKID == usercomboDto.userId.Value && u.ISDISMISS == 0
|
|
// select new AssignListView() { rname = r.GroupName, eid = a.eid, uname = u.UNAME, gname = g.GNAME, allocations = a.allocations, todayallocations = a.todayallocations, quantity = a.quantity, tgquantity = a.tgquantity }
|
|
// ).ToList();
|
|
// }
|
|
// else if (!string.IsNullOrEmpty(usercomboDto.groupIds))
|
|
// {
|
|
// var _groupids = OperationUtil.ConvertToDecimal(usercomboDto.groupIds.Split(','));
|
|
// list = (from a in data
|
|
// join u in users on a.eid equals u.EID
|
|
// join ug in userGroups on u.PKID equals ug.INNERUSERID
|
|
// join g in groups on ug.GID equals g.GID
|
|
// join r in ruleGroupList on a.salegroupid equals r.ID
|
|
// where _groupids.Contains(g.GID) && u.ISDISMISS == 0
|
|
// select new AssignListView() { rname = r.GroupName, eid = a.eid, uname = u.UNAME, gname = g.GNAME, allocations = a.allocations, todayallocations = a.todayallocations, quantity = a.quantity, tgquantity = a.tgquantity }
|
|
// ).ToList();
|
|
// }
|
|
// else if (!string.IsNullOrEmpty(usercomboDto.deptId))
|
|
// {
|
|
// UserServices userservices = new UserServices();
|
|
// List<decimal> ALLdeptIDS = new List<decimal>();
|
|
// List<decimal> ALLgidS = new List<decimal>();
|
|
// userservices.GetAllDeptIDOrGidByDeptStr(usercomboDto.deptId, ref ALLdeptIDS, ref ALLgidS);//获取所有的组别和gid
|
|
// list = (from a in data
|
|
// join u in users on a.eid equals u.EID
|
|
// join ug in userGroups on u.PKID equals ug.INNERUSERID
|
|
// join g in groups on ug.GID equals g.GID
|
|
// join r in ruleGroupList on a.salegroupid equals r.ID
|
|
// where (ALLdeptIDS.Contains(ug.DEPTID.Value) || (ug.GID != null && ALLgidS.Contains(ug.GID.Value))) && u.ISDISMISS == 0
|
|
// select new AssignListView() { rname = r.GroupName, eid = a.eid, uname = u.UNAME, gname = g.GNAME, allocations = a.allocations, todayallocations = a.todayallocations, quantity = a.quantity, tgquantity = a.tgquantity }
|
|
// ).ToList();
|
|
// }
|
|
// else if (usercomboDto.companyId.HasValue)
|
|
// {
|
|
// list = (from a in data
|
|
// join u in users on a.eid equals u.EID
|
|
// join ug in userGroups on u.PKID equals ug.INNERUSERID
|
|
// join g in groups on ug.GID equals g.GID
|
|
// join m in depatment on g.SALEDEPTID equals m.SALEDEPTID
|
|
// join r in ruleGroupList on a.salegroupid equals r.ID
|
|
// where m.COMPANYID == usercomboDto.companyId.Value && u.ISDISMISS == 0
|
|
// select new AssignListView() { rname = r.GroupName, eid = a.eid, uname = u.UNAME, gname = g.GNAME, allocations = a.allocations, todayallocations = a.todayallocations, quantity = a.quantity, tgquantity = a.tgquantity }
|
|
// ).ToList();
|
|
// }
|
|
// else
|
|
// {
|
|
// list = (from a in data
|
|
// join u in users on a.eid equals u.EID
|
|
// join ug in userGroups on u.PKID equals ug.INNERUSERID
|
|
// join g in groups on ug.GID equals g.GID
|
|
// join r in ruleGroupList on a.salegroupid equals r.ID
|
|
// where u.ISDISMISS == 0
|
|
// select new AssignListView() { rname = r.GroupName, eid = a.eid, uname = u.UNAME, gname = g.GNAME, allocations = a.allocations, todayallocations = a.todayallocations, quantity = a.quantity, tgquantity = a.tgquantity }
|
|
// ).ToList();
|
|
// }
|
|
|
|
// var allocate = _myallocate.GetToDayAllocateRes();
|
|
// foreach (var item in allocate)
|
|
// {
|
|
// var distime = DateTime.Parse(item.DisTime.Value.ToShortDateString());
|
|
// var ctime = DateTime.Parse(item.CTime.Value.ToShortDateString());
|
|
// if (distime > ctime)
|
|
// {
|
|
// item.IsNew = 0;
|
|
// }
|
|
// }
|
|
// var isNewList = allocate.Where(p => p.IsNew == 1).GroupBy(p => p.Eid).Select(p => new { eid = p.Key, count = p.Count() });
|
|
// var isOldList = allocate.Where(p => p.IsNew == 0).GroupBy(p => p.Eid).Select(p => new { eid = p.Key, count = p.Count() });
|
|
|
|
// foreach (var item in list)
|
|
// {
|
|
// item.isnew = 0;
|
|
// item.isold = 0;
|
|
// var isnew = isNewList.FirstOrDefault(p => p.eid == item.eid);
|
|
// if (isnew != null)
|
|
// {
|
|
// item.isnew = isnew.count;
|
|
// }
|
|
// var isold = isOldList.FirstOrDefault(p => p.eid == item.eid);
|
|
// if (isold != null)
|
|
// {
|
|
// item.isold = isold.count;
|
|
// }
|
|
// item.total = item.isnew + item.isold;
|
|
// //LogHelper.Info(item.total.ToString());
|
|
// }
|
|
|
|
// return list.OrderByDescending(p => p.quantity).ThenByDescending(p => p.total).ToList();
|
|
// }
|
|
// }
|
|
|
|
// return null;
|
|
//}
|
|
|
|
public bool Batch(int[] eids, int level, int sgid, int islimit)
|
|
{
|
|
var users = _cache.GetUserList();
|
|
var salelevel = _cache.GetValue_Parameter("SaleLevel");
|
|
var levelList = salelevel.ToObject<List<ResSalesLevelView>>();
|
|
|
|
var e = levelList.Find(p => p.Level == level);
|
|
var num = 0;
|
|
decimal no = 0;
|
|
if (e != null)
|
|
{
|
|
num = e.LevelNum;
|
|
no = e.Level;
|
|
}
|
|
|
|
var data = new List<RES_SALES_RULE>();
|
|
foreach (var eid in eids)
|
|
{
|
|
var user = users.Find(p => p.EID == eid);
|
|
var uname = string.Empty;
|
|
decimal uid = 0;
|
|
if (user != null)
|
|
{
|
|
uname = user.UNAME;
|
|
uid = user.PKID;
|
|
}
|
|
|
|
var info = new RES_SALES_RULE()
|
|
{
|
|
EID = eid,
|
|
UNAME = uname,
|
|
NUM = num,
|
|
ISLIMIT = islimit,
|
|
CTIME = DateTime.Now,
|
|
LEVELNO = no,
|
|
ISVALID = 1,
|
|
INNERUSERID = uid,
|
|
SALEGROUPID = sgid
|
|
};
|
|
|
|
data.Add(info);
|
|
}
|
|
|
|
AddList(data);
|
|
|
|
return Push();
|
|
}
|
|
|
|
public bool Update(string eids, int? level, int? islimit, int? isvalid)
|
|
{
|
|
var salelevel = _cache.GetValue_Parameter("SaleLevel");
|
|
var levelList = salelevel.ToObject<List<ResSalesLevelView>>();
|
|
|
|
//var arr = eids.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select<string, int>(x => Convert.ToInt32(x)).ToArray();
|
|
var arr = eids.Split(',');
|
|
|
|
foreach (var a in arr)
|
|
{
|
|
var subArr = a.Split('|');
|
|
var eid = int.Parse(subArr[0]);
|
|
var sid = int.Parse(subArr[1]);
|
|
var info = Get(p => p.EID == eid && p.SALEGROUPID == sid);
|
|
if (info != null)
|
|
{
|
|
if (level.HasValue)
|
|
{
|
|
var e = levelList.Find(p => p.Level == level);
|
|
if (e != null)
|
|
{
|
|
info.NUM = e.LevelNum;
|
|
}
|
|
info.LEVELNO = level.Value;
|
|
}
|
|
if (islimit.HasValue)
|
|
info.ISLIMIT = islimit.Value;
|
|
if (isvalid.HasValue)
|
|
info.ISVALID = isvalid.Value;
|
|
|
|
Update(info);
|
|
}
|
|
}
|
|
|
|
return Push();
|
|
}
|
|
|
|
//public retMsg UpdateLevel(string level)
|
|
//{
|
|
// try
|
|
// {
|
|
// var levelList = level.ToObject<List<ResSalesLevelView>>();
|
|
|
|
// var ruleList = GetList().ToList();
|
|
|
|
// var lArr = levelList.Select(m => m.Level);
|
|
// var nArr = ruleList.Select(m => m.LEVELNO).Distinct();
|
|
// var gArr = ruleList.Select(m => m.SALEGROUPID).Distinct();
|
|
|
|
// var except = nArr.Except(lArr);
|
|
// if (except.Any())
|
|
// {
|
|
// return new retMsg() { result = false, retcode = 0, retmsg = "any" };
|
|
// }
|
|
|
|
// foreach (var item in ruleList)
|
|
// {
|
|
// var e = levelList.Find(p => p.Level == item.LEVELNO);
|
|
// if (e != null)
|
|
// {
|
|
// item.NUM = e.LevelNum;
|
|
// }
|
|
// }
|
|
|
|
// Delete(p => gArr.Contains(p.SALEGROUPID));
|
|
|
|
// AddList(ruleList);
|
|
|
|
// _para.Update_ParameterValueByKey("SaleLevel", level);
|
|
|
|
// CacheHelper.Remove("cache_Parameter_getList");
|
|
|
|
// var ret = Push();
|
|
// if (ret)
|
|
// {
|
|
// return new retMsg() { result = true, retcode = 200, retmsg = "success" };
|
|
// }
|
|
// else
|
|
// {
|
|
// return new retMsg() { result = false, retcode = 501, retmsg = "error" };
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// LogHelper.Error(ex);
|
|
|
|
// return new retMsg() { result = false, retcode = 500, retmsg = "error" };
|
|
// }
|
|
//}
|
|
|
|
public bool Push()
|
|
{
|
|
try
|
|
{
|
|
var ch = Utility.GetSettingOrNullByKey("Channel");
|
|
var url = _cache.GetValue_Parameter("Core_ZxdService_ResSaleRule");
|
|
if (string.IsNullOrEmpty(url))
|
|
{
|
|
LogHelper.Info("Core_ZxdService_ResSaleRule:未配置");
|
|
return false;
|
|
}
|
|
if (string.IsNullOrEmpty(ch))
|
|
{
|
|
LogHelper.Info("渠道号:未配置");
|
|
return false;
|
|
}
|
|
|
|
var ruleList = new List<RES_SALES_RULE>();
|
|
var deptList = new List<RES_DEPT_RULE>();
|
|
using (var db = new crmContext())
|
|
{
|
|
var ruleQuery = db.RES_SALES_RULE.AsQueryable();
|
|
|
|
ruleList = ruleQuery.ToList();
|
|
|
|
deptList = db.RES_DEPT_RULE.ToList();
|
|
}
|
|
|
|
var users = _cache.GetUserList();
|
|
var groups = _cache.GetGroupList();
|
|
var userGroups = _cache.GetList_InnerUserGroup();
|
|
var depatment = _cache.GetList_SalesDepartMent();
|
|
|
|
ruleList = (from r in ruleList
|
|
join u in users on r.EID equals u.EID
|
|
where u.ISDISMISS == 0
|
|
select r).ToList();
|
|
|
|
var dept = from u in users
|
|
join ug in userGroups on u.PKID equals ug.INNERUSERID
|
|
join g in groups on ug.GID equals g.GID
|
|
join m in depatment on g.SALEDEPTID equals m.SALEDEPTID
|
|
join d in deptList on m.SALEDEPTID equals d.DEPTID
|
|
select new { u.EID, d.DEPTID, d.RATE };
|
|
|
|
//var deptGroupList = from r in ruleList
|
|
// join d in dept on r.EID equals d.EID
|
|
// where r.ISVALID == 1
|
|
// select new { r.SALEGROUPID, d.DEPTID, r.NUM };
|
|
|
|
//var deptGroupCount = from g in deptGroupList
|
|
// group g by new { g.SALEGROUPID, g.DEPTID } into gg
|
|
// select new { gg.Key.SALEGROUPID, gg.Key.DEPTID, count = gg.Sum(p => p.NUM) };
|
|
|
|
var ruleGroup = from r in ruleList
|
|
group r by r.SALEGROUPID into rg
|
|
select new { Gid = rg.Key, Count = rg.Sum(p => p.NUM) };
|
|
|
|
foreach (var group in ruleGroup)
|
|
{
|
|
var rules = ruleList.Where(p => p.SALEGROUPID == group.Gid);
|
|
//decimal totalCount = rules.Where(p => p.ISVALID == 1).Sum(p => p.NUM);
|
|
foreach (var item in rules)
|
|
{
|
|
var deptInfo = dept.FirstOrDefault(p => p.EID == item.EID);
|
|
|
|
if (deptInfo != null)
|
|
{
|
|
item.DEPTRATE = deptInfo.RATE;
|
|
item.DEPTID = deptInfo.DEPTID;
|
|
}
|
|
|
|
//if (deptList.Any())
|
|
//{
|
|
// var deptCountInfo = deptGroupCount.FirstOrDefault(p => p.SALEGROUPID == group.Gid && p.DEPTID == item.DEPTID);
|
|
// if (deptCountInfo != null)
|
|
// totalCount = deptCountInfo.count;
|
|
//}
|
|
//if (totalCount > 0)
|
|
//{
|
|
// if (item.DEPTRATE.HasValue)
|
|
// {
|
|
// item.RATE = (item.NUM / totalCount * (item.DEPTRATE.Value / 100)) * 100;
|
|
// }
|
|
// else
|
|
// {
|
|
// item.RATE = (item.NUM / totalCount) * 100;
|
|
// }
|
|
//}
|
|
//else
|
|
//{
|
|
// item.RATE = 0;
|
|
//}
|
|
//if (item.ISVALID == 0)
|
|
//{
|
|
// item.RATE = 0;
|
|
//}
|
|
item.CH = decimal.Parse(ch);
|
|
|
|
//item.RATE = decimal.Parse(item.RATE.ToString("f2"));
|
|
}
|
|
|
|
//var totalRate = rules.Where(p => p.ISVALID == 1).Sum(p => p.RATE);
|
|
//if (!(totalRate > 99 && totalRate < 101))
|
|
//{
|
|
// LogHelper.Info("比例不正确:" + totalRate.ToString());
|
|
// //return false;
|
|
//}
|
|
}
|
|
|
|
var para = ruleList.ToJson();
|
|
LogHelper.Info("para:" + para);
|
|
var rsp = Utility.PostAjaxData(url, para, Encoding.UTF8);
|
|
|
|
var rspObj = JsonConvert.DeserializeAnonymousType(rsp, new { result = false, retcode = 0, retmsg = string.Empty });
|
|
|
|
if (rspObj.result)
|
|
{
|
|
var gArr = ruleList.Select(m => m.SALEGROUPID).Distinct();
|
|
|
|
Delete(p => gArr.Contains(p.SALEGROUPID));
|
|
|
|
AddList(ruleList);
|
|
}
|
|
|
|
return rspObj.result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|