MachineReturnController.cs 16 KB

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