StoreChangeHistoryController.cs 20 KB

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