Commit e3c7c837 authored by liudong1993's avatar liudong1993

1探马客户

parent 0a02ab0b
using Edu.Common.Plugin;
using System;
using System.Collections.Generic;
using System.Text;
namespace Edu.Common.Enum.WeChat
{
/// <summary>
/// 企业微信客户添加方式枚举
/// </summary>
public enum CustomerAddWayEnum
{
/// <summary>
/// 好友创建
/// </summary>
[EnumField("好友创建")]
Friend = 1,
/// <summary>
/// 转移添加
/// </summary>
[EnumField("转移添加")]
Transfer = 2,
/// <summary>
/// 个人创建
/// </summary>
[EnumField("个人创建")]
Person = 3,
/// <summary>
/// 公司分配
/// </summary>
[EnumField("公司分配")]
Company = 4,
/// <summary>
/// 公海领取
/// </summary>
[EnumField("公海领取")]
Public = 5,
}
}
using Edu.Common.Plugin;
using System;
using System.Collections.Generic;
using System.Text;
namespace Edu.Common.Enum.WeChat
{
/// <summary>
/// 企业微信旅程类型枚举
/// </summary>
public enum CustomerTripTypeEnum
{
/// <summary>
/// 行为动态
/// </summary>
[EnumField("行为动态")]
Behavior = 1,
/// <summary>
/// 操作动态
/// </summary>
[EnumField("操作动态")]
Operate = 2,
/// <summary>
/// 跟进记录
/// </summary>
[EnumField("跟进记录")]
FollowUp = 3,
/// <summary>
/// 签到记录
/// </summary>
[EnumField("签到记录")]
Check = 4,
/// <summary>
/// 聊天
/// </summary>
[EnumField("聊天")]
Chat = 5,
/// <summary>
/// 短信
/// </summary>
[EnumField("短信")]
Message = 6,
/// <summary>
/// 通话
/// </summary>
[EnumField("通话")]
Tell = 7,
/// <summary>
/// 流转记录
/// </summary>
[EnumField("流转记录")]
Record = 8
}
}
using Edu.Common.Enum;
using Edu.Common.Enum.Course;
using Edu.Common.Enum.WeChat;
using System;
using VT.FW.DB;
namespace Edu.Model.Entity.WeChat
{
/// <summary>
/// 企业微信客户信息实体类
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_WeChat_CustomerInfo
{
/// <summary>
/// Id
/// </summary>
public int Id { get; set; }
/// <summary>
/// 员工id
/// </summary>
public int EmpId { get; set; }
/// <summary>
/// 员工企业微信Id
/// </summary>
public string WorkEmpId { get; set; }
/// <summary>
/// 员工企业微信名称
/// </summary>
public string WorkEmpName { get; set; }
/// <summary>
/// 客户企业微信Id
/// </summary>
public string ExternalUserId { get; set; }
/// <summary>
/// 删除状态
/// </summary>
public int Status { get; set; }
/// <summary>
/// 集团编号
/// </summary>
public int Group_Id { get; set; }
/// <summary>
/// 创建人
/// </summary>
public int CreateBy { get; set; }
/// <summary>
/// 创建日期
/// </summary>
public DateTime CreateTime { get; set; }
/// <summary>
/// 修改人
/// </summary>
public int UpdateBy { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdateTime { get; set; }
/// <summary>
/// 该成员对此客人的备注
/// </summary>
public string CustomerName { get; set; }
/// <summary>
/// 微信名称
/// </summary>
public string WeChatName { get; set; }
/// <summary>
/// 微信头像
/// </summary>
public string WeChatPhoto { get; set; }
/// <summary>
/// 外部联系人所在企业的简称(企业微信用户)
/// </summary>
public string CorpName { get; set; }
/// <summary>
/// 外部联系人所在企业的主体名称(企业微信用户)
/// </summary>
public string CorpFullName { get; set; }
/// <summary>
/// 类型,1微信用户,2企业微信用户
/// </summary>
public int CustomerType { get; set; }
/// <summary>
/// 阶段id
/// </summary>
public int StageId { get; set; }
/// <summary>
/// 企业标签ids
/// </summary>
public string LableIds { get; set; }
/// <summary>
/// 员工设置个人标签
/// </summary>
public string PersonLable { get; set; }
/// <summary>
/// 活码来源
/// </summary>
public string Source { get; set; }
/// <summary>
/// 自定义客户字段内容 json格式 需根据客户字段来查找
/// </summary>
public string CustomContent { get; set; }
/// <summary>
/// 好友状态 1好友客户 2待添加 3已申请
/// </summary>
public int FriendState { get; set; }
/// <summary>
/// 好友添加的时间
/// </summary>
public DateTime? FriendTime { get; set; }
/// <summary>
/// 上次跟进日期
/// </summary>
public DateTime? LastFollowUpTime { get; set; }
/// <summary>
/// 签到拜访数量
/// </summary>
public int CheckInNum { get; set; }
/// <summary>
/// 是否公海客户 1是 2否
/// </summary>
public int IsPublic { get; set; }
/// <summary>
/// 客户手机号码 多个英文逗号分隔
/// </summary>
public string CustomerMobile { get; set; }
/// <summary>
/// 添加方式枚举
/// </summary>
public CustomerAddWayEnum AddWay { get; set; }
/// <summary>
/// 系统备注
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 微信客户来源
/// </summary>
public int WeChatAddWay { get; set; }
}
}
using Edu.Common.Enum;
using Edu.Common.Enum.Course;
using Edu.Common.Enum.WeChat;
using System;
using VT.FW.DB;
namespace Edu.Model.Entity.WeChat
{
/// <summary>
/// 企业微信客户记录实体类
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_WeChat_CustomerTrip
{
/// <summary>
/// Id
/// </summary>
public int Id { get; set; }
/// <summary>
/// 类型 枚举
/// </summary>
public CustomerTripTypeEnum Type { get; set; }
/// <summary>
/// 客户id
/// </summary>
public int CustomerId { get; set; }
/// <summary>
/// 员工id
/// </summary>
public int EmpId { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 图片地址 List<string>
/// </summary>
public string Images { get; set; }
/// <summary>
/// 附件 文件名称 地址 大小 json格式
/// </summary>
public string Files { get; set; }
/// <summary>
/// 删除状态
/// </summary>
public int Status { get; set; }
/// <summary>
/// 集团编号
/// </summary>
public int Group_Id { get; set; }
/// <summary>
/// 创建人
/// </summary>
public int CreateBy { get; set; }
/// <summary>
/// 创建日期
/// </summary>
public DateTime CreateTime { get; set; }
/// <summary>
/// 修改人
/// </summary>
public int UpdateBy { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdateTime { get; set; }
}
}
......@@ -20,6 +20,11 @@ namespace Edu.Model.ViewModel.WeChat
/// 部门名称
/// </summary>
public string DeptName { get; set; }
/// <summary>
/// 当前客户对应字段的值
/// </summary>
public string Value { get; set; }
}
/// <summary>
......
using System;
using System.Collections.Generic;
using System.Text;
using Edu.Common.Enum.Sale;
using Edu.Model.Entity.WeChat;
namespace Edu.Model.ViewModel.WeChat
{
/// <summary>
/// 企业微信客户信息扩展类
/// </summary>
public class RB_WeChat_CustomerInfo_ViewModel : RB_WeChat_CustomerInfo
{
/// <summary>
/// 查询自定义参数
/// </summary>
public List<CustomerInfoSelectModel> SelectList { get; set; }
/// <summary>
/// 查询条件 1并且 2或者
/// </summary>
public int AddCondition { get; set; }
/// <summary>
/// 企业标签列表
/// </summary>
public List<RB_WeChat_Lable_ViewModel> LableList { get; set; }
/// <summary>
/// 自定义字段值
/// </summary>
public List<CustomFiledContentExtend> CustomFiledList { get; set; }
/// <summary>
/// 字段明细列表(包含下拉选项s)
/// </summary>
public List<RB_WeChat_CustomerField_ViewModel> FiledDetailList { get; set; }
/// <summary>
/// 客户阶段名称
/// </summary>
public string StageName { get; set; }
/// <summary>
/// 内部员工名称
/// </summary>
public string EmpName { get; set; }
/// <summary>
/// 未跟进天数
/// </summary>
public int Q_NotFollowUpDay { get; set; }
/// <summary>
/// 排序 1创建时间升序 2创建时间降序 3跟进时间升序 4跟进时间降序
/// </summary>
public int OrderBy { get; set; }
/// <summary>
/// 好友关系
/// </summary>
public string Q_Friends { get; set; }
/// <summary>
/// 获取途径
/// </summary>
public string Q_AddWay { get; set; }
/// <summary>
/// 创建开始时间
/// </summary>
public string CreateSTime { get; set; }
/// <summary>
/// 创建结束时间
/// </summary>
public string CreateETime { get; set; }
/// <summary>
/// 好友开始时间
/// </summary>
public string FriendSTime { get; set; }
/// <summary>
/// 好友结束时间
/// </summary>
public string FriendETime { get; set; }
}
/// <summary>
/// 扩展字段查询Model
/// </summary>
public class CustomerInfoSelectModel {
/// <summary>
/// 字段名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 类型 1包含 2等于 3日期 4日期范围 5数值
/// </summary>
public int Type { get; set; }
/// <summary>
/// 方向 1包含所有/等于/等于 2包含任意/不等于/大于 3不包含/为空/大于等于 4为空/不为空/小于 5不为空/模糊/小于等于 对应 type的1/2/5
/// </summary>
public int Direction { get; set; }
/// <summary>
/// 开始值
/// </summary>
public string StartValue { get; set; }
/// <summary>
/// 结束值
/// </summary>
public string EndValue { get; set; }
/// <summary>
/// 是否自定义字段 1是 2否
/// </summary>
public int IsCustom { get; set; }
}
/// <summary>
/// 客户信息自定义字段存值
/// </summary>
public class CustomerFiledContentModel {
/// <summary>
/// 字段ID
/// </summary>
public int Id { get; set; }
/// <summary>
/// 字段值 多选的:英文逗号分隔
/// </summary>
public string Value { get; set; }
}
/// <summary>
/// 自定义字段返回扩展
/// </summary>
public class CustomFiledContentExtend : CustomerFiledContentModel
{
/// <summary>
/// 字段名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 显示值
/// </summary>
public string ShowValue { get; set; }
/// <summary>
/// 排序
/// </summary>
public int Sort { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Edu.Common.Enum.Sale;
using Edu.Model.Entity.WeChat;
using Edu.Model.Public;
namespace Edu.Model.ViewModel.WeChat
{
/// <summary>
/// 企业微信客户旅途记录扩展类
/// </summary>
public class RB_WeChat_CustomerTrip_ViewModel : RB_WeChat_CustomerTrip
{
/// <summary>
/// 文件列表
/// </summary>
public List<FileModel> FileList { get; set; }
/// <summary>
/// 图片列表
/// </summary>
public List<string> ImageList { get; set; }
/// <summary>
/// 员工名称
/// </summary>
public string UpdateByName { get; set; }
}
}
......@@ -9,6 +9,7 @@ using Edu.Common.API;
using Edu.Common.Enum.Finance;
using Edu.Common.Plugin;
using Edu.Model.CacheModel;
using Edu.Model.Public;
using Edu.Model.ViewModel.User;
using Edu.Model.ViewModel.WeChat;
using Edu.Repository.User;
......@@ -26,6 +27,10 @@ namespace Edu.Module.QYWeChat
/// </summary>
public class QYCustomerModule
{
/// <summary>
/// 配置
/// </summary>
private RB_WeChat_ConfigRepository weChat_ConfigRepository = new RB_WeChat_ConfigRepository();
/// <summary>
/// 客户字段
/// </summary>
......@@ -39,6 +44,18 @@ namespace Edu.Module.QYWeChat
/// </summary>
private RB_WeChat_CustomerStageFlowRepository weChat_CustomerStageFlowRepository = new RB_WeChat_CustomerStageFlowRepository();
/// <summary>
/// 客户信息
/// </summary>
private RB_WeChat_CustomerInfoRepository weChat_CustomerInfoRepository = new RB_WeChat_CustomerInfoRepository();
/// <summary>
/// 客户旅程(操作记录)
/// </summary>
private RB_WeChat_CustomerTripRepository weChat_CustomerTripRepository = new RB_WeChat_CustomerTripRepository();
/// <summary>
/// 客户标签
/// </summary>
private readonly RB_WeChat_LableRepository weChat_LableRepository = new RB_WeChat_LableRepository();
/// <summary>
/// 部门
/// </summary>
private RB_DepartmentRepository departmentRepository = new RB_DepartmentRepository();
......@@ -549,5 +566,802 @@ namespace Edu.Module.QYWeChat
}
#endregion
#region 客户管理
/// <summary>
/// 获取客户分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="count"></param>
/// <param name="demodel"></param>
/// <returns></returns>
public List<RB_WeChat_CustomerInfo_ViewModel> GetCustomerInfoPageList(int pageIndex, int pageSize, out long count, RB_WeChat_CustomerInfo_ViewModel demodel)
{
var list = weChat_CustomerInfoRepository.GetPageList(pageIndex, pageSize, out count, demodel);
if (list.Any()) {
//客户标签
string lableIds = string.Join(",", list.Where(x => !string.IsNullOrEmpty(x.LableIds)).Select(x => x.LableIds));
List<RB_WeChat_Lable_ViewModel> LableList = new List<RB_WeChat_Lable_ViewModel>();
if (!string.IsNullOrEmpty(lableIds)) {
LableList = weChat_LableRepository.GetList(new RB_WeChat_Lable_ViewModel() { Group_Id = demodel.Group_Id, LableIds = lableIds });
}
//客户阶段
string stageIds = string.Join(",", list.Where(x => x.StageId > 0).Select(x => x.StageId));
List<RB_WeChat_CustomerStage_ViewModel> StageList = new List<RB_WeChat_CustomerStage_ViewModel>();
if (!string.IsNullOrEmpty(stageIds)) {
StageList = weChat_CustomerStageRepository.GetList(new RB_WeChat_CustomerStage_ViewModel() { Group_Id = demodel.Group_Id, StageIds = stageIds });
}
//负责人
string EmpWorkUserId = "'" + string.Join("','", list.Where(x => !string.IsNullOrEmpty(x.WorkEmpId)).Select(x => x.WorkEmpId).Distinct()) + "'";
List<Employee_ViewModel> EmpList = new List<Employee_ViewModel>();
if (EmpWorkUserId != "''")
{
EmpList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = demodel.Group_Id, WorkUserIds = EmpWorkUserId });
}
//上次跟进时间
//string customerIds = string.Join(",", list.Select(x => x.Id));
//var fuList = weChat_CustomerTripRepository.GetLastFollowUpTimeList(demodel.Group_Id, customerIds);
//自定义字段 -- 这个怎么处理呢 根据自定义子段遍历吗
//先直接返回自定义子段
var cFieldList = weChat_CustomerFieldRepository.GetList(new RB_WeChat_CustomerField_ViewModel() { Group_Id = demodel.Group_Id, Enable = 1 });
foreach (var item in cFieldList) {
item.OptionsList = new List<CustomerOptions>();
if (!string.IsNullOrEmpty(item.Options))
{
item.OptionsList = JsonHelper.DeserializeObject<List<CustomerOptions>>(item.Options);
}
}
foreach (var item in list) {
item.LableList = LableList.Where(x => ("," + x.LableIds + ",").Contains("," + x.Id + ",")).ToList();
item.StageName = StageList.Where(x => x.Id == item.StageId).FirstOrDefault()?.Name ?? "";
var empModel = EmpList.Where(x => x.WorkUserId == item.WorkEmpId).FirstOrDefault();
item.EmpId = empModel?.Id ?? 0;
item.EmpName = (empModel?.EmployeeName ?? "") + ((empModel?.IsLeave ?? 0) == 2 ? "(已离职)" : "");
List<CustomerFiledContentModel> CustomValueList = new List<CustomerFiledContentModel>();
if (!string.IsNullOrEmpty(item.CustomContent)) {
var keyValueList = JsonHelper.DeserializeObject<Dictionary<string, string>>(item.CustomContent);
foreach (var kitem in keyValueList) {
CustomValueList.Add(new CustomerFiledContentModel
{
Id = Convert.ToInt32(kitem.Key.Replace("z", "")),
Value = kitem.Value
});
}
}
item.CustomFiledList = new List<CustomFiledContentExtend>();
foreach (var qitem in cFieldList) {
var cmodel = CustomValueList.Where(x => x.Id == qitem.Id).FirstOrDefault();
string value = cmodel?.Value ?? "";
if (qitem.Type == Common.Enum.WeChat.CustomerFieldTypeEnum.Date)
{
item.CustomFiledList.Add(new CustomFiledContentExtend()
{
Id = qitem.Id,
Value = value,
ShowValue = value != "" ? Convert.ToDateTime(value).ToString("yyyy-MM-dd") : "",
Name = qitem.Name,
Sort = qitem.Sort
});
}
else if (qitem.Type == Common.Enum.WeChat.CustomerFieldTypeEnum.MultiSelect)
{
var optionList = qitem.OptionsList.Where(x => ("," + value + ",").Contains("," + x.Id + ",")).ToList();
item.CustomFiledList.Add(new CustomFiledContentExtend()
{
Id = qitem.Id,
ShowValue = string.Join(",", optionList.Select(x => x.Name)),
Value = string.Join(",", optionList.Select(x => x.Id)),
Name = qitem.Name,
Sort = qitem.Sort
});
}
else if (qitem.Type == Common.Enum.WeChat.CustomerFieldTypeEnum.Radio)
{
int vInt = Convert.ToInt32(value == "" ? "0" : value);
var Name = qitem.OptionsList.Where(x => x.Id == vInt).FirstOrDefault()?.Name ?? "";
item.CustomFiledList.Add(new CustomFiledContentExtend()
{
Id = qitem.Id,
ShowValue = Name,
Value = value,
Name = qitem.Name,
Sort = qitem.Sort
});
}
else if (qitem.Type == Common.Enum.WeChat.CustomerFieldTypeEnum.Time)
{
item.CustomFiledList.Add(new CustomFiledContentExtend()
{
Id = qitem.Id,
ShowValue = value != "" ? Convert.ToDateTime(value).ToString("yyyy-MM-dd HH:mm") : "",
Value = value,
Name = qitem.Name,
Sort = qitem.Sort
});
}
else {
item.CustomFiledList.Add(new CustomFiledContentExtend()
{
Id = qitem.Id,
ShowValue = value,
Value = value,
Name = qitem.Name,
Sort = qitem.Sort
});
}
}
}
}
return list;
}
/// <summary>
/// 获取客户列表
/// </summary>
/// <param name="demodel"></param>
/// <returns></returns>
public List<RB_WeChat_CustomerInfo_ViewModel> GetCustomerInfoList(RB_WeChat_CustomerInfo_ViewModel demodel) {
return weChat_CustomerInfoRepository.GetList(demodel);
}
/// <summary>
/// 获取客户信息
/// </summary>
/// <param name="customerId"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
public RB_WeChat_CustomerInfo_ViewModel GetCustomerInfo(int customerId, UserInfo userInfo)
{
var model = weChat_CustomerInfoRepository.GetEntity<RB_WeChat_CustomerInfo_ViewModel>(customerId);
if (model == null) { return null; }
//客户标签
if (!string.IsNullOrEmpty(model.LableIds))
{
model.LableList = weChat_LableRepository.GetList(new RB_WeChat_Lable_ViewModel() { Group_Id = userInfo.Group_Id, LableIds = model.LableIds });
}
//客户阶段
if (model.StageId > 0)
{
model.StageName = weChat_CustomerStageRepository.GetList(new RB_WeChat_CustomerStage_ViewModel() { Group_Id = userInfo.Group_Id, Id = model.StageId }).FirstOrDefault()?.Name ?? "";
}
//负责人
if (!string.IsNullOrEmpty(model.WorkEmpId))
{
var empModel = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, WorkUserId = model.WorkEmpId }).FirstOrDefault();
model.EmpId = empModel?.Id ?? 0;
model.EmpName = (empModel?.EmployeeName ?? "") + ((empModel?.IsLeave ?? 0) == 2 ? "(已离职)" : "");
}
var cFieldList = weChat_CustomerFieldRepository.GetList(new RB_WeChat_CustomerField_ViewModel() { Group_Id = userInfo.Group_Id, Enable = 1 });
foreach (var item in cFieldList)
{
item.OptionsList = new List<CustomerOptions>();
if (!string.IsNullOrEmpty(item.Options))
{
item.OptionsList = JsonHelper.DeserializeObject<List<CustomerOptions>>(item.Options);
}
}
List<CustomerFiledContentModel> CustomValueList = new List<CustomerFiledContentModel>();
if (!string.IsNullOrEmpty(model.CustomContent))
{
var keyValueList = JsonHelper.DeserializeObject<Dictionary<string, string>>(model.CustomContent);
foreach (var kitem in keyValueList)
{
CustomValueList.Add(new CustomerFiledContentModel
{
Id = Convert.ToInt32(kitem.Key.Replace("z", "")),
Value = kitem.Value
});
}
}
foreach (var qitem in cFieldList)
{
qitem.Value = CustomValueList.Where(x => x.Id == qitem.Id).FirstOrDefault()?.Value ?? "";
}
model.FiledDetailList = cFieldList;
return model;
}
/// <summary>
/// 设置客户信息
/// </summary>
/// <param name="customerId"></param>
/// <param name="type"></param>
/// <param name="customId"></param>
/// <param name="value"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
public string SetCustomerInfo(int customerId, int type, int customId, string value, UserInfo userInfo)
{
var cmodel = weChat_CustomerInfoRepository.GetEntity(customerId);
if (cmodel == null || cmodel.Group_Id != userInfo.Group_Id) { return "客户不存在"; }
Dictionary<string, object> keyValues = new Dictionary<string, object>() { };
if (type == 1)
{
//1客户阶段
keyValues.Add(nameof(RB_WeChat_CustomerInfo_ViewModel.StageId), Convert.ToInt32(value));
}
else if (type == 2)
{
//自定义字段
var custModel = weChat_CustomerFieldRepository.GetEntity(customId);
if (custModel == null) { return "字段不存在"; }
List<CustomerFiledContentModel> FiledValueList = new List<CustomerFiledContentModel>();
if (!string.IsNullOrEmpty(cmodel.CustomContent))
{
var keyValueList = JsonHelper.DeserializeObject<Dictionary<string, string>>(cmodel.CustomContent);
foreach (var kitem in keyValueList)
{
FiledValueList.Add(new CustomerFiledContentModel
{
Id = Convert.ToInt32(kitem.Key.Replace("z", "")),
Value = kitem.Value
});
}
}
if (FiledValueList.Where(x => x.Id == customId).Any())
{
//修改
var fmodel = FiledValueList.Where(x => x.Id == customId).FirstOrDefault();
fmodel.Value = value;
}
else
{
//新增
FiledValueList.Add(new CustomerFiledContentModel() { Id = customId, Value = value });
}
Dictionary<string, string> CustomContentKV = new Dictionary<string, string>();
foreach (var qitem in FiledValueList)
{
CustomContentKV.Add("z" + qitem.Id, qitem.Value);
}
keyValues.Add(nameof(RB_WeChat_CustomerInfo_ViewModel.CustomContent), JsonHelper.Serialize(CustomContentKV));
}
else if (type == 3) {
var oldLable = cmodel.LableIds;
var newLable = value;
//对比 那些需要删除 那些新增
//企业微信接口更新OK之后
}
else
{
return "type不正确";
}
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName= nameof(RB_WeChat_CustomerInfo_ViewModel.Id),
FiledValue= customerId,
OperatorEnum =OperatorEnum.Equal
},
};
bool flag = weChat_CustomerInfoRepository.Update(keyValues, wheres);
return flag ? "" : "出错了,请联系管理员";
}
/// <summary>
/// 获取客户旅程分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="count"></param>
/// <param name="demodel"></param>
/// <returns></returns>
public List<RB_WeChat_CustomerTrip_ViewModel> GetCustomerTripPageList(int pageIndex, int pageSize, out long count, RB_WeChat_CustomerTrip_ViewModel demodel)
{
var list = weChat_CustomerTripRepository.GetPageList(pageIndex, pageSize, out count, demodel);
if (list.Any()) {
//员工
string empIds = string.Join(",", list.Select(x => x.UpdateBy));
List<Employee_ViewModel> empList = new List<Employee_ViewModel>();
if (!string.IsNullOrEmpty(empIds)) {
empList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = demodel.Group_Id, QIds = empIds });
}
foreach (var item in list) {
item.UpdateByName = empList.Where(x => x.Id == item.UpdateBy).FirstOrDefault()?.EmployeeName ?? "";
item.ImageList = new List<string>();
if (!string.IsNullOrEmpty(item.Images)) {
item.ImageList = JsonHelper.DeserializeObject<List<string>>(item.Images);
}
item.FileList = new List<Model.Public.FileModel>();
if (!string.IsNullOrEmpty(item.Files)) {
item.FileList = JsonHelper.DeserializeObject<List<FileModel>>(item.Files);
}
}
}
return list;
}
/// <summary>
/// 新增客户跟进记录
/// </summary>
/// <param name="demodel"></param>
/// <returns></returns>
public string SetCustomerTripFollowUpInfo(RB_WeChat_CustomerTrip_ViewModel demodel)
{
bool flag;
if (demodel.Id > 0)
{
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_WeChat_CustomerTrip_ViewModel.Description), demodel.Description},
{ nameof(RB_WeChat_CustomerTrip_ViewModel.Remark), demodel.Remark},
{ nameof(RB_WeChat_CustomerTrip_ViewModel.Images), demodel.Images},
{ nameof(RB_WeChat_CustomerTrip_ViewModel.Files), demodel.Files},
{ nameof(RB_WeChat_CustomerTrip_ViewModel.UpdateBy), demodel.UpdateBy},
{ nameof(RB_WeChat_CustomerTrip_ViewModel.UpdateTime), demodel.UpdateTime},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName= nameof(RB_WeChat_CustomerTrip_ViewModel.Id),
FiledValue= demodel.Id,
OperatorEnum= OperatorEnum.Equal
}
};
flag = weChat_CustomerTripRepository.Update(keyValues, wheres);
}
else {
flag = weChat_CustomerTripRepository.Insert(demodel) > 0;
}
return flag ? "" : "出错了,请联系管理员";
}
/// <summary>
/// 删除客户旅程
/// </summary>
/// <param name="tripId"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
public string DelCustomerTripInfo(int tripId, UserInfo userInfo)
{
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_WeChat_CustomerTrip_ViewModel.Status), 1},
{ nameof(RB_WeChat_CustomerTrip_ViewModel.UpdateBy), userInfo.Id},
{ nameof(RB_WeChat_CustomerTrip_ViewModel.UpdateTime), DateTime.Now},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName= nameof(RB_WeChat_CustomerTrip_ViewModel.Id),
FiledValue= tripId,
OperatorEnum= OperatorEnum.Equal
},
new WhereHelper(){
FiledName= nameof(RB_WeChat_CustomerTrip_ViewModel.Group_Id),
FiledValue= userInfo.Group_Id,
OperatorEnum= OperatorEnum.Equal
},
};
var flag = weChat_CustomerTripRepository.Update(keyValues, wheres);
return flag ? "" : "出错了,请联系管理员";
}
/// <summary>
/// 初始化客户信息数据
/// </summary>
/// <param name="userInfo"></param>
/// <returns></returns>
public string InitializeCustomerInfoList(UserInfo userInfo)
{
//查询所有的带企业微信Id的用户列表
var empList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id });
empList = empList.Where(x => !string.IsNullOrEmpty(x.WorkUserId)).ToList();//排除未关联企业微信的员工
empList = empList.Where(x => x.Id == 2623).ToList();//暂时测试刘小勇账号 如果是微信删除了账号需测试-------------------
if (empList.Any()) {
//遍历员工列表 查询员工下所有的客户列表
List<string> WorkUserIdList = empList.Select(x => x.WorkUserId).ToList();
var configmodel = weChat_ConfigRepository.GetList(new RB_WeChat_Config_ViewModel() { Group_Id = userInfo.Group_Id, Enable = 1 }).FirstOrDefault();
if (configmodel == null || configmodel.Enable != 1) { return "未启用企业微信,无法同步"; }
string token = GetContactToken(userInfo.Group_Id, configmodel);
if (string.IsNullOrEmpty(token)) { return "token获取失败"; }
//获取所有的客户列表
List<ExternalContactList> AllContactList = new List<ExternalContactList>();
string next_cursor = "";
for (int i = 0; i <= 100; i++) {
if (i > 0 && next_cursor == "")
{
break;//没有下一页了 退出循环
}
var Rmsg = QYWeiXinHelper.GetExternalContactInfoBatch(token, WorkUserIdList, next_cursor, 100);
if (Rmsg.errcode != Senparc.Weixin.ReturnCode_Work.请求成功)
{
return "获取客户列表失败";
}
else
{
AllContactList.AddRange(Rmsg.external_contact_list);
}
}
if (AllContactList.Any()) {
//获取系统客户列表
var CustomerList = weChat_CustomerInfoRepository.GetList(new RB_WeChat_CustomerInfo_ViewModel() { Group_Id = userInfo.Group_Id });
//自定义字段
var FieldList = weChat_CustomerFieldRepository.GetList(new RB_WeChat_CustomerField_ViewModel() { Group_Id = userInfo.Group_Id, Enable = 1 });
//获取所有标签列表
var LableList = weChat_LableRepository.GetList(new RB_WeChat_Lable_ViewModel() { Group_Id = userInfo.Group_Id });
//查询所有的阶段流程
var FlowList = weChat_CustomerStageFlowRepository.GetList(new RB_WeChat_CustomerStageFlow_ViewModel() { Group_Id = userInfo.Group_Id, Enable = 1 });
foreach (var item in AllContactList) {
//与数据库客户数据对比
//首先看该用户是否在客户表中
var cmodel = CustomerList.Where(x => x.ExternalUserId == item.external_contact.external_userid && x.WorkEmpId == item.follow_info.userid).FirstOrDefault();
if (cmodel == null)
{
var tagWrokIdList = item.follow_info.tag_id?.ToList() ?? new List<string>();
var llist = LableList.Where(x => tagWrokIdList.Contains(x.WXLableId)).Select(x => x.Id).ToList();
#region 自定义内容
//暂 电话 + 性别
List<CustomerFiledContentModel> CustomContent = new List<CustomerFiledContentModel>();
string CustomerMobile = string.Join(",", item.follow_info.remark_mobiles);
int Sex = 0;
var TelModel = FieldList.Where(x => x.Name == "电话").FirstOrDefault();
var SexModel = FieldList.Where(x => x.Name == "性别").FirstOrDefault();
SexModel.OptionsList = JsonHelper.DeserializeObject<List<CustomerOptions>>(SexModel.Options);
if (item.external_contact.gender == 1)
{
//男
Sex = SexModel.OptionsList.Where(x => x.Name.Contains("男")).FirstOrDefault()?.Id ?? 0;
}
else if (item.external_contact.gender == 2) {
//女
Sex = SexModel.OptionsList.Where(x => x.Name.Contains("女")).FirstOrDefault()?.Id ?? 0;
}
else
{
//其他
Sex = SexModel.OptionsList.Where(x => !x.Name.Contains("女") && !x.Name.Contains("男")).FirstOrDefault()?.Id ?? 0;
}
CustomContent.Add(new CustomerFiledContentModel()
{
Id = TelModel.Id,
Value = CustomerMobile
});
CustomContent.Add(new CustomerFiledContentModel()
{
Id = SexModel.Id,
Value = Sex.ToString()
});
Dictionary<string, string> CustomContentKV = new Dictionary<string, string>();
foreach (var qitem in CustomContent) {
CustomContentKV.Add("z" + qitem.Id, qitem.Value);
}
#endregion
#region 阶段流程
//初始化阶段ID
int StageId = 0;
//获取对应的员工
var emodel = empList.Where(x => x.WorkUserId == item.follow_info.userid).FirstOrDefault();
var fmodel = FlowList.Where(x => ("," + x.DeptIds + ",").Contains("," + emodel.Dept_Id + ",") || ("," + x.EmpIds + ",").Contains("," + emodel.Id + ",")).FirstOrDefault();
if (fmodel == null) {
fmodel = FlowList.Where(x => x.DeptIds == "-1" && x.DeptIds == "-1" && x.IsDefault != 1).FirstOrDefault();
}
if (fmodel == null) {
fmodel = FlowList.Where(x => x.IsDefault == 1).FirstOrDefault();
}
if (fmodel != null) {
StageId = Convert.ToInt32(fmodel.UseStage.Split(',')[0]);//直接取第一个 保存时就需注意
}
#endregion
//直接新增客户信息
weChat_CustomerInfoRepository.Insert(new Model.Entity.WeChat.RB_WeChat_CustomerInfo()
{
Id = 0,
EmpId = emodel.Id,
WorkEmpId = item.follow_info.userid,
WorkEmpName = "",//暂不查询 需要单独调取通讯录api获取
ExternalUserId = item.external_contact.external_userid,
Status = 0,
Group_Id = userInfo.Group_Id,
CreateBy = userInfo.Id,
CreateTime = DateTime.Now,
UpdateBy = userInfo.Id,
UpdateTime = DateTime.Now,
CustomerName = string.IsNullOrEmpty(item.follow_info.remark) ? item.external_contact.name : item.follow_info.remark,
WeChatName = item.external_contact.name,
WeChatPhoto = item.external_contact.avatar,
CorpName = item.external_contact.corp_name,
CorpFullName = item.external_contact.corp_full_name,
CustomerType = item.external_contact.type,
StageId = StageId,
LableIds = string.Join(",", llist),
PersonLable = "",//暂存 查询不了
Source = item.follow_info.state,
CustomContent = JsonHelper.Serialize(CustomContentKV),
FriendState = 1,
FriendTime = ConvertToDateTime(item.follow_info.createtime.ToString()),
LastFollowUpTime = null,
CheckInNum = 0,
IsPublic = 2,
CustomerMobile = CustomerMobile,
Remark = "",
WeChatAddWay = item.follow_info.add_way,
AddWay = Common.Enum.WeChat.CustomerAddWayEnum.Friend
});
}
else {
//看可更新一下资料
}
}
}
}
return "";
}
/// <summary>
/// 更新客户好友状态
/// </summary>
/// <param name="id"></param>
public bool UpdateCustomerInfoFriendState(int id)
{
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_WeChat_CustomerInfo_ViewModel.FriendState),1},
{ nameof(RB_WeChat_CustomerInfo_ViewModel.FriendTime),DateTime.Now},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerInfo_ViewModel.Id),
FiledValue = id,
OperatorEnum = OperatorEnum.Equal
}
};
return weChat_CustomerInfoRepository.Update(keyValues, wheres);
}
/// <summary>
/// Unix时间戳转DateTime
/// </summary>
/// <param name="timestamp">时间戳</param>
/// <returns></returns>
private DateTime ConvertToDateTime(string timestamp)
{
DateTime time = DateTime.MinValue;
DateTime startTime = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Local);
if (timestamp.Length == 10) //精确到秒
{
time = startTime.AddSeconds(double.Parse(timestamp));
}
else if (timestamp.Length == 13) //精确到毫秒
{
time = startTime.AddMilliseconds(double.Parse(timestamp));
}
return time;
}
/// <summary>
/// 获取外部联系人token
/// </summary>
/// <param name="Group_Id"></param>
/// <param name="configmodel"></param>
/// <returns></returns>
private string GetContactToken(int Group_Id, RB_WeChat_Config_ViewModel configmodel)
{
string token = WeChatReidsCache.GetToken(Cache.CacheKey.QYWeChat_EmpToken_Key + Group_Id);
if (string.IsNullOrEmpty(token) || Config.IsLocal == 1)
{
var TelToken = QYWeiXinHelper.GetToken(configmodel.WX_CorpId, configmodel.Contact_Secret);
if (TelToken.errcode == Senparc.Weixin.ReturnCode_Work.请求成功)
{
if (Config.IsLocal == 1) { return TelToken.access_token; }
WeChatReidsCache.TokenSet(Cache.CacheKey.QYWeChat_EmpToken_Key + Group_Id, TelToken.access_token, TelToken.expires_in - 1);
token = TelToken.access_token;
}
else
{
LogHelper.Write("token获取失败," + TelToken.errmsg);
return "";
}
}
return token;
}
/// <summary>
/// 新增客户信息
/// </summary>
/// <returns></returns>
public bool AddCustomerInfoForBack(string UserID, string ExternalUserID, string State, int groupId)
{
//首先查询该客户是否已存在
var cmodel = GetCustomerInfoList(new RB_WeChat_CustomerInfo_ViewModel() { Group_Id = groupId, WorkEmpId = UserID, ExternalUserId = ExternalUserID }).FirstOrDefault();
if (cmodel == null)
{
//没有 需要新增
var configmodel = weChat_ConfigRepository.GetList(new RB_WeChat_Config_ViewModel() { Group_Id = groupId, Enable = 1 }).FirstOrDefault();
if (configmodel == null || configmodel.Enable != 1) { return false; }
string token = GetContactToken(groupId, configmodel);
if (string.IsNullOrEmpty(token)) { return false; }
var ContactModel = QYWeiXinHelper.GetExternalContactInfo(token, ExternalUserID);
if (ContactModel.errcode != Senparc.Weixin.ReturnCode_Work.请求成功)
{
LogHelper.Write("获取客户信息失败:" + ContactModel.errmsg);
}
var follow_user = ContactModel.follow_user.Where(x => x.userid == UserID).FirstOrDefault();
string Mobile = follow_user?.remark_mobiles.FirstOrDefault() ?? "";
bool IsInsert = false;
if (!string.IsNullOrEmpty(Mobile))
{
//判断手机号码 看是否有公司分配的
var mobileList = weChat_CustomerInfoRepository.GetList(new RB_WeChat_CustomerInfo_ViewModel() { Group_Id = groupId, WorkEmpId = UserID, CustomerMobile = Mobile });
mobileList = mobileList.Where(x => string.IsNullOrEmpty(x.ExternalUserId)).ToList();
if (mobileList.Any())
{
var mmodel = mobileList.FirstOrDefault();
if (mmodel.FriendState != 1)
{
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_WeChat_CustomerInfo_ViewModel.FriendState),1},
{ nameof(RB_WeChat_CustomerInfo_ViewModel.FriendTime),DateTime.Now},
{ nameof(RB_WeChat_CustomerInfo_ViewModel.ExternalUserId),ExternalUserID},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerInfo_ViewModel.Id),
FiledValue = mmodel.Id,
OperatorEnum = OperatorEnum.Equal
}
};
return weChat_CustomerInfoRepository.Update(keyValues, wheres);
}
else {
IsInsert = true;
}
}
else
{
IsInsert = true;
}
}
else {
IsInsert = true;
}
if (IsInsert) {
//自定义字段
var FieldList = weChat_CustomerFieldRepository.GetList(new RB_WeChat_CustomerField_ViewModel() { Group_Id = groupId, Enable = 1 });
//获取所有标签列表
var LableList = weChat_LableRepository.GetList(new RB_WeChat_Lable_ViewModel() { Group_Id = groupId });
//查询所有的阶段流程
var FlowList = weChat_CustomerStageFlowRepository.GetList(new RB_WeChat_CustomerStageFlow_ViewModel() { Group_Id = groupId, Enable = 1 });
//插入客户明细信息
var tagWrokIdList = follow_user.tags.Where(x => x.type == 1).Select(x => x.tag_id).ToList();
var llist = LableList.Where(x => tagWrokIdList.Contains(x.WXLableId)).Select(x => x.Id).ToList();
#region 自定义内容
//暂 电话 + 性别
List<CustomerFiledContentModel> CustomContent = new List<CustomerFiledContentModel>();
string CustomerMobile = string.Join(",", follow_user.remark_mobiles);
int Sex = 0;
var TelModel = FieldList.Where(x => x.Name == "电话").FirstOrDefault();
var SexModel = FieldList.Where(x => x.Name == "性别").FirstOrDefault();
SexModel.OptionsList = JsonHelper.DeserializeObject<List<CustomerOptions>>(SexModel.Options);
if (ContactModel.external_contact.gender == 1)
{
//男
Sex = SexModel.OptionsList.Where(x => x.Name.Contains("男")).FirstOrDefault()?.Id ?? 0;
}
else if (ContactModel.external_contact.gender == 2)
{
//女
Sex = SexModel.OptionsList.Where(x => x.Name.Contains("女")).FirstOrDefault()?.Id ?? 0;
}
else
{
//其他
Sex = SexModel.OptionsList.Where(x => !x.Name.Contains("女") && !x.Name.Contains("男")).FirstOrDefault()?.Id ?? 0;
}
CustomContent.Add(new CustomerFiledContentModel()
{
Id = TelModel.Id,
Value = CustomerMobile
});
CustomContent.Add(new CustomerFiledContentModel()
{
Id = SexModel.Id,
Value = Sex.ToString()
});
Dictionary<string, string> CustomContentKV = new Dictionary<string, string>();
foreach (var qitem in CustomContent)
{
CustomContentKV.Add("z" + qitem.Id, qitem.Value);
}
#endregion
#region 阶段流程
//初始化阶段ID
int StageId = 0;
//获取对应的员工
var emodel = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = groupId, WorkUserId = UserID }).FirstOrDefault();
var fmodel = FlowList.Where(x => ("," + x.DeptIds + ",").Contains("," + emodel.Dept_Id + ",") || ("," + x.EmpIds + ",").Contains("," + emodel.Id + ",")).FirstOrDefault();
if (fmodel == null)
{
fmodel = FlowList.Where(x => x.DeptIds == "-1" && x.DeptIds == "-1" && x.IsDefault != 1).FirstOrDefault();
}
if (fmodel == null)
{
fmodel = FlowList.Where(x => x.IsDefault == 1).FirstOrDefault();
}
if (fmodel != null)
{
StageId = Convert.ToInt32(fmodel.UseStage.Split(',')[0]);//直接取第一个 保存时就需注意
}
#endregion
//直接新增客户信息
weChat_CustomerInfoRepository.Insert(new Model.Entity.WeChat.RB_WeChat_CustomerInfo()
{
Id = 0,
EmpId = emodel.Id,
WorkEmpId = UserID,
WorkEmpName = "",//暂不查询 需要单独调取通讯录api获取
ExternalUserId = ExternalUserID,
Status = 0,
Group_Id = groupId,
CreateBy = 0,
CreateTime = DateTime.Now,
UpdateBy = 0,
UpdateTime = DateTime.Now,
CustomerName = string.IsNullOrEmpty(follow_user.remark) ? ContactModel.external_contact.name : follow_user.remark,
WeChatName = ContactModel.external_contact.name,
WeChatPhoto = ContactModel.external_contact.avatar,
CorpName = ContactModel.external_contact.corp_name,
CorpFullName = ContactModel.external_contact.corp_full_name,
CustomerType = ContactModel.external_contact.type,
StageId = StageId,
LableIds = string.Join(",", llist),
PersonLable = "",//暂存 查询不了
Source = follow_user.state,
CustomContent = JsonHelper.Serialize(CustomContentKV),
FriendState = 1,
FriendTime = ConvertToDateTime(follow_user.createtime.ToString()),
LastFollowUpTime = null,
CheckInNum = 0,
IsPublic = 2,
CustomerMobile = CustomerMobile,
Remark = "",
WeChatAddWay = follow_user.add_way,
AddWay = Common.Enum.WeChat.CustomerAddWayEnum.Friend
});
}
}
else
{
//判断客户状态 修改为已添加好友
if (cmodel.FriendState != 1)
{
UpdateCustomerInfoFriendState(cmodel.Id);
}
}
return true;
}
/// <summary>
/// 更新客户好友状态为待添加
/// </summary>
/// <param name="UserID"></param>
/// <param name="ExternalUserID"></param>
/// <param name="groupId"></param>
/// <returns></returns>
public bool UpdateCustomerFriendStateForBack(string UserID, string ExternalUserID, int groupId) {
var cmodel = GetCustomerInfoList(new RB_WeChat_CustomerInfo_ViewModel() { Group_Id = groupId, WorkEmpId = UserID, ExternalUserId = ExternalUserID }).FirstOrDefault();
if (cmodel != null && cmodel.FriendState != 2) {
//更新状态
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_WeChat_CustomerInfo_ViewModel.FriendState),2},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerInfo_ViewModel.Id),
FiledValue = cmodel.Id,
OperatorEnum = OperatorEnum.Equal
}
};
return weChat_CustomerInfoRepository.Update(keyValues, wheres);
}
return false;
}
#endregion
}
}
using Edu.Common.Enum;
using Edu.Model.Entity.WeChat;
using Edu.Model.ViewModel.WeChat;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;
namespace Edu.Repository.WeChat
{
/// <summary>
/// 企业微信客户信息仓储层
/// </summary>
public class RB_WeChat_CustomerInfoRepository : BaseRepository<RB_WeChat_CustomerInfo>
{
/// <summary>
/// 获取分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="count"></param>
/// <param name="demodel"></param>
/// <returns></returns>
public List<RB_WeChat_CustomerInfo_ViewModel> GetPageList(int pageIndex,int pageSize,out long count, RB_WeChat_CustomerInfo_ViewModel demodel)
{
DynamicParameters parameters = new DynamicParameters();
string where = $@" 1=1 and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.Status)} =0";
if (demodel.Group_Id > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.CustomerType > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CustomerType)} ={demodel.CustomerType}";
}
if (demodel.EmpId > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.EmpId)} ={demodel.EmpId}";
}
if (demodel.FriendState > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.FriendState)} ={demodel.FriendState}";
}
if (demodel.StageId > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.StageId)} ={demodel.StageId}";
}
if (!string.IsNullOrEmpty(demodel.CustomerName))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CustomerName)} like @CustomerName";
parameters.Add("CustomerName", "%" + demodel.CustomerName + "%");
}
if (!string.IsNullOrEmpty(demodel.WeChatName))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.WeChatName)} like @WeChatName";
parameters.Add("WeChatName", "%" + demodel.WeChatName + "%");
}
if (!string.IsNullOrEmpty(demodel.CustomerMobile))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CustomerMobile)} like @CustomerMobile";
parameters.Add("CustomerMobile", "%" + demodel.CustomerMobile + "%");
}
if (!string.IsNullOrEmpty(demodel.CorpName))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CorpName)} like @CorpName";
parameters.Add("CorpName", "%" + demodel.CorpName + "%");
}
if (!string.IsNullOrEmpty(demodel.CorpFullName))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CorpFullName)} like @CorpFullName";
parameters.Add("CorpFullName", "%" + demodel.CorpFullName + "%");
}
if (!string.IsNullOrEmpty(demodel.CreateSTime))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CreateTime)} >='{demodel.CreateSTime}'";
}
if (!string.IsNullOrEmpty(demodel.CreateETime))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CreateTime)} <='{demodel.CreateETime} 23:59:59'";
}
if (!string.IsNullOrEmpty(demodel.FriendSTime))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.FriendTime)} >='{demodel.FriendSTime}'";
}
if (!string.IsNullOrEmpty(demodel.FriendETime))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.FriendTime)} <='{demodel.FriendETime} 23:59:59'";
}
if (demodel.Q_NotFollowUpDay > 0)
{//几天未跟进
var followDay = DateTime.Now.AddDays(0 - demodel.Q_NotFollowUpDay).ToString("yyyy-MM-dd HH:mm:ss");
where += $@" and (r.{nameof(RB_WeChat_CustomerInfo_ViewModel.LastFollowUpTime)} <='{followDay}' or r.{nameof(RB_WeChat_CustomerInfo_ViewModel.LastFollowUpTime)} is null)";
}
if (!string.IsNullOrEmpty(demodel.Q_Friends))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.FriendState)} in({demodel.Q_Friends})";
}
if (!string.IsNullOrEmpty(demodel.Q_AddWay))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.AddWay)} in({demodel.Q_AddWay})";
}
#region 解析查询参数
if (demodel.SelectList != null && demodel.SelectList.Any())
{
int Num = 1;
where += " and (";
foreach (var item in demodel.SelectList)
{
if (item.IsCustom == 1) { item.Name = "z" + item.Name; }
if (Num != 1) { where += demodel.AddCondition == 1 ? " and" : " or"; }
switch (item.Type) {
case 1://包含 都是int类型的
List<int> valueList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<int>>("[" + item.StartValue + "]");
where += "(";
switch (item.Direction) {
case 1://包含所有
int Num1 = 1;
foreach (var value in valueList)
{
if (Num1 != 1) { where += " and"; }
if (item.IsCustom == 1)
{
where += $@" FIND_IN_SET('{value}',r.CustomContent -> '$.{item.Name}') ";
}
else
{
where += $@" FIND_IN_SET('{value}',r.{item.Name}) ";
}
Num1++;
}
break;
case 2://包含任意
Num1 = 1;
foreach (var value in valueList)
{
if (Num1 != 1) { where += " or"; }
if (item.IsCustom == 1)
{
where += $@" FIND_IN_SET('{value}',r.CustomContent -> '$.{item.Name}') ";
}
else
{
where += $@" FIND_IN_SET('{value}',r.{item.Name}) ";
}
Num1++;
}
break;
case 3://不包含
Num1 = 1;
foreach (var value in valueList)
{
if (Num1 != 1) { where += " and"; }
if (item.IsCustom == 1)
{
where += $@" !FIND_IN_SET('{value}',r.CustomContent -> '$.{item.Name}') ";
}
else
{
where += $@" !FIND_IN_SET('{value}',r.{item.Name}) ";
}
Num1++;
}
break;
case 4://为空
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' ='' ";
}
else
{
where += $@" r.{item.Name} ='' ";
}
break;
case 5://不为空
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' <>'' ";
}
else
{
where += $@" r.{item.Name} <>'' ";
}
break;
}
where += ")";
break;
case 2://等于 string类型
where += "(";
switch (item.Direction) {
case 1://等于
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' ='{item.StartValue}' ";
}
else
{
where += $@" r.{item.Name} ='{item.StartValue}' ";
}
break;
case 2://不等于
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' <>'{item.StartValue}' ";
}
else
{
where += $@" r.{item.Name} <>'{item.StartValue}' ";
}
break;
case 3://为空
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' ='' ";
}
else
{
where += $@" r.{item.Name} ='' ";
}
break;
case 4://不为空
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' <>'' ";
}
else
{
where += $@" r.{item.Name} <>'' ";
}
break;
case 5://模糊匹配
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' like '%{item.StartValue}%' ";
}
else
{
where += $@" r.{item.Name} like '%{item.StartValue}%' ";
}
break;
}
where += ")";
break;
case 3://日期
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' ='{item.StartValue}' ";
}
else
{
where += $@" r.{item.Name} ='{item.StartValue}' ";
}
break;
case 4://日期范围
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' >='{item.StartValue}' and r.CustomContent -> '$.{item.Name}' <='{item.EndValue}' ";
}
else
{
where += $@" r.{item.Name} >='{item.StartValue}' and r.{item.Name} <='{item.EndValue}' ";
}
break;
case 5://数值
switch (item.Direction) {
case 1://等于
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' ={item.StartValue} ";
}
else
{
where += $@" r.{item.Name} ={item.StartValue} ";
}
break;
case 2://大于
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' >{item.StartValue} ";
}
else
{
where += $@" r.{item.Name} >{item.StartValue} ";
}
break;
case 3://大于等于
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' >={item.StartValue} ";
}
else
{
where += $@" r.{item.Name} >={item.StartValue} ";
}
break;
case 4://小于
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' <{item.StartValue} ";
}
else
{
where += $@" r.{item.Name} <{item.StartValue} ";
}
break;
case 5://小于等于
if (item.IsCustom == 1)
{
where += $@" r.CustomContent -> '$.{item.Name}' <={item.StartValue} ";
}
else
{
where += $@" r.{item.Name} <={item.StartValue} ";
}
break;
}
break;
}
Num++;
}
where += " )";
}
#endregion
string orderByStr = " r.Id DESC";
if (demodel.OrderBy > 0) {
switch (demodel.OrderBy) {
case 1:
orderByStr = " r.CreateTime asc";
break;
case 2:
orderByStr = " r.CreateTime desc";
break;
case 3:
orderByStr = " r.LastFollowUpTime asc";
break;
case 4:
orderByStr = " r.LastFollowUpTime desc";
break;
}
}
string sql = $@"
SELECT * From RB_WeChat_CustomerInfo r
WHERE {where}
ORDER BY {orderByStr} ";
return GetPage<RB_WeChat_CustomerInfo_ViewModel>(pageIndex, pageSize, out count, sql, parameters).ToList();
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="demodel"></param>
/// <returns></returns>
public List<RB_WeChat_CustomerInfo_ViewModel> GetList(RB_WeChat_CustomerInfo_ViewModel demodel)
{
DynamicParameters parameters = new DynamicParameters();
string where = $@" 1=1 and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.Status)} =0";
if (demodel.Group_Id > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.CustomerType > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CustomerType)} ={demodel.CustomerType}";
}
if (demodel.EmpId > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.EmpId)} ={demodel.EmpId}";
}
if (demodel.FriendState > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.FriendState)} ={demodel.FriendState}";
}
if (demodel.IsPublic > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.IsPublic)} ={demodel.IsPublic}";
}
if (demodel.StageId > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.StageId)} ={demodel.StageId}";
}
if (!string.IsNullOrEmpty(demodel.WorkEmpId))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.WorkEmpId)} ='{demodel.WorkEmpId}'";
}
if (!string.IsNullOrEmpty(demodel.ExternalUserId))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.ExternalUserId)} ='{demodel.ExternalUserId}'";
}
if (!string.IsNullOrEmpty(demodel.CustomerMobile))
{
where += $@" and FIND_IN_SET('{demodel.CustomerMobile}'), r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CustomerMobile)})";
}
if (!string.IsNullOrEmpty(demodel.CustomerName))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CustomerName)} like @CustomerName";
parameters.Add("CustomerName", "%" + demodel.CustomerName + "%");
}
if (!string.IsNullOrEmpty(demodel.WeChatName))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.WeChatName)} like @WeChatName";
parameters.Add("WeChatName", "%" + demodel.WeChatName + "%");
}
if (!string.IsNullOrEmpty(demodel.CorpName))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CorpName)} like @CorpName";
parameters.Add("CorpName", "%" + demodel.CorpName + "%");
}
if (!string.IsNullOrEmpty(demodel.CorpFullName))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CorpFullName)} like @CorpFullName";
parameters.Add("CorpFullName", "%" + demodel.CorpFullName + "%");
}
string sql = $@"
SELECT * From RB_WeChat_CustomerInfo r
WHERE {where}
ORDER BY r.Id DESC ";
return Get<RB_WeChat_CustomerInfo_ViewModel>(sql, parameters).ToList();
}
}
}
......@@ -32,6 +32,10 @@ namespace Edu.Repository.WeChat
{
where += $@" and r.{nameof(RB_WeChat_CustomerStage_ViewModel.Type)} ={demodel.Type}";
}
if (demodel.Id > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerStage_ViewModel.Id)} ={demodel.Id}";
}
if (!string.IsNullOrEmpty(demodel.StageIds))
{
where += $@" and r.{nameof(RB_WeChat_CustomerStage_ViewModel.Id)} in({demodel.StageIds})";
......
using Edu.Common.Enum;
using Edu.Model.Entity.WeChat;
using Edu.Model.ViewModel.WeChat;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB;
using VT.FW.DB.Dapper;
namespace Edu.Repository.WeChat
{
/// <summary>
/// 企业微信客户旅程仓储层
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_WeChat_CustomerTripRepository : BaseRepository<RB_WeChat_CustomerTrip>
{
/// <summary>
/// 获取分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="count"></param>
/// <param name="demodel"></param>
/// <returns></returns>
public List<RB_WeChat_CustomerTrip_ViewModel> GetPageList(int pageIndex,int pageSize,out long count, RB_WeChat_CustomerTrip_ViewModel demodel)
{
DynamicParameters parameters = new DynamicParameters();
string where = $@" 1=1 and r.{nameof(RB_WeChat_CustomerTrip_ViewModel.Status)} =0";
if (demodel.Group_Id > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerTrip_ViewModel.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.Type > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerTrip_ViewModel.Type)} ={(int)demodel.Type}";
}
if (demodel.CustomerId > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerTrip_ViewModel.CustomerId)} ={demodel.CustomerId}";
}
string sql = $@"
SELECT * From RB_WeChat_CustomerTrip r
WHERE {where}
ORDER BY r.Id DESC ";
return GetPage<RB_WeChat_CustomerTrip_ViewModel>(pageIndex, pageSize, out count, sql, parameters).ToList();
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="demodel"></param>
/// <returns></returns>
public List<RB_WeChat_CustomerTrip_ViewModel> GetList(RB_WeChat_CustomerTrip_ViewModel demodel)
{
DynamicParameters parameters = new DynamicParameters();
string where = $@" 1=1 and r.{nameof(RB_WeChat_CustomerTrip_ViewModel.Status)} =0";
if (demodel.Group_Id > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerTrip_ViewModel.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.Type > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerTrip_ViewModel.Type)} ={(int)demodel.Type}";
}
if (demodel.CustomerId > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerTrip_ViewModel.CustomerId)} ={demodel.CustomerId}";
}
string sql = $@"
SELECT * From RB_WeChat_CustomerTrip r
WHERE {where}
ORDER BY r.Id DESC ";
return Get<RB_WeChat_CustomerTrip_ViewModel>(sql, parameters).ToList();
}
/// <summary>
/// 获取最后一次跟进时间
/// </summary>
/// <param name="group_Id"></param>
/// <param name="customerIds"></param>
/// <returns></returns>
public List<RB_WeChat_CustomerTrip_ViewModel> GetLastFollowUpTimeList(int group_Id, string customerIds)
{
string sql = $@"SELECT CustomerId , MAX(CreateTime) AS CreateTime FROM rb_wechat_customertrip
WHERE `Status` =0 and Group_Id ={group_Id} and Type =3 and CustomerId in ({customerIds}) GROUP BY CustomerId";
return Get<RB_WeChat_CustomerTrip_ViewModel>(sql).ToList();
}
}
}

