using System; using System.Linq; using System.Web.Mvc; using WX.CRM.Common; using WX.CRM.IBLL.QH; using WX.CRM.Model.Entity; using WX.CRM.Model.QueryMap; using WX.CRM.WebHelper; namespace WX.CRM.WEB.Controllers.QH { public class MonthlystatementController : BaseController { private readonly IQH_MONTHLYSTATEMENT _gjsMon; private readonly IQH_MONTHLYSTATEMENT_Q _gjsMonQ; public MonthlystatementController(IQH_MONTHLYSTATEMENT gjsMon, IQH_MONTHLYSTATEMENT_Q gjsMonQ) { _gjsMon = gjsMon; _gjsMonQ = gjsMonQ; } public ActionResult Index() { ToolBar tool = new ToolBar(); string[] balance = new ToolButtonView().ToolButtonRight(InitRights.期货报表月结反月结, userRightId); tool.AllowButton(balance); tool.AddOtherButton("Other3", "月结校检", "icon-check", "", true); tool.AddOtherButton("Other1", "月结", "icon-check", "", true); //tool.AddOtherButton("Other5", "月结(分步骤)", "icon-check", "", true); tool.AddOtherButton("Other2", "撤销月结", "icon-uncheck", "", true); tool.AddOtherButton("Other4", "转移佣金分成规则并生成下月规则", "icon-check", "BackupCommissionRule", true); ViewBag.ToolBar = tool; //月结记录 var pager = new Pager() { order = "optime", page = 1, rows = 10 }; string tableId = "tablist"; var tab = new Table(tableId); tab.AddHeadCol("pkid", "", "编号"); tab.AddHeadCol("monthcode", "", "月结码"); tab.AddHeadCol("optype", "", "月结类型"); tab.AddHeadCol("opuser", "", "月结人"); tab.AddHeadCol("optime", "", "月结时间"); tab.AddHeadCol("backuser", "", "返月结人"); tab.AddHeadCol("backtime", "", "反月结时间"); tab.AddHeadCol("opremark", "", "备注"); tab.AddHeadRow(); ViewBag.gridTable = tab.GetTable() + Pagination.GetPage(pager, tableId, "5,8,10,15"); //月结校验 string checkTable = "checkTable"; var chktab = new Table(checkTable); chktab.AddHeadCol("checkType", "", "类型"); chktab.AddHeadCol("checkValue", "", "数量"); chktab.AddHeadCol("checkDate", "", "校验日期"); chktab.AddHeadCol("remark", "", "备注"); chktab.AddHeadRow(); ViewBag.checkTable = chktab.GetTable(); return View(); } public JsonResult GetHtmlList(Pager pager, string columns) { try { int c = 0; var list = _gjsMonQ.GetMONTHLYSTATEMENTList(pager.page, pager.rows, out c); pager.totalRows = c; var table = new Table(columns, true); foreach (var model in list) { table.AddCol(model.PKID); table.AddCol(model.MONTHCODE); table.AddCol(balanceStatus(model)); table.AddCol(InnerUserHelper.Instance.GetEid(model.OPUSER) + " - " + InnerUserHelper.Instance.GetUsername(model.OPUSER)); table.AddCol(model.OPTIME); table.AddCol(InnerUserHelper.Instance.GetEid(model.BACKUSER) + " - " + InnerUserHelper.Instance.GetUsername(model.BACKUSER)); table.AddCol(model.BACKTIME); table.AddCol(model.OPREMARK); table.AddRow(); } var json = new { totalPages = pager.totalPages, totalRows = pager.totalRows, rowsList = table.GetRows() }; return Json(json, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.Error("qh_MonthlystatementController_GetHtmlList:" + ex.Message + ex.StackTrace); return JsonHandler.ManageMessage(ex.Message, false); } } public JsonResult GetCheckHtmlList(Pager pager, string columns) { try { string mc = Request["balanceCode"]; int m = int.Parse(mc); System.Data.DataSet ds = _gjsMon.MonthCheckBalance(m); var list = ds.Tables[1].ToList(); int cr = int.Parse(ds.Tables[0].Rows[0][0].ToString()); var table = new Table(columns, true); foreach (var model in list) { table.AddCol(model.checkType); table.AddCol(model.checkValue); table.AddCol(model.checkDate); table.AddCol(model.remark); table.AddRow(); } var json = new { result = cr, totalPages = pager.totalPages, totalRows = pager.totalRows, rowsList = table.GetRows(), msg = cr == 1 ? "成功" : "校验未通过,查看明细!" }; return Json(json, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.Error("qh_MonthlystatementController_GetCheckHtmlList:" + ex.Message + ex.StackTrace); var json = new { result = "0", msg = ex.Message }; return Json(json, JsonRequestBehavior.AllowGet); } } public JsonResult MonthBalance() { try { string mc = Request["balanceCode"]; int m = int.Parse(mc); _gjsMon.MonthBalance(m, UserId); //System.Threading.Thread.Sleep(10 * 1000); var json = new { result = 1, message = "成功" }; return Json(json, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.Error("qh_MonthlystatementController_MonthBalance:" + ex.Message + ex.StackTrace); var json = new { result = "0", msg = ex.Message }; return Json(json, JsonRequestBehavior.AllowGet); } } public JsonResult MonthUnBalance() { try { string mc = Request["balanceCode"]; int m = int.Parse(mc); _gjsMon.MonthUnBalance(m, UserId, 0); //System.Threading.Thread.Sleep(100 * 1000); var json = new { result = 1, message = "成功" }; return Json(json, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.Error("qh_MonthlystatementController_MonthUnBalance:" + ex.Message + ex.StackTrace); var json = new { result = "0", msg = ex.Message }; return Json(json, JsonRequestBehavior.AllowGet); } } public JsonResult GenNextRule() { try { //System.Threading.Thread.Sleep(5000); _gjsMon.GenNextRule(UserId); var json = new { result = 1, message = "下月佣金规则生成成功!" }; return Json(json, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.Error("qh_MonthlystatementController_GenNextRule:" + ex.Message + ex.StackTrace); var json = new { result = 0, message = ex.Message }; return Json(json, JsonRequestBehavior.AllowGet); } } public JsonResult GetGenNextMonthCode() { try { //System.Threading.Thread.Sleep(5000); var m = _gjsMonQ.getMaxMonthCode(); if (m != null && m > 0) { string s = string.Format("{0}01", m); DateTime d = DateTime.ParseExact(s, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); d = d.AddMonths(2); var json = new { result = 1, message = d.ToString("yyyyMM") }; return Json(json, JsonRequestBehavior.AllowGet); } else { throw new Exception("未找到最大结算月"); } } catch (Exception ex) { LogHelper.Error("qh_MonthlystatementController_GenNextRule:" + ex.Message + ex.StackTrace); var json = new { result = 0, message = ex.Message }; return Json(json, JsonRequestBehavior.AllowGet); } } public JsonResult BackupCommissionRule() { try { string mc = Request["balanceCode"]; int m = int.Parse(mc); _gjsMon.BackupCommissionRule(m, UserId); var json = new { result = 1, message = "成功" }; return Json(json, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.Error("qh_MonthlystatementController_BackupCommissionRule:" + ex.Message + ex.StackTrace); var json = new { result = "0", msg = ex.Message }; return Json(json, JsonRequestBehavior.AllowGet); } } //--------------------------------------------- #region 分步月结 /// /// 根据月结记录反回月结状态 /// /// 月结记录 /// 反回月结状态 string balanceStatus(QH_MONTHLYSTATEMENT binfo) { string s = ""; if (binfo.OPTYPE == 1) { int ti = (int)(binfo.BALANCTSTEP ?? 1); switch (ti) { case 1: s = "月结【月结开始】"; //初始值,月结值是从2开始 break; case 2: s = "月结【步骤1】"; break; case 3: s = "月结【步骤2】"; break; case 4: s = "月结【步骤3】"; break; case 5: s = "月结【完成】"; break; } } else if (binfo.OPTYPE == -1) { s = "反月结"; } return s; } public JsonResult GetBalanceInfo(string balanceCode) { try { decimal bcode = decimal.Parse(balanceCode); var m = _gjsMonQ.getMonthlyStatement(bcode); if (m == null) throw new Exception("月结记录不存在!"); var json = new { result = 1, step = m.BALANCTSTEP ?? 1, message = "" }; return Json(json, JsonRequestBehavior.AllowGet); } catch (Exception ex) { //LogHelper.Error("Gjs_MonthlystatementController_GenNextRule:" + ex.Message + ex.StackTrace); var json = new { result = 0, step = 1, message = ex.Message }; return Json(json, JsonRequestBehavior.AllowGet); } } public JsonResult GetBalanceStep() { try { string mc = Request["balanceCode"]; int m = int.Parse(mc); _gjsMon.MonthBalanceStep(m, UserId); //System.Threading.Thread.Sleep(3000); var json = new { result = 1, message = "月结成功" }; return Json(json, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.Error("QH_MonthlystatementController:GetBalanceStep():" + ex.Message + ex.StackTrace); var json = new { result = 0, message = ex.Message }; return Json(json, JsonRequestBehavior.AllowGet); } } #endregion } }