PosCouponOrdersController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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.Models.Main;
  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) : base(accessor)
  21. {
  22. }
  23. #region 创客-首页-客小爽产品-码牌管理-划拨记录
  24. // [Authorize]
  25. public JsonResult List(string value)
  26. {
  27. value = DesDecrypt(value);
  28. value = value.Replace("null", "\"\"");
  29. JsonData data = JsonMapper.ToObject(value);
  30. Dictionary<string, object> other = new Dictionary<string, object>();
  31. List<Dictionary<string, object>> dataList = ListDo(value, out other);
  32. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = other });
  33. }
  34. public List<Dictionary<string, object>> ListDo(string value, out Dictionary<string, object> other)
  35. {
  36. JsonData data = JsonMapper.ToObject(value);
  37. int UserId = int.Parse(function.CheckInt(data.getItem("UserId").ToString())); //创客Id
  38. int ChangeKind = int.Parse(function.CheckInt(data.getItem("ChangeKind").ToString())); // 1-拨入,2-拨出
  39. int PageSize = int.Parse(function.CheckInt(data.getItem("PageSize").ToString()));
  40. int PageNum = int.Parse(function.CheckInt(data.getItem("PageNum").ToString()));
  41. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  42. IQueryable<PosCouponOrders> query = maindb.PosCouponOrders.Where(m=> m.ChangeKind == 1);
  43. if(ChangeKind == 1)
  44. {
  45. query = query.Where(m => m.ToUserId == UserId);
  46. }
  47. else
  48. {
  49. query = query.Where(m => m.FromUserId == UserId);
  50. }
  51. query = query.OrderByDescending(m => m.Id);
  52. if (PageNum == 1)
  53. {
  54. query = query.Take(PageSize);
  55. }
  56. else
  57. {
  58. int skipNum = PageSize * (PageNum - 1);
  59. query = query.Skip(skipNum).Take(PageSize);
  60. }
  61. foreach (var subdata in query.ToList())
  62. {
  63. Dictionary<string, object> curData = new Dictionary<string, object>();
  64. curData.Add("Id", subdata.Id);
  65. string RealName = "";
  66. string MakerCode = "";
  67. if(ChangeKind == 1)
  68. {
  69. Models.KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == subdata.FromUserId) ?? new Models.KxsMainModels.Users();
  70. RealName = function.CheckNull(user.RealName);
  71. MakerCode = function.CheckNull(user.MakerCode);
  72. if(string.IsNullOrEmpty(RealName)) RealName = "成都总仓";
  73. }
  74. else
  75. {
  76. Models.KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == subdata.ToUserId) ?? new Models.KxsMainModels.Users();
  77. RealName = function.CheckNull(user.RealName);
  78. MakerCode = function.CheckNull(user.MakerCode);
  79. }
  80. if (RealName.Length > 2 && RealName != "成都总仓")
  81. {
  82. RealName = RealName.Substring(0, 1) + "*" + RealName.Substring(RealName.Length - 1);
  83. }
  84. else if(!string.IsNullOrEmpty(RealName) && RealName != "成都总仓")
  85. {
  86. RealName = RealName.Substring(0, 1) + "*";
  87. }
  88. curData.Add("RealName", RealName); //真实姓名
  89. curData.Add("MakerCode", MakerCode); //创客编号
  90. curData.Add("ChangeCount", subdata.ChangeCount); //变更数量
  91. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  92. dataList.Add(curData);
  93. }
  94. other = new Dictionary<string, object>();
  95. if(PageNum == 1)
  96. {
  97. DataTable dt = CustomerSqlConn.dtable("select (select count(Id) from PosCouponOrders where FromUserId=" + UserId + "),(select count(Id) from PosCouponOrders where ToUserId=" + UserId + " and ChangeKind=1)", AppConfig.Base.SqlConnStr);
  98. if(dt.Rows.Count > 0)
  99. {
  100. other.Add("FromTotalCount", dt.Rows[0][1].ToString());
  101. other.Add("ToTotalCount", dt.Rows[0][0].ToString());
  102. }
  103. }
  104. return dataList;
  105. }
  106. #endregion
  107. #region 创客-首页-客小爽产品-码牌管理-划拨记录-详情
  108. // [Authorize]
  109. public JsonResult Detail(string value)
  110. {
  111. value = DesDecrypt(value);
  112. value = value.Replace("null", "\"\"");
  113. JsonData data = JsonMapper.ToObject(value);
  114. Dictionary<string, object> Obj = DetailDo(value);
  115. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  116. }
  117. public Dictionary<string, object> DetailDo(string value)
  118. {
  119. JsonData data = JsonMapper.ToObject(value);
  120. Dictionary<string, object> Obj = new Dictionary<string, object>();
  121. int UserId = int.Parse(function.CheckInt(data.getItem("UserId").ToString()));
  122. int Id = int.Parse(function.CheckInt(data.getItem("Id").ToString()));
  123. PosCouponOrders query = maindb.PosCouponOrders.FirstOrDefault(m => m.Id == Id) ?? new PosCouponOrders();
  124. string OrderNo = query.OrderNo;
  125. Dictionary<string, object> UserInfo = new Dictionary<string, object>();
  126. string RealName = "";
  127. string MakerCode = "";
  128. string Mobile = "";
  129. if(query.ToUserId == UserId)
  130. {
  131. Models.KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == query.FromUserId) ?? new Models.KxsMainModels.Users();
  132. RealName = function.CheckNull(user.RealName);
  133. MakerCode = function.CheckNull(user.MakerCode);
  134. Mobile = function.CheckNull(user.Mobile);
  135. if(string.IsNullOrEmpty(RealName)) RealName = "成都总仓";
  136. }
  137. else
  138. {
  139. Models.KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == query.ToUserId) ?? new Models.KxsMainModels.Users();
  140. RealName = function.CheckNull(user.RealName);
  141. MakerCode = function.CheckNull(user.MakerCode);
  142. Mobile = function.CheckNull(user.Mobile);
  143. }
  144. if (RealName.Length > 2 && RealName != "成都总仓")
  145. {
  146. RealName = RealName.Substring(0, 1) + "*" + RealName.Substring(RealName.Length - 1);
  147. }
  148. else if(!string.IsNullOrEmpty(RealName) && RealName != "成都总仓")
  149. {
  150. RealName = RealName.Substring(0, 1) + "*";
  151. }
  152. Obj.Add("RealName", RealName); //真实姓名
  153. Obj.Add("MakerCode", MakerCode); //创客编号
  154. Obj.Add("Mobile", Mobile); //手机号
  155. Obj.Add("ChangeCount", query.ChangeCount); //变更数量
  156. Obj.Add("ChangeKind", query.ChangeKind); //变更类型
  157. Obj.Add("CreateDate", query.CreateDate); //创建时间
  158. List<int> posids = maindb.PosCouponRecord.Where(m => m.OrderNo == query.OrderNo).ToList().Select(m => m.PosCouponId).ToList();
  159. List<string> list = main1db.PosMachinesTwo.Where(m => posids.Contains(m.Id)).ToList().Select(m => m.PosSn).ToList();
  160. Obj.Add("SnNoList", list); //机具券列表
  161. return Obj;
  162. }
  163. #endregion
  164. #region 创客-首页-客小爽产品-音响管理-划拨记录
  165. // [Authorize]
  166. public JsonResult List2(string value)
  167. {
  168. value = DesDecrypt(value);
  169. value = value.Replace("null", "\"\"");
  170. JsonData data = JsonMapper.ToObject(value);
  171. Dictionary<string, object> other = new Dictionary<string, object>();
  172. List<Dictionary<string, object>> dataList = List2Do(value, out other);
  173. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = other });
  174. }
  175. public List<Dictionary<string, object>> List2Do(string value, out Dictionary<string, object> other)
  176. {
  177. JsonData data = JsonMapper.ToObject(value);
  178. int UserId = int.Parse(function.CheckInt(data.getItem("UserId").ToString())); //创客Id
  179. int ChangeKind = int.Parse(function.CheckInt(data.getItem("ChangeKind").ToString())); // 1-拨入,2-拨出
  180. int PageSize = int.Parse(function.CheckInt(data.getItem("PageSize").ToString()));
  181. int PageNum = int.Parse(function.CheckInt(data.getItem("PageNum").ToString()));
  182. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  183. IQueryable<PosCouponOrders> query = maindb.PosCouponOrders.Where(m=> m.ChangeKind == 2);
  184. if(ChangeKind == 1)
  185. {
  186. query = query.Where(m => m.ToUserId == UserId);
  187. }
  188. else
  189. {
  190. query = query.Where(m => m.FromUserId == UserId);
  191. }
  192. query = query.OrderByDescending(m => m.Id);
  193. if (PageNum == 1)
  194. {
  195. query = query.Take(PageSize);
  196. }
  197. else
  198. {
  199. int skipNum = PageSize * (PageNum - 1);
  200. query = query.Skip(skipNum).Take(PageSize);
  201. }
  202. foreach (var subdata in query.ToList())
  203. {
  204. Dictionary<string, object> curData = new Dictionary<string, object>();
  205. curData.Add("Id", subdata.Id);
  206. string RealName = "";
  207. string MakerCode = "";
  208. if(ChangeKind == 1)
  209. {
  210. Models.KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == subdata.FromUserId) ?? new Models.KxsMainModels.Users();
  211. RealName = function.CheckNull(user.RealName);
  212. MakerCode = function.CheckNull(user.MakerCode);
  213. if(string.IsNullOrEmpty(RealName)) RealName = "成都总仓";
  214. }
  215. else
  216. {
  217. Models.KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == subdata.ToUserId) ?? new Models.KxsMainModels.Users();
  218. RealName = function.CheckNull(user.RealName);
  219. MakerCode = function.CheckNull(user.MakerCode);
  220. }
  221. if (RealName.Length > 2 && RealName != "成都总仓")
  222. {
  223. RealName = RealName.Substring(0, 1) + "*" + RealName.Substring(RealName.Length - 1);
  224. }
  225. else if(!string.IsNullOrEmpty(RealName) && RealName != "成都总仓")
  226. {
  227. RealName = RealName.Substring(0, 1) + "*";
  228. }
  229. curData.Add("RealName", RealName); //真实姓名
  230. curData.Add("MakerCode", MakerCode); //创客编号
  231. curData.Add("ChangeCount", subdata.ChangeCount); //变更数量
  232. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  233. dataList.Add(curData);
  234. }
  235. other = new Dictionary<string, object>();
  236. if(PageNum == 1)
  237. {
  238. DataTable dt = CustomerSqlConn.dtable("select (select count(Id) from PosCouponOrders where FromUserId=" + UserId + "),(select count(Id) from PosCouponOrders where ToUserId=" + UserId + " and ChangeKind=2)", AppConfig.Base.SqlConnStr);
  239. if(dt.Rows.Count > 0)
  240. {
  241. other.Add("FromTotalCount", dt.Rows[0][1].ToString());
  242. other.Add("ToTotalCount", dt.Rows[0][0].ToString());
  243. }
  244. }
  245. return dataList;
  246. }
  247. #endregion
  248. #region 创客-首页-客小爽产品-音响管理-划拨记录-详情
  249. // [Authorize]
  250. public JsonResult Detail2(string value)
  251. {
  252. value = DesDecrypt(value);
  253. value = value.Replace("null", "\"\"");
  254. JsonData data = JsonMapper.ToObject(value);
  255. Dictionary<string, object> Obj = Detail2Do(value);
  256. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  257. }
  258. public Dictionary<string, object> Detail2Do(string value)
  259. {
  260. JsonData data = JsonMapper.ToObject(value);
  261. Dictionary<string, object> Obj = new Dictionary<string, object>();
  262. int UserId = int.Parse(function.CheckInt(data.getItem("UserId").ToString()));
  263. int Id = int.Parse(function.CheckInt(data.getItem("Id").ToString()));
  264. PosCouponOrders query = maindb.PosCouponOrders.FirstOrDefault(m => m.Id == Id) ?? new PosCouponOrders();
  265. string OrderNo = query.OrderNo;
  266. Dictionary<string, object> UserInfo = new Dictionary<string, object>();
  267. string RealName = "";
  268. string MakerCode = "";
  269. string Mobile = "";
  270. if(query.ToUserId == UserId)
  271. {
  272. Models.KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == query.FromUserId) ?? new Models.KxsMainModels.Users();
  273. RealName = function.CheckNull(user.RealName);
  274. MakerCode = function.CheckNull(user.MakerCode);
  275. Mobile = function.CheckNull(user.Mobile);
  276. if(string.IsNullOrEmpty(RealName)) RealName = "成都总仓";
  277. }
  278. else
  279. {
  280. Models.KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == query.ToUserId) ?? new Models.KxsMainModels.Users();
  281. RealName = function.CheckNull(user.RealName);
  282. MakerCode = function.CheckNull(user.MakerCode);
  283. Mobile = function.CheckNull(user.Mobile);
  284. }
  285. if (RealName.Length > 2 && RealName != "成都总仓")
  286. {
  287. RealName = RealName.Substring(0, 1) + "*" + RealName.Substring(RealName.Length - 1);
  288. }
  289. else if(!string.IsNullOrEmpty(RealName) && RealName != "成都总仓")
  290. {
  291. RealName = RealName.Substring(0, 1) + "*";
  292. }
  293. Obj.Add("RealName", RealName); //真实姓名
  294. Obj.Add("MakerCode", MakerCode); //创客编号
  295. Obj.Add("Mobile", Mobile); //手机号
  296. Obj.Add("ChangeCount", query.ChangeCount); //变更数量
  297. Obj.Add("ChangeKind", query.ChangeKind); //变更类型
  298. Obj.Add("CreateDate", query.CreateDate); //创建时间
  299. List<int> posids = maindb.PosCouponRecord.Where(m => m.OrderNo == query.OrderNo).ToList().Select(m => m.PosCouponId).ToList();
  300. List<string> list = main1db.PosMachines.Where(m => posids.Contains(m.Id)).ToList().Select(m => m.PosSn).ToList();
  301. Obj.Add("SnNoList", list); //机具券列表
  302. return Obj;
  303. }
  304. #endregion
  305. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  306. /// <summary>
  307. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  308. /// </summary>
  309. /// <param name="value">请求的参数(json字符串)</param>
  310. /// <param name="signField">要签名的字段</param>
  311. /// <returns></returns>
  312. private string CheckSign(string value, string[] signField)
  313. {
  314. JsonData json = JsonMapper.ToObject(value);
  315. Dictionary<string, string> dic = new Dictionary<string, string>();
  316. for (int i = 0; i < signField.Length; i++)
  317. {
  318. dic.Add(signField[i], json[signField[i]].ToString());
  319. }
  320. string sign = json["sign"].ToString(); //客户端签名字符串
  321. return new Sign().sign(dic, sign);
  322. }
  323. #endregion
  324. }
  325. }