RecycMachineOrderController.cs 17 KB

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