using System; using System.Collections.Generic; using System.Linq; using System.Data; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.AspNetCore.Authorization; using System.Web; using MySystem.MainModels; using LitJson; using Library; namespace MySystem.Areas.Api.Controllers.v1.pos { [Area("Api")] [Route("Api/v1/pos/[controller]/[action]")] public class ActiveRewardController : BaseController { public ActiveRewardController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString(); } #region 创客-首页-我的业绩-个人业绩-激活商户-每月明细 [Authorize] public JsonResult ActMerchantForMonth(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = ActMerchantForMonthDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> ActMerchantForMonthDo(string value) { JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客 string TradeMonth = data["TradeMonth"].ToString(); //交易月 int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); List> dataList = new List>(); DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"); if (DateTime.Now.ToString("yyyyMM") != TradeMonth) { start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00").AddHours(1).AddDays(-1).AddMonths(1); } if (PageNum > 1) { int skipNum = PageSize * (PageNum - 1); start = start.AddDays(-skipNum); } for (int i = 0; i < PageSize; i++) { DateTime date = start.AddDays(-i); string Month = date.ToString("yyyyMM"); string Date = date.ToString("yyyyMMdd"); // if (Date != DateTime.Now.ToString("yyyyMMdd")) // { Dictionary curData = new Dictionary(); DataTable dt = OtherMySqlConn.dtable("select sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'self' and UserId = " + UserId + " and TradeMonth = " + Month + " and SeoKeyword = " + Date + ""); foreach (DataRow item in dt.Rows) { var ActTotal = Convert.ToInt32(function.CheckInt(item["sum"].ToString())); curData.Add("Date", date.ToString("yyyy-MM-dd")); //时间 curData.Add("ActTotal", ActTotal); //总激活 } //产品列表 List> TypeList = new List>(); DataTable dts = OtherMySqlConn.dtable("select BrandId, sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'self' and UserId = " + UserId + " and TradeMonth = " + Month + " and SeoKeyword = " + Date + " GROUP BY BrandId"); foreach (DataRow item in dts.Rows) { Dictionary TypeCount = new Dictionary(); var Id = Convert.ToInt32(item["BrandId"]); var query = maindb.KqProducts.FirstOrDefault(m => m.Id == Id); var Count = Convert.ToInt32(function.CheckInt(item["sum"].ToString())); if (Count > 0) { TypeCount.Add("Brand", query.Name); //产品名称 TypeCount.Add("Count", Count); //激活数 TypeList.Add(TypeCount); } } curData.Add("TypeList", TypeList); dataList.Add(curData); // } } return dataList; } #endregion #region 创客-首页-我的业绩-个人业绩-激活商户-近半年 [Authorize] public JsonResult ActMerchantForHalfYear(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = ActMerchantForHalfYearDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> ActMerchantForHalfYearDo(string value) { JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客 int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); List> dataList = new List>(); for (int i = 0; i < 6; i++) { DateTime Month = DateTime.Now.AddMonths(-i); var TradeMonth = Month.ToString("yyyyMM"); Dictionary curData = new Dictionary(); curData.Add("TradeMonth", Month.ToString("yyyy-MM")); //交易月份 DataTable dt = OtherMySqlConn.dtable("select sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'self' and UserId = " + UserId + " and TradeMonth = " + TradeMonth + ""); foreach (DataRow item in dt.Rows) { var ActTotal = Convert.ToInt32(function.CheckInt(item["sum"].ToString())); curData.Add("ActTotal", ActTotal); //总激活 } //产品列表 List> TypeList = new List>(); DataTable dts = OtherMySqlConn.dtable("select BrandId, sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'self' and UserId = " + UserId + " and TradeMonth = " + TradeMonth + " GROUP BY BrandId"); foreach (DataRow item in dts.Rows) { Dictionary TypeCount = new Dictionary(); var Id = Convert.ToInt32(item["BrandId"]); var query = maindb.KqProducts.FirstOrDefault(m => m.Id == Id); var Count = Convert.ToInt32(function.CheckInt(item["sum"].ToString())); if (Count > 0) { TypeCount.Add("Brand", query.Name); //产品名称 TypeCount.Add("Count", Count); //激活数 TypeList.Add(TypeCount); } } curData.Add("TypeList", TypeList); dataList.Add(curData); } return dataList; } #endregion #region 创客-首页-我的业绩-团队业绩-激活商户-每月明细 [Authorize] public JsonResult TeamActMerchantForMonth(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = TeamActMerchantForMonthDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> TeamActMerchantForMonthDo(string value) { JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客 string TradeMonth = data["TradeMonth"].ToString(); //交易月 int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); List> dataList = new List>(); DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"); if (DateTime.Now.ToString("yyyyMM") != TradeMonth) { start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00").AddHours(1).AddDays(-1).AddMonths(1); } if (PageNum > 1) { int skipNum = PageSize * (PageNum - 1); start = start.AddDays(-skipNum); } for (int i = 0; i < PageSize; i++) { DateTime date = start.AddDays(-i); string Month = date.ToString("yyyyMM"); string Date = date.ToString("yyyyMMdd"); // if (Date != DateTime.Now.ToString("yyyyMMdd")) // { Dictionary curData = new Dictionary(); DataTable dt = OtherMySqlConn.dtable("select sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'team' and UserId = " + UserId + " and TradeMonth = " + Month + " and SeoKeyword = " + Date + ""); foreach (DataRow item in dt.Rows) { var ActTotal = Convert.ToInt32(function.CheckInt(item["sum"].ToString())); curData.Add("Date", date.ToString("yyyy-MM-dd")); //时间 curData.Add("ActTotal", ActTotal); //总激活 } //产品列表 List> TypeList = new List>(); DataTable dts = OtherMySqlConn.dtable("select BrandId, sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'team' and UserId = " + UserId + " and TradeMonth = " + Month + " and SeoKeyword = " + Date + " GROUP BY BrandId"); foreach (DataRow item in dts.Rows) { Dictionary TypeCount = new Dictionary(); var Id = Convert.ToInt32(item["BrandId"]); var query = maindb.KqProducts.FirstOrDefault(m => m.Id == Id); var Count = Convert.ToInt32(function.CheckInt(item["sum"].ToString())); if (Count > 0) { TypeCount.Add("Brand", query.Name); //产品名称 TypeCount.Add("Count", Count); //激活数 TypeList.Add(TypeCount); } } curData.Add("TypeList", TypeList); dataList.Add(curData); // } } return dataList; } #endregion #region 创客-首页-我的业绩-团队业绩-激活商户-近半年 [Authorize] public JsonResult TeamActMerchantForHalfYear(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = TeamActMerchantForHalfYearDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> TeamActMerchantForHalfYearDo(string value) { JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客 int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); List> dataList = new List>(); for (int i = 0; i < 6; i++) { DateTime Month = DateTime.Now.AddMonths(-i); var TradeMonth = Month.ToString("yyyyMM"); Dictionary curData = new Dictionary(); curData.Add("TradeMonth", Month.ToString("yyyy-MM")); //交易月份 DataTable dt = OtherMySqlConn.dtable("select sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'team' and UserId = " + UserId + " and TradeMonth = " + TradeMonth + ""); foreach (DataRow item in dt.Rows) { var ActTotal = Convert.ToInt32(function.CheckInt(item["sum"].ToString())); curData.Add("ActTotal", ActTotal); //总激活 } //产品列表 List> TypeList = new List>(); DataTable dts = OtherMySqlConn.dtable("select BrandId, sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'team' and UserId = " + UserId + " and TradeMonth = " + TradeMonth + " GROUP BY BrandId"); foreach (DataRow item in dts.Rows) { Dictionary TypeCount = new Dictionary(); var Id = Convert.ToInt32(item["BrandId"]); var query = maindb.KqProducts.FirstOrDefault(m => m.Id == Id); var Count = Convert.ToInt32(function.CheckInt(item["sum"].ToString())); if (Count > 0) { TypeCount.Add("Brand", query.Name); //产品名称 TypeCount.Add("Count", Count); //激活数 TypeList.Add(TypeCount); } } curData.Add("TypeList", TypeList); dataList.Add(curData); } return dataList; } #endregion #region 首页-客小爽产品-收益查看-激活奖励 [Authorize] public JsonResult StatList(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = StatListDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> StatListDo(string value) { JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客 string ProductType = data["ProductType"].ToString(); //产品类型 int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); int Kind = int.Parse(function.CheckInt(data["Kind"].ToString())); string Date = Kind == 1 ? "Day" : "Month"; List> dataList = new List>(); List query = RedisDbconn.Instance.GetList("ActiveReward" + Date + ":" + UserId + ":" + ProductType, PageNum, PageSize); foreach (var subdata in query) { Dictionary curData = new Dictionary(); curData.Add("RewardAmount", RedisDbconn.Instance.Get("ActiveRewardAmt:" + UserId + ":" + ProductType + ":" + subdata)); //奖励金额 if (Kind == 1) { curData.Add("ActDate", subdata.Substring(0, 4) + "年" + subdata.Substring(4, 2) + "月" + subdata.Substring(6, 2) + "日"); //激活时间 } else { curData.Add("ActDate", subdata.Substring(0, 4) + "年" + subdata.Substring(4, 2) + "月"); //激活时间 } curData.Add("ActDateValue", subdata); //激活时间值 dataList.Add(curData); } return dataList; } #endregion #region 首页-客小爽产品-收益查看-激活奖励-详情 [Authorize] public JsonResult StatDetail(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = StatDetailDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> StatDetailDo(string value) { JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客 string ProductType = data["ProductType"].ToString(); //产品类型 string ActDate = data["ActDate"].ToString(); //激活时间 int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); List> dataList = new List>(); List query = RedisDbconn.Instance.GetList("ActiveRewardDetail:" + UserId + ":" + ProductType + ":" + ActDate, PageNum, PageSize); foreach (var subdata in query) { Dictionary curData = new Dictionary(); PosMerchantInfo merchant = PosMerchantInfoDbconn.Instance.Get(subdata) ?? new PosMerchantInfo(); curData.Add("MerchantName", merchant.MerchantName); //商户名称 curData.Add("RewardAmount", RedisDbconn.Instance.Get("ActiveRewardAmt:mer:" + merchant.Id + ":" + ProductType + ":" + ActDate)); //奖励金额 dataList.Add(curData); } return dataList; } #endregion #region 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 请求的参数(json字符串) /// 要签名的字段 /// private string CheckSign(string value, string[] signField) { JsonData json = JsonMapper.ToObject(value); Dictionary dic = new Dictionary(); for (int i = 0; i < signField.Length; i++) { dic.Add(signField[i], json[signField[i]].ToString()); } string sign = json["sign"].ToString(); //客户端签名字符串 return new Sign().sign(dic, sign); } #endregion } }