KqProductsController.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 KqProductsController : BaseController
  18. {
  19. public KqProductsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 通用-产品列表
  23. [Authorize]
  24. public JsonResult List(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. List<Dictionary<string, object>> dataList = ListDo(value);
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  30. }
  31. public List<Dictionary<string, object>> ListDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  35. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  36. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  37. List<KqProducts> query = KqProductsDbconn.Instance.GetList();
  38. foreach (var subdata in query)
  39. {
  40. Dictionary<string, object> curData = new Dictionary<string, object>();
  41. int Price = 0;
  42. if (subdata.Name.Contains("电签"))
  43. {
  44. Price = 200;
  45. }
  46. if (subdata.Name.Contains("POS"))
  47. {
  48. Price = 300;
  49. }
  50. curData.Add("Name", subdata.Name); //名称
  51. curData.Add("Id", subdata.Id); //Id
  52. curData.Add("Price", Price); //价格
  53. dataList.Add(curData);
  54. }
  55. return dataList;
  56. }
  57. #endregion
  58. #region 首页-客小爽产品-主界面产品数据
  59. [Authorize]
  60. public JsonResult MainStatData(string value)
  61. {
  62. value = DesDecrypt(value);
  63. JsonData data = JsonMapper.ToObject(value);
  64. List<Dictionary<string, object>> Obj = MainStatDataDo(value);
  65. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  66. }
  67. public List<Dictionary<string, object>> MainStatDataDo(string value)
  68. {
  69. JsonData data = JsonMapper.ToObject(value);
  70. string UserId = data["UserId"].ToString(); //创客Id
  71. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  72. List<KqProducts> querys = KqProductsDbconn.Instance.GetList();
  73. foreach (KqProducts query in querys)
  74. {
  75. Dictionary<string, object> Obj = new Dictionary<string, object>();
  76. Obj.Add("Id", query.Id);
  77. Obj.Add("Name", query.Name); //名称
  78. UserMachineData MachineData = UserMachineDataDbconn.Instance.Get(UserId + "_" + query.Id) ?? new UserMachineData();
  79. Dictionary<string, object> Machine = new Dictionary<string, object>();
  80. Machine.Add("TotalMachineCount", MachineData.TotalMachineCount); //总机具数
  81. Machine.Add("UnBindCount", MachineData.UnBindCount); //未绑定机具数
  82. Machine.Add("BindCount", MachineData.BindCount); //已绑定机具数
  83. Obj.Add("Machine", Machine); //机具管理数据
  84. Dictionary<string, object> Profit = new Dictionary<string, object>();
  85. Profit.Add("TradeProfit", MachineData.TradeProfit); //交易分润
  86. Profit.Add("ActProfit", MachineData.ActProfit); //激活奖励
  87. Profit.Add("OpenProfit", MachineData.OpenProfit); //开机奖励
  88. Profit.Add("DividendsProfit", MachineData.DividendsProfit); //分红奖励
  89. Profit.Add("OtherProfit", MachineData.OtherProfit); //分润补贴
  90. Profit.Add("FluxProfit", MachineData.FluxProfit); //流量卡分佣
  91. Obj.Add("Profit", Profit); //收益查看数据
  92. List<Dictionary<string, object>> Advertisment = new List<Dictionary<string, object>>();
  93. string ColId = "";
  94. if (query.Id == 1)
  95. {
  96. ColId = "003002";
  97. }
  98. else if (query.Id == 2)
  99. {
  100. ColId = "003004";
  101. }
  102. else if (query.Id == 3)
  103. {
  104. ColId = "003003";
  105. }
  106. else if (query.Id == 4)
  107. {
  108. ColId = "003005";
  109. }
  110. else if (query.Id == 5)
  111. {
  112. ColId = "003006";
  113. }
  114. else if (query.Id == 6)
  115. {
  116. ColId = "003007";
  117. }
  118. else if (query.Id == 7)
  119. {
  120. ColId = "003009";
  121. }
  122. else if (query.Id == 8 || query.Id == 9)
  123. {
  124. ColId = "003008";
  125. }
  126. else if (query.Id == 10 || query.Id == 11)
  127. {
  128. ColId = "003010";
  129. }
  130. List<Models.Advertisment> ads = AdvertismentDbconn.Instance.GetList(ColId);
  131. foreach (Models.Advertisment ad in ads)
  132. {
  133. Dictionary<string, object> item = new Dictionary<string, object>();
  134. item.Add("Url", ad.Url); //跳转地址
  135. item.Add("BannerPic", DefaultPic(ad.PicPath)); //广告图片
  136. item.Add("Id", ad.Id); //Id
  137. Advertisment.Add(item);
  138. }
  139. Obj.Add("Advertisment", Advertisment);
  140. list.Add(Obj);
  141. }
  142. return list;
  143. }
  144. #endregion
  145. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  146. /// <summary>
  147. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  148. /// </summary>
  149. /// <param name="value">请求的参数(json字符串)</param>
  150. /// <param name="signField">要签名的字段</param>
  151. /// <returns></returns>
  152. private string CheckSign(string value, string[] signField)
  153. {
  154. JsonData json = JsonMapper.ToObject(value);
  155. Dictionary<string, string> dic = new Dictionary<string, string>();
  156. for (int i = 0; i < signField.Length; i++)
  157. {
  158. dic.Add(signField[i], json[signField[i]].ToString());
  159. }
  160. string sign = json["sign"].ToString(); //客户端签名字符串
  161. return new Sign().sign(dic, sign);
  162. }
  163. #endregion
  164. }
  165. }