808 lines
36 KiB
C#
808 lines
36 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.DAL.Wx;
|
|
using WX.CRM.IBLL.Wx;
|
|
using WX.CRM.Model.Entity;
|
|
using WX.CRM.Model.MAP;
|
|
using WX.CRM.Model.QueryMap;
|
|
|
|
namespace WX.CRM.BLL.Wx
|
|
{
|
|
public class WX_RCONTACT_BL : DbContextRepository<WX_RCONTACT>, IWX_RCONTACT
|
|
{
|
|
private WX_RCONTACT_DAL wx_Rcontact_DAL = new WX_RCONTACT_DAL();
|
|
|
|
public WX_RCONTACT GetModel(decimal pkid)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.WX_RCONTACT.Where(m => m.PKID == pkid).FirstOrDefault();
|
|
}
|
|
}
|
|
|
|
public List<WX_RCONTACT> GetList(ref Pager page, string jobWxUserName, string userName, string alias, string nickName, string conRemark, string stime, string etime)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var queryData = db.WX_RCONTACT.AsQueryable();
|
|
if (!string.IsNullOrWhiteSpace(jobWxUserName))
|
|
{
|
|
jobWxUserName = jobWxUserName.Trim();
|
|
queryData = queryData.Where(m => m.JOBWXUSERNAME == jobWxUserName);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(userName))
|
|
{
|
|
userName = userName.Trim();
|
|
queryData = queryData.Where(m => m.USERNAME.Contains(userName));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(alias))
|
|
{
|
|
alias = alias.Trim();
|
|
queryData = queryData.Where(m => m.ALIAS.Contains(alias));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(nickName))
|
|
{
|
|
nickName = nickName.Trim();
|
|
queryData = queryData.Where(m => m.NICKNAME.Contains(nickName));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(conRemark))
|
|
{
|
|
conRemark = conRemark.Trim();
|
|
queryData = queryData.Where(m => m.CONREMARK.Contains(conRemark));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(stime))
|
|
{
|
|
DateTime time1 = Convert.ToDateTime(stime);
|
|
queryData = queryData.Where(m => m.CTIME >= time1);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(etime))
|
|
{
|
|
DateTime time2 = Convert.ToDateTime(etime).AddDays(1);
|
|
queryData = queryData.Where(m => m.CTIME < time2);
|
|
}
|
|
|
|
queryData = queryData.OrderByDescending(m => m.CTIME);
|
|
PagerUtil.SetPager<WX_RCONTACT>(ref queryData, ref page);
|
|
return queryData.ToList();
|
|
}
|
|
}
|
|
|
|
public List<WX_RCONTACT> GetFilterList(ref Pager page, string jobWxUserName, string userName, string alias, string nickName, string conRemark, string stime, string etime)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var queryData = db.WX_RCONTACT.Where(m => !m.USERNAME.StartsWith("fake_") && !m.USERNAME.StartsWith("gh_") && !m.USERNAME.Equals("weixin")).AsQueryable();
|
|
if (!string.IsNullOrWhiteSpace(jobWxUserName))
|
|
{
|
|
jobWxUserName = jobWxUserName.Trim();
|
|
queryData = queryData.Where(m => m.JOBWXUSERNAME == jobWxUserName);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(userName))
|
|
{
|
|
userName = userName.Trim();
|
|
queryData = queryData.Where(m => m.USERNAME.Contains(userName));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(alias))
|
|
{
|
|
alias = alias.Trim();
|
|
queryData = queryData.Where(m => m.ALIAS.Contains(alias));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(nickName))
|
|
{
|
|
nickName = nickName.Trim();
|
|
queryData = queryData.Where(m => m.NICKNAME.Contains(nickName));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(conRemark))
|
|
{
|
|
conRemark = conRemark.Trim();
|
|
queryData = queryData.Where(m => m.CONREMARK.Contains(conRemark));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(stime))
|
|
{
|
|
DateTime time1 = Convert.ToDateTime(stime);
|
|
queryData = queryData.Where(m => m.CTIME >= time1);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(etime))
|
|
{
|
|
DateTime time2 = Convert.ToDateTime(etime).AddDays(1);
|
|
queryData = queryData.Where(m => m.CTIME < time2);
|
|
}
|
|
|
|
queryData = queryData.OrderByDescending(m => m.CTIME);
|
|
PagerUtil.SetPager<WX_RCONTACT>(ref queryData, ref page);
|
|
return queryData.ToList();
|
|
}
|
|
}
|
|
|
|
public List<WX_RCONTACT_Extend> GetListAndWorkAccount(ref Pager page, string jobWxUserName, string userName, string alias, string nickName, string conRemark, string stime, string etime, string resId)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var queryData = db.WX_RCONTACT.AsQueryable();
|
|
//过滤非好友的,群里面的记录
|
|
List<decimal?> types = new List<decimal?> { 1, 3, 5, 7, 257, 259, 67, 65539 };
|
|
queryData = queryData.Where(m => m.TYPE > 11 || types.Contains(m.TYPE));
|
|
if (!string.IsNullOrWhiteSpace(jobWxUserName))
|
|
{
|
|
jobWxUserName = jobWxUserName.Trim();
|
|
queryData = queryData.Where(m => m.JOBWXUSERNAME == jobWxUserName);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(userName))
|
|
{
|
|
userName = userName.Trim();
|
|
queryData = queryData.Where(m => m.USERNAME == userName);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(alias))
|
|
{
|
|
alias = alias.Trim();
|
|
queryData = queryData.Where(m => m.ALIAS.Contains(alias));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(nickName))
|
|
{
|
|
nickName = nickName.Trim();
|
|
queryData = queryData.Where(m => m.NICKNAME.Contains(nickName));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(conRemark))
|
|
{
|
|
conRemark = conRemark.Trim();
|
|
queryData = queryData.Where(m => m.CONREMARK.Contains(conRemark));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(resId))
|
|
{
|
|
resId = resId.Trim();
|
|
queryData = queryData.Where(m => m.RESID == resId);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(stime))
|
|
{
|
|
DateTime time1 = Convert.ToDateTime(stime);
|
|
queryData = queryData.Where(m => m.CTIME >= time1);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(etime))
|
|
{
|
|
DateTime time2 = Convert.ToDateTime(etime).AddDays(1);
|
|
queryData = queryData.Where(m => m.CTIME < time2);
|
|
}
|
|
|
|
var query = from r in queryData
|
|
join o in db.WX_WORKACCOUNT on r.JOBWXUSERNAME equals o.USERNAME into tmp0
|
|
from ro in tmp0.DefaultIfEmpty()
|
|
select new WX_RCONTACT_Extend()
|
|
{
|
|
wx_rcontact = r,
|
|
inneruserId = ro.INNERUSERID,
|
|
WorkAlias = ro.ALIAS
|
|
};
|
|
|
|
query = query.OrderByDescending(m => m.wx_rcontact.CTIME);
|
|
PagerUtil.SetPager<WX_RCONTACT_Extend>(ref query, ref page);
|
|
return query.ToList();
|
|
}
|
|
}
|
|
|
|
public List<WX_RCONTACT> GetMyList(ref Pager pager, string resId, string userName, string alias, string conreMark, string nickName, string jobWxUser, string stime, string etime, decimal? userId, bool canSearchAll, decimal? orderId = null)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var queryData = db.WX_RCONTACT.AsQueryable();
|
|
if (!string.IsNullOrWhiteSpace(resId))
|
|
{
|
|
queryData = queryData.Where(p => p.RESID == resId);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(userName))
|
|
{
|
|
queryData = queryData.Where(p => p.USERNAME.Contains(userName));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(alias))
|
|
{
|
|
queryData = queryData.Where(p => p.ALIAS.Contains(alias));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(conreMark))
|
|
{
|
|
queryData = queryData.Where(p => p.CONREMARK.Contains(conreMark));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(nickName))
|
|
{
|
|
queryData = queryData.Where(p => p.NICKNAME.Contains(nickName));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(jobWxUser))
|
|
{
|
|
queryData = queryData.Where(p => p.JOBWXUSERNAME == jobWxUser);
|
|
}
|
|
else
|
|
{
|
|
//var myWorkAccountList = new WX_WORKACCOUNT_BL().GetMyWorkAccountList(userId);
|
|
//List<string> jobWxList = new List<string>();
|
|
//foreach (var workAccount in myWorkAccountList)
|
|
//{
|
|
// if (!string.IsNullOrWhiteSpace(workAccount.USERNAME))
|
|
// {
|
|
// jobWxList.Add(workAccount.USERNAME);
|
|
// }
|
|
//}
|
|
//queryData = queryData.Where(p => jobWxList.Contains(p.JOBWXUSERNAME));
|
|
List<string> jobWxList = new List<string>();
|
|
if (orderId.HasValue)
|
|
{
|
|
//var orderUserIds = new WX_COMMISSIONRULE_BL().GetList(p => p.ORDERID == orderId.Value).Select(p => p.SALEUSERID).ToList();
|
|
//foreach (var item in orderUserIds)
|
|
//{
|
|
// var myWorkAccountList = workAccountList.Where(p => p.INNERUSERID == item);
|
|
// foreach (var workAccount in myWorkAccountList)
|
|
// {
|
|
// if (!string.IsNullOrWhiteSpace(workAccount.USERNAME))
|
|
// {
|
|
// jobWxList.Add(workAccount.USERNAME);
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
var orderUserIds = db.WX_COMMISSIONRULE.AsQueryable().Where(p => p.ORDERID == orderId.Value).Select(p => p.SALEUSERID).ToList();
|
|
var myWorkAccountList = db.WX_WORKACCOUNT.AsQueryable().Where(p => orderUserIds.Contains(p.INNERUSERID.Value));
|
|
if (!orderUserIds.Any())
|
|
{
|
|
myWorkAccountList = db.WX_WORKACCOUNT.AsQueryable();
|
|
if (userId.HasValue)
|
|
{
|
|
myWorkAccountList = myWorkAccountList.Where(p => p.INNERUSERID == userId);
|
|
}
|
|
}
|
|
foreach (var workAccount in myWorkAccountList)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(workAccount.USERNAME))
|
|
{
|
|
jobWxList.Add(workAccount.USERNAME);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var myWorkAccountList = db.WX_WORKACCOUNT.AsQueryable();
|
|
if (userId.HasValue)
|
|
{
|
|
myWorkAccountList = myWorkAccountList.Where(p => p.INNERUSERID == userId);
|
|
}
|
|
foreach (var workAccount in myWorkAccountList)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(workAccount.USERNAME))
|
|
{
|
|
jobWxList.Add(workAccount.USERNAME);
|
|
}
|
|
}
|
|
}
|
|
queryData = queryData.Where(p => jobWxList.Contains(p.JOBWXUSERNAME));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(stime))
|
|
{
|
|
DateTime dt = Convert.ToDateTime(stime);
|
|
queryData = queryData.Where(p => p.CTIME >= dt);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(etime))
|
|
{
|
|
DateTime dt = Convert.ToDateTime(etime).AddDays(1);
|
|
queryData = queryData.Where(p => p.CTIME < dt);
|
|
}
|
|
|
|
queryData = queryData.OrderByDescending(m => m.CTIME);
|
|
PagerUtil.SetPager<WX_RCONTACT>(ref queryData, ref pager);
|
|
return queryData.ToList();
|
|
}
|
|
}
|
|
|
|
public List<WX_RCONTACT> GetWorkAliasRcontactList(ref Pager pager, string userName, string alias, string conreMark, string nickName, string workAlias)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var queryData = db.WX_RCONTACT.AsQueryable();
|
|
if (!string.IsNullOrWhiteSpace(userName))
|
|
{
|
|
queryData = queryData.Where(p => p.USERNAME.Contains(userName));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(alias))
|
|
{
|
|
queryData = queryData.Where(p => p.ALIAS.Contains(alias));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(conreMark))
|
|
{
|
|
queryData = queryData.Where(p => p.CONREMARK.Contains(conreMark));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(nickName))
|
|
{
|
|
queryData = queryData.Where(p => p.NICKNAME.Contains(nickName));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(workAlias))
|
|
{
|
|
var myWorkAccount = db.WX_WORKACCOUNT.AsQueryable().Where(p => p.ALIAS == workAlias).FirstOrDefault();
|
|
if (myWorkAccount != null)
|
|
{
|
|
queryData = queryData.Where(p => p.JOBWXUSERNAME == myWorkAccount.USERNAME);
|
|
}
|
|
else
|
|
{
|
|
queryData = queryData.Where(p => p.JOBWXUSERNAME == "");
|
|
}
|
|
}
|
|
|
|
queryData = queryData.OrderByDescending(m => m.CTIME);
|
|
PagerUtil.SetPager<WX_RCONTACT>(ref queryData, ref pager);
|
|
return queryData.ToList();
|
|
}
|
|
}
|
|
|
|
public bool UpdateResId(ref ValidationErrors errors, decimal pkId, string resId)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var model = db.WX_RCONTACT.Where(m => m.PKID == pkId).FirstOrDefault();
|
|
if (model != null)
|
|
{
|
|
model.RESID = resId;
|
|
}
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
LogHelper.Error(ex);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public DataSet ExportWeiXinResource(DateTime beginTime, DateTime endTime, decimal? inneruserid)
|
|
{
|
|
return new WX_RCONTACT_DAL().ExportWeiXinResource(beginTime, endTime, inneruserid);
|
|
}
|
|
|
|
public DataTable CountRcontactByWxJobUserName()
|
|
{
|
|
DataTable dt = wx_Rcontact_DAL.CountRcontactByWxJobUserName();
|
|
|
|
return dt;
|
|
}
|
|
|
|
public DataTable CountRcontactByInnerUserId()
|
|
{
|
|
return wx_Rcontact_DAL.CountRcontactByInnerUserId();
|
|
}
|
|
|
|
public DataTable CountRcontactByUserGroup()
|
|
{
|
|
return wx_Rcontact_DAL.CountRcontactByUserGroup();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 推送数据到推广
|
|
/// </summary>
|
|
/// <param name="v_username">用户名</param>
|
|
/// <param name="v_jobusername">工作微信username</param>
|
|
/// <returns>返回PICI</returns>
|
|
public decimal pushRcontactToTG(string v_username, string v_jobusername)
|
|
{
|
|
return wx_Rcontact_DAL.pushRcontactToTG(v_username, v_jobusername);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 从message表中提取好友关系被加数据
|
|
/// </summary>
|
|
/// <param name="v_username">好友username</param>
|
|
/// <param name="v_jobusername">工作微信</param>
|
|
/// <param name="v_msgSvrId">msgSvrId</param>
|
|
/// <param name="v_content">内容</param>
|
|
/// <param name="v_createTime">时间</param>
|
|
/// <returns>返回pici</returns>
|
|
public decimal extractToBeFriendsDataFromMsg(decimal type, string v_username, string v_jobusername, DateTime v_createTime, ref bool ret)
|
|
{
|
|
return wx_Rcontact_DAL.extractToBeFriendsDataFromMsg(type, v_username, v_jobusername, v_createTime, ref ret);
|
|
}
|
|
|
|
public DataTable RcontactByDayReport(DateTime? beginTime, DateTime? endTime, decimal? type)
|
|
{
|
|
return wx_Rcontact_DAL.RcontactByDayReport(beginTime, endTime, type);
|
|
}
|
|
|
|
public DataTable RcontactByUserAndDay(DateTime beginTime, DateTime endTime, decimal? type)
|
|
{
|
|
return wx_Rcontact_DAL.RcontactByUserAndDay(beginTime, endTime, type);
|
|
}
|
|
|
|
public DataTable RcontactByTag(DateTime beginTime, DateTime endTime)
|
|
{
|
|
return wx_Rcontact_DAL.RcontactByTag(beginTime, endTime);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取微信信息配置
|
|
/// </summary>
|
|
/// <param name="username"></param>
|
|
/// <returns></returns>
|
|
public Wx_MsgConfig GetMsgConfig(string username)
|
|
{
|
|
return wx_Rcontact_DAL.GetMsgConfig(username);
|
|
}
|
|
|
|
public bool WxDbUploadLog(WX_DBUPLOADLOG model, long createTime, DateTime createTimewin, string qunfaclientid)
|
|
{
|
|
return wx_Rcontact_DAL.WxDbUploadLog(model, createTime, createTimewin, qunfaclientid);
|
|
}
|
|
|
|
public IList<WxResourceCheckView> GetWxResourceCheck(decimal? groupId, decimal? userId)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var workAccountList = new WX_WORKACCOUNT_BL().GetList();
|
|
var where = PredicateExtensionses.True<WxResourceCheckView>();
|
|
if (groupId.HasValue)
|
|
{
|
|
var userids = db.BAS_INNERUSERGROUP.Where(m => m.GID.Value == groupId.Value).Select(m => m.INNERUSERID);
|
|
List<string> jobWxList = new List<string>();
|
|
foreach (var item in userids)
|
|
{
|
|
var myWorkAccountList = workAccountList.Where(p => p.INNERUSERID == item);
|
|
foreach (var workAccount in myWorkAccountList)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(workAccount.USERNAME))
|
|
{
|
|
jobWxList.Add(workAccount.USERNAME);
|
|
}
|
|
}
|
|
}
|
|
|
|
where = where.And(p => jobWxList.Contains(p.JobUserName));
|
|
}
|
|
else if (userId.HasValue)
|
|
{
|
|
var myWorkAccountList = workAccountList.Where(p => p.INNERUSERID == userId.Value);
|
|
List<string> jobWxList = new List<string>();
|
|
foreach (var workAccount in myWorkAccountList)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(workAccount.USERNAME))
|
|
{
|
|
jobWxList.Add(workAccount.USERNAME);
|
|
}
|
|
}
|
|
where = where.And(p => jobWxList.Contains(p.JobUserName));
|
|
}
|
|
var afterSaleList = from w in db.WX_WORKACCOUNT
|
|
join u in db.BAS_INNERUSER on w.INNERUSERID equals u.PKID
|
|
join ug in db.BAS_INNERUSERGROUP on u.PKID equals ug.INNERUSERID
|
|
join g in db.BAS_INNERGROUP on ug.GID equals g.GID
|
|
where g.GNAME == "服务组"
|
|
select w.USERNAME;
|
|
var rList = (from rc in db.WX_RESOURCECHECK select new { rc.USERNAME, rc.JOBUSERNAME }).Distinct();
|
|
var list = from p in db.WX_RCONTACT
|
|
join t in (from rc in db.WX_RESOURCECHECK select new { rc.USERNAME, rc.CTIME }).Distinct() on p.USERNAME equals t.USERNAME
|
|
join w in
|
|
(from ww in db.WX_WORKACCOUNT where !afterSaleList.Contains(ww.USERNAME) select ww) on p.JOBWXUSERNAME equals w.USERNAME
|
|
where !rList.Any(r => r.JOBUSERNAME == p.JOBWXUSERNAME && r.USERNAME == p.USERNAME) && !db.WX_RESOURCECHECK_NOTE.Any(m => m.USERNAME == p.USERNAME)
|
|
orderby t.CTIME descending
|
|
select new WxResourceCheckView()
|
|
{
|
|
Eid = w.INNERUSERID.Value,
|
|
alias = w.ALIAS,
|
|
UserName = p.USERNAME,
|
|
JobUserName = p.JOBWXUSERNAME,
|
|
NickName = p.NICKNAME,
|
|
ReMark = p.CONREMARK,
|
|
InneruserId = w.INNERUSERID.Value
|
|
};
|
|
list = list.Where(where);
|
|
return list.ToList();
|
|
}
|
|
}
|
|
|
|
public IList<WX_RCONTACT_VIEW> GetMyWxCustomerList(Pager pager, string resId, string userName, string alias, string conreMark, string nickName, string jobWxUser, string stime, string etime, decimal userId, string isopen)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var where = PredicateExtensionses.True<WX_RCONTACT_VIEW>();
|
|
if (!string.IsNullOrWhiteSpace(resId))
|
|
{
|
|
where = where.And(p => p.RESID == resId);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(userName))
|
|
{
|
|
where = where.And(p => p.USERNAME.Contains(userName));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(alias))
|
|
{
|
|
where = where.And(p => p.ALIAS.Contains(alias));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(conreMark))
|
|
{
|
|
where = where.And(p => p.CONREMARK.Contains(conreMark));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(jobWxUser))
|
|
{
|
|
where = where.And(p => p.JOBWXUSERNAME == jobWxUser);
|
|
}
|
|
else
|
|
{
|
|
var myWorkAccountList = new WX_WORKACCOUNT_BL().GetMyWorkAccountList(userId);
|
|
List<string> jobWxList = new List<string>();
|
|
foreach (var workAccount in myWorkAccountList)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(workAccount.USERNAME))
|
|
{
|
|
jobWxList.Add(workAccount.USERNAME);
|
|
}
|
|
}
|
|
where = where.And(p => jobWxList.Contains(p.JOBWXUSERNAME));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(stime))
|
|
{
|
|
DateTime dt = Convert.ToDateTime(stime);
|
|
where = where.And(p => p.CTIME >= dt);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(etime))
|
|
{
|
|
DateTime dt = Convert.ToDateTime(etime).AddDays(1);
|
|
where = where.And(p => p.CTIME < dt);
|
|
}
|
|
if (!string.IsNullOrEmpty(isopen))
|
|
{
|
|
var letIsOpen = int.Parse(isopen);
|
|
if (letIsOpen == 1)
|
|
where = where.And(p => p.IsOpen == letIsOpen);
|
|
else
|
|
where = where.And(p => p.IsOpen == null);
|
|
//where = where.And(p => p.IsOpen == letIsOpen);
|
|
}
|
|
|
|
var query = from r in db.WX_RCONTACT
|
|
join c in db.RES_CUSTOMER on r.RESID equals c.RESID
|
|
join o in (db.WX_SZZYORDER.Where(p => p.ISOPEN == 1).GroupBy(p => new { p.CUSTOMERUSERNAME, p.ISOPEN }).Select(g => new { g.Key.CUSTOMERUSERNAME, g.Key.ISOPEN })) on r.USERNAME equals o.CUSTOMERUSERNAME into tmp0
|
|
from ro in tmp0.DefaultIfEmpty()
|
|
//join c in db.WX_COMMISSIONRULE.Where(p => p.SALEUSERID == userId) on ro.ORDERID equals c.ORDERID into tmp1
|
|
//from roc in tmp1.DefaultIfEmpty()
|
|
select new WX_RCONTACT_VIEW()
|
|
{
|
|
PKID = r.PKID,
|
|
JOBWXUSERNAME = r.JOBWXUSERNAME,
|
|
USERNAME = r.USERNAME,
|
|
ALIAS = r.ALIAS,
|
|
RESID = c.UMID,
|
|
NICKNAME = r.NICKNAME,
|
|
CONREMARK = r.CONREMARK,
|
|
CTIME = r.CTIME,
|
|
IsOpen = ro.ISOPEN
|
|
};
|
|
query = query.Where(where);
|
|
query = query.OrderByDescending(p => p.CTIME);
|
|
PagerUtil.SetPager<WX_RCONTACT_VIEW>(ref query, ref pager);
|
|
return query.ToList();
|
|
}
|
|
}
|
|
|
|
public List<WX_JOBUSERLASTFRIEND> GetJobWeiXinLastFriendList()
|
|
{
|
|
List<WX_JOBUSERLASTFRIEND> list = new List<WX_JOBUSERLASTFRIEND>();
|
|
DataSet ds = wx_Rcontact_DAL.GetJobWeiXinLastFriendList();
|
|
if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
|
|
{
|
|
list = ds.Tables[0].ToList<WX_JOBUSERLASTFRIEND>();
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public decimal GetDistinctWeiXinFriendCount(string day, decimal? type, decimal? saleDeptId)
|
|
{
|
|
return wx_Rcontact_DAL.GetDistinctWeiXinFriendCount(day, type, saleDeptId);
|
|
}
|
|
|
|
public int ResourceByTagDistinctCount(DateTime beginTime, string tag)
|
|
{
|
|
return wx_Rcontact_DAL.ResourceByTagDistinctCount(beginTime, tag);
|
|
}
|
|
|
|
public int ResourceByNameDistinctCount(DateTime beginTime, string tag, decimal? groupid)
|
|
{
|
|
return wx_Rcontact_DAL.ResourceByNameDistinctCount(beginTime, tag, groupid);
|
|
}
|
|
|
|
public DataTable GetRcontactByResId(string resid)
|
|
{
|
|
return new WX_RCONTACT_DAL().GetRcontactList(resid);
|
|
}
|
|
|
|
public DataTable GetChatUserByResId(string resid)
|
|
{
|
|
return new WX_RCONTACT_DAL().GetChatUserByResId(resid);
|
|
}
|
|
|
|
public DataTable GetChatQwByResId(string resid)
|
|
{
|
|
return new WX_RCONTACT_DAL().GetChatQwByResId(resid);
|
|
}
|
|
|
|
public DataTable GetChatUser(string resid, string username, string alias, string nickname, string conremark, string jobusername, string workalias, decimal? eid)
|
|
{
|
|
return new WX_RCONTACT_DAL().GetChatUser(resid, username, alias, nickname, conremark, jobusername, workalias, eid);
|
|
}
|
|
|
|
public bool UpdateRcontactResId(ref ValidationErrors errors, string username, string resid, decimal inneruserid)
|
|
{
|
|
bool isSucced = true;
|
|
try
|
|
{
|
|
new WX_RCONTACT_DAL().UpdateRcontactResId(username, resid, inneruserid);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add("出现错误:" + ex.ToString());
|
|
LogHelper.Error(ex.ToString());
|
|
isSucced = false;
|
|
}
|
|
return isSucced;
|
|
}
|
|
|
|
public WX_RCONTACT GetModel(string jobusername, string username)
|
|
{
|
|
using (crmContext db = new crmContext())
|
|
{
|
|
return db.WX_RCONTACT.FirstOrDefault(m => m.USERNAME == username && m.JOBWXUSERNAME == jobusername);
|
|
}
|
|
}
|
|
|
|
public DataSet GetWeixinFriendCount(decimal type)
|
|
{
|
|
return wx_Rcontact_DAL.GetWeixinFriendCount(type);
|
|
}
|
|
|
|
public int UpadteUserPoint(ref ValidationErrors errors, string eids, string points, decimal type)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrWhiteSpace(eids) || string.IsNullOrWhiteSpace(eids) || string.IsNullOrWhiteSpace(points))
|
|
{
|
|
return (int)WxUpdatePercentFlag.ParamsError;
|
|
}
|
|
string[] eidArry = eids.Split(',');
|
|
string[] pointArry = points.Split(',');
|
|
|
|
for (int i = 0; i < eidArry.Length; i++)
|
|
{
|
|
decimal eid = Convert.ToDecimal(eidArry[i]);
|
|
decimal point = Convert.ToDecimal(pointArry[i]);
|
|
wx_Rcontact_DAL.UpadteUserPoint(eid, point);
|
|
}
|
|
wx_Rcontact_DAL.ComputeToPushData(eids, type);
|
|
return (int)WxUpdatePercentFlag.Success;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return (int)WxUpdatePercentFlag.Fail;
|
|
}
|
|
}
|
|
|
|
public List<WX_UserCommissionCount> CountSaleUserCommission()
|
|
{
|
|
return wx_Rcontact_DAL.CountSaleUserCommission().ToList<WX_UserCommissionCount>();
|
|
}
|
|
|
|
public List<WX_GroupCommissionCount> CountSaleGroupCommission()
|
|
{
|
|
return wx_Rcontact_DAL.CountSaleGroupCommission().ToList<WX_GroupCommissionCount>();
|
|
}
|
|
|
|
public List<WX_RCONTACT_UserNameCount> GetRcontactUserNameCount(string stime, string etime, List<string> usernameList)
|
|
{
|
|
var usernames = "";
|
|
if (string.IsNullOrEmpty(stime))
|
|
{
|
|
stime = DateTime.Now.ToShortDateString();
|
|
}
|
|
if (string.IsNullOrEmpty(etime))
|
|
{
|
|
etime = DateTime.Now.AddDays(1).ToShortDateString();
|
|
}
|
|
else
|
|
{
|
|
etime = Convert.ToDateTime(etime).AddDays(1).ToShortDateString();
|
|
}
|
|
if (usernameList != null)
|
|
{
|
|
foreach (var m in usernameList)
|
|
{
|
|
usernames += "'" + m + "',";
|
|
}
|
|
if (usernames != null)
|
|
{
|
|
usernames = usernames.TrimEnd(',');
|
|
}
|
|
}
|
|
DataSet ds = wx_Rcontact_DAL.GetRcontactUserNameCount(stime, etime, usernames);
|
|
if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
|
|
{
|
|
return ds.Tables[0].ToList<WX_RCONTACT_UserNameCount>();
|
|
}
|
|
return new List<WX_RCONTACT_UserNameCount>(); ;
|
|
}
|
|
|
|
public DataSet GetWebChatResourceList(DateTime? beginTime, DateTime? endTime, decimal? type)
|
|
{
|
|
return wx_Rcontact_DAL.GetWebChatResourceList(beginTime, endTime, type);
|
|
}
|
|
|
|
public DataSet GetWebChatResourceDetail(DateTime? beginTime, DateTime? endTime, string jobUsername)
|
|
{
|
|
return wx_Rcontact_DAL.GetWebChatResourceDetail(beginTime, endTime, jobUsername);
|
|
}
|
|
|
|
//public List<WX_RCONTACT_Extend> GetList(ref Pager page, string username, string jobwxusername, string inneruserId, string groupId, decimal salesId, string stime, string etime)
|
|
//{
|
|
// using (var db = new crmContext())
|
|
// {
|
|
// var queryData = db.WX_RCONTACT.AsQueryable();
|
|
// var inneruserJobNumData = db.WX_INNERUSERJOBNUM.AsEnumerable();
|
|
// if (!string.IsNullOrWhiteSpace(username))
|
|
// {
|
|
// username = username.Trim();
|
|
// queryData = queryData.Where(m => m.USERNAME.Contains(username));
|
|
// }
|
|
// if (!string.IsNullOrWhiteSpace(jobwxusername))
|
|
// {
|
|
// jobwxusername = jobwxusername.Trim();
|
|
// queryData = queryData.Where(m => m.JOBWXUSERNAME.Contains(jobwxusername));
|
|
// }
|
|
|
|
// if (!string.IsNullOrWhiteSpace(stime))
|
|
// {
|
|
// DateTime time1 = Convert.ToDateTime(stime);
|
|
// queryData = queryData.Where(m => m.CTIME >= time1);
|
|
// }
|
|
// if (!string.IsNullOrWhiteSpace(etime))
|
|
// {
|
|
// DateTime time2 = Convert.ToDateTime(etime).AddDays(1);
|
|
// queryData = queryData.Where(m => m.CTIME >= time2);
|
|
// }
|
|
// if (!string.IsNullOrWhiteSpace(inneruserId))
|
|
// {
|
|
// decimal userid = Convert.ToDecimal(inneruserId);
|
|
// inneruserJobNumData = inneruserJobNumData.Where(m => m.INNERUSERID == userid);
|
|
// }
|
|
// else if (!string.IsNullOrWhiteSpace(groupId))
|
|
// {
|
|
// decimal[] _groupIds = OperationUtil.ConvertToDecimal(groupId.Split(','));
|
|
// var userids = db.BAS_INNERUSERGROUP.Where(m => _groupIds.Contains(m.GID.Value)).Select(m => m.INNERUSERID);
|
|
// inneruserJobNumData = inneruserJobNumData.Where(m => userids.Contains(m.INNERUSERID.Value));
|
|
// }
|
|
// if (salesId > 0)
|
|
// inneruserJobNumData = inneruserJobNumData.Where(m => m.INNERUSERID == salesId);
|
|
|
|
// var returnData = (from a in queryData
|
|
// join b in inneruserJobNumData on a.JOBWXUSERNAME equals b.WXUSERNAME
|
|
// join c in db.BAS_INNERUSER on b.INNERUSERID equals c.PKID
|
|
// join d in db.BAS_INNERUSERGROUP on c.PKID equals d.INNERUSERID
|
|
// join e in db.BAS_INNERGROUP on d.GID equals e.GID
|
|
// select new WX_RCONTACT_Extend()
|
|
// {
|
|
// wx_rcontact = a,
|
|
// groupid = d.GID.Value,
|
|
// groupName = e.GNAME,
|
|
// inneruserEid = c.EID,
|
|
// inneruserName = c.TRUENAME,
|
|
// inneruserId = c.PKID
|
|
// });
|
|
// returnData = returnData.OrderBy(m => m.groupid).OrderBy(m => m.inneruserEid).OrderBy(m => m.wx_rcontact.JOBWXUSERNAME).OrderBy(m => m.wx_rcontact.USERNAME);
|
|
// PagerUtil.SetPager<WX_RCONTACT_Extend>(ref returnData, ref page);
|
|
// return returnData.ToList();
|
|
// }
|
|
|
|
/// <summary>
|
|
/// 获取工作微信的订单客户
|
|
/// </summary>
|
|
/// <param name="jobusername"></param>
|
|
/// <returns></returns>
|
|
public DataTable GetOrderUserName(string jobusername)
|
|
{
|
|
return new WX_RCONTACT_DAL().GetOrderUserName(jobusername);
|
|
}
|
|
}
|
|
} |