/* * 激活奖励记录 */ using System; using System.Web; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Data; 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; namespace MySystem.Areas.Admin.Controllers { [Area("Admin")] [Route("Admin/[controller]/[action]")] public class ActiveRewardController : BaseController { public ActiveRewardController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString(); } #region 激活奖励记录列表 /// /// 根据条件查询激活奖励记录列表 /// /// public IActionResult Index(ActiveReward data, string right, string BrandId) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; ViewBag.BrandId = BrandId; return View(); } #endregion #region 根据条件查询激活奖励记录列表 /// /// 激活奖励记录列表 /// /// public JsonResult IndexData(ActiveReward data, string right, string BrandId, string MerchantNo, string MerchantName, string MakerCode, string RealName, string MerMakerCode, string MerRealName, string ParentMakerCode, string ParentRealName, string ParentParentMakerCode, string ParentParentRealName, string StoreNo, string StoreName, string SnTypeSelect, string ActTypeSelect, string ActDateData, int page = 1, int limit = 30) { Dictionary Fields = new Dictionary(); Fields.Add("BrandId", "1"); Fields.Add("KqMerNo", "1"); //快钱商户编号 Fields.Add("KqSnNo", "1"); //快钱SN号 Fields.Add("ActDate", "3"); //激活时间 Fields.Add("TopUserId", "0"); //顶级创客 ViewBag.RightInfo = RightInfo; ViewBag.right = right; ViewBag.BrandId = BrandId; string condition = " and Status>-1"; //商户编号 if (!string.IsNullOrEmpty(MerchantNo)) { condition += " and MerchantId in (select MerchantId from MerchantForCode where MakerCode='" + MerchantNo + "')"; } //商户名称 if (!string.IsNullOrEmpty(MerchantName)) { condition += " and MerchantId in (select MerchantId from MerchantForName where RealName='" + MerchantName + "')"; } //创客编号 if (!string.IsNullOrEmpty(MakerCode)) { condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')"; } //创客名称 if (!string.IsNullOrEmpty(RealName)) { condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')"; } //商户创客编号 if (!string.IsNullOrEmpty(MerMakerCode)) { condition += " and MerUserId in (select UserId from UserForMakerCode where MakerCode='" + MerMakerCode + "')"; } //商户创客名称 if (!string.IsNullOrEmpty(MerRealName)) { condition += " and MerUserId in (select UserId from UserForRealName where RealName='" + MerRealName + "')"; } //上级创客编号 if (!string.IsNullOrEmpty(ParentMakerCode)) { condition += " and ParentUserId in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')"; } //上级创客名称 if (!string.IsNullOrEmpty(ParentRealName)) { condition += " and ParentUserId in (select UserId from UserForRealName where RealName='" + ParentRealName + "')"; } //上上级创客编号 if (!string.IsNullOrEmpty(ParentParentMakerCode)) { condition += " and ParentParentUserId in (select UserId from UserForMakerCode where MakerCode='" + ParentParentMakerCode + "')"; } //上上级创客名称 if (!string.IsNullOrEmpty(ParentParentRealName)) { condition += " and ParentParentUserId in (select UserId from UserForRealName where RealName='" + ParentParentRealName + "')"; } //仓库编号 if (!string.IsNullOrEmpty(StoreNo)) { condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')"; } //仓库名称 if (!string.IsNullOrEmpty(RealName)) { condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreName + "')"; } //机具类型 if(!string.IsNullOrEmpty(SnTypeSelect)) { condition += " and SnType=" + SnTypeSelect; } //激活类型 if(!string.IsNullOrEmpty(ActTypeSelect)) { condition += " and ActType=" + ActTypeSelect; } if(!string.IsNullOrEmpty(ActDateData)) { string[] datelist = ActDateData.Split(new string[] { " - " }, StringSplitOptions.None); string start = datelist[0]; string end = datelist[1]; condition += " and ActDate>='" + start + " 00:00:00' and ActDate<='" + end + " 23:59:59'"; } Dictionary obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ActiveReward", Fields, "Id desc", "0", page, limit, condition); List> diclist = obj["data"] as List>; foreach (Dictionary dic in diclist) { //商户 int MerchantId = int.Parse(dic["MerchantId"].ToString()); MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new MerchantInfo(); dic["MerchantNo"] = ""; dic["MerchantName"] = merchant.Name; //奖励创客 int UserId = int.Parse(dic["UserId"].ToString()); Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users(); dic["MakerCode"] = user.MakerCode; dic["RealName"] = user.RealName; //顶级创客 int TopUserId = int.Parse(dic["TopUserId"].ToString()); Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users(); dic["TopMakerCode"] = tuser.MakerCode; dic["TopRealName"] = tuser.RealName; //直属创客 int MerUserId = int.Parse(dic["MerUserId"].ToString()); Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users(); dic["MerMakerCode"] = muser.MakerCode; dic["MerRealName"] = muser.RealName; //上级创客 int ParentUserId = int.Parse(dic["ParentUserId"].ToString()); Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users(); dic["ParentMakerCode"] = puser.MakerCode; dic["ParentRealName"] = puser.RealName; //上上级创客 int ParentParentUserId = int.Parse(dic["ParentParentUserId"].ToString()); Users ppuser = db.Users.FirstOrDefault(m => m.Id == ParentParentUserId) ?? new Users(); dic["ParentParentMakerCode"] = ppuser.MakerCode; dic["ParentParentRealName"] = ppuser.RealName; //申请创客 int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString()); Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users(); dic["SnApplyMakerCode"] = snuser.MakerCode; dic["SnApplyRealName"] = snuser.RealName; //SN仓库 int SnStoreId = int.Parse(dic["SnStoreId"].ToString()); StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse(); dic["StoreNo"] = store.StoreNo; dic["StoreName"] = store.StoreName; //机具类型 int SnType = int.Parse(dic["SnType"].ToString()); if(SnType == 0) dic["SnType"] = "购买机具"; if(SnType == 1) dic["SnType"] = "赠送机具"; //激活类型 int ActType = int.Parse(dic["ActType"].ToString()); if(ActType == 0) dic["ActType"] = "正常激活"; if(ActType == 1) dic["ActType"] = "首次已激活MPOS"; if(ActType == 2) dic["ActType"] = "首次已激活KPOS"; if(ActType == 3) dic["ActType"] = "循环机划拨激活"; } Dictionary other = new Dictionary(); string RewardAmount = "0.00";//奖励金额 DataTable dt = OtherMySqlConn.dtable("select sum(RewardAmount) from ActiveReward where BrandId='" + ViewBag.BrandId + "'" + condition); if (dt.Rows.Count > 0) { RewardAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2"); } other.Add("RewardAmount", RewardAmount); obj.Add("other", other); return Json(obj); } #endregion #region 增加激活奖励记录 /// /// 增加或修改激活奖励记录信息 /// /// public IActionResult Add(string right) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; return View(); } #endregion #region 增加激活奖励记录 /// /// 增加或修改激活奖励记录信息 /// /// [HttpPost] public string Add(ActiveReward data) { Dictionary Fields = new Dictionary(); Fields.Add("SeoTitle", data.SeoTitle); Fields.Add("SeoKeyword", data.SeoKeyword); Fields.Add("SeoDescription", data.SeoDescription); int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("ActiveReward", Fields, 0); AddSysLog(data.Id.ToString(), "ActiveReward", "add"); db.SaveChanges(); return "success"; } #endregion #region 修改激活奖励记录 /// /// 增加或修改激活奖励记录信息 /// /// public IActionResult Edit(string right, int Id = 0) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; ActiveReward editData = db.ActiveReward.FirstOrDefault(m => m.Id == Id) ?? new ActiveReward(); ViewBag.data = editData; return View(); } #endregion #region 修改激活奖励记录 /// /// 增加或修改激活奖励记录信息 /// /// [HttpPost] public string Edit(ActiveReward data) { Dictionary Fields = new Dictionary(); Fields.Add("SeoTitle", data.SeoTitle); Fields.Add("SeoKeyword", data.SeoKeyword); Fields.Add("SeoDescription", data.SeoDescription); new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ActiveReward", Fields, data.Id); AddSysLog(data.Id.ToString(), "ActiveReward", "update"); db.SaveChanges(); return "success"; } #endregion #region 删除激活奖励记录信息 /// /// 删除激活奖励记录信息 /// /// public string Delete(string Id) { string[] idlist = Id.Split(new char[] { ',' }); AddSysLog(Id, "ActiveReward", "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("ActiveReward", Fields, id); } db.SaveChanges(); return "success"; } #endregion #region 开启 /// /// 开启 /// /// public string Open(string Id) { string[] idlist = Id.Split(new char[] { ',' }); AddSysLog(Id, "ActiveReward", "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("ActiveReward", Fields, id); } db.SaveChanges(); return "success"; } #endregion #region 关闭 /// /// 关闭 /// /// public string Close(string Id) { string[] idlist = Id.Split(new char[] { ',' }); AddSysLog(Id, "ActiveReward", "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("ActiveReward", Fields, id); } db.SaveChanges(); return "success"; } #endregion #region 排序 /// /// 排序 /// /// public string Sort(int Id, int Sort) { new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("ActiveReward", Sort, Id); AddSysLog(Id.ToString(), "ActiveReward", "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.ActiveReward.Add(new ActiveReward() { CreateDate = DateTime.Now, UpdateDate = DateTime.Now, }); db.SaveChanges(); } AddSysLog("0", "ActiveReward", "Import"); return "success"; } #endregion #region 导出Excel /// /// 导出Excel /// /// public JsonResult ExportExcel(ActiveReward data, string MerchantNo, string MerchantName, string MakerCode, string RealName, string MerMakerCode, string MerRealName, string ParentMakerCode, string ParentRealName, string ParentParentMakerCode, string ParentParentRealName, string StoreNo, string StoreName, string SnTypeSelect, string ActTypeSelect) { Dictionary Fields = new Dictionary(); Fields.Add("BrandId", "1"); Fields.Add("KqMerNo", "1"); //快钱商户编号 Fields.Add("KqSnNo", "1"); //快钱SN号 Fields.Add("ActDate", "3"); //激活时间 Fields.Add("TopUserId", "0"); //顶级创客 string condition = " and Status>-1"; //商户编号 if (!string.IsNullOrEmpty(MerchantNo)) { condition += " and MerchantId in (select MerchantId from MerchantForCode where MakerCode='" + MerchantNo + "')"; } //商户名称 if (!string.IsNullOrEmpty(MerchantName)) { condition += " and MerchantId in (select MerchantId from MerchantForName where RealName='" + MerchantName + "')"; } //创客编号 if (!string.IsNullOrEmpty(MakerCode)) { condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')"; } //创客名称 if (!string.IsNullOrEmpty(RealName)) { condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')"; } //商户创客编号 if (!string.IsNullOrEmpty(MerMakerCode)) { condition += " and MerUserId in (select UserId from UserForMakerCode where MakerCode='" + MerMakerCode + "')"; } //商户创客名称 if (!string.IsNullOrEmpty(MerRealName)) { condition += " and MerUserId in (select UserId from UserForRealName where RealName='" + MerRealName + "')"; } //上级创客编号 if (!string.IsNullOrEmpty(ParentMakerCode)) { condition += " and ParentUserId in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')"; } //上级创客名称 if (!string.IsNullOrEmpty(ParentRealName)) { condition += " and ParentUserId in (select UserId from UserForRealName where RealName='" + ParentRealName + "')"; } //上上级创客编号 if (!string.IsNullOrEmpty(ParentParentMakerCode)) { condition += " and ParentParentUserId in (select UserId from UserForMakerCode where MakerCode='" + ParentParentMakerCode + "')"; } //上上级创客名称 if (!string.IsNullOrEmpty(ParentParentRealName)) { condition += " and ParentParentUserId in (select UserId from UserForRealName where RealName='" + ParentParentRealName + "')"; } //仓库编号 if (!string.IsNullOrEmpty(StoreNo)) { condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')"; } //仓库名称 if (!string.IsNullOrEmpty(RealName)) { condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreName + "')"; } //机具类型 if(!string.IsNullOrEmpty(SnTypeSelect)) { condition += " and SnType=" + SnTypeSelect; } //激活类型 if(!string.IsNullOrEmpty(ActTypeSelect)) { condition += " and ActType=" + ActTypeSelect; } Dictionary obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ActiveReward", Fields, "Id desc", "0", 1, 20000, condition, "MerchantId,ActDate,CreateDate,UserId,MerUserId,ParentUserId,ParentParentUserId,TopUserId,KqMerNo,KqSnNo,SnType,ActType,SnStoreId,SnApplyUserId,RewardAmount", false); List> diclist = obj["data"] as List>; foreach (Dictionary dic in diclist) { //商户 int MerchantId = int.Parse(dic["MerchantId"].ToString()); MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new MerchantInfo(); dic["MerchantNo"] = ""; dic["MerchantName"] = merchant.Name; //奖励创客 int UserId = int.Parse(dic["UserId"].ToString()); Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users(); dic["MakerCode"] = user.MakerCode; dic["RealName"] = user.RealName; //顶级创客 int TopUserId = int.Parse(dic["TopUserId"].ToString()); Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users(); dic["TopMakerCode"] = tuser.MakerCode; dic["TopRealName"] = tuser.RealName; //直属创客 int MerUserId = int.Parse(dic["MerUserId"].ToString()); Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users(); dic["MerMakerCode"] = muser.MakerCode; dic["MerRealName"] = muser.RealName; //上级创客 int ParentUserId = int.Parse(dic["ParentUserId"].ToString()); Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users(); dic["ParentMakerCode"] = puser.MakerCode; dic["ParentRealName"] = puser.RealName; //上上级创客 int ParentParentUserId = int.Parse(dic["ParentParentUserId"].ToString()); Users ppuser = db.Users.FirstOrDefault(m => m.Id == ParentParentUserId) ?? new Users(); dic["ParentParentMakerCode"] = ppuser.MakerCode; dic["ParentParentRealName"] = ppuser.RealName; //申请创客 int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString()); Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users(); dic["SnApplyMakerCode"] = snuser.MakerCode; dic["SnApplyRealName"] = snuser.RealName; //SN仓库 int SnStoreId = int.Parse(dic["SnStoreId"].ToString()); StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse(); dic["StoreNo"] = store.StoreNo; dic["StoreName"] = store.StoreName; //机具类型 int SnType = int.Parse(dic["SnType"].ToString()); if(SnType == 0) dic["SnType"] = "购买机具"; if(SnType == 1) dic["SnType"] = "赠送机具"; //激活类型 int ActType = int.Parse(dic["ActType"].ToString()); if(ActType == 0) dic["ActType"] = "正常激活"; if(ActType == 1) dic["ActType"] = "首次已激活MPOS"; if(ActType == 2) dic["ActType"] = "首次已激活KPOS"; if(ActType == 3) dic["ActType"] = "循环机划拨激活"; dic.Remove("MerchantId"); dic.Remove("UserId"); dic.Remove("MerUserId"); dic.Remove("ParentUserId"); dic.Remove("ParentParentUserId"); dic.Remove("SnApplyUserId"); dic.Remove("SnStoreId"); } 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("MerchantNo", "商户编号"); ReturnFields.Add("MerchantName", "商户名称"); ReturnFields.Add("ActDate", "激活日期"); ReturnFields.Add("CreateDate", "奖励时间"); ReturnFields.Add("MakerCode", "奖励创客编号"); ReturnFields.Add("RealName", "奖励创客名称"); ReturnFields.Add("MerMakerCode", "直属创客编号"); ReturnFields.Add("MerRealName", "直属创客名称"); ReturnFields.Add("ParentMakerCode", "上级创客编码"); ReturnFields.Add("ParentRealName", "上级创客名称"); ReturnFields.Add("ParentParentMakerCode", "上上级创客编码"); ReturnFields.Add("ParentParentRealName", "上上级创客名称"); ReturnFields.Add("TopMakerCode", "顶级创客编码"); ReturnFields.Add("TopRealName", "顶级创客名称"); ReturnFields.Add("KqMerNo", "快钱商户编号"); ReturnFields.Add("KqSnNo", "快钱SN号"); ReturnFields.Add("SnType", "机具类型"); ReturnFields.Add("ActType", "激活类型"); ReturnFields.Add("StoreNo", "SN仓库编号"); ReturnFields.Add("StoreName", "SN仓库名称"); ReturnFields.Add("SnApplyMakerCode", "机具申请创客编号"); ReturnFields.Add("SnApplyRealName", "机具申请创客姓名"); ReturnFields.Add("RewardAmount", "奖励金额(元)"); result.Add("Fields", ReturnFields); AddSysLog("0", "ActiveReward", "ExportExcel"); return Json(result); } #endregion } }