TG.WXCRM.V4/WEB/Controllers/WeiXin/DealCustomerController.cs

266 lines
11 KiB
C#

using Ninject;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using WX.CRM.BLL.Base;
using WX.CRM.BLL.Wx;
using WX.CRM.Common;
using WX.CRM.IBLL.Base;
using WX.CRM.IBLL.Util;
using WX.CRM.IBLL.Wx;
using WX.CRM.Model.DTO;
using WX.CRM.Model.Entity;
using WX.CRM.Model.MAP;
using WX.CRM.WebHelper;
using static WX.CRM.WEB.Controllers.WeiXin.JZOrderController;
using static WX.CRM.WebHelper.ExcelHelper;
namespace WX.CRM.WEB.Controllers.WeiXin
{
public class DealCustomerController : BaseController
{
private readonly IWX_DealCustomer _wx_dealCustomer;
public IWX_SZZYMIDPRODUCT _midProduct { get; set; }
[Inject]
public ICACHE_Q _CacheQ { get; set; }
[Inject]
public IBAS_BUSINESSLINE_Q _BAS_BUSINESSLINE_Q { get; set; }
[Inject]
public IBAS_INNERGROUP_Q _BAS_INNERGROUP_Q { get; set; }
public DealCustomerController(IWX_DealCustomer wX_DealCustomer, ICACHE_Q cacheQ, IWX_SZZYMIDPRODUCT midProduct, IBAS_BUSINESSLINE_Q BAS_BUSINESSLINE_Q, IBAS_INNERGROUP_Q BAS_INNERGROUP_Q) {
this._wx_dealCustomer = wX_DealCustomer;
this._CacheQ = cacheQ;
this._midProduct = midProduct;
this._BAS_BUSINESSLINE_Q = BAS_BUSINESSLINE_Q;
this._BAS_INNERGROUP_Q = BAS_INNERGROUP_Q;
}
[HttpGet]
[AuthorizeRedirect(Roles = InitRights.CONST_成交客户跟进列表)]
public ActionResult List(DealCustomerDto dto)
{
IList<DealCustomerItem> dataList= new List<DealCustomerItem>();
string tableId = "tablist";
Table tab = new Table(tableId);
tab.isFloatHead = true;
Pager pager = new Pager() { page = 1, rows = 30 };
// tab.AddHeadCol("szzyorderid", "", "szzyorderid", true);
tab.AddHeadCol("umid", "", "客户ID");
tab.AddHeadCol("name", "", "客户姓名");
tab.AddHeadCol("nickname", "", "企微昵称");
tab.AddHeadCol("amount_type", "", "资金量");
tab.AddHeadCol("overdateName", "", "在期状态");
tab.AddHeadCol("enddate", "", "过期时间", true);
tab.AddHeadCol("subproductname", "", "最新订单产品");
tab.AddHeadCol("arrivalpay", "", "订单金额", true);
tab.AddHeadCol("sumarrivalpay", "", "累计金额", true);
tab.AddHeadCol("share_dept_name", "", "成交事业部");
tab.AddHeadCol("share_group_name", "", "成交组别");
tab.AddHeadCol("share_eid_name", "", "成交客服");
tab.AddHeadCol("last_follow_deptid", "", "最后跟进事业部");
tab.AddHeadCol("last_follow_groupid", "", "最后跟进组别");
tab.AddHeadCol("last_follow_eid", "", "最后跟进客服");
tab.AddHeadCol("is_follow", "", "跟进类型");
tab.AddHeadCol("last_follow_time", "", "最后跟进时间", true);
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "30,50,1000");
var deptList = _CacheQ.GetList_BusinessLines();
var selectList = new List<SelectListItem>();
foreach (var item in deptList)
{
selectList.Add(new SelectListItem() { Text = item.BUSINESSNAME, Value = item.BUSINESSID.ToString() });
}
ViewBag.DeptList = selectList;
ViewBag.midproductList = GetMidProductList();
return View();
//dataList =
//ViewBag.dataList = dataList;
//return View(dto);
}
public JsonResult QueryList(QueryUserComboDto usercomboDto,DealCustomerDto dto, Pager pager,string columns) {
try
{
var BusinessLine = _BAS_BUSINESSLINE_Q.GetBusinessLineByRoot(UserId);
if (BusinessLine.Any())
{
dto.order_share_deptids = string.Join(",", BusinessLine.Select(m => m.BUSINESSID));
}
List<string> newProductid = new List<string>();
foreach (var item in dto.subproductids.Split(','))
{
if (item == "0"|| string.IsNullOrEmpty(item) ) continue;
newProductid.Add(item);
}
dto.subproductids = string.Join(",", newProductid);
if (usercomboDto.eid.HasValue && usercomboDto.eid != 0)
{
dto.order_share_eids = usercomboDto.eid.ToString();
}
else if(!string.IsNullOrEmpty(usercomboDto.groupIds)) {
var innerGup = _BAS_INNERGROUP_Q.GetModel_InnerGroup(Convert.ToDecimal(usercomboDto.groupIds));
dto.order_share_groupids= innerGup?.DEPARTMENT_ID.ToString();
}
//
var list = _wx_dealCustomer.GetDealCustomerList(dto, pager);
Table table = new Table(columns, true);
table.gridPager = pager;
foreach (var item in list)
{
var linkUrl = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>"
, "客户详细"
, "/Csvr/CustomerInfo/CustomerDetail?resid=" + item.umid
, item.umid);
table.AddCol($"{linkUrl}");
table.AddCol($"{item.name}");
table.AddCol($"{item.nickname}");
table.AddCol($"{item.amount_type}");
table.AddCol($"{item.overdateName}");
table.AddCol($"{item.enddate}");
table.AddCol($"{item.subproductname}");
table.AddCol($"{item.arrivalpay}");
table.AddCol($"{item.sumarrivalpay}");
table.AddCol($"{item.share_dept_name}");
table.AddCol($"{item.share_group_name}");
table.AddCol($"{item.share_eid_name}");
table.AddCol($"{item.last_follow_dept_name}");
table.AddCol($"{item.last_follow_group_name}");
table.AddCol($"{item.last_follow_employee_name}");
if (item.follow_type == "10") {
table.AddCol($"坐席电话");
} else if (item.follow_type == "20") {
table.AddCol($"微信互动");
}
else
{
table.AddCol($"{item.follow_type}");
}
table.AddCol($"{item.last_follow_time}");
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows(),
foot = table.GetFoot()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("DealCustomerController:QueryList" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
/// <summary>
/// 汇总
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
public JsonResult DealStat(DealCustomerDto dto) {
try
{
var BusinessLine = _BAS_BUSINESSLINE_Q.GetBusinessLineByRoot(UserId);
if (BusinessLine.Any())
{
dto.order_share_deptids = string.Join(",", BusinessLine.Select(m => m.BUSINESSID));
}
var res = _wx_dealCustomer.GetDealCustomerStat(dto);
return Json(new { s=true,d= res }, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("DealCustomerController:DealStat" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
[AuthorizeRedirect(Roles = InitRights.CONST_订单列表)]
public FileResult Export(DealCustomerDto dto, QueryUserComboDto usercomboDto)
{
string checkedFilds = PageRequest.GetQueryString("checkedFilds");
checkedFilds = checkedFilds.Replace("[]", "");
string checkedTitles = PageRequest.GetQueryString("checkedTitles");
Pager pager = new Pager() { page = 1, rows = int.MaxValue };
var BusinessLine = _BAS_BUSINESSLINE_Q.GetBusinessLineByRoot(UserId);
if (BusinessLine.Any())
{
dto.order_share_deptids = string.Join(",", BusinessLine.Select(m => m.BUSINESSID));
}
List<string> newProductid = new List<string>();
foreach (var item in dto.subproductids.Split(','))
{
if (item == "0" || string.IsNullOrEmpty(item)) continue;
newProductid.Add(item);
}
dto.subproductids = string.Join(",", newProductid);
if (usercomboDto.eid.HasValue && usercomboDto.eid != 0)
{
dto.order_share_eids = usercomboDto.eid.ToString();
}
else if (!string.IsNullOrEmpty(usercomboDto.groupIds))
{
var innerGup = _BAS_INNERGROUP_Q.GetModel_InnerGroup(Convert.ToDecimal(usercomboDto.groupIds));
dto.order_share_groupids = innerGup?.DEPARTMENT_ID.ToString();
}
var list = _wx_dealCustomer.GetDealCustomerList(dto, pager);
//var data = new List<WX_SZZYORDER_EXPORT>();
//foreach (var item in list)
//{
//}
return File(ExcelHelper.ExportListModelToExcel<DealCustomerItem>(list.ToList(), "成交客户跟进列表", 50000, checkedFilds, checkedTitles, DataFormart)
, "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;
}
private List<SelectListItem> GetMidProductList()
{
var data = new List<SelectListItem>();
var list = _midProduct.GetList();
foreach (var item in list)
{
data.Add(new SelectListItem() { Text = item.MIDPRODUCTNAME, Value = item.MIDPRODUCTID.ToString() });
}
return data;
}
}
}