StoreBalanceController.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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("TransRecordNo", "1"); //交易流水编号
  50. string condition = " and Status>-1";
  51. //仓库编号
  52. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  53. {
  54. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
  55. }
  56. //仓库名称
  57. if (!string.IsNullOrEmpty(StoreIdStoreName))
  58. {
  59. condition += " and StoreId in (select StoreId from StoreForStoreName where Name='" + StoreIdStoreName + "')";
  60. }
  61. //操作时间
  62. if (!string.IsNullOrEmpty(CreateDateData))
  63. {
  64. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  65. string start = datelist[0];
  66. string end = datelist[1];
  67. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  68. }
  69. //交易类型
  70. if (!string.IsNullOrEmpty(TransTypeSelect))
  71. {
  72. condition += " and TransType=" + TransTypeSelect;
  73. }
  74. //产品类型
  75. if (!string.IsNullOrEmpty(BrandIdSelect))
  76. {
  77. condition += " and BrandId=" + BrandIdSelect;
  78. }
  79. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreBalance", Fields, "Id desc", "0", page, limit, condition);
  80. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  81. foreach (Dictionary<string, object> dic in diclist)
  82. {
  83. //仓库
  84. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  85. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  86. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  87. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  88. dic.Remove("StoreId");
  89. //交易类型
  90. int TransType = int.Parse(dic["TransType"].ToString());
  91. if (TransType == 0) dic["TransType"] = "入库";
  92. if (TransType == 1) dic["TransType"] = "调拨";
  93. if (TransType == 2) dic["TransType"] = "出货";
  94. //产品类型
  95. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  96. //操作符
  97. string OpSymbol = dic["OpSymbol"].ToString();
  98. if (OpSymbol == "1") dic["OpSymbol"] = "增加";
  99. if (OpSymbol == "2") dic["OpSymbol"] = "减少";
  100. if (OpSymbol == "") dic["OpSymbol"] = "";
  101. }
  102. Dictionary<string, object> other = new Dictionary<string, object>();
  103. int InCount = 0;//入库
  104. int MoveInCount = 0;//调拨入库
  105. int MoveOutCount = 0;//调拨出库
  106. int OutCount = 0;//出库
  107. DataTable dt = OtherMySqlConn.dtable("select sum(OpStoreNum) from StoreBalance where TransType=0" + condition);
  108. if (dt.Rows.Count > 0)
  109. {
  110. InCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString()));
  111. }
  112. dt = OtherMySqlConn.dtable("select sum(OpStoreNum) from StoreBalance where TransType=1 and OpSymbol='+'" + condition);
  113. if (dt.Rows.Count > 0)
  114. {
  115. MoveInCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString()));
  116. }
  117. dt = OtherMySqlConn.dtable("select sum(OpStoreNum) from StoreBalance where TransType=1 and OpSymbol='-'" + condition);
  118. if (dt.Rows.Count > 0)
  119. {
  120. MoveOutCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString()));
  121. }
  122. dt = OtherMySqlConn.dtable("select sum(OpStoreNum) from StoreBalance where TransType=2" + condition);
  123. if (dt.Rows.Count > 0)
  124. {
  125. OutCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString()));
  126. }
  127. other.Add("InCount", InCount);
  128. other.Add("MoveInCount", MoveInCount);
  129. other.Add("MoveOutCount", MoveOutCount);
  130. other.Add("OutCount", OutCount);
  131. obj.Add("other", other);
  132. return Json(obj);
  133. }
  134. #endregion
  135. #region 增加仓库库存变动信息
  136. /// <summary>
  137. /// 增加或修改仓库库存变动信息信息
  138. /// </summary>
  139. /// <returns></returns>
  140. public IActionResult Add(string right)
  141. {
  142. ViewBag.RightInfo = RightInfo;
  143. ViewBag.right = right;
  144. return View();
  145. }
  146. #endregion
  147. #region 增加仓库库存变动信息
  148. /// <summary>
  149. /// 增加或修改仓库库存变动信息信息
  150. /// </summary>
  151. /// <returns></returns>
  152. [HttpPost]
  153. public string Add(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. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreBalance", Fields, 0);
  160. AddSysLog(data.Id.ToString(), "StoreBalance", "add");
  161. db.SaveChanges();
  162. return "success";
  163. }
  164. #endregion
  165. #region 修改仓库库存变动信息
  166. /// <summary>
  167. /// 增加或修改仓库库存变动信息信息
  168. /// </summary>
  169. /// <returns></returns>
  170. public IActionResult Edit(string right, int Id = 0)
  171. {
  172. ViewBag.RightInfo = RightInfo;
  173. ViewBag.right = right;
  174. StoreBalance editData = db.StoreBalance.FirstOrDefault(m => m.Id == Id) ?? new StoreBalance();
  175. ViewBag.data = editData;
  176. return View();
  177. }
  178. #endregion
  179. #region 修改仓库库存变动信息
  180. /// <summary>
  181. /// 增加或修改仓库库存变动信息信息
  182. /// </summary>
  183. /// <returns></returns>
  184. [HttpPost]
  185. public string Edit(StoreBalance data)
  186. {
  187. Dictionary<string, object> Fields = new Dictionary<string, object>();
  188. Fields.Add("SeoTitle", data.SeoTitle);
  189. Fields.Add("SeoKeyword", data.SeoKeyword);
  190. Fields.Add("SeoDescription", data.SeoDescription);
  191. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreBalance", Fields, data.Id);
  192. AddSysLog(data.Id.ToString(), "StoreBalance", "update");
  193. db.SaveChanges();
  194. return "success";
  195. }
  196. #endregion
  197. #region 删除仓库库存变动信息信息
  198. /// <summary>
  199. /// 删除仓库库存变动信息信息
  200. /// </summary>
  201. /// <returns></returns>
  202. public string Delete(string Id)
  203. {
  204. string[] idlist = Id.Split(new char[] { ',' });
  205. AddSysLog(Id, "StoreBalance", "del");
  206. foreach (string subid in idlist)
  207. {
  208. int id = int.Parse(subid);
  209. Dictionary<string, object> Fields = new Dictionary<string, object>();
  210. Fields.Add("Status", -1);
  211. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreBalance", Fields, id);
  212. }
  213. db.SaveChanges();
  214. return "success";
  215. }
  216. #endregion
  217. #region 开启
  218. /// <summary>
  219. /// 开启
  220. /// </summary>
  221. /// <returns></returns>
  222. public string Open(string Id)
  223. {
  224. string[] idlist = Id.Split(new char[] { ',' });
  225. AddSysLog(Id, "StoreBalance", "open");
  226. foreach (string subid in idlist)
  227. {
  228. int id = int.Parse(subid);
  229. Dictionary<string, object> Fields = new Dictionary<string, object>();
  230. Fields.Add("Status", 1);
  231. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreBalance", Fields, id);
  232. }
  233. db.SaveChanges();
  234. return "success";
  235. }
  236. #endregion
  237. #region 关闭
  238. /// <summary>
  239. /// 关闭
  240. /// </summary>
  241. /// <returns></returns>
  242. public string Close(string Id)
  243. {
  244. string[] idlist = Id.Split(new char[] { ',' });
  245. AddSysLog(Id, "StoreBalance", "close");
  246. foreach (string subid in idlist)
  247. {
  248. int id = int.Parse(subid);
  249. Dictionary<string, object> Fields = new Dictionary<string, object>();
  250. Fields.Add("Status", 0);
  251. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreBalance", Fields, id);
  252. }
  253. db.SaveChanges();
  254. return "success";
  255. }
  256. #endregion
  257. #region 排序
  258. /// <summary>
  259. /// 排序
  260. /// </summary>
  261. /// <param name="Id"></param>
  262. public string Sort(int Id, int Sort)
  263. {
  264. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreBalance", Sort, Id);
  265. AddSysLog(Id.ToString(), "StoreBalance", "sort");
  266. return "success";
  267. }
  268. #endregion
  269. #region 导入数据
  270. /// <summary>
  271. /// 导入数据
  272. /// </summary>
  273. /// <param name="ExcelData"></param>
  274. public string Import(string ExcelData)
  275. {
  276. ExcelData = HttpUtility.UrlDecode(ExcelData);
  277. JsonData list = JsonMapper.ToObject(ExcelData);
  278. for (int i = 1; i < list.Count; i++)
  279. {
  280. JsonData dr = list[i];
  281. db.StoreBalance.Add(new StoreBalance()
  282. {
  283. CreateDate = DateTime.Now,
  284. UpdateDate = DateTime.Now,
  285. });
  286. db.SaveChanges();
  287. }
  288. AddSysLog("0", "StoreBalance", "Import");
  289. return "success";
  290. }
  291. #endregion
  292. #region 导出Excel
  293. /// <summary>
  294. /// 导出Excel
  295. /// </summary>
  296. /// <returns></returns>
  297. public JsonResult ExportExcel(StoreBalance data, string StoreIdStoreNo, string StoreIdStoreName, string TransTypeSelect, string CreateDateData, string BrandIdSelect)
  298. {
  299. Dictionary<string, string> Fields = new Dictionary<string, string>();
  300. // Fields.Add("CreateDate", "3"); //时间
  301. Fields.Add("TransRecordNo", "1"); //交易流水编号
  302. string condition = " and Status>-1";
  303. //仓库编号
  304. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  305. {
  306. condition += " and StoreId in (select StoreId from StoreForStoreNo where StoreNo='" + StoreIdStoreNo + "')";
  307. }
  308. //仓库名称
  309. if (!string.IsNullOrEmpty(StoreIdStoreName))
  310. {
  311. condition += " and StoreId in (select StoreId from StoreForStoreName where StoreName='" + StoreIdStoreName + "')";
  312. }
  313. //操作时间
  314. if (!string.IsNullOrEmpty(CreateDateData))
  315. {
  316. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  317. string start = datelist[0];
  318. string end = datelist[1];
  319. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  320. }
  321. //交易类型
  322. if (!string.IsNullOrEmpty(TransTypeSelect))
  323. {
  324. condition += " and TransType=" + TransTypeSelect;
  325. }
  326. //产品类型
  327. if (!string.IsNullOrEmpty(BrandIdSelect))
  328. {
  329. condition += " and BrandId=" + BrandIdSelect;
  330. }
  331. 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);
  332. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  333. foreach (Dictionary<string, object> dic in diclist)
  334. {
  335. //仓库
  336. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  337. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  338. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  339. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  340. dic.Remove("StoreId");
  341. //交易类型
  342. int TransType = int.Parse(dic["TransType"].ToString());
  343. if (TransType == 0) dic["TransType"] = "入库";
  344. if (TransType == 1) dic["TransType"] = "调拨";
  345. if (TransType == 2) dic["TransType"] = "出货";
  346. //产品类型
  347. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  348. //操作符
  349. string OpSymbol = dic["OpSymbol"].ToString();
  350. if (OpSymbol == "1") dic["OpSymbol"] = "增加";
  351. if (OpSymbol == "2") dic["OpSymbol"] = "减少";
  352. if (OpSymbol == "") dic["OpSymbol"] = "";
  353. }
  354. Dictionary<string, object> result = new Dictionary<string, object>();
  355. result.Add("Status", "1");
  356. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  357. result.Add("Obj", diclist);
  358. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  359. ReturnFields.Add("StoreIdStoreNo", "仓库编号");
  360. ReturnFields.Add("StoreIdStoreName", "仓库名称");
  361. ReturnFields.Add("TransRecordNo", "交易流水编号");
  362. ReturnFields.Add("TransType", "交易类型");
  363. ReturnFields.Add("BrandId", "产品类型");
  364. ReturnFields.Add("OpStoreNum", "操作库存数");
  365. ReturnFields.Add("OpSymbol", "操作符");
  366. ReturnFields.Add("BeforeTotalNum", "操作前总库存数");
  367. ReturnFields.Add("AfterTotalNum", "操作后总库存数");
  368. ReturnFields.Add("BeforeLaveNum", "操作前剩余库存数");
  369. ReturnFields.Add("AfterLaveNum", "操作后剩余库存数");
  370. ReturnFields.Add("BeforeOutNum", "操作前出库数");
  371. ReturnFields.Add("AfterOutNum", "操作后出库数");
  372. result.Add("Fields", ReturnFields);
  373. AddSysLog("0", "StoreBalance", "ExportExcel");
  374. return Json(result);
  375. }
  376. #endregion
  377. #region 快捷导出Excel
  378. public IActionResult QuickExportExcel(string right)
  379. {
  380. ViewBag.RightInfo = RightInfo;
  381. ViewBag.right = right;
  382. return View();
  383. }
  384. [HttpPost]
  385. public string QuickExportExcelDo(string StoreIdStoreNo, string StoreIdStoreName, string TransTypeSelect, string CreateDateData, string BrandIdSelect, string TransRecordNo)
  386. {
  387. string condition = " WhERE 1=1 and a.Status>-1";
  388. //仓库编号
  389. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  390. {
  391. condition += " and a.StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
  392. }
  393. //仓库名称
  394. if (!string.IsNullOrEmpty(StoreIdStoreName))
  395. {
  396. condition += " and a.StoreId in (select StoreId from StoreForStoreName where Name='" + StoreIdStoreName + "')";
  397. }
  398. //操作时间
  399. if (!string.IsNullOrEmpty(CreateDateData))
  400. {
  401. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  402. string start = datelist[0];
  403. string end = datelist[1];
  404. condition += " and a.CreateDate>='" + start + " 00:00:00' and a.CreateDate<='" + end + " 23:59:59'";
  405. }
  406. //交易类型
  407. if (!string.IsNullOrEmpty(TransTypeSelect))
  408. {
  409. condition += " and a.TransType=" + TransTypeSelect;
  410. }
  411. //产品类型
  412. if (!string.IsNullOrEmpty(BrandIdSelect))
  413. {
  414. condition += " and a.BrandId=" + BrandIdSelect;
  415. }
  416. var Sql = "SELECT b.StoreNo '仓库编号',b.StoreName '仓库名称',a.TransRecordNo '交易流水编号',(CASE WHEN a.TransType=0 THEN '入库' WHEN a.TransType=1 THEN '调拨' WHEN a.TransType=2 THEN '出货' ELSE '' end) '交易类型',c.`Name` '产品类型',a.OpStoreNum '操作库存数',a.OpSymbol '操作符',a.BeforeTotalNum '操作前总库存数',a.AfterTotalNum '操作后总库存数',a.BeforeLaveNum '操作前剩余库存数',a.AfterLaveNum '操作后剩余库存数',a.BeforeOutNum '操作前出库数',a.AfterOutNum '操作后出库数' FROM StoreBalance a LEFT JOIN StoreHouse b ON a.StoreId=b.Id LEFT JOIN KqProducts c ON a.BrandId=c.Id" + condition + "";
  417. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
  418. var FileName = "仓库库存变动记录" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  419. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  420. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  421. return "success";
  422. }
  423. #endregion
  424. }
  425. }