MachineChangeController.cs 23 KB

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