Commit c83ed12e authored by liudong1993's avatar liudong1993

1 客户管理阶段性提交代码

parent 07237255
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using Edu.Common.Plugin;
namespace Edu.Common.Data
{
/// <summary>
/// 客户导入帮助类
/// </summary>
public class QYCustomerClueHelper
{
/// <summary>
/// 根据Excel文件获取列表
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static List<CustomerClueListModel> GetCustomerClueData(string filePath, List<string> fieldList)
{
List<CustomerClueListModel> xlsItems = new List<CustomerClueListModel>();
var dt = Common.Plugin.NPOIHelper.ImportExcelToDatatable(filePath, 0, 2, true);
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow item in dt.Rows)
{
xlsItems.Add(DataRowToModel(item, fieldList));
}
}
return xlsItems;
}
/// <summary>
/// DataRow转实体
/// </summary>
/// <param name="dr"></param>
/// <returns></returns>
private static CustomerClueListModel DataRowToModel(DataRow dr, List<string> fieldList)
{
List<CustomerClueModel> list = new List<CustomerClueModel>();
if (dr != null)
{
foreach (var item in fieldList) {
if (dr.Table.Columns.Contains(item) && !string.IsNullOrEmpty(dr[item].ToString()))
{
list.Add(new CustomerClueModel()
{
Name = item,
Value = dr[item].ToString()
});
}
//有必填带*情况
else if (dr.Table.Columns.Contains(item + "*") && !string.IsNullOrEmpty(dr[item + "*"].ToString()))
{
list.Add(new CustomerClueModel()
{
Name = item,
Value = dr[item + "*"].ToString()
});
}
}
}
return new CustomerClueListModel() {
list = list
};
}
}
/// <summary>
/// 导入数据格式
/// </summary>
public class CustomerClueModel
{
/// <summary>
/// 字段名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 字段值
/// </summary>
public string Value { get; set; }
}
/// <summary>
/// 导入数据列表
/// </summary>
public class CustomerClueListModel
{
public List<CustomerClueModel> list;
}
}
......@@ -758,5 +758,44 @@ namespace Edu.Common.Plugin
workbook.Close();
out1.Close();
}
/// <summary>
/// excel 指定行插入数据(客户线索专用)
/// </summary>
/// <param name="dtSource"></param>
/// <param name="SheetName"></param>
/// <param name="Path"></param>
/// <param name="NewPath"></param>
/// <param name="rowIndex"></param>
public static void CustomerExportInsert(DataTable dtSource, string SheetName, string Path, string NewPath, int rowIndex = 0)
{
FileStream file = new FileStream(Path, FileMode.Open, FileAccess.Read);
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.GetSheet(SheetName) as XSSFSheet;
foreach (DataRow row in dtSource.Rows)
{
#region 填充内容
var rowSource = sheet.GetRow(rowIndex);
var cellSource = rowSource.GetCell(0);//都以第一列的样式复制
XSSFRow dataRow = sheet.CreateRow(rowIndex) as XSSFRow;
dataRow.Height = 500;
foreach (DataColumn column in dtSource.Columns)
{
XSSFCell newCell = dataRow.CreateCell(column.Ordinal) as XSSFCell;
newCell.CellStyle = cellSource.CellStyle;
String drValue = row[column].ToString();
newCell.SetCellValue(drValue);
}
#endregion
rowIndex++;
}
FileStream out1 = new FileStream(NewPath, FileMode.Create);
workbook.Write(out1);
workbook.Close();
out1.Close();
}
}
}
\ No newline at end of file
......@@ -142,5 +142,10 @@ namespace Edu.Model.Entity.WeChat
/// </summary>
public string TransferCustomerEmp { get; set; }
/// <summary>
/// 公海 查重规则 1客户库查重 2全局查重
/// </summary>
public int LookRepeat { get; set; }
}
}
......@@ -124,7 +124,7 @@ namespace Edu.Model.Entity.WeChat
public string CustomContent { get; set; }
/// <summary>
/// 好友状态 1好友客户 2待添加 3已申请
/// 好友状态 1好友客户 2待添加 3已申请 4已删除(客户主动删除) 5已删除(员工主动删除)
/// </summary>
public int FriendState { get; set; }
......@@ -144,7 +144,7 @@ namespace Edu.Model.Entity.WeChat
public int CheckInNum { get; set; }
/// <summary>
/// 是否公海客户 1是 2否
/// 是否公海客户 1是 2否 (暂时弃用 字段保留)
/// </summary>
public int IsPublic { get; set; }
......@@ -192,5 +192,25 @@ namespace Edu.Model.Entity.WeChat
/// 分配客户时间
/// </summary>
public DateTime? AllotCustomerTime { get; set; }
/// <summary>
/// 前负责员工ID (如放弃公海)
/// </summary>
public int OldEmpId { get; set; }
/// <summary>
/// 客户库ID (主要用于公海)
/// </summary>
public int CustomerLibraryId { get; set; }
/// <summary>
/// 放弃至公海的原因
/// </summary>
public string AbandonReason { get; set; }
/// <summary>
/// 放弃至公海的时间
/// </summary>
public DateTime? AbandonTime { get; set; }
}
}
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_CustomerLibrary
{
/// <summary>
/// Id
/// </summary>
public int Id { get; set; }
/// <summary>
/// 公海名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 是否默认 1是 2否
/// </summary>
public int IsDefault { get; set; }
/// <summary>
/// 是否允许重复客户 1允许 2不允许
/// </summary>
public int IsAllowRepeat { get; set; }
/// <summary>
/// 部门ids
/// </summary>
public string DeptIds { get; set; }
/// <summary>
/// 员工ids
/// </summary>
public string EmpIds { get; set; }
/// <summary>
/// 回收类型 1手动回收 2自动回收
/// </summary>
public int RecyclingType { get; set; }
/// <summary>
/// 回收条件 存List<obj>
/// </summary>
public string RecycleCondition { get; set; }
/// <summary>
/// 免回收的时间段 List<obj>
/// </summary>
public string NotRecycleTime { get; set; }
/// <summary>
/// 提前几天提醒
/// </summary>
public int RemindDay { get; set; }
/// <summary>
/// 类型 1天 2小时 3分钟
/// </summary>
public int RemindType { get; set; }
/// <summary>
/// 回收到公海后,前负责人多少天不能领取
/// </summary>
public int LimitDay { get; set; }
/// <summary>
/// 私库限制
/// </summary>
public string PrivateLibraryLimit { get; set; }
/// <summary>
/// 占用私库的类型 多选英文逗号分隔
/// </summary>
public string PrivateLibraryType { 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; }
}
}
......@@ -25,6 +25,11 @@ namespace Edu.Model.ViewModel.WeChat
/// 当前客户对应字段的值
/// </summary>
public string Value { get; set; }
/// <summary>
/// 自定义字段名称
/// </summary>
public string CName { get; set; }
}
/// <summary>
......
......@@ -46,6 +46,11 @@ namespace Edu.Model.ViewModel.WeChat
/// </summary>
public string EmpName { get; set; }
/// <summary>
/// 前负责人名称
/// </summary>
public string OldEmpName { get; set; }
/// <summary>
/// 未跟进天数
/// </summary>
......@@ -71,6 +76,25 @@ namespace Edu.Model.ViewModel.WeChat
/// </summary>
public string Q_CustomerIds { get; set; }
/// <summary>
/// 客户企业微信Ids
/// </summary>
public string Q_ExternalUserIds { get; set; }
/// <summary>
/// 员工的部门ID
/// </summary>
public int DeptId { get; }
/// <summary>
/// 客人姓名
/// </summary>
public string CName { get; set; }
/// <summary>
/// 姓名自定义字段ID
/// </summary>
public int CNameId { get; set; }
/// <summary>
/// 创建开始时间
......@@ -88,6 +112,24 @@ namespace Edu.Model.ViewModel.WeChat
/// 好友结束时间
/// </summary>
public string FriendETime { get; set; }
/// <summary>
/// 转客户开始时间
/// </summary>
public string TurnCustomerSTime { get; set; }
/// <summary>
/// 转客户结束时间
/// </summary>
public string TurnCustomerETime { get; set; }
/// <summary>
/// 分配客户开始时间
/// </summary>
public string AllotCustomerSTime { get; set; }
/// <summary>
/// 分配客户结束时间
/// </summary>
public string AllotCustomerETime { get; set; }
}
/// <summary>
......
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_CustomerLibrary_ViewModel : RB_WeChat_CustomerLibrary
{
/// <summary>
/// 分配的部门
/// </summary>
public List<User.RB_Department_ViewModel> DeptList { get; set; }
/// <summary>
/// 分配的员工
/// </summary>
public List<User.Employee_ViewModel> EmpList { get; set; }
/// <summary>
/// 回收条件列表
/// </summary>
public List<RecycleConditionModel> ConditionList { get; set; }
/// <summary>
/// 私库限制列表
/// </summary>
public List<PrivateLibraryLimitExtend> LimitList { get; set; }
/// <summary>
/// 免回收时间段列表
/// </summary>
public List<NotRecycleTimeModel> NotRecycleTimeList { get; set; }
/// <summary>
/// 占用私库名额类型名称
/// </summary>
public string PrivateLibraryTypeStr { get; set; }
}
/// <summary>
/// 免回收时间段
/// </summary>
public class NotRecycleTimeModel {
/// <summary>
/// 开始时间
/// </summary>
public string StartTime { get; set; }
/// <summary>
/// 结束时间
/// </summary>
public string EndTime { get; set; }
/// <summary>
/// 类型 1每天
/// </summary>
public int Type { get; set; }
}
/// <summary>
/// 自动回收条件
/// </summary>
public class RecycleConditionModel
{
/// <summary>
/// 类型 1未跟进 2未加微信好友 3客户阶段未到达"成交"阶段 4客户阶段达到某一个后 没有签到拜访 5没有再次跟进 6没有再次更新客户阶段
/// </summary>
public int Type { get; set; }
/// <summary>
/// 数量
/// </summary>
public int Num { get; set; }
/// <summary>
/// 类型 1天 2小时 3分钟
/// </summary>
public int DateType { get; set; }
/// <summary>
/// 阶段ID
/// </summary>
public int StageId { get; set; }
}
/// <summary>
/// 私库限制
/// </summary>
public class PrivateLibraryLimitModel {
/// <summary>
/// 是否默认 1是
/// </summary>
public int IsDefault { get; set; }
/// <summary>
/// 部门Ids
/// </summary>
public string DeptIds { get; set; }
/// <summary>
/// 人员Ids
/// </summary>
public string EmpIds { get; set; }
/// <summary>
/// 私库限制客户数量
/// </summary>
public int LimitNum { get; set; }
/// <summary>
/// 私库锁库客户数量
/// </summary>
public int LockNum { get; set; }
}
/// <summary>
/// 限制扩展
/// </summary>
public class PrivateLibraryLimitExtend : PrivateLibraryLimitModel {
/// <summary>
/// 分配的部门
/// </summary>
public List<User.RB_Department_ViewModel> DeptList { get; set; }
/// <summary>
/// 分配的员工
/// </summary>
public List<User.Employee_ViewModel> EmpList { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
......@@ -30,27 +31,27 @@ namespace Edu.Module.QYWeChat
/// <summary>
/// 配置
/// </summary>
private RB_WeChat_ConfigRepository weChat_ConfigRepository = new RB_WeChat_ConfigRepository();
private readonly RB_WeChat_ConfigRepository weChat_ConfigRepository = new RB_WeChat_ConfigRepository();
/// <summary>
/// 客户字段
/// </summary>
private RB_WeChat_CustomerFieldRepository weChat_CustomerFieldRepository = new RB_WeChat_CustomerFieldRepository();
private readonly RB_WeChat_CustomerFieldRepository weChat_CustomerFieldRepository = new RB_WeChat_CustomerFieldRepository();
/// <summary>
/// 客户阶段
/// </summary>
private RB_WeChat_CustomerStageRepository weChat_CustomerStageRepository = new RB_WeChat_CustomerStageRepository();
private readonly RB_WeChat_CustomerStageRepository weChat_CustomerStageRepository = new RB_WeChat_CustomerStageRepository();
/// <summary>
/// 阶段流程
/// </summary>
private RB_WeChat_CustomerStageFlowRepository weChat_CustomerStageFlowRepository = new RB_WeChat_CustomerStageFlowRepository();
private readonly RB_WeChat_CustomerStageFlowRepository weChat_CustomerStageFlowRepository = new RB_WeChat_CustomerStageFlowRepository();
/// <summary>
/// 客户信息
/// </summary>
private RB_WeChat_CustomerInfoRepository weChat_CustomerInfoRepository = new RB_WeChat_CustomerInfoRepository();
private readonly RB_WeChat_CustomerInfoRepository weChat_CustomerInfoRepository = new RB_WeChat_CustomerInfoRepository();
/// <summary>
/// 客户旅程(操作记录)
/// </summary>
private RB_WeChat_CustomerTripRepository weChat_CustomerTripRepository = new RB_WeChat_CustomerTripRepository();
private readonly RB_WeChat_CustomerTripRepository weChat_CustomerTripRepository = new RB_WeChat_CustomerTripRepository();
/// <summary>
/// 客户标签
/// </summary>
......@@ -64,6 +65,10 @@ namespace Edu.Module.QYWeChat
/// </summary>
private readonly RB_WeChat_CustomerClueRuleRepository weChat_CustomerClueRuleRepository = new RB_WeChat_CustomerClueRuleRepository();
/// <summary>
/// 客户库
/// </summary>
private readonly RB_WeChat_CustomerLibraryRepository weChat_CustomerLibraryRepository = new RB_WeChat_CustomerLibraryRepository();
/// <summary>
/// 部门
/// </summary>
private RB_DepartmentRepository departmentRepository = new RB_DepartmentRepository();
......@@ -234,6 +239,8 @@ namespace Edu.Module.QYWeChat
return flag ? "" : "出错了,请联系管理员";
}
#endregion
#region 客户阶段
......@@ -755,13 +762,24 @@ namespace Edu.Module.QYWeChat
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 (demodel.CustomerState == 3)
{
string oldEmpIds = string.Join(",", list.Where(x => x.OldEmpId > 0).Select(x => x.OldEmpId));
if (oldEmpIds != "''")
{
EmpList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = demodel.Group_Id, QIds = oldEmpIds });
}
}
else
{
string EmpWorkUserId = "'" + string.Join("','", list.Where(x => !string.IsNullOrEmpty(x.WorkEmpId)).Select(x => x.WorkEmpId).Distinct()) + "'";
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);
......@@ -779,9 +797,16 @@ namespace Edu.Module.QYWeChat
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 ?? "";
if (demodel.CustomerState == 3)
{
item.OldEmpName = EmpList.Where(x => x.Id == item.OldEmpId).FirstOrDefault()?.EmployeeName ?? "";
}
else
{
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)) {
......@@ -1097,6 +1122,20 @@ namespace Edu.Module.QYWeChat
else {
flag = weChat_CustomerTripRepository.Insert(demodel) > 0;
}
if (flag) {
//更新客户表 上次跟进时间
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_WeChat_CustomerInfo_ViewModel.LastFollowUpTime), DateTime.Now}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName =nameof(RB_WeChat_CustomerInfo_ViewModel.Id),
FiledValue = demodel.CustomerId,
OperatorEnum =OperatorEnum.Equal
}
};
weChat_CustomerInfoRepository.Update(keyValues, wheres);
}
return flag ? "" : "出错了,请联系管理员";
}
......@@ -1647,7 +1686,7 @@ namespace Edu.Module.QYWeChat
if (AddLable.Any() || DelLable.Any())
{
var LabelAddList = labelList.Where(x => AddLable.Contains(x.Id)).Select(x => x.WXLableId).Distinct().ToList();
var LabelDelList = labelList.Where(x => DelLable.Contains(x.Id)).Select(x => x.WXLableId).Distinct().ToList();// ----
var LabelDelList = labelList.Where(x => DelLable.Contains(x.Id)).Select(x => x.WXLableId).Distinct().ToList();// ----删除标签
string labelName = string.Join(",", labelList.Where(x => SetLable.Contains(x.Id)).Select(x => x.Name));
#region 给客户打标签
if (LabelAddList.Any())
......@@ -1656,8 +1695,20 @@ namespace Edu.Module.QYWeChat
if (lmsg.errcode != Senparc.Weixin.ReturnCode_Work.请求成功)
{
LogHelper.Write("设置客户标签失败:" + lmsg.errmsg);
return "企业微信标签更新失败";
}
else {
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_WeChat_CustomerInfo_ViewModel.LableIds),lableIds }
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerInfo_ViewModel.Id),
FiledValue = customerId,
OperatorEnum =OperatorEnum.Equal
}
};
weChat_CustomerInfoRepository.Update(keyValues, wheres);
//记录日志
weChat_CustomerTripRepository.Insert(new Model.Entity.WeChat.RB_WeChat_CustomerTrip()
{
......@@ -1696,15 +1747,166 @@ namespace Edu.Module.QYWeChat
var newEmpModel = accountRepository.GetEmployeeInfo(empId);
var list = weChat_CustomerInfoRepository.GetList(new RB_WeChat_CustomerInfo_ViewModel() { Group_Id = userInfo.Group_Id, Q_CustomerIds = customerIds });
if (list.Any()) {
#region 验证不能转移给原负责人
foreach (var item in list)
{
if (item.WorkEmpId == newEmpModel.WorkUserId) {
return "客户:" + item.CustomerName + "(" + item.Id + ") 与新转入员工是同一人,请排除后再试";
}
}
#endregion
//先验证只支持离职转交吧, 在职有限制 三个月两次
string empIds = string.Join(",", list.Select(x => x.EmpId).Distinct());
var emlist = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, QIds = empIds });
if (emlist.Where(x => x.LeaveStatus != Common.Enum.User.LeaveStatusEnum.Departure).Any()) {
//有非离职的
var zzlist = emlist.Where(x => x.LeaveStatus != Common.Enum.User.LeaveStatusEnum.Departure).ToList();
var lzlist = emlist.Where(x => x.LeaveStatus == Common.Enum.User.LeaveStatusEnum.Departure).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获取失败"; }
if (zzlist.Any()) {
//在职分配客户
foreach (var item in zzlist) {
List<string> CoustomerList = list.Where(x => x.WorkEmpId == item.WorkUserId).Select(x => x.ExternalUserId).ToList();
if (CoustomerList.Any())
{
int pageIndex = (int)Math.Ceiling(Convert.ToDecimal(CoustomerList.Count()) / 100);
int pageSize = 100;//微信只支持单次100条数据
for (int index = 1; index <= pageIndex; index++)
{
//开始转移
var clist = CoustomerList.Skip((index - 1) * pageSize).Take(pageSize).ToList();
if (clist.Any())
{
string Robj = QYWeiXinHelper.TransferCostomer(token, clist, item.WorkUserId, newEmpModel.WorkUserId);
if (!string.IsNullOrEmpty(Robj))
{
JObject parms = JObject.Parse(Robj);
int errcode = parms.GetInt("errcode", -1);
if (errcode == 0)
{
foreach (var qitem in clist) {
int CustomerId = list.Where(x => x.ExternalUserId == qitem && x.WorkEmpId == item.WorkUserId).FirstOrDefault()?.Id ?? 0;
#region 跟新客户原跟进人员
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_WeChat_CustomerInfo_ViewModel.OldEmpId), item.Id},
{ nameof(RB_WeChat_CustomerInfo_ViewModel.EmpId), newEmpModel.Id},
{ nameof(RB_WeChat_CustomerInfo_ViewModel.WorkEmpId), newEmpModel.EmployeeName},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerInfo_ViewModel.Id),
FiledValue = CustomerId,
OperatorEnum =OperatorEnum.Equal
}
};
weChat_CustomerInfoRepository.Update(keyValues, wheres);
#endregion
#region 新增流转记录
weChat_CustomerTripRepository.Insert(new Model.Entity.WeChat.RB_WeChat_CustomerTrip()
{
Id = 0,
CreateBy = userInfo.Id,
CreateTime = DateTime.Now,
CustomerId = CustomerId,
Description = "客户转移:将该客户由:" + item.EmployeeName + "转移给:" + newEmpModel.EmployeeName,
EmpId = newEmpModel.Id,
Type = Common.Enum.WeChat.CustomerTripTypeEnum.Record,
Group_Id = userInfo.Group_Id,
Remark = "",
Status = 0,
UpdateBy = userInfo.Id,
UpdateTime = DateTime.Now,
});
#endregion
}
}
else
{
//失败
return "转移客户失败,请联系管理员后再试";
}
}
else
{
return "企业微信请求失败,请联系管理员";
}
}
}
}
}
}
if (lzlist.Any()) {
//离职分配客户
foreach (var item in lzlist) {
List<string> CoustomerList = list.Where(x => x.WorkEmpId == item.WorkUserId).Select(x => x.ExternalUserId).ToList();
if (CoustomerList.Any()) {
int pageIndex = (int)Math.Ceiling(Convert.ToDecimal(CoustomerList.Count()) / 100);
int pageSize = 100;//微信只支持单次100条数据
for (int index = 1; index <= pageIndex; index++)
{
//开始转移
var clist = CoustomerList.Skip((index - 1) * pageSize).Take(pageSize).ToList();
if (clist.Any())
{
var requestL = new TransferCustomerRequest()
{
handover_userid = item.WorkUserId,
takeover_userid = newEmpModel.WorkUserId,
external_userid = clist
};
var Rmsg = QYWeiXinHelper.LeaveTransferCustomer(token, requestL);
if (Rmsg.errcode == Senparc.Weixin.ReturnCode_Work.请求成功)
{
foreach (var qitem in clist)
{
int CustomerId = list.Where(x => x.ExternalUserId == qitem && x.WorkEmpId == item.WorkUserId).FirstOrDefault()?.Id ?? 0;
#region 跟新客户原跟进人员
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_WeChat_CustomerInfo_ViewModel.OldEmpId), item.Id},
{ nameof(RB_WeChat_CustomerInfo_ViewModel.EmpId), newEmpModel.Id},
{ nameof(RB_WeChat_CustomerInfo_ViewModel.WorkEmpId), newEmpModel.EmployeeName},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerInfo_ViewModel.Id),
FiledValue = CustomerId,
OperatorEnum =OperatorEnum.Equal
}
};
weChat_CustomerInfoRepository.Update(keyValues, wheres);
#endregion
#region 新增流转记录
weChat_CustomerTripRepository.Insert(new Model.Entity.WeChat.RB_WeChat_CustomerTrip()
{
Id = 0,
CreateBy = userInfo.Id,
CreateTime = DateTime.Now,
CustomerId = CustomerId,
Description = "客户转移:将该客户由:" + item.EmployeeName + "转移给:" + newEmpModel.EmployeeName,
EmpId = newEmpModel.Id,
Type = Common.Enum.WeChat.CustomerTripTypeEnum.Record,
Group_Id = userInfo.Group_Id,
Remark = "",
Status = 0,
UpdateBy = userInfo.Id,
UpdateTime = DateTime.Now,
});
#endregion
}
}
else
{
LogHelper.Write("离职转移客户失败:" + Rmsg.errmsg);
return "转移客户失败,请联系管理员后再试";
}
}
}
}
return "暂时不做";
}
}
}
return "";
}
/// <summary>
......@@ -1716,11 +1918,128 @@ namespace Edu.Module.QYWeChat
/// <returns></returns>
public string SetCustomerAbandon(string customerIds, string reason, UserInfo userInfo)
{
#region 验证是否有权限放弃
var configModel = weChat_CustomerConfigRepository.GetList(new RB_WeChat_CustomerConfig_ViewModel() { Group_Id = userInfo.Group_Id }).FirstOrDefault();
if (configModel != null) {
if (configModel.AbandonDept != "-1" || configModel.AbandonEmp != "-1") {
bool IsHavePermission = false;
if (configModel.AbandonEmp != "-1") {
if((","+ configModel.AbandonEmp + ",").Contains("," + userInfo.Id + ","))
{
IsHavePermission = true;
}
}
if (IsHavePermission == false && configModel.AbandonDept != "-1") {
if (("," + configModel.AbandonDept + ",").Contains("," + userInfo.DeptId + ","))
{
IsHavePermission = true;
}
}
if (!IsHavePermission) {
return "您没有权限放弃客户至公海";
}
}
}
#endregion
var list = weChat_CustomerInfoRepository.GetList(new RB_WeChat_CustomerInfo_ViewModel() { Group_Id = userInfo.Group_Id, Q_CustomerIds = customerIds });
foreach (var item in list)
{
#region 验证客户权限
if (configModel != null && configModel.AbandonType == 2)
{
#region 客户自定义字段转化
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
});
}
}
#endregion
//部分客户验证
if (!string.IsNullOrEmpty(configModel.AbandonSelectValue)) {
//转化
List<CustomerCommissionSelectModel> AbandonCList = JsonHelper.DeserializeObject<List<CustomerCommissionSelectModel>>(configModel.AbandonSelectValue);
bool IsSure = false;
if (configModel.AbandonSelectType == 1)
{
//并且 所有条件必须满足
bool ConditionOk = false;
foreach (var citem in AbandonCList)
{
string cvValue = "";
if (citem.IsCustom == 1)
{
var cvModel = CustomValueList.Where(x => x.Id == citem.Id).FirstOrDefault();
if (cvModel == null) { ConditionOk = false; break; }
cvValue = cvModel.Value;
}
else if (citem.IsCustom == 2)
{
//标签
cvValue = item.LableIds;
}
else if (citem.IsCustom == 3)
{
//客户阶段
cvValue = item.StageId.ToString();
}
//写成一个通用方法
ConditionOk = GetConditionValidata(ConditionOk, citem, cvValue);
if (ConditionOk == false) { break; }
}
//所有条件都必须Ok才算Ok
if (ConditionOk) { IsSure = true; }
}
else
{
//或者 满足一个条件就可以
bool ConditionOk = false;
foreach (var citem in AbandonCList)
{
string cvValue = "";
if (citem.IsCustom == 1)
{
var cvModel = CustomValueList.Where(x => x.Id == citem.Id).FirstOrDefault();
if (cvModel == null) { continue; }
cvValue = cvModel.Value;
}
else if (citem.IsCustom == 2)
{
//标签
cvValue = item.LableIds;
}
else if (citem.IsCustom == 3)
{
//客户阶段
cvValue = item.StageId.ToString();
}
//写成一个通用方法
ConditionOk = GetConditionValidata(ConditionOk, citem, cvValue);
if (ConditionOk) { break; }
}
//所有条件都必须Ok才算Ok
if (ConditionOk) { IsSure = true; }
}
if (!IsSure)
{
return "客户" + item.CustomerName + "(" + item.Id + ") 无法放弃至公海";
}
}
}
#endregion
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_WeChat_CustomerInfo_ViewModel.IsPublic), 1},
{ nameof(RB_WeChat_CustomerInfo_ViewModel.CustomerState), 3},
{ nameof(RB_WeChat_CustomerInfo_ViewModel.AbandonReason), reason},
{ nameof(RB_WeChat_CustomerInfo_ViewModel.AbandonTime), DateTime.Now},
{ nameof(RB_WeChat_CustomerInfo_ViewModel.UpdateBy), userInfo.Id},
{ nameof(RB_WeChat_CustomerInfo_ViewModel.UpdateTime), DateTime.Now},
};
......@@ -2304,6 +2623,22 @@ namespace Edu.Module.QYWeChat
/// <returns></returns>
public string SetCustomerClueInfo(RB_WeChat_CustomerInfo_ViewModel demodel)
{
#region 验证手机号码
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerInfo_ViewModel.CustomerMobile),
FiledValue = demodel.CustomerMobile,
OperatorEnum =OperatorEnum.Equal
},
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerInfo_ViewModel.Group_Id),
FiledValue = demodel.Group_Id,
OperatorEnum =OperatorEnum.Equal
}
};
bool fvalidata = weChat_CustomerInfoRepository.ValidataMobile(new RB_WeChat_CustomerInfo_ViewModel() { Group_Id = demodel.Group_Id, CustomerMobile = demodel.CustomerMobile });
if (fvalidata) { return "手机号码已经存在"; }
#endregion
int Id = weChat_CustomerInfoRepository.Insert(demodel);
bool flag = Id > 0;
if (flag) {
......@@ -2411,8 +2746,8 @@ namespace Edu.Module.QYWeChat
{
//并且 所有条件必须满足
bool ConditionOk = false;
foreach (var citem in ritem.ConditionList) {
//bool IsContinue = true;//是否继续下一个条件
foreach (var citem in ritem.ConditionList)
{
string cvValue = "";
if (citem.IsCustom == 1)
{
......@@ -2426,192 +2761,168 @@ namespace Edu.Module.QYWeChat
//标签
cvValue = item.LableIds;
}
else if (citem.IsCustom == 3) {
else if (citem.IsCustom == 3)
{
//客户阶段
cvValue = item.StageId.ToString();
}
//写成一个通用方法
switch (citem.Type) {
case 1://包含
//方向 1包含所有/等于/等于 2包含任意/不等于/大于 3不包含/为空/大于等于 4为空/不为空/小于 5不为空/模糊/小于等于 对应 type的1/2/5
List<int> dxList = JsonHelper.DeserializeObject<List<int>>("[" + citem.StartValue + "]");
switch (citem.Direction) {
case 1://包含所有
ConditionOk = true;
foreach (var dxitem in dxList) {
if (!("," + cvValue + ",").Contains("," + dxitem + ","))
{
//不包含
ConditionOk = false;//此条件不成立
break;
ConditionOk = GetConditionValidata(ConditionOk, citem, cvValue);
if (ConditionOk == false) { break; }
}
//所有条件都必须Ok才算Ok
if (ConditionOk) { IsSure = true; }
}
break;
case 2://包含任意
ConditionOk = false;
foreach (var dxitem in dxList)
else {
//或者 满足一个条件就可以
bool ConditionOk = false;
foreach (var citem in ritem.ConditionList)
{
if (("," + cvValue + ",").Contains("," + dxitem + ","))
string cvValue = "";
if (citem.IsCustom == 1)
{
//包含
ConditionOk = true;
break;
}
var fieldModel = cFieldList.Where(x => x.Id == citem.Id).FirstOrDefault();
if (fieldModel == null) { continue; }
var cvModel = CustomValueList.Where(x => x.Id == citem.Id).FirstOrDefault();
cvValue = cvModel.Value;
}
break;
case 3://不包含
ConditionOk = true;
foreach (var dxitem in dxList)
else if (citem.IsCustom == 2)
{
if (("," + cvValue + ",").Contains("," + dxitem + ","))
//标签
cvValue = item.LableIds;
}
else if (citem.IsCustom == 3)
{
//包含
ConditionOk = false;
break;
}
}
break;
case 4://为空
ConditionOk = true;
if (!string.IsNullOrEmpty(cvValue))
{
ConditionOk = false;
}
break;
case 5://不为空
ConditionOk = true;
if (string.IsNullOrEmpty(cvValue))
{
ConditionOk = false;
}
break;
}
break;
case 2://等于
switch (citem.Direction) {
case 1://等于
ConditionOk = true;
if (cvValue != citem.StartValue) {
ConditionOk = false;
//客户阶段
cvValue = item.StageId.ToString();
}
break;
case 2://不等于
ConditionOk = true;
if (cvValue == citem.StartValue)
{
ConditionOk = false;
//写成一个通用方法
ConditionOk = GetConditionValidata(ConditionOk, citem, cvValue);
if (ConditionOk) { break; }
}
break;
case 3://为空
ConditionOk = true;
if (!string.IsNullOrEmpty(cvValue)) {
ConditionOk = false;
//所有条件都必须Ok才算Ok
if (ConditionOk) { IsSure = true; }
}
if (IsSure) {
customerRuleList.Add(ritem.Id, item.Id);
break;
case 4://不为空
ConditionOk = true;
if (string.IsNullOrEmpty(cvValue)) {
ConditionOk = false;
}
break;
case 5://模糊
ConditionOk = true;
if (!cvValue.Contains(citem.StartValue)) {
ConditionOk = false;
}
break;
if (!IsSure) {
//继续匹配为默认的
customerRuleList.Add(defaultRuleModel.Id, item.Id);
}
break;
case 3://日期
List<string> vList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(citem.StartValue);
if (string.IsNullOrEmpty(cvValue))
{
ConditionOk = false;
}
else
{
if (!vList.Contains(Convert.ToDateTime(cvValue).ToString("MM月dd号")))
//开始根据规则来 分配客户
if (customerRuleList.Any()) {
List<int> RuleList = customerRuleList.Select(x => x.Key).ToList();
foreach (var ruleId in RuleList) {
var ruleModel = otherRuleList.Where(x => x.Id == ruleId).FirstOrDefault();
if (ruleModel == null) { ruleModel = defaultRuleModel; }
//获取规则下所有的用户
List<Employee_ViewModel> elist = new List<Employee_ViewModel>();
if (!string.IsNullOrEmpty(ruleModel.DeptIds)) {
var edlist = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = ruleModel.DeptIds });
if (edlist.Any())
{
ConditionOk = false;
elist.AddRange(edlist);
}
}
break;
case 4://日期范围
if (string.IsNullOrEmpty(cvValue))
if (!string.IsNullOrEmpty(ruleModel.EmpIds)) {
var edlist = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, QIds = ruleModel.EmpIds });
if (edlist.Any())
{
ConditionOk = false;
elist.AddRange(edlist);
}
else
}
elist = elist.Distinct().ToList();//去除重复的 看怎么排序分配 (这个排序可能涉及一套分配规则)
var empIdList = elist.Select(x => x.Id).ToList();
//获取当前的客户
var customerVL = customerRuleList.Where(x => x.Key == ruleId).Select(x => x.Value).ToList();
var customerList = clist.Where(x => customerVL.Contains(x.Id)).ToList();
//开始分配
if (ruleModel.RuleAllotWay == 1)
{
if (!(Convert.ToDateTime(cvValue) >= Convert.ToDateTime(citem.StartValue) && Convert.ToDateTime(cvValue) <= Convert.ToDateTime(citem.EndValue)))
//依次分配
int Num = 1;
foreach (var item in customerList)
{
ConditionOk = false;
}
}
break;
case 5://数值
switch (citem.Direction) {
case 1://等于
ConditionOk = true;
if (Convert.ToDecimal(cvValue) != Convert.ToDecimal(citem.StartValue)) {
ConditionOk = false;
//获取用户ID
int empId = GetRankEmpId(empIdList, Num);//获取顺序用户
var empModel = elist.Where(x => x.Id == empId).FirstOrDefault();
keyValues.Add(nameof(RB_WeChat_CustomerInfo_ViewModel.EmpId), empId);
keyValues.Add(nameof(RB_WeChat_CustomerInfo_ViewModel.WorkEmpId), empId);
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerInfo_ViewModel.Id),
FiledValue = item,
OperatorEnum =OperatorEnum.Equal
}
break;
case 2://大于
ConditionOk = true;
if (Convert.ToDecimal(cvValue) <= Convert.ToDecimal(citem.StartValue))
};
weChat_CustomerInfoRepository.Update(keyValues, wheres);
weChat_CustomerTripRepository.Insert(new Model.Entity.WeChat.RB_WeChat_CustomerTrip()
{
ConditionOk = false;
Id = 0,
CreateBy = userInfo.Id,
CreateTime = DateTime.Now,
CustomerId = item.Id,
Description = userInfo.AccountName + "提交有效线索,系统依次将该客户分配给" + (empModel?.EmployeeName ?? ""),
EmpId = 0,
Files = "",
Group_Id = userInfo.Group_Id,
Images = "",
Remark = "",
Status = 0,
Type = Common.Enum.WeChat.CustomerTripTypeEnum.Operate,
UpdateBy = userInfo.Id,
UpdateTime = DateTime.Now
});
Num++;
}
break;
case 3://大于等于
ConditionOk = true;
if (Convert.ToDecimal(cvValue) < Convert.ToDecimal(citem.StartValue))
{
ConditionOk = false;
}
break;
case 4://小于
ConditionOk = true;
if (Convert.ToDecimal(cvValue) >= Convert.ToDecimal(citem.StartValue))
else {
//随机分配
foreach (var item in customerList)
{
ConditionOk = false;
//获取用户ID
int empId = GetRandomEmpId(empIdList);//获取随机用户
var empModel = elist.Where(x => x.Id == empId).FirstOrDefault();
keyValues.Add(nameof(RB_WeChat_CustomerInfo_ViewModel.EmpId), empId);
keyValues.Add(nameof(RB_WeChat_CustomerInfo_ViewModel.WorkEmpId), empModel?.WorkUserId ?? "");
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerInfo_ViewModel.Id),
FiledValue = item,
OperatorEnum =OperatorEnum.Equal
}
break;
case 5://小于等于
ConditionOk = true;
if (Convert.ToDecimal(cvValue) > Convert.ToDecimal(citem.StartValue))
};
weChat_CustomerInfoRepository.Update(keyValues, wheres);
weChat_CustomerTripRepository.Insert(new Model.Entity.WeChat.RB_WeChat_CustomerTrip()
{
ConditionOk = false;
}
break;
}
break;
}
if (ConditionOk == false) { break; }
}
//所有条件都必须Ok才算Ok
if (ConditionOk) { IsSure = true; }
}
else {
//或者 满足一个条件就可以
Id = 0,
CreateBy = userInfo.Id,
CreateTime = DateTime.Now,
CustomerId = item.Id,
Description = userInfo.AccountName + "提交有效线索,系统随机将该客户分配给" + (empModel?.EmployeeName ?? ""),
EmpId = 0,
Files = "",
Group_Id = userInfo.Group_Id,
Images = "",
Remark = "",
Status = 0,
Type = Common.Enum.WeChat.CustomerTripTypeEnum.Operate,
UpdateBy = userInfo.Id,
UpdateTime = DateTime.Now
});
}
if (IsSure) {
customerRuleList.Add(ritem.Id, item.Id);
break;
}
}
if (!IsSure) {
//继续匹配为默认的
customerRuleList.Add(defaultRuleModel.Id, item.Id);
}
}
//怎么验证重复分配(重复分配之后 又该怎么分配)
//
//怎么验证重复分配(重复分配之后 又该怎么分配)??????????????????? 待确认
}
else {
......@@ -2683,7 +2994,7 @@ namespace Edu.Module.QYWeChat
int empId = GetRankEmpId(empIdList, Num);//获取顺序用户
var empModel = elist.Where(x => x.Id == empId).FirstOrDefault();
keyValues.Add(nameof(RB_WeChat_CustomerInfo_ViewModel.EmpId), empId);
keyValues.Add(nameof(RB_WeChat_CustomerInfo_ViewModel.WorkEmpId), empId);
keyValues.Add(nameof(RB_WeChat_CustomerInfo_ViewModel.WorkEmpId), empModel?.WorkUserId ?? "");
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerInfo_ViewModel.Id),
......@@ -2726,6 +3037,7 @@ namespace Edu.Module.QYWeChat
int empId = GetRandomEmpId(empIdList);//获取随机用户
var empModel = elist.Where(x => x.Id == empId).FirstOrDefault();
keyValues.Add(nameof(RB_WeChat_CustomerInfo_ViewModel.EmpId), empId);
keyValues.Add(nameof(RB_WeChat_CustomerInfo_ViewModel.WorkEmpId), empModel?.WorkUserId ?? "");
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerInfo_ViewModel.Id),
......@@ -2816,34 +3128,892 @@ namespace Edu.Module.QYWeChat
}
/// <summary>
/// 获取顺序人员ID
/// 条件验证
/// </summary>
/// <param name="empIdList"></param>
/// <param name="num"></param>
/// <param name="ConditionOk"></param>
/// <param name="citem"></param>
/// <param name="cvValue"></param>
/// <returns></returns>
private int GetRankEmpId(List<int> empIdList, int num)
private bool GetConditionValidata(bool ConditionOk, CustomerCommissionSelectModel citem, string cvValue)
{
int ecount = empIdList.Count();
if (num > ecount) {
num %= ecount;
if (num == 0) {
num = ecount;
switch (citem.Type)
{
case 1://包含
//方向 1包含所有/等于/等于 2包含任意/不等于/大于 3不包含/为空/大于等于 4为空/不为空/小于 5不为空/模糊/小于等于 对应 type的1/2/5
List<int> dxList = JsonHelper.DeserializeObject<List<int>>("[" + citem.StartValue + "]");
switch (citem.Direction)
{
case 1://包含所有
ConditionOk = true;
foreach (var dxitem in dxList)
{
if (!("," + cvValue + ",").Contains("," + dxitem + ","))
{
//不包含
ConditionOk = false;//此条件不成立
break;
}
}
return empIdList[num - 1];
break;
case 2://包含任意
ConditionOk = false;
foreach (var dxitem in dxList)
{
if (("," + cvValue + ",").Contains("," + dxitem + ","))
{
//包含
ConditionOk = true;
break;
}
/// <summary>
/// 获取随机人员ID
/// </summary>
/// <param name="empIdList"></param>
/// <returns></returns>
private int GetRandomEmpId(List<int> empIdList)
}
break;
case 3://不包含
ConditionOk = true;
foreach (var dxitem in dxList)
{
int ecount = empIdList.Count();
int num = new Random().Next(1, ecount);
return empIdList[num - 1];
if (("," + cvValue + ",").Contains("," + dxitem + ","))
{
//包含
ConditionOk = false;
break;
}
}
break;
case 4://为空
ConditionOk = true;
if (!string.IsNullOrEmpty(cvValue))
{
ConditionOk = false;
}
break;
case 5://不为空
ConditionOk = true;
if (string.IsNullOrEmpty(cvValue))
{
ConditionOk = false;
}
break;
}
break;
case 2://等于
switch (citem.Direction)
{
case 1://等于
ConditionOk = true;
if (cvValue != citem.StartValue)
{
ConditionOk = false;
}
break;
case 2://不等于
ConditionOk = true;
if (cvValue == citem.StartValue)
{
ConditionOk = false;
}
break;
case 3://为空
ConditionOk = true;
if (!string.IsNullOrEmpty(cvValue))
{
ConditionOk = false;
}
break;
case 4://不为空
ConditionOk = true;
if (string.IsNullOrEmpty(cvValue))
{
ConditionOk = false;
}
break;
case 5://模糊
ConditionOk = true;
if (!cvValue.Contains(citem.StartValue))
{
ConditionOk = false;
}
break;
}
break;
case 3://日期
List<string> vList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(citem.StartValue);
if (string.IsNullOrEmpty(cvValue))
{
ConditionOk = false;
}
else
{
if (!vList.Contains(Convert.ToDateTime(cvValue).ToString("MM月dd号")))
{
ConditionOk = false;
}
}
break;
case 4://日期范围
if (string.IsNullOrEmpty(cvValue))
{
ConditionOk = false;
}
else
{
if (!(Convert.ToDateTime(cvValue) >= Convert.ToDateTime(citem.StartValue) && Convert.ToDateTime(cvValue) <= Convert.ToDateTime(citem.EndValue)))
{
ConditionOk = false;
}
}
break;
case 5://数值
switch (citem.Direction)
{
case 1://等于
ConditionOk = true;
if (Convert.ToDecimal(cvValue) != Convert.ToDecimal(citem.StartValue))
{
ConditionOk = false;
}
break;
case 2://大于
ConditionOk = true;
if (Convert.ToDecimal(cvValue) <= Convert.ToDecimal(citem.StartValue))
{
ConditionOk = false;
}
break;
case 3://大于等于
ConditionOk = true;
if (Convert.ToDecimal(cvValue) < Convert.ToDecimal(citem.StartValue))
{
ConditionOk = false;
}
break;
case 4://小于
ConditionOk = true;
if (Convert.ToDecimal(cvValue) >= Convert.ToDecimal(citem.StartValue))
{
ConditionOk = false;
}
break;
case 5://小于等于
ConditionOk = true;
if (Convert.ToDecimal(cvValue) > Convert.ToDecimal(citem.StartValue))
{
ConditionOk = false;
}
break;
}
break;
}
return ConditionOk;
}
/// <summary>
/// 获取顺序人员ID
/// </summary>
/// <param name="empIdList"></param>
/// <param name="num"></param>
/// <returns></returns>
private int GetRankEmpId(List<int> empIdList, int num)
{
int ecount = empIdList.Count();
if (num > ecount) {
num %= ecount;
if (num == 0) {
num = ecount;
}
}
return empIdList[num - 1];
}
/// <summary>
/// 获取随机人员ID
/// </summary>
/// <param name="empIdList"></param>
/// <returns></returns>
private int GetRandomEmpId(List<int> empIdList)
{
int ecount = empIdList.Count();
int num = new Random().Next(1, ecount);
return empIdList[num - 1];
}
/// <summary>
/// 上传客户线索excel
/// </summary>
/// <param name="path_server"></param>
/// <param name="userId"></param>
/// <returns></returns>
public string ImportExcelForCustomerClue(string path_server, int userId)
{
var empModel = accountRepository.GetEmployeeInfo(userId);
if (empModel == null) { return "用户不存在"; }
//首先获取客户字段
var fieldList = weChat_CustomerFieldRepository.GetList(new RB_WeChat_CustomerField_ViewModel() { Group_Id = empModel.Group_Id, Enable = 1 });
if (!fieldList.Any()) { return "请联系管理员,客户字段不存在"; }
foreach (var item in fieldList) {
item.OptionsList = new List<CustomerOptions>();
if (!string.IsNullOrEmpty(item.Options))
{
item.OptionsList = JsonHelper.DeserializeObject<List<CustomerOptions>>(item.Options);
}
}
List<string> fieldCList = fieldList.Select(x => x.Name).ToList();
var list = Common.Data.QYCustomerClueHelper.GetCustomerClueData(path_server, fieldCList);
if (list != null && list.Count > 0)
{
List<RB_WeChat_CustomerInfo_ViewModel> customerList = new List<RB_WeChat_CustomerInfo_ViewModel>();
//遍历客户
foreach (var item in list)
{
if (item.list.Any())
{
//遍历客户子段
List<CustomFiledContentExtend> CustomFiledList = new List<CustomFiledContentExtend>();
string mobile = "", xName = "";
foreach (var qitem in item.list) {
var fmodel = fieldList.Where(x => x.Name == qitem.Name).FirstOrDefault();
if (fmodel.Required == 1 && string.IsNullOrEmpty(qitem.Value))
{
return "有必填项为空,请核实后再次上传";
}
if (fmodel.Name == "姓名")
{
xName = qitem.Value;
}
if (fmodel.Name == "电话")
{
mobile = qitem.Value;
}
switch (fmodel.Type)
{
case Common.Enum.WeChat.CustomerFieldTypeEnum.Radio:
int Id = fmodel.OptionsList.Where(x => x.Name == qitem.Value).FirstOrDefault()?.Id ?? 0;
CustomFiledList.Add(new CustomFiledContentExtend()
{
Id = fmodel.Id,
Value = Id.ToString(),
Name = fmodel.Name,
Sort = fmodel.Sort
});
break;
case Common.Enum.WeChat.CustomerFieldTypeEnum.MultiSelect:
var optionList = fmodel.OptionsList.Where(x => ("," + qitem.Value + ",").Contains("," + x.Name + ",")).ToList();
CustomFiledList.Add(new CustomFiledContentExtend()
{
Id = fmodel.Id,
Value = string.Join(",", optionList.Select(x => x.Id)),
Name = fmodel.Name,
Sort = fmodel.Sort
});
break;
case Common.Enum.WeChat.CustomerFieldTypeEnum.Number:
CustomFiledList.Add(new CustomFiledContentExtend()
{
Id = fmodel.Id,
Value = qitem.Value == "" ? "0" : qitem.Value,
Name = fmodel.Name,
Sort = fmodel.Sort
});
break;
default:
CustomFiledList.Add(new CustomFiledContentExtend()
{
Id = fmodel.Id,
Value = qitem.Value,
Name = fmodel.Name,
Sort = fmodel.Sort
});
break;
}
}
if (!string.IsNullOrEmpty(mobile)) {
#region 验证手机号码
bool fvalidata = weChat_CustomerInfoRepository.ValidataMobile(new RB_WeChat_CustomerInfo_ViewModel() { Group_Id = empModel.Group_Id, CustomerMobile = mobile });
if (fvalidata) { return xName + "手机号码已经存在"; }
#endregion
}
Dictionary<string, string> CustomContentKV = new Dictionary<string, string>();
foreach (var qitem in CustomFiledList)
{
CustomContentKV.Add("z" + qitem.Id, qitem.Value);
}
string CustomContent = JsonHelper.Serialize(CustomContentKV);
var demodel = new RB_WeChat_CustomerInfo_ViewModel()
{
CustomContent = JsonHelper.Serialize(CustomContentKV),
CustomerMobile = mobile,
CustomerName = xName,
//基本信息
Status = 0,
Group_Id = empModel.Group_Id,
CreateBy = empModel.Id,
CreateTime = DateTime.Now,
UpdateBy = empModel.Id,
UpdateTime = DateTime.Now,
AddWay = Common.Enum.WeChat.CustomerAddWayEnum.Person,
CustomerState = 2,//线索
ClueState = 1,//未处理
AllotState = 0,//分配状态
EmpId = 0,
WorkEmpId = "",
WorkEmpName = "",
ExternalUserId = "",
CustomerType = 1,//微信用户
StageId = 0,//阶段 根据领用用户来判断
FriendState = 2,
};
customerList.Add(demodel);
}
}
foreach (var item in customerList) {
weChat_CustomerInfoRepository.Insert(item);
}
}
System.IO.File.Delete(path_server);
return "";
}
/// <summary>
/// 获取客户线索导入模板路径
/// </summary>
/// <param name="userInfo"></param>
/// <returns></returns>
public string GetCustomerClueExportFile(UserInfo userInfo)
{
var fieldList = weChat_CustomerFieldRepository.GetList(new RB_WeChat_CustomerField_ViewModel() { Group_Id = userInfo.Group_Id, Enable = 1 });
foreach (var item in fieldList)
{
item.OptionsList = new List<CustomerOptions>();
if (!string.IsNullOrEmpty(item.Options))
{
item.OptionsList = JsonHelper.DeserializeObject<List<CustomerOptions>>(item.Options);
}
}
fieldList = fieldList.OrderBy(x => x.Sort).ToList();
//字段使用dataTable存储
DataTable FieldNameList = new DataTable();
foreach (var item in fieldList) {
FieldNameList.Columns.Add(new DataColumn("z" + item.Id));
}
DataRow row = FieldNameList.NewRow();
DataRow row1 = FieldNameList.NewRow();
foreach (var item in fieldList)
{
row["z" + item.Id] = item.Name + (item.Required == 1 ? "*" : "");
switch (item.Type) {
case Common.Enum.WeChat.CustomerFieldTypeEnum.Date:
row1["z" + item.Id] = DateTime.Now.ToString("yyyy/MM/dd");
break;
case Common.Enum.WeChat.CustomerFieldTypeEnum.MultiSelect:
row1["z" + item.Id] = string.Join(",", item.OptionsList.Select(x => x.Name));
break;
case Common.Enum.WeChat.CustomerFieldTypeEnum.Number:
row1["z" + item.Id] = "0";
break;
case Common.Enum.WeChat.CustomerFieldTypeEnum.Radio:
row1["z" + item.Id] = "选项值,比如 " + item.OptionsList.FirstOrDefault()?.Name ?? "";
break;
case Common.Enum.WeChat.CustomerFieldTypeEnum.Time:
row1["z" + item.Id] = DateTime.Now.ToString("yyyy/MM/dd HH:mm");
break;
default:
if (item.Name == "姓名")
{
row1["z" + item.Id] = "甲小鹤";
}
else if (item.Name == "电话")
{
row1["z" + item.Id] = "16666666666";
}
else
{
row1["z" + item.Id] = "输入文本";
}
break;
}
}
FieldNameList.Rows.Add(row);
FieldNameList.Rows.Add(row1);
string basepath = AppContext.BaseDirectory;
string oldPath = basepath + "\\upfile\\template\\导入线索模板.xlsx";
string dateStr = DateTime.Now.ToString("yyyyMMdd");
string rdStr = DateTime.Now.ToString("MMdd") + (new Random().Next(100, 999));
string newPath = basepath + "\\upfile\\temporary\\" + dateStr + "\\导入线索模板" + rdStr + ".xlsx";
string httpPath = "/upfile/temporary/" + dateStr + "/导入线索模板" + rdStr + ".xlsx";
NPOIHelper.CustomerExportInsert(FieldNameList, "Sheet0", oldPath, newPath, 2);
return httpPath;
}
#endregion
#region 客户库
/// <summary>
/// 获取客户库查重规则
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
public int GetCustomerLibraryLookRepeat(int groupId)
{
var model = weChat_CustomerConfigRepository.GetList(new RB_WeChat_CustomerConfig_ViewModel() { Group_Id = groupId }).FirstOrDefault();
return model?.LookRepeat ?? 1;
}
/// <summary>
/// 保存客户库查重规则
/// </summary>
/// <param name="groupId"></param>
/// <param name="LookRepeat"></param>
/// <returns></returns>
public string SetCustomerLibraryLookRepeat(int groupId, int LookRepeat) {
var model = weChat_CustomerConfigRepository.GetList(new RB_WeChat_CustomerConfig_ViewModel() { Group_Id = groupId }).FirstOrDefault();
if (model != null) {
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_WeChat_CustomerConfig_ViewModel.LookRepeat), LookRepeat}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerConfig_ViewModel.Id),
FiledValue = model.Id,
OperatorEnum =OperatorEnum.Equal
}
};
bool flag = weChat_CustomerConfigRepository.Update(keyValues, wheres);
return flag ? "" : "出错了,请联系管理员";
}
return "配置不存在";
}
/// <summary>
/// 获取客户库列表
/// </summary>
/// <param name="group_Id"></param>
/// <returns></returns>
public List<RB_WeChat_CustomerLibrary_ViewModel> GetCustomerLibraryList(int group_Id)
{
var list = weChat_CustomerLibraryRepository.GetList(new RB_WeChat_CustomerLibrary_ViewModel() { Group_Id = group_Id });
if (list.Any()) {
//查询部门 人员
string deptIds = string.Join(",", list.Where(x => !string.IsNullOrEmpty(x.DeptIds) && x.DeptIds != "-1").Select(x => x.DeptIds));
string empIds = string.Join(",", list.Where(x => !string.IsNullOrEmpty(x.EmpIds) && x.EmpIds != "-1").Select(x => x.EmpIds));
foreach (var item in list) {
item.LimitList = new List<PrivateLibraryLimitExtend>();
if (!string.IsNullOrEmpty(item.PrivateLibraryLimit))
{
item.LimitList = JsonHelper.DeserializeObject<List<PrivateLibraryLimitExtend>>(item.PrivateLibraryLimit);
string dIds = string.Join(",", item.LimitList.Where(x => !string.IsNullOrEmpty(x.DeptIds) && x.DeptIds != "-1").Select(x => x.DeptIds));
string eIds = string.Join(",", item.LimitList.Where(x => !string.IsNullOrEmpty(x.EmpIds) && x.EmpIds != "-1").Select(x => x.EmpIds));
if (!string.IsNullOrEmpty(dIds)) {
if (!string.IsNullOrEmpty(deptIds))
{
deptIds += "," + dIds;
}
else {
deptIds = dIds;
}
}
if (!string.IsNullOrEmpty(eIds)) {
if (!string.IsNullOrEmpty(empIds))
{
empIds += "," + eIds;
}
else
{
empIds = eIds;
}
}
}
}
List<RB_Department_ViewModel> deptList = new List<RB_Department_ViewModel>();
if (!string.IsNullOrEmpty(deptIds))
{
deptList = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = group_Id, QDeptIds = deptIds });
}
List<Employee_ViewModel> empList = new List<Employee_ViewModel>();
if (!string.IsNullOrEmpty(empIds))
{
empList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = group_Id, QIds = empIds });
}
foreach (var item in list) {
item.DeptList = new List<RB_Department_ViewModel>();
item.EmpList = new List<Employee_ViewModel>();
if (!string.IsNullOrEmpty(item.DeptIds) && item.DeptIds != "-1")
{
item.DeptList = deptList.Where(x => ("," + item.DeptIds + ",").Contains("," + x.DeptId + ",")).ToList();
}
if (!string.IsNullOrEmpty(item.EmpIds) && item.EmpIds != "-1")
{
item.EmpList = empList.Where(x => ("," + item.EmpIds + ",").Contains("," + x.Id + ",")).ToList();
}
item.ConditionList = new List<RecycleConditionModel>();
if (!string.IsNullOrEmpty(item.RecycleCondition)) {
item.ConditionList = JsonHelper.DeserializeObject<List<RecycleConditionModel>>(item.RecycleCondition);
}
foreach (var qitem in item.LimitList) {
qitem.DeptList = new List<RB_Department_ViewModel>();
qitem.EmpList = new List<Employee_ViewModel>();
if (!string.IsNullOrEmpty(qitem.DeptIds) && qitem.DeptIds != "-1")
{
qitem.DeptList = deptList.Where(x => ("," + qitem.DeptIds + ",").Contains("," + x.DeptId + ",")).ToList();
}
if (!string.IsNullOrEmpty(qitem.EmpIds) && qitem.EmpIds != "-1")
{
qitem.EmpList = empList.Where(x => ("," + qitem.EmpIds + ",").Contains("," + x.Id + ",")).ToList();
}
}
item.PrivateLibraryTypeStr = "";
if (!string.IsNullOrEmpty(item.PrivateLibraryType)) {
List<int> typeIdList = JsonHelper.DeserializeObject<List<int>>("[" + item.PrivateLibraryType + "]");
foreach (var typeId in typeIdList)
{
item.PrivateLibraryTypeStr += ((Common.Enum.WeChat.CustomerAddWayEnum)typeId).ToName() + "、";
}
item.PrivateLibraryTypeStr = item.PrivateLibraryTypeStr[0..^1];
}
item.NotRecycleTimeList = new List<NotRecycleTimeModel>();
if (!string.IsNullOrEmpty(item.NotRecycleTime)) {
item.NotRecycleTimeList = JsonHelper.DeserializeObject<List<NotRecycleTimeModel>>(item.NotRecycleTime);
}
}
}
return list;
}
/// <summary>
/// 获取客户库详情
/// </summary>
/// <param name="libraryId"></param>
/// <param name="group_Id"></param>
/// <returns></returns>
public RB_WeChat_CustomerLibrary_ViewModel GetCustomerLibraryInfo(int libraryId,int group_Id)
{
var list = weChat_CustomerLibraryRepository.GetList(new RB_WeChat_CustomerLibrary_ViewModel() { Group_Id = group_Id, Id = libraryId });
if (list.Any())
{
//查询部门 人员
string deptIds = string.Join(",", list.Where(x => !string.IsNullOrEmpty(x.DeptIds) && x.DeptIds != "-1").Select(x => x.DeptIds));
string empIds = string.Join(",", list.Where(x => !string.IsNullOrEmpty(x.EmpIds) && x.EmpIds != "-1").Select(x => x.EmpIds));
foreach (var item in list)
{
item.LimitList = new List<PrivateLibraryLimitExtend>();
if (!string.IsNullOrEmpty(item.PrivateLibraryLimit))
{
item.LimitList = JsonHelper.DeserializeObject<List<PrivateLibraryLimitExtend>>(item.PrivateLibraryLimit);
string dIds = string.Join(",", item.LimitList.Where(x => !string.IsNullOrEmpty(x.DeptIds) && x.DeptIds != "-1").Select(x => x.DeptIds));
string eIds = string.Join(",", item.LimitList.Where(x => !string.IsNullOrEmpty(x.EmpIds) && x.EmpIds != "-1").Select(x => x.EmpIds));
if (!string.IsNullOrEmpty(dIds))
{
if (!string.IsNullOrEmpty(deptIds))
{
deptIds += "," + dIds;
}
else
{
deptIds = dIds;
}
}
if (!string.IsNullOrEmpty(eIds))
{
if (!string.IsNullOrEmpty(empIds))
{
empIds += "," + eIds;
}
else
{
empIds = eIds;
}
}
}
}
List<RB_Department_ViewModel> deptList = new List<RB_Department_ViewModel>();
if (!string.IsNullOrEmpty(deptIds))
{
deptList = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = group_Id, QDeptIds = deptIds });
}
List<Employee_ViewModel> empList = new List<Employee_ViewModel>();
if (!string.IsNullOrEmpty(empIds))
{
empList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = group_Id, QIds = empIds });
}
foreach (var item in list)
{
item.DeptList = new List<RB_Department_ViewModel>();
item.EmpList = new List<Employee_ViewModel>();
if (!string.IsNullOrEmpty(item.DeptIds) && item.DeptIds != "-1")
{
item.DeptList = deptList.Where(x => ("," + item.DeptIds + ",").Contains("," + x.DeptId + ",")).ToList();
}
if (!string.IsNullOrEmpty(item.EmpIds) && item.EmpIds != "-1")
{
item.EmpList = empList.Where(x => ("," + item.EmpIds + ",").Contains("," + x.Id + ",")).ToList();
}
item.ConditionList = new List<RecycleConditionModel>();
if (!string.IsNullOrEmpty(item.RecycleCondition))
{
item.ConditionList = JsonHelper.DeserializeObject<List<RecycleConditionModel>>(item.RecycleCondition);
}
foreach (var qitem in item.LimitList)
{
qitem.DeptList = new List<RB_Department_ViewModel>();
qitem.EmpList = new List<Employee_ViewModel>();
if (!string.IsNullOrEmpty(qitem.DeptIds) && qitem.DeptIds != "-1")
{
qitem.DeptList = deptList.Where(x => ("," + qitem.DeptIds + ",").Contains("," + x.DeptId + ",")).ToList();
}
if (!string.IsNullOrEmpty(qitem.EmpIds) && qitem.EmpIds != "-1")
{
qitem.EmpList = empList.Where(x => ("," + qitem.EmpIds + ",").Contains("," + x.Id + ",")).ToList();
}
}
item.PrivateLibraryTypeStr = "";
if (!string.IsNullOrEmpty(item.PrivateLibraryType))
{
List<int> typeIdList = JsonHelper.DeserializeObject<List<int>>("[" + item.PrivateLibraryType + "]");
foreach (var typeId in typeIdList)
{
item.PrivateLibraryTypeStr += ((Common.Enum.WeChat.CustomerAddWayEnum)typeId).ToName() + "、";
}
item.PrivateLibraryTypeStr = item.PrivateLibraryTypeStr[0..^1];
}
item.NotRecycleTimeList = new List<NotRecycleTimeModel>();
if (!string.IsNullOrEmpty(item.NotRecycleTime))
{
item.NotRecycleTimeList = JsonHelper.DeserializeObject<List<NotRecycleTimeModel>>(item.NotRecycleTime);
}
}
}
return list.FirstOrDefault();
}
/// <summary>
/// 新增修改客户库
/// </summary>
/// <param name="demodel"></param>
/// <returns></returns>
public string SetCustomerLibraryInfo(RB_WeChat_CustomerLibrary_ViewModel demodel)
{
if (demodel.Id > 0)
{
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.Name), demodel.Name},
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.IsAllowRepeat), demodel.IsAllowRepeat},
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.DeptIds), demodel.DeptIds},
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.EmpIds), demodel.EmpIds},
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.RecyclingType), demodel.RecyclingType},
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.RecycleCondition), demodel.RecycleCondition},
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.NotRecycleTime), demodel.NotRecycleTime},
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.RemindDay), demodel.RemindDay},
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.RemindType), demodel.RemindType},
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.LimitDay), demodel.LimitDay},
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.PrivateLibraryLimit), demodel.PrivateLibraryLimit},
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.PrivateLibraryType), demodel.PrivateLibraryType},
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.UpdateBy), demodel.UpdateBy},
{ nameof(RB_WeChat_CustomerLibrary_ViewModel.UpdateTime), demodel.UpdateTime},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_WeChat_CustomerLibrary_ViewModel.Id),
FiledValue = demodel.Id,
OperatorEnum =OperatorEnum.Equal
}
};
bool flag = weChat_CustomerLibraryRepository.Update(keyValues, wheres);
return flag ? "" : "出错了,请联系管理员";
}
else {
bool flag = weChat_CustomerLibraryRepository.Insert(demodel) > 0;
return flag ? "" : "出错了,请联系管理员";
}
}
#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> GetCustomerRepeatToFollowUpPageList(int pageIndex, int pageSize, out long count, RB_WeChat_CustomerInfo_ViewModel demodel)
{
if (!string.IsNullOrEmpty(demodel.CName))
{
//查询姓名的自定义ID
demodel.CNameId = weChat_CustomerFieldRepository.GetList(new RB_WeChat_CustomerField_ViewModel() { Group_Id = demodel.Group_Id, CName = "姓名" }).FirstOrDefault()?.Id ?? 0;
if (demodel.CNameId <= 0)
{
count = 0;
return new List<RB_WeChat_CustomerInfo_ViewModel>();
}
}
var RList = new List<RB_WeChat_CustomerInfo_ViewModel>();
var clist = weChat_CustomerInfoRepository.GetCustomerRepeatToFollowUpPageList(pageIndex, pageSize, out count, demodel);
if (clist.Any()) {
//根据客人的企业微信ID 查询出所有的客户ID
string ExternalUserIds = "'" + string.Join("','", clist.Select(x => x.ExternalUserId)) + "'";
var list = weChat_CustomerInfoRepository.GetList(new RB_WeChat_CustomerInfo_ViewModel() { Group_Id = demodel.Group_Id, Q_ExternalUserIds = ExternalUserIds });
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 });
}
//负责人 、 公海前负责人查询
List<Employee_ViewModel> EmpList = new List<Employee_ViewModel>();
string EmpWorkUserId = "'" + string.Join("','", list.Where(x => !string.IsNullOrEmpty(x.WorkEmpId)).Select(x => x.WorkEmpId).Distinct()) + "'";
if (EmpWorkUserId != "''")
{
EmpList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = demodel.Group_Id, WorkUserIds = EmpWorkUserId });
}
//自定义字段 -- 这个怎么处理呢 根据自定义子段遍历吗
//先直接返回自定义子段
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 ?? "";
if (demodel.CustomerState == 3)
{
item.OldEmpName = EmpList.Where(x => x.Id == item.OldEmpId).FirstOrDefault()?.EmployeeName ?? "";
}
else
{
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
});
}
}
}
}
foreach (var item in clist)
{
RList.AddRange(list.Where(x => x.ExternalUserId == item.ExternalUserId).ToList());
}
}
return RList;
}
#endregion
}
}
......
......@@ -36,6 +36,10 @@ namespace Edu.Repository.WeChat
{
where += $@" and r.{nameof(RB_WeChat_CustomerField_ViewModel.Type)} ={(int)demodel.Type}";
}
if (!string.IsNullOrEmpty(demodel.CName))
{
where += $@" and r.{nameof(RB_WeChat_CustomerField_ViewModel.Name)} ='{demodel.CName}'";
}
if (!string.IsNullOrEmpty(demodel.Name))
{
where += $@" and r.{nameof(RB_WeChat_CustomerField_ViewModel.Name)} like @Name";
......
......@@ -113,6 +113,35 @@ namespace Edu.Repository.WeChat
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.AddWay)} in({demodel.Q_AddWay})";
}
if (!string.IsNullOrEmpty(demodel.TurnCustomerSTime))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.TurnCustomerTime)} >='{demodel.TurnCustomerSTime}'";
}
if (!string.IsNullOrEmpty(demodel.TurnCustomerETime))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.TurnCustomerTime)} <='{demodel.TurnCustomerETime} 23:59:59'";
}
if (!string.IsNullOrEmpty(demodel.AllotCustomerSTime))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.AllotCustomerTime)} >='{demodel.AllotCustomerSTime}'";
}
if (!string.IsNullOrEmpty(demodel.AllotCustomerETime))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.AllotCustomerTime)} <='{demodel.AllotCustomerETime} 23:59:59'";
}
if (demodel.DeptId > 0)
{
where += $@" and e.RB_Department_Id ={demodel.DeptId}";
}
if (!string.IsNullOrEmpty(demodel.AbandonReason))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.AbandonReason)} ='{demodel.AbandonReason}'";
}
if (demodel.CustomerLibraryId > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CustomerLibraryId)} ={demodel.CustomerLibraryId}";
}
#region 解析查询参数
if (demodel.SelectList != null && demodel.SelectList.Any())
{
......@@ -120,7 +149,19 @@ namespace Edu.Repository.WeChat
where += " and (";
foreach (var item in demodel.SelectList)
{
if (item.IsCustom == 1) { item.Name = "z" + item.Name; }
if (item.IsCustom == 1)
{
item.Name = "z" + item.Name;
}
else if (item.IsCustom == 2)
{
//标签
item.Name = "LableIds";
}
else if (item.IsCustom == 3) {
//客户阶段
item.Name = "StageId";
}
if (Num != 1) { where += demodel.AddCondition == 1 ? " and" : " or"; }
switch (item.Type) {
case 1://包含 都是int类型的
......@@ -259,7 +300,8 @@ namespace Edu.Repository.WeChat
string vstr = "'" + string.Join("','", vList) + "'";
if (item.IsCustom == 1)
{
where += $@" DATE_FORMAT(r.CustomContent -> '$.{item.Name}','%m月%d号') in({vstr}) ";
//where += $@" DATE_FORMAT(r.CustomContent -> '$.{item.Name}','%m月%d号') in({vstr}) ";
where += " date_format(REPLACE( r.CustomContent -> '$." + item.Name + "', '\"', ''), '%m月%d号') in({vstr}) ";
}
else
{
......@@ -357,6 +399,7 @@ namespace Edu.Repository.WeChat
string sql = $@"
SELECT * From RB_WeChat_CustomerInfo r
left join rb_employee e on r.EmpId = e.EmployeeId
WHERE {where}
ORDER BY {orderByStr} ";
return GetPage<RB_WeChat_CustomerInfo_ViewModel>(pageIndex, pageSize, out count, sql, parameters).ToList();
......@@ -435,6 +478,10 @@ ORDER BY {orderByStr} ";
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CorpFullName)} like @CorpFullName";
parameters.Add("CorpFullName", "%" + demodel.CorpFullName + "%");
}
if (!string.IsNullOrEmpty(demodel.Q_ExternalUserIds))
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.ExternalUserId)} in({demodel.Q_ExternalUserIds})";
}
string sql = $@"
SELECT * From RB_WeChat_CustomerInfo r
......@@ -442,5 +489,86 @@ WHERE {where}
ORDER BY r.Id DESC ";
return Get<RB_WeChat_CustomerInfo_ViewModel>(sql, parameters).ToList();
}
/// <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> GetCustomerRepeatToFollowUpPageList(int pageIndex, int pageSize, out long count, RB_WeChat_CustomerInfo_ViewModel demodel)
{
DynamicParameters parameters = new DynamicParameters();
string where = $" 1=1 and r.`Status` =0 and r.CustomerState =1 and r.EmpId >0 and r.ExternalUserId <> '' ";
if (demodel.Group_Id > 0)
{
where += $" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.Group_Id)} ={demodel.Group_Id}";
}
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.CName))
{
where += $@" and r.CustomContent -> '$.z{demodel.CNameId}' like '%{demodel.CName}%' ";
}
if (demodel.EmpId > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.EmpId)} ={demodel.EmpId}";
}
if (demodel.DeptId > 0)
{
where += $@" and e.RB_Department_Id ={demodel.DeptId}";
}
string sql = $@"select r.ExternalUserId, COUNT(0) as Num from rb_wechat_customerinfo r
left join rb_employee e on r.EmpId = e.EmployeeId
where {where}
GROUP BY r.ExternalUserId HAVING COUNT(0) >1";
return GetPage<RB_WeChat_CustomerInfo_ViewModel>(pageIndex, pageSize, out count, sql).ToList();
}
/// <summary>
/// 验证手机号码是否存在
/// </summary>
/// <param name="demodel"></param>
/// <returns></returns>
public bool ValidataMobile(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.Id > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerInfo_ViewModel.Id)} <>{demodel.Id}";
}
if (!string.IsNullOrEmpty(demodel.CustomerMobile))
{
where += $@" and FIND_IN_SET('{demodel.CustomerMobile}'), r.{nameof(RB_WeChat_CustomerInfo_ViewModel.CustomerMobile)})";
}
string sql = $@"
SELECT count(0) From RB_WeChat_CustomerInfo r
WHERE {where} ";
var obj = ExecuteScalar(sql);
return (obj == null ? 0 : Convert.ToInt32(obj)) > 0;
}
}
}
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_CustomerLibraryRepository : BaseRepository<RB_WeChat_CustomerLibrary>
{
/// <summary>
/// 获取列表
/// </summary>
/// <param name="demodel"></param>
/// <returns></returns>
public List<RB_WeChat_CustomerLibrary_ViewModel> GetList(RB_WeChat_CustomerLibrary_ViewModel demodel)
{
DynamicParameters parameters = new DynamicParameters();
string where = $@" 1=1 and r.{nameof(RB_WeChat_CustomerLibrary_ViewModel.Status)} =0";
if (demodel.Group_Id > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerLibrary_ViewModel.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.Id > 0)
{
where += $@" and r.{nameof(RB_WeChat_CustomerLibrary_ViewModel.Id)} ={demodel.Id}";
}
if (!string.IsNullOrEmpty(demodel.Name))
{
where += $@" and r.{nameof(RB_WeChat_CustomerLibrary_ViewModel.Name)} like @Name";
parameters.Add("Name", "%" + demodel.Name + "%");
}
string sql = $@"
SELECT * From RB_WeChat_CustomerLibrary r
WHERE {where}
ORDER BY r.Id DESC ";
return Get<RB_WeChat_CustomerLibrary_ViewModel>(sql, parameters).ToList();
}
}
}
......@@ -622,7 +622,7 @@ namespace Edu.ThirdCore.QYWinXin
userid = UserId,
external_userid = ExternalUserId,
add_tag = LableList
};
};//remove_tag
var Rmsg = HttpHelper.HttpPost(url, JsonHelper.Serialize(SendDate), "");
if (!string.IsNullOrEmpty(Rmsg))
......
......@@ -625,7 +625,8 @@ namespace Edu.WebApi.Controllers.QYWeChat
x.Options,
x.OptionsList,
x.Digits,
x.Sort
x.Sort,
x.Value
}),
model.FriendState,
LastFollowUpTime = model.LastFollowUpTime.HasValue ? model.LastFollowUpTime.Value.ToString("yyyy-MM-dd HH:mm") : "",
......@@ -862,7 +863,7 @@ namespace Edu.WebApi.Controllers.QYWeChat
}
/// <summary>
/// 客户转移(在职,离职
/// 客户转移(在职,离职
/// </summary>
/// <returns></returns>
[HttpPost]
......@@ -1085,11 +1086,11 @@ namespace Edu.WebApi.Controllers.QYWeChat
demodel.RuleSelectValue = JsonHelper.Serialize(demodel.ConditionList);
demodel.DeptIds = "-1";
demodel.EmpIds = "-1";
if (demodel.DeptList == null || !demodel.DeptList.Any())
if (demodel.DeptList != null || demodel.DeptList.Any())
{
demodel.DeptIds = string.Join(",", demodel.DeptList.Select(x => x.DeptId));
}
if (demodel.EmpList == null || !demodel.EmpList.Any())
if (demodel.EmpList != null || demodel.EmpList.Any())
{
demodel.EmpIds = string.Join(",", demodel.EmpList.Select(x => x.Id));
}
......@@ -1282,8 +1283,498 @@ namespace Edu.WebApi.Controllers.QYWeChat
return ApiResult.ParamIsNull(msg);
}
}
/// <summary>
/// 获取客户线索已转客户分页列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerClueToPassPageList()
{
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;
demodel.ClueState = 4;//已转客户
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.Source,
x.CustomContent,
x.CustomFiledList,
x.FriendState,
TurnCustomerTime = x.TurnCustomerTime.HasValue ? x.TurnCustomerTime.Value.ToString("yyyy-MM-dd HH:mm") : "",
CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm")
});
return ApiResult.Success("", pmodel);
}
/// <summary>
/// 获取客户线索导入文件
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerClueExportFile() {
var userInfo = base.UserInfo;
string FliePath = customerModule.GetCustomerClueExportFile(userInfo);
return ApiResult.Success("", new { Path = FliePath });
}
#endregion
#endregion
#region 待分配客户
/// <summary>
/// 获取客户待分配分页列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerClueWaitDistributionPageList()
{
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;
demodel.CustomerState = 2;//还是线索
demodel.ClueState = 4;//已转客户
demodel.AllotState = 1;//待分配
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.Source,
x.CustomContent,
x.CustomFiledList,
x.FriendState,
LastFollowUpTime = x.LastFollowUpTime.HasValue ? x.LastFollowUpTime.Value.ToString("yyyy-MM-dd HH:mm") : "",
CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm")
});
return ApiResult.Success("", pmodel);
}
/// <summary>
/// 获取客户已分配分页列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerClueAssignedPageList()
{
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;
demodel.ClueState = 4;//已转客户
demodel.AllotState = 2;//已分配
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.Source,
x.CustomContent,
x.CustomFiledList,
x.FriendState,
AllotCustomerTime = x.AllotCustomerTime.HasValue ? x.AllotCustomerTime.Value.ToString("yyyy-MM-dd HH:mm") : "",
CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm")
});
return ApiResult.Success("", pmodel);
}
#endregion
#region 公海
#region 客户库
/// <summary>
/// 获取客户库 查重规则
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerLibraryLookRepeat() {
var userInfo = base.UserInfo;
int lookRepeat = customerModule.GetCustomerLibraryLookRepeat(userInfo.Group_Id);
return ApiResult.Success("", lookRepeat);
}
/// <summary>
/// 设置客户库 查重规则
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetCustomerLibraryLookRepeat() {
var userInfo = base.UserInfo;
JObject parms = JObject.Parse(base.RequestParm.Msg.ToString());
int LookRepeat = parms.GetInt("LookRepeat", 1);//查重规则
if (LookRepeat <= 0) {
return ApiResult.ParamIsNull();
}
string msg = customerModule.SetCustomerLibraryLookRepeat(userInfo.Group_Id, LookRepeat);
if (msg == "")
{
return ApiResult.Success();
}
else {
return ApiResult.Failed(msg);
}
}
/// <summary>
/// 获取客户库列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerLibraryList() {
var userInfo = base.UserInfo;
var list = customerModule.GetCustomerLibraryList(userInfo.Group_Id);
return ApiResult.Success("", list.OrderBy(x => x.IsDefault).ThenByDescending(x => x.Id).Select(x => new
{
x.Id,
x.Name,
x.IsDefault,
x.IsAllowRepeat,
DeptList = x.DeptList.Select(z => new
{
z.DeptId,
z.DeptName
}),
EmpList = x.EmpList.Select(z => new
{
z.Id,
z.EmployeeName
}),
x.RecyclingType,
x.ConditionList,
x.NotRecycleTimeList,
x.RemindDay,
x.RemindType,
x.LimitDay,
LimitList = x.LimitList.Select(z => new
{
z.IsDefault,
z.LimitNum,
z.LockNum,
DeptList = z.DeptList.Select(y => new
{
y.DeptId,
y.DeptName
}),
EmpList = z.EmpList.Select(y => new
{
y.Id,
y.EmployeeName
})
}),
x.PrivateLibraryType,
x.PrivateLibraryTypeStr,
UpdateByName = Cache.User.UserReidsCache.GetUserLoginInfo(x.UpdateBy)?.AccountName ?? "",
UpdateTime = x.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss"),
}));
}
/// <summary>
/// 获取客户库详情
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerLibraryInfo() {
var userInfo = base.UserInfo;
JObject parms = JObject.Parse(base.RequestParm.Msg.ToString());
int LibraryId = parms.GetInt("LibraryId", 0);//客户库ID
if (LibraryId <= 0) {
return ApiResult.ParamIsNull();
}
var model = customerModule.GetCustomerLibraryInfo(LibraryId, userInfo.Group_Id);
return ApiResult.Success("", new
{
model.Id,
model.Name,
model.IsDefault,
model.IsAllowRepeat,
DeptList = model.DeptList.Select(z => new
{
z.DeptId,
z.DeptName
}),
EmpList = model.EmpList.Select(z => new
{
z.Id,
z.EmployeeName
}),
model.RecyclingType,
model.ConditionList,
model.NotRecycleTimeList,
model.RemindDay,
model.RemindType,
model.LimitDay,
LimitList = model.LimitList.Select(z => new
{
z.IsDefault,
z.LimitNum,
z.LockNum,
DeptList = z.DeptList.Select(y => new
{
y.DeptId,
y.DeptName
}),
EmpList = z.EmpList.Select(y => new
{
y.Id,
y.EmployeeName
})
}),
model.PrivateLibraryType
});
}
/// <summary>
/// 新增修改客户库信息
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetCustomerLibraryInfo() {
var userInfo = base.UserInfo;
RB_WeChat_CustomerLibrary_ViewModel demodel = JsonHelper.DeserializeObject<RB_WeChat_CustomerLibrary_ViewModel>(base.RequestParm.Msg.ToString());
if (string.IsNullOrEmpty(demodel.Name)) {
return ApiResult.ParamIsNull("请输入客户库名称");
}
if (demodel.RecyclingType == 2) {
if (demodel.ConditionList == null || !demodel.ConditionList.Any()) {
return ApiResult.ParamIsNull("请传递条件列表");
}
demodel.RecycleCondition = JsonHelper.Serialize(demodel.ConditionList);
}
if (demodel.IsDefault == 1)
{
demodel.DeptIds = "";
demodel.EmpIds = "";
}
else {
if ((demodel.DeptList == null || !demodel.DeptList.Any()) && (demodel.EmpList == null || !demodel.EmpList.Any())) {
return ApiResult.ParamIsNull("请选择部门/员工");
}
demodel.DeptIds = string.Join(",", demodel.DeptList.Select(x => x.DeptId));
demodel.EmpIds = string.Join(",", demodel.EmpList.Select(x => x.Id));
}
demodel.PrivateLibraryLimit = "";
if (demodel.LimitList != null && demodel.LimitList.Any()) {
foreach (var item in demodel.LimitList) {
if (item.IsDefault == 1)
{
item.DeptIds = "";
item.EmpIds = "";
}
else {
if ((item.DeptList == null || !item.DeptList.Any()) && (item.EmpList == null || !item.EmpList.Any()))
{
return ApiResult.ParamIsNull("请选择部门/员工");
}
item.DeptIds = string.Join(",", item.DeptList.Select(x => x.DeptId));
item.EmpIds = string.Join(",", item.EmpList.Select(x => x.Id));
}
}
demodel.PrivateLibraryLimit = JsonHelper.Serialize(demodel.LimitList);
}
demodel.NotRecycleTime = "";
if (demodel.NotRecycleTimeList != null && demodel.NotRecycleTimeList.Any()) {
demodel.NotRecycleTime = JsonHelper.Serialize(demodel.NotRecycleTimeList);
}
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.SetCustomerLibraryInfo(demodel);
if (msg == "")
{
return ApiResult.Success();
}
else {
return ApiResult.Failed(msg);
}
}
#endregion
/// <summary>
/// 获取公海客户分页列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerPublicPageList()
{
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;
demodel.CustomerState = 3;//公海客户
//这里有个放弃的原因 放弃时间 前负责人
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.OldEmpId,
x.OldEmpName,
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.Source,
x.CustomContent,
x.CustomFiledList,
x.FriendState,
x.AbandonReason,
AbandonTime = x.AbandonTime.HasValue ? x.AbandonTime.Value.ToString("yyyy-MM-dd HH:mm") : "",
LastFollowUpTime = x.LastFollowUpTime.HasValue ? x.LastFollowUpTime.Value.ToString("yyyy-MM-dd HH:mm") : "",
CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm")
});
return ApiResult.Success("", pmodel);
}
#endregion
#region 重复跟进
/// <summary>
/// 获取重复跟进客户分页列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetCustomerRepeatToFollowUpPageList() {
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.GetCustomerRepeatToFollowUpPageList(pmodel.PageIndex, pmodel.PageSize, out long count, demodel);
pmodel.Count = Convert.ToInt32(count);
pmodel.PageData = list.GroupBy(x => x.ExternalUserId).Select(x => new
{
x.Key,
x.FirstOrDefault()?.WeChatName,
x.FirstOrDefault()?.WeChatPhoto,
List = x.Select(z => new
{
z.Id,
z.EmpId,
z.EmpName,
z.WorkEmpId,
z.WorkEmpName,
z.ExternalUserId,
z.CustomerName,
z.WeChatName,
z.WeChatPhoto,
z.CorpName,
z.CorpFullName,
z.CustomerType,
z.StageId,
z.StageName,
z.LableIds,
LableList = z.LableList?.Select(y => new
{
y.Id,
y.Name
}),
z.PersonLable,
z.Source,
z.CustomContent,
z.CustomFiledList,
z.FriendState,
LastFollowUpTime = z.LastFollowUpTime.HasValue ? z.LastFollowUpTime.Value.ToString("yyyy-MM-dd HH:mm") : "",
z.CheckInNum,
CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm"),
FriendTime = z.FriendTime.HasValue ? z.FriendTime.Value.ToString("yyyy-MM-dd HH:mm") : ""
})
});
return ApiResult.Success("", pmodel);
}
#endregion
}
}
......@@ -26,6 +26,10 @@ namespace Edu.WebApi.Controllers.Upload
/// 投稿
/// </summary>
readonly QYContributeModule contributeModule = new QYContributeModule();
/// <summary>
/// 客户管理
/// </summary>
readonly QYCustomerModule customerModule = new QYCustomerModule();
/// <summary>
/// 上传Excel文件
......@@ -44,7 +48,7 @@ namespace Edu.WebApi.Controllers.Upload
}
var json = !string.IsNullOrEmpty(Request.Form["params"]) ? JObject.Parse(Request.Form["params"].ToString()) : null;
Int32.TryParse((json["Analysis"]!=null? json["Analysis"].ToString():"0"), out int Analysis);
Int32.TryParse((json["Analysis"] != null ? json["Analysis"].ToString() : "0"), out int Analysis);
Int32.TryParse((json["Excel"] != null ? json["Excel"].ToString() : "0"), out int Excel);
Int32.TryParse((json["Word"] != null ? json["Word"].ToString() : "0"), out int Word);
Int32.TryParse((json["CourseId"] != null ? json["CourseId"].ToString() : "0"), out int CourseId);
......@@ -65,7 +69,7 @@ namespace Edu.WebApi.Controllers.Upload
}
string path = Guid.NewGuid().ToString() + fileExtention;
string basepath = AppContext.BaseDirectory;
string tempPath = basepath + "\\upfile\\temporary\\" + DateTime.Now.ToString("yyyyMMdd")+"\\";
string tempPath = basepath + "\\upfile\\temporary\\" + DateTime.Now.ToString("yyyyMMdd") + "\\";
string path_server = tempPath + path;
if (!Directory.Exists(tempPath))
{
......@@ -82,9 +86,9 @@ namespace Edu.WebApi.Controllers.Upload
return new QuestionController().ImportExcelQuestion(path_server, CourseId, Uid);
}
//导入Word文件
if (Analysis == 1 && Word == 1 )
if (Analysis == 1 && Word == 1)
{
return new QuestionController().ImportWordQuestion(path_server, CourseId, Uid,isDelete:true);
return new QuestionController().ImportWordQuestion(path_server, CourseId, Uid, isDelete: true);
}
return ApiResult.Success("", new { Name = filename, Path = path_server });
}
......@@ -308,7 +312,7 @@ namespace Edu.WebApi.Controllers.Upload
}
#region 图片上传至公众号
string RMsg = contributeModule.UploadImageTextGetUrl(path_server, 100000,out bool flag);
string RMsg = contributeModule.UploadImageTextGetUrl(path_server, 100000, out bool flag);
#endregion
if (flag)
{
......@@ -324,5 +328,74 @@ namespace Edu.WebApi.Controllers.Upload
return ApiResult.Failed();
}
}
/// <summary>
/// 导入客户线索
/// </summary>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public ApiResult UploadQYWeChatCustomerClueInfo() {
try
{
var files = Request.Form.Files;
if (files.Count == 0)
{
return new ApiResult { Code = (int)ResultCode.Fail, Message = "未选择文件", Data = "" };
}
var json = !string.IsNullOrEmpty(Request.Form["params"]) ? JObject.Parse(Request.Form["params"].ToString()) : null;
Int32.TryParse((json["Uid"] != null ? json["Uid"].ToString() : "0"), out int UserId);
string filename = files[0].FileName;
string fileExtention = System.IO.Path.GetExtension(files[0].FileName);
//验证文件格式
List<string> ExtList = new List<string>() {
".xls",
".xlsx"
};
if (!ExtList.Contains(fileExtention))
{
return new ApiResult { Code = (int)ResultCode.Fail, Message = "文件格式有误", Data = "" };
}
if (files[0].Length <= 0)
{
return new ApiResult { Code = (int)ResultCode.Fail, Message = "文件大小有误", Data = "" };
}
decimal fileMNum = files[0].Length / (1024 * 1024);
if (fileMNum > 10) { return ApiResult.Failed("文件不能超过10M"); }
string path = Guid.NewGuid().ToString() + fileExtention;
string basepath = AppContext.BaseDirectory;
string dateStr = DateTime.Now.ToString("yyyyMMdd");
string tempPath = basepath + "upfile\\temporary\\" + dateStr + "\\";
string path_server = tempPath + path;
string httpPath = "/upfile/temporary/" + dateStr + "/" + path;
if (!Directory.Exists(tempPath))
{
Directory.CreateDirectory(tempPath);
}
using (FileStream fstream = new FileStream(path_server, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
files[0].CopyTo(fstream);
}
#region 解析文档数据
string rmsg = customerModule.ImportExcelForCustomerClue(path_server, UserId);
if (rmsg == "")
{
return ApiResult.Success();
}
else
{
return ApiResult.Failed(rmsg);
}
#endregion
}
catch (Exception ex)
{
LogHelper.Write(ex, "UploadQYWeChatCustomerClueInfo");
return ApiResult.Failed();
}
}
}
}
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