ComplianceServer/oldcode/WEB/Controllers/WeiXin/CommissionBalanceController.cs

270 lines
10 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web.Mvc;
using WX.CRM.BLL;
using WX.CRM.Common;
using WX.CRM.IBLL.Util;
using WX.CRM.IBLL.Wx;
using WX.CRM.Model.Entity;
using WX.CRM.WebHelper;
namespace WX.CRM.WEB.Controllers.WeiXin
{
public class CommissionBalanceController : BaseController
{
private readonly IWX_BALANCE_LOG _balanceLog;
private readonly IWX_BALANCE _balance;
private readonly ICACHE_Q _cache;
public CommissionBalanceController(IWX_BALANCE_LOG balanceLog, IWX_BALANCE balance, ICACHE_Q cache)
{
_balanceLog = balanceLog;
_balance = balance;
_cache = cache;
}
[HttpGet]
[AuthorizeRedirect(InitRights.CONST_分成结算)]
//[AuthorizeSession(HasRight = true)]
public ActionResult Index()
{
var pager = new Pager() { order = "optime", page = 1, rows = 10 };
string tableId = "tablist";
var tab = new Table(tableId);
tab.AddHeadCol("pkid", "", "编号");
tab.AddHeadCol("month", "", "结算年月");
tab.AddHeadCol("type", "", "操作类型");
tab.AddHeadCol("operator", "", "操作人");
tab.AddHeadCol("ctime", "", "操作时间");
tab.AddHeadCol("remark", "", "备注");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable() + Pagination.GetPage(pager, tableId, "5,8,10,15");
return View();
}
[HttpPost]
[AuthorizeRedirect(InitRights.CONST_分成结算)]
//[AuthorizeSession(HasRight = true)]
public JsonResult BalanceLog(Pager pager, string columns)
{
try
{
var table = new Table(columns, true);
var where = PredicateExtensionses.True<WX_BALANCE_LOG>();
var list = _balanceLog.GetList(where, p => p.PKID, pager);
foreach (var model in list)
{
table.AddCol(model.PKID);
table.AddCol(model.MONTH);
table.AddCol(model.TYPE);
table.AddCol(InnerUserHelper.Instance.GetEid(model.OPERATOR) + " - " + InnerUserHelper.Instance.GetUsername(model.OPERATOR));
table.AddCol(model.CTIME);
table.AddCol(model.REMARK);
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("CommissionBalance/BalanceLog:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
[HttpPost]
[AuthorizeRedirect(InitRights.CONST_分成结算)]
//[AuthorizeSession(HasRight = true)]
public JsonResult CheckBalance()
{
try
{
var ret = _balance.CheckCommission();
if (string.IsNullOrEmpty(ret))
{
return Json(new { result = "ok" }, JsonRequestBehavior.AllowGet);
}
var data = new List<CheckCommissionView>();
var list = new List<string>(ret.Split(','));
foreach (var item in list)
{
data.Add(new CheckCommissionView() { OrderId = item.Split('#')[0], EidAndUserName = InnerUserHelper.Instance.EidAndName(decimal.Parse(item.Split('#')[1].ToString())) });
}
return Json(new { result = "no", data = data }, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("CommissionBalance/BalanceLog:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
[HttpPost]
[AuthorizeRedirect(InitRights.CONST_分成结算)]
//[AuthorizeSession(HasRight = true)]
public JsonResult Balance(string month)
{
try
{
if (string.IsNullOrEmpty(month))
return JsonHandler.ManageMessage("参数错误,请确认!", false);
DateTime m;
if (!DateTime.TryParse(month, out m))
{
return JsonHandler.ManageMessage("参数错误,请确认!", false);
}
var ret = _balance.SaleUserCommissionBalance(m, UserId, string.Empty);
return Json(new { result = ret }, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("CommissionBalance/Balance:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
[HttpPost]
[AuthorizeRedirect(InitRights.CONST_分成结算)]
//[AuthorizeSession(HasRight = true)]
public JsonResult UnBalance(string month)
{
try
{
if (string.IsNullOrEmpty(month))
return JsonHandler.ManageMessage("参数错误,请确认!", false);
DateTime m;
if (!DateTime.TryParse(month, out m))
{
return JsonHandler.ManageMessage("参数错误,请确认!", false);
}
_balance.SaleUserCommissionUnBalance(m, UserId);
return Json(new { result = "ok" }, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("CommissionBalance/UnBalance:" + ex.Message + ex.StackTrace);
//return JsonHandler.ManageMessage(ex.Message, false);
return Json(new { result = "err" }, JsonRequestBehavior.AllowGet);
}
}
[HttpGet]
[AuthorizeRedirect(InitRights.CONST_分成报表查询)]
//[AuthorizeSession(HasRight = true)]
public ActionResult Report()
{
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AllowButton(toolbtn);
tool.AddOtherButton("Other2", "导出", "icon-export", "ExportAllPage_Click", true);
ViewBag.ToolBar = tool;
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("yearmonth", "", "结算年月");
tab.AddHeadCol("gname", "", "组别");
tab.AddHeadCol("eid", "", "工号");
tab.AddHeadCol("uname", "", "姓名");
tab.AddHeadCol("commissionprice", "", "分成金额");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable();
try
{
var list = _balance.GetList().OrderByDescending(p => p.PKID).Select(p => p.MONTH);
ViewBag.YearMonth = list;
}
catch (Exception ex)
{
LogHelper.Error(ex);
}
return View();
}
[HttpPost]
[AuthorizeRedirect(InitRights.CONST_分成报表查询)]
//[AuthorizeSession(HasRight = true)]
public ActionResult ReportHtml(string columns, string month)
{
try
{
if (string.IsNullOrEmpty(month))
return JsonHandler.ManageMessage("参数错误,请确认!", false);
DateTime m;
if (!DateTime.TryParse(month, out m))
{
return JsonHandler.ManageMessage("参数错误,请确认!", false);
}
var table = new Table(columns, true);
var ds = _balance.CommissionBalanceReport(m);
foreach (DataRow model in ds.Tables[0].Rows)
{
table.AddCol(model["yearmonth"].ToString());
table.AddCol(model["gname"].ToString());
table.AddCol(model["eid"].ToString());
table.AddCol(model["uname"].ToString());
table.AddCol(model["commissionprice"].ToString());
table.AddRow();
}
table.AddCol("");
table.AddCol("");
table.AddCol("");
table.AddCol("");
table.AddCol("合计:" + ds.Tables[1].Rows[0][0].ToString());
table.AddRow();
var json = new
{
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("CommissionBalance/ReportHtml:" + ex.Message + ex.StackTrace);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
[AuthorizeRedirect(InitRights.CONST_分成报表查询)]
//[AuthorizeSession(HasRight = true)]
public FileResult Export(string month)
{
DateTime m;
DateTime.TryParse(month, out m);
var checkedFilds = PageRequest.GetQueryString("checkedFilds");
var checkedTitle = PageRequest.GetQueryString("checkedTitles");
var ds = _balance.CommissionBalanceReport(m);
var list = ds.Tables[0].ToList<CommissonBalanceExport>();
return File(ExcelHelper.ExportListModelToExcel<CommissonBalanceExport>(list, "分成报表", 50000, checkedFilds, checkedTitle, null), "application/ms-excel", PageRequest.GetDlownLoadName("分成报表.xls"));
//return File(ExcelHelper.ExportDataTableToExcel(ds.Tables[0], "分成报表", checkedFilds, checkedTitle, DataFormart), "application/ms-excel", PageRequest.GetDlownLoadName("分成报表.xls"));
}
}
public class CheckCommissionView
{
public string OrderId { get; set; }
public string EidAndUserName { get; set; }
}
public class CommissonBalanceExport
{
public string YearMonth { get; set; }
public string GName { get; set; }
public decimal Eid { get; set; }
public string UName { get; set; }
public decimal CommissionPrice { get; set; }
}
}