RecycMachineOrderController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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 RecycMachineOrderController : BaseController
  23. {
  24. public RecycMachineOrderController(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(RecycMachineOrder 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(RecycMachineOrder data, string UserIdMakerCode, string UserIdRealName, string RecycStoreIdStoreNo, string RecycStoreIdStoreName, string RecycStoreIdManageMobile, string PostTypeSelect, string BrandIdSelect, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("CreateDate", "3"); //时间
  49. Fields.Add("ErpName", "1"); //快递名称
  50. Fields.Add("ErpCode", "1"); //快递单号
  51. Fields.Add("RecycOrderNo", "1"); //申请单号
  52. string condition = " and Status>-1";
  53. //创客创客编号
  54. if (!string.IsNullOrEmpty(UserIdMakerCode))
  55. {
  56. condition += " and UserId in (select UserId from UsersForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  57. }
  58. //创客真实姓名
  59. if (!string.IsNullOrEmpty(UserIdRealName))
  60. {
  61. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  62. }
  63. //退回仓库仓库编号
  64. if (!string.IsNullOrEmpty(RecycStoreIdStoreNo))
  65. {
  66. condition += " and RecycStoreId in (select RecycStoreId from StoreHouseForStoreNo where StoreNo='" + RecycStoreIdStoreNo + "')";
  67. }
  68. //退回仓库仓库名称
  69. if (!string.IsNullOrEmpty(RecycStoreIdStoreName))
  70. {
  71. condition += " and RecycStoreId in (select RecycStoreId from StoreHouseForStoreName where StoreName='" + RecycStoreIdStoreName + "')";
  72. }
  73. //退回仓库管理者手机号
  74. if (!string.IsNullOrEmpty(RecycStoreIdManageMobile))
  75. {
  76. condition += " and RecycStoreId in (select RecycStoreId from StoreHouseForManageMobile where ManageMobile='" + RecycStoreIdManageMobile + "')";
  77. }
  78. //寄回方式
  79. if (!string.IsNullOrEmpty(PostTypeSelect))
  80. {
  81. condition += " and PostType=" + PostTypeSelect;
  82. }
  83. //机具品牌
  84. if (!string.IsNullOrEmpty(BrandIdSelect))
  85. {
  86. condition += " and BrandId=" + BrandIdSelect;
  87. }
  88. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("RecycMachineOrder", Fields, "Id desc", "0", page, limit, condition);
  89. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  90. foreach (Dictionary<string, object> dic in diclist)
  91. {
  92. //创客
  93. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  94. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  95. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  96. dic["UserIdRealName"] = userid_Users.RealName;
  97. dic.Remove("UserId");
  98. //退回仓库
  99. int RecycStoreId = int.Parse(function.CheckInt(dic["RecycStoreId"].ToString()));
  100. StoreHouse recycstoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == RecycStoreId) ?? new StoreHouse();
  101. dic["RecycStoreIdStoreNo"] = recycstoreid_StoreHouse.StoreNo;
  102. dic["RecycStoreIdStoreName"] = recycstoreid_StoreHouse.StoreName;
  103. dic["RecycStoreIdManageMobile"] = recycstoreid_StoreHouse.ManageMobile;
  104. dic.Remove("RecycStoreId");
  105. //寄回方式
  106. int PostType = int.Parse(dic["PostType"].ToString());
  107. if (PostType == 1) dic["PostType"] = "邮寄";
  108. if (PostType == 2) dic["PostType"] = "送货上门";
  109. if (PostType == 0) dic["PostType"] = "";
  110. }
  111. return Json(obj);
  112. }
  113. #endregion
  114. #region 增加机具回收申请
  115. /// <summary>
  116. /// 增加或修改机具回收申请信息
  117. /// </summary>
  118. /// <returns></returns>
  119. public IActionResult Add(string right)
  120. {
  121. ViewBag.RightInfo = RightInfo;
  122. ViewBag.right = right;
  123. return View();
  124. }
  125. #endregion
  126. #region 增加机具回收申请
  127. /// <summary>
  128. /// 增加或修改机具回收申请信息
  129. /// </summary>
  130. /// <returns></returns>
  131. [HttpPost]
  132. public string Add(RecycMachineOrder data)
  133. {
  134. Dictionary<string, object> Fields = new Dictionary<string, object>();
  135. Fields.Add("UserId", data.UserId); //创客
  136. Fields.Add("RecycStoreId", data.RecycStoreId); //退回仓库
  137. Fields.Add("PostType", data.PostType); //寄回方式
  138. Fields.Add("ErpName", data.ErpName); //快递名称
  139. Fields.Add("ErpCode", data.ErpCode); //快递单号
  140. Fields.Add("SeoTitle", data.SeoTitle);
  141. Fields.Add("SeoKeyword", data.SeoKeyword);
  142. Fields.Add("SeoDescription", data.SeoDescription);
  143. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("RecycMachineOrder", Fields, 0);
  144. AddSysLog(data.Id.ToString(), "RecycMachineOrder", "add");
  145. db.SaveChanges();
  146. return "success";
  147. }
  148. #endregion
  149. #region 修改机具回收申请
  150. /// <summary>
  151. /// 增加或修改机具回收申请信息
  152. /// </summary>
  153. /// <returns></returns>
  154. public IActionResult Edit(string right, int Id = 0)
  155. {
  156. ViewBag.RightInfo = RightInfo;
  157. ViewBag.right = right;
  158. RecycMachineOrder editData = db.RecycMachineOrder.FirstOrDefault(m => m.Id == Id) ?? new RecycMachineOrder();
  159. ViewBag.data = editData;
  160. return View();
  161. }
  162. #endregion
  163. #region 修改机具回收申请
  164. /// <summary>
  165. /// 增加或修改机具回收申请信息
  166. /// </summary>
  167. /// <returns></returns>
  168. [HttpPost]
  169. public string Edit(RecycMachineOrder data)
  170. {
  171. Dictionary<string, object> Fields = new Dictionary<string, object>();
  172. Fields.Add("UserId", data.UserId); //创客
  173. Fields.Add("RecycStoreId", data.RecycStoreId); //退回仓库
  174. Fields.Add("PostType", data.PostType); //寄回方式
  175. Fields.Add("ErpName", data.ErpName); //快递名称
  176. Fields.Add("ErpCode", data.ErpCode); //快递单号
  177. Fields.Add("SeoTitle", data.SeoTitle);
  178. Fields.Add("SeoKeyword", data.SeoKeyword);
  179. Fields.Add("SeoDescription", data.SeoDescription);
  180. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("RecycMachineOrder", Fields, data.Id);
  181. AddSysLog(data.Id.ToString(), "RecycMachineOrder", "update");
  182. db.SaveChanges();
  183. return "success";
  184. }
  185. #endregion
  186. #region 删除机具回收申请信息
  187. /// <summary>
  188. /// 删除机具回收申请信息
  189. /// </summary>
  190. /// <returns></returns>
  191. public string Delete(string Id)
  192. {
  193. string[] idlist = Id.Split(new char[] { ',' });
  194. AddSysLog(Id, "RecycMachineOrder", "del");
  195. foreach (string subid in idlist)
  196. {
  197. int id = int.Parse(subid);
  198. Dictionary<string, object> Fields = new Dictionary<string, object>();
  199. Fields.Add("Status", -1);
  200. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("RecycMachineOrder", Fields, id);
  201. }
  202. db.SaveChanges();
  203. return "success";
  204. }
  205. #endregion
  206. #region 开启
  207. /// <summary>
  208. /// 开启
  209. /// </summary>
  210. /// <returns></returns>
  211. public string Open(string Id)
  212. {
  213. string[] idlist = Id.Split(new char[] { ',' });
  214. AddSysLog(Id, "RecycMachineOrder", "open");
  215. foreach (string subid in idlist)
  216. {
  217. int id = int.Parse(subid);
  218. Dictionary<string, object> Fields = new Dictionary<string, object>();
  219. Fields.Add("Status", 1);
  220. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("RecycMachineOrder", Fields, id);
  221. }
  222. db.SaveChanges();
  223. return "success";
  224. }
  225. #endregion
  226. #region 关闭
  227. /// <summary>
  228. /// 关闭
  229. /// </summary>
  230. /// <returns></returns>
  231. public string Close(string Id)
  232. {
  233. string[] idlist = Id.Split(new char[] { ',' });
  234. AddSysLog(Id, "RecycMachineOrder", "close");
  235. foreach (string subid in idlist)
  236. {
  237. int id = int.Parse(subid);
  238. Dictionary<string, object> Fields = new Dictionary<string, object>();
  239. Fields.Add("Status", 0);
  240. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("RecycMachineOrder", Fields, id);
  241. }
  242. db.SaveChanges();
  243. return "success";
  244. }
  245. #endregion
  246. #region 排序
  247. /// <summary>
  248. /// 排序
  249. /// </summary>
  250. /// <param name="Id"></param>
  251. public string Sort(int Id, int Sort)
  252. {
  253. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("RecycMachineOrder", Sort, Id);
  254. AddSysLog(Id.ToString(), "RecycMachineOrder", "sort");
  255. return "success";
  256. }
  257. #endregion
  258. #region 导入数据
  259. /// <summary>
  260. /// 导入数据
  261. /// </summary>
  262. /// <param name="ExcelData"></param>
  263. public string Import(string ExcelData)
  264. {
  265. ExcelData = HttpUtility.UrlDecode(ExcelData);
  266. JsonData list = JsonMapper.ToObject(ExcelData);
  267. for (int i = 1; i < list.Count; i++)
  268. {
  269. JsonData dr = list[i];
  270. db.RecycMachineOrder.Add(new RecycMachineOrder()
  271. {
  272. CreateDate = DateTime.Now,
  273. UpdateDate = DateTime.Now,
  274. });
  275. db.SaveChanges();
  276. }
  277. AddSysLog("0", "RecycMachineOrder", "Import");
  278. return "success";
  279. }
  280. #endregion
  281. #region 导出Excel
  282. /// <summary>
  283. /// 导出Excel
  284. /// </summary>
  285. /// <returns></returns>
  286. public JsonResult ExportExcel(RecycMachineOrder data, string UserIdMakerCode, string UserIdRealName, string RecycStoreIdStoreNo, string RecycStoreIdStoreName, string RecycStoreIdManageMobile, string PostTypeSelect, string BrandIdSelect)
  287. {
  288. Dictionary<string, string> Fields = new Dictionary<string, string>();
  289. Fields.Add("CreateDate", "3"); //时间
  290. Fields.Add("ErpName", "1"); //快递名称
  291. Fields.Add("ErpCode", "1"); //快递单号
  292. Fields.Add("RecycOrderNo", "1"); //申请单号
  293. string condition = " and Status>-1";
  294. //创客创客编号
  295. if (!string.IsNullOrEmpty(UserIdMakerCode))
  296. {
  297. condition += " and UserId in (select UserId from UsersForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  298. }
  299. //创客真实姓名
  300. if (!string.IsNullOrEmpty(UserIdRealName))
  301. {
  302. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  303. }
  304. //退回仓库仓库编号
  305. if (!string.IsNullOrEmpty(RecycStoreIdStoreNo))
  306. {
  307. condition += " and RecycStoreId in (select RecycStoreId from StoreHouseForStoreNo where StoreNo='" + RecycStoreIdStoreNo + "')";
  308. }
  309. //退回仓库仓库名称
  310. if (!string.IsNullOrEmpty(RecycStoreIdStoreName))
  311. {
  312. condition += " and RecycStoreId in (select RecycStoreId from StoreHouseForStoreName where StoreName='" + RecycStoreIdStoreName + "')";
  313. }
  314. //退回仓库管理者手机号
  315. if (!string.IsNullOrEmpty(RecycStoreIdManageMobile))
  316. {
  317. condition += " and RecycStoreId in (select RecycStoreId from StoreHouseForManageMobile where ManageMobile='" + RecycStoreIdManageMobile + "')";
  318. }
  319. //寄回方式
  320. if (!string.IsNullOrEmpty(PostTypeSelect))
  321. {
  322. condition += " and PostType=" + PostTypeSelect;
  323. }
  324. //机具品牌
  325. if (!string.IsNullOrEmpty(BrandIdSelect))
  326. {
  327. condition += " and BrandId=" + BrandIdSelect;
  328. }
  329. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("RecycMachineOrder", Fields, "Id desc", "0", 1, 20000, condition, "UserId,RecycStoreId,PostType,ErpName,ErpCode,ResultDate,CancelDate,RecycOrderNo", false);
  330. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  331. foreach (Dictionary<string, object> dic in diclist)
  332. {
  333. //创客
  334. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  335. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  336. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  337. dic["UserIdRealName"] = userid_Users.RealName;
  338. dic.Remove("UserId");
  339. //退回仓库
  340. int RecycStoreId = int.Parse(function.CheckInt(dic["RecycStoreId"].ToString()));
  341. StoreHouse recycstoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == RecycStoreId) ?? new StoreHouse();
  342. dic["RecycStoreIdStoreNo"] = recycstoreid_StoreHouse.StoreNo;
  343. dic["RecycStoreIdStoreName"] = recycstoreid_StoreHouse.StoreName;
  344. dic["RecycStoreIdManageMobile"] = recycstoreid_StoreHouse.ManageMobile;
  345. dic.Remove("RecycStoreId");
  346. //寄回方式
  347. int PostType = int.Parse(dic["PostType"].ToString());
  348. if (PostType == 1) dic["PostType"] = "邮寄";
  349. if (PostType == 2) dic["PostType"] = "送货上门";
  350. if (PostType == 0) dic["PostType"] = "";
  351. }
  352. Dictionary<string, object> result = new Dictionary<string, object>();
  353. result.Add("Status", "1");
  354. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  355. result.Add("Obj", diclist);
  356. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  357. ReturnFields.Add("UserIdMakerCode", "创客创客编号");
  358. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  359. ReturnFields.Add("RecycStoreIdStoreNo", "退回仓库仓库编号");
  360. ReturnFields.Add("RecycStoreIdStoreName", "退回仓库仓库名称");
  361. ReturnFields.Add("RecycStoreIdManageMobile", "退回仓库管理者手机号");
  362. ReturnFields.Add("PostType", "寄回方式");
  363. ReturnFields.Add("ErpName", "快递名称");
  364. ReturnFields.Add("ErpCode", "快递单号");
  365. ReturnFields.Add("ResultDate", "确认或驳回时间");
  366. ReturnFields.Add("CancelDate", "创客撤销时间");
  367. ReturnFields.Add("RecycOrderNo", "申请单号");
  368. result.Add("Fields", ReturnFields);
  369. AddSysLog("0", "RecycMachineOrder", "ExportExcel");
  370. return Json(result);
  371. }
  372. #endregion
  373. }
  374. }