StoreBalanceController.cs 17 KB

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