StoreChangeHistoryController.cs 20 KB

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