MachineChangeController.cs 22 KB

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