MachineRenewController.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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 MachineRenewController : BaseController
  23. {
  24. public MachineRenewController(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(MachineRenew 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(MachineRenew data, string MakerCode, string RealName, string DamagedSnTypeSelect, string AuditStatusSelect, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("CreateDate", "3"); //机具售后换新申请时间
  49. Fields.Add("DamagedBrandId", "0"); //损坏的机具产品类型
  50. Fields.Add("DamagedSnNo", "1"); //创客损坏的机具SN
  51. Fields.Add("AuditDate", "3"); //审核时间
  52. string condition = " and Status>-1";
  53. //创客编号
  54. if (!string.IsNullOrEmpty(MakerCode))
  55. {
  56. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  57. }
  58. //创客名称
  59. if (!string.IsNullOrEmpty(RealName))
  60. {
  61. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  62. }
  63. //损坏机具SN类型
  64. if(!string.IsNullOrEmpty(DamagedSnTypeSelect))
  65. {
  66. condition += " and DamagedSnType=" + DamagedSnTypeSelect;
  67. }
  68. //审核状态
  69. if(!string.IsNullOrEmpty(AuditStatusSelect))
  70. {
  71. condition += " and AuditStatus=" + AuditStatusSelect;
  72. }
  73. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("MachineRenew", Fields, "Id desc", "0", page, limit, condition);
  74. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  75. foreach (Dictionary<string, object> dic in diclist)
  76. {
  77. dic["DamagedBrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["DamagedBrandId"].ToString()));
  78. dic["ReplaceBrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["ReplaceBrandId"].ToString()));
  79. dic["DeliverBrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["DeliverBrandId"].ToString()));
  80. int UserId = int.Parse(dic["UserId"].ToString());
  81. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  82. dic["MakerCode"] = user.MakerCode;
  83. dic["RealName"] = user.RealName;
  84. int DamagedSnType = int.Parse(dic["DamagedSnType"].ToString());
  85. if(DamagedSnType == 0) dic["DamagedSnType"] = "购买机具";
  86. if(DamagedSnType == 1) dic["DamagedSnType"] = "赠送机具";
  87. int ReplaceSnType = int.Parse(dic["ReplaceSnType"].ToString());
  88. if(ReplaceSnType == 0) dic["ReplaceSnType"] = "购买机具";
  89. if(ReplaceSnType == 1) dic["ReplaceSnType"] = "赠送机具";
  90. int AuditStatus = int.Parse(dic["AuditStatus"].ToString());
  91. if(AuditStatus == 0) dic["AuditStatus"] = "未审核";
  92. if(AuditStatus == 1) dic["AuditStatus"] = "同步循环通过";
  93. if(AuditStatus == 2) dic["AuditStatus"] = "审核失败";
  94. }
  95. return Json(obj);
  96. }
  97. #endregion
  98. #region 增加机具损坏换新申请
  99. /// <summary>
  100. /// 增加或修改机具损坏换新申请信息
  101. /// </summary>
  102. /// <returns></returns>
  103. public IActionResult Add(string right)
  104. {
  105. ViewBag.RightInfo = RightInfo;
  106. ViewBag.right = right;
  107. return View();
  108. }
  109. #endregion
  110. #region 增加机具损坏换新申请
  111. /// <summary>
  112. /// 增加或修改机具损坏换新申请信息
  113. /// </summary>
  114. /// <returns></returns>
  115. [HttpPost]
  116. public string Add(MachineRenew data, string MakerCode)
  117. {
  118. Dictionary<string, object> Fields = new Dictionary<string, object>();
  119. UserForMakerCode user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  120. if (user == null)
  121. {
  122. return "创客编号不存在";
  123. }
  124. Fields.Add("ApplyNo", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  125. Fields.Add("UserId", data.UserId); //创客
  126. Fields.Add("DamagedBrandId", data.DamagedBrandId); //损坏的机具产品类型
  127. Fields.Add("DamagedSnNo", data.DamagedSnNo); //创客损坏的机具SN
  128. Fields.Add("DamagedSnType", data.DamagedSnType); //损坏的机具SN机具类型
  129. Fields.Add("ReplaceBrandId", data.ReplaceBrandId); //替换的机具产品类型
  130. Fields.Add("ReplaceSnNo", data.ReplaceSnNo); //创客机具替换SN
  131. Fields.Add("ReplaceSnType", data.ReplaceSnType); //替换的机具SN机具类型
  132. Fields.Add("DeliverBrandId", data.DeliverBrandId); //仓库换新发货的机具产品类型
  133. Fields.Add("DeliverSnNo", data.DeliverSnNo); //仓库换新发货SN
  134. Fields.Add("DemandDesc", data.DemandDesc); //售后换新机具处理需求描述
  135. Fields.Add("UpdateMan", SysUserName); //操作人
  136. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("MachineRenew", Fields, 0);
  137. AddSysLog(data.Id.ToString(), "MachineRenew", "add");
  138. db.SaveChanges();
  139. return "success";
  140. }
  141. #endregion
  142. #region 修改机具损坏换新申请
  143. /// <summary>
  144. /// 增加或修改机具损坏换新申请信息
  145. /// </summary>
  146. /// <returns></returns>
  147. public IActionResult Edit(string right, int Id = 0)
  148. {
  149. ViewBag.RightInfo = RightInfo;
  150. ViewBag.right = right;
  151. MachineRenew editData = db.MachineRenew.FirstOrDefault(m => m.Id == Id) ?? new MachineRenew();
  152. ViewBag.data = editData;
  153. return View();
  154. }
  155. #endregion
  156. #region 修改机具损坏换新申请
  157. /// <summary>
  158. /// 增加或修改机具损坏换新申请信息
  159. /// </summary>
  160. /// <returns></returns>
  161. [HttpPost]
  162. public string Edit(MachineRenew data)
  163. {
  164. Dictionary<string, object> Fields = new Dictionary<string, object>();
  165. Fields.Add("SeoTitle", data.SeoTitle);
  166. Fields.Add("SeoKeyword", data.SeoKeyword);
  167. Fields.Add("SeoDescription", data.SeoDescription);
  168. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineRenew", Fields, data.Id);
  169. AddSysLog(data.Id.ToString(), "MachineRenew", "update");
  170. db.SaveChanges();
  171. return "success";
  172. }
  173. #endregion
  174. #region 删除机具损坏换新申请信息
  175. /// <summary>
  176. /// 删除机具损坏换新申请信息
  177. /// </summary>
  178. /// <returns></returns>
  179. public string Delete(string Id)
  180. {
  181. string[] idlist = Id.Split(new char[] { ',' });
  182. AddSysLog(Id, "MachineRenew", "del");
  183. foreach (string subid in idlist)
  184. {
  185. int id = int.Parse(subid);
  186. Dictionary<string, object> Fields = new Dictionary<string, object>();
  187. Fields.Add("Status", -1);
  188. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineRenew", Fields, id);
  189. }
  190. db.SaveChanges();
  191. return "success";
  192. }
  193. #endregion
  194. #region 开启
  195. /// <summary>
  196. /// 开启
  197. /// </summary>
  198. /// <returns></returns>
  199. public string Open(string Id)
  200. {
  201. string[] idlist = Id.Split(new char[] { ',' });
  202. AddSysLog(Id, "MachineRenew", "open");
  203. foreach (string subid in idlist)
  204. {
  205. int id = int.Parse(subid);
  206. Dictionary<string, object> Fields = new Dictionary<string, object>();
  207. Fields.Add("Status", 1);
  208. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineRenew", Fields, id);
  209. }
  210. db.SaveChanges();
  211. return "success";
  212. }
  213. #endregion
  214. #region 关闭
  215. /// <summary>
  216. /// 关闭
  217. /// </summary>
  218. /// <returns></returns>
  219. public string Close(string Id)
  220. {
  221. string[] idlist = Id.Split(new char[] { ',' });
  222. AddSysLog(Id, "MachineRenew", "close");
  223. foreach (string subid in idlist)
  224. {
  225. int id = int.Parse(subid);
  226. Dictionary<string, object> Fields = new Dictionary<string, object>();
  227. Fields.Add("Status", 0);
  228. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineRenew", Fields, id);
  229. }
  230. db.SaveChanges();
  231. return "success";
  232. }
  233. #endregion
  234. #region 排序
  235. /// <summary>
  236. /// 排序
  237. /// </summary>
  238. /// <param name="Id"></param>
  239. public string Sort(int Id, int Sort)
  240. {
  241. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("MachineRenew", Sort, Id);
  242. AddSysLog(Id.ToString(), "MachineRenew", "sort");
  243. return "success";
  244. }
  245. #endregion
  246. #region 导入数据
  247. /// <summary>
  248. /// 导入数据
  249. /// </summary>
  250. /// <param name="ExcelData"></param>
  251. public string Import(string ExcelData)
  252. {
  253. ExcelData = HttpUtility.UrlDecode(ExcelData);
  254. JsonData list = JsonMapper.ToObject(ExcelData);
  255. for (int i = 1; i < list.Count; i++)
  256. {
  257. JsonData dr = list[i];
  258. string MakerCode = dr[0].ToString(); //创客编号
  259. int DamagedBrandId = int.Parse(dr[1].ToString()); //损坏的机具产品类型
  260. string DamagedSnNo = dr[2].ToString(); //创客损坏的机具SN
  261. int DamagedSnType = int.Parse(dr[3].ToString()); //损坏的机具SN机具类型
  262. int ReplaceBrandId = int.Parse(dr[4].ToString()); //替换的机具产品类型
  263. string ReplaceSnNo = dr[5].ToString(); //创客机具替换SN
  264. int ReplaceSnType = int.Parse(dr[6].ToString()); //替换的机具SN机具类型
  265. int DeliverBrandId = int.Parse(dr[7].ToString()); //仓库换新发货的机具产品类型
  266. string DeliverSnNo = dr[8].ToString(); //仓库换新发货SN
  267. string DemandDesc = dr[9].ToString(); //售后换新机具处理需求描述
  268. string UpdateMan = dr[10].ToString(); //操作人
  269. UserForMakerCode user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  270. if (user == null)
  271. {
  272. return "创客编号" + MakerCode + "不存在";
  273. }
  274. db.MachineRenew.Add(new MachineRenew()
  275. {
  276. CreateDate = DateTime.Now,
  277. UpdateDate = DateTime.Now,
  278. ApplyNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), //机具售后换新申请订单号
  279. ApplyDate = DateTime.Now.ToString("yyyyMMdd"), //机具售后换新申请时间
  280. UserId = user.UserId, //创客
  281. DamagedBrandId = DamagedBrandId, //损坏的机具产品类型
  282. DamagedSnNo = DamagedSnNo, //创客损坏的机具SN
  283. DamagedSnType = DamagedSnType, //损坏的机具SN机具类型
  284. ReplaceBrandId = ReplaceBrandId, //替换的机具产品类型
  285. ReplaceSnNo = ReplaceSnNo, //创客机具替换SN
  286. ReplaceSnType = ReplaceSnType, //替换的机具SN机具类型
  287. DeliverBrandId = DeliverBrandId, //仓库换新发货的机具产品类型
  288. DeliverSnNo = DeliverSnNo, //仓库换新发货SN
  289. DemandDesc = DemandDesc, //售后换新机具处理需求描述
  290. });
  291. db.SaveChanges();
  292. }
  293. AddSysLog("0", "MachineRenew", "Import");
  294. return "success";
  295. }
  296. #endregion
  297. #region 导出Excel
  298. /// <summary>
  299. /// 导出Excel
  300. /// </summary>
  301. /// <returns></returns>
  302. public JsonResult ExportExcel(MachineRenew data, string MakerCode, string RealName, string DamagedSnTypeSelect, string AuditStatusSelect)
  303. {
  304. Dictionary<string, string> Fields = new Dictionary<string, string>();
  305. Fields.Add("CreateDate", "3"); //机具售后换新申请时间
  306. Fields.Add("DamagedBrandId", "0"); //损坏的机具产品类型
  307. Fields.Add("DamagedSnNo", "1"); //创客损坏的机具SN
  308. Fields.Add("AuditDate", "3"); //审核时间
  309. string condition = " and Status>-1";
  310. //创客编号
  311. if (!string.IsNullOrEmpty(MakerCode))
  312. {
  313. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  314. }
  315. //创客名称
  316. if (!string.IsNullOrEmpty(RealName))
  317. {
  318. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  319. }
  320. //损坏机具SN类型
  321. if(!string.IsNullOrEmpty(DamagedSnTypeSelect))
  322. {
  323. condition += " and DamagedSnType=" + DamagedSnTypeSelect;
  324. }
  325. //审核状态
  326. if(!string.IsNullOrEmpty(AuditStatusSelect))
  327. {
  328. condition += " and AuditStatus=" + AuditStatusSelect;
  329. }
  330. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("MachineRenew", Fields, "Id desc", "0", 1, 20000, condition, "ApplyNo,ApplyDate,UserId,DamagedBrandId,DamagedSnNo,DamagedSnType,ReplaceBrandId,ReplaceSnNo,ReplaceSnType,DeliverBrandId,DeliverSnNo,DemandDesc,AuditStatus,AuditDesc,AuditDate,UpdateMan", false);
  331. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  332. foreach (Dictionary<string, object> dic in diclist)
  333. {
  334. dic["DamagedBrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["DamagedBrandId"].ToString()));
  335. dic["ReplaceBrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["ReplaceBrandId"].ToString()));
  336. dic["DeliverBrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["DeliverBrandId"].ToString()));
  337. int UserId = int.Parse(dic["UserId"].ToString());
  338. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  339. dic["MakerCode"] = user.MakerCode;
  340. dic["RealName"] = user.RealName;
  341. int DamagedSnType = int.Parse(dic["DamagedSnType"].ToString());
  342. if(DamagedSnType == 0) dic["DamagedSnType"] = "购买机具";
  343. if(DamagedSnType == 1) dic["DamagedSnType"] = "赠送机具";
  344. int ReplaceSnType = int.Parse(dic["ReplaceSnType"].ToString());
  345. if(ReplaceSnType == 0) dic["ReplaceSnType"] = "购买机具";
  346. if(ReplaceSnType == 1) dic["ReplaceSnType"] = "赠送机具";
  347. int AuditStatus = int.Parse(dic["AuditStatus"].ToString());
  348. if(AuditStatus == 0) dic["AuditStatus"] = "未审核";
  349. if(AuditStatus == 1) dic["AuditStatus"] = "同步循环通过";
  350. if(AuditStatus == 2) dic["AuditStatus"] = "审核失败";
  351. dic.Remove("UserId");
  352. }
  353. Dictionary<string, object> result = new Dictionary<string, object>();
  354. result.Add("Status", "1");
  355. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  356. result.Add("Obj", diclist);
  357. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  358. ReturnFields.Add("ApplyNo", "机具售后换新申请订单号");
  359. ReturnFields.Add("MakerCode", "创客编号");
  360. ReturnFields.Add("RealName", "创客名称");
  361. ReturnFields.Add("DamagedBrandId", "损坏的机具产品名称");
  362. ReturnFields.Add("DamagedSnNo", "损坏的机具SN");
  363. ReturnFields.Add("DamagedSnType", "损坏的机具SN机具类型");
  364. ReturnFields.Add("ReplaceBrandId", "替换机具产品名称");
  365. ReturnFields.Add("ReplaceSnNo", "创客机具替换SN");
  366. ReturnFields.Add("ReplaceSnType", "替换的机具SN机具类型");
  367. ReturnFields.Add("DeliverBrandId", "仓库换新发货机具产品名称");
  368. ReturnFields.Add("DeliverSnNo", "仓库换新发货SN");
  369. ReturnFields.Add("DemandDesc", "售后换新机具处理需求描述");
  370. ReturnFields.Add("CreateDate", "机具售后换新申请时间");
  371. ReturnFields.Add("AuditStatus", "同步循环状态");
  372. ReturnFields.Add("AuditDesc", "机具售后换新审核描述");
  373. ReturnFields.Add("AuditDate", "同步循环时间");
  374. ReturnFields.Add("UpdateMan", "操作人员");
  375. result.Add("Fields", ReturnFields);
  376. AddSysLog("0", "MachineRenew", "ExportExcel");
  377. return Json(result);
  378. }
  379. #endregion
  380. }
  381. }