MachineChangeController.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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 MachineChangeController : BaseController
  23. {
  24. public MachineChangeController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. }
  27. #region 机具转换订单列表
  28. /// <summary>
  29. /// 根据条件查询机具转换订单列表
  30. /// </summary>
  31. /// <returns></returns>
  32. public IActionResult Index(MachineChange data, string right)
  33. {
  34. ViewBag.RightInfo = RightInfo;
  35. ViewBag.right = right;
  36. return View();
  37. }
  38. #endregion
  39. #region 根据条件查询机具转换订单列表
  40. /// <summary>
  41. /// 机具转换订单列表
  42. /// </summary>
  43. /// <returns></returns>
  44. public JsonResult IndexData(MachineChange data, string UserIdRealName, string UserIdMakerCode, string BackProductTypeSelect, string AuditResultSelect, string BackStoreIdStoreName, string BackStoreIdStoreNo, string BackStoreUserIdMakerCode, string BackStoreUserIdRealName, string OutProductTypeSelect, string OutStoreIdStoreName, string OutStoreIdStoreNo, int page = 1, int limit = 30)
  45. {
  46. Dictionary<string, string> Fields = new Dictionary<string, string>();
  47. Fields.Add("ChangeNo", "1"); //转换单号
  48. Fields.Add("CreateDate", "3"); //时间
  49. Fields.Add("OutStoreManagerMobile", "1"); //出库仓库联系人手机号
  50. string condition = " and Status>-1";
  51. //创客真实姓名
  52. if (!string.IsNullOrEmpty(UserIdRealName))
  53. {
  54. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  55. }
  56. //创客创客编号
  57. if (!string.IsNullOrEmpty(UserIdMakerCode))
  58. {
  59. condition += " and UserId in (select UserId from UsersForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  60. }
  61. //退回产品类型
  62. if (!string.IsNullOrEmpty(BackProductTypeSelect))
  63. {
  64. condition += " and BackProductType=" + BackProductTypeSelect;
  65. }
  66. //审核结果
  67. if (!string.IsNullOrEmpty(AuditResultSelect))
  68. {
  69. condition += " and AuditResult=" + AuditResultSelect;
  70. }
  71. //退回仓库仓库名称
  72. if (!string.IsNullOrEmpty(BackStoreIdStoreName))
  73. {
  74. condition += " and BackStoreId in (select BackStoreId from StoreHouseForStoreName where StoreName='" + BackStoreIdStoreName + "')";
  75. }
  76. //退回仓库仓库编号
  77. if (!string.IsNullOrEmpty(BackStoreIdStoreNo))
  78. {
  79. condition += " and BackStoreId in (select BackStoreId from StoreHouseForStoreNo where StoreNo='" + BackStoreIdStoreNo + "')";
  80. }
  81. //退回仓库归属人创客编号
  82. if (!string.IsNullOrEmpty(BackStoreUserIdMakerCode))
  83. {
  84. condition += " and BackStoreUserId in (select BackStoreUserId from UsersForMakerCode where MakerCode='" + BackStoreUserIdMakerCode + "')";
  85. }
  86. //退回仓库归属人真实姓名
  87. if (!string.IsNullOrEmpty(BackStoreUserIdRealName))
  88. {
  89. condition += " and BackStoreUserId in (select BackStoreUserId from UsersForRealName where RealName='" + BackStoreUserIdRealName + "')";
  90. }
  91. //出库产品类型
  92. if (!string.IsNullOrEmpty(OutProductTypeSelect))
  93. {
  94. condition += " and OutProductType=" + OutProductTypeSelect;
  95. }
  96. //出库仓库仓库名称
  97. if (!string.IsNullOrEmpty(OutStoreIdStoreName))
  98. {
  99. condition += " and OutStoreId in (select OutStoreId from StoreHouseForStoreName where StoreName='" + OutStoreIdStoreName + "')";
  100. }
  101. //出库仓库仓库编号
  102. if (!string.IsNullOrEmpty(OutStoreIdStoreNo))
  103. {
  104. condition += " and OutStoreId in (select OutStoreId from StoreHouseForStoreNo where StoreNo='" + OutStoreIdStoreNo + "')";
  105. }
  106. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).IndexData("MachineChange", Fields, "Id desc", "0", page, limit, condition);
  107. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  108. foreach (Dictionary<string, object> dic in diclist)
  109. {
  110. //创客
  111. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  112. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  113. dic["UserIdRealName"] = userid_Users.RealName;
  114. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  115. dic.Remove("UserId");
  116. //退回产品类型
  117. dic["BackProductType"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BackProductType"].ToString()));
  118. //审核结果
  119. int AuditResult = int.Parse(dic["AuditResult"].ToString());
  120. if (AuditResult == 0) dic["AuditResult"] = "待审";
  121. if (AuditResult == 1) dic["AuditResult"] = "通过";
  122. if (AuditResult == 2) dic["AuditResult"] = "驳回";
  123. //退回仓库
  124. int BackStoreId = int.Parse(function.CheckInt(dic["BackStoreId"].ToString()));
  125. StoreHouse backstoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == BackStoreId) ?? new StoreHouse();
  126. dic["BackStoreIdStoreName"] = backstoreid_StoreHouse.StoreName;
  127. dic["BackStoreIdStoreNo"] = backstoreid_StoreHouse.StoreNo;
  128. dic.Remove("BackStoreId");
  129. //退回仓库归属人
  130. int BackStoreUserId = int.Parse(function.CheckInt(dic["BackStoreUserId"].ToString()));
  131. Users backstoreuserid_Users = db.Users.FirstOrDefault(m => m.Id == BackStoreUserId) ?? new Users();
  132. dic["BackStoreUserIdMakerCode"] = backstoreuserid_Users.MakerCode;
  133. dic["BackStoreUserIdRealName"] = backstoreuserid_Users.RealName;
  134. dic.Remove("BackStoreUserId");
  135. //出库产品类型
  136. dic["OutProductType"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["OutProductType"].ToString()));
  137. //出库仓库
  138. int OutStoreId = int.Parse(function.CheckInt(dic["OutStoreId"].ToString()));
  139. StoreHouse outstoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == OutStoreId) ?? new StoreHouse();
  140. dic["OutStoreIdStoreName"] = outstoreid_StoreHouse.StoreName;
  141. dic["OutStoreIdStoreNo"] = outstoreid_StoreHouse.StoreNo;
  142. dic.Remove("OutStoreId");
  143. }
  144. return Json(obj);
  145. }
  146. #endregion
  147. #region 增加机具转换订单
  148. /// <summary>
  149. /// 增加或修改机具转换订单信息
  150. /// </summary>
  151. /// <returns></returns>
  152. public IActionResult Add(string right)
  153. {
  154. ViewBag.RightInfo = RightInfo;
  155. ViewBag.right = right;
  156. return View();
  157. }
  158. #endregion
  159. #region 增加机具转换订单
  160. /// <summary>
  161. /// 增加或修改机具转换订单信息
  162. /// </summary>
  163. /// <returns></returns>
  164. [HttpPost]
  165. public string Add(MachineChange data)
  166. {
  167. Dictionary<string, object> Fields = new Dictionary<string, object>();
  168. Fields.Add("AuditResult", data.AuditResult); //审核结果
  169. Fields.Add("AuditRemark", data.AuditRemark); //审核备注
  170. Fields.Add("SeoTitle", data.SeoTitle);
  171. Fields.Add("SeoKeyword", data.SeoKeyword);
  172. Fields.Add("SeoDescription", data.SeoDescription);
  173. int Id = new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Add("MachineChange", Fields, 0);
  174. AddSysLog(data.Id.ToString(), "MachineChange", "add");
  175. db.SaveChanges();
  176. return "success";
  177. }
  178. #endregion
  179. #region 修改机具转换订单
  180. /// <summary>
  181. /// 增加或修改机具转换订单信息
  182. /// </summary>
  183. /// <returns></returns>
  184. public IActionResult Edit(string right, int Id = 0)
  185. {
  186. ViewBag.RightInfo = RightInfo;
  187. ViewBag.right = right;
  188. MachineChange editData = db.MachineChange.FirstOrDefault(m => m.Id == Id) ?? new MachineChange();
  189. ViewBag.data = editData;
  190. return View();
  191. }
  192. #endregion
  193. #region 修改机具转换订单
  194. /// <summary>
  195. /// 增加或修改机具转换订单信息
  196. /// </summary>
  197. /// <returns></returns>
  198. [HttpPost]
  199. public string Edit(MachineChange data)
  200. {
  201. Dictionary<string, object> Fields = new Dictionary<string, object>();
  202. Fields.Add("AuditResult", data.AuditResult); //审核结果
  203. Fields.Add("AuditRemark", data.AuditRemark); //审核备注
  204. Fields.Add("SeoTitle", data.SeoTitle);
  205. Fields.Add("SeoKeyword", data.SeoKeyword);
  206. Fields.Add("SeoDescription", data.SeoDescription);
  207. new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("MachineChange", Fields, data.Id);
  208. AddSysLog(data.Id.ToString(), "MachineChange", "update");
  209. db.SaveChanges();
  210. return "success";
  211. }
  212. #endregion
  213. #region 删除机具转换订单信息
  214. /// <summary>
  215. /// 删除机具转换订单信息
  216. /// </summary>
  217. /// <returns></returns>
  218. public string Delete(string Id)
  219. {
  220. string[] idlist = Id.Split(new char[] { ',' });
  221. AddSysLog(Id, "MachineChange", "del");
  222. foreach (string subid in idlist)
  223. {
  224. int id = int.Parse(subid);
  225. Dictionary<string, object> Fields = new Dictionary<string, object>();
  226. Fields.Add("Status", -1);
  227. new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("MachineChange", Fields, id);
  228. }
  229. db.SaveChanges();
  230. return "success";
  231. }
  232. #endregion
  233. #region 开启
  234. /// <summary>
  235. /// 开启
  236. /// </summary>
  237. /// <returns></returns>
  238. public string Open(string Id)
  239. {
  240. string[] idlist = Id.Split(new char[] { ',' });
  241. AddSysLog(Id, "MachineChange", "open");
  242. foreach (string subid in idlist)
  243. {
  244. int id = int.Parse(subid);
  245. Dictionary<string, object> Fields = new Dictionary<string, object>();
  246. Fields.Add("Status", 1);
  247. new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("MachineChange", Fields, id);
  248. }
  249. db.SaveChanges();
  250. return "success";
  251. }
  252. #endregion
  253. #region 关闭
  254. /// <summary>
  255. /// 关闭
  256. /// </summary>
  257. /// <returns></returns>
  258. public string Close(string Id)
  259. {
  260. string[] idlist = Id.Split(new char[] { ',' });
  261. AddSysLog(Id, "MachineChange", "close");
  262. foreach (string subid in idlist)
  263. {
  264. int id = int.Parse(subid);
  265. Dictionary<string, object> Fields = new Dictionary<string, object>();
  266. Fields.Add("Status", 0);
  267. new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("MachineChange", Fields, id);
  268. }
  269. db.SaveChanges();
  270. return "success";
  271. }
  272. #endregion
  273. #region 排序
  274. /// <summary>
  275. /// 排序
  276. /// </summary>
  277. /// <param name="Id"></param>
  278. public string Sort(int Id, int Sort)
  279. {
  280. new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Sort("MachineChange", Sort, Id);
  281. AddSysLog(Id.ToString(), "MachineChange", "sort");
  282. return "success";
  283. }
  284. #endregion
  285. #region 导入数据
  286. /// <summary>
  287. /// 导入数据
  288. /// </summary>
  289. /// <param name="ExcelData"></param>
  290. public string Import(string ExcelData)
  291. {
  292. ExcelData = HttpUtility.UrlDecode(ExcelData);
  293. JsonData list = JsonMapper.ToObject(ExcelData);
  294. for (int i = 1; i < list.Count; i++)
  295. {
  296. JsonData dr = list[i];
  297. db.MachineChange.Add(new MachineChange()
  298. {
  299. CreateDate = DateTime.Now,
  300. UpdateDate = DateTime.Now,
  301. });
  302. db.SaveChanges();
  303. }
  304. AddSysLog("0", "MachineChange", "Import");
  305. return "success";
  306. }
  307. #endregion
  308. #region 导出Excel
  309. /// <summary>
  310. /// 导出Excel
  311. /// </summary>
  312. /// <returns></returns>
  313. public JsonResult ExportExcel(MachineChange data, string UserIdRealName, string UserIdMakerCode, string BackProductTypeSelect, string AuditResultSelect, string BackStoreIdStoreName, string BackStoreIdStoreNo, string BackStoreUserIdMakerCode, string BackStoreUserIdRealName, string OutProductTypeSelect, string OutStoreIdStoreName, string OutStoreIdStoreNo)
  314. {
  315. Dictionary<string, string> Fields = new Dictionary<string, string>();
  316. Fields.Add("ChangeNo", "1"); //转换单号
  317. Fields.Add("CreateDate", "3"); //时间
  318. Fields.Add("OutStoreManagerMobile", "1"); //出库仓库联系人手机号
  319. string condition = " and Status>-1";
  320. //创客真实姓名
  321. if (!string.IsNullOrEmpty(UserIdRealName))
  322. {
  323. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  324. }
  325. //创客创客编号
  326. if (!string.IsNullOrEmpty(UserIdMakerCode))
  327. {
  328. condition += " and UserId in (select UserId from UsersForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  329. }
  330. //退回产品类型
  331. if (!string.IsNullOrEmpty(BackProductTypeSelect))
  332. {
  333. condition += " and BackProductType=" + BackProductTypeSelect;
  334. }
  335. //审核结果
  336. if (!string.IsNullOrEmpty(AuditResultSelect))
  337. {
  338. condition += " and AuditResult=" + AuditResultSelect;
  339. }
  340. //退回仓库仓库名称
  341. if (!string.IsNullOrEmpty(BackStoreIdStoreName))
  342. {
  343. condition += " and BackStoreId in (select BackStoreId from StoreHouseForStoreName where StoreName='" + BackStoreIdStoreName + "')";
  344. }
  345. //退回仓库仓库编号
  346. if (!string.IsNullOrEmpty(BackStoreIdStoreNo))
  347. {
  348. condition += " and BackStoreId in (select BackStoreId from StoreHouseForStoreNo where StoreNo='" + BackStoreIdStoreNo + "')";
  349. }
  350. //退回仓库归属人创客编号
  351. if (!string.IsNullOrEmpty(BackStoreUserIdMakerCode))
  352. {
  353. condition += " and BackStoreUserId in (select BackStoreUserId from UsersForMakerCode where MakerCode='" + BackStoreUserIdMakerCode + "')";
  354. }
  355. //退回仓库归属人真实姓名
  356. if (!string.IsNullOrEmpty(BackStoreUserIdRealName))
  357. {
  358. condition += " and BackStoreUserId in (select BackStoreUserId from UsersForRealName where RealName='" + BackStoreUserIdRealName + "')";
  359. }
  360. //出库产品类型
  361. if (!string.IsNullOrEmpty(OutProductTypeSelect))
  362. {
  363. condition += " and OutProductType=" + OutProductTypeSelect;
  364. }
  365. //出库仓库仓库名称
  366. if (!string.IsNullOrEmpty(OutStoreIdStoreName))
  367. {
  368. condition += " and OutStoreId in (select OutStoreId from StoreHouseForStoreName where StoreName='" + OutStoreIdStoreName + "')";
  369. }
  370. //出库仓库仓库编号
  371. if (!string.IsNullOrEmpty(OutStoreIdStoreNo))
  372. {
  373. condition += " and OutStoreId in (select OutStoreId from StoreHouseForStoreNo where StoreNo='" + OutStoreIdStoreNo + "')";
  374. }
  375. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).IndexData("MachineChange", Fields, "Id desc", "0", 1, 20000, condition, "ChangeNo,UserId,BackProductType,ChangeDeviceNum,ChangeTime,AuditBy,AuditResult,AuditRemark,ChangeSnExpand,BackStoreId,Remark,BackStoreUserId,OutProductType,OutStoreId,OutStoreManagerMobile", false);
  376. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  377. foreach (Dictionary<string, object> dic in diclist)
  378. {
  379. //创客
  380. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  381. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  382. dic["UserIdRealName"] = userid_Users.RealName;
  383. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  384. dic.Remove("UserId");
  385. //退回产品类型
  386. dic["BackProductType"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BackProductType"].ToString()));
  387. //审核结果
  388. int AuditResult = int.Parse(dic["AuditResult"].ToString());
  389. if (AuditResult == 0) dic["AuditResult"] = "待审";
  390. if (AuditResult == 1) dic["AuditResult"] = "通过";
  391. if (AuditResult == 2) dic["AuditResult"] = "驳回";
  392. //退回仓库
  393. int BackStoreId = int.Parse(function.CheckInt(dic["BackStoreId"].ToString()));
  394. StoreHouse backstoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == BackStoreId) ?? new StoreHouse();
  395. dic["BackStoreIdStoreName"] = backstoreid_StoreHouse.StoreName;
  396. dic["BackStoreIdStoreNo"] = backstoreid_StoreHouse.StoreNo;
  397. dic.Remove("BackStoreId");
  398. //退回仓库归属人
  399. int BackStoreUserId = int.Parse(function.CheckInt(dic["BackStoreUserId"].ToString()));
  400. Users backstoreuserid_Users = db.Users.FirstOrDefault(m => m.Id == BackStoreUserId) ?? new Users();
  401. dic["BackStoreUserIdMakerCode"] = backstoreuserid_Users.MakerCode;
  402. dic["BackStoreUserIdRealName"] = backstoreuserid_Users.RealName;
  403. dic.Remove("BackStoreUserId");
  404. //出库产品类型
  405. dic["OutProductType"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["OutProductType"].ToString()));
  406. //出库仓库
  407. int OutStoreId = int.Parse(function.CheckInt(dic["OutStoreId"].ToString()));
  408. StoreHouse outstoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == OutStoreId) ?? new StoreHouse();
  409. dic["OutStoreIdStoreName"] = outstoreid_StoreHouse.StoreName;
  410. dic["OutStoreIdStoreNo"] = outstoreid_StoreHouse.StoreNo;
  411. dic.Remove("OutStoreId");
  412. }
  413. Dictionary<string, object> result = new Dictionary<string, object>();
  414. result.Add("Status", "1");
  415. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  416. result.Add("Obj", diclist);
  417. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  418. ReturnFields.Add("ChangeNo", "转换单号");
  419. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  420. ReturnFields.Add("UserIdMakerCode", "创客创客编号");
  421. ReturnFields.Add("BackProductType", "退回产品类型");
  422. ReturnFields.Add("ChangeDeviceNum", "转换机具数量");
  423. ReturnFields.Add("ChangeTime", "转换时间");
  424. ReturnFields.Add("AuditBy", "审核人");
  425. ReturnFields.Add("AuditResult", "审核结果");
  426. ReturnFields.Add("AuditRemark", "审核备注");
  427. ReturnFields.Add("ChangeSnExpand", "转换机器SN来源");
  428. ReturnFields.Add("BackStoreIdStoreName", "退回仓库仓库名称");
  429. ReturnFields.Add("BackStoreIdStoreNo", "退回仓库仓库编号");
  430. ReturnFields.Add("Remark", "订单备注");
  431. ReturnFields.Add("BackStoreUserIdMakerCode", "退回仓库归属人创客编号");
  432. ReturnFields.Add("BackStoreUserIdRealName", "退回仓库归属人真实姓名");
  433. ReturnFields.Add("OutProductType", "出库产品类型");
  434. ReturnFields.Add("OutStoreIdStoreName", "出库仓库仓库名称");
  435. ReturnFields.Add("OutStoreIdStoreNo", "出库仓库仓库编号");
  436. ReturnFields.Add("OutStoreManagerMobile", "出库仓库联系人手机号");
  437. result.Add("Fields", ReturnFields);
  438. AddSysLog("0", "MachineChange", "ExportExcel");
  439. return Json(result);
  440. }
  441. #endregion
  442. }
  443. }