655 lines
30 KiB
C#
655 lines
30 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;
|
|
using WX.CRM.Model.Enum;
|
|
using WX.CRM.Common.StockHelper;
|
|
using WX.CRM.Model.DTO;
|
|
using WX.CRM.Common.Layui;
|
|
|
|
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();
|
|
public BAS_BUSSINESSLINE_BL line_BL = new BAS_BUSSINESSLINE_BL();
|
|
|
|
//private IRES_MYALLOCATERES _myallocate = NinjectControllerFactory.ninjectKernel.Get<IRES_MYALLOCATERES>();
|
|
private RES_MYALLOCATERES_BL _myallocate = new RES_MYALLOCATERES_BL();
|
|
|
|
private BAS_BUSSINESSLINE_BL _bussinessLies = new BAS_BUSSINESSLINE_BL();
|
|
|
|
public List<ResSalesRuleListView> GetResSalesRule(ref Laypage pager, QueryUserComboDto usercomboDto, decimal userid, ResSalesRuleQueryDto dto)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var zxdCrmUrl = _cache.GetValue_Parameter(Parameter.Core_ZxdService_WebApi) + "Api/AssignRule/GetAssignList";
|
|
var salelevel = _cache.GetValue_Parameter("SaleLevel");
|
|
var ruleGroups = _cache.GetValue_Parameter("SaleGroup");
|
|
var levelList = salelevel.ToObject<List<ResSalesLevelView>>();
|
|
var ruleGroupList = ruleGroups.ToObject<List<SaleGroupView>>();
|
|
//zxdCrmUrl = "https://localhost:7163/Api/AssignRule/GetAssignList";
|
|
var users = _cache.GetUserList();
|
|
var filterUserid = new List<decimal>();
|
|
var postModel = $"pageIndex={pager.page}&pageSize= {pager.limit}";
|
|
var paras = Utility.BuildQueryParams<ResSalesRuleQueryDto>(dto);
|
|
if (ruleGroupList.Count > 0)
|
|
{
|
|
postModel += $"&allsgids={string.Join(",", ruleGroupList.Select(n => n.ID).ToList())}";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(dto.phone))
|
|
{
|
|
var resid = ResUtil.CreateResId(dto.phone);
|
|
postModel += $"&resid={resid}";
|
|
}
|
|
if (usercomboDto.userId.HasValue)
|
|
{
|
|
postModel += $"&userId={usercomboDto.userId}";
|
|
}
|
|
else if (usercomboDto.txt_departmentid.HasValue)
|
|
{
|
|
postModel += $"&departmentId={usercomboDto.txt_departmentid}";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(paras))
|
|
{
|
|
postModel += paras;
|
|
}
|
|
var cmsdata = Utility.GetData(zxdCrmUrl, postModel, Encoding.UTF8);
|
|
ApiResult<PageResult<CmsAssignRules>> reqInfo = JsonConvert.DeserializeObject<ApiResult<PageResult<CmsAssignRules>>>(cmsdata);
|
|
pager.count = reqInfo.Data.Total;
|
|
var list = reqInfo.Data.Data;
|
|
var eidFilter = list.Select(n => n.eid).ToList();
|
|
var wwuserList = db.WW_HHUSER_EID.Where(n => n.EID != null && eidFilter.Contains(n.EID.Value) && n.ASSIGNSTATUS == 1).GroupBy(n => n.EID)
|
|
.Select(n => new { eid = n.Key, count = n.Count() });
|
|
var groups = _cache.GetGroupList();
|
|
var userGroups = _cache.GetList_InnerUserGroup();
|
|
var depatment = _cache.GetList_SalesDepartMent();
|
|
List<ResSalesRuleListView> res = new List<ResSalesRuleListView>();
|
|
foreach (var item in list)
|
|
{
|
|
var basUser = users.FirstOrDefault(n => n.EID == item.eid);
|
|
var user = wwuserList.FirstOrDefault(n => n.eid == item.eid);
|
|
var model = new ResSalesRuleListView()
|
|
{
|
|
ID = item.id,
|
|
SID = item.salegroupid.HasValue ? item.salegroupid.Value : 0,
|
|
EID = item.eid.HasValue ? item.eid.Value : 0,
|
|
UNAME = item.uname,
|
|
LEVEL = item.levelno.HasValue ? item.levelno.Value : 0,
|
|
NUM = item.num.HasValue ? item.num.Value : 0,
|
|
ISLIMIT = item.islimit == 1 ? "是" : "否",
|
|
ISVALID = item.isvalid == 1 ? "是" : "否",
|
|
Count = user == null ? 0 : user.count,
|
|
LEVELNAME = levelList.FirstOrDefault(n => n.Level == item.levelno)?.LevelName,
|
|
SGNAME = ruleGroupList.FirstOrDefault(n => n.ID == item.salegroupid).GroupName,
|
|
ISDISMISS = basUser == null ? "是" : basUser.ISDISMISS == 1 ? "是" : "否",
|
|
APPNAME = item.AppName,
|
|
USERID = item.userid,
|
|
PHONE = item.Phone,
|
|
NickName = item.nickName,
|
|
startTime = item.StartTime,
|
|
endTime = item.EndTime
|
|
};
|
|
if (basUser != null)
|
|
{
|
|
var usergroup = userGroups.FirstOrDefault(n => n.INNERUSERID == basUser.PKID);
|
|
if (usergroup != null)
|
|
{
|
|
var group = groups.FirstOrDefault(n => n.GID == usergroup?.GID);
|
|
model.GID = group == null ? 0 : group.GID;
|
|
model.GNAME = group == null ? "" : group.GNAME;
|
|
var dept = depatment.FirstOrDefault(n => n.SALEDEPTID == usergroup.DEPTID);
|
|
model.DEPTNAME = dept == null ? "" : dept.DEPTNAME;
|
|
}
|
|
}
|
|
res.Add(model);
|
|
}
|
|
if (res.Count > 0)
|
|
{
|
|
res.Add(new ResSalesRuleListView
|
|
{
|
|
NUM = res.Sum(n => n.NUM)
|
|
});
|
|
}
|
|
return res;
|
|
}
|
|
}
|
|
|
|
public List<ResSaleUnRuleListView> GetResSalesUnRule(QueryUserComboDto usercomboDto, int? sgid, string uname, decimal userId)
|
|
{
|
|
var businessDept = _cache.GetValue_Parameter("BusinessDept");
|
|
List<ResSaleUnRuleListView> res = new List<ResSaleUnRuleListView>();
|
|
var zxdCrmUrl = _cache.GetValue_Parameter(Parameter.Core_ZxdService_WebApi) + "Api/AssignRule/GetNotSetAssignList";
|
|
//zxdCrmUrl = "https://localhost:7163/Api/AssignRule/GetNotSetAssignList";
|
|
var postModel = $"sgid={sgid}";
|
|
var lineid = "";
|
|
if (!string.IsNullOrWhiteSpace(usercomboDto.txt_deptIds))
|
|
{
|
|
lineid = usercomboDto.txt_deptIds;
|
|
}
|
|
else
|
|
{
|
|
var lineList = line_BL.GetBusinessLineByRoot(userId);
|
|
lineid = string.Join(",", lineList.Select(o => o.BUSINESSID));
|
|
}
|
|
postModel += $"&deptIds={lineid}";
|
|
if (usercomboDto.txt_departmentid.HasValue)
|
|
{
|
|
postModel += $"&departmentId={usercomboDto.txt_departmentid}";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(uname))
|
|
{
|
|
postModel += $"&uname={uname}";
|
|
}
|
|
var cmsdata = Utility.GetData(zxdCrmUrl, postModel, Encoding.UTF8);
|
|
ApiResult<List<NotSetAssignRuleDto>> reqInfo = JsonConvert.DeserializeObject<ApiResult<List<NotSetAssignRuleDto>>>(cmsdata);
|
|
var users = _cache.GetUserList();
|
|
var groups = _cache.GetGroupList();
|
|
var userGroups = _cache.GetList_InnerUserGroup();
|
|
var depatment = _cache.GetList_SalesDepartMent();
|
|
var eiddeptMap = from n in users
|
|
join b in userGroups on n.PKID equals b.INNERUSERID
|
|
join c in groups on b.GID equals c.GID into temp
|
|
from c in temp.DefaultIfEmpty()
|
|
join d in depatment on b.DEPTID equals d.SALEDEPTID
|
|
into temp2
|
|
from d in temp2.DefaultIfEmpty()
|
|
select new
|
|
{
|
|
groupid = c?.GID,
|
|
deptid = d?.SALEDEPTID,
|
|
eid = n.EID,
|
|
gname = c?.GNAME,
|
|
deptName = d?.DEPTNAME
|
|
};
|
|
var eidDeptMapList = eiddeptMap.ToList();
|
|
foreach (var item in reqInfo.Data)
|
|
{
|
|
ResSaleUnRuleListView newModel = new ResSaleUnRuleListView
|
|
{
|
|
Id = item.Id,
|
|
EID = Convert.ToDecimal(item.Eid),
|
|
AppId = item.AppId,
|
|
UserId = item.UserId,
|
|
UNAME = item.Uname,
|
|
AppName = item.AppName,
|
|
NickName = item.NickName
|
|
};
|
|
var deptMap = eidDeptMapList.FirstOrDefault(n => n.eid == item.Eid);
|
|
if (deptMap != null)
|
|
{
|
|
newModel.DEPTNAME = deptMap.deptName;
|
|
newModel.GNAME = deptMap.gname;
|
|
newModel.Gid = deptMap.groupid;
|
|
newModel.DeptId = deptMap.deptid;
|
|
}
|
|
|
|
res.Add(newModel);
|
|
}
|
|
return res;
|
|
}
|
|
|
|
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 Create(List<ResSaleUnRuleListView> data, int level, int sgid, int islimit)
|
|
{
|
|
var salelevel = _cache.GetValue_Parameter("SaleLevel");
|
|
var levelList = salelevel.ToObject<List<ResSalesLevelView>>();
|
|
|
|
var users = _cache.GetUserList();
|
|
var groups = _cache.GetGroupList();
|
|
var userGroups = _cache.GetList_InnerUserGroup();
|
|
var depatment = _cache.GetList_SalesDepartMent();
|
|
var deptList = new List<RES_DEPT_RULE>();
|
|
using (var db = new crmContext())
|
|
{
|
|
deptList = db.RES_DEPT_RULE.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 into temp2
|
|
from g in temp2.DefaultIfEmpty()
|
|
join m in depatment on ug.DEPTID equals m.SALEDEPTID into temp3
|
|
from m in temp3.DefaultIfEmpty()
|
|
join d in deptList on m.SALEDEPTID equals d.DEPTID into temp4
|
|
from d in temp4.DefaultIfEmpty()
|
|
select new { u.PKID, u.EID, d?.DEPTID, d?.RATE };
|
|
List<AssignRuleCreateDto> postModel = new List<AssignRuleCreateDto>();
|
|
foreach (var item in data)
|
|
{
|
|
var e = levelList.Find(p => p.Level == level);
|
|
AssignRuleCreateDto createDto = new AssignRuleCreateDto
|
|
{
|
|
eid = Convert.ToInt32(item.EID),
|
|
salegroupid = sgid,
|
|
appid = item.AppId,
|
|
userid = item.UserId,
|
|
uname = item.UNAME,
|
|
num = e.LevelNum,
|
|
islimit = islimit,
|
|
levelno = Convert.ToInt32(e.Level),
|
|
isvalid = 1,
|
|
crmdeptid = item.DeptId.HasValue ? Convert.ToInt32(item.DeptId) : item.Gid.HasValue ? Convert.ToInt32(item.Gid) : 0
|
|
};
|
|
var deptInfo = dept.FirstOrDefault(p => p.EID == item.EID);
|
|
if (deptInfo != null)
|
|
{
|
|
createDto.rate = deptInfo.RATE;
|
|
createDto.crmdeptid = Convert.ToInt32(deptInfo.DEPTID);
|
|
createDto.deptrate = deptInfo.RATE;
|
|
createDto.inneruserid = Convert.ToInt32(deptInfo.PKID);
|
|
postModel.Add(createDto);
|
|
}
|
|
}
|
|
var zxdCrmUrl = _cache.GetValue_Parameter(Parameter.Core_ZxdService_WebApi) + "Api/AssignRule/CreateAssignRule";
|
|
//zxdCrmUrl = "https://localhost:7163/Api/AssignRule/CreateAssignRule";
|
|
var cmsData = Utility.PostAjaxData(zxdCrmUrl, postModel.ToJson(), Encoding.UTF8);
|
|
var res = JsonConvert.DeserializeObject<ApiResult<bool>>(cmsData);
|
|
if (res.Code == 0)
|
|
{
|
|
return res.Data;
|
|
}
|
|
else
|
|
{
|
|
throw new Exception(res.Message);
|
|
}
|
|
}
|
|
|
|
public bool Update(string ids, int? level, int? islimit, int? isvalid, DateTime? startTime, DateTime? endTime, int? type = 2)
|
|
{
|
|
if (startTime.HasValue && endTime.HasValue && startTime >= endTime)
|
|
{
|
|
throw new Exception("上线时间不能大于下线时间");
|
|
}
|
|
var salelevel = _cache.GetValue_Parameter("SaleLevel");
|
|
var levelList = salelevel.ToObject<List<ResSalesLevelView>>();
|
|
var e = levelList.Find(p => p.Level == level);
|
|
AssignRuleUpOrDowmDto postModel = new AssignRuleUpOrDowmDto
|
|
{
|
|
type = type,
|
|
ids = ids.Split(',').Select(n => Convert.ToInt32(n)).ToList(),
|
|
num = e?.LevelNum,
|
|
levelno = Convert.ToInt32(e?.Level),
|
|
islimit = islimit,
|
|
isvalid = isvalid,
|
|
startTime = startTime,
|
|
endTime = endTime
|
|
};
|
|
|
|
var zxdCrmUrl = _cache.GetValue_Parameter(Parameter.Core_ZxdService_WebApi) + "Api/AssignRule/UpAssignRule";
|
|
//zxdCrmUrl = "https://localhost:7163/Api/AssignRule/UpAssignRule";
|
|
var cmsData = Utility.PostAjaxData(zxdCrmUrl, postModel.ToJson(), Encoding.UTF8);
|
|
var res = JsonConvert.DeserializeObject<ApiResult<bool>>(cmsData);
|
|
if (res.Code == 0)
|
|
{
|
|
return res.Data;
|
|
}
|
|
else
|
|
{
|
|
throw new Exception(res.Message);
|
|
}
|
|
}
|
|
|
|
public bool Delete(string ids)
|
|
{
|
|
List<int> delIds = ids.Split(',').Select(n => Convert.ToInt32(n)).Distinct().ToList();
|
|
var zxdCrmUrl = _cache.GetValue_Parameter(Parameter.Core_ZxdService_WebApi) + "Api/AssignRule/DeleteRule";
|
|
//zxdCrmUrl = "https://localhost:7163/Api/AssignRule/DeleteRule";
|
|
var cmsData = Utility.PostAjaxData(zxdCrmUrl, delIds.ToJson(), Encoding.UTF8);
|
|
var res = JsonConvert.DeserializeObject<ApiResult<bool>>(cmsData);
|
|
if (res.Code == 0)
|
|
{
|
|
return res.Data;
|
|
}
|
|
else
|
|
{
|
|
throw new Exception(res.Message);
|
|
}
|
|
}
|
|
|
|
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.PKID, u.EID, d.DEPTID, d.RATE };
|
|
|
|
var ruleGroup = from r in ruleList
|
|
group r by r.SALEGROUPID into rg
|
|
select new { Gid = rg.Key, Count = rg.Sum(p => p.NUM) };
|
|
//业务线关系
|
|
var saleline = _bussinessLies.GetChannelByUser(dept.Select(n => n.PKID).ToList());
|
|
foreach (var group in ruleGroup)
|
|
{
|
|
var rules = ruleList.Where(p => p.SALEGROUPID == group.Gid);
|
|
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 (saleline.ContainsKey(deptInfo.PKID))
|
|
{
|
|
item.CH = saleline[deptInfo.PKID];
|
|
}
|
|
}
|
|
//没有值 取默认渠道
|
|
if (!item.CH.HasValue)
|
|
{
|
|
item.CH = decimal.Parse(ch);
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
} |