StoreHouseAmountRecordController.cs 15 KB

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