using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web.Mvc; using WX.CRM.Common; using WX.CRM.IBLL.Ord; using WX.CRM.IBLL.Res; using WX.CRM.IBLL.Util; using WX.CRM.Model.Entity; using WX.CRM.Model.Enum; using WX.CRM.Model.MAP; using WX.CRM.WebHelper; namespace WX.CRM.WEB.Controllers.Res { public class ResourceEffectAnalysisController : BaseController { #region 初始化 IORD_MEMOTYPE_Q memoTypeBll; ICACHE_Q cacheBll; IRES_CUSTOMER_Q cusBll; IRES_RESOURCETYPE_Q resourceTypeBiz_Q; IRES_ACTIVITY_Q activeBiz_Q; private IORD_MEMOSUBTYPE_Q memoSubTypeBll; public ResourceEffectAnalysisController(IORD_MEMOTYPE_Q _memoTypeBll, ICACHE_Q _cacheBll, IRES_CUSTOMER_Q _cusBll, IRES_RESOURCETYPE_Q _resourceTypeBiz_Q, IRES_ACTIVITY_Q _activeBiz_Q, IORD_MEMOSUBTYPE_Q _memosubtypeQ) { this.memoTypeBll = _memoTypeBll; this.cacheBll = _cacheBll; this.cusBll = _cusBll; this.resourceTypeBiz_Q = _resourceTypeBiz_Q; this.activeBiz_Q = _activeBiz_Q; this.memoSubTypeBll = _memosubtypeQ; } ValidationErrors errors = new ValidationErrors(); #endregion [AuthorizeRedirect(Roles = InitRights.CONST_资源效果分析)] public ActionResult Index() { ToolBar tool = new ToolBar(); string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.资源效果分析, userRightId); tool.AllowButton(toolbtn); tool.AddOtherButton("Other1", "导出", "icon-export", "ExportAllPage_Click1", true); ViewBag.ToolBar = tool; Pager pg = new Pager() { page = 1, rows = 10, order = "desc", sort = "restypename" }; Table tb = new Table("tablist"); //tb.AddHiddenHeadCol("资源类型", "资源类型ID"); tb.AddHeadCol("restypename", "", "资源类型", true); tb.AddHeadCol("activityname", "", "活动名称", true); tb.AddHeadCol("regNumber", "", "注册数", true); tb.AddHeadCol("resNumber", "", "资源总数", true); string paraValue = cacheBll.GetValue_Parameter(Parameter.Res_EffectAnalysis_01); string[] str = paraValue.Split('#'); //工单大类 //for (int i = 0; i < str.Length; i++) //{ // ORD_MEMOTYPE model = memoTypeBll.GetModel_MemoType(Convert.ToDecimal(str[i])); // if (model != null) // tb.AddHeadCol(model.TYPEID.ToString(), "", model.TYPENAME, true); //} //工单小类 for (int i = 0; i < str.Length; i++) { ORD_MEMOSUBTYPE model = cacheBll.GetList_MemoSubType().Where(m => m.SUBTYPEID == Convert.ToDecimal(str[i])).FirstOrDefault(); if (model != null) tb.AddHeadCol(model.SUBTYPEID.ToString(), "", model.TYPENAME, true); } //tb.AddHeadCol("180", "", "已开户", true); //tb.AddHeadCol("200", "", "已签约", true); //tb.AddHeadCol("220", "", "已激活", true); tb.AddHeadCol("orderList", "", "订单详情"); tb.AddHeadRow(); ViewBag.GroupList = tb.GetHead() + Pagination.GetPage(pg, "tablist", "5,8,10,15"); List lis = new List(); var rlis = resourceTypeBiz_Q.GetList(); lis.Add(new SelectListItem() { Value = "0", Text = "-请选择-" }); foreach (var obj in rlis) { lis.Add(new SelectListItem() { Value = string.Format("{0}", obj.RESTYPEID), Text = obj.TYPENAME }); } ViewData["slt_ResourctType"] = lis; ViewBag.inneruserid = UserId; ViewBag.userGroupId = userGroupId; ViewBag.saleDeptId = saleDeptId; ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId); return View(); } #region 查询 [AuthorizeRedirect(Roles = InitRights.CONST_资源效果分析)] [HttpPost] public JsonResult GetHtmlList(Pager pg, string columns, QueryUserComboDto usercomboDto) { string stime = Request.Form["STime"]; string etime = Request.Form["ETime"]; decimal restypeId = Request.Form["ResourctType"].GetDecimal(0); decimal activityId = Request.Form["activityId"].GetDecimal(0); //string groupId = Request["groupId"]; //string inneruserid = Request["userId"]; DateTime? sd1 = null; DateTime? ed1 = null; try { if (!string.IsNullOrEmpty(stime)) sd1 = DateTime.Parse(stime); if (!string.IsNullOrEmpty(etime)) ed1 = DateTime.Parse(etime).AddDays(1); if (pg.sort != "restypename" && pg.sort != "resNumber" && pg.sort != "activityname" && pg.sort != "null" && pg.sort != null) { pg.sort = "'" + pg.sort + "'"; } DataTable dt = cusBll.Res_ResourceEffectAnalysis(ref pg, sd1, ed1, restypeId, activityId, usercomboDto); Table tb = new Table(columns, true); tb.gridPager = pg; string[] cols = columns.Split(','); foreach (DataRow dr in dt.Rows) { foreach (var everyCol in cols) { string str = ""; if (everyCol == "restypename" || everyCol == "resNumber" || everyCol == "activityname" || everyCol == "regNumber") str = everyCol; else str = "'" + everyCol + "'"; if (everyCol != "orderList") { tb.AddCol(dr[str]); } else { var linkUrl = string.Format("{2}" , "订单列表" , "/Res/ResourceEffectAnalysis/OrderList?sd1=" + sd1 + "&sd2=" + ed1 + "&restypeId=" + dr["restypeid"] + " &activityId=" + dr["activityid"] + " & groupId=" + usercomboDto.groupIds + "&inneruserId=" + usercomboDto.userId , "订单列表"); tb.AddCol(linkUrl); } } tb.AddRow(); } var json = new { totalPages = pg.totalPages, totalRows = pg.totalRows, rowsList = tb.GetRows(), foot = tb.GetFoot() }; return Json(json, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.Error("ResourceEffectAnalysisController:" + ex.Message + ex.StackTrace); return JsonHandler.ManageMessage(ex.ToString(), false); } } #endregion public void Export(QueryUserComboDto usercomboDto) { string stime = Request.QueryString["STime"]; string etime = Request.QueryString["ETime"]; decimal restypeId = Request.QueryString["ResourctType"].GetDecimal(0); decimal activityId = Request.QueryString["activityId"].GetDecimal(0); string groupId = Request["groupId"]; string inneruserid = Request["userId"]; DateTime? sd1 = null; DateTime? ed1 = null; if (!string.IsNullOrEmpty(stime)) sd1 = DateTime.Parse(stime); if (!string.IsNullOrEmpty(etime)) ed1 = DateTime.Parse(etime).AddDays(1); Pager pg = new Pager() { rows = int.MaxValue, page = 1, order = "desc", sort = "restypename" }; DataTable dt = cusBll.Res_ResourceEffectAnalysis(ref pg, sd1, ed1, restypeId, activityId, usercomboDto); foreach (DataColumn dc in dt.Columns) { if (dc.ColumnName == "RESTYPEID") dc.ColumnName = "资源类型ID"; else if (dc.ColumnName == "RESTYPENAME") dc.ColumnName = "资源类型"; else if (dc.ColumnName == "ACTIVITYID") dc.ColumnName = "活动类型ID"; else if (dc.ColumnName == "ACTIVITYNAME") dc.ColumnName = "活动类型名称"; else if (dc.ColumnName == "RESNUMBER") dc.ColumnName = "资源总数"; else if (dc.ColumnName == "RNO") dc.ColumnName = "行号"; //else if (dc.ColumnName.Contains("180")) // dc.ColumnName = "已开户"; //else if (dc.ColumnName.Contains("200")) // dc.ColumnName = "已签约"; //else if (dc.ColumnName.Contains("220")) // dc.ColumnName = "已激活"; else { //dc.ColumnName=memoTypeBll.GetModel(Convert.ToDecimal(dc.ColumnName.Trim().Replace("'",""))).TYPENAME; dc.ColumnName = memoSubTypeBll.GetModel(Convert.ToDecimal(dc.ColumnName.Trim().Replace("'", ""))).TYPENAME; } } ExcelHelper.ExportDataTableToExcel(dt, "资源效果分析.xls", "资源效果分析"); } public ActionResult OrderList() { //table string tableId = "tablist"; Table tab = new Table(tableId); tab.AddHeadCol("RESID", "", "客户ID"); tab.AddHeadCol("INNERUSERID", "", "工号"); tab.AddHeadCol("SUBPRODUCTNAME", "", "产品"); tab.AddHeadCol("NEEDPAY", "", "应付金额"); tab.AddHeadCol("FINALPAY", "", "实付金额"); tab.AddHeadCol("ARRIVALPAY", "", "到账金额"); tab.AddHeadCol("ARRIVALTIME", "", "到账时间"); tab.AddHeadCol("SZZYORDERID", "", "订单ID"); tab.AddHeadCol("CNAME", "", "客户姓名"); tab.AddHeadCol("ORDERTYPE", "", "订单类型"); tab.AddHeadCol("ORDERSTATUS", "", "订单状态"); tab.AddHeadCol("CTIME", "", "下单时间"); tab.AddHeadCol("OTIME", "", "开通时间"); tab.AddHeadCol("SOURCE", "", "客户来源"); tab.AddHeadCol("CUSTOMERUSERNAME", "", "客户微信用户名"); tab.AddHeadRow(); ViewBag.gridTable = tab.GetHead(); return View(); } public JsonResult GetOrderList(DateTime? sd1, DateTime? sd2, decimal restypeId, decimal activityId, string groupId, string inneruserId, string columns) { DataTable dt = cusBll.Res_ResourceOrderList(sd1, sd2, restypeId, activityId, groupId, inneruserId); Table table = new Table(columns, true); if (dt != null) { foreach (DataRow item in dt.Rows) { var linkUrl = string.Format("{2}" , "客户详细" , "/Csvr/CustomerInfo/CustomerDetail?resid=" + item["RESID"] , item["RESID"]); table.AddCol(linkUrl); table.AddCol(InnerUserHelper.Instance.GetEid(Convert.ToDecimal(item["INNERUSERID"]))); table.AddCol(item["SUBPRODUCTNAME"]); table.AddCol(item["NEEDPAY"]); table.AddCol(item["FINALPAY"]); table.AddCol(item["ARRIVALPAY"]); table.AddCol(item["ARRIVALTIME"]); table.AddCol(item["SZZYORDERID"]); table.AddCol(item["CNAME"]); table.AddCol(getOrderTypeStr(Convert.ToDecimal(item["ORDERTYPE"]))); table.AddCol(getOrderStatusStr(item["ORDERSTATUS"].ToString())); table.AddCol(item["CTIME"]); table.AddCol(item["OTIME"]); table.AddCol(Utility.getSourceText(item["SOURCE"].ToString())); table.AddCol(item["CUSTOMERUSERNAME"]); table.AddRow(); } } var json = new { rowsList = table.GetRows() }; return Json(json, JsonRequestBehavior.AllowGet); } #region 活动 public ActionResult ActiveList(decimal? id) { var lis = activeBiz_Q.GetList(id.GetValueOrDefault(0)); if (Request.IsAjaxRequest()) { return Json(lis, JsonRequestBehavior.AllowGet); } else { return View(""); } } #endregion private string getOrderTypeStr(decimal orderType) { if (orderType == 1) { return "普通订单"; } else if (orderType == 2) { return "续费订单"; } else if (orderType == 3) { return "升级订单"; } else { return ""; } } private string getOrderStatusStr(string orderStatus) { if (orderStatus == "0") { return string.Format("下单失败"); } else if (orderStatus == "1") { return "未开通"; } else if (orderStatus == "2") { return "部分支付"; } else if (orderStatus == "3") { return "已支付"; } else if (orderStatus == "4") { return "已开通"; } else if (orderStatus == "5") { return "已到期"; } else if (orderStatus == "6") { return "已升级"; } else if (orderStatus == "7") { return "已退款"; } else if (orderStatus == "8") { return "已取消"; } else if (orderStatus == "9") { return "已关闭"; } else if (orderStatus == "10") { return "隐藏"; } else { return ""; } } } }