StoreChangeHistoryController.cs 20 KB

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