RecycMachineOrderController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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 UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  57. }
  58. //退回仓库编号
  59. if (!string.IsNullOrEmpty(RecycStoreIdStoreNo))
  60. {
  61. condition += " and RecycStoreId in (select StoreId from StoreForCode where Code='" + RecycStoreIdStoreNo + "')";
  62. }
  63. //寄回方式
  64. if (!string.IsNullOrEmpty(PostTypeSelect))
  65. {
  66. condition += " and PostType=" + PostTypeSelect;
  67. }
  68. //机具品牌
  69. if (!string.IsNullOrEmpty(BrandIdSelect))
  70. {
  71. condition += " and BrandId=" + BrandIdSelect;
  72. }
  73. if (!string.IsNullOrEmpty(CreateDateData))
  74. {
  75. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  76. string start = datelist[0];
  77. string end = datelist[1];
  78. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  79. }
  80. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("RecycMachineOrder", Fields, "Id desc", "0", page, limit, condition);
  81. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  82. foreach (Dictionary<string, object> dic in diclist)
  83. {
  84. //创客
  85. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  86. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  87. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  88. dic["UserIdRealName"] = userid_Users.RealName;
  89. dic.Remove("UserId");
  90. //退回仓库
  91. int RecycStoreId = int.Parse(function.CheckInt(dic["RecycStoreId"].ToString()));
  92. StoreHouse recycstoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == RecycStoreId) ?? new StoreHouse();
  93. dic["RecycStoreIdStoreNo"] = recycstoreid_StoreHouse.StoreNo;
  94. dic["RecycStoreIdStoreName"] = recycstoreid_StoreHouse.StoreName;
  95. dic["RecycStoreIdManageMobile"] = recycstoreid_StoreHouse.ManageMobile;
  96. dic.Remove("RecycStoreId");
  97. //寄回方式
  98. int PostType = int.Parse(dic["PostType"].ToString());
  99. if (PostType == 1) dic["PostType"] = "邮寄";
  100. if (PostType == 2) dic["PostType"] = "送货上门";
  101. if (PostType == 0) dic["PostType"] = "";
  102. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  103. }
  104. return Json(obj);
  105. }
  106. #endregion
  107. #region 增加机具回收申请
  108. /// <summary>
  109. /// 增加或修改机具回收申请信息
  110. /// </summary>
  111. /// <returns></returns>
  112. public IActionResult Add(string right)
  113. {
  114. ViewBag.RightInfo = RightInfo;
  115. ViewBag.right = right;
  116. return View();
  117. }
  118. #endregion
  119. #region 增加机具回收申请
  120. /// <summary>
  121. /// 增加或修改机具回收申请信息
  122. /// </summary>
  123. /// <returns></returns>
  124. [HttpPost]
  125. public string Add(RecycMachineOrder data)
  126. {
  127. Dictionary<string, object> Fields = new Dictionary<string, object>();
  128. Fields.Add("UserId", data.UserId); //创客
  129. Fields.Add("RecycStoreId", data.RecycStoreId); //退回仓库
  130. Fields.Add("PostType", data.PostType); //寄回方式
  131. Fields.Add("ErpName", data.ErpName); //快递名称
  132. Fields.Add("ErpCode", data.ErpCode); //快递单号
  133. Fields.Add("SeoTitle", data.SeoTitle);
  134. Fields.Add("SeoKeyword", data.SeoKeyword);
  135. Fields.Add("SeoDescription", data.SeoDescription);
  136. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("RecycMachineOrder", Fields, 0);
  137. AddSysLog(data.Id.ToString(), "RecycMachineOrder", "add");
  138. db.SaveChanges();
  139. return "success";
  140. }
  141. #endregion
  142. #region 修改机具回收申请
  143. /// <summary>
  144. /// 增加或修改机具回收申请信息
  145. /// </summary>
  146. /// <returns></returns>
  147. public IActionResult Edit(string right, int Id = 0)
  148. {
  149. ViewBag.RightInfo = RightInfo;
  150. ViewBag.right = right;
  151. RecycMachineOrder editData = db.RecycMachineOrder.FirstOrDefault(m => m.Id == Id) ?? new RecycMachineOrder();
  152. ViewBag.data = editData;
  153. return View();
  154. }
  155. #endregion
  156. #region 修改机具回收申请
  157. /// <summary>
  158. /// 增加或修改机具回收申请信息
  159. /// </summary>
  160. /// <returns></returns>
  161. [HttpPost]
  162. public string Edit(RecycMachineOrder data)
  163. {
  164. Dictionary<string, object> Fields = new Dictionary<string, object>();
  165. Fields.Add("UserId", data.UserId); //创客
  166. Fields.Add("RecycStoreId", data.RecycStoreId); //退回仓库
  167. Fields.Add("PostType", data.PostType); //寄回方式
  168. Fields.Add("ErpName", data.ErpName); //快递名称
  169. Fields.Add("ErpCode", data.ErpCode); //快递单号
  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("RecycMachineOrder", Fields, data.Id);
  174. AddSysLog(data.Id.ToString(), "RecycMachineOrder", "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, "RecycMachineOrder", "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("RecycMachineOrder", 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, "RecycMachineOrder", "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("RecycMachineOrder", 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, "RecycMachineOrder", "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("RecycMachineOrder", 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("RecycMachineOrder", Sort, Id);
  247. AddSysLog(Id.ToString(), "RecycMachineOrder", "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.RecycMachineOrder.Add(new RecycMachineOrder()
  264. {
  265. CreateDate = DateTime.Now,
  266. UpdateDate = DateTime.Now,
  267. });
  268. db.SaveChanges();
  269. }
  270. AddSysLog("0", "RecycMachineOrder", "Import");
  271. return "success";
  272. }
  273. #endregion
  274. #region 导出Excel
  275. /// <summary>
  276. /// 导出Excel
  277. /// </summary>
  278. /// <returns></returns>
  279. public JsonResult ExportExcel(RecycMachineOrder data, string UserIdMakerCode, string UserIdRealName, string RecycStoreIdStoreNo, string RecycStoreIdStoreName, string RecycStoreIdManageMobile, string PostTypeSelect, string BrandIdSelect)
  280. {
  281. Dictionary<string, string> Fields = new Dictionary<string, string>();
  282. Fields.Add("CreateDate", "3"); //时间
  283. Fields.Add("ErpName", "1"); //快递名称
  284. Fields.Add("ErpCode", "1"); //快递单号
  285. Fields.Add("RecycOrderNo", "1"); //申请单号
  286. string condition = " and Status>-1";
  287. //创客创客编号
  288. if (!string.IsNullOrEmpty(UserIdMakerCode))
  289. {
  290. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  291. }
  292. //创客真实姓名
  293. if (!string.IsNullOrEmpty(UserIdRealName))
  294. {
  295. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  296. }
  297. //退回仓库仓库编号
  298. if (!string.IsNullOrEmpty(RecycStoreIdStoreNo))
  299. {
  300. condition += " and RecycStoreId in (select RecycStoreId from StoreHouseForStoreNo where StoreNo='" + RecycStoreIdStoreNo + "')";
  301. }
  302. //退回仓库仓库名称
  303. if (!string.IsNullOrEmpty(RecycStoreIdStoreName))
  304. {
  305. condition += " and RecycStoreId in (select RecycStoreId from StoreHouseForStoreName where StoreName='" + RecycStoreIdStoreName + "')";
  306. }
  307. //退回仓库管理者手机号
  308. if (!string.IsNullOrEmpty(RecycStoreIdManageMobile))
  309. {
  310. condition += " and RecycStoreId in (select RecycStoreId from StoreHouseForManageMobile where ManageMobile='" + RecycStoreIdManageMobile + "')";
  311. }
  312. //寄回方式
  313. if (!string.IsNullOrEmpty(PostTypeSelect))
  314. {
  315. condition += " and PostType=" + PostTypeSelect;
  316. }
  317. //机具品牌
  318. if (!string.IsNullOrEmpty(BrandIdSelect))
  319. {
  320. condition += " and BrandId=" + BrandIdSelect;
  321. }
  322. 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);
  323. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  324. foreach (Dictionary<string, object> dic in diclist)
  325. {
  326. //创客
  327. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  328. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  329. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  330. dic["UserIdRealName"] = userid_Users.RealName;
  331. dic.Remove("UserId");
  332. //退回仓库
  333. int RecycStoreId = int.Parse(function.CheckInt(dic["RecycStoreId"].ToString()));
  334. StoreHouse recycstoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == RecycStoreId) ?? new StoreHouse();
  335. dic["RecycStoreIdStoreNo"] = recycstoreid_StoreHouse.StoreNo;
  336. dic["RecycStoreIdStoreName"] = recycstoreid_StoreHouse.StoreName;
  337. dic["RecycStoreIdManageMobile"] = recycstoreid_StoreHouse.ManageMobile;
  338. dic.Remove("RecycStoreId");
  339. //寄回方式
  340. int PostType = int.Parse(dic["PostType"].ToString());
  341. if (PostType == 1) dic["PostType"] = "邮寄";
  342. if (PostType == 2) dic["PostType"] = "送货上门";
  343. if (PostType == 0) dic["PostType"] = "";
  344. }
  345. Dictionary<string, object> result = new Dictionary<string, object>();
  346. result.Add("Status", "1");
  347. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  348. result.Add("Obj", diclist);
  349. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  350. ReturnFields.Add("UserIdMakerCode", "创客创客编号");
  351. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  352. ReturnFields.Add("RecycStoreIdStoreNo", "退回仓库仓库编号");
  353. ReturnFields.Add("RecycStoreIdStoreName", "退回仓库仓库名称");
  354. ReturnFields.Add("RecycStoreIdManageMobile", "退回仓库管理者手机号");
  355. ReturnFields.Add("PostType", "寄回方式");
  356. ReturnFields.Add("ErpName", "快递名称");
  357. ReturnFields.Add("ErpCode", "快递单号");
  358. ReturnFields.Add("ResultDate", "确认或驳回时间");
  359. ReturnFields.Add("CancelDate", "创客撤销时间");
  360. ReturnFields.Add("RecycOrderNo", "申请单号");
  361. result.Add("Fields", ReturnFields);
  362. AddSysLog("0", "RecycMachineOrder", "ExportExcel");
  363. return Json(result);
  364. }
  365. #endregion
  366. }
  367. }