StoreHouseAmountRecordController.cs 15 KB

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