MachineChangeController.cs 23 KB

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