/* * 待扣款明细 */ using System; using System.Web; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MySystem.Models; using Library; using LitJson; using MySystemLib; namespace MySystem.Areas.Admin.Controllers { [Area("Admin")] [Route("Admin/[controller]/[action]")] public class ToChargeBackRecordSubController : BaseController { public ToChargeBackRecordSubController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString(); } #region 待扣款明细列表 /// /// 根据条件查询待扣款明细列表 /// /// public IActionResult Index(ToChargeBackRecordSub data, string right, string ParentId) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; ViewBag.ParentId = ParentId; return View(); } #endregion #region 根据条件查询待扣款明细列表 /// /// 待扣款明细列表 /// /// public JsonResult IndexData(ToChargeBackRecordSub data, string OrderNo, string StatusSelect, string KindSelect, string CreateDateData, int page = 1, int limit = 30) { Dictionary Fields = new Dictionary(); Fields.Add("ParentId", "1"); string condition = " and Status>-1"; //分期单号 if (!string.IsNullOrEmpty(OrderNo)) { var toChargeByStage = db.ToChargeByStage.FirstOrDefault(m => m.SeoKeyword == OrderNo) ?? new ToChargeByStage(); var toChargeBackRecordSub = db.ToChargeBackRecordSub.FirstOrDefault(m => m.ParentId == toChargeByStage.Id) ?? new ToChargeBackRecordSub(); condition += " and ParentId=" + toChargeByStage.Id; } //待扣类别 if (!string.IsNullOrEmpty(KindSelect)) { condition += " and Kind=" + KindSelect; } //状态 if (!string.IsNullOrEmpty(StatusSelect)) { condition += " and Status=" + StatusSelect; } //创建时间 if (!string.IsNullOrEmpty(CreateDateData)) { string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None); string start = datelist[0]; string end = datelist[1]; condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'"; } Dictionary obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ToChargeBackRecordSub", Fields, "Id desc", "0", page, limit, condition); List> diclist = obj["data"] as List>; foreach (Dictionary dic in diclist) { //状态 int Status = int.Parse(function.CheckInt(dic["Status"].ToString())); dic["StatusName"] = ""; if (Status == 0) { dic["StatusName"] = "待扣款"; } if (Status == 1) { dic["StatusName"] = "已扣款"; } if (Status == 2) { dic["StatusName"] = "扣款中"; } //待扣类别 int Kind = int.Parse(dic["Kind"].ToString()); if (Kind == 0) dic["KindName"] = "创客预扣款"; if (Kind == 1) dic["KindName"] = "盟主预扣款"; if (Kind == 2) dic["KindName"] = "运营中心预扣款"; //分期单号 int ParentId = int.Parse(function.CheckInt(dic["ParentId"].ToString())); var toChargeByStage = db.ToChargeByStage.FirstOrDefault(m => m.Id == ParentId) ?? new ToChargeByStage(); dic["OrderNo"] = toChargeByStage.SeoKeyword; } return Json(obj); } #endregion #region 增加待扣款明细 /// /// 增加或修改待扣款明细信息 /// /// public IActionResult Add(string right, string ParentId) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; ViewBag.ParentId = ParentId; return View(); } #endregion #region 增加待扣款明细 /// /// 增加或修改待扣款明细信息 /// /// [HttpPost] public string Add(ToChargeBackRecordSub data) { Dictionary Fields = new Dictionary(); Fields.Add("ParentId", data.ParentId); Fields.Add("ChargeAmount", data.ChargeAmount); //待扣金额 Fields.Add("Remark", data.Remark); //备注 Fields.Add("StartDate", data.StartDate); //扣款开始时间 Fields.Add("TimeNumber", data.TimeNumber); //期数 Fields.Add("SeoTitle", data.SeoTitle); Fields.Add("SeoKeyword", data.SeoKeyword); Fields.Add("SeoDescription", data.SeoDescription); int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("ToChargeBackRecordSub", Fields, 0); AddSysLog(data.Id.ToString(), "ToChargeBackRecordSub", "add"); db.SaveChanges(); return "success"; } #endregion #region 修改待扣款明细 /// /// 增加或修改待扣款明细信息 /// /// public IActionResult Edit(string right, string ParentId, int Id = 0) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; ViewBag.ParentId = ParentId; ToChargeBackRecordSub editData = db.ToChargeBackRecordSub.FirstOrDefault(m => m.Id == Id) ?? new ToChargeBackRecordSub(); ViewBag.data = editData; return View(); } #endregion #region 修改待扣款明细 /// /// 增加或修改待扣款明细信息 /// /// [HttpPost] public string Edit(ToChargeBackRecordSub data) { Dictionary Fields = new Dictionary(); var toChargeBackRecordSub = db.ToChargeBackRecordSub.FirstOrDefault(m => m.Id == data.Id) ?? new ToChargeBackRecordSub(); var toChargeByStage = db.ToChargeByStage.FirstOrDefault(m => m.Id == toChargeBackRecordSub.ParentId) ?? new ToChargeByStage(); if (toChargeByStage.QueryCount > 0) { return "该扣款记录正处于扣款中或已经结束,不能修改!"; } if (toChargeBackRecordSub.ChargeAmount != data.ChargeAmount) { var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == toChargeByStage.UserId) ?? new UserAccount(); if (toChargeBackRecordSub.ChargeAmount > data.ChargeAmount) { toChargeByStage.TotalAmount -= toChargeBackRecordSub.ChargeAmount - data.ChargeAmount; if (toChargeBackRecordSub.Kind == 0) userAccount.ToChargeAmount -= toChargeBackRecordSub.ChargeAmount - data.ChargeAmount; if (toChargeBackRecordSub.Kind == 1) userAccount.LeaderToChargeAmount -= toChargeBackRecordSub.ChargeAmount - data.ChargeAmount; if (toChargeBackRecordSub.Kind == 2) userAccount.OperateToChargeAmount -= toChargeBackRecordSub.ChargeAmount - data.ChargeAmount; } if (toChargeBackRecordSub.ChargeAmount < data.ChargeAmount) { toChargeByStage.TotalAmount += data.ChargeAmount - toChargeBackRecordSub.ChargeAmount; if (toChargeBackRecordSub.Kind == 0) userAccount.ToChargeAmount += data.ChargeAmount - toChargeBackRecordSub.ChargeAmount; if (toChargeBackRecordSub.Kind == 1) userAccount.LeaderToChargeAmount += data.ChargeAmount - toChargeBackRecordSub.ChargeAmount; if (toChargeBackRecordSub.Kind == 2) userAccount.OperateToChargeAmount += data.ChargeAmount - toChargeBackRecordSub.ChargeAmount; } } Fields.Add("ChargeAmount", data.ChargeAmount); //待扣金额 Fields.Add("Remark", data.Remark); //备注 Fields.Add("StartDate", data.StartDate); //扣款开始时间 Fields.Add("TimeNumber", data.TimeNumber); //期数 Fields.Add("SeoTitle", data.SeoTitle); new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ToChargeBackRecordSub", Fields, data.Id); AddSysLog(data.Id.ToString(), "ToChargeBackRecordSub", "update"); db.SaveChanges(); return "success"; } #endregion #region 删除待扣款明细信息 /// /// 删除待扣款明细信息 /// /// public string Delete(string Id) { string[] idlist = Id.Split(new char[] { ',' }); AddSysLog(Id, "ToChargeBackRecordSub", "del"); foreach (string subid in idlist) { int id = int.Parse(subid); Dictionary Fields = new Dictionary(); Fields.Add("Status", -1); new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ToChargeBackRecordSub", Fields, id); } db.SaveChanges(); return "success"; } #endregion #region 开启 /// /// 开启 /// /// public string Open(string Id) { string[] idlist = Id.Split(new char[] { ',' }); AddSysLog(Id, "ToChargeBackRecordSub", "open"); foreach (string subid in idlist) { int id = int.Parse(subid); Dictionary Fields = new Dictionary(); Fields.Add("Status", 1); new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ToChargeBackRecordSub", Fields, id); } db.SaveChanges(); return "success"; } #endregion #region 关闭 /// /// 关闭 /// /// public string Close(string Id) { string[] idlist = Id.Split(new char[] { ',' }); AddSysLog(Id, "ToChargeBackRecordSub", "close"); foreach (string subid in idlist) { int id = int.Parse(subid); Dictionary Fields = new Dictionary(); Fields.Add("Status", 0); new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ToChargeBackRecordSub", Fields, id); } db.SaveChanges(); return "success"; } #endregion #region 排序 /// /// 排序 /// /// public string Sort(int Id, int Sort) { new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("ToChargeBackRecordSub", Sort, Id); AddSysLog(Id.ToString(), "ToChargeBackRecordSub", "sort"); return "success"; } #endregion #region 导入数据 /// /// 导入数据 /// /// public string Import(string ExcelData) { ExcelData = HttpUtility.UrlDecode(ExcelData); JsonData list = JsonMapper.ToObject(ExcelData); for (int i = 1; i < list.Count; i++) { JsonData dr = list[i]; db.ToChargeBackRecordSub.Add(new ToChargeBackRecordSub() { CreateDate = DateTime.Now, UpdateDate = DateTime.Now, }); db.SaveChanges(); } AddSysLog("0", "ToChargeBackRecordSub", "Import"); return "success"; } #endregion #region 导出Excel /// /// 导出Excel /// /// public JsonResult ExportExcel(ToChargeBackRecordSub data) { Dictionary Fields = new Dictionary(); Fields.Add("CreateDate", "3"); //时间 string condition = " and Status>-1"; Dictionary obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ToChargeBackRecordSub", Fields, "Id desc", "0", 1, 20000, condition, "ChargeAmount,Remark", false); List> diclist = obj["data"] as List>; foreach (Dictionary dic in diclist) { } Dictionary result = new Dictionary(); result.Add("Status", "1"); result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx"); result.Add("Obj", diclist); Dictionary ReturnFields = new Dictionary(); ReturnFields.Add("ChargeAmount", "待扣金额"); ReturnFields.Add("Remark", "备注"); result.Add("Fields", ReturnFields); AddSysLog("0", "ToChargeBackRecordSub", "ExportExcel"); return Json(result); } #endregion } }