123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- 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<BaseController> logger, IOptions<Setting> 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<Dictionary<string, object>> dataList = ActMerchantForMonthDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> 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<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- 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<string, object> curData = new Dictionary<string, object>();
- 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<Dictionary<string, object>> TypeList = new List<Dictionary<string, object>>();
- 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<string, object> TypeCount = new Dictionary<string, object>();
- 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<Dictionary<string, object>> dataList = ActMerchantForHalfYearDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> 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<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- for (int i = 0; i < 6; i++)
- {
- DateTime Month = DateTime.Now.AddMonths(-i);
- var TradeMonth = Month.ToString("yyyyMM");
- Dictionary<string, object> curData = new Dictionary<string, object>();
- 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<Dictionary<string, object>> TypeList = new List<Dictionary<string, object>>();
- 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<string, object> TypeCount = new Dictionary<string, object>();
- 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<Dictionary<string, object>> dataList = TeamActMerchantForMonthDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> 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<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- 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<string, object> curData = new Dictionary<string, object>();
- 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<Dictionary<string, object>> TypeList = new List<Dictionary<string, object>>();
- 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<string, object> TypeCount = new Dictionary<string, object>();
- 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<Dictionary<string, object>> dataList = TeamActMerchantForHalfYearDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> 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<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- for (int i = 0; i < 6; i++)
- {
- DateTime Month = DateTime.Now.AddMonths(-i);
- var TradeMonth = Month.ToString("yyyyMM");
- Dictionary<string, object> curData = new Dictionary<string, object>();
- 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<Dictionary<string, object>> TypeList = new List<Dictionary<string, object>>();
- 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<string, object> TypeCount = new Dictionary<string, object>();
- 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<Dictionary<string, object>> dataList = StatListDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> 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<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- List<string> query = RedisDbconn.Instance.GetList<string>("ActiveReward" + Date + ":" + UserId + ":" + ProductType, PageNum, PageSize);
- foreach (var subdata in query)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("RewardAmount", RedisDbconn.Instance.Get<decimal>("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<Dictionary<string, object>> dataList = StatDetailDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> 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<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- List<int> query = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + UserId + ":" + ProductType + ":" + ActDate, PageNum, PageSize);
- foreach (var subdata in query)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- PosMerchantInfo merchant = PosMerchantInfoDbconn.Instance.Get(subdata) ?? new PosMerchantInfo();
- curData.Add("MerchantName", merchant.MerchantName); //商户名称
- curData.Add("RewardAmount", RedisDbconn.Instance.Get<decimal>("ActiveRewardAmt:mer:" + merchant.Id + ":" + ProductType + ":" + ActDate)); //奖励金额
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 检查签名是否合法,合法返回1,不合法返回提示信息
- /// <summary>
- /// 检查签名是否合法,合法返回1,不合法返回提示信息
- /// </summary>
- /// <param name="value">请求的参数(json字符串)</param>
- /// <param name="signField">要签名的字段</param>
- /// <returns></returns>
- private string CheckSign(string value, string[] signField)
- {
- JsonData json = JsonMapper.ToObject(value);
- Dictionary<string, string> dic = new Dictionary<string, string>();
- 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
- }
- }
|