SmallStoreHouseController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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
  15. {
  16. [Area("Api")]
  17. [Route("Api/v1/pos/[controller]/[action]")]
  18. public class SmallStoreHouseController : BaseController
  19. {
  20. public SmallStoreHouseController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  21. {
  22. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  23. }
  24. #region 创客-首页-仓库管理-小分仓-列表
  25. [Authorize]
  26. public JsonResult List(string value)
  27. {
  28. value = DesDecrypt(value);
  29. JsonData data = JsonMapper.ToObject(value);
  30. List<Dictionary<string, object>> dataList = ListDo(value);
  31. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  32. }
  33. public List<Dictionary<string, object>> ListDo(string value)
  34. {
  35. JsonData data = JsonMapper.ToObject(value);
  36. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));//出货创客Id
  37. string SearchKey = data["SearchKey"].ToString(); //搜索关键词
  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. List<KqProducts> brandList = maindb.KqProducts.ToList();
  42. DataTable dt = new DataTable();
  43. if (!string.IsNullOrEmpty(SearchKey))
  44. {
  45. var UserForMakerCode = maindb.UserForMakerCode.FirstOrDefault(m => m.MakerCode == SearchKey);
  46. if (UserForMakerCode != null)
  47. {
  48. var ToUserIds = UserForMakerCode.UserId.ToString();
  49. var ToUserIdss = Convert.ToInt32(ToUserIds);
  50. dt = OtherMySqlConn.dtable("select ToUserId,count(Id) count from PreSendStockDetail where FromUserId='" + UserId + "' and `Status`>=0 and `Status`<=1 and ApplyFlag=0 and ToUserId='" + ToUserIdss + "' group by ToUserId");
  51. }
  52. else
  53. {
  54. var SnNo = SearchKey;
  55. var SnNos = Convert.ToInt32(SnNo);
  56. dt = OtherMySqlConn.dtable("select ToUserId,count(Id) count from PreSendStockDetail where FromUserId='" + UserId + "' and `Status`>=0 and `Status`<=1 and ApplyFlag=0 and SnNo like '%" + SnNos + "%' group by ToUserId");
  57. }
  58. }
  59. else
  60. {
  61. dt = OtherMySqlConn.dtable("select ToUserId,count(Id) count from PreSendStockDetail where FromUserId='" + UserId + "' and `Status`>=0 and `Status`<=1 and ApplyFlag=0 group by ToUserId");
  62. }
  63. // foreach (DataRow item in dt.Rows)
  64. // {
  65. // int ToUserId = int.Parse(item["ToUserId"].ToString());
  66. // Dictionary<string, object> userInfo = new Dictionary<string, object>();
  67. // Users user = maindb.Users.FirstOrDefault(m => m.Id == ToUserId);
  68. // userInfo.Add("UserId", ToUserId);//创客Id
  69. // userInfo.Add("UserName", user.RealName);//创客姓名
  70. // userInfo.Add("MakerCode", user.MakerCode);//创客编号
  71. // userInfo.Add("Mobile", user.Mobile);//手机号
  72. // // userInfo.Add("HeadPhoto", DefaultPic(user.HeadPhoto));//头像
  73. // userInfo.Add("HeadPhoto", DefaultPic(user.HeadPhoto));//头像
  74. // userInfo.Add("UserLevel", user.UserLevel);//职级
  75. // List<Dictionary<string, object>> brands = new List<Dictionary<string, object>>();
  76. // bool op = false;
  77. // foreach (var items in brandList)
  78. // {
  79. // List<PreSendStockDetail> mydata = maindb.PreSendStockDetail.Where(m => m.FromUserId == UserId && m.ToUserId == ToUserId && m.BrandId == items.Id && m.Status >= 0 && m.Status <= 1 && m.ApplyFlag == 0).ToList();
  80. // if (mydata.Count > 0)
  81. // {
  82. // Dictionary<string, object> brandInfo = new Dictionary<string, object>();
  83. // KqProducts kqProducts = maindb.KqProducts.FirstOrDefault(m => m.Id == items.Id);
  84. // brandInfo.Add("Id", items.Id);//产品类型Id
  85. // brandInfo.Add("Name", items.Name);//产品类型名称
  86. // List<Dictionary<string, object>> snList = new List<Dictionary<string, object>>();
  87. // foreach (var subdata in mydata)
  88. // {
  89. // Dictionary<string, object> curData = new Dictionary<string, object>();
  90. // var pos = maindb.PosMachinesTwo.FirstOrDefault( m => m.Id == subdata.SnId) ?? new PosMachinesTwo();
  91. // curData.Add("Id", subdata.Id);//记录Id
  92. // curData.Add("SnId", subdata.SnId);//机具Id
  93. // curData.Add("SnNo", subdata.SnNo); //机具SN
  94. // curData.Add("Status", subdata.Status); //确认状态(0 待确认,1 已确认)
  95. // curData.Add("isGrant", subdata.AuthFlag); //占用小分仓额度标记
  96. // curData.Add("CreateDate", pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));//入库时间
  97. // snList.Add(curData);
  98. // }
  99. // brandInfo.Add("SnList", snList);
  100. // brands.Add(brandInfo);
  101. // op = true;
  102. // }
  103. // }
  104. //new 优化
  105. foreach (DataRow item in dt.Rows)
  106. {
  107. int ToUserId = int.Parse(item["ToUserId"].ToString());
  108. Dictionary<string, object> userInfo = new Dictionary<string, object>();
  109. Users user = maindb.Users.FirstOrDefault(m => m.Id == ToUserId);
  110. userInfo.Add("UserId", ToUserId);//创客Id
  111. userInfo.Add("UserName", user.RealName);//创客姓名
  112. userInfo.Add("MakerCode", user.MakerCode);//创客编号
  113. userInfo.Add("Mobile", user.Mobile);//手机号
  114. userInfo.Add("HeadPhoto", DefaultPic(user.HeadPhoto));//头像
  115. userInfo.Add("UserLevel", user.UserLevel);//职级
  116. List<Dictionary<string, object>> brands = new List<Dictionary<string, object>>();
  117. List<PreSendStockDetail> mydata = maindb.PreSendStockDetail.Where(m => m.FromUserId == UserId && m.ToUserId == ToUserId && m.Status >= 0 && m.Status <= 1 && m.ApplyFlag == 0).ToList();
  118. bool op = false;
  119. foreach (var items in brandList)
  120. {
  121. var mydatas = mydata.Where(m => m.BrandId == items.Id).ToList();
  122. if (mydatas.Count > 0)
  123. {
  124. Dictionary<string, object> brandInfo = new Dictionary<string, object>();
  125. KqProducts kqProducts = maindb.KqProducts.FirstOrDefault(m => m.Id == items.Id);
  126. brandInfo.Add("Id", items.Id);//产品类型Id
  127. brandInfo.Add("Name", items.Name);//产品类型名称
  128. List<Dictionary<string, object>> snList = new List<Dictionary<string, object>>();
  129. foreach (var subdata in mydatas)
  130. {
  131. Dictionary<string, object> curData = new Dictionary<string, object>();
  132. var pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == subdata.SnId) ?? new PosMachinesTwo();
  133. curData.Add("Id", subdata.Id);//记录Id
  134. curData.Add("SnId", subdata.SnId);//机具Id
  135. curData.Add("SnNo", subdata.SnNo); //机具SN
  136. curData.Add("Status", subdata.Status); //确认状态(0 待确认,1 已确认)
  137. curData.Add("isGrant", subdata.AuthFlag); //占用小分仓额度标记
  138. curData.Add("CreateDate", pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));//入库时间
  139. snList.Add(curData);
  140. }
  141. brandInfo.Add("SnList", snList);
  142. brands.Add(brandInfo);
  143. op = true;
  144. }
  145. }
  146. if (op)
  147. {
  148. userInfo.Add("BrandList", brands);
  149. dataList.Add(userInfo);
  150. }
  151. }
  152. dataList = dataList.Skip((PageNum - 1) * PageSize).Take(PageSize).ToList();//分页的重点
  153. return dataList;
  154. }
  155. #endregion
  156. #region 创客-首页-仓库管理-小分仓-查询预发机数量
  157. [Authorize]
  158. public JsonResult Detail(string value)
  159. {
  160. value = DesDecrypt(value);
  161. JsonData data = JsonMapper.ToObject(value);
  162. Dictionary<string, object> Obj = DetailDo(value);
  163. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  164. }
  165. public Dictionary<string, object> DetailDo(string value)
  166. {
  167. JsonData data = JsonMapper.ToObject(value);
  168. string MakerCode = data["MakerCode"].ToString(); //搜索创客编号
  169. int FromUserId = int.Parse(function.CheckInt(data["FromUserId"].ToString())); //出货创客Id
  170. int FromStoreId = int.Parse(function.CheckInt(data["FromStoreId"].ToString())); //出货创客仓库Id
  171. var UserIdStr = FromUserId.ToString();
  172. Users users = maindb.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  173. Dictionary<string, object> Obj = new Dictionary<string, object>();
  174. SmallStoreHouse query = maindb.SmallStoreHouse.FirstOrDefault(m => m.UserId == users.Id);
  175. if (query == null)
  176. {
  177. query = maindb.SmallStoreHouse.Add(new SmallStoreHouse()
  178. {
  179. CreateDate = DateTime.Now, //创建时间
  180. SeoDescription = UserIdStr,//描述--创建创客Id
  181. // Remark = FromUserId.ToString(),//备注--创建创客Id
  182. Mobile = users.Mobile, //手机号
  183. LaveNum = 10, //剩余库存数
  184. UserId = users.Id, //所属创客Id
  185. StoreName = users.RealName, //仓库名称
  186. StoreNo = users.MakerCode, //仓库编号
  187. }).Entity;
  188. maindb.SaveChanges();
  189. }
  190. else if (query != null)
  191. {
  192. if (!query.SeoDescription.Contains(UserIdStr))
  193. {
  194. query.SeoDescription = query.SeoDescription + ',' + UserIdStr;
  195. maindb.SaveChanges();
  196. }
  197. }
  198. Obj.Add("LaveNum", query.LaveNum); //剩余库存数
  199. Obj.Add("TotalNum", query.TotalNum); //库存数
  200. return Obj;
  201. }
  202. #endregion
  203. #region 创客-首页-仓库管理-出货记录-按天
  204. [Authorize]
  205. public JsonResult ForDate(string value)
  206. {
  207. value = DesDecrypt(value);
  208. JsonData data = JsonMapper.ToObject(value);
  209. List<Dictionary<string, object>> dataList = ForDateDo(value);
  210. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  211. }
  212. public List<Dictionary<string, object>> ForDateDo(string value)
  213. {
  214. JsonData data = JsonMapper.ToObject(value);
  215. int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库
  216. int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
  217. string Month = data["Month"].ToString(); //月份
  218. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  219. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  220. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  221. IQueryable<StoreStockChange> query = maindb.StoreStockChange.Where(m => m.Status > 0);
  222. if (!string.IsNullOrEmpty(data["StoreId"].ToString()))
  223. {
  224. query = query.Where(m => m.StoreId == StoreId);
  225. }
  226. if (!string.IsNullOrEmpty(data["BrandId"].ToString()))
  227. {
  228. query = query.Where(m => m.BrandId == BrandId);
  229. }
  230. int TotalCount = query.Count();
  231. query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
  232. if (PageNum == 1)
  233. {
  234. query = query.Take(PageSize);
  235. }
  236. else
  237. {
  238. int skipNum = PageSize * (PageNum - 1);
  239. query = query.Skip(skipNum).Take(PageSize);
  240. }
  241. var mydata = query.ToList();
  242. foreach (var subdata in mydata)
  243. {
  244. Dictionary<string, object> curData = new Dictionary<string, object>();
  245. curData.Add("Date", ""); //日期
  246. curData.Add("SnCount", ""); //机具数量
  247. curData.Add("SnNos", ""); //机具列表
  248. dataList.Add(curData);
  249. }
  250. return dataList;
  251. }
  252. #endregion
  253. #region 创客-首页-仓库管理-出货记录-按月
  254. [Authorize]
  255. public JsonResult ForMonth(string value)
  256. {
  257. value = DesDecrypt(value);
  258. JsonData data = JsonMapper.ToObject(value);
  259. List<Dictionary<string, object>> dataList = ForMonthDo(value);
  260. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  261. }
  262. public List<Dictionary<string, object>> ForMonthDo(string value)
  263. {
  264. JsonData data = JsonMapper.ToObject(value);
  265. int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库
  266. int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
  267. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  268. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  269. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  270. IQueryable<StoreStockChange> query = maindb.StoreStockChange.Where(m => m.Status > 0);
  271. if (!string.IsNullOrEmpty(data["StoreId"].ToString()))
  272. {
  273. query = query.Where(m => m.StoreId == StoreId);
  274. }
  275. if (!string.IsNullOrEmpty(data["BrandId"].ToString()))
  276. {
  277. query = query.Where(m => m.BrandId == BrandId);
  278. }
  279. int TotalCount = query.Count();
  280. query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
  281. if (PageNum == 1)
  282. {
  283. query = query.Take(PageSize);
  284. }
  285. else
  286. {
  287. int skipNum = PageSize * (PageNum - 1);
  288. query = query.Skip(skipNum).Take(PageSize);
  289. }
  290. var mydata = query.ToList();
  291. foreach (var subdata in mydata)
  292. {
  293. Dictionary<string, object> curData = new Dictionary<string, object>();
  294. curData.Add("Month", ""); //月份
  295. curData.Add("SendCount", ""); //总发货
  296. dataList.Add(curData);
  297. }
  298. return dataList;
  299. }
  300. #endregion
  301. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  302. /// <summary>
  303. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  304. /// </summary>
  305. /// <param name="value">请求的参数(json字符串)</param>
  306. /// <param name="signField">要签名的字段</param>
  307. /// <returns></returns>
  308. private string CheckSign(string value, string[] signField)
  309. {
  310. JsonData json = JsonMapper.ToObject(value);
  311. Dictionary<string, string> dic = new Dictionary<string, string>();
  312. for (int i = 0; i < signField.Length; i++)
  313. {
  314. dic.Add(signField[i], json[signField[i]].ToString());
  315. }
  316. string sign = json["sign"].ToString(); //客户端签名字符串
  317. return new Sign().sign(dic, sign);
  318. }
  319. #endregion
  320. }
  321. }