/* * 机具费率调整申请 */ 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 PosMachinesFeeChangeRecordController : BaseController { public PosMachinesFeeChangeRecordController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString(); } #region 机具费率调整申请列表 /// /// 根据条件查询机具费率调整申请列表 /// /// public IActionResult Index(PosMachinesFeeChangeRecord data, string right) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; return View(); } #endregion #region 根据条件查询机具费率调整申请列表 /// /// 机具费率调整申请列表 /// /// public JsonResult IndexData(PosMachinesFeeChangeRecord data, string UserIdMakerCode, string StatusSelect, string UserIdRealName, string PosUserIdMakerCode, string PosUserIdRealName, int page = 1, int limit = 30) { Dictionary Fields = new Dictionary(); Fields.Add("CreateDate", "3"); //时间 Fields.Add("PosSn", "1"); //机具SN Fields.Add("MerNo", "1"); //商户号 Fields.Add("Sort", "0"); // string condition = " and Status>=-1"; if (!string.IsNullOrEmpty(StatusSelect)) { condition += " and Status=" + StatusSelect; } //创客创客编号 if (!string.IsNullOrEmpty(UserIdMakerCode)) { condition += " and UserId in (select UserId from UsersForMakerCode where MakerCode='" + UserIdMakerCode + "')"; } //创客真实姓名 if (!string.IsNullOrEmpty(UserIdRealName)) { condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')"; } //机具所属人创客编号 if (!string.IsNullOrEmpty(PosUserIdMakerCode)) { condition += " and PosUserId in (select PosUserId from UsersForMakerCode where MakerCode='" + PosUserIdMakerCode + "')"; } //机具所属人真实姓名 if (!string.IsNullOrEmpty(PosUserIdRealName)) { condition += " and PosUserId in (select PosUserId from UsersForRealName where RealName='" + PosUserIdRealName + "')"; } Dictionary obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesFeeChangeRecord", Fields, "Id desc", "0", page, limit, condition); List> diclist = obj["data"] as List>; foreach (Dictionary dic in diclist) { //创客 int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString())); Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users(); dic["UserIdMakerCode"] = userid_Users.MakerCode; dic["UserIdRealName"] = userid_Users.RealName; dic.Remove("UserId"); //机具所属人 int PosUserId = int.Parse(function.CheckInt(dic["PosUserId"].ToString())); Users posuserid_Users = db.Users.FirstOrDefault(m => m.Id == PosUserId) ?? new Users(); dic["PosUserIdMakerCode"] = posuserid_Users.MakerCode; dic["PosUserIdRealName"] = posuserid_Users.RealName; dic.Remove("PosUserId"); //状态 int Status = int.Parse(function.CheckInt(dic["Status"].ToString())); if (Status == 0) dic["Status"] = "处理中"; if (Status == 1) dic["Status"] = "成功"; if (Status == -1) dic["Status"] = "失败"; //产品类型 dic["Sort"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["Sort"].ToString())); } return Json(obj); } #endregion #region 增加机具费率调整申请 /// /// 增加或修改机具费率调整申请信息 /// /// public IActionResult Add(string right) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; return View(); } #endregion #region 增加机具费率调整申请 /// /// 增加或修改机具费率调整申请信息 /// /// [HttpPost] public string Add(PosMachinesFeeChangeRecord data) { Dictionary Fields = new Dictionary(); Fields.Add("UserId", data.UserId); //创客 Fields.Add("ChangeFee", data.ChangeFee); //调整费率 Fields.Add("PosSn", data.PosSn); //机具SN Fields.Add("MerNo", data.MerNo); //商户号 Fields.Add("PosUserId", data.PosUserId); //机具所属人 Fields.Add("SeoTitle", data.SeoTitle); Fields.Add("SeoKeyword", data.SeoKeyword); Fields.Add("SeoDescription", data.SeoDescription); int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMachinesFeeChangeRecord", Fields, 0); AddSysLog(data.Id.ToString(), "PosMachinesFeeChangeRecord", "add"); db.SaveChanges(); return "success"; } #endregion #region 修改机具费率调整申请 /// /// 增加或修改机具费率调整申请信息 /// /// public IActionResult Edit(string right, int Id = 0) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; PosMachinesFeeChangeRecord editData = db.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesFeeChangeRecord(); ViewBag.data = editData; return View(); } #endregion #region 修改机具费率调整申请 /// /// 增加或修改机具费率调整申请信息 /// /// [HttpPost] public string Edit(PosMachinesFeeChangeRecord data) { Dictionary Fields = new Dictionary(); Fields.Add("UserId", data.UserId); //创客 Fields.Add("ChangeFee", data.ChangeFee); //调整费率 Fields.Add("PosSn", data.PosSn); //机具SN Fields.Add("MerNo", data.MerNo); //商户号 Fields.Add("PosUserId", data.PosUserId); //机具所属人 Fields.Add("SeoTitle", data.SeoTitle); Fields.Add("SeoKeyword", data.SeoKeyword); Fields.Add("SeoDescription", data.SeoDescription); new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesFeeChangeRecord", Fields, data.Id); AddSysLog(data.Id.ToString(), "PosMachinesFeeChangeRecord", "update"); db.SaveChanges(); return "success"; } #endregion #region 删除机具费率调整申请信息 /// /// 删除机具费率调整申请信息 /// /// public string Delete(string Id) { string[] idlist = Id.Split(new char[] { ',' }); AddSysLog(Id, "PosMachinesFeeChangeRecord", "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("PosMachinesFeeChangeRecord", Fields, id); } db.SaveChanges(); return "success"; } #endregion #region 开启 /// /// 开启 /// /// public string Open(string Id) { string[] idlist = Id.Split(new char[] { ',' }); AddSysLog(Id, "PosMachinesFeeChangeRecord", "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("PosMachinesFeeChangeRecord", Fields, id); } db.SaveChanges(); return "success"; } #endregion #region 关闭 /// /// 关闭 /// /// public string Close(string Id) { string[] idlist = Id.Split(new char[] { ',' }); AddSysLog(Id, "PosMachinesFeeChangeRecord", "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("PosMachinesFeeChangeRecord", Fields, id); } db.SaveChanges(); return "success"; } #endregion #region 排序 /// /// 排序 /// /// public string Sort(int Id, int Sort) { new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMachinesFeeChangeRecord", Sort, Id); AddSysLog(Id.ToString(), "PosMachinesFeeChangeRecord", "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.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord() { CreateDate = DateTime.Now, UpdateDate = DateTime.Now, }); db.SaveChanges(); } AddSysLog("0", "PosMachinesFeeChangeRecord", "Import"); return "success"; } #endregion #region 导出Excel /// /// 导出Excel /// /// public JsonResult ExportExcel(PosMachinesFeeChangeRecord data, string UserIdMakerCode, string UserIdRealName, string PosUserIdMakerCode, string PosUserIdRealName) { Dictionary Fields = new Dictionary(); Fields.Add("CreateDate", "3"); //时间 Fields.Add("PosSn", "1"); //机具SN Fields.Add("MerNo", "1"); //商户号 string condition = " and Status>-1"; //创客创客编号 if (!string.IsNullOrEmpty(UserIdMakerCode)) { condition += " and UserId in (select UserId from UsersForMakerCode where MakerCode='" + UserIdMakerCode + "')"; } //创客真实姓名 if (!string.IsNullOrEmpty(UserIdRealName)) { condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')"; } //机具所属人创客编号 if (!string.IsNullOrEmpty(PosUserIdMakerCode)) { condition += " and PosUserId in (select PosUserId from UsersForMakerCode where MakerCode='" + PosUserIdMakerCode + "')"; } //机具所属人真实姓名 if (!string.IsNullOrEmpty(PosUserIdRealName)) { condition += " and PosUserId in (select PosUserId from UsersForRealName where RealName='" + PosUserIdRealName + "')"; } Dictionary obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesFeeChangeRecord", Fields, "Id desc", "0", 1, 20000, condition, "UserId,ChangeFee,PosSn,MerNo,PosUserId", false); List> diclist = obj["data"] as List>; foreach (Dictionary dic in diclist) { //创客 int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString())); Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users(); dic["UserIdMakerCode"] = userid_Users.MakerCode; dic["UserIdRealName"] = userid_Users.RealName; dic.Remove("UserId"); //机具所属人 int PosUserId = int.Parse(function.CheckInt(dic["PosUserId"].ToString())); Users posuserid_Users = db.Users.FirstOrDefault(m => m.Id == PosUserId) ?? new Users(); dic["PosUserIdMakerCode"] = posuserid_Users.MakerCode; dic["PosUserIdRealName"] = posuserid_Users.RealName; dic.Remove("PosUserId"); } 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("UserIdMakerCode", "创客创客编号"); ReturnFields.Add("UserIdRealName", "创客真实姓名"); ReturnFields.Add("ChangeFee", "调整费率"); ReturnFields.Add("PosSn", "机具SN"); ReturnFields.Add("MerNo", "商户号"); ReturnFields.Add("PosUserIdMakerCode", "机具所属人创客编号"); ReturnFields.Add("PosUserIdRealName", "机具所属人真实姓名"); result.Add("Fields", ReturnFields); AddSysLog("0", "PosMachinesFeeChangeRecord", "ExportExcel"); return Json(result); } #endregion } }