using Senparc.Weixin.Entities;
using Senparc.Weixin.Work.AdvancedAPIs.External;
using System.Collections.Generic;
namespace Edu.ThirdCore.QYWinXin.Model
{
/// <summary>
/// 批量获取客户详情 返回结果
/// </summary>
public class GetExternalContactInfoBatchResult_V2 : WorkJsonResult
{
/// <summary>
/// 客户列表
/// </summary>
public List<ExternalContactList> external_contact_list { get; set; }
/// <summary>
/// 分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空
/// </summary>
public string next_cursor { get; set; }
}
public class ExternalContactList
{
/// <summary>
/// 客户信息
/// </summary>
public External_Contact external_contact { get; set; }
/// <summary>
/// 员工信息
/// </summary>
public Follow_User_V2 follow_info { get; set; }
}
public class Follow_User_V2
{
//
// 摘要:
// 添加了此外部联系人的企业成员userid
public string userid { get; set; }
//
// 摘要:
// 该成员对此外部联系人的备注
public string remark { get; set; }
//
// 摘要:
// 该成员对此外部联系人的描述
public string description { get; set; }
//
// 摘要:
// 该成员添加此外部联系人的时间
public int createtime { get; set; }
//
// 摘要:
// 企业自定义的state参数,用于区分客户具体是通过哪个「联系我」添加,由企业通过创建「联系我」方式指定
public string state { get; set; }
//
// 摘要:
// 发起添加的userid,如果成员主动添加,为成员的userid;如果是客户主动添加,则为客户的外部联系人userid;如果是内部成员共享/管理员分配,则为对应的成员/管理员userid
public string oper_userid { get; set; }
//
// 摘要:
// 该成员添加此客户的来源
public int add_way { get; set; }
//
// 摘要:
// 该成员对此客户备注的企业名称
public string remark_corp_name { get; set; }
//
// 摘要:
// 该成员对此客户备注的手机号码,第三方不可获取
public string[] remark_mobiles { get; set; }
public string[] tag_id { get; set; }
}
}
......@@ -276,6 +276,34 @@ namespace Edu.ThirdCore.QYWinXin
return ExternalApi.GetExternalContactInfo(accessTokenOrAppKey, externalUserId);
}
/// <summary>
/// 批量获取客户详情
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="userid"></param>
/// <param name="cursor"></param>
/// <param name="limit"></param>
/// <param name="timeOut"></param>
public static GetExternalContactInfoBatchResult_V2 GetExternalContactInfoBatch(string accessTokenOrAppKey, List<string> userid, string cursor = "", int limit = 50)
{
string url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/batch/get_by_user?access_token=" + accessTokenOrAppKey;
var SendDate = new
{
userid_list = userid,
cursor,
limit
};
var Rmsg = HttpHelper.HttpPost(url, JsonHelper.Serialize(SendDate), "");
if (!string.IsNullOrEmpty(Rmsg))
{
var rmodel = JsonHelper.DeserializeObject<GetExternalContactInfoBatchResult_V2>(Rmsg);
return rmodel;
}
return null;
}
/// <summary>
/// 转移客户
......
......@@ -402,5 +402,281 @@ namespace Edu.WebApi.Controllers.QYWeChat
#endregion
#endregion
#region 客户管理
/// <summary>
/// 获取客户信息分页列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerInfoPageList() {
var userInfo = base.UserInfo;
ResultPageModel pmodel = JsonHelper.DeserializeObject<ResultPageModel>(base.RequestParm.Msg.ToString());
RB_WeChat_CustomerInfo_ViewModel demodel = JsonHelper.DeserializeObject<RB_WeChat_CustomerInfo_ViewModel>(base.RequestParm.Msg.ToString());
demodel.Group_Id = userInfo.Group_Id;
var list = customerModule.GetCustomerInfoPageList(pmodel.PageIndex, pmodel.PageSize, out long count, demodel);
pmodel.Count = Convert.ToInt32(count);
pmodel.PageData = list.Select(x => new
{
x.Id,
x.EmpId,
x.EmpName,
x.WorkEmpId,
x.WorkEmpName,
x.ExternalUserId,
x.CustomerName,
x.WeChatName,
x.WeChatPhoto,
x.CorpName,
x.CorpFullName,
x.CustomerType,
x.StageId,
x.StageName,
x.LableIds,
LableList = x.LableList?.Select(z => new
{
z.Id,
z.Name
}),
x.PersonLable,
x.Source,
x.CustomContent,
x.CustomFiledList,
x.FriendState,
LastFollowUpTime = x.LastFollowUpTime.HasValue ? x.LastFollowUpTime.Value.ToString("yyyy-MM-dd HH:mm") : "",
x.CheckInNum,
CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm"),
FriendTime = x.FriendTime.HasValue ? x.FriendTime.Value.ToString("yyyy-MM-dd HH:mm") : ""
});
return ApiResult.Success("", pmodel);
}
/// <summary>
/// 获取客户信息
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerInfo() {
var userInfo = base.UserInfo;
JObject parms = JObject.Parse(base.RequestParm.Msg.ToString());
int CustomerId = parms.GetInt("CustomerId", 0);//客户Id
if (CustomerId <= 0) { return ApiResult.ParamIsNull(); }
var model = customerModule.GetCustomerInfo(CustomerId, userInfo);
if (model == null || model.Group_Id != userInfo.Group_Id) { return ApiResult.Failed("客户不存在,请核实后再试"); }
return ApiResult.Success("", new
{
model.Id,
model.EmpId,
model.EmpName,
model.WorkEmpId,
model.WorkEmpName,
model.ExternalUserId,
model.CustomerName,
model.WeChatName,
model.WeChatPhoto,
model.CorpName,
model.CorpFullName,
model.CustomerType,
model.StageId,
model.StageName,
model.LableIds,
LableList = model.LableList?.Select(z => new
{
z.Id,
z.Name
}),
model.PersonLable,
model.Source,
model.CustomContent,
FiledDetailList = model.FiledDetailList.OrderBy(x=>x.Sort).Select(x=>new {
x.Id,
x.Type,
TypeName = x.Type.ToName(),
x.Name,
x.Required,
x.WordNum,
x.InputType,
x.Options,
x.OptionsList,
x.Digits,
x.Sort
}),
model.FriendState,
LastFollowUpTime = model.LastFollowUpTime.HasValue ? model.LastFollowUpTime.Value.ToString("yyyy-MM-dd HH:mm") : "",
model.CheckInNum,
CreateTime = model.CreateTime.ToString("yyyy-MM-dd HH:mm"),
FriendTime = model.FriendTime.HasValue ? model.FriendTime.Value.ToString("yyyy-MM-dd HH:mm") : ""
});
}
/// <summary>
/// 修改客户信息
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetCustomerInfo() {
var userInfo = base.UserInfo;
JObject parms = JObject.Parse(base.RequestParm.Msg.ToString());
int Type = parms.GetInt("Type", 0);//类型 1客户阶段 2自定义字段 3客户企业标签
int CustomId = parms.GetInt("CustomId", 0);//自定义字段ID
int CustomerId = parms.GetInt("CustomerId", 0);//客户Id
string Value = parms.GetStringValue("Value");//值 多选的话 英文逗号分隔
if (CustomerId <= 0) {
return ApiResult.ParamIsNull("请传递客户ID");
}
if (Type == 2 && CustomId <= 0) {
return ApiResult.ParamIsNull("请传递自定义字段ID");
}
string msg = customerModule.SetCustomerInfo(CustomerId, Type, CustomId, Value, userInfo);
if (msg == "")
{
return ApiResult.Success();
}
else {
return ApiResult.Failed(msg);
}
}
//修改客户企业标签(批量处理)
//批量转移 放弃 导出 删除
/// <summary>
/// 获取客户旅程分页列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerTripPageList() {
var userInfo = base.UserInfo;
ResultPageModel pmodel = JsonHelper.DeserializeObject<ResultPageModel>(base.RequestParm.Msg.ToString());
RB_WeChat_CustomerTrip_ViewModel demodel = JsonHelper.DeserializeObject<RB_WeChat_CustomerTrip_ViewModel>(base.RequestParm.Msg.ToString());
demodel.Group_Id = userInfo.Group_Id;
var list = customerModule.GetCustomerTripPageList(pmodel.PageIndex, pmodel.PageSize, out long count, demodel);
pmodel.Count = Convert.ToInt32(count);
pmodel.PageData = list.Select(x => new
{
x.Id,
x.Type,
TypeName = x.Type.ToName(),
x.CustomerId,
x.Description,
x.Remark,
x.ImageList,
x.FileList,
x.UpdateBy,
x.UpdateByName,
UpdateTime = x.UpdateTime.ToString("yyyy-MM-dd HH:mm")
});
return ApiResult.Success("", pmodel);
}
/// <summary>
/// 企业微信旅程类型枚举
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerTripTypeEnumList()
{
var list = EnumHelper.EnumToList(typeof(CustomerTripTypeEnum));
return ApiResult.Success("", list);
}
/// <summary>
/// 新增客户跟进记录
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetCustomerTripFollowUpInfo() {
var userInfo = base.UserInfo;
RB_WeChat_CustomerTrip_ViewModel demodel = JsonHelper.DeserializeObject<RB_WeChat_CustomerTrip_ViewModel>(base.RequestParm.Msg.ToString());
if (demodel.CustomerId <= 0) {
return ApiResult.ParamIsNull("请传递客户id");
}
if (string.IsNullOrEmpty(demodel.Remark)) {
return ApiResult.ParamIsNull("请输入跟进记录");
}
if (demodel.ImageList != null && demodel.ImageList.Any()) {
demodel.Images = JsonHelper.Serialize(demodel.ImageList);
}
if (demodel.FileList != null && demodel.FileList.Any()) {
demodel.Files = JsonHelper.Serialize(demodel.FileList);
}
demodel.Type = CustomerTripTypeEnum.FollowUp;
demodel.Description = "添加了跟进记录:";
demodel.Status = 0;
demodel.Group_Id = userInfo.Group_Id;
demodel.CreateBy = userInfo.Id;
demodel.CreateTime = DateTime.Now;
demodel.UpdateBy = userInfo.Id;
demodel.UpdateTime = DateTime.Now;
string msg = customerModule.SetCustomerTripFollowUpInfo(demodel);
if (msg == "")
{
return ApiResult.Success();
}
else {
return ApiResult.Failed(msg);
}
}
/// <summary>
/// 删除客户旅程
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult DelCustomerTripInfo() {
var userInfo = base.UserInfo;
JObject parms = JObject.Parse(base.RequestParm.Msg.ToString());
int TripId = parms.GetInt("TripId", 0);//
if (TripId <= 0) {
return ApiResult.ParamIsNull();
}
string msg = customerModule.DelCustomerTripInfo(TripId, userInfo);
if (msg == "")
{
return ApiResult.Success();
}
else {
return ApiResult.Failed(msg);
}
}
/// <summary>
/// 获取客户添加方式枚举
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerAddWayEnumList()
{
var list = EnumHelper.EnumToList(typeof(CustomerAddWayEnum));
return ApiResult.Success("", list);
}
/// <summary>
/// 初始化客户信息列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult InitializeCustomerInfoList() {
var userInfo = base.UserInfo;
string msg = customerModule.InitializeCustomerInfoList(userInfo);
if (msg == "")
{
return ApiResult.Success();
}
else {
return ApiResult.Failed(msg);
}
}
#endregion
}
}
......@@ -24,6 +24,10 @@ namespace Edu.WebApi.Controllers.QYWeChat
/// 企业微信处理类对象
/// </summary>
private readonly QYWeChatModule weChatModule = new QYWeChatModule();
/// <summary>
/// 客户处理类
/// </summary>
//private readonly QYCustomerModule customerModule = new QYCustomerModule();
#region 欢迎语管理
......@@ -106,7 +110,7 @@ namespace Edu.WebApi.Controllers.QYWeChat
#endregion
//处理新添加客人事件
if (!string.IsNullOrEmpty(WelcomeCode) && MsgType == "event" && Event == "change_external_contact" && (ChangeType == "add_external_contact" || ChangeType == "add_half_external_contact"))
if (!string.IsNullOrEmpty(WelcomeCode) && MsgType == "event" && Event == "change_external_contact" && ChangeType == "add_external_contact")
{
#region 正常推送
//获取token
......@@ -426,8 +430,23 @@ namespace Edu.WebApi.Controllers.QYWeChat
UpdateTime = DateTime.Now,
WorkEmpId = UserID
});
//更新客户信息 好友状态为待添加
//if (ChangeType == "del_external_contact") {
// System.Threading.Tasks.Task.Run(() => customerModule.UpdateCustomerFriendStateForBack(UserID, ExternalUserID, groupId));
//}
}
//任务记录客户明细信息
//if (MsgType == "event" && Event == "change_external_contact" && ChangeType == "add_external_contact")
//{
// System.Threading.Tasks.Task.Run(() => customerModule.AddCustomerInfoForBack(UserID, ExternalUserID, State, groupId));
//}
//客户交替失败事件
//if (MsgType == "event" && Event == "change_external_contact" && ChangeType == "transfer_fail") {
//}
return "";
}
......@@ -487,294 +506,301 @@ namespace Edu.WebApi.Controllers.QYWeChat
string WelcomeCode = root["WelcomeCode"]?.InnerText ?? "";
#endregion
//处理新添加客人事件
if (!string.IsNullOrEmpty(WelcomeCode) && MsgType == "event" && Event == "change_external_contact" && (ChangeType == "add_external_contact" || ChangeType == "add_half_external_contact"))
{
#region 正常推送
//获取token
string token = GetContactToken(groupId, configmodel);
if (string.IsNullOrEmpty(token)) { return ""; }
//根据WXUserId 获取对应系统用户
var empModel = weChatModule.GetUserInfoForWeiXinWorkUserId(groupId, UserID);
if (!string.IsNullOrEmpty(State) && State.Contains("ChannelId="))
{
try
{
//从渠道码进来的
int ChannelId = Convert.ToInt32(State.Split("=")[1]);
if (ChannelId > 0)
{
var channelModel = weChatModule.GetWeChatChannelForBackUp(ChannelId);
if (channelModel == null) { return ""; }
var ContactModel = QYWeiXinHelper.GetExternalContactInfo(token, ExternalUserID);
if (ContactModel.errcode != Senparc.Weixin.ReturnCode_Work.请求成功)
{
LogHelper.Write("获取客户信息失败:" + ContactModel.errmsg);
}
#region 推送欢迎语
RB_WeChat_Welcomes_ViewModel welcomeModel = new RB_WeChat_Welcomes_ViewModel();
DateTime NowDate = DateTime.Now;
DateTime NowDay = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
string NowDateStr = DateTime.Now.ToString("yyyy-MM-dd");
bool IsChannelWelcome = false;
if (channelModel.WelcomeEnable == 1)
{
if (channelModel.WelcomeSpecialEnable == 1)
{
var swlist = channelModel.WelcomeSpecialList.Where(x => x.StartDate <= NowDay && x.EndDate >= NowDay && Convert.ToDateTime(NowDateStr + " " + x.StartHours) <= NowDate && Convert.ToDateTime(NowDateStr + " " + x.EndHours) >= NowDate).ToList();
if (swlist.Any())
{
var swmodel = swlist.FirstOrDefault();
welcomeModel.Type = string.IsNullOrEmpty(swmodel.MediumIds) ? 1 : 2;
welcomeModel.Content = swmodel.Content;
welcomeModel.MediumIds = swmodel.MediumIds;
welcomeModel.MediumList = swmodel.MediumList;
}
}
if (welcomeModel.Type == 0 && channelModel.WelcomeWeekEnable == 1)
{
//查询正常周期配置
string weekNum = "," + (int)DateTime.Now.DayOfWeek + ",";
var wlist = channelModel.WelcomeWeekList.Where(x => ("," + x.Weeks + ",").Contains(weekNum) && Convert.ToDateTime(NowDateStr + " " + x.StartHours) <= NowDate && Convert.ToDateTime(NowDateStr + " " + x.EndHours) >= NowDate).ToList();
if (wlist.Any())
{
var swmodel = wlist.FirstOrDefault();
welcomeModel.Type = string.IsNullOrEmpty(swmodel.MediumIds) ? 1 : 2;
welcomeModel.Content = swmodel.Content;
welcomeModel.MediumIds = swmodel.MediumIds;
welcomeModel.MediumList = swmodel.MediumList;
}
}
if (welcomeModel.Type == 0)
{
var swlist = channelModel.WelcomeList;
if (swlist.Any())
{
var swmodel = swlist.FirstOrDefault();
welcomeModel.Type = string.IsNullOrEmpty(swmodel.MediumIds) ? 1 : 2;
welcomeModel.Content = swmodel.Content;
welcomeModel.MediumIds = swmodel.MediumIds;
welcomeModel.MediumList = swmodel.MediumList;
}
}
if (welcomeModel.Type > 0)
{
IsChannelWelcome = true;
//推送欢迎语
if (welcomeModel.Content.Contains("##客户名称##"))
{
//替换客户名称
string ContactName = ContactModel?.external_contact?.name ?? "";
welcomeModel.Content = welcomeModel.Content.Replace("##客户名称##", ContactName);
}
//开始状态欢迎语 掉推送接口
string RMsg = weChatModule.SendNewCustomerWelcome(token, WelcomeCode, welcomeModel);
//处理消息
if (!string.IsNullOrEmpty(RMsg))
{
JObject parms = JObject.Parse(RMsg);
int errcode = parms.GetInt("errcode");
if (errcode != 0)
{
string errmsg = parms.GetStringValue("errmsg");
LogHelper.Write("推送欢迎语失败:" + errmsg);
}
}
}
}
if (!IsChannelWelcome)
{
//获取欢迎语列表 使用通用配置的欢迎语
var WelcomeList = weChatModule.GetWeChatWelcomesList(new RB_WeChat_Welcomes_ViewModel() { Group_Id = groupId, UserId = empModel.Id });
if (WelcomeList.Any())
{
if (WelcomeList.Where(x => x.UserIds != "-1").Any())
{
WelcomeList = WelcomeList.Where(x => x.UserIds != "-1").ToList();//优先使用配置人员的 再使用通用的
}
//多个欢迎语 默认取最新的
welcomeModel = WelcomeList.FirstOrDefault();
if (welcomeModel.Content.Contains("##客户名称##"))
{
//替换客户名称
string ContactName = ContactModel?.external_contact?.name ?? "";
welcomeModel.Content = welcomeModel.Content.Replace("##客户名称##", ContactName);
}
//开始状态欢迎语 掉推送接口
string RMsg = weChatModule.SendNewCustomerWelcome(token, WelcomeCode, welcomeModel);
//处理消息
if (!string.IsNullOrEmpty(RMsg))
{
JObject parms = JObject.Parse(RMsg);
int errcode = parms.GetInt("errcode");
if (errcode != 0)
{
string errmsg = parms.GetStringValue("errmsg");
LogHelper.Write("推送欢迎语失败:" + errmsg);
}
}
}
}
#endregion
#region 给客户打标签
if (channelModel.LabelList != null && channelModel.LabelList.Any())
{
var lmsg = QYWeiXinHelper.SetUserCoustmerLable(token, UserID, ExternalUserID, channelModel.LabelList);
if (lmsg.errcode != Senparc.Weixin.ReturnCode_Work.请求成功)
{
LogHelper.Write("记录客户标记失败:" + lmsg.errmsg);
}
}
#endregion
#region 添加客户记录
weChatModule.AddWeChatClientRecord(new RB_WeChat_ChannelRecord_ViewModel()
{
Id = 0,
ChannelId = ChannelId,
CreateBy = 1,
CreateTime = DateTime.Now,
CustomerNum = 0,
EmpId = (empModel?.Id ?? 0),
ExternalUserId = ExternalUserID,
CustomerName = ContactModel?.external_contact?.name ?? "",
Group_Id = channelModel.Group_Id,
Status = 0,
Type = 1,
UpdateBy = 1,
UpdateTime = DateTime.Now,
WorkEmpId = UserID
});
#endregion
#region 添加人员限制
bool IsLimit = false;
//人员添加记录
if (channelModel.EmpAddLimit == 1 && channelModel.LimitList.Any())
{
var limitModel = channelModel.LimitList.Where(x => x.EmpId == (empModel?.Id ?? -1)).FirstOrDefault();
if (limitModel != null)
{
limitModel.ClientNum++;
weChatModule.UpdateWeChatLimitClientNum(limitModel);
if (limitModel.LimitNum > 0 && limitModel.LimitNum <= limitModel.ClientNum)
{
IsLimit = true;//已经添加满了
}
}
}
//如果人员已添加满 需更新渠道码 重新定义用户
if (IsLimit)
{
var Rmsg = weChatModule.UpdateContactWayForQYWeiXin(channelModel, configmodel, true);
if (Rmsg.errcode != Senparc.Weixin.ReturnCode_Work.请求成功)
{
LogHelper.Write("添加客户回调(" + channelModel.Id + ")更新渠道码失败," + Rmsg.errmsg);
}
}
#endregion
}
}
catch (Exception ex)
{
LogHelper.Write(ex, "WeChatReceiveCustomerAdd");
}
}
else
{
#region 正常的添加客户好友
if (empModel == null) { return ""; }
//获取欢迎语列表
var WelcomeList = weChatModule.GetWeChatWelcomesList(new RB_WeChat_Welcomes_ViewModel() { Group_Id = groupId, UserId = empModel.Id });
if (WelcomeList.Any())
{
if (WelcomeList.Where(x => x.UserIds != "-1").Any())
{
WelcomeList = WelcomeList.Where(x => x.UserIds != "-1").ToList();//优先使用配置人员的 再使用通用的
}
//多个欢迎语 默认取最新的
var welcomeModel = WelcomeList.FirstOrDefault();
if (welcomeModel.Content.Contains("##客户名称##"))
{
//替换客户名称
var ContactModel = QYWeiXinHelper.GetExternalContactInfo(token, ExternalUserID);
string ContactName = ContactModel?.external_contact?.name ?? "";
welcomeModel.Content = welcomeModel.Content.Replace("##客户名称##", ContactName);
}
//开始状态欢迎语 掉推送接口
string RMsg = weChatModule.SendNewCustomerWelcome(token, WelcomeCode, welcomeModel);
//处理消息
if (!string.IsNullOrEmpty(RMsg))
{
JObject parms = JObject.Parse(RMsg);
int errcode = parms.GetInt("errcode");
if (errcode != 0)
{
string errmsg = parms.GetStringValue("errmsg");
LogHelper.Write("推送欢迎语失败:" + errmsg);
}
}
}
#endregion
}
#region 欢迎语
//处理新添加客人事件 add_half_external_contact(这个事件需注意)
//if (!string.IsNullOrEmpty(WelcomeCode) && MsgType == "event" && Event == "change_external_contact" && ChangeType == "add_external_contact")
//{
// #region 正常推送
// //获取token
// string token = GetContactToken(groupId, configmodel);
// if (string.IsNullOrEmpty(token)) { return ""; }
// //根据WXUserId 获取对应系统用户
// var empModel = weChatModule.GetUserInfoForWeiXinWorkUserId(groupId, UserID);
// if (!string.IsNullOrEmpty(State) && State.Contains("ChannelId="))
// {
// try
// {
// //从渠道码进来的
// int ChannelId = Convert.ToInt32(State.Split("=")[1]);
// if (ChannelId > 0)
// {
// var channelModel = weChatModule.GetWeChatChannelForBackUp(ChannelId);
// if (channelModel == null) { return ""; }
// var ContactModel = QYWeiXinHelper.GetExternalContactInfo(token, ExternalUserID);
// if (ContactModel.errcode != Senparc.Weixin.ReturnCode_Work.请求成功)
// {
// LogHelper.Write("获取客户信息失败:" + ContactModel.errmsg);
// }
// #region 推送欢迎语
// RB_WeChat_Welcomes_ViewModel welcomeModel = new RB_WeChat_Welcomes_ViewModel();
// DateTime NowDate = DateTime.Now;
// DateTime NowDay = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
// string NowDateStr = DateTime.Now.ToString("yyyy-MM-dd");
// bool IsChannelWelcome = false;
// if (channelModel.WelcomeEnable == 1)
// {
// if (channelModel.WelcomeSpecialEnable == 1)
// {
// var swlist = channelModel.WelcomeSpecialList.Where(x => x.StartDate <= NowDay && x.EndDate >= NowDay && Convert.ToDateTime(NowDateStr + " " + x.StartHours) <= NowDate && Convert.ToDateTime(NowDateStr + " " + x.EndHours) >= NowDate).ToList();
// if (swlist.Any())
// {
// var swmodel = swlist.FirstOrDefault();
// welcomeModel.Type = string.IsNullOrEmpty(swmodel.MediumIds) ? 1 : 2;
// welcomeModel.Content = swmodel.Content;
// welcomeModel.MediumIds = swmodel.MediumIds;
// welcomeModel.MediumList = swmodel.MediumList;
// }
// }
// if (welcomeModel.Type == 0 && channelModel.WelcomeWeekEnable == 1)
// {
// //查询正常周期配置
// string weekNum = "," + (int)DateTime.Now.DayOfWeek + ",";
// var wlist = channelModel.WelcomeWeekList.Where(x => ("," + x.Weeks + ",").Contains(weekNum) && Convert.ToDateTime(NowDateStr + " " + x.StartHours) <= NowDate && Convert.ToDateTime(NowDateStr + " " + x.EndHours) >= NowDate).ToList();
// if (wlist.Any())
// {
// var swmodel = wlist.FirstOrDefault();
// welcomeModel.Type = string.IsNullOrEmpty(swmodel.MediumIds) ? 1 : 2;
// welcomeModel.Content = swmodel.Content;
// welcomeModel.MediumIds = swmodel.MediumIds;
// welcomeModel.MediumList = swmodel.MediumList;
// }
// }
// if (welcomeModel.Type == 0)
// {
// var swlist = channelModel.WelcomeList;
// if (swlist.Any())
// {
// var swmodel = swlist.FirstOrDefault();
// welcomeModel.Type = string.IsNullOrEmpty(swmodel.MediumIds) ? 1 : 2;
// welcomeModel.Content = swmodel.Content;
// welcomeModel.MediumIds = swmodel.MediumIds;
// welcomeModel.MediumList = swmodel.MediumList;
// }
// }
// if (welcomeModel.Type > 0)
// {
// IsChannelWelcome = true;
// //推送欢迎语
// if (welcomeModel.Content.Contains("##客户名称##"))
// {
// //替换客户名称
// string ContactName = ContactModel?.external_contact?.name ?? "";
// welcomeModel.Content = welcomeModel.Content.Replace("##客户名称##", ContactName);
// }
// //开始状态欢迎语 掉推送接口
// string RMsg = weChatModule.SendNewCustomerWelcome(token, WelcomeCode, welcomeModel);
// //处理消息
// if (!string.IsNullOrEmpty(RMsg))
// {
// JObject parms = JObject.Parse(RMsg);
// int errcode = parms.GetInt("errcode");
// if (errcode != 0)
// {
// string errmsg = parms.GetStringValue("errmsg");
// LogHelper.Write("推送欢迎语失败:" + errmsg);
// }
// }
// }
// }
// if (!IsChannelWelcome)
// {
// //获取欢迎语列表 使用通用配置的欢迎语
// var WelcomeList = weChatModule.GetWeChatWelcomesList(new RB_WeChat_Welcomes_ViewModel() { Group_Id = groupId, UserId = empModel.Id });
// if (WelcomeList.Any())
// {
// if (WelcomeList.Where(x => x.UserIds != "-1").Any())
// {
// WelcomeList = WelcomeList.Where(x => x.UserIds != "-1").ToList();//优先使用配置人员的 再使用通用的
// }
// //多个欢迎语 默认取最新的
// welcomeModel = WelcomeList.FirstOrDefault();
// if (welcomeModel.Content.Contains("##客户名称##"))
// {
// //替换客户名称
// string ContactName = ContactModel?.external_contact?.name ?? "";
// welcomeModel.Content = welcomeModel.Content.Replace("##客户名称##", ContactName);
// }
// //开始状态欢迎语 掉推送接口
// string RMsg = weChatModule.SendNewCustomerWelcome(token, WelcomeCode, welcomeModel);
// //处理消息
// if (!string.IsNullOrEmpty(RMsg))
// {
// JObject parms = JObject.Parse(RMsg);
// int errcode = parms.GetInt("errcode");
// if (errcode != 0)
// {
// string errmsg = parms.GetStringValue("errmsg");
// LogHelper.Write("推送欢迎语失败:" + errmsg);
// }
// }
// }
// }
// #endregion
// #region 给客户打标签
// if (channelModel.LabelList != null && channelModel.LabelList.Any())
// {
// var lmsg = QYWeiXinHelper.SetUserCoustmerLable(token, UserID, ExternalUserID, channelModel.LabelList);
// if (lmsg.errcode != Senparc.Weixin.ReturnCode_Work.请求成功)
// {
// LogHelper.Write("记录客户标记失败:" + lmsg.errmsg);
// }
// }
// #endregion
// #region 添加客户记录
// weChatModule.AddWeChatClientRecord(new RB_WeChat_ChannelRecord_ViewModel()
// {
// Id = 0,
// ChannelId = ChannelId,
// CreateBy = 1,
// CreateTime = DateTime.Now,
// CustomerNum = 0,
// EmpId = (empModel?.Id ?? 0),
// ExternalUserId = ExternalUserID,
// CustomerName = ContactModel?.external_contact?.name ?? "",
// Group_Id = channelModel.Group_Id,
// Status = 0,
// Type = 1,
// UpdateBy = 1,
// UpdateTime = DateTime.Now,
// WorkEmpId = UserID
// });
// #endregion
// #region 添加人员限制
// bool IsLimit = false;
// //人员添加记录
// if (channelModel.EmpAddLimit == 1 && channelModel.LimitList.Any())
// {
// var limitModel = channelModel.LimitList.Where(x => x.EmpId == (empModel?.Id ?? -1)).FirstOrDefault();
// if (limitModel != null)
// {
// limitModel.ClientNum++;
// weChatModule.UpdateWeChatLimitClientNum(limitModel);
// if (limitModel.LimitNum > 0 && limitModel.LimitNum <= limitModel.ClientNum)
// {
// IsLimit = true;//已经添加满了
// }
// }
// }
// //如果人员已添加满 需更新渠道码 重新定义用户
// if (IsLimit)
// {
// var Rmsg = weChatModule.UpdateContactWayForQYWeiXin(channelModel, configmodel, true);
// if (Rmsg.errcode != Senparc.Weixin.ReturnCode_Work.请求成功)
// {
// LogHelper.Write("添加客户回调(" + channelModel.Id + ")更新渠道码失败," + Rmsg.errmsg);
// }
// }
// #endregion
// }
// }
// catch (Exception ex)
// {
// LogHelper.Write(ex, "WeChatReceiveCustomerAdd");
// }
// }
// else
// {
// #region 正常的添加客户好友
// if (empModel == null) { return ""; }
// //获取欢迎语列表
// var WelcomeList = weChatModule.GetWeChatWelcomesList(new RB_WeChat_Welcomes_ViewModel() { Group_Id = groupId, UserId = empModel.Id });
// if (WelcomeList.Any())
// {
// if (WelcomeList.Where(x => x.UserIds != "-1").Any())
// {
// WelcomeList = WelcomeList.Where(x => x.UserIds != "-1").ToList();//优先使用配置人员的 再使用通用的
// }
// //多个欢迎语 默认取最新的
// var welcomeModel = WelcomeList.FirstOrDefault();
// if (welcomeModel.Content.Contains("##客户名称##"))
// {
// //替换客户名称
// var ContactModel = QYWeiXinHelper.GetExternalContactInfo(token, ExternalUserID);
// string ContactName = ContactModel?.external_contact?.name ?? "";
// welcomeModel.Content = welcomeModel.Content.Replace("##客户名称##", ContactName);
// }
// //开始状态欢迎语 掉推送接口
// string RMsg = weChatModule.SendNewCustomerWelcome(token, WelcomeCode, welcomeModel);
// //处理消息
// if (!string.IsNullOrEmpty(RMsg))
// {
// JObject parms = JObject.Parse(RMsg);
// int errcode = parms.GetInt("errcode");
// if (errcode != 0)
// {
// string errmsg = parms.GetStringValue("errmsg");
// LogHelper.Write("推送欢迎语失败:" + errmsg);
// }
// }
// }
// #endregion
// }
// #endregion
//}
////成员删除外部联系人时 / 成员被外部联系人删除时
//else if (MsgType == "event" && Event == "change_external_contact" && (ChangeType == "del_external_contact" || ChangeType == "del_follow_user"))
//{
// int ChannelId = 0;
// if (!string.IsNullOrEmpty(State) && State.Contains("ChannelId="))
// {
// ChannelId = Convert.ToInt32(State.Split("=")[1]);
// }
// else
// {
// //根据员工 + 客人的企业微信Id 获取新增记录
// var recordModel = weChatModule.GeetWeChatClientRecord(groupId, UserID, ExternalUserID);
// ChannelId = recordModel?.ChannelId ?? 0;
// }
// //根据WXUserId 获取对应系统用户
// var empModel = weChatModule.GetUserInfoForWeiXinWorkUserId(groupId, UserID);
// //获取token
// string token = GetContactToken(groupId, configmodel);
// if (string.IsNullOrEmpty(token)) { return ""; }
// var ContactModel = QYWeiXinHelper.GetExternalContactInfo(token, ExternalUserID);
// if (ContactModel.errcode != Senparc.Weixin.ReturnCode_Work.请求成功)
// {
// LogHelper.Write("获取客户信息失败:" + ContactModel.errmsg);
// }
// weChatModule.AddWeChatClientRecord(new RB_WeChat_ChannelRecord_ViewModel()
// {
// Id = 0,
// ChannelId = ChannelId,
// CreateBy = 1,
// CreateTime = DateTime.Now,
// CustomerNum = 0,
// EmpId = (empModel?.Id ?? 0),
// ExternalUserId = ExternalUserID,
// CustomerName = ContactModel?.external_contact?.name ?? "",
// Group_Id = groupId,
// Status = 0,
// Type = ChangeType == "del_external_contact" ? 3 : 2,
// UpdateBy = 1,
// UpdateTime = DateTime.Now,
// WorkEmpId = UserID
// });
//}
#endregion
}
//成员删除外部联系人时 / 成员被外部联系人删除时
else if (MsgType == "event" && Event == "change_external_contact" && (ChangeType == "del_external_contact" || ChangeType == "del_follow_user"))
{
int ChannelId = 0;
if (!string.IsNullOrEmpty(State) && State.Contains("ChannelId="))
{
ChannelId = Convert.ToInt32(State.Split("=")[1]);
}
else
{
//根据员工 + 客人的企业微信Id 获取新增记录
var recordModel = weChatModule.GeetWeChatClientRecord(groupId, UserID, ExternalUserID);
ChannelId = recordModel?.ChannelId ?? 0;
}
//根据WXUserId 获取对应系统用户
var empModel = weChatModule.GetUserInfoForWeiXinWorkUserId(groupId, UserID);
//获取token
string token = GetContactToken(groupId, configmodel);
if (string.IsNullOrEmpty(token)) { return ""; }
var ContactModel = QYWeiXinHelper.GetExternalContactInfo(token, ExternalUserID);
if (ContactModel.errcode != Senparc.Weixin.ReturnCode_Work.请求成功)
{
LogHelper.Write("获取客户信息失败:" + ContactModel.errmsg);
}
weChatModule.AddWeChatClientRecord(new RB_WeChat_ChannelRecord_ViewModel()
{
Id = 0,
ChannelId = ChannelId,
CreateBy = 1,
CreateTime = DateTime.Now,
CustomerNum = 0,
EmpId = (empModel?.Id ?? 0),
ExternalUserId = ExternalUserID,
CustomerName = ContactModel?.external_contact?.name ?? "",
Group_Id = groupId,
Status = 0,
Type = ChangeType == "del_external_contact" ? 3 : 2,
UpdateBy = 1,
UpdateTime = DateTime.Now,
WorkEmpId = UserID
});
}
//任务记录客户明细信息
//if (MsgType == "event" && Event == "change_external_contact" && ChangeType == "add_external_contact")
//{
// System.Threading.Tasks.Task.Run(() => customerModule.AddCustomerInfoForBack(UserID, ExternalUserID, State, groupId));
//}
return "";
}
#endregion
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment