PosCouponOrdersController.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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/[controller]/[action]")]
  18. public class PosCouponOrdersController : BaseController
  19. {
  20. public PosCouponOrdersController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  21. {
  22. }
  23. #region 创客-首页-客小爽产品-码牌管理-划拨记录
  24. [Authorize]
  25. public JsonResult List(string value)
  26. {
  27. value = DesDecrypt(value);
  28. JsonData data = JsonMapper.ToObject(value);
  29. Dictionary<string, object> other = new Dictionary<string, object>();
  30. List<Dictionary<string, object>> dataList = ListDo(value, out other);
  31. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = other });
  32. }
  33. public List<Dictionary<string, object>> ListDo(string value, out Dictionary<string, object> other)
  34. {
  35. JsonData data = JsonMapper.ToObject(value);
  36. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
  37. int ChangeKind = int.Parse(function.CheckInt(data["ChangeKind"].ToString())); // 1-拨入,2-拨出
  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. IQueryable<PosCouponOrders> query = maindb.PosCouponOrders;
  42. if(ChangeKind == 1)
  43. {
  44. query = query.Where(m => m.ToUserId == UserId);
  45. }
  46. else
  47. {
  48. query = query.Where(m => m.FromUserId == UserId);
  49. }
  50. query = query.OrderByDescending(m => m.Id);
  51. if (PageNum == 1)
  52. {
  53. query = query.Take(PageSize);
  54. }
  55. else
  56. {
  57. int skipNum = PageSize * (PageNum - 1);
  58. query = query.Skip(skipNum).Take(PageSize);
  59. }
  60. foreach (var subdata in query.ToList())
  61. {
  62. Dictionary<string, object> curData = new Dictionary<string, object>();
  63. curData.Add("Id", subdata.Id);
  64. string RealName = "";
  65. string MakerCode = "";
  66. if(ChangeKind == 1)
  67. {
  68. KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == subdata.FromUserId) ?? new KxsMainModels.Users();
  69. RealName = function.CheckNull(user.RealName);
  70. MakerCode = function.CheckNull(user.MakerCode);
  71. if(string.IsNullOrEmpty(RealName)) RealName = "成都总仓";
  72. }
  73. else
  74. {
  75. KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == subdata.ToUserId) ?? new KxsMainModels.Users();
  76. RealName = function.CheckNull(user.RealName);
  77. MakerCode = function.CheckNull(user.MakerCode);
  78. }
  79. if (RealName.Length > 2 && RealName != "成都总仓")
  80. {
  81. RealName = RealName.Substring(0, 1) + "*" + RealName.Substring(RealName.Length - 1);
  82. }
  83. else if(!string.IsNullOrEmpty(RealName) && RealName != "成都总仓")
  84. {
  85. RealName = RealName.Substring(0, 1) + "*";
  86. }
  87. curData.Add("RealName", RealName); //真实姓名
  88. curData.Add("MakerCode", MakerCode); //创客编号
  89. curData.Add("ChangeCount", subdata.ChangeCount); //变更数量
  90. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  91. dataList.Add(curData);
  92. }
  93. other = new Dictionary<string, object>();
  94. if(PageNum == 1)
  95. {
  96. DataTable dt = CustomerSqlConn.dtable("select (select count(Id) from PosCouponOrders where FromUserId=" + UserId + "),(select count(Id) from PosCouponOrders where ToUserId=" + UserId + ")", AppConfig.Base.SqlConnStr);
  97. if(dt.Rows.Count > 0)
  98. {
  99. other.Add("FromTotalCount", dt.Rows[0][1].ToString());
  100. other.Add("ToTotalCount", dt.Rows[0][0].ToString());
  101. }
  102. }
  103. return dataList;
  104. }
  105. #endregion
  106. #region 创客-首页-客小爽产品-码牌管理-划拨记录-详情
  107. [Authorize]
  108. public JsonResult Detail(string value)
  109. {
  110. value = DesDecrypt(value);
  111. JsonData data = JsonMapper.ToObject(value);
  112. Dictionary<string, object> Obj = DetailDo(value);
  113. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  114. }
  115. public Dictionary<string, object> DetailDo(string value)
  116. {
  117. JsonData data = JsonMapper.ToObject(value);
  118. Dictionary<string, object> Obj = new Dictionary<string, object>();
  119. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));
  120. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  121. PosCouponOrders query = maindb.PosCouponOrders.FirstOrDefault(m => m.Id == Id) ?? new PosCouponOrders();
  122. string OrderNo = query.OrderNo;
  123. Dictionary<string, object> UserInfo = new Dictionary<string, object>();
  124. string RealName = "";
  125. string MakerCode = "";
  126. string Mobile = "";
  127. if(query.ToUserId == UserId)
  128. {
  129. KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == query.FromUserId) ?? new KxsMainModels.Users();
  130. RealName = function.CheckNull(user.RealName);
  131. MakerCode = function.CheckNull(user.MakerCode);
  132. Mobile = function.CheckNull(user.Mobile);
  133. if(string.IsNullOrEmpty(RealName)) RealName = "成都总仓";
  134. }
  135. else
  136. {
  137. KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == query.ToUserId) ?? new KxsMainModels.Users();
  138. RealName = function.CheckNull(user.RealName);
  139. MakerCode = function.CheckNull(user.MakerCode);
  140. Mobile = function.CheckNull(user.Mobile);
  141. }
  142. if (RealName.Length > 2 && RealName != "成都总仓")
  143. {
  144. RealName = RealName.Substring(0, 1) + "*" + RealName.Substring(RealName.Length - 1);
  145. }
  146. else if(!string.IsNullOrEmpty(RealName) && RealName != "成都总仓")
  147. {
  148. RealName = RealName.Substring(0, 1) + "*";
  149. }
  150. Obj.Add("RealName", RealName); //真实姓名
  151. Obj.Add("MakerCode", MakerCode); //创客编号
  152. Obj.Add("Mobile", Mobile); //手机号
  153. Obj.Add("ChangeCount", query.ChangeCount); //变更数量
  154. Obj.Add("ChangeKind", query.ChangeKind); //变更类型
  155. Obj.Add("CreateDate", query.CreateDate); //创建时间
  156. List<int> posids = maindb.PosCouponRecord.Where(m => m.OrderNo == query.OrderNo).ToList().Select(m => m.PosCouponId).ToList();
  157. List<string> list = maindb.PosMachinesTwo.Where(m => posids.Contains(m.Id)).ToList().Select(m => m.PosSn).ToList();
  158. Obj.Add("SnNoList", list); //机具券列表
  159. return Obj;
  160. }
  161. #endregion
  162. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  163. /// <summary>
  164. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  165. /// </summary>
  166. /// <param name="value">请求的参数(json字符串)</param>
  167. /// <param name="signField">要签名的字段</param>
  168. /// <returns></returns>
  169. private string CheckSign(string value, string[] signField)
  170. {
  171. JsonData json = JsonMapper.ToObject(value);
  172. Dictionary<string, string> dic = new Dictionary<string, string>();
  173. for (int i = 0; i < signField.Length; i++)
  174. {
  175. dic.Add(signField[i], json[signField[i]].ToString());
  176. }
  177. string sign = json["sign"].ToString(); //客户端签名字符串
  178. return new Sign().sign(dic, sign);
  179. }
  180. #endregion
  181. }
  182. }