PosCouponsController.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.MainModels;
  11. using LitJson;
  12. using Library;
  13. namespace MySystem.Areas.Api.Controllers.v1.pos
  14. {
  15. [Area("Api")]
  16. [Route("Api/v1/pos/[controller]/[action]")]
  17. public class PosCouponsController : BaseController
  18. {
  19. public PosCouponsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 创客-首页-客小爽产品-机具管理-机具申请-要兑换的券
  23. [Authorize]
  24. public JsonResult ExchangeCoupons(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. Dictionary<string, object> Other = new Dictionary<string, object>();
  29. List<Dictionary<string, object>> dataList = ExchangeCouponsDo(value, out Other);
  30. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  31. }
  32. public List<Dictionary<string, object>> ExchangeCouponsDo(string value, out Dictionary<string, object> Other)
  33. {
  34. JsonData data = JsonMapper.ToObject(value);
  35. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  36. int Kind = int.Parse(function.CheckInt(data["Kind"].ToString()));//券类型
  37. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  38. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  39. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  40. IQueryable<PosCoupons> query = maindb.PosCoupons.Where(m => m.UserId == UserId && m.QueryCount == Kind && m.IsUse == 0 && m.IsLock == 0 && m.HelpProfitMerchantId == 0 && m.HelpProfitStatus == 0 && m.HelpProfitFlag == 0);
  41. if (PageNum == 1)
  42. {
  43. query = query.Take(PageSize);
  44. }
  45. else
  46. {
  47. int skipNum = PageSize * (PageNum - 1);
  48. query = query.Skip(skipNum).Take(PageSize);
  49. }
  50. foreach (var subdata in query.ToList())
  51. {
  52. Dictionary<string, object> curData = new Dictionary<string, object>();
  53. int IsLeader = 0;//是否为大盟主机(0-否 1-是)
  54. if (subdata.LeaderUserId > 0)
  55. {
  56. IsLeader = 1;
  57. }
  58. else
  59. {
  60. IsLeader = 0;
  61. }
  62. curData.Add("ExchangeCode", subdata.ExchangeCode); //兑换码
  63. curData.Add("Id", subdata.Id); //Id
  64. curData.Add("Kind", subdata.QueryCount); //券类型
  65. int day = 0;
  66. if (subdata.UpdateDate != null)
  67. {
  68. TimeSpan ts = subdata.UpdateDate.Value - DateTime.Now;
  69. day = ts.Days;
  70. }
  71. curData.Add("RecycDays", day); //循环剩余天数
  72. curData.Add("EndDate", subdata.UpdateDate == null ? "" : subdata.UpdateDate.Value.ToString("yyyy-MM-dd")); //截止日期
  73. List<int> ProductType = new List<int>();
  74. if (subdata.QueryCount == 1)
  75. {
  76. ProductType.Add(1);
  77. ProductType.Add(2);
  78. ProductType.Add(4);
  79. ProductType.Add(6);
  80. ProductType.Add(7);
  81. ProductType.Add(8);
  82. ProductType.Add(10);
  83. }
  84. else if (subdata.QueryCount == 2)
  85. {
  86. ProductType.Add(3);
  87. ProductType.Add(5);
  88. ProductType.Add(9);
  89. ProductType.Add(11);
  90. }
  91. curData.Add("ProductType", ProductType);
  92. curData.Add("IsLeader",IsLeader);
  93. dataList.Add(curData);
  94. }
  95. Other = new Dictionary<string, object>();
  96. if (PageNum == 1)
  97. {
  98. Other.Add("NotUseCount", maindb.PosCoupons.Count(m => m.UserId == UserId && m.IsUse == 0 && m.QueryCount == 1 && m.HelpProfitFlag == 0));
  99. Other.Add("UsedCount", maindb.PosCoupons.Count(m => m.UserId == UserId && m.IsUse == 1 && m.QueryCount == 1));
  100. Other.Add("NotUseCount2", maindb.PosCoupons.Count(m => m.UserId == UserId && m.IsUse == 0 && m.QueryCount == 2 && m.HelpProfitFlag == 0));
  101. Other.Add("UsedCount2", maindb.PosCoupons.Count(m => m.UserId == UserId && m.IsUse == 1 && m.QueryCount == 2));
  102. }
  103. return dataList;
  104. }
  105. #endregion
  106. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  107. /// <summary>
  108. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  109. /// </summary>
  110. /// <param name="value">请求的参数(json字符串)</param>
  111. /// <param name="signField">要签名的字段</param>
  112. /// <returns></returns>
  113. private string CheckSign(string value, string[] signField)
  114. {
  115. JsonData json = JsonMapper.ToObject(value);
  116. Dictionary<string, string> dic = new Dictionary<string, string>();
  117. for (int i = 0; i < signField.Length; i++)
  118. {
  119. dic.Add(signField[i], json[signField[i]].ToString());
  120. }
  121. string sign = json["sign"].ToString(); //客户端签名字符串
  122. return new Sign().sign(dic, sign);
  123. }
  124. #endregion
  125. }
  126. }