StoreBalanceController.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /*
  2. * 仓库库存变动信息
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.Models;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  18. namespace MySystem.Areas.Admin.Controllers
  19. {
  20. [Area("Admin")]
  21. [Route("Admin/[controller]/[action]")]
  22. public class StoreBalanceController : BaseController
  23. {
  24. public StoreBalanceController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  27. }
  28. #region 仓库库存变动信息列表
  29. /// <summary>
  30. /// 根据条件查询仓库库存变动信息列表
  31. /// </summary>
  32. /// <returns></returns>
  33. public IActionResult Index(StoreBalance data, string right)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. return View();
  38. }
  39. #endregion
  40. #region 根据条件查询仓库库存变动信息列表
  41. /// <summary>
  42. /// 仓库库存变动信息列表
  43. /// </summary>
  44. /// <returns></returns>
  45. public JsonResult IndexData(StoreBalance data, string StoreIdStoreNo, string StoreIdStoreName, string TransTypeSelect, string BrandIdSelect, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("CreateDate", "3"); //时间
  49. Fields.Add("TransRecordNo", "1"); //交易流水编号
  50. string condition = " and Status>-1";
  51. //仓库仓库编号
  52. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  53. {
  54. condition += " and StoreId in (select StoreId from StoreForStoreNo where StoreNo='" + StoreIdStoreNo + "')";
  55. }
  56. //仓库仓库名称
  57. if (!string.IsNullOrEmpty(StoreIdStoreName))
  58. {
  59. condition += " and StoreId in (select StoreId from StoreForStoreName where StoreName='" + StoreIdStoreName + "')";
  60. }
  61. //交易类型
  62. if (!string.IsNullOrEmpty(TransTypeSelect))
  63. {
  64. condition += " and TransType=" + TransTypeSelect;
  65. }
  66. //产品类型
  67. if (!string.IsNullOrEmpty(BrandIdSelect))
  68. {
  69. condition += " and BrandId=" + BrandIdSelect;
  70. }
  71. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreBalance", Fields, "Id desc", "0", page, limit, condition);
  72. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  73. foreach (Dictionary<string, object> dic in diclist)
  74. {
  75. //仓库
  76. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  77. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  78. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  79. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  80. dic.Remove("StoreId");
  81. //交易类型
  82. int TransType = int.Parse(dic["TransType"].ToString());
  83. if (TransType == 0) dic["TransType"] = "入库";
  84. if (TransType == 1) dic["TransType"] = "调拨";
  85. if (TransType == 2) dic["TransType"] = "出货";
  86. //产品类型
  87. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  88. //操作符
  89. string OpSymbol = dic["OpSymbol"].ToString();
  90. if (OpSymbol == "1") dic["OpSymbol"] = "增加";
  91. if (OpSymbol == "2") dic["OpSymbol"] = "减少";
  92. if (OpSymbol == "") dic["OpSymbol"] = "";
  93. }
  94. Dictionary<string, object> other = new Dictionary<string, object>();
  95. other.Add("InCount", 0);
  96. other.Add("MoveInCount", 0);
  97. other.Add("MoveOutCount", 0);
  98. other.Add("OutCount", 0);
  99. obj.Add("other", other);
  100. return Json(obj);
  101. }
  102. #endregion
  103. #region 增加仓库库存变动信息
  104. /// <summary>
  105. /// 增加或修改仓库库存变动信息信息
  106. /// </summary>
  107. /// <returns></returns>
  108. public IActionResult Add(string right)
  109. {
  110. ViewBag.RightInfo = RightInfo;
  111. ViewBag.right = right;
  112. return View();
  113. }
  114. #endregion
  115. #region 增加仓库库存变动信息
  116. /// <summary>
  117. /// 增加或修改仓库库存变动信息信息
  118. /// </summary>
  119. /// <returns></returns>
  120. [HttpPost]
  121. public string Add(StoreBalance data)
  122. {
  123. Dictionary<string, object> Fields = new Dictionary<string, object>();
  124. Fields.Add("SeoTitle", data.SeoTitle);
  125. Fields.Add("SeoKeyword", data.SeoKeyword);
  126. Fields.Add("SeoDescription", data.SeoDescription);
  127. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreBalance", Fields, 0);
  128. AddSysLog(data.Id.ToString(), "StoreBalance", "add");
  129. db.SaveChanges();
  130. return "success";
  131. }
  132. #endregion
  133. #region 修改仓库库存变动信息
  134. /// <summary>
  135. /// 增加或修改仓库库存变动信息信息
  136. /// </summary>
  137. /// <returns></returns>
  138. public IActionResult Edit(string right, int Id = 0)
  139. {
  140. ViewBag.RightInfo = RightInfo;
  141. ViewBag.right = right;
  142. StoreBalance editData = db.StoreBalance.FirstOrDefault(m => m.Id == Id) ?? new StoreBalance();
  143. ViewBag.data = editData;
  144. return View();
  145. }
  146. #endregion
  147. #region 修改仓库库存变动信息
  148. /// <summary>
  149. /// 增加或修改仓库库存变动信息信息
  150. /// </summary>
  151. /// <returns></returns>
  152. [HttpPost]
  153. public string Edit(StoreBalance data)
  154. {
  155. Dictionary<string, object> Fields = new Dictionary<string, object>();
  156. Fields.Add("SeoTitle", data.SeoTitle);
  157. Fields.Add("SeoKeyword", data.SeoKeyword);
  158. Fields.Add("SeoDescription", data.SeoDescription);
  159. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreBalance", Fields, data.Id);
  160. AddSysLog(data.Id.ToString(), "StoreBalance", "update");
  161. db.SaveChanges();
  162. return "success";
  163. }
  164. #endregion
  165. #region 删除仓库库存变动信息信息
  166. /// <summary>
  167. /// 删除仓库库存变动信息信息
  168. /// </summary>
  169. /// <returns></returns>
  170. public string Delete(string Id)
  171. {
  172. string[] idlist = Id.Split(new char[] { ',' });
  173. AddSysLog(Id, "StoreBalance", "del");
  174. foreach (string subid in idlist)
  175. {
  176. int id = int.Parse(subid);
  177. Dictionary<string, object> Fields = new Dictionary<string, object>();
  178. Fields.Add("Status", -1);
  179. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreBalance", Fields, id);
  180. }
  181. db.SaveChanges();
  182. return "success";
  183. }
  184. #endregion
  185. #region 开启
  186. /// <summary>
  187. /// 开启
  188. /// </summary>
  189. /// <returns></returns>
  190. public string Open(string Id)
  191. {
  192. string[] idlist = Id.Split(new char[] { ',' });
  193. AddSysLog(Id, "StoreBalance", "open");
  194. foreach (string subid in idlist)
  195. {
  196. int id = int.Parse(subid);
  197. Dictionary<string, object> Fields = new Dictionary<string, object>();
  198. Fields.Add("Status", 1);
  199. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreBalance", Fields, id);
  200. }
  201. db.SaveChanges();
  202. return "success";
  203. }
  204. #endregion
  205. #region 关闭
  206. /// <summary>
  207. /// 关闭
  208. /// </summary>
  209. /// <returns></returns>
  210. public string Close(string Id)
  211. {
  212. string[] idlist = Id.Split(new char[] { ',' });
  213. AddSysLog(Id, "StoreBalance", "close");
  214. foreach (string subid in idlist)
  215. {
  216. int id = int.Parse(subid);
  217. Dictionary<string, object> Fields = new Dictionary<string, object>();
  218. Fields.Add("Status", 0);
  219. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreBalance", Fields, id);
  220. }
  221. db.SaveChanges();
  222. return "success";
  223. }
  224. #endregion
  225. #region 排序
  226. /// <summary>
  227. /// 排序
  228. /// </summary>
  229. /// <param name="Id"></param>
  230. public string Sort(int Id, int Sort)
  231. {
  232. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreBalance", Sort, Id);
  233. AddSysLog(Id.ToString(), "StoreBalance", "sort");
  234. return "success";
  235. }
  236. #endregion
  237. #region 导入数据
  238. /// <summary>
  239. /// 导入数据
  240. /// </summary>
  241. /// <param name="ExcelData"></param>
  242. public string Import(string ExcelData)
  243. {
  244. ExcelData = HttpUtility.UrlDecode(ExcelData);
  245. JsonData list = JsonMapper.ToObject(ExcelData);
  246. for (int i = 1; i < list.Count; i++)
  247. {
  248. JsonData dr = list[i];
  249. db.StoreBalance.Add(new StoreBalance()
  250. {
  251. CreateDate = DateTime.Now,
  252. UpdateDate = DateTime.Now,
  253. });
  254. db.SaveChanges();
  255. }
  256. AddSysLog("0", "StoreBalance", "Import");
  257. return "success";
  258. }
  259. #endregion
  260. #region 导出Excel
  261. /// <summary>
  262. /// 导出Excel
  263. /// </summary>
  264. /// <returns></returns>
  265. public JsonResult ExportExcel(StoreBalance data, string StoreIdStoreNo, string StoreIdStoreName, string TransTypeSelect, string BrandIdSelect)
  266. {
  267. Dictionary<string, string> Fields = new Dictionary<string, string>();
  268. Fields.Add("CreateDate", "3"); //时间
  269. Fields.Add("TransRecordNo", "1"); //交易流水编号
  270. string condition = " and Status>-1";
  271. //仓库仓库编号
  272. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  273. {
  274. condition += " and StoreId in (select StoreId from StoreForStoreNo where StoreNo='" + StoreIdStoreNo + "')";
  275. }
  276. //仓库仓库名称
  277. if (!string.IsNullOrEmpty(StoreIdStoreName))
  278. {
  279. condition += " and StoreId in (select StoreId from StoreForStoreName where StoreName='" + StoreIdStoreName + "')";
  280. }
  281. //交易类型
  282. if (!string.IsNullOrEmpty(TransTypeSelect))
  283. {
  284. condition += " and TransType=" + TransTypeSelect;
  285. }
  286. //产品类型
  287. if (!string.IsNullOrEmpty(BrandIdSelect))
  288. {
  289. condition += " and BrandId=" + BrandIdSelect;
  290. }
  291. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreBalance", Fields, "Id desc", "0", 1, 20000, condition, "StoreId,TransRecordNo,TransType,BrandId,OpStoreNum,OpSymbol,BeforeTotalNum,AfterTotalNum,BeforeLaveNum,AfterLaveNum,BeforeOutNum,AfterOutNum", false);
  292. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  293. foreach (Dictionary<string, object> dic in diclist)
  294. {
  295. //仓库
  296. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  297. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  298. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  299. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  300. dic.Remove("StoreId");
  301. //交易类型
  302. int TransType = int.Parse(dic["TransType"].ToString());
  303. if (TransType == 0) dic["TransType"] = "入库";
  304. if (TransType == 1) dic["TransType"] = "调拨";
  305. if (TransType == 2) dic["TransType"] = "出货";
  306. //产品类型
  307. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  308. //操作符
  309. string OpSymbol = dic["OpSymbol"].ToString();
  310. if (OpSymbol == "1") dic["OpSymbol"] = "增加";
  311. if (OpSymbol == "2") dic["OpSymbol"] = "减少";
  312. if (OpSymbol == "") dic["OpSymbol"] = "";
  313. }
  314. Dictionary<string, object> result = new Dictionary<string, object>();
  315. result.Add("Status", "1");
  316. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  317. result.Add("Obj", diclist);
  318. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  319. ReturnFields.Add("StoreIdStoreNo", "仓库仓库编号");
  320. ReturnFields.Add("StoreIdStoreName", "仓库仓库名称");
  321. ReturnFields.Add("TransRecordNo", "交易流水编号");
  322. ReturnFields.Add("TransType", "交易类型");
  323. ReturnFields.Add("BrandId", "产品类型");
  324. ReturnFields.Add("OpStoreNum", "操作库存数");
  325. ReturnFields.Add("OpSymbol", "操作符");
  326. ReturnFields.Add("BeforeTotalNum", "操作前总库存数");
  327. ReturnFields.Add("AfterTotalNum", "操作后总库存数");
  328. ReturnFields.Add("BeforeLaveNum", "操作前剩余库存数");
  329. ReturnFields.Add("AfterLaveNum", "操作后剩余库存数");
  330. ReturnFields.Add("BeforeOutNum", "操作前出库数");
  331. ReturnFields.Add("AfterOutNum", "操作后出库数");
  332. result.Add("Fields", ReturnFields);
  333. AddSysLog("0", "StoreBalance", "ExportExcel");
  334. return Json(result);
  335. }
  336. #endregion
  337. }
  338. }