using Ninject; using System; using System.Collections.Generic; using System.Web.Mvc; using WX.CRM.BLL; using WX.CRM.Common; using WX.CRM.IBLL.Base; using WX.CRM.IBLL.Res; using WX.CRM.IBLL.Util; using WX.CRM.IBLL.Wx; using WX.CRM.Model.Entity; using WX.CRM.WEB.Handler; using WX.CRM.WebHelper; using WX.CRM.WebHelper.RedisFactory; namespace WX.CRM.WEB.Controllers.WeiXin { public class WXCustomerInfoController : BaseController { ValidationErrors errors = new ValidationErrors(); private RedisFactory redisFactory = new RedisFactory(); private IBAS_PARAMETER_Q _BAS_PARAMETER_Q; private IRES_CUSTOMER _RES_CUSTOMER; private IRES_APPLY _RES_APPLY; private IRES_CUSTOMER_Q _RES_CUSTOMER_Q; private IWX_RCONTACT _wxRcontact; private IWX_WORKACCOUNT wx_WorkAccount_BL; private ICACHE_Q cache_q; [Inject] public IWX_SZZYORDER wx_SzzyOrder_BL { get; set; } public WXCustomerInfoController(IBAS_PARAMETER_Q BAS_PARAMETER_Q, IRES_CUSTOMER RES_CUSTOMER, IRES_APPLY RES_APPLY, IRES_CUSTOMER_Q RES_CUSTOMER_Q, IWX_RCONTACT wxRcontact, IWX_WORKACCOUNT wx_WorkAccount_BL, ICACHE_Q _cache_q) { this._BAS_PARAMETER_Q = BAS_PARAMETER_Q; this._RES_APPLY = RES_APPLY; this._RES_CUSTOMER = RES_CUSTOMER; this._RES_CUSTOMER_Q = RES_CUSTOMER_Q; this._wxRcontact = wxRcontact; this.wx_WorkAccount_BL = wx_WorkAccount_BL; this.cache_q = _cache_q; } #region 首页 [AuthorizeRedirect(Roles = InitRights.CONST_我的微信客户)] public ActionResult Index() { ControlResource.JudgeSYQ(); string isShowAlias = cache_q.GetValue_Parameter("WeiXin_IsShowAlias");//是否显示微信号 string isShowOpenOrderTip = cache_q.GetValue_Parameter(Model.Enum.Parameter.WeiXin_IsShowOpenOrderTip); ToolBar tool = new ToolBar(); string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.我的微信客户, userRightId); tool.AllowButton(toolbtn); tool.AddOtherButton("Other1", "导出", "icon-export", "Export_Click1", true); ViewBag.ToolBar = tool; Pager pager = new Pager() { page = 1, rows = 20 }; string tableId = "tablist"; Table tab = new Table(tableId); tab.AddHiddenHeadCol("PKID", "编号"); tab.AddHeadCol("USERNAME", "", "微信用户名"); if (!string.IsNullOrEmpty(isShowAlias) && isShowAlias == "1") { tab.AddHeadCol("ALIAS", "", "微信号"); } tab.AddHeadCol("RESID", "", "客户ID"); tab.AddHeadCol("NICKNAME", "", "昵称"); tab.AddHeadCol("CONREMARK", "", "备注"); tab.AddHeadCol("CTIME", "", "创建时间"); tab.AddHeadRow(); ViewBag.gridTable = tab.GetTable() + Pagination.GetPage(pager, tableId, "5,8,10,15"); var myWorkAccountList = wx_WorkAccount_BL.GetMyWorkAccountList(UserId); List list = new List(); list.Add(new SelectListItem() { Text = "全部", Value = "" }); foreach (var workAccount in myWorkAccountList) { list.Add(new SelectListItem() { Text = workAccount.ALIAS, Value = workAccount.USERNAME }); } ViewBag.jobWxUserList = list; ViewBag.IsShowOpenOrderTip = isShowOpenOrderTip; return View(); } #endregion #region 列表 /// /// 按照条件获取数据 /// /// /// /// [HttpPost] [AuthorizeRedirect(Roles = InitRights.CONST_我的微信客户)] public JsonResult GetHtmlList(Pager pager, string resId, string userName, string alias, string conreMark, string nickName, string jobWxUser, string isopen, string columns) { ControlResource.JudgeSYQ(); string isShowAlias = cache_q.GetValue_Parameter("WeiXin_IsShowAlias");//是否显示微信号 string isShowMobileOfContent = cache_q.GetValue_Parameter(Model.Enum.Parameter.Sys_IsShowMobileOfContent); string isShowOpenOrderTip = cache_q.GetValue_Parameter(Model.Enum.Parameter.WeiXin_IsShowOpenOrderTip); string Stime = Request.Form["Stime"]; string Etime = Request.Form["Etime"]; //var list = getMyWxCustomerList(pager, resId, userName, alias, conreMark, nickName, jobWxUser, Stime, Etime); var list = _wxRcontact.GetMyWxCustomerList(pager, resId, userName, alias, conreMark, nickName, jobWxUser, Stime, Etime, UserId, isopen); Table table = new Table(columns, true); table.gridPager = pager; foreach (var model in list) { table.AddHiddenCol(model.PKID); if (!string.IsNullOrEmpty(isShowOpenOrderTip) && isShowOpenOrderTip == "1") { table.AddCol(model.IsOpen == 1 ? string.Format("{0}[已开通]", model.USERNAME) : model.USERNAME); } else { table.AddCol(model.USERNAME); } if (!string.IsNullOrEmpty(isShowAlias) && isShowAlias == "1") { table.AddCol(model.ALIAS); } //table.AddCol(model.USERNAME); var linkUrl = string.Format("{2}" , "客户详细" , "/Csvr/CustomerInfo/CustomerDetail?resid=" + model.RESID , model.RESID); table.AddCol(linkUrl); if (!string.IsNullOrEmpty(isShowMobileOfContent) && isShowMobileOfContent == "1") { table.AddCol(model.NICKNAME); table.AddCol(model.CONREMARK); } else { table.AddCol(Utility.ReplaceMobile(model.NICKNAME)); table.AddCol(Utility.ReplaceMobile(model.CONREMARK)); } table.AddCol(model.CTIME); table.AddRow(); } var json = new { totalPages = pager.totalPages, totalRows = pager.totalRows, rowsList = table.GetRows() }; return Json(json, JsonRequestBehavior.AllowGet); } #endregion #region 编辑 [HttpGet] [AuthorizeToolBar(InitRights.CONST_我的微信客户, InitToolBar.CONST_Edit)] public ActionResult Edit(string id) { WX_RCONTACT model = new WX_RCONTACT(); model = _wxRcontact.GetModel(Convert.ToDecimal(id)); return View(model); } [HttpPost] [AuthorizeToolBar(InitRights.CONST_我的微信客户, InitToolBar.CONST_Edit)] public JsonResult Edit(WX_RCONTACT model) { //定义的RESID字段,如果验证的话,手机号就通不过,下面已经有对这个字段做了验证 //if (!ModelState.IsValid) //{ // return JsonHandler.ValidateFailMessage(); //} var flag = false; model.RESID = model.RESID.Trim(); if (!string.IsNullOrWhiteSpace(model.RESID)) { int len = model.RESID.Length; if (len == 18) { if (_RES_CUSTOMER_Q.getResCustomerByResId(model.RESID) == null) { errors.Add("请填写正确的客户ID!"); return JsonHandler.UpdateMessage(errors, false); } } else { if (!Utility.ChekMobile(model.RESID) && !Utility.ValidateTelCode2(model.RESID)) { errors.Add("请填写正确的号码!"); return JsonHandler.UpdateMessage(errors, false); } string resid = WX.CRM.Common.ResUtil.CreateResId(model.RESID); if (_RES_CUSTOMER_Q.getResCustomerByResId(resid) == null) { _RES_CUSTOMER.ResgisterCustomer(model.RESID, resid, "wxres"); } model.RESID = resid; } } flag = _wxRcontact.UpdateResId(ref errors, model.PKID, model.RESID); wx_SzzyOrder_BL.UpdateCustomerWXUserNameByResId(model.RESID, model.USERNAME); return JsonHandler.UpdateMessage(errors, flag); } #endregion #region 删除 /// /// 删除数据 /// /// /// [AuthorizeToolBar(InitRights.CONST_微信客户基础信息, InitToolBar.CONST_Delete)] public JsonResult Delete(string id) { if (string.IsNullOrWhiteSpace(id)) { return JsonHandler.ManageMessage("删除失败", false); } bool result = true;// bizinfoBL.Delete(ref errors, Convert.ToDecimal(id)); return JsonHandler.DeleteMessage(errors, result); } #endregion #region 导出 //[AuthorizeToolBar(InitRights.CONST_我的微信客户, InitToolBar.CONST_Other1)] //public FileResult ListExport() //{ // string resId = Request.QueryString["resId"]; // string userName = Request.QueryString["userName"]; // string alias = Request.QueryString["alias"]; // string conreMark = Request.QueryString["conreMark"]; // string nickName = Request.QueryString["nickName"]; // string jobWxUser = Request.QueryString["jobWxUser"]; // string Stime = Request.QueryString["Stime"]; // string Etime = Request.QueryString["Etime"]; // Pager pager = new Pager() { rows = int.MaxValue, page = 1 }; // string checkedFilds = PageRequest.GetQueryString("checkedFilds"); // string checkedTitle = PageRequest.GetQueryString("checkedTitles"); // List list = getMyWxCustomerList(pager, resId, userName, alias, conreMark, nickName, jobWxUser, Stime, Etime); // return File(ExcelHelper.ExportListModelToExcel(list, "我的微信客户", 60000, checkedFilds, checkedTitle, null), "application/ms-excel", PageRequest.GetDlownLoadName("我的微信客户.xls")); //} #endregion private List getMyWxCustomerList(Pager pager, string resId, string userName, string alias, string conreMark, string nickName, string jobWxUser, string stime, string etime) { var where = PredicateExtensionses.True(); if (!string.IsNullOrWhiteSpace(resId)) { where = where.And(p => p.RESID == resId); } if (!string.IsNullOrWhiteSpace(userName)) { where = where.And(p => p.USERNAME.Contains(userName)); } if (!string.IsNullOrWhiteSpace(alias)) { where = where.And(p => p.ALIAS.Contains(alias)); } if (!string.IsNullOrWhiteSpace(conreMark)) { where = where.And(p => p.CONREMARK.Contains(conreMark)); } if (!string.IsNullOrWhiteSpace(jobWxUser)) { where = where.And(p => p.JOBWXUSERNAME == jobWxUser); } else { var myWorkAccountList = wx_WorkAccount_BL.GetMyWorkAccountList(UserId); List jobWxList = new List(); foreach (var workAccount in myWorkAccountList) { if (!string.IsNullOrWhiteSpace(workAccount.USERNAME)) { jobWxList.Add(workAccount.USERNAME); } } where = where.And(p => jobWxList.Contains(p.JOBWXUSERNAME)); } if (!string.IsNullOrWhiteSpace(stime)) { DateTime dt = Convert.ToDateTime(stime); where = where.And(p => p.CTIME >= dt); } if (!string.IsNullOrWhiteSpace(etime)) { DateTime dt = Convert.ToDateTime(etime).AddDays(1); where = where.And(p => p.CTIME < dt); } var list = _wxRcontact.GetList(where, p => p.CTIME, pager); return list as List; } } }