RecycMachineOrderController.cs 17 KB

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