StoreChangeHistoryController.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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 StoreChangeHistoryController : BaseController
  23. {
  24. public StoreChangeHistoryController(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(StoreChangeHistory 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(StoreChangeHistory data, string UserIdMakerCode, string UserIdRealName, string BrandIdSelect, string TransTypeSelect, string SnTypeSelect, string StockOpDirectSelect, string StoreIdStoreNo, string StoreIdStoreName, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("CreateDate", "3"); //时间
  49. Fields.Add("SnNo", "1"); //SN编号
  50. string condition = " and Status>-1";
  51. //创客编号
  52. if (!string.IsNullOrEmpty(UserIdMakerCode))
  53. {
  54. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  55. }
  56. //创客真实姓名
  57. if (!string.IsNullOrEmpty(UserIdRealName))
  58. {
  59. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  60. }
  61. //产品类型
  62. if (!string.IsNullOrEmpty(BrandIdSelect))
  63. {
  64. condition += " and BrandId=" + BrandIdSelect;
  65. }
  66. //交易类型
  67. if (!string.IsNullOrEmpty(TransTypeSelect))
  68. {
  69. condition += " and TransType=" + TransTypeSelect;
  70. }
  71. //SN机具类型
  72. if (!string.IsNullOrEmpty(SnTypeSelect))
  73. {
  74. condition += " and SnType=" + SnTypeSelect;
  75. }
  76. //库存操作方向
  77. if (!string.IsNullOrEmpty(StockOpDirectSelect))
  78. {
  79. condition += " and StockOpDirect=" + StockOpDirectSelect;
  80. }
  81. //仓库编号
  82. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  83. {
  84. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
  85. }
  86. //仓库名称
  87. if (!string.IsNullOrEmpty(StoreIdStoreName))
  88. {
  89. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdStoreName + "')";
  90. }
  91. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreChangeHistory", Fields, "Id desc", "0", page, limit, condition);
  92. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  93. foreach (Dictionary<string, object> dic in diclist)
  94. {
  95. //创客
  96. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  97. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  98. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  99. dic["UserIdRealName"] = userid_Users.RealName;
  100. dic.Remove("UserId");
  101. //产品类型
  102. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  103. //交易类型
  104. int TransType = int.Parse(dic["TransType"].ToString());
  105. if (TransType == 1) dic["TransType"] = "调拨";
  106. if (TransType == 2) dic["TransType"] = "出货";
  107. if (TransType == 3) dic["TransType"] = "退货";
  108. if (TransType == 0) dic["TransType"] = "采购";
  109. //SN机具类型
  110. int SnType = int.Parse(dic["SnType"].ToString());
  111. if (SnType == 0) dic["SnType"] = "购买机具";
  112. if (SnType == 1) dic["SnType"] = "赠送机具";
  113. //库存操作方向
  114. int StockOpDirect = int.Parse(dic["StockOpDirect"].ToString());
  115. if (StockOpDirect == 0) dic["StockOpDirect"] = "入库";
  116. if (StockOpDirect == 1) dic["StockOpDirect"] = "出库";
  117. //收货创客
  118. int ToUserId = int.Parse(function.CheckInt(dic["ToUserId"].ToString()));
  119. StoreHouse touserid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == ToUserId) ?? new StoreHouse();
  120. dic["ToUserIdStoreNo"] = touserid_StoreHouse.StoreNo;
  121. dic["ToUserIdStoreName"] = touserid_StoreHouse.StoreName;
  122. dic.Remove("ToUserId");
  123. //创客退货收货仓库
  124. int ToStoreId = int.Parse(function.CheckInt(dic["ToStoreId"].ToString()));
  125. StoreHouse tostoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == ToStoreId) ?? new StoreHouse();
  126. dic["ToStoreIdStoreNo"] = tostoreid_StoreHouse.StoreNo;
  127. dic["ToStoreIdStoreName"] = tostoreid_StoreHouse.StoreName;
  128. dic.Remove("ToStoreId");
  129. //源仓库
  130. int SourceStoreId = int.Parse(function.CheckInt(dic["SourceStoreId"].ToString()));
  131. StoreHouse sourcestoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == SourceStoreId) ?? new StoreHouse();
  132. dic["SourceStoreIdStoreNo"] = sourcestoreid_StoreHouse.StoreNo;
  133. dic["SourceStoreIdStoreName"] = sourcestoreid_StoreHouse.StoreName;
  134. dic.Remove("SourceStoreId");
  135. //仓库
  136. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  137. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  138. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  139. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  140. dic.Remove("StoreId");
  141. }
  142. return Json(obj);
  143. }
  144. #endregion
  145. #region 增加机具变动历史
  146. /// <summary>
  147. /// 增加或修改机具变动历史信息
  148. /// </summary>
  149. /// <returns></returns>
  150. public IActionResult Add(string right)
  151. {
  152. ViewBag.RightInfo = RightInfo;
  153. ViewBag.right = right;
  154. return View();
  155. }
  156. #endregion
  157. #region 增加机具变动历史
  158. /// <summary>
  159. /// 增加或修改机具变动历史信息
  160. /// </summary>
  161. /// <returns></returns>
  162. [HttpPost]
  163. public string Add(StoreChangeHistory data)
  164. {
  165. Dictionary<string, object> Fields = new Dictionary<string, object>();
  166. Fields.Add("SeoTitle", data.SeoTitle);
  167. Fields.Add("SeoKeyword", data.SeoKeyword);
  168. Fields.Add("SeoDescription", data.SeoDescription);
  169. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreChangeHistory", Fields, 0);
  170. AddSysLog(data.Id.ToString(), "StoreChangeHistory", "add");
  171. db.SaveChanges();
  172. return "success";
  173. }
  174. #endregion
  175. #region 修改机具变动历史
  176. /// <summary>
  177. /// 增加或修改机具变动历史信息
  178. /// </summary>
  179. /// <returns></returns>
  180. public IActionResult Edit(string right, int Id = 0)
  181. {
  182. ViewBag.RightInfo = RightInfo;
  183. ViewBag.right = right;
  184. StoreChangeHistory editData = db.StoreChangeHistory.FirstOrDefault(m => m.Id == Id) ?? new StoreChangeHistory();
  185. ViewBag.data = editData;
  186. return View();
  187. }
  188. #endregion
  189. #region 修改机具变动历史
  190. /// <summary>
  191. /// 增加或修改机具变动历史信息
  192. /// </summary>
  193. /// <returns></returns>
  194. [HttpPost]
  195. public string Edit(StoreChangeHistory data)
  196. {
  197. Dictionary<string, object> Fields = new Dictionary<string, object>();
  198. Fields.Add("SeoTitle", data.SeoTitle);
  199. Fields.Add("SeoKeyword", data.SeoKeyword);
  200. Fields.Add("SeoDescription", data.SeoDescription);
  201. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreChangeHistory", Fields, data.Id);
  202. AddSysLog(data.Id.ToString(), "StoreChangeHistory", "update");
  203. db.SaveChanges();
  204. return "success";
  205. }
  206. #endregion
  207. #region 删除机具变动历史信息
  208. /// <summary>
  209. /// 删除机具变动历史信息
  210. /// </summary>
  211. /// <returns></returns>
  212. public string Delete(string Id)
  213. {
  214. string[] idlist = Id.Split(new char[] { ',' });
  215. AddSysLog(Id, "StoreChangeHistory", "del");
  216. foreach (string subid in idlist)
  217. {
  218. int id = int.Parse(subid);
  219. Dictionary<string, object> Fields = new Dictionary<string, object>();
  220. Fields.Add("Status", -1);
  221. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreChangeHistory", Fields, id);
  222. }
  223. db.SaveChanges();
  224. return "success";
  225. }
  226. #endregion
  227. #region 开启
  228. /// <summary>
  229. /// 开启
  230. /// </summary>
  231. /// <returns></returns>
  232. public string Open(string Id)
  233. {
  234. string[] idlist = Id.Split(new char[] { ',' });
  235. AddSysLog(Id, "StoreChangeHistory", "open");
  236. foreach (string subid in idlist)
  237. {
  238. int id = int.Parse(subid);
  239. Dictionary<string, object> Fields = new Dictionary<string, object>();
  240. Fields.Add("Status", 1);
  241. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreChangeHistory", Fields, id);
  242. }
  243. db.SaveChanges();
  244. return "success";
  245. }
  246. #endregion
  247. #region 关闭
  248. /// <summary>
  249. /// 关闭
  250. /// </summary>
  251. /// <returns></returns>
  252. public string Close(string Id)
  253. {
  254. string[] idlist = Id.Split(new char[] { ',' });
  255. AddSysLog(Id, "StoreChangeHistory", "close");
  256. foreach (string subid in idlist)
  257. {
  258. int id = int.Parse(subid);
  259. Dictionary<string, object> Fields = new Dictionary<string, object>();
  260. Fields.Add("Status", 0);
  261. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreChangeHistory", Fields, id);
  262. }
  263. db.SaveChanges();
  264. return "success";
  265. }
  266. #endregion
  267. #region 排序
  268. /// <summary>
  269. /// 排序
  270. /// </summary>
  271. /// <param name="Id"></param>
  272. public string Sort(int Id, int Sort)
  273. {
  274. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreChangeHistory", Sort, Id);
  275. AddSysLog(Id.ToString(), "StoreChangeHistory", "sort");
  276. return "success";
  277. }
  278. #endregion
  279. #region 导入数据
  280. /// <summary>
  281. /// 导入数据
  282. /// </summary>
  283. /// <param name="ExcelData"></param>
  284. public string Import(string ExcelData)
  285. {
  286. ExcelData = HttpUtility.UrlDecode(ExcelData);
  287. JsonData list = JsonMapper.ToObject(ExcelData);
  288. for (int i = 1; i < list.Count; i++)
  289. {
  290. JsonData dr = list[i];
  291. db.StoreChangeHistory.Add(new StoreChangeHistory()
  292. {
  293. CreateDate = DateTime.Now,
  294. UpdateDate = DateTime.Now,
  295. });
  296. db.SaveChanges();
  297. }
  298. AddSysLog("0", "StoreChangeHistory", "Import");
  299. return "success";
  300. }
  301. #endregion
  302. #region 导出Excel
  303. /// <summary>
  304. /// 导出Excel
  305. /// </summary>
  306. /// <returns></returns>
  307. public JsonResult ExportExcel(StoreChangeHistory data, string UserIdMakerCode, string UserIdRealName, string BrandIdSelect, string TransTypeSelect, string SnTypeSelect, string StockOpDirectSelect, string StoreIdStoreNo, string StoreIdStoreName)
  308. {
  309. Dictionary<string, string> Fields = new Dictionary<string, string>();
  310. Fields.Add("CreateDate", "3"); //时间
  311. Fields.Add("SnNo", "1"); //SN编号
  312. string condition = " and Status>-1";
  313. //创客编号
  314. if (!string.IsNullOrEmpty(UserIdMakerCode))
  315. {
  316. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  317. }
  318. //创客真实姓名
  319. if (!string.IsNullOrEmpty(UserIdRealName))
  320. {
  321. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  322. }
  323. //产品类型
  324. if (!string.IsNullOrEmpty(BrandIdSelect))
  325. {
  326. condition += " and BrandId=" + BrandIdSelect;
  327. }
  328. //交易类型
  329. if (!string.IsNullOrEmpty(TransTypeSelect))
  330. {
  331. condition += " and TransType=" + TransTypeSelect;
  332. }
  333. //SN机具类型
  334. if (!string.IsNullOrEmpty(SnTypeSelect))
  335. {
  336. condition += " and SnType=" + SnTypeSelect;
  337. }
  338. //库存操作方向
  339. if (!string.IsNullOrEmpty(StockOpDirectSelect))
  340. {
  341. condition += " and StockOpDirect=" + StockOpDirectSelect;
  342. }
  343. //仓库编号
  344. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  345. {
  346. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
  347. }
  348. //仓库名称
  349. if (!string.IsNullOrEmpty(StoreIdStoreName))
  350. {
  351. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdStoreName + "')";
  352. }
  353. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreChangeHistory", Fields, "Id desc", "0", 1, 20000, condition, "", false);
  354. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  355. foreach (Dictionary<string, object> dic in diclist)
  356. {
  357. //创客
  358. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  359. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  360. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  361. dic["UserIdRealName"] = userid_Users.RealName;
  362. dic.Remove("UserId");
  363. //产品类型
  364. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  365. //交易类型
  366. int TransType = int.Parse(dic["TransType"].ToString());
  367. if (TransType == 1) dic["TransType"] = "调拨";
  368. if (TransType == 2) dic["TransType"] = "出货";
  369. if (TransType == 3) dic["TransType"] = "退货";
  370. if (TransType == 0) dic["TransType"] = "采购";
  371. //SN机具类型
  372. int SnType = int.Parse(dic["SnType"].ToString());
  373. if (SnType == 0) dic["SnType"] = "购买机具";
  374. if (SnType == 1) dic["SnType"] = "赠送机具";
  375. //库存操作方向
  376. int StockOpDirect = int.Parse(dic["StockOpDirect"].ToString());
  377. if (StockOpDirect == 0) dic["StockOpDirect"] = "入库";
  378. if (StockOpDirect == 1) dic["StockOpDirect"] = "出库";
  379. //收货创客
  380. int ToUserId = int.Parse(function.CheckInt(dic["ToUserId"].ToString()));
  381. StoreHouse touserid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == ToUserId) ?? new StoreHouse();
  382. dic["ToUserIdStoreNo"] = touserid_StoreHouse.StoreNo;
  383. dic["ToUserIdStoreName"] = touserid_StoreHouse.StoreName;
  384. dic.Remove("ToUserId");
  385. //创客退货收货仓库
  386. int ToStoreId = int.Parse(function.CheckInt(dic["ToStoreId"].ToString()));
  387. StoreHouse tostoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == ToStoreId) ?? new StoreHouse();
  388. dic["ToStoreIdStoreNo"] = tostoreid_StoreHouse.StoreNo;
  389. dic["ToStoreIdStoreName"] = tostoreid_StoreHouse.StoreName;
  390. dic.Remove("ToStoreId");
  391. //源仓库
  392. int SourceStoreId = int.Parse(function.CheckInt(dic["SourceStoreId"].ToString()));
  393. StoreHouse sourcestoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == SourceStoreId) ?? new StoreHouse();
  394. dic["SourceStoreIdStoreNo"] = sourcestoreid_StoreHouse.StoreNo;
  395. dic["SourceStoreIdStoreName"] = sourcestoreid_StoreHouse.StoreName;
  396. dic.Remove("SourceStoreId");
  397. //仓库
  398. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  399. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  400. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  401. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  402. dic.Remove("StoreId");
  403. }
  404. Dictionary<string, object> result = new Dictionary<string, object>();
  405. result.Add("Status", "1");
  406. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  407. result.Add("Obj", diclist);
  408. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  409. result.Add("Fields", ReturnFields);
  410. AddSysLog("0", "StoreChangeHistory", "ExportExcel");
  411. return Json(result);
  412. }
  413. #endregion
  414. }
  415. }