StoreHouseController.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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
  14. {
  15. [Area("Api")]
  16. [Route("Api/v1/[controller]/[action]")]
  17. public class StoreHouseController : BaseController
  18. {
  19. public StoreHouseController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 创客-商城-确认支付-发货仓库
  23. [Authorize]
  24. public JsonResult SendStores(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. List<Dictionary<string, object>> dataList = SendStoresDo(value);
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  30. }
  31. public List<Dictionary<string, object>> SendStoresDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
  35. string BrandId = data["BrandId"].ToString(); //品牌Id
  36. string searchContent = data["searchContent"].ToString();
  37. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  38. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  39. Users user = UsersDbconn.Instance.Get(UserId) ?? new Users();
  40. List<int> uids = new List<int>();
  41. uids.Add(1);
  42. uids.Add(UserId);
  43. if (!string.IsNullOrEmpty(user.ParentNav))
  44. {
  45. string ParentNav = function.CheckNull(user.ParentNav).Trim(',').Replace(",,", ",");
  46. string[] ParentNavList = ParentNav.Split(',');
  47. // foreach (string uid in ParentNavList)
  48. // {
  49. // uids.Add(int.Parse(uid));
  50. // }
  51. int TopUserId = 0;
  52. if (ParentNavList.Length > 1)
  53. {
  54. TopUserId = int.Parse(ParentNavList[1]);
  55. }
  56. else
  57. {
  58. TopUserId = int.Parse(ParentNavList[0]);
  59. }
  60. string UidString = "," + TopUserId + ",";
  61. var subusers = maindb.Users.Select(m => new { m.Id, m.ParentNav }).Where(m => m.ParentNav.Contains(UidString)).ToList();
  62. foreach (var subuser in subusers)
  63. {
  64. uids.Add(subuser.Id);
  65. }
  66. uids.Add(TopUserId);
  67. }
  68. // string UidString = "," + UserId + ",";
  69. // var subusers = maindb.Users.Select(m => new { m.Id, m.ParentNav }).Where(m => m.ParentNav.Contains(UidString)).ToList();
  70. // foreach (var subuser in subusers)
  71. // {
  72. // uids.Add(subuser.Id);
  73. // }
  74. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  75. IQueryable<StoreHouse> query = maindb.StoreHouse.Where(m => m.Status == 1);
  76. if (UserId == 1)
  77. {
  78. query = query.Where(m => m.LaveNum > 0 && m.BrandId == BrandId);
  79. }
  80. else
  81. {
  82. query = query.Where(m => uids.Contains(m.UserId) && m.LaveNum > 0 && m.BrandId == BrandId);
  83. }
  84. // IQueryable<StoreHouse> query = maindb.StoreHouse.Where(m => m.LaveNum > 0 && m.BrandId == BrandId);
  85. if (!string.IsNullOrEmpty(searchContent))
  86. {
  87. query = query.Where(m => m.StoreName.Contains(searchContent));
  88. }
  89. query = query.OrderBy(m => m.UserId);
  90. if (PageNum == 1)
  91. {
  92. query = query.Take(PageSize);
  93. }
  94. else
  95. {
  96. int skipNum = PageSize * (PageNum - 1);
  97. query = query.Skip(skipNum).Take(PageSize);
  98. }
  99. foreach (StoreHouse subdata in query.ToList())
  100. {
  101. // StoreHouse subdata = StoreHouseDbconn.Instance.Get(id) ?? new StoreHouse();
  102. Dictionary<string, object> curData = new Dictionary<string, object>();
  103. curData.Add("StoreName", subdata.StoreName); //仓库名称
  104. curData.Add("Address", subdata.Address); //仓库地址
  105. curData.Add("LaveNum", subdata.LaveNum); //剩余库存数
  106. curData.Add("Areas", function.CheckNull(subdata.Areas).Replace(",", "")); //所属地区
  107. curData.Add("Id", subdata.Id); //Id
  108. dataList.Add(curData);
  109. }
  110. return dataList;
  111. }
  112. #endregion
  113. #region 创客-商城-确认支付-发货仓库详情
  114. [Authorize]
  115. public JsonResult SendStoreDetail(string value)
  116. {
  117. value = DesDecrypt(value);
  118. JsonData data = JsonMapper.ToObject(value);
  119. Dictionary<string, object> Obj = SendStoreDetailDo(value);
  120. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  121. }
  122. public Dictionary<string, object> SendStoreDetailDo(string value)
  123. {
  124. JsonData data = JsonMapper.ToObject(value);
  125. string UserId = data["UserId"].ToString(); //创客Id
  126. Dictionary<string, object> Obj = new Dictionary<string, object>();
  127. StoreHouse query = new StoreHouse();
  128. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  129. query = StoreHouseDbconn.Instance.Get(Id) ?? new StoreHouse();
  130. Obj.Add("StoreName", query.StoreName); //仓库名称
  131. Obj.Add("Address", query.Address); //仓库地址
  132. Obj.Add("LaveNum", query.LaveNum); //剩余库存数
  133. Obj.Add("Areas", function.CheckNull(query.Areas).Replace(",", "")); //所属地区
  134. Users user = UsersDbconn.Instance.Get(query.ManageUserId) ?? new Users();
  135. Obj.Add("ManageName", user.RealName); //仓库联系人名称
  136. if(query.ManageUserId == 1)
  137. {
  138. Obj.Add("ManageMobile", "19141324516"); //仓库联系人手机号
  139. }
  140. else
  141. {
  142. Obj.Add("ManageMobile", user.Mobile); //仓库联系人手机号
  143. }
  144. Obj.Add("Id", query.Id); //Id
  145. return Obj;
  146. }
  147. #endregion
  148. #region 首页-仓库管理-主界面产品
  149. [Authorize]
  150. public JsonResult IndexList(string value)
  151. {
  152. value = DesDecrypt(value);
  153. JsonData data = JsonMapper.ToObject(value);
  154. List<Dictionary<string, object>> dataList = IndexListDo(value);
  155. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  156. }
  157. public List<Dictionary<string, object>> IndexListDo(string value)
  158. {
  159. JsonData data = JsonMapper.ToObject(value);
  160. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //仓库归属人
  161. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  162. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  163. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  164. List<StoreHouse> query = maindb.StoreHouse.Where(m => m.UserId == UserId && m.Sort == 0 && m.Status > 0).ToList(); //StoreHouseDbconn.Instance.GetList(UserId, PageNum, PageSize);
  165. foreach (StoreHouse subdata in query)
  166. {
  167. // StoreHouse subdata = StoreHouseDbconn.Instance.Get(id) ?? new StoreHouse();
  168. Dictionary<string, object> curData = new Dictionary<string, object>();
  169. curData.Add("ProductName", subdata.ProductName); //产品名称
  170. int PreCount = maindb.PreSendStockDetail.Count(m => m.FromStoreId == subdata.Id && m.ApplyFlag == 0 && m.Status >= 0 && m.Status <= 1);
  171. curData.Add("LaveNum", subdata.LaveNum); //剩余库存数
  172. curData.Add("PreCount", PreCount); //预发机数
  173. curData.Add("Id", subdata.Id); //Id
  174. curData.Add("BrandId", subdata.BrandId);
  175. curData.Add("Icon", ""); //产品图标
  176. dataList.Add(curData);
  177. }
  178. return dataList;
  179. }
  180. #endregion
  181. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  182. /// <summary>
  183. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  184. /// </summary>
  185. /// <param name="value">请求的参数(json字符串)</param>
  186. /// <param name="signField">要签名的字段</param>
  187. /// <returns></returns>
  188. private string CheckSign(string value, string[] signField)
  189. {
  190. JsonData json = JsonMapper.ToObject(value);
  191. Dictionary<string, string> dic = new Dictionary<string, string>();
  192. for (int i = 0; i < signField.Length; i++)
  193. {
  194. dic.Add(signField[i], json[signField[i]].ToString());
  195. }
  196. string sign = json["sign"].ToString(); //客户端签名字符串
  197. return new Sign().sign(dic, sign);
  198. }
  199. #endregion
  200. }
  201. }