279 lines
11 KiB
C#
279 lines
11 KiB
C#
using Ninject;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Base;
|
|
using WX.CRM.IBLL.weapp;
|
|
using WX.CRM.Model.Entity;
|
|
using WX.CRM.WebHelper;
|
|
using WX.CRM.WebHelper.Infrastructure;
|
|
|
|
namespace AppletMvcService.Controllers
|
|
{
|
|
|
|
//[EnableCors("http://localhost:10229", "*", "*")]
|
|
public class WxGroupSvrController : Controller
|
|
{
|
|
private readonly IWEAPP_GROUP _weappGroup = NinjectControllerFactory.ninjectKernel.Get<IWEAPP_GROUP>();
|
|
private readonly IWEAPP_USERGROUP _weappUserGroup = NinjectControllerFactory.ninjectKernel.Get<IWEAPP_USERGROUP>();
|
|
private readonly IWEAPP_FRIENDS _weappFriends = NinjectControllerFactory.ninjectKernel.Get<IWEAPP_FRIENDS>();
|
|
private readonly ISEQUENCES _sequences = NinjectControllerFactory.ninjectKernel.Get<ISEQUENCES>();
|
|
/// <summary>
|
|
/// 编辑分组的时候列出全部分组
|
|
/// </summary>
|
|
/// <param name="accountNum"></param>
|
|
/// <param name="eId"></param>
|
|
/// <returns></returns>
|
|
public JsonResult GetGroup(string accountNum, decimal eId)
|
|
{
|
|
try
|
|
{
|
|
//var sw = new Stopwatch();
|
|
//sw.Start();
|
|
var list = _weappGroup.GetGroup(accountNum, eId);
|
|
//sw.Stop();
|
|
//LogHelper.Info("请求时间:" + sw.ElapsedMilliseconds);
|
|
return Json(new { type = 1, data = list }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex.ToString());
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
}
|
|
|
|
public JsonResult AddGroup(decimal eid, string groupName, string accountNum)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(groupName) || string.IsNullOrEmpty(accountNum))
|
|
{
|
|
return JsonHandler.ManageMessage("参数错误,请确认!", false);
|
|
}
|
|
var info = new WEAPP_GROUP
|
|
{
|
|
PKID = _sequences.Seq_base_get(),
|
|
GROUPNAME = groupName,
|
|
GROUPTYPE = 1,
|
|
SALEUSEREID = eid,
|
|
CTIME = DateTime.Now,
|
|
ACCOUNTNUM = accountNum
|
|
};
|
|
var ret = _weappGroup.Add(info) > 0 ? 1 : 0;
|
|
return Json(new { type = ret, pkid = info.PKID }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex.ToString());
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
}
|
|
|
|
public JsonResult UpdateGroup(decimal groupId, decimal eid, string groupName, string accountNum)
|
|
{
|
|
try
|
|
{
|
|
if (groupId == 0)
|
|
return AddGroup(eid, groupName, accountNum);
|
|
if (string.IsNullOrEmpty(groupName) || string.IsNullOrEmpty(accountNum))
|
|
{
|
|
return JsonHandler.ManageMessage("参数错误,请确认!", false);
|
|
}
|
|
WEAPP_GROUP info = _weappGroup.Get(p => p.PKID == groupId);
|
|
info.GROUPNAME = groupName;
|
|
info.ACCOUNTNUM = accountNum;
|
|
var ret = _weappGroup.Update(info) ? 1 : 0;
|
|
return Json(new { type = ret }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex.ToString());
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
}
|
|
|
|
public JsonResult DeleteGroup(decimal groupId)
|
|
{
|
|
try
|
|
{
|
|
if (groupId <= 0)
|
|
{
|
|
return JsonHandler.ManageMessage("参数错误,请确认!", false);
|
|
}
|
|
_weappUserGroup.Delete(p => p.GROUPID == groupId);
|
|
var ret = _weappGroup.Delete(p => p.PKID == groupId) ? 1 : 0;
|
|
return Json(new { type = ret }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex.ToString());
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取客服 所有的和客户的分组情况
|
|
/// </summary>
|
|
/// <param name="accountNum"></param>
|
|
/// <param name="eId"></param>
|
|
/// <returns></returns>
|
|
public JsonResult GetUserGroup(string accountNum, decimal eId)
|
|
{
|
|
try
|
|
{
|
|
//var sw = new Stopwatch();
|
|
//sw.Start();
|
|
var list = new List<UserGroupView>();
|
|
var userGroupView = _weappGroup.GetUserGroup(accountNum, eId);
|
|
var groups = userGroupView.groups;
|
|
foreach (var item in groups)
|
|
{
|
|
var userGroup = userGroupView.userGroups.Where(p => p.GROUPID == item.PKID);
|
|
var userGroupList = new List<UserGroup>();
|
|
foreach (var row in userGroup)
|
|
{
|
|
var data = new UserGroup { GroupId = row.GROUPID, OpenId = row.OPENID, SaleUserEid = row.SALEUSEREID };
|
|
userGroupList.Add(data);
|
|
}
|
|
var info = new UserGroupView()
|
|
{
|
|
GroupId = item.PKID,
|
|
GroupName = item.GROUPNAME,
|
|
GroupType = item.GROUPTYPE,
|
|
SaleUserEid = item.SALEUSEREID,
|
|
AccountNum = item.ACCOUNTNUM,
|
|
UserGroupList = userGroupList
|
|
};
|
|
list.Add(info);
|
|
}
|
|
//sw.Stop();
|
|
//LogHelper.Info("请求时间:" + sw.ElapsedMilliseconds);
|
|
return Json(new { type = 1, data = list }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex.ToString());
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取客户的单个分组情况
|
|
/// </summary>
|
|
/// <param name="accountnum"></param>
|
|
/// <param name="openid"></param>
|
|
/// <param name="eid"></param>
|
|
/// <returns></returns>
|
|
public JsonResult GetUserInGroupByOpenId(string accountnum, string openid, decimal eId)
|
|
{
|
|
try
|
|
{
|
|
var list = _weappGroup.GetList(p => p.GROUPTYPE == 1 && p.ACCOUNTNUM == accountnum && p.SALEUSEREID == eId).OrderBy(m => m.CTIME);
|
|
var userGroups = _weappUserGroup.GetList(p => p.SALEUSEREID == eId && p.ACCOUNTNUM == accountnum && p.OPENID == openid);
|
|
List<object> xnn = new List<object>();
|
|
foreach (var item in userGroups)
|
|
{
|
|
xnn.Add(new { gid = item.GROUPID });
|
|
}
|
|
return Json(new { type = 1, data = xnn, data2 = list }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex.ToString());
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
}
|
|
|
|
public JsonResult UpdateUserGroup(string accountNum, decimal eId, string openId, string groups)
|
|
{
|
|
try
|
|
{
|
|
var sysGid = _weappGroup.GetList(m => m.GROUPTYPE == 0).Select(m => m.PKID);
|
|
_weappUserGroup.Delete(p => p.OPENID == openId && p.SALEUSEREID == eId && !sysGid.Contains(p.GROUPID));//不能删除系统分组
|
|
var list = new List<WEAPP_USERGROUP>();
|
|
var groupList = new List<string>(groups.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
|
|
foreach (var item in groupList)
|
|
{
|
|
var info = new WEAPP_USERGROUP
|
|
{
|
|
PKID = _sequences.Seq_base_get(),
|
|
GROUPID = Convert.ToDecimal(item),
|
|
SALEUSEREID = eId,
|
|
OPENID = openId,
|
|
ACCOUNTNUM = accountNum,
|
|
CTIME = DateTime.Now
|
|
};
|
|
list.Add(info);
|
|
}
|
|
_weappUserGroup.AddList(list);
|
|
return Json(new { type = 1 }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex.ToString());
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
}
|
|
|
|
public JsonResult DeleteUserGroup(UserGroup userGroup)
|
|
{
|
|
try
|
|
{
|
|
if (userGroup.GroupId <= 0 || userGroup.SaleUserEid <= 0 || string.IsNullOrEmpty(userGroup.OpenId))
|
|
{
|
|
return JsonHandler.ManageMessage("参数错误,请确认!", false);
|
|
}
|
|
var ret = _weappUserGroup.Delete(p => p.GROUPID == userGroup.GroupId && p.OPENID == userGroup.OpenId) ? 1 : 0;
|
|
return Json(new { type = ret }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex.ToString());
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
}
|
|
|
|
public JsonResult UpdateRemark(string OPENID, string REMARKS, string ACCOUNTNUM, int EID)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(OPENID) || string.IsNullOrEmpty(ACCOUNTNUM) || EID <= 0)
|
|
{
|
|
return JsonHandler.ManageMessage("参数错误,请确认!", false);
|
|
}
|
|
var info = _weappFriends.Get(p => p.EID == EID && p.OPENID == OPENID && p.ACCOUNTNUM == ACCOUNTNUM);
|
|
if (info == null)
|
|
{
|
|
return Json(new { type = 0, message = "未找到记录!" }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
info.REMARKS = REMARKS;
|
|
var ret = _weappFriends.Update(info) ? "1" : "0";
|
|
return Json(new { type = ret }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex.ToString());
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
}
|
|
|
|
public class UserGroupView
|
|
{
|
|
public decimal GroupId { get; set; }
|
|
public string GroupName { get; set; }
|
|
public decimal GroupType { get; set; }
|
|
public decimal? SaleUserEid { get; set; }
|
|
public string AccountNum { get; set; }
|
|
public List<UserGroup> UserGroupList { get; set; }
|
|
}
|
|
|
|
public class UserGroup
|
|
{
|
|
public decimal GroupId { get; set; }
|
|
public decimal SaleUserEid { get; set; }
|
|
public string OpenId { get; set; }
|
|
|
|
}
|
|
}
|
|
} |