StoreHouseAmountRecordController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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 StoreHouseAmountRecordController : BaseController
  23. {
  24. public StoreHouseAmountRecordController(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(StoreHouseAmountRecord 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(StoreHouseAmountRecord data, string UserIdRealName, string UserIdMakerCode, string AmountTypeSelect, string OperateTypeSelect, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("CreateDate", "3"); //时间
  49. string condition = " and Status>-1";
  50. //创客真实姓名
  51. if (!string.IsNullOrEmpty(UserIdRealName))
  52. {
  53. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  54. }
  55. //创客创客编号
  56. if (!string.IsNullOrEmpty(UserIdMakerCode))
  57. {
  58. condition += " and UserId in (select UserId from UsersForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  59. }
  60. //额度类别
  61. if (!string.IsNullOrEmpty(AmountTypeSelect))
  62. {
  63. condition += " and AmountType=" + AmountTypeSelect;
  64. }
  65. //操作类别
  66. if (!string.IsNullOrEmpty(OperateTypeSelect))
  67. {
  68. condition += " and OperateType=" + OperateTypeSelect;
  69. }
  70. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreHouseAmountRecord", Fields, "Id desc", "0", page, limit, condition);
  71. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  72. foreach (Dictionary<string, object> dic in diclist)
  73. {
  74. //创客
  75. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  76. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  77. dic["UserIdRealName"] = userid_Users.RealName;
  78. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  79. dic.Remove("UserId");
  80. //申请单
  81. dic["ApplyId"] = RelationClass.GetStoreMachineApplyInfo(int.Parse(dic["ApplyId"].ToString()));
  82. //额度类别
  83. int AmountType = int.Parse(dic["AmountType"].ToString());
  84. if (AmountType == 0) dic["AmountType"] = "固定额度";
  85. if (AmountType == 1) dic["AmountType"] = "临时额度";
  86. //操作类别
  87. int OperateType = int.Parse(dic["OperateType"].ToString());
  88. if (OperateType == 1) dic["OperateType"] = "增加";
  89. if (OperateType == 2) dic["OperateType"] = "减少";
  90. if (OperateType == 0) dic["OperateType"] = "";
  91. }
  92. return Json(obj);
  93. }
  94. #endregion
  95. #region 增加分仓机具额度记录
  96. /// <summary>
  97. /// 增加或修改分仓机具额度记录信息
  98. /// </summary>
  99. /// <returns></returns>
  100. public IActionResult Add(string right)
  101. {
  102. ViewBag.RightInfo = RightInfo;
  103. ViewBag.right = right;
  104. return View();
  105. }
  106. #endregion
  107. #region 增加分仓机具额度记录
  108. /// <summary>
  109. /// 增加或修改分仓机具额度记录信息
  110. /// </summary>
  111. /// <returns></returns>
  112. [HttpPost]
  113. public string Add(StoreHouseAmountRecord data)
  114. {
  115. Dictionary<string, object> Fields = new Dictionary<string, object>();
  116. Fields.Add("OperateType", data.OperateType); //操作类别
  117. Fields.Add("SeoTitle", data.SeoTitle);
  118. Fields.Add("SeoKeyword", data.SeoKeyword);
  119. Fields.Add("SeoDescription", data.SeoDescription);
  120. int Id = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreHouseAmountRecord", Fields, 0);
  121. AddSysLog(data.Id.ToString(), "StoreHouseAmountRecord", "add");
  122. db.SaveChanges();
  123. return "success";
  124. }
  125. #endregion
  126. #region 修改分仓机具额度记录
  127. /// <summary>
  128. /// 增加或修改分仓机具额度记录信息
  129. /// </summary>
  130. /// <returns></returns>
  131. public IActionResult Edit(string right, int Id = 0)
  132. {
  133. ViewBag.RightInfo = RightInfo;
  134. ViewBag.right = right;
  135. StoreHouseAmountRecord editData = db.StoreHouseAmountRecord.FirstOrDefault(m => m.Id == Id) ?? new StoreHouseAmountRecord();
  136. ViewBag.data = editData;
  137. return View();
  138. }
  139. #endregion
  140. #region 修改分仓机具额度记录
  141. /// <summary>
  142. /// 增加或修改分仓机具额度记录信息
  143. /// </summary>
  144. /// <returns></returns>
  145. [HttpPost]
  146. public string Edit(StoreHouseAmountRecord data)
  147. {
  148. Dictionary<string, object> Fields = new Dictionary<string, object>();
  149. Fields.Add("OperateType", data.OperateType); //操作类别
  150. Fields.Add("SeoTitle", data.SeoTitle);
  151. Fields.Add("SeoKeyword", data.SeoKeyword);
  152. Fields.Add("SeoDescription", data.SeoDescription);
  153. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouseAmountRecord", Fields, data.Id);
  154. AddSysLog(data.Id.ToString(), "StoreHouseAmountRecord", "update");
  155. db.SaveChanges();
  156. return "success";
  157. }
  158. #endregion
  159. #region 删除分仓机具额度记录信息
  160. /// <summary>
  161. /// 删除分仓机具额度记录信息
  162. /// </summary>
  163. /// <returns></returns>
  164. public string Delete(string Id)
  165. {
  166. string[] idlist = Id.Split(new char[] { ',' });
  167. AddSysLog(Id, "StoreHouseAmountRecord", "del");
  168. foreach (string subid in idlist)
  169. {
  170. int id = int.Parse(subid);
  171. Dictionary<string, object> Fields = new Dictionary<string, object>();
  172. Fields.Add("Status", -1);
  173. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouseAmountRecord", Fields, id);
  174. }
  175. db.SaveChanges();
  176. return "success";
  177. }
  178. #endregion
  179. #region 开启
  180. /// <summary>
  181. /// 开启
  182. /// </summary>
  183. /// <returns></returns>
  184. public string Open(string Id)
  185. {
  186. string[] idlist = Id.Split(new char[] { ',' });
  187. AddSysLog(Id, "StoreHouseAmountRecord", "open");
  188. foreach (string subid in idlist)
  189. {
  190. int id = int.Parse(subid);
  191. Dictionary<string, object> Fields = new Dictionary<string, object>();
  192. Fields.Add("Status", 1);
  193. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouseAmountRecord", Fields, id);
  194. }
  195. db.SaveChanges();
  196. return "success";
  197. }
  198. #endregion
  199. #region 关闭
  200. /// <summary>
  201. /// 关闭
  202. /// </summary>
  203. /// <returns></returns>
  204. public string Close(string Id)
  205. {
  206. string[] idlist = Id.Split(new char[] { ',' });
  207. AddSysLog(Id, "StoreHouseAmountRecord", "close");
  208. foreach (string subid in idlist)
  209. {
  210. int id = int.Parse(subid);
  211. Dictionary<string, object> Fields = new Dictionary<string, object>();
  212. Fields.Add("Status", 0);
  213. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouseAmountRecord", Fields, id);
  214. }
  215. db.SaveChanges();
  216. return "success";
  217. }
  218. #endregion
  219. #region 排序
  220. /// <summary>
  221. /// 排序
  222. /// </summary>
  223. /// <param name="Id"></param>
  224. public string Sort(int Id, int Sort)
  225. {
  226. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreHouseAmountRecord", Sort, Id);
  227. AddSysLog(Id.ToString(), "StoreHouseAmountRecord", "sort");
  228. return "success";
  229. }
  230. #endregion
  231. #region 导入数据
  232. /// <summary>
  233. /// 导入数据
  234. /// </summary>
  235. /// <param name="ExcelData"></param>
  236. public string Import(string ExcelData)
  237. {
  238. ExcelData = HttpUtility.UrlDecode(ExcelData);
  239. JsonData list = JsonMapper.ToObject(ExcelData);
  240. for (int i = 1; i < list.Count; i++)
  241. {
  242. JsonData dr = list[i];
  243. db.StoreHouseAmountRecord.Add(new StoreHouseAmountRecord()
  244. {
  245. CreateDate = DateTime.Now,
  246. UpdateDate = DateTime.Now,
  247. });
  248. db.SaveChanges();
  249. }
  250. AddSysLog("0", "StoreHouseAmountRecord", "Import");
  251. return "success";
  252. }
  253. #endregion
  254. #region 导出Excel
  255. /// <summary>
  256. /// 导出Excel
  257. /// </summary>
  258. /// <returns></returns>
  259. public JsonResult ExportExcel(StoreHouseAmountRecord data, string UserIdRealName, string UserIdMakerCode, string AmountTypeSelect, string OperateTypeSelect)
  260. {
  261. Dictionary<string, string> Fields = new Dictionary<string, string>();
  262. Fields.Add("CreateDate", "3"); //时间
  263. string condition = " and Status>-1";
  264. //创客真实姓名
  265. if (!string.IsNullOrEmpty(UserIdRealName))
  266. {
  267. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  268. }
  269. //创客创客编号
  270. if (!string.IsNullOrEmpty(UserIdMakerCode))
  271. {
  272. condition += " and UserId in (select UserId from UsersForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  273. }
  274. //额度类别
  275. if (!string.IsNullOrEmpty(AmountTypeSelect))
  276. {
  277. condition += " and AmountType=" + AmountTypeSelect;
  278. }
  279. //操作类别
  280. if (!string.IsNullOrEmpty(OperateTypeSelect))
  281. {
  282. condition += " and OperateType=" + OperateTypeSelect;
  283. }
  284. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreHouseAmountRecord", Fields, "Id desc", "0", 1, 20000, condition, "UserId,ApplyId,UseAmount,BeforeAmount,AfterAmount,AmountType,OperateType", false);
  285. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  286. foreach (Dictionary<string, object> dic in diclist)
  287. {
  288. //创客
  289. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  290. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  291. dic["UserIdRealName"] = userid_Users.RealName;
  292. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  293. dic.Remove("UserId");
  294. //申请单
  295. dic["ApplyId"] = RelationClass.GetStoreMachineApplyInfo(int.Parse(dic["ApplyId"].ToString()));
  296. //额度类别
  297. int AmountType = int.Parse(dic["AmountType"].ToString());
  298. if (AmountType == 0) dic["AmountType"] = "固定额度";
  299. if (AmountType == 1) dic["AmountType"] = "临时额度";
  300. //操作类别
  301. int OperateType = int.Parse(dic["OperateType"].ToString());
  302. if (OperateType == 1) dic["OperateType"] = "增加";
  303. if (OperateType == 2) dic["OperateType"] = "减少";
  304. if (OperateType == 0) dic["OperateType"] = "";
  305. }
  306. Dictionary<string, object> result = new Dictionary<string, object>();
  307. result.Add("Status", "1");
  308. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  309. result.Add("Obj", diclist);
  310. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  311. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  312. ReturnFields.Add("UserIdMakerCode", "创客创客编号");
  313. ReturnFields.Add("ApplyId", "申请单");
  314. ReturnFields.Add("UseAmount", "使用额度");
  315. ReturnFields.Add("BeforeAmount", "使用前剩余额度");
  316. ReturnFields.Add("AfterAmount", "使用后剩余额度");
  317. ReturnFields.Add("AmountType", "额度类别");
  318. ReturnFields.Add("OperateType", "操作类别");
  319. result.Add("Fields", ReturnFields);
  320. AddSysLog("0", "StoreHouseAmountRecord", "ExportExcel");
  321. return Json(result);
  322. }
  323. #endregion
  324. }
  325. }