StoreChangeHistoryController.cs 20 KB

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