using Core.Web.App_Start; using Core.Web.WebHelper; using CRM.Core.BLL; using CRM.Core.BLL.Application.Order; using CRM.Core.BLL.Application.Performance; using CRM.Core.BLL.B; using CRM.Core.BLL.TransOrder; using CRM.Core.BLL.Util; using CRM.Core.BLL.Wx; using CRM.Core.DTO; using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using WX.CRM.Common; namespace Core.Web.Controllers { public class PerformanceController : BaseController { WX_SZZYORDER_BL _order = new WX_SZZYORDER_BL(); WX_SzzyOrderDeposit_BL _orderDeposit = new WX_SzzyOrderDeposit_BL(); Reward_PayInfo_BL _rewardPayInfo = new Reward_PayInfo_BL(); WX_SzzyOrderRefund_BL _orderRefund = new WX_SzzyOrderRefund_BL(); B_Audit_Items_BL b_Audit_Items_Bl = new B_Audit_Items_BL(); private readonly PerformanceService _performanceService = new PerformanceService(); private readonly OrderService _orderService = new OrderService(); CACHE_BL _cache = new CACHE_BL(); QueryAudit queryAudit= new QueryAudit(); [AuthorizeRedirect(RightsConfig.CONST_业绩核算, ToolBarConfig.CONST_NotButton, true)] [HttpGet] public ActionResult List() { ViewBag.companyList = _cache.GetCompanyVirtual(); return View(); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_业绩核算, ToolBarConfig.CONST_NotButton, false)] public JsonResult List(string channels, string yearMonth) { var dataAll = new List(); var dataXL = new List(); var starttime = string.Empty; var endtime = string.Empty; //订单数据 var orderList = _order.GetOpenOrder(starttime, endtime); //到账数据 var orderPayList = _order.GetDzOrder2(starttime, endtime); //退款数据 var orderRefund = _orderRefund.GetNotCurMonthRefundOrder(starttime, endtime); //LogHelper.Info("orderlist:" + orderList.Count.ToString() + "==orderpaylist:" + orderPayList.Count.ToString() + "==orderrefund:" + orderRefund.Count.ToString()); if (!string.IsNullOrEmpty(channels)) { //cacheKey2 = cacheKey2 + channels; var arr0 = channels.Split('|'); if (arr0.Length > 1) { var whereOr = PredicateExtensionses.False(); var whereOr2 = PredicateExtensionses.False(); var whereOr3 = PredicateExtensionses.False(); foreach (var arr in arr0) { var a = arr.Split(','); var min = Convert.ToInt32(a[0]); var max = Convert.ToInt32(a[1]); whereOr = whereOr.Or(m => m.channel >= min && m.channel <= max); whereOr2 = whereOr2.Or(m => m.channel >= min && m.channel <= max); whereOr3 = whereOr3.Or(m => m.channel >= min && m.channel <= max); } orderList = orderList.Where(whereOr.Compile()).ToList(); orderPayList = orderPayList.Where(whereOr2.Compile()).ToList(); orderRefund = orderRefund.Where(whereOr3.Compile()).ToList(); } else { var arr = channels.Split(','); var min = Convert.ToInt32(arr[0]); var max = Convert.ToInt32(arr[1]); orderList = orderList.Where(m => m.channel >= min && m.channel <= max).ToList(); orderPayList = orderPayList.Where(m => m.channel >= min && m.channel <= max).ToList(); orderRefund = orderRefund.Where(m => m.channel >= min && m.channel <= max).ToList(); } } var orderRefundList = _orderRefund.GetList(p => p.auditstatus == 1) .Select(p => new OrderRefundView { fmonth = int.Parse(p.refunddate.Value.ToString("yyyyMM")), refundprice = p.refundprice, refundtype = p.refundtype }).ToList(); foreach (var item in orderRefundList) { if (item.refundtype == 11) { item.refundprice = item.refundprice * Convert.ToDecimal(0.68607); } else if (item.refundtype == 12) { item.refundprice = item.refundprice * Convert.ToDecimal(0.68760); //LogHelper.Info("item.refundprice:" + item.refundprice.ToString()); } else if (item.refundtype == 13) { item.refundprice = item.refundprice * Convert.ToDecimal(0.686); } } //其他收入 var rewardPayInfoList = _rewardPayInfo.GetList(p => p.auditstatus == 1 && p.isdelete == 0) .Select(p => new { paydate = int.Parse(p.paydate.ToString("yyyyMM")), payprice = p.payprice }) .GroupBy(p => p.paydate) .Select(g => new { omonth = g.Key, dzje = g.Sum(p => p.payprice) }) .OrderBy(p => p.omonth) ; var data = new List(); var dayCount = 0; decimal rate = 1; //data = _performanceService.GetPerformanceDay(); //LogHelper.Info("data:" + data.Count.ToString()); if (!data.Any()) { #region 订单部分处理 foreach (var order in orderList) { //爱赢系列 //if (order.productid == 1007) //{ if (order.settletype == 1007) { order.opendays = 1; order.endday = order.opday.AddDays(1); } //} //多赢系列 if (order.arrivalpay < 10) { //9.9订单放到多赢系列 order.productid = 1009; } var nowDate = order.opday; var diffmonth = (order.endday.Year - order.opday.Year) * 12 + (order.endday.Month - order.opday.Month);//相差月数 var i = 0; while (i <= diffmonth) { var curMonthFirstDay = nowDate.AddDays(1 - nowDate.Day);//本月第一天 var curMonthLastDay = nowDate.AddDays(1 - nowDate.Day).Date.AddMonths(1).AddDays(-1);//本月最后一天 var nextMonthFirstDay = nowDate.AddDays(1 - nowDate.Day).Date.AddMonths(1);//下个月第一天 if (i == 0) { //第一个月 if (curMonthLastDay < order.endday) { dayCount = (nextMonthFirstDay - nowDate).Days; } else { dayCount = (order.endday - nowDate).Days; } } else if (i == diffmonth) { //最后一个月 dayCount = (order.endday - curMonthFirstDay).Days; } else { dayCount = (nextMonthFirstDay - curMonthFirstDay).Days; } //写入60%部分 var oyear = int.Parse(nowDate.ToString("yyyy")); var omonth = int.Parse(nowDate.ToString("yyyyMM")); //if (order.productid == 1008) //{ // if (i == 0) // { // //第一个月写入60% // data.Add(new Performance() // { // orderid = order.orderid, // oyear = order.orderyear, // omonth = order.ordermonth, // daycount = dayCount, // jiazhi = 0, // jzcount = order.arrivalpay * 6 / 10, // channel = order.channel, // opmonth = order.ordermonth, // opyear = order.orderyear, // type = 1, // productid = order.productid, // amonth = order.amonth, // arrivalpay = order.arrivalpay, // opendays = order.opendays // }); // } // data.Add(new Performance() // { // orderid = order.orderid, // oyear = oyear, // omonth = omonth, // daycount = dayCount, // jiazhi = order.arrivalpay * 4 / 10 / order.opendays, // jzcount = dayCount * (order.arrivalpay * 4 / 10 / order.opendays), // channel = order.channel, // opmonth = order.ordermonth, // opyear = order.orderyear, // type = 0, // productid = order.productid, // amonth = order.amonth, // arrivalpay = order.arrivalpay, // opendays = order.opendays // }); // if(!string.IsNullOrEmpty(order.upgradeorderids)) // { // var upArr = order.upgradeorderids.Split(','); // foreach (var arr in upArr) // { // //var oldOrderId = Convert.ToInt32(order.upgradeorderids); // var oldOrderId = Convert.ToInt32(arr); // var oldOrderList = data.Where(p => p.orderid == oldOrderId && p.omonth > omonth && p.type == 0); // foreach (var item in oldOrderList) // { // item.daycount = 0; // item.jiazhi = 0; // item.jzcount = 0; // } // var oldOrder = data.Find(p => p.orderid == oldOrderId && p.omonth == omonth && p.type == 0); // var oldOrder40Sum = data.Where(p => p.orderid == oldOrderId && p.omonth < order.ordermonth && p.type == 0).Sum(p => p.jzcount); // decimal curOrderRate = Convert.ToDecimal(Convert.ToDecimal(dayCount) / Convert.ToDecimal(order.opendays)); // if (oldOrder != null) // { // oldOrder.daycount = dayCount; // oldOrder.jiazhi = oldOrder.arrivalpay * 4 / 10 / oldOrder.opendays; // oldOrder.jzcount = curOrderRate * (oldOrder.arrivalpay * 4 / 10 - oldOrder40Sum); // } // else // { // var addorder = orderList.Find(p => p.orderid == oldOrderId); // data.Add(new Performance() // { // orderid = addorder.orderid, // oyear = oyear, // omonth = omonth, // daycount = dayCount, // jiazhi = addorder.arrivalpay * 4 / 10 / addorder.opendays, // jzcount = curOrderRate * (addorder.arrivalpay * 4 / 10 - oldOrder40Sum), // channel = addorder.channel, // opmonth = addorder.ordermonth, // opyear = addorder.orderyear, // type = 0, // productid = addorder.productid, // amonth = addorder.amonth, // arrivalpay = addorder.arrivalpay, // opendays = addorder.opendays // }); // } // } // } //} //else { data.Add(new Performance() { orderid = order.orderid, oyear = oyear, omonth = omonth, daycount = dayCount, jiazhi = order.arrivalpay / order.opendays, jzcount = dayCount * (order.arrivalpay / order.opendays), channel = order.channel, opmonth = order.ordermonth, opyear = order.orderyear, type = 0, productid = order.productid, amonth = order.amonth, arrivalpay = order.arrivalpay, opendays = order.opendays }); // //if (!string.IsNullOrEmpty(order.upgradeorderids)) //{ // var upArr = order.upgradeorderids.Split(','); // foreach (var arr in upArr) // { // var oldOrderId = Convert.ToInt32(arr); // var oldOrderList = data.Where(p => p.orderid == oldOrderId && p.omonth > omonth && p.type == 0); // foreach (var item in oldOrderList) // { // item.daycount = 0; // item.jiazhi = 0; // item.jzcount = 0; // } // var oldOrder = data.Find(p => p.orderid == oldOrderId && p.omonth == omonth && p.type == 0); // var oldOrderUsePriceSum = data.Where(p => p.orderid == oldOrderId && p.omonth < order.ordermonth && p.type == 0).Sum(p => p.jzcount); // decimal curOrderRate = Convert.ToDecimal(Convert.ToDecimal(dayCount) / Convert.ToDecimal(order.opendays)); // if (oldOrder != null) // { // oldOrder.daycount = dayCount; // oldOrder.jiazhi = oldOrder.arrivalpay / oldOrder.opendays; // oldOrder.jzcount = curOrderRate * (oldOrder.arrivalpay - oldOrderUsePriceSum); // } // else // { // var addorder = orderList.Find(p => p.orderid == oldOrderId); // data.Add(new Performance() // { // orderid = addorder.orderid, // oyear = oyear, // omonth = omonth, // daycount = dayCount, // jiazhi = addorder.arrivalpay / addorder.opendays, // jzcount = curOrderRate * (addorder.arrivalpay - oldOrderUsePriceSum), // channel = addorder.channel, // opmonth = addorder.ordermonth, // opyear = addorder.orderyear, // type = 0, // productid = addorder.productid, // amonth = addorder.amonth, // arrivalpay = addorder.arrivalpay, // opendays = addorder.opendays // }); // } // } //} } nowDate = nowDate.AddMonths(1); i++; } } #endregion #region 退款部分处理 //decimal allRefund = 0; //var oid = 80089645; foreach (var item in orderRefund) { //if (item.productid == 1007) //{ if (item.settletype == 1007) { item.opendays = 1; item.endRefundDate = item.startRefundDate; } //} if (item.arrivalpay < 10) item.productid = 1009; //decimal refundTotal = 0; var nowDate = item.endRefundDate; //if (item.orderid == oid) //{ // LogHelper.Info("item.endRefundDate:" + item.endRefundDate.ToString() + ", item.startRefundDate:" + item.startRefundDate.ToString()); //} var diffmonth = (item.endRefundDate.Year - item.startRefundDate.Year) * 12 + (item.endRefundDate.Month - item.startRefundDate.Month);//相差月数 //if (item.orderid == oid) //{ // LogHelper.Info("diffmonth:" + diffmonth.ToString()); //} //decimal notCurMonthPrice = 0; decimal notCurMonthPrice60 = 0; if (diffmonth > 0) { //摊分退款的处理 var i = diffmonth; while (i > 0) { var curMonthFirstDay = nowDate.AddDays(1 - nowDate.Day);//本月第一天 var curMonthLastDay = nowDate.AddDays(1 - nowDate.Day).Date.AddMonths(1).AddDays(-1);//本月最后一天 var nextMonthFirstDay = nowDate.AddDays(1 - nowDate.Day).Date.AddMonths(1);//下个月第一天 if (i == 0) { //第一个月 if (curMonthLastDay < item.endRefundDate) { dayCount = (nextMonthFirstDay - nowDate).Days; } else { dayCount = (item.endRefundDate - nowDate).Days; } } else if (i == diffmonth) { //最后一个月 dayCount = (item.endRefundDate - curMonthFirstDay).Days; } else { dayCount = (nextMonthFirstDay - curMonthFirstDay).Days; } //LogHelper.Info("dayCount:" + dayCount.ToString()); var nowMonth = int.Parse(nowDate.ToString("yyyyMM")); //累计预收退款小于退款金额,说明还有退款需要处理 if (notCurMonthPrice60 < item.refundprice) { //var refundInfo = data.FirstOrDefault(p => p.omonth == nowMonth && p.orderid == item.orderid); var model60 = data.FirstOrDefault(p => p.omonth == nowMonth && p.orderid == item.orderid); if (model60 != null) { //去掉60服务费 //if (item.productid == 1008) // rate = Convert.ToDecimal(0.4); //else // rate = 1; /*新代码*/ var monthPrice = dayCount * (item.arrivalpay * rate / item.opendays); var diffPrice = monthPrice - model60.monthRefundPrice; if (item.arrivalpay > item.needpay && item.arrivalpay - item.refundprice == item.needpay) { //多付部分的退款,不需要处理 //model60.monthRefundPrice = dayCount * (item.refundprice * rate / item.opendays); } else { //可能存在多笔退款的情况 if (model60.monthRefundPrice == model60.jzcount) { } else { if (!model60.fmonth.HasValue) { model60.fmonth = item.refunddate; } if (diffPrice <= (item.refundprice - notCurMonthPrice60)) { model60.monthRefundPrice += diffPrice; notCurMonthPrice60 += diffPrice; } else { model60.monthRefundPrice += (item.refundprice - notCurMonthPrice60); notCurMonthPrice60 += (item.refundprice - notCurMonthPrice60); } } } /*旧代码*/ //if (item.arrivalpay - item.refundprice == item.needpay) //{ // model60.monthRefundPrice = dayCount * (item.refundprice * rate / item.opendays); //} //else //{ // model60.monthRefundPrice = dayCount * (item.arrivalpay * rate / item.opendays); // //model60.monthRefundPrice = model60.jzcount; //} ////model60.monthRefundPrice = model60.jzcount; //notCurMonthPrice60 += model60.monthRefundPrice; ////如果退款少于预收则直接就是当前退款金额 //if (notCurMonthPrice60 > item.refundprice) //{ // notCurMonthPrice60 -= model60.monthRefundPrice; // model60.monthRefundPrice = item.refundprice - notCurMonthPrice60; // notCurMonthPrice60 += model60.monthRefundPrice; //} } } nowDate = nowDate.AddMonths(-1); i--; } //服务费及第一个月退款的处理 if (item.refundprice > notCurMonthPrice60) { var model60 = data.FirstOrDefault(p => p.omonth == item.refunddate && p.orderid == item.orderid); if (model60 != null) { if (!model60.fmonth.HasValue) { model60.fmonth = item.refunddate; } //去掉60%服务费 //if (item.productid == 1008) // rate = Convert.ToDecimal(0.6); //else // rate = 1; if (item.arrivalpay > item.needpay && item.arrivalpay - item.refundprice == item.needpay) { //多付部分的退款,不需要处理 /*旧代码,新代码不需要处理*/ //model60.firstRefundPrice = dayCount * (item.refundprice * rate / item.opendays); } else { model60.firstRefundPrice = dayCount * (item.arrivalpay * rate / item.opendays); //model60.monthRefundPrice = model60.jzcount; } //LogHelper.Info("model60.curMonthRefundPrice:" + model60.curMonthRefundPrice.ToString() + ",item.refundprice:" + item.refundprice.ToString() + ",notCurMonthPrice60:" + notCurMonthPrice60.ToString()); /*新代码 处理多个退款的问题*/ model60.curMonthRefundPrice += item.refundprice - notCurMonthPrice60; /*旧代码 多个退款会覆盖退款金额*/ //model60.curMonthRefundPrice = item.refundprice - notCurMonthPrice60; //refundTotal += model60.curMonthRefundPrice; } } } else { //if (item.orderid == oid) //{ // LogHelper.Info("item.refunddate:" + item.refunddate.ToString() + ", item.refundprice:" + item.refundprice.ToString()); //} //服务期已经结束的情况 //refundTotal += item.refundprice; data.Add(new Performance() { orderid = item.orderid, oyear = int.Parse(item.startRefundDate.ToString("yyyy")), omonth = item.refunddate, daycount = dayCount, jiazhi = 0, jzcount = 0, channel = item.channel, opmonth = item.refunddate, opyear = int.Parse(item.startRefundDate.ToString("yyyy")), type = 0, productid = item.productid, curMonthRefundPrice = item.refundprice, monthRefundPrice = 0, fmonth = item.refunddate }); } //if (refundTotal != item.refundprice) //{ // LogHelper.Info("refundTotal:" + refundTotal.ToString() + ",orderid:" + item.orderid.ToString() + ",item.refundprice" + item.refundprice.ToString()); //} } #endregion } //LogHelper.Info("data2:" + data.Count.ToString()); _performanceService.PutMonPerformanceDay(data); _performanceService.PutMonDzOrderDay(orderPayList); //LogHelper.Info("put:ok"); if (!string.IsNullOrEmpty(channels)) { var arr0 = channels.Split('|'); if (arr0.Length > 1) { var whereOr = PredicateExtensionses.False(); foreach (var arr in arr0) { var a = arr.Split(','); var min = Convert.ToInt32(a[0]); var max = Convert.ToInt32(a[1]); whereOr = whereOr.Or(m => m.channel >= min && m.channel <= max); } data = data.Where(whereOr.Compile()).ToList(); } else { var arr = channels.Split(','); var min = Convert.ToInt32(arr[0]); var max = Convert.ToInt32(arr[1]); data = data.Where(m => m.channel >= min && m.channel <= max).ToList(); } } #region 合计 var dataMonth = data.GroupBy(p => p.omonth); decimal djSum = 0; foreach (var item in dataMonth) { //差额 //var ce = orderPayList.Where(p => p.paymonth == item.Key && p.orderstatus == "90" && p.fmonth > p.nmonth).Sum(p => p.payprice); //订单收入 var ddsr = orderList.Where(p => p.ordermonth == item.Key).Sum(p => p.arrivalpay); //ddsr = ddsr - ce; //预收 decimal ys = 0; //if (item.Key < 202101) //{ ys = orderPayList.Where(p => p.paymonth == item.Key && (p.omonth > p.paymonth || p.orderstatus == "200" || (p.omonth is null && (p.amonth > p.paymonth || p.amonth is null)))).Sum(p => p.payprice); //ys = orderPayList.Where(p => p.paymonth == item.Key && (p.omonth > p.paymonth || p.orderstatus == "200" || (p.omonth is null && (p.amonth > p.paymonth || p.amonth is null || p.orderstatus == "90")))).Sum(p => p.payprice); //ys = orderPayList.Where(p => p.paymonth == item.Key && (p.omonth > p.paymonth || p.orderstatus == "200" || (p.omonth is null && p.amonth is null))).Sum(p => p.payprice); //} //else //{ // ys = orderPayList.Where(p => p.paymonth == item.Key && (p.omonth > p.paymonth || p.orderstatus == "200" || (p.omonth is null && (p.amonth > p.paymonth || p.amonth is null))) || excludeeList2.Contains(p.orderid.Value)).Sum(p => p.payprice); //} //ys = ys + ce; //订金使用 var useDj = orderPayList.Where(p => (p.omonth == item.Key && p.omonth > p.paymonth) || (p.omonth is null && p.amonth > p.paymonth && p.fmonth == item.Key)).Sum(p => p.payprice); //其它收入 var ds = rewardPayInfoList.Where(p => p.omonth == item.Key).Sum(p => p.dzje); //当月订单总收入 var dyddzsr = ddsr + ys + ds - useDj; //var dyddzsr = ddsr + ys + ds; //当月总退款 var dyztk = orderRefundList.Where(p => p.fmonth == item.Key).Sum(p => p.refundprice); //账户收入 var zhsr = dyddzsr - dyztk; //入账 var rz = data.Where(p => p.omonth == item.Key).Sum(p => p.jzcount); //预收 var lc = data.Where(p => p.omonth > item.Key && p.type == 0 && p.opmonth <= item.Key).Sum(p => p.jzcount); //var dytk = data.Where(p => p.omonth == item.Key).Sum(p => p.curMonthRefundPrice); //var fdytk = data.Where(p => p.omonth == item.Key).Sum(p => p.monthRefundPrice); //入账退款 var rztk = data.Where(p => p.omonth == item.Key).Sum(p => p.curMonthRefundPrice + p.monthRefundPrice); //预收退款 var lctk = data.Where(p => p.omonth > item.Key && p.type == 0 && p.fmonth <= item.Key).Sum(p => p.monthRefundPrice); //订金退款 //var djtk = orderPayList.Where(p => p.fmonth <= item.Key && p.omonth == null && p.isuse == null && (p.orderstatus == null || p.orderstatus == "90")).Sum(p => p.payprice); var djtk = orderPayList.Where(p => p.fmonth <= item.Key && p.omonth == null && p.isuse == null && p.orderstatus == null).Sum(p => p.payprice); //如果当前月没有订金退款 var djtkCurMonth = orderPayList.Where(p => p.fmonth == item.Key && p.omonth == null && p.isuse == null && p.orderstatus == null).Sum(p => p.payprice); if (djtkCurMonth == 0) djtk = 0; if (ys > 0 || useDj > 0) { djSum += ys - useDj; } else { djSum = 0; } dataAll.Add(new PerformanceView() { omonth = item.Key, ddsr = ddsr.ToString("f"), ys = ys.ToString("f"), //notUseDj = notUseDj.ToString("f"), useDj = useDj.ToString("f"), //tkDj = tkDj.ToString("f"), ds = ds.ToString("f"), dyddzsr = dyddzsr.ToString("f"), dyztk = dyztk.ToString("f"), zhsr = zhsr.ToString("f"), rz = (rz - rztk).ToString("f"), lc = (lc - lctk - djtk).ToString("f"), dytk = "0", fdytk = "0", rztk = rztk.ToString("f"), lctk = lctk.ToString("f"), djtk = djtk.ToString("f"), dj = djSum.ToString("f") }); } #endregion #region 系列 decimal zydjSum = 0; decimal dydjSum = 0; decimal aydjSum = 0; foreach (var item in dataMonth) { #region //软件费 var rjf1008 = data.Where(p => p.productid == 1008 && p.omonth == item.Key && p.type == 1).Sum(p => p.jzcount); //维护费 var whf1008 = data.Where(p => p.productid == 1008 && p.omonth == item.Key && p.type == 0).Sum(p => p.jzcount); //软件费退款 var rjftk1008 = data.Where(p => p.productid == 1008 && p.omonth == item.Key).Sum(p => p.curMonthRefundPrice - p.firstRefundPrice); //维护费退款 var whftk1008 = data.Where(p => p.productid == 1008 && p.omonth == item.Key).Sum(p => p.monthRefundPrice + p.firstRefundPrice); //入账 var rz1008 = data.Where(p => p.productid == 1008 && p.omonth == item.Key).Sum(p => p.jzcount); //入账退款 var rztk1008 = data.Where(p => p.productid == 1008 && p.omonth == item.Key).Sum(p => p.curMonthRefundPrice + p.monthRefundPrice); //预收 var lc1008 = data.Where(p => p.productid == 1008 && p.omonth > item.Key && p.type == 0 && p.opmonth <= item.Key).Sum(p => p.jzcount); //预收退款 var lctk1008 = data.Where(p => p.productid == 1008 && p.omonth > item.Key && p.type == 0 && p.fmonth <= item.Key).Sum(p => p.monthRefundPrice); //订金退款 var djtk1008 = orderPayList.Where(p => p.productid == 1008 && p.fmonth <= item.Key && p.omonth == null && p.isuse == null && p.orderstatus == null).Sum(p => p.payprice); var djtk1008CurMonth = orderPayList.Where(p => p.productid == 1008 && p.fmonth == item.Key && p.omonth == null && p.isuse == null && p.orderstatus == null).Sum(p => p.payprice); if (djtk1008CurMonth == 0) djtk1008 = 0; //订金 var ys1008 = orderPayList.Where(p => p.productid == 1008 && (p.paymonth == item.Key && (p.omonth > p.paymonth || p.orderstatus == "200" || (p.omonth is null && (p.amonth > p.paymonth || p.amonth is null))))).Sum(p => p.payprice); //订金使用 var useDj1008 = orderPayList.Where(p => p.productid == 1008 && ((p.omonth == item.Key && p.omonth > p.paymonth) || (p.omonth is null && p.amonth > p.paymonth && p.fmonth == item.Key))).Sum(p => p.payprice); if (ys1008 > 0 || useDj1008 > 0) { zydjSum += ys1008 - useDj1008; } else { zydjSum = 0; } #endregion #region //入账 var rz1009 = data.Where(p => p.productid == 1009 && p.omonth == item.Key).Sum(p => p.jzcount); //入账退款 var rztk1009 = data.Where(p => p.productid == 1009 && p.omonth == item.Key).Sum(p => p.curMonthRefundPrice + p.monthRefundPrice); //预收 var lc1009 = data.Where(p => p.productid == 1009 && p.omonth > item.Key && p.type == 0 && p.opmonth <= item.Key).Sum(p => p.jzcount); //预收退款 var lctk1009 = data.Where(p => p.productid == 1009 && p.omonth > item.Key && p.type == 0 && p.fmonth <= item.Key).Sum(p => p.monthRefundPrice); //订金退款 var djtk1009 = orderPayList.Where(p => p.productid == 1009 && p.fmonth <= item.Key && p.omonth == null && p.isuse == null && p.orderstatus == null).Sum(p => p.payprice); var djtk1009CurMonth = orderPayList.Where(p => p.productid == 1009 && p.fmonth == item.Key && p.omonth == null && p.isuse == null && p.orderstatus == null).Sum(p => p.payprice); if (djtk1009CurMonth == 0) djtk1009 = 0; //订金 var ys1009 = orderPayList.Where(p => p.productid == 1009 && (p.paymonth == item.Key && (p.omonth > p.paymonth || p.orderstatus == "200" || (p.omonth is null && (p.amonth > p.paymonth || p.amonth is null))))).Sum(p => p.payprice); //订金使用 var useDj1009 = orderPayList.Where(p => p.productid == 1009 && ((p.omonth == item.Key && p.omonth > p.paymonth) || (p.omonth is null && p.amonth > p.paymonth && p.fmonth == item.Key))).Sum(p => p.payprice); if (ys1009 > 0 || useDj1009 > 0) { dydjSum += ys1009 - useDj1009; } else { dydjSum = 0; } #endregion #region //入账 var rz1007 = data.Where(p => p.productid == 1007 && p.omonth == item.Key).Sum(p => p.jzcount); //入账退款 var rztk1007 = data.Where(p => p.productid == 1007 && p.omonth == item.Key).Sum(p => p.curMonthRefundPrice + p.monthRefundPrice); //预收 var lc1007 = data.Where(p => p.productid == 1007 && p.omonth > item.Key && p.type == 0 && p.opmonth <= item.Key).Sum(p => p.jzcount); //预收退款 var lctk1007 = data.Where(p => p.productid == 1007 && p.omonth > item.Key && p.type == 0 && p.fmonth <= item.Key).Sum(p => p.monthRefundPrice); //订金退款 var djtk1007 = orderPayList.Where(p => p.productid == 1007 && p.fmonth <= item.Key && p.omonth == null && p.isuse == null && p.orderstatus == null).Sum(p => p.payprice); var djtk1007CurMonth = orderPayList.Where(p => p.productid == 1007 && p.fmonth == item.Key && p.omonth == null && p.isuse == null && p.orderstatus == null).Sum(p => p.payprice); if (djtk1007CurMonth == 0) djtk1007 = 0; //订金 var ys1007 = orderPayList.Where(p => p.productid == 1007 && (p.paymonth == item.Key && (p.omonth > p.paymonth || p.orderstatus == "200" || (p.omonth is null && (p.amonth > p.paymonth || p.amonth is null))))).Sum(p => p.payprice); //订金使用 var useDj1007 = orderPayList.Where(p => p.productid == 1007 && ((p.omonth == item.Key && p.omonth > p.paymonth) || (p.omonth is null && p.amonth > p.paymonth && p.fmonth == item.Key))).Sum(p => p.payprice); if (ys1007 > 0 || useDj1007 > 0) { aydjSum += ys1007 - useDj1007; } else { aydjSum = 0; } #endregion var zyrjf = rjf1008 - rjftk1008; var zywhf = whf1008 - whftk1008; var zyrz = rz1008 - rztk1008; var zyys = lc1008 - lctk1008 - djtk1008 + zydjSum; var dyrz = rz1009 - rztk1009; var dyys = lc1009 - lctk1009 - djtk1009 + dydjSum; var ayrz = rz1007 - rztk1007; var ayys = lc1007 - lctk1007 - djtk1007 + aydjSum; dataXL.Add(new XieLieView() { omonth = item.Key, zyrjf = zyrjf.ToString("f"), zywhf = zywhf.ToString("f"), zyrz = zyrz.ToString("f"), zyys = zyys.ToString("f"), dyrz = dyrz.ToString("f"), dyys = dyys.ToString("f"), ayrz = ayrz.ToString("f"), ayys = ayys.ToString("f") }); } #endregion //var lcSum = data.Where(p => p.omonth > 202006 && p.type == 0 && p.opmonth <= 202006).Sum(p => p.jzcount); //LogHelper.Info("lcsum:" + lcSum.ToString()); ////预收退款 //var lctkSum = data.Where(p => p.omonth > 202006 && p.type == 0 && p.fmonth <= 202006).Sum(p => p.monthRefundPrice); //LogHelper.Info("lctkSum:" + lctkSum.ToString()); //var djtksum = orderPayList.Where(p => p.fmonth <= 202006 && p.omonth == null && p.isuse == null && p.orderstatus == null).Sum(p => p.payprice); //LogHelper.Info("djtksum:" + djtksum.ToString()); ////foreach (var item in orderPayList.Where(p => p.fmonth <= 202006 && p.omonth == null && p.isuse == null && p.orderstatus == null).OrderBy(p => p.orderid)) ////{ //// LogHelper.Info("item:" + item.orderid + "," + item.payprice); ////} //var ysSum = orderPayList.Where(p => p.paymonth == 202006 && (p.omonth > p.paymonth || p.orderstatus == "200" || (p.omonth is null && (p.amonth > p.paymonth || p.amonth is null)))).Sum(p => p.payprice); //LogHelper.Info("ysSum:" + ysSum.ToString()); //var useDjSum = orderPayList.Where(p => (p.omonth == 202006 && p.omonth > p.paymonth && p.fmonth is null) || (p.omonth is null && p.amonth > p.paymonth && p.fmonth == 202006)).Sum(p => p.payprice); //LogHelper.Info("useDjSum:" + useDjSum.ToString()); //foreach (var item in orderPayList.Where(p => (p.omonth == 202006 && p.omonth > p.paymonth && p.fmonth is null) || (p.omonth is null && p.amonth > p.paymonth && p.fmonth == 202006)).OrderBy(p => p.orderid)) //{ // LogHelper.Info("item:" + item.orderid + "," + item.fmonth); //} //var aaaaSum = orderPayList.Where(p => (p.omonth == 202003 && p.omonth > p.paymonth) || (p.omonth is null && p.amonth > p.paymonth && p.fmonth == 202003)).Sum(p => p.payprice); //LogHelper.Info("aaa:" + aaaaSum.ToString()); //foreach (var item in orderPayList.Where(p => (p.omonth == 202003 && p.omonth > p.paymonth) || (p.omonth is null && p.amonth > p.paymonth && p.fmonth == 202003)).OrderBy(p => p.orderid)) //{ // LogHelper.Info(item.orderid + "," + item.payprice); //} //if (!CacheHelper.Exists(cacheKey)) //{ // CacheHelper.Set(cacheKey, dataAll, new DateTime(DateTime.Now.AddDays(1).Year, DateTime.Now.AddDays(1).Month, DateTime.Now.AddDays(1).Day), false); //} //if (!CacheHelper.Exists(cacheKey2)) //{ // CacheHelper.Set(cacheKey2, dataXL, new DateTime(DateTime.Now.AddDays(1).Year, DateTime.Now.AddDays(1).Month, DateTime.Now.AddDays(1).Day), false); //} //} return Json(new { dataAll = dataAll.OrderBy(p => p.omonth).ToList(), dataProducts = dataXL.OrderBy(p => p.omonth).ToList() }, JsonRequestBehavior.AllowGet); } [AuthorizeRedirect(RightsConfig.CONST_收入进度, ToolBarConfig.CONST_NotButton, true)] [HttpGet] public ActionResult Income() { return View(); } [HttpGet] public ActionResult Exec() { ViewBag.AuditItems = b_Audit_Items_Bl.GetAuditItemsFromId(0); ViewBag.userRightId = userRightId.Where(d=>d.Equals("AUDIT|64")).FirstOrDefault(); return View(); } [AuthorizeRedirect(RightsConfig.CONST_结算报表, ToolBarConfig.CONST_NotButton, true)] [HttpPost] public JsonResult Exec(DateTime sTime, DateTime eTime, DateTime? bTime, DateTime? fTime, string channel) { _orderService.ExecActCur(); return Json(new { result = true }, JsonRequestBehavior.AllowGet); } [AuthorizeRedirect(RightsConfig.CONST_结算报表, ToolBarConfig.CONST_NotButton, true)] public JsonResult FlushExec2(DateTime sTime, DateTime eTime, DateTime? bTime, DateTime? fTime, string channel) { var ret = _orderService.FlushExecInomce(sTime, eTime, bTime, fTime, channel); return Json(ret, JsonRequestBehavior.AllowGet); } [AuthorizeRedirect(RightsConfig.CONST_结算报表, ToolBarConfig.CONST_NotButton, true)] public JsonResult Exec2(DateTime sTime, DateTime eTime, DateTime? bTime, DateTime? fTime, string channel) { var ret = _orderService.ExecInomce(sTime, eTime, bTime, fTime, channel); return Json(ret, JsonRequestBehavior.AllowGet); } public JsonResult Show() { var data = _orderService.GetIncomeJieSuan(); return Json(new { data }, JsonRequestBehavior.AllowGet); } [AuthorizeRedirect(RightsConfig.CONST_结算报表, ToolBarConfig.CONST_NotButton, true)] [HttpPost] public JsonResult Export(DateTime eTime, DateTime fTime, string queryType) { var result = _orderService.ExportAuditExcel( queryType); return Json(new { result }, JsonRequestBehavior.AllowGet); } [AuthorizeRedirect(RightsConfig.CONST_结算报表, ToolBarConfig.CONST_NotButton, true)] [HttpPost] public JsonResult Query(int itemId, string queryType) { if (itemId == 0) { var monkey = Int32.Parse(DateTime.Now.ToString("yyyyMM")); var resultmonkey = queryAudit.GetAuditResult(monkey, queryType); return Json(new { resultmonkey }, JsonRequestBehavior.AllowGet); } var result = queryAudit.GetItemAuditResult(itemId, queryType); return Json(new { result }, JsonRequestBehavior.AllowGet); } [AuthorizeRedirect(RightsConfig.CONST_结算报表, ToolBarConfig.CONST_NotButton, true)] [HttpPost] public JsonResult GenModule(DateTime btime, DateTime fTime) { GenModule_Price genModule_Price = new GenModule_Price(); genModule_Price.Init_GenModule(btime, fTime.AddDays(1)); return Json(new retMsg() { result = true, retmsg = "生成成功" }, JsonRequestBehavior.AllowGet); } //[HttpPost] public JsonResult MonthIncome(string userid, string yearMonth) { var data = _performanceService.GetMonthInCome(userid, yearMonth); return Json(data, JsonRequestBehavior.AllowGet); } public JsonResult MonthCost(string userid, string yearMonth) { var data = _performanceService.GetMonthCost(userid, yearMonth); return Json(data, JsonRequestBehavior.AllowGet); } //[HttpPost] public JsonResult YearIncome(string userid, string yearMonth) { var data = _performanceService.GetYearInCome(userid, yearMonth); return Json(data, JsonRequestBehavior.AllowGet); } //[AuthorizeRedirect(RightsConfig.CONST_业绩估算, ToolBarConfig.CONST_Other1, false)] public JsonResult Clear() { //var cacheKey = "PerformanceAll"; //var cacheKey2 = "PerformanceXL"; //CacheHelper.Remove(cacheKey); //CacheHelper.Remove(cacheKey2); //var companyList = _cache.GetCompanyVirtual(); //foreach (var item in companyList) //{ // CacheHelper.Remove(cacheKey2 + item); //} var ret = _performanceService.ClearPerformanDay(); return Json(new { result = ret }, JsonRequestBehavior.AllowGet); } public JsonResult SaveMonth() { var ret = _performanceService.SavePerformanMonth(); return Json(new { result = ret }, JsonRequestBehavior.AllowGet); } //private class Performance //{ // public int orderid { get; set; } // public int oyear { get; set; } // /// // /// 使用月份 // /// // public int omonth { get; set; } // /// // /// 使用年份 // /// // public int daycount { get; set; } // public decimal jiazhi { get; set; } // public decimal jzcount { get; set; } // public int channel { get; set; } // /// // /// 开通月份 // /// // public int opmonth { get; set; } // /// // /// 开通年份 // /// // public int opyear { get; set; } // public int type { get; set; } // public int productid { get; set; } // /// // /// 到账月份 // /// // public int amonth { get; set; } // public decimal arrivalpay { get; set; } // public decimal curMonthRefundPrice { get; set; } // public decimal monthRefundPrice { get; set; } // public decimal firstRefundPrice { get; set; } // public int? fmonth { get; set; } //} private class PerformanceCount { public int omonth { get; set; } public string csfu { get; set; } public string cswh { get; set; } public string yj { get; set; } public string fyj { get; set; } public string rz { get; set; } public string lcje { get; set; } public string zyj { get; set; } /// /// 当月业绩 /// public string dyyj { get; set; } /// /// 到账金额 /// public string dzje { get; set; } public string tkfu { get; set; } public string tkwh { get; set; } public string tk1 { get; set; } public string tk2 { get; set; } public string tk3 { get; set; } public string tk4 { get; set; } /// /// 当月退款 /// public string dytk { get; set; } /// /// 已支付未开通 /// public string yzfwkt { get; set; } /// /// 本月到账 /// public string dzsj_ktsj_diff { get; set; } public string djdz { get; set; } public string dj { get; set; } public string djtk { get; set; } public string nextdzje { get; set; } } private class PerformanceOther { public int omonth { get; set; } public string dzje { get; set; } } private class PerformanceView { public int omonth { get; set; } /// /// 订单收入 /// public string ddsr { get; set; } /// /// 预收 /// public string ys { get; set; } public string notUseDj { get; set; } /// /// 已使用订金 /// public string useDj { get; set; } public string tkDj { get; set; } public string ds { get; set; } /// /// 单月订单总收入 /// public string dyddzsr { get; set; } /// /// 单月总退款 /// public string dyztk { get; set; } /// /// 账户收入 /// public string zhsr { get; set; } /// /// 入账 /// public string rz { get; set; } /// /// 预收 /// public string lc { get; set; } public string dytk { get; set; } public string fdytk { get; set; } /// /// 入账退款 /// public string rztk { get; set; } /// /// 预收退款 /// public string lctk { get; set; } /// /// 订金退款 /// public string djtk { get; set; } public string dj { get; set; } } private class XieLieView { public int omonth { get; set; } public string zyrjf { get; set; } public string zywhf { get; set; } public string zyrz { get; set; } public string zyys { get; set; } public string dyrz { get; set; } public string dyys { get; set; } public string ayrz { get; set; } public string ayys { get; set; } } private class OrderRefundView { public int fmonth { get; set; } public decimal refundprice { get; set; } public int refundtype { get; set; } } } }