ActiveRewardController.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.AspNetCore.Http;
  7. using Microsoft.Extensions.Logging;
  8. using Microsoft.Extensions.Options;
  9. using Microsoft.AspNetCore.Authorization;
  10. using System.Web;
  11. using MySystem.MainModels;
  12. using LitJson;
  13. using Library;
  14. namespace MySystem.Areas.Api.Controllers.v1.pos
  15. {
  16. [Area("Api")]
  17. [Route("Api/v1/pos/[controller]/[action]")]
  18. public class ActiveRewardController : BaseController
  19. {
  20. public ActiveRewardController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  21. {
  22. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  23. }
  24. #region 创客-首页-我的业绩-个人业绩-激活商户-每月明细
  25. [Authorize]
  26. public JsonResult ActMerchantForMonth(string value)
  27. {
  28. value = DesDecrypt(value);
  29. JsonData data = JsonMapper.ToObject(value);
  30. List<Dictionary<string, object>> dataList = ActMerchantForMonthDo(value);
  31. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  32. }
  33. public List<Dictionary<string, object>> ActMerchantForMonthDo(string value)
  34. {
  35. JsonData data = JsonMapper.ToObject(value);
  36. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  37. string TradeMonth = data["TradeMonth"].ToString(); //交易月
  38. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  39. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  40. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  41. DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
  42. if (DateTime.Now.ToString("yyyyMM") != TradeMonth)
  43. {
  44. start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00").AddHours(1).AddDays(-1).AddMonths(1);
  45. }
  46. if (PageNum > 1)
  47. {
  48. int skipNum = PageSize * (PageNum - 1);
  49. start = start.AddDays(-skipNum);
  50. }
  51. for (int i = 0; i < PageSize; i++)
  52. {
  53. DateTime date = start.AddDays(-i);
  54. string Month = date.ToString("yyyyMM");
  55. string Date = date.ToString("yyyyMMdd");
  56. // if (Date != DateTime.Now.ToString("yyyyMMdd"))
  57. // {
  58. Dictionary<string, object> curData = new Dictionary<string, object>();
  59. DataTable dt = OtherMySqlConn.dtable("select sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'self' and UserId = " + UserId + " and TradeMonth = " + Month + " and SeoKeyword = " + Date + "");
  60. foreach (DataRow item in dt.Rows)
  61. {
  62. var ActTotal = Convert.ToInt32(function.CheckInt(item["sum"].ToString()));
  63. curData.Add("Date", date.ToString("yyyy-MM-dd")); //时间
  64. curData.Add("ActTotal", ActTotal); //总激活
  65. }
  66. //产品列表
  67. List<Dictionary<string, object>> TypeList = new List<Dictionary<string, object>>();
  68. 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");
  69. foreach (DataRow item in dts.Rows)
  70. {
  71. Dictionary<string, object> TypeCount = new Dictionary<string, object>();
  72. var Id = Convert.ToInt32(item["BrandId"]);
  73. var query = maindb.KqProducts.FirstOrDefault(m => m.Id == Id);
  74. var Count = Convert.ToInt32(function.CheckInt(item["sum"].ToString()));
  75. if (Count > 0)
  76. {
  77. TypeCount.Add("Brand", query.Name); //产品名称
  78. TypeCount.Add("Count", Count); //激活数
  79. TypeList.Add(TypeCount);
  80. }
  81. }
  82. curData.Add("TypeList", TypeList);
  83. dataList.Add(curData);
  84. // }
  85. }
  86. return dataList;
  87. }
  88. #endregion
  89. #region 创客-首页-我的业绩-个人业绩-激活商户-近半年
  90. [Authorize]
  91. public JsonResult ActMerchantForHalfYear(string value)
  92. {
  93. value = DesDecrypt(value);
  94. JsonData data = JsonMapper.ToObject(value);
  95. List<Dictionary<string, object>> dataList = ActMerchantForHalfYearDo(value);
  96. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  97. }
  98. public List<Dictionary<string, object>> ActMerchantForHalfYearDo(string value)
  99. {
  100. JsonData data = JsonMapper.ToObject(value);
  101. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  102. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  103. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  104. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  105. for (int i = 0; i < 6; i++)
  106. {
  107. DateTime Month = DateTime.Now.AddMonths(-i);
  108. var TradeMonth = Month.ToString("yyyyMM");
  109. Dictionary<string, object> curData = new Dictionary<string, object>();
  110. curData.Add("TradeMonth", Month.ToString("yyyy-MM")); //交易月份
  111. DataTable dt = OtherMySqlConn.dtable("select sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'self' and UserId = " + UserId + " and TradeMonth = " + TradeMonth + "");
  112. foreach (DataRow item in dt.Rows)
  113. {
  114. var ActTotal = Convert.ToInt32(function.CheckInt(item["sum"].ToString()));
  115. curData.Add("ActTotal", ActTotal); //总激活
  116. }
  117. //产品列表
  118. List<Dictionary<string, object>> TypeList = new List<Dictionary<string, object>>();
  119. DataTable dts = OtherMySqlConn.dtable("select BrandId, sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'self' and UserId = " + UserId + " and TradeMonth = " + TradeMonth + " GROUP BY BrandId");
  120. foreach (DataRow item in dts.Rows)
  121. {
  122. Dictionary<string, object> TypeCount = new Dictionary<string, object>();
  123. var Id = Convert.ToInt32(item["BrandId"]);
  124. var query = maindb.KqProducts.FirstOrDefault(m => m.Id == Id);
  125. var Count = Convert.ToInt32(function.CheckInt(item["sum"].ToString()));
  126. if (Count > 0)
  127. {
  128. TypeCount.Add("Brand", query.Name); //产品名称
  129. TypeCount.Add("Count", Count); //激活数
  130. TypeList.Add(TypeCount);
  131. }
  132. }
  133. curData.Add("TypeList", TypeList);
  134. dataList.Add(curData);
  135. }
  136. return dataList;
  137. }
  138. #endregion
  139. #region 创客-首页-我的业绩-团队业绩-激活商户-每月明细
  140. [Authorize]
  141. public JsonResult TeamActMerchantForMonth(string value)
  142. {
  143. value = DesDecrypt(value);
  144. JsonData data = JsonMapper.ToObject(value);
  145. List<Dictionary<string, object>> dataList = TeamActMerchantForMonthDo(value);
  146. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  147. }
  148. public List<Dictionary<string, object>> TeamActMerchantForMonthDo(string value)
  149. {
  150. JsonData data = JsonMapper.ToObject(value);
  151. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  152. string TradeMonth = data["TradeMonth"].ToString(); //交易月
  153. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  154. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  155. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  156. DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
  157. if (DateTime.Now.ToString("yyyyMM") != TradeMonth)
  158. {
  159. start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00").AddHours(1).AddDays(-1).AddMonths(1);
  160. }
  161. if (PageNum > 1)
  162. {
  163. int skipNum = PageSize * (PageNum - 1);
  164. start = start.AddDays(-skipNum);
  165. }
  166. for (int i = 0; i < PageSize; i++)
  167. {
  168. DateTime date = start.AddDays(-i);
  169. string Month = date.ToString("yyyyMM");
  170. string Date = date.ToString("yyyyMMdd");
  171. // if (Date != DateTime.Now.ToString("yyyyMMdd"))
  172. // {
  173. Dictionary<string, object> curData = new Dictionary<string, object>();
  174. DataTable dt = OtherMySqlConn.dtable("select sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'team' and UserId = " + UserId + " and TradeMonth = " + Month + " and SeoKeyword = " + Date + "");
  175. foreach (DataRow item in dt.Rows)
  176. {
  177. var ActTotal = Convert.ToInt32(function.CheckInt(item["sum"].ToString()));
  178. curData.Add("Date", date.ToString("yyyy-MM-dd")); //时间
  179. curData.Add("ActTotal", ActTotal); //总激活
  180. }
  181. //产品列表
  182. List<Dictionary<string, object>> TypeList = new List<Dictionary<string, object>>();
  183. 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");
  184. foreach (DataRow item in dts.Rows)
  185. {
  186. Dictionary<string, object> TypeCount = new Dictionary<string, object>();
  187. var Id = Convert.ToInt32(item["BrandId"]);
  188. var query = maindb.KqProducts.FirstOrDefault(m => m.Id == Id);
  189. var Count = Convert.ToInt32(function.CheckInt(item["sum"].ToString()));
  190. if (Count > 0)
  191. {
  192. TypeCount.Add("Brand", query.Name); //产品名称
  193. TypeCount.Add("Count", Count); //激活数
  194. TypeList.Add(TypeCount);
  195. }
  196. }
  197. curData.Add("TypeList", TypeList);
  198. dataList.Add(curData);
  199. // }
  200. }
  201. return dataList;
  202. }
  203. #endregion
  204. #region 创客-首页-我的业绩-团队业绩-激活商户-近半年
  205. [Authorize]
  206. public JsonResult TeamActMerchantForHalfYear(string value)
  207. {
  208. value = DesDecrypt(value);
  209. JsonData data = JsonMapper.ToObject(value);
  210. List<Dictionary<string, object>> dataList = TeamActMerchantForHalfYearDo(value);
  211. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  212. }
  213. public List<Dictionary<string, object>> TeamActMerchantForHalfYearDo(string value)
  214. {
  215. JsonData data = JsonMapper.ToObject(value);
  216. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  217. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  218. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  219. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  220. for (int i = 0; i < 6; i++)
  221. {
  222. DateTime Month = DateTime.Now.AddMonths(-i);
  223. var TradeMonth = Month.ToString("yyyyMM");
  224. Dictionary<string, object> curData = new Dictionary<string, object>();
  225. curData.Add("TradeMonth", Month.ToString("yyyy-MM")); //交易月份
  226. DataTable dt = OtherMySqlConn.dtable("select sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'team' and UserId = " + UserId + " and TradeMonth = " + TradeMonth + "");
  227. foreach (DataRow item in dt.Rows)
  228. {
  229. var ActTotal = Convert.ToInt32(function.CheckInt(item["sum"].ToString()));
  230. curData.Add("ActTotal", ActTotal); //总激活
  231. }
  232. //产品列表
  233. List<Dictionary<string, object>> TypeList = new List<Dictionary<string, object>>();
  234. DataTable dts = OtherMySqlConn.dtable("select BrandId, sum(ActiveBuddyMerStatus) sum from UserTradeMonthSummary where SeoTitle = 'team' and UserId = " + UserId + " and TradeMonth = " + TradeMonth + " GROUP BY BrandId");
  235. foreach (DataRow item in dts.Rows)
  236. {
  237. Dictionary<string, object> TypeCount = new Dictionary<string, object>();
  238. var Id = Convert.ToInt32(item["BrandId"]);
  239. var query = maindb.KqProducts.FirstOrDefault(m => m.Id == Id);
  240. var Count = Convert.ToInt32(function.CheckInt(item["sum"].ToString()));
  241. if (Count > 0)
  242. {
  243. TypeCount.Add("Brand", query.Name); //产品名称
  244. TypeCount.Add("Count", Count); //激活数
  245. TypeList.Add(TypeCount);
  246. }
  247. }
  248. curData.Add("TypeList", TypeList);
  249. dataList.Add(curData);
  250. }
  251. return dataList;
  252. }
  253. #endregion
  254. #region 首页-客小爽产品-收益查看-激活奖励
  255. [Authorize]
  256. public JsonResult StatList(string value)
  257. {
  258. value = DesDecrypt(value);
  259. JsonData data = JsonMapper.ToObject(value);
  260. List<Dictionary<string, object>> dataList = StatListDo(value);
  261. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  262. }
  263. public List<Dictionary<string, object>> StatListDo(string value)
  264. {
  265. JsonData data = JsonMapper.ToObject(value);
  266. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  267. string ProductType = data["ProductType"].ToString(); //产品类型
  268. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  269. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  270. int Kind = int.Parse(function.CheckInt(data["Kind"].ToString()));
  271. string Date = Kind == 1 ? "Day" : "Month";
  272. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  273. List<string> query = RedisDbconn.Instance.GetList<string>("ActiveReward" + Date + ":" + UserId + ":" + ProductType, PageNum, PageSize);
  274. foreach (var subdata in query)
  275. {
  276. Dictionary<string, object> curData = new Dictionary<string, object>();
  277. curData.Add("RewardAmount", RedisDbconn.Instance.Get<decimal>("ActiveRewardAmt:" + UserId + ":" + ProductType + ":" + subdata)); //奖励金额
  278. if (Kind == 1)
  279. {
  280. curData.Add("ActDate", subdata.Substring(0, 4) + "年" + subdata.Substring(4, 2) + "月" + subdata.Substring(6, 2) + "日"); //激活时间
  281. }
  282. else
  283. {
  284. curData.Add("ActDate", subdata.Substring(0, 4) + "年" + subdata.Substring(4, 2) + "月"); //激活时间
  285. }
  286. curData.Add("ActDateValue", subdata); //激活时间值
  287. dataList.Add(curData);
  288. }
  289. return dataList;
  290. }
  291. #endregion
  292. #region 首页-客小爽产品-收益查看-激活奖励-详情
  293. [Authorize]
  294. public JsonResult StatDetail(string value)
  295. {
  296. value = DesDecrypt(value);
  297. JsonData data = JsonMapper.ToObject(value);
  298. List<Dictionary<string, object>> dataList = StatDetailDo(value);
  299. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  300. }
  301. public List<Dictionary<string, object>> StatDetailDo(string value)
  302. {
  303. JsonData data = JsonMapper.ToObject(value);
  304. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  305. string ProductType = data["ProductType"].ToString(); //产品类型
  306. string ActDate = data["ActDate"].ToString(); //激活时间
  307. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  308. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  309. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  310. List<int> query = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + UserId + ":" + ProductType + ":" + ActDate, PageNum, PageSize);
  311. foreach (var subdata in query)
  312. {
  313. Dictionary<string, object> curData = new Dictionary<string, object>();
  314. PosMerchantInfo merchant = PosMerchantInfoDbconn.Instance.Get(subdata) ?? new PosMerchantInfo();
  315. curData.Add("MerchantName", merchant.MerchantName); //商户名称
  316. curData.Add("RewardAmount", RedisDbconn.Instance.Get<decimal>("ActiveRewardAmt:mer:" + merchant.Id + ":" + ProductType + ":" + ActDate)); //奖励金额
  317. dataList.Add(curData);
  318. }
  319. return dataList;
  320. }
  321. #endregion
  322. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  323. /// <summary>
  324. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  325. /// </summary>
  326. /// <param name="value">请求的参数(json字符串)</param>
  327. /// <param name="signField">要签名的字段</param>
  328. /// <returns></returns>
  329. private string CheckSign(string value, string[] signField)
  330. {
  331. JsonData json = JsonMapper.ToObject(value);
  332. Dictionary<string, string> dic = new Dictionary<string, string>();
  333. for (int i = 0; i < signField.Length; i++)
  334. {
  335. dic.Add(signField[i], json[signField[i]].ToString());
  336. }
  337. string sign = json["sign"].ToString(); //客户端签名字符串
  338. return new Sign().sign(dic, sign);
  339. }
  340. #endregion
  341. }
  342. }