using Ninject; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Web.Mvc; using WX.CRM.BLL.Soft; using WX.CRM.Common; using WX.CRM.IBLL.Res; using WX.CRM.IBLL.Soft; using WX.CRM.IBLL.Util; using WX.CRM.IBLL.Wx; using WX.CRM.Model.Entity; using WX.CRM.Model.Enum; using WX.CRM.Model.MAP; using WX.CRM.WEB.ViewModel.softcustomer; using WX.CRM.WebHelper; using WX.CRM.WebHelper.UtilityModel; namespace WX.CRM.WEB.Controllers.Soft { public class Soft_CustomerController : BaseController { // // GET: /Soft_Customer/ private ValidationErrors errors = new ValidationErrors(); private ISOFT_CUSTOMER_Q customerQ; private ICACHE_Q cache_Q_bll; private ISOFT_CUSTOMER customer; private ISOFT_ALLOCATERESLOG allocatereslog; private ISOFT_USER_Q softuser_q; private ISecurityHelper sHelper; [Inject] public IWX_SZZYORDER _order { get; set; } [Inject] public IRES_RESOURCEMOBILE_Q res_ResourceMobile_BL { get; set; } public Soft_CustomerController(ICACHE_Q _cache_Q_bll, ISOFT_CUSTOMER_Q _customerQ, ISOFT_CUSTOMER _customer, ISOFT_ALLOCATERESLOG _allocatereslog, ISOFT_USER_Q _softuser_q, ISecurityHelper _sHelper) { this.cache_Q_bll = _cache_Q_bll; this.customerQ = _customerQ; this.customer = _customer; this.allocatereslog = _allocatereslog; this.softuser_q = _softuser_q; this.sHelper = _sHelper; } #region 软件客户列表首页 [AuthorizeRedirect(Roles = InitRights.CONST_软件客户列表)] public ActionResult Index() { ToolBar tb = new ToolBar(); string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.软件客户列表, userRightId); tb.AllowButton(toolbtn); tb.AddOtherButton("Other1", "导出", "icon-export", "Export_Click", true); ViewBag.ToolBar = tb; Pager gp = new Pager() { page = 1, rows = 20, order = "desc" }; Table tab = new Table("tablist"); tab.AddHeadCol("USERNAME", "", "软件用户名", true); tab.AddHeadCol("RESID", "", "客户ID"); tab.AddHeadCol("UNIONID", "", "unionID"); tab.AddHeadCol("REGCAMPAINID", "", "渠道来源"); //tab.AddHeadCol("USERNO", "", "用户卡号"); tab.AddHeadCol("REGDATE", "", "注册时间"); tab.AddHeadCol("CZ", "", "操作"); tab.AddHeadRow(); ViewBag.GroupList = tab.GetTable() + Pagination.GetPage(gp, "tablist"); //ViewBag.inneruserid = UserId; //ViewBag.userGroupId = userGroupId; //ViewBag.saleDeptId = saleDeptId; //ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId); return View(); } #endregion 软件客户列表首页 #region 软件客户列表查询 [HttpPost] [AuthorizeRedirect(Roles = InitRights.CONST_软件客户列表)] public JsonResult GetHtmlList(Pager pager, string columns, string SoftName, string ResID, DateTime? ctime1, DateTime? ctime2) { try { //var list = _soft_userQ.GetList(ref pager, SoftName, ResID, ctime1, ctime2); var list = new SOFT_USER_BL().GetList2(ref pager, SoftName, ResID, ctime1, ctime2); Table table = new Table(columns, true); table.gridPager = pager; foreach (var model in list) { table.AddCol(PhoneHelper.FormatPhoneUserName(model.USERNAME)); table.AddCol("" + model.RESID + ""); table.AddCol(model.UNIONID); table.AddCol(model.REGCAMPAINID); //table.AddCol(model.USERNO); table.AddCol(model.REGDATE); var btnStr = ""; btnStr += ""; btnStr += ""; btnStr += ""; btnStr += ""; table.AddCol(btnStr); table.AddRow(); } var json = new { totalPages = pager.totalPages, totalRows = pager.totalRows, rowsList = table.GetRows() }; return Json(json, JsonRequestBehavior.AllowGet); //LogHelper.Info("1"); //return null; } catch (Exception ex) { LogHelper.Error("Soft_UserController:" + ex.Message + ex.StackTrace); return JsonHandler.ManageMessage(ex.Message, false); } } public string GetUserStatus(int userStatus) { string status = ""; switch (userStatus) { case 1: status = "未开通"; break; case 2: status = "在用"; break; case 3: status = "过期"; break; case 4: status = "退款"; break; default: status = "未知"; break; } return status; } public string GetSoftType(int type) { string status = ""; switch (type) { case 1: status = "Level2"; break; case 2: status = "券商"; break; default: status = "未知"; break; } return status; } /// /// 获取对应渠道 /// /// /// public string GetChannel(decimal channelid) { if (channelid >= 9501 & channelid <= 9600) { return "Android手机"; } else if (channelid >= 9001 & channelid <= 9100) { return "IOS手机"; } else { return channelid.ToString(); } } /// /// 产品子类名 /// /// 产品子类代码 /// protected string GetProductName(string productCode) { //if (!string.IsNullOrEmpty(productCode)) //{ // var model = cache_Q_bll.GetSProductList().Where(p => p.PRODUCTCODE == productCode).FirstOrDefault(); // return model == null ? productCode : model.PRODUCTNAME; //} return productCode; } #endregion 软件客户列表查询 #region 软件客户主分配 /// /// 软件客户列表 /// /// [AuthorizeRedirect(Roles = InitRights.CONST_软件客户分配)] public ActionResult SaleUserAssign() { ToolBar tool = new ToolBar(); string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.软件客户分配, userRightId); tool.AllowButton(toolbtn); tool.AddOtherButton("Other1", "提交变更", "icon-flag", "Complete_Click", true); tool.AddOtherButton("Other2", "批量分配", "icon-add", "ListComplete_Click", true); ViewBag.ToolBar = tool; //table Pager gp = new Pager() { page = 1, rows = 10 }; Table tab = new Table("tablist"); tab.AddHeadCol("SOFTNAME", "", "软件用户名"); tab.AddHeadCol("RESID", "", "客户ID"); tab.AddHeadCol("SOFTTYPE", "", "软件类型"); tab.AddHeadCol("PRODUCTCODE", "", "软件产品"); tab.AddHeadCol("USERSTATUS", "", "用户状态"); tab.AddHeadCol("OPENDATE", "", "权限开通日期"); tab.AddHeadCol("ENDDATE", "", "权限截止日期"); tab.AddHeadCol("SALEUSERID", "", "现有"); tab.AddHeadCol("operation", "", "新分配"); tab.AddHeadRow(); ViewBag.GroupList = tab.GetTable() + Pagination.GetPage(gp, "tablist"); return View(); } [HttpPost] [AuthorizeRedirect(Roles = InitRights.CONST_软件客户分配)] public JsonResult GetSaleUserAssignList(Pager pager, string columns, string SoftName, string SaleEid, string ResID) { try { decimal? saleid = InnerUserHelper.Instance.GetUserIdByEid(SaleEid.GetDecimal()); List list = customerQ.GetList(ref pager, SoftName, saleid, ResID, 0, null, null, null, null, null, null); Table table = new Table(columns, true); table.gridPager = pager; int i = 1; foreach (SOFT_CUSTOMER_Extend model in list) { //table.AddCol(model.CUSTOMERID); table.AddCol(PhoneHelper.FormatPhoneUserName(model.SOFTNAME)); table.AddCol(model.RESID); table.AddCol(GetSoftType(Convert.ToInt32(model.SOFTTYPE))); table.AddCol(GetProductName(model.PRODUCTCODE)); table.AddCol(GetUserStatus(Convert.ToInt32(model.USERSTATUS))); table.AddCol(model.OPENDATE.ToUnityString(1)); table.AddCol(model.ENDDATE.ToUnityString(1)); table.AddCol(InnerUserHelper.Instance.EidAndName(model.SALEUSERID)); //tradeCode 保存的是customerid table.AddCol(string.Format("工号:", model.SALEUSERID, "Trader" + i, model.CUSTOMERID)); table.AddRow(); i++; } var json = new { totalPages = pager.totalPages, totalRows = pager.totalRows, rowsList = table.GetRows() }; return Json(json, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.Error("Soft_CustomerController_SaleUserAssign" + ex.Message + ex.StackTrace); return JsonHandler.ManageMessage(ex.Message, false); } } [AuthorizeToolBar(InitRights.CONST_软件客户分配, InitToolBar.CONST_Other1)] public ActionResult SoftCustomerSalerCommit(string trader) { List lists = new List(); if (!string.IsNullOrEmpty(trader)) { var traderlist = JsonHelper.JsonDivertToObj>(trader); foreach (var item in traderlist) { decimal eid; if (decimal.TryParse(item.newUserId, out eid)) { TraderCommit list = new TraderCommit(); decimal newUserId = InnerUserHelper.Instance.GetUserIdByEid(eid); if (newUserId > 1) { list.Id = item.Id; list.newUserId = newUserId.ToString(); list.oldUserId = item.oldUserId; list.tradeCode = item.tradeCode; lists.Add(list); } else { ModelState.AddModelError(item.Id, "工号不存在"); } } else { ModelState.AddModelError(item.Id, "工号不正确"); } } } if (ModelState.IsValid) { List log_lists = new List(); List customer_lists = new List(); string error = ""; foreach (var item in lists) { var model = customerQ.GetModel(item.tradeCode.GetDecimal(0)); if (null != model) { var allocateResLogModel = new SOFT_ALLOCATERESLOG(); allocateResLogModel.SOFTNAME = model.SOFTNAME; allocateResLogModel.RESID = model.RESID; allocateResLogModel.ALLOCATETYPE = Convert.ToDecimal(Allocatetype.手工分配); allocateResLogModel.SALESTYPE = Convert.ToDecimal(10); allocateResLogModel.ORGSALESID = Convert.ToDecimal(item.oldUserId); allocateResLogModel.NEWSALESID = Convert.ToDecimal(item.newUserId); allocateResLogModel.OPUSERID = UserId; allocateResLogModel.OPTIME = DateTime.Now; allocateResLogModel.OPREMART = "软件客户分配与变更"; log_lists.Add(allocateResLogModel); model.SALEUSERID = Convert.ToDecimal(item.newUserId); customer_lists.Add(model); } else { error += item.tradeCode + "不存在软件客户。"; } } bool log = allocatereslog.CreateList(ref errors, log_lists); if (!log) error += "_log:" + errors.Error; bool cusResult = customer.UpdateList(ref errors, customer_lists); if (!cusResult) error += "_update:" + errors.Error; if (error == "") { error = "修改成功"; } else { LogHelper.Error(error); } return JsonHandler.ManageMessage(error, true); } else { return JsonHandler.JsonResultSerialize(ModelState); } } public ActionResult GetSaleUserAssignHtmlList() { return View(); } #endregion 软件客户主分配 #region 批量分配 [HttpGet] [AuthorizeToolBar(InitRights.CONST_软件客户分配, InitToolBar.CONST_Other2)] public ActionResult ListOfSoftSalerCommit() { int count = customerQ.SoftCustomerCount(); ListSoftSalerCommit soft = new ListSoftSalerCommit(); soft.t_count = count; return View(soft); } [HttpPost] [AuthorizeToolBar(InitRights.CONST_软件客户分配, InitToolBar.CONST_Other2)] public ActionResult ListSoftSalerCommit(ListSoftSalerCommit model) { if (ModelState.IsValid) { decimal newUserId = InnerUserHelper.Instance.GetUserIdByEid(model.Eid); if (newUserId <= 1) { return JsonHandler.ManageMessage("工号不存在", false); } if (model.count.Value > model.t_count) { return JsonHandler.ManageMessage("分配数不能大于未分配总数", false); } customer.ListOfSoftSalerCommit(newUserId, UserId, model.count.Value); return JsonHandler.ManageMessage("分配成功", true); } else { return JsonHandler.ManageMessage("数据验证不通过", false); } } #endregion 批量分配 public ActionResult SoftUser_Search() { //ToolBar tb = new ToolBar(); //string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.软件客户列表, userRightId); //tb.AllowButton(toolbtn); //tb.AddOtherButton("Other1", "导出", "icon-export", "Export_Click", true); //ViewBag.ToolBar = tb; Pager gp = new Pager() { page = 1, rows = 10, order = "desc" }; Table tab = new Table("tablist"); tab.AddHeadCol("username", "", "帐号"); tab.AddHeadCol("phone", "", "手机号码"); tab.AddHeadCol("registerTime", "", "注册时间"); tab.AddHeadCol("resid", "", "操作"); tab.AddHeadRow(); ViewBag.GroupList = tab.GetTable() + Pagination.GetPage(gp, "tablist"); ViewBag.inneruserid = UserId; ViewBag.userGroupId = userGroupId; ViewBag.saleDeptId = saleDeptId; ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId); return View(); } public JsonResult SoftUser_SearchGetHtmlList(Pager pager, string columns, string phone, string username) { try { string clientid = Utility.GetSettingByKey("CRMClientKey"); List list = softuser_q.GetCanOpenRes(username, phone, ref pager); Table table = new Table(columns, true); table.gridPager = pager; foreach (SOFT_USER_MK model in list) { table.AddCol(model.username); table.AddCol(sHelper.decyptData(clientid, model.phone)); //table.AddCol(clientid,model.phone); table.AddCol(model.registerTime.ToUnityString(2)); table.AddCol("开通" + "  TD开通"); table.AddRow(); } var json = new { totalPages = pager.totalPages, totalRows = pager.totalRows, rowsList = table.GetRows() }; return Json(json, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.Error("Soft_CustomerController:" + ex.Message + ex.StackTrace); return JsonHandler.ManageMessage(ex.Message, false); } } [AuthorizeRedirect(Roles = InitRights.CONST_软件客户列表)] public FileResult Export(string SoftName, string ResID, DateTime? ctime1, DateTime? ctime2) { //decimal p_saleDeptId = Request["saleDeptId"].GetDecimal(0); //string groupId = Request["groupId"]; //decimal innerUserId = Request["userId"].GetDecimal(0); //decimal? teamEid = null; //string checkedFilds = ""; //checkedFilds = checkedFilds.Replace("[]", ""); //string checkedTitles = ""; Pager pager = new Pager() { page = 1, rows = int.MaxValue }; var list = new SOFT_USER_BL().GetList(ref pager, SoftName, ResID, ctime1, ctime2); var orderList = _order.GetList(p => p.ISOPEN == 1 && p.ARRIVALTIME >= ctime1); var data = (from a in list join b in orderList on a.RESID equals b.RESID into abTmp from ab in abTmp.DefaultIfEmpty() select new Soft_User_Export() { UserName = a.USERNAME, RegDate = a.REGDATE, ResId = a.UMID, HasOrder = ab != null ? "是" : "否", OrderId = ab != null ? (decimal?)ab.ORDERID : null, ArrivalPay = ab != null ? ab.ARRIVALPAY : null, OTime = ab != null ? ab.OTIME : null, SubProductName = ab != null ? ab.SUBPRODUCTNAME : null }).ToList(); var softExportMobile = cache_Q_bll.GetValue_Parameter("Sys_SoftExportMobile");//是否导出手机号码 if (softExportMobile == "1") { foreach (var item in data) { if (!string.IsNullOrEmpty(item.ResId)) { PhoneLogModel phoneLogModel = new PhoneLogModel { Method = System.Reflection.MethodBase.GetCurrentMethod().Name, userid = UserId }; item.Mobile = res_ResourceMobile_BL.GetNumberByResId(item.ResId, phoneLogModel); } }; } //LogHelper.Info(list.Count.ToString()); //return File(ExcelHelper.ExportListModelToExcel(data, "软件客户列表", 10000, checkedFilds, checkedTitles, DataFormart), "application/ms-excel", PageRequest.GetDlownLoadName("软件客户列表.xls")); System.IO.Stream strem = ExcelHelper.ExportListModelToExcel(data, "软件客户列表", 50000, null); return File(strem, "application/ms-excel", PageRequest.GetDlownLoadName("软件客户列表.xls")); } public string DataFormart(string key, object value) { string formartValue = string.Empty; switch (key) { default: formartValue = string.Format("{0}", value); break; } return formartValue; } public class Soft_User_Export { [DisplayName("软件用户名")] public string UserName { get; set; } [DisplayName("注册时间")] public DateTime? RegDate { get; set; } [DisplayName("客户ID")] public string ResId { get; set; } [DisplayName("手机号码")] public string Mobile { get; set; } //public string RegCampainId { get; set; } [DisplayName("是否订单")] public string HasOrder { get; set; } [DisplayName("订单ID")] public decimal? OrderId { get; set; } [DisplayName("支付金额")] public decimal? ArrivalPay { get; set; } [DisplayName("开通时间")] public DateTime? OTime { get; set; } [DisplayName("产品名称")] public string SubProductName { get; set; } } } }