StoreBalanceController.cs 16 KB

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