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

941 lines
36 KiB
C#

using Ninject;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web.Mvc;
using WX.CRM.BLL;
using WX.CRM.BLL.Util;
using WX.CRM.Common;
using WX.CRM.IBLL.Base;
using WX.CRM.IBLL.Res;
using WX.CRM.IBLL.WeWork;
using WX.CRM.IBLL.Ww;
using WX.CRM.IBLL.Wx;
using WX.CRM.Model.Entity;
using WX.CRM.Model.Ww;
using WX.CRM.WebHelper;
namespace WX.CRM.WEB.Controllers.WeiXin
{
public class SzzyOrderController : BaseController
{
private IWX_SZZYORDER wx_SzzyOrder_BL;
private IWX_SZZYPRODUCT wx_SzzyProduct_BL;
private IWX_SZZYSUBPRODUCT wx_SzzySubProduct_BL;
private IRES_CUSTOMERDETAIL res_CustomerDetail_BL;
private IRES_CUSTOMER_Q res_Customer_Q_BL;
private IRES_CUSTOMER res_Customer_BL;
[Inject]
public IWw_huser _iww_hhuser_service { get; set; }
[Inject]
public CACHE_BL cache_BL { get; set; }
[Inject]
public IWX_RCONTACT wx_Rcontact_BL { get; set; }
[Inject]
public IWX_ARRIVALPAYLOG wx_ArrivalPayLog_BL { get; set; }
[Inject]
public IBAS_SALESDEPARTMENT_Q bas_SalesDept_Q_BL { get; set; }
[Inject]
public IWEWORK_RCONTACT _weworkRcontact { get; set; }
[Inject]
public IWW_EXTUSER _wwExtUser { get; set; }
[Inject]
public IWw_huser ww_huser_bl { get; set; }
[Inject]
public IWX_SZZYMIDPRODUCT _midProduct { get; set; }
private ValidationErrors errors = new ValidationErrors();
public SzzyOrderController(IWX_SZZYORDER wx_SzzyOrder_BL, IWX_SZZYPRODUCT wx_SzzyProduct_BL, IWX_SZZYSUBPRODUCT wx_SzzySubProduct_BL, IRES_CUSTOMERDETAIL res_CustomerDetail_BL, IRES_CUSTOMER_Q res_Customer_Q_BL, IRES_CUSTOMER res_Customer_BL)
{
this.wx_SzzyOrder_BL = wx_SzzyOrder_BL;
this.wx_SzzyProduct_BL = wx_SzzyProduct_BL;
this.wx_SzzySubProduct_BL = wx_SzzySubProduct_BL;
this.res_CustomerDetail_BL = res_CustomerDetail_BL;
this.res_Customer_Q_BL = res_Customer_Q_BL;
this.res_Customer_BL = res_Customer_BL;
}
[AuthorizeRedirect(Roles = InitRights.CONST_我的订单)]
public ActionResult RContactIndex()
{
//ToolBar
ToolBar tool = new ToolBar();
ViewBag.ToolBar = tool;
//table
Pager pager = new Pager() { page = 1, rows = 15 };
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("USERNAME", "", "微信用户名");
//tab.AddHeadCol("ALIAS", "", "微信号");
tab.AddHeadCol("NICKNAME", "", "昵称");
tab.AddHeadCol("CONREMARK", "", "备注");
tab.AddHeadCol("", "8%", "");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "5,10,15,20");
ViewBag.eid = Request["eid"];
ViewBag.orderId = Request["orderid"];
var userNameRequired = cache_BL.GetValue_Parameter(Model.Enum.Parameter.WeiXin_OrderUserNameRequired);
if (string.IsNullOrWhiteSpace(userNameRequired) || userNameRequired == "1")
{
ViewBag.userNameRequired = 1;
}
else
{
ViewBag.userNameRequired = 0;
}
if (userRoleCodes.IndexOf("[ZJZL]") > -1 || userRoleCodes.IndexOf("[GLY]") > -1 || userRoleCodes.IndexOf("[BDSY]") > -1)
{
ViewBag.showSearchEid = 1;
}
return View();
}
[HttpPost]
[AuthorizeRedirect(Roles = InitRights.CONST_我的订单)]
public JsonResult GetRcontactHtmlList(Pager pager, string alias, string nickName, string conRemark, string eid, string orderId, string searchEid, string columns)
{
decimal? innerUserId = null;
bool canSearchAll = false;
if (userRoleCodes.IndexOf("[ZJZL]") > -1 || userRoleCodes.IndexOf("[GLY]") > -1 || userRoleCodes.IndexOf("[BDSY]") > -1)
{
canSearchAll = true;
}
if (!string.IsNullOrWhiteSpace(searchEid))
{
decimal decEid = Convert.ToDecimal(searchEid);
innerUserId = InnerUserHelper.Instance.GetUserIdByEid(decEid);
}
else
{
if (canSearchAll == false && !string.IsNullOrWhiteSpace(eid))
{
decimal decEid = Convert.ToDecimal(eid);
innerUserId = InnerUserHelper.Instance.GetUserIdByEid(decEid);
}
}
decimal? oId = null;
if (!string.IsNullOrEmpty(orderId))
{
decimal tId = 0;
decimal.TryParse(orderId, out tId);
oId = tId;
}
string isShowMobileOfContent = cache_BL.GetValue_Parameter(Model.Enum.Parameter.Sys_IsShowMobileOfContent);
List<WX_RCONTACT> list = wx_Rcontact_BL.GetMyList(ref pager, null, null, alias, conRemark, nickName, null, null, null, innerUserId, canSearchAll, oId);
Table table = new Table(columns, true);
table.gridPager = pager;
foreach (var model in list)
{
table.AddCol(model.USERNAME);
//table.AddCol(model.ALIAS);
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));
}
var payInfoUrl = string.Format("<a href=\"javascript:selectCustomerWx('{0}')\">选择</a>", model.USERNAME);
table.AddCol(payInfoUrl);
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
[HttpGet]
public ActionResult WeWorkRcontact()
{
Pager pager = new Pager() { page = 1, rows = 10 };
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("NAME", "", "姓名");
tab.AddHeadCol("COMPANYREMARK", "", "备注企业信息");
tab.AddHeadCol("REMARKPHONE", "", "备注号码");
tab.AddHeadCol("REALREMARK", "", "备注名称");
tab.AddHeadCol("REMARKS", "", "备注描述");
tab.AddHeadCol("action", "8%", "选择");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "10,20,50");
//ViewBag.eid = Request["eid"];
//ViewBag.orderId = Request["orderid"];
return View();
}
[HttpPost]
public JsonResult WeWorkRcontact(Pager pager, string columns, string name, string companyremark, string remarkphone, string realremark, string remarks)
{
var where = PredicateExtensionses.True<WEWORK_RCONTACT>();
if (!string.IsNullOrEmpty(name))
{
where = where.And(p => p.NAME == name);
}
if (!string.IsNullOrEmpty(companyremark))
{
where = where.And(p => p.COMPANYREMARK.Contains(companyremark));
}
if (!string.IsNullOrEmpty(remarkphone))
{
where = where.And(p => p.REMARKPHONE.Contains(remarkphone));
}
if (!string.IsNullOrEmpty(realremark))
{
where = where.And(p => p.REALREMARK.Contains(realremark));
}
if (!string.IsNullOrEmpty(remarks))
{
where = where.And(p => p.REMARKS.Contains(remarks));
}
var data = _weworkRcontact.GetList(where, p => p.CTIME, pager);
Table table = new Table(columns, true);
var remoteIds = data.Select(p => p.REMOTEID);
var extuserList = _wwExtUser.GetList(p => remoteIds.Contains(p.REMOTEID));
foreach (var item in data)
{
var extuser = extuserList.FirstOrDefault(p => p.REMOTEID == item.REMOTEID);
var userId = string.Empty;
if (extuser != null)
{
userId = extuser.USERID;
}
table.AddCol(item.NAME);
table.AddCol(Utility.ReplaceMobile(item.COMPANYREMARK));
table.AddCol(Utility.ReplaceMobile(item.REMARKPHONE));
table.AddCol(Utility.ReplaceMobile(item.REALREMARK));
table.AddCol(Utility.ReplaceMobile(item.REMARKS));
table.AddCol(string.Format("<a href=\"javascript:SelectCustomerQw('{0}','{1}')\">选择</a>", item.REMOTEID, userId));
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
[HttpGet]
public ActionResult WwExtuser()
{
Pager pager = new Pager() { page = 1, rows = 10 };
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("NAME", "", "姓名");
tab.AddHeadCol("AVATAR", "", "头像");
tab.AddHeadCol("action", "8%", "选择");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "10,20,50");
return View();
}
[HttpPost]
public JsonResult WwExtuser(Pager pager, string columns, string name)
{
//var where = PredicateExtensionses.True<WW_EXTUSER>();
//if (!string.IsNullOrEmpty(name))
//{
// where = where.And(p => p.NAME.Contains(name) || p.EXINFO.Contains(name));
//}
//var data = _wwExtUser.GetList(where, p => p.CTIME, pager);
string companycode = companyCode;
List<Ww_Corp> list = _iww_hhuser_service.Corp_Get();
if (!string.IsNullOrEmpty(companycode))
{
string companycodeFormat = string.Format("[{0}]", companycode);
list = list.Where(m => m.companycode.Contains(companycodeFormat)).ToList();
}
string ss = string.Join("','", list.Select(m => m.corpid));
if (!string.IsNullOrWhiteSpace(ss))
{
ss = "'" + ss + "'";
}
var data = ww_huser_bl.GeExtUsertList(ss, name, ref pager);
Table table = new Table(columns, true);
foreach (var item in data)
{
table.AddCol(item.name);
table.AddCol(string.Format("<img src='{0}' width='40' />", item.avatar));
table.AddCol(string.Format("<a href=\"javascript:SelectCustomerWw('{0}')\">选择</a>", item.userid));
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
#region
[AuthorizeRedirect(Roles = InitRights.CONST_订单统计)]
public ActionResult CountOrder()
{
//ToolBar
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AllowButton(toolbtn);
ViewBag.ToolBar = tool;
ViewBag.subProductList = getConfigSubProductList();
return View();
}
public JsonResult GetCountOrderHtml(string stime, string etime)
{
//string temp = "<tr>" +
//"<td>{0}</td>" +
//"<td>{1}</td>" +
//"<td>{2}</td>" +
//"{3}" +
//"<td>" +
// "<table width = \"100%\" >" +
// "<tr>" +
// "<td>成单</td>" +
// "<td>金额</td>" +
// "</tr>" +
// "<tr>" +
// "<td>{4}</td>" +
// "<td>{5}</td>" +
// "</tr>" +
// "</table >" +
// "</td>" +
// "<td>{6}</td><td>{7}</td>" +
// "</tr>";
string temp = "<tr>" +
"<td>{0}</td>" +
"<td>{1}</td>" +
"{2}" +
"</tr>";
var deptCode = Utility.GetSettingOrNullByKey("DataClientCode");
var ds = wx_SzzyOrder_BL.CountSzzyOrder(stime, etime);
//var totalNum = 0;
var totalOpenNum = 0;
decimal totalOpenMoney = 0;
//decimal inMoney = 0, outMoney = 0;
//if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
//{
// totalNum = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
//}
if (ds != null && ds.Tables[1] != null && ds.Tables[1].Rows.Count > 0)
{
totalOpenNum = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
totalOpenMoney = Convert.ToDecimal(ds.Tables[1].Rows[0][2]);
}
//ViewBag.totalNum = totalNum;
//ViewBag.totalOpenNum = totalOpenNum;
//ViewBag.totalOpenMoney = totalOpenMoney;
//var otherCountNum = "0";
//var otherCountMoney = "0";
DataTable dt = new DataTable();
if (ds != null && ds.Tables[2] != null && ds.Tables[2].Rows.Count > 0)
{
dt = ds.Tables[2];
}
DataTable dt3 = new DataTable();
if (ds != null && ds.Tables[3] != null && ds.Tables[3].Rows.Count > 0)
{
dt3 = ds.Tables[3];
}
var dt4 = new DataTable();
if (ds != null && ds.Tables[4] != null && ds.Tables[4].Rows.Count > 0)
{
dt4 = ds.Tables[4];
}
var dt5 = new DataTable();
if (ds != null && ds.Tables[5] != null && ds.Tables[5].Rows.Count > 0)
{
dt5 = ds.Tables[5];
}
var configSubProcutOrderStr = getSubProdutOrderCount(dt, totalOpenNum, totalOpenMoney);
var res = string.Format(temp, totalOpenNum, totalOpenMoney, configSubProcutOrderStr);
//var res = string.Format(temp, totalOpenNum, totalOpenMoney, configSubProcutOrderStr, otherCountNum, otherCountMoney, inMoney, outMoney);
var isShowPrice = cache_BL.GetValue_Parameter("OrderStatisticsShowPrice");
string tableId = "tablist2";
Table tab = new Table(tableId);
var x = 1;
tab.AddHeadCol("SubProductName", "", "产品", "sortTable('tablist2'," + x + ",'string');", true);
x++;
//tab.AddHeadCol("ProductCountNum", "", "下单数");
tab.AddHeadCol("CountNum", "", "成交单数", "sortTable('tablist2'," + x + ",'float');", true);
x++;
if (isShowPrice != null && isShowPrice == "true")
{
tab.AddHeadCol("NeedPay", "", "产品金额", "sortTable('tablist2'," + x + ",'float');", true);
x++;
}
tab.AddHeadCol("NumRate", "", "成交单数占比(%)", "sortTable('tablist2'," + x + ",'float');", true);
x++;
tab.AddHeadCol("TotalFinalPay", "", "成交金额", "sortTable('tablist2'," + x + ",'float');", true, true);
x++;
tab.AddHeadCol("MoneyRate", "", "成交金额占比(%)", "sortTable('tablist2'," + x + ",'float');", true);
if (deptCode == "SHZZ")
{
tab.AddHeadCol("InMoney", "", "分入金额");
tab.AddHeadCol("OutMoney", "", "分出金额");
}
tab.AddHeadRow();
var list = dt3.ToList<SubProdutCount>();
var inList = dt4.ToList<InOutMoneyDto>();
var outList = dt5.ToList<InOutMoneyDto>();
//var list1 = dt1.ToList<SubProdutCount>();
var data = new List<SubProdutCount>();
foreach (var item in list)
{
data.Add(new SubProdutCount() { SubProductId = item.SubProductId, SubProductName = item.SubProductName, CountNum = item.CountNum, NumRate = item.NumRate, TotalFinalPay = item.TotalFinalPay, MoneyRate = item.MoneyRate });
}
var exceptArr = inList.Select(p => p.SubProductId).Except(list.Select(p => p.SubProductId));
if (exceptArr.Any())
{
foreach (var item in exceptArr)
{
data.Add(new SubProdutCount() { SubProductId = item, SubProductName = inList.Single(p => p.SubProductId == item).SubProductName, CountNum = 0, NumRate = 0, TotalFinalPay = 0, MoneyRate = 0 });
}
}
var exceptArr2 = outList.Select(p => p.SubProductId).Except(list.Select(p => p.SubProductId));
if (exceptArr2.Any())
{
foreach (var item in exceptArr2)
{
data.Add(new SubProdutCount() { SubProductId = item, SubProductName = outList.Single(p => p.SubProductId == item).SubProductName, CountNum = 0, NumRate = 0, TotalFinalPay = 0, MoneyRate = 0 });
}
}
foreach (var item in data)
{
//decimal CountNum = 0;
tab.AddCol(item.SubProductName);
//var l1 = list1.Where(p => p.SubProductId == item.SubProductId && p.SubProductName == item.SubProductName).FirstOrDefault();
//CountNum = l1 == null ? 0 : l1.CountNum;
//tab.AddCol(CountNum);
tab.AddCol(item.CountNum);
if (isShowPrice != null && isShowPrice == "true")
{
tab.AddCol(item.NeedPay);
}
tab.AddCol(item.NumRate);
tab.AddCol(item.TotalFinalPay);
tab.AddCol(item.MoneyRate);
if (deptCode == "SHZZ")
{
tab.AddCol(inList.Where(p => p.SubProductId == item.SubProductId).Sum(p => p.totalupgradevalue));
tab.AddCol(outList.Where(p => p.SubProductId == item.SubProductId).Sum(p => p.totalupgradevalue));
}
tab.AddRow();
}
//ViewBag.gridTable = tab.GetTable();
var json = new
{
data = res,
rowList = tab.GetTable()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
public FileResult CountOrderExport(string stime, string etime)
{
var deptCode = Utility.GetSettingOrNullByKey("DataClientCode");
var ds = wx_SzzyOrder_BL.CountSzzyOrder(stime, etime);
var list = ds.Tables[3].ToList<SubProdutCount>();
var inList = ds.Tables[4].ToList<InOutMoneyDto>();
var outList = ds.Tables[5].ToList<InOutMoneyDto>();
var data = new List<SubProdutCount>();
foreach (var item in list)
{
data.Add(new SubProdutCount() { SubProductId = item.SubProductId, SubProductName = item.SubProductName, CountNum = item.CountNum, NumRate = item.NumRate, TotalFinalPay = item.TotalFinalPay, MoneyRate = item.MoneyRate });
}
var exceptArr = inList.Select(p => p.SubProductId).Except(list.Select(p => p.SubProductId));
if (exceptArr.Any())
{
foreach (var item in exceptArr)
{
data.Add(new SubProdutCount() { SubProductId = item, SubProductName = inList.Single(p => p.SubProductId == item).SubProductName, CountNum = 0, NumRate = 0, TotalFinalPay = 0, MoneyRate = 0 });
}
}
var exceptArr2 = outList.Select(p => p.SubProductId).Except(list.Select(p => p.SubProductId));
if (exceptArr2.Any())
{
foreach (var item in exceptArr2)
{
data.Add(new SubProdutCount() { SubProductId = item, SubProductName = outList.Single(p => p.SubProductId == item).SubProductName, CountNum = 0, NumRate = 0, TotalFinalPay = 0, MoneyRate = 0 });
}
}
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("产品", typeof(string)));
dt.Columns.Add(new DataColumn("成交单数", typeof(decimal)));
dt.Columns.Add(new DataColumn("成交单数占比(%)", typeof(decimal)));
dt.Columns.Add(new DataColumn("成交金额", typeof(decimal)));
dt.Columns.Add(new DataColumn("成交金额占比(%)", typeof(decimal)));
if (deptCode == "SHZZ")
{
dt.Columns.Add(new DataColumn("分入金额", typeof(decimal)));
dt.Columns.Add(new DataColumn("分出金额", typeof(decimal)));
}
foreach (var item in data)
{
DataRow dr = dt.NewRow();
dr[0] = item.SubProductName;
dr[1] = item.CountNum;
dr[2] = item.NumRate;
dr[3] = item.TotalFinalPay;
dr[4] = item.MoneyRate;
if (deptCode == "SHZZ")
{
dr[5] = inList.Where(p => p.SubProductId == item.SubProductId).Sum(p => p.totalupgradevalue);
dr[6] = outList.Where(p => p.SubProductId == item.SubProductId).Sum(p => p.totalupgradevalue);
}
dt.Rows.Add(dr);
}
return File(ExcelHelper.ExportDataTableToExcel(dt, "订单统计"), "application/ms-excel", PageRequest.GetDlownLoadName("订单统计.xls"));
}
[AuthorizeRedirect(Roles = InitRights.CONST_订单来源统计)]
public ActionResult CountOrderBySource()
{
//ToolBar
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AllowButton(toolbtn);
ViewBag.ToolBar = tool;
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("SOURCE", "", "来源");
tab.AddHeadCol("COUNTNUM", "", "开通单数");
tab.AddHeadCol("COUNTNUM", "", "成交金额(元)");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead();
return View();
}
[AuthorizeRedirect(Roles = InitRights.CONST_订单来源统计)]
public JsonResult GetCountOrderBySourceHtml(string stime, string etime, string columns)
{
DataSet ds = wx_SzzyOrder_BL.CountSzzyClassifyOrder(stime, etime);
DataTable dt = new DataTable();
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
dt = ds.Tables[0];
}
Table table = new Table("tablist");
for (int i = 0; i < dt.Rows.Count; i++)
{
var model = dt.Rows[i];
table.AddCol(Utility.getSourceText(model["source"].ToString()));
table.AddCol(model["countnum"]);
table.AddCol(model["countmoney"]);
table.AddRow();
}
string tableId2 = "tablist2";
Table tab2 = new Table(tableId2);
tab2.AddHeadCol("ORDERTYPE", "", "订单类型");
tab2.AddHeadCol("COUNTNUM", "", "开通单数");
tab2.AddHeadCol("COUNTNUM", "", "成交金额(元)");
tab2.AddHeadRow();
if (ds != null && ds.Tables[1] != null && ds.Tables[1].Rows.Count > 0)
{
DataTable dt2 = ds.Tables[1];
for (int m = 0; m < dt2.Rows.Count; m++)
{
var model = dt2.Rows[m];
tab2.AddCol(getOrderTypeStr(Convert.ToDecimal(model["ordertype"])));
tab2.AddCol(model["countnum"]);
tab2.AddCol(model["countmoney"]);
tab2.AddRow();
}
}
var json = new
{
rowsList = table.GetRows(),
rowsList2 = tab2.GetTable()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
private string getSubProdutOrderCount(DataTable dt, decimal totalOpenNum, decimal totalOpenMoney)
{
var subProductCountList = new List<SubProdutCount>();
if (dt != null && dt.Rows.Count > 0)
{
subProductCountList = dt.ToList<SubProdutCount>();
}
var list = getConfigSubProductList();
string temp = "<td>" +
"<table width = \"100%\" >" +
"<tr>" +
"<td>成单</td>" +
"<td>成单占比</td>" +
"<td>金额</td>" +
"<td>金额占比</td>" +
"</tr>" +
"<tr>" +
"<td>{0}</td>" +
"<td>{1}</td>" +
"<td>{2}</td>" +
"<td>{3}</td>" +
"</tr>" +
"</table >" +
"</td>";
var str = "";
foreach (var item in list)
{
var model = subProductCountList.FirstOrDefault(m => m.SubProductId == item.MIDPRODUCTID);
if (model == null)
{
model = new SubProdutCount();
}
str += string.Format(temp
, model.CountNum
, string.Format("{0:p}", totalOpenNum > 0 ? (model.CountNum / totalOpenNum) : 0)
, model.TotalFinalPay
, string.Format("{0:p}", totalOpenMoney > 0 ? (model.TotalFinalPay / totalOpenMoney) : 0));
}
return str;
}
private class SubProdutCount
{
public decimal SubProductPrice { get; set; }
public decimal NeedPay { get; set; }
public decimal CountNum { get; set; }
public decimal TotalNeedPay { get; set; }
public decimal TotalFinalPay { get; set; }
public decimal SubProductId { get; set; }
public string SubProductName { get; set; }
public decimal NumRate { get; set; }
public decimal MoneyRate { get; set; }
}
private class InOutMoneyDto
{
public decimal SubProductId { get; set; }
public string SubProductName { get; set; }
public decimal totalupgradevalue { get; set; }
}
private IEnumerable<WX_SZZYMIDPRODUCT> getConfigSubProductList()
{
var midProductList = _midProduct.GetList();
return midProductList;
}
public ActionResult CountOrderList()
{
//ToolBar
ToolBar tool = new ToolBar();
ViewBag.ToolBar = tool;
//table
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHiddenHeadCol("ORDERID", "编号");
//tab.AddHeadCol("RESID", "11%", "客户ID");
tab.AddHeadCol("SUBPRODUCTNAME", "", "产品");
tab.AddHeadCol("NEEDPAY", "", "应付金额");
tab.AddHeadCol("FINALPAY", "", "实付金额");
tab.AddHeadCol("ARRIVALPAY", "", "到账金额");
tab.AddHeadCol("SZZYORDERID", "", "订单ID");
tab.AddHeadCol("ORDERID", "", "CRM订单ID");
tab.AddHeadCol("ORDERTYPE", "", "订单类型");
tab.AddHeadCol("ORDERSTATUSNAME", "", "订单状态");
tab.AddHeadCol("CTIME", "", "下单时间");
tab.AddHeadCol("ARRIVALTIME", "", "到账时间");
tab.AddHeadCol("OTIME", "", "开通时间");
//tab.AddHeadCol("", "8%", "");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead();
return View();
}
[HttpPost]
public JsonResult GetCountOrderHtmlList(string columns)
{
var subProductId = Request["subProductId"].GetDecimal(0);
var type = Request["type"].GetDecimal(0);
var stime = Request["stime"];
var etime = Request["etime"];
decimal[] subProductIds = new decimal[] { subProductId };
if (subProductId == 0)
{
var str = cache_BL.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.WeiXin_OrderCountShowColumn);
if (!string.IsNullOrWhiteSpace(str))
{
str = str.Trim().Trim(',');
string[] strs = str.Split(',');
decimal[] ids = strs.Select(m => m.GetDecimal(0)).ToArray();
List<WX_SZZYSUBPRODUCT> subList = wx_SzzySubProduct_BL.GetList(m => !ids.Contains(m.SUBPRODUCTID)).ToList();
subProductIds = subList.Select(m => m.SUBPRODUCTID).ToArray();
}
}
//三部销售部门id
decimal threeDeptId = 0;
var threeDeptIdStr = cache_BL.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_SaleDeptId_Three);
if (!string.IsNullOrWhiteSpace(threeDeptIdStr))
{
decimal.TryParse(threeDeptIdStr, out threeDeptId);
}
List<WX_SZZYORDER> list = wx_SzzyOrder_BL.GetList(subProductIds, stime, etime, type, threeDeptId);
Table table = new Table(columns, true);
foreach (var model in list)
{
table.AddHiddenCol(model.ORDERID);
//var linkUrl = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>"
// , "客户详细"
// , "/Csvr/CustomerInfo/CustomerDetail?resid=" + model.RESID
// , model.RESID);
//table.AddCol(linkUrl);
table.AddCol(model.SUBPRODUCTNAME);
table.AddCol(model.NEEDPAY);
table.AddCol(model.FINALPAY);
table.AddCol(model.ARRIVALPAY);
table.AddCol(model.SZZYORDERID);
table.AddCol(model.ORDERID);
table.AddCol(getOrderTypeStr(model.ORDERTYPE.Value));
table.AddCol(getOrderStatusStr(model.ORDERSTATUS));
table.AddCol(model.CTIME);
table.AddCol(model.ARRIVALTIME);
table.AddCol(model.OTIME);
//var payInfoUrl = string.Format("<a href=\"javascript:GetWxPayInfo('{0}')\">获取二维码</a>", model.ORDERID);
//table.AddCol(payInfoUrl);
table.AddRow();
}
var json = new
{
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
#endregion
public ActionResult GetQRCode(string url)
{
//QRCodeOperate qrCode = new QRCodeOperate();
QRCodeHelper.qrCodeScale = 8;
QRCodeHelper.encode = System.Text.Encoding.UTF8;
byte[] bytes = QRCodeHelper.Create(url);
return File(bytes, @"image/jpeg");
}
private List<SelectListItem> getProductList()
{
List<SelectListItem> selectList = new List<SelectListItem>();
var where = PredicateExtensionses.True<WX_SZZYPRODUCT>();
where = where.And(m => m.ISVALID == 1);
Pager pager = new Pager() { page = 1, rows = int.MaxValue };
var list = wx_SzzyProduct_BL.GetList(where, m => m.PRODUCTID, pager, SortOrder.Ascending);
foreach (var szzyProduct in list)
{
selectList.Add(new SelectListItem() { Text = szzyProduct.PRODUCTNAME, Value = szzyProduct.PRODUCTID.ToString() });
}
return selectList;
}
private List<SelectListItem> getAllProductList()
{
List<SelectListItem> selectList = new List<SelectListItem>();
var where = PredicateExtensionses.True<WX_SZZYPRODUCT>();
Pager pager = new Pager() { page = 1, rows = int.MaxValue };
var list = wx_SzzyProduct_BL.GetList(where, m => m.PRODUCTID, pager, SortOrder.Ascending);
foreach (var szzyProduct in list)
{
selectList.Add(new SelectListItem() { Text = szzyProduct.PRODUCTNAME, Value = szzyProduct.PRODUCTID.ToString() });
}
return selectList;
}
private List<SelectListItem> getSubProductListByProductId(int productId, int isValid)
{
List<SelectListItem> selectList = new List<SelectListItem>();
var where = PredicateExtensionses.True<WX_SZZYSUBPRODUCT>();
if (productId > 0)
{
where = where.And(m => m.PRODUCTID == productId);
}
if (isValid == 1)
{
where = where.And(m => m.ISVALID == 1);
}
Pager pager = new Pager() { page = 1, rows = int.MaxValue };
var list = wx_SzzySubProduct_BL.GetList(where, m => m.SUBPRODUCTID, pager, SortOrder.Ascending);
foreach (var szzySubProduct in list)
{
selectList.Add(new SelectListItem() { Text = szzySubProduct.SUBPRODUCTNAME, Value = szzySubProduct.SUBPRODUCTID.ToString() });
}
return selectList;
}
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("<font style=\"color:red\">下单失败</span>");
}
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 "";
}
}
public JsonResult GetSubProductList(int productId)
{
return Json(this.getSubProductListByProductId(productId, 1), JsonRequestBehavior.AllowGet);
}
public JsonResult GetAllSubProductList(int productId)
{
return Json(this.getSubProductListByProductId(productId, 0), JsonRequestBehavior.AllowGet);
}
public JsonResult GetSubProductPriceById(int subProductId)
{
var subProduct = wx_SzzySubProduct_BL.Get(m => m.SUBPRODUCTID == subProductId);
if (subProduct != null)
{
return Json(new { result = true, price = subProduct.PRICE, days = subProduct.RIGHTPERIOD }, JsonRequestBehavior.AllowGet);
}
else
{
return Json(new { result = false, price = 0, days = 0 }, JsonRequestBehavior.AllowGet);
}
}
}
}