DevelopersController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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 DevelopersController : BaseController
  23. {
  24. public DevelopersController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. }
  27. #region 开发者列表
  28. /// <summary>
  29. /// 根据条件查询开发者列表
  30. /// </summary>
  31. /// <returns></returns>
  32. public IActionResult Index(Developers data, string right)
  33. {
  34. ViewBag.RightInfo = RightInfo;
  35. ViewBag.right = right;
  36. return View();
  37. }
  38. #endregion
  39. #region 根据条件查询开发者列表
  40. /// <summary>
  41. /// 开发者列表
  42. /// </summary>
  43. /// <returns></returns>
  44. public JsonResult IndexData(Developers data, string UserIdRealName, string UserIdMobile, int page = 1, int limit = 30)
  45. {
  46. Dictionary<string, string> Fields = new Dictionary<string, string>();
  47. Fields.Add("NickName", "1"); //昵称
  48. Fields.Add("CreateDate", "3"); //时间
  49. Fields.Add("RealName", "1"); //真实姓名
  50. Fields.Add("Mobile", "1"); //手机号
  51. string condition = " and Status>-1";
  52. //所属用户真实姓名
  53. if (!string.IsNullOrEmpty(UserIdRealName))
  54. {
  55. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  56. }
  57. //所属用户手机号
  58. if (!string.IsNullOrEmpty(UserIdMobile))
  59. {
  60. condition += " and UserId in (select UserId from UsersForMobile where Mobile='" + UserIdMobile + "')";
  61. }
  62. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).IndexData("Developers", Fields, "Id desc", "0", page, limit, condition);
  63. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  64. foreach (Dictionary<string, object> dic in diclist)
  65. {
  66. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  67. //所属用户
  68. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  69. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  70. dic["UserIdRealName"] = userid_Users.RealName;
  71. dic["UserIdMobile"] = userid_Users.Mobile;
  72. dic.Remove("UserId");
  73. }
  74. return Json(obj);
  75. }
  76. #endregion
  77. #region 增加开发者
  78. /// <summary>
  79. /// 增加或修改开发者信息
  80. /// </summary>
  81. /// <returns></returns>
  82. public IActionResult Add(string right)
  83. {
  84. ViewBag.RightInfo = RightInfo;
  85. ViewBag.right = right;
  86. return View();
  87. }
  88. #endregion
  89. #region 增加开发者
  90. /// <summary>
  91. /// 增加或修改开发者信息
  92. /// </summary>
  93. /// <returns></returns>
  94. [HttpPost]
  95. public string Add(Developers data)
  96. {
  97. Dictionary<string, object> Fields = new Dictionary<string, object>();
  98. Fields.Add("NickName", data.NickName); //昵称
  99. Fields.Add("RealName", data.RealName); //真实姓名
  100. Fields.Add("Mobile", data.Mobile); //手机号
  101. Fields.Add("UserId", data.UserId); //所属用户
  102. Fields.Add("SeoTitle", data.SeoTitle);
  103. Fields.Add("SeoKeyword", data.SeoKeyword);
  104. Fields.Add("SeoDescription", data.SeoDescription);
  105. int Id = new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Add("Developers", Fields, 0);
  106. AddSysLog(data.Id.ToString(), "Developers", "add");
  107. db.SaveChanges();
  108. return "success";
  109. }
  110. #endregion
  111. #region 修改开发者
  112. /// <summary>
  113. /// 增加或修改开发者信息
  114. /// </summary>
  115. /// <returns></returns>
  116. public IActionResult Edit(string right, int Id = 0)
  117. {
  118. ViewBag.RightInfo = RightInfo;
  119. ViewBag.right = right;
  120. Developers editData = db.Developers.FirstOrDefault(m => m.Id == Id) ?? new Developers();
  121. ViewBag.data = editData;
  122. return View();
  123. }
  124. #endregion
  125. #region 修改开发者
  126. /// <summary>
  127. /// 增加或修改开发者信息
  128. /// </summary>
  129. /// <returns></returns>
  130. [HttpPost]
  131. public string Edit(Developers data)
  132. {
  133. Dictionary<string, object> Fields = new Dictionary<string, object>();
  134. Fields.Add("NickName", data.NickName); //昵称
  135. Fields.Add("RealName", data.RealName); //真实姓名
  136. Fields.Add("Mobile", data.Mobile); //手机号
  137. Fields.Add("UserId", data.UserId); //所属用户
  138. Fields.Add("SeoTitle", data.SeoTitle);
  139. Fields.Add("SeoKeyword", data.SeoKeyword);
  140. Fields.Add("SeoDescription", data.SeoDescription);
  141. new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("Developers", Fields, data.Id);
  142. AddSysLog(data.Id.ToString(),"Developers","update");
  143. db.SaveChanges();
  144. return "success";
  145. }
  146. #endregion
  147. #region 删除开发者信息
  148. /// <summary>
  149. /// 删除开发者信息
  150. /// </summary>
  151. /// <returns></returns>
  152. public string Delete(string Id)
  153. {
  154. string[] idlist = Id.Split(new char[] { ',' });
  155. AddSysLog(Id,"Developers","del");
  156. foreach (string subid in idlist)
  157. {
  158. int id = int.Parse(subid);
  159. Dictionary<string, object> Fields = new Dictionary<string, object>();
  160. Fields.Add("Status", -1);
  161. new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("Developers", Fields, id);
  162. }
  163. db.SaveChanges();
  164. return "success";
  165. }
  166. #endregion
  167. #region 开启
  168. /// <summary>
  169. /// 开启
  170. /// </summary>
  171. /// <returns></returns>
  172. public string Open(string Id)
  173. {
  174. string[] idlist = Id.Split(new char[] { ',' });
  175. AddSysLog(Id,"Developers","open");
  176. foreach (string subid in idlist)
  177. {
  178. int id = int.Parse(subid);
  179. Dictionary<string, object> Fields = new Dictionary<string, object>();
  180. Fields.Add("Status", 1);
  181. new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("Developers", Fields, id);
  182. }
  183. db.SaveChanges();
  184. return "success";
  185. }
  186. #endregion
  187. #region 关闭
  188. /// <summary>
  189. /// 关闭
  190. /// </summary>
  191. /// <returns></returns>
  192. public string Close(string Id)
  193. {
  194. string[] idlist = Id.Split(new char[] { ',' });
  195. AddSysLog(Id,"Developers","close");
  196. foreach (string subid in idlist)
  197. {
  198. int id = int.Parse(subid);
  199. Dictionary<string, object> Fields = new Dictionary<string, object>();
  200. Fields.Add("Status", 0);
  201. new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("Developers", Fields, id);
  202. }
  203. db.SaveChanges();
  204. return "success";
  205. }
  206. #endregion
  207. #region 排序
  208. /// <summary>
  209. /// 排序
  210. /// </summary>
  211. /// <param name="Id"></param>
  212. public string Sort(int Id, int Sort)
  213. {
  214. new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Sort("Developers", Sort, Id);
  215. AddSysLog(Id.ToString(), "Developers", "sort");
  216. return "success";
  217. }
  218. #endregion
  219. #region 导入数据
  220. /// <summary>
  221. /// 导入数据
  222. /// </summary>
  223. /// <param name="ExcelData"></param>
  224. public string Import(string ExcelData)
  225. {
  226. ExcelData = HttpUtility.UrlDecode(ExcelData);
  227. JsonData list = JsonMapper.ToObject(ExcelData);
  228. for (int i = 1; i < list.Count;i++ )
  229. {
  230. JsonData dr = list[i];
  231. db.Developers.Add(new Developers()
  232. {
  233. CreateDate = DateTime.Now,
  234. UpdateDate = DateTime.Now,
  235. });
  236. db.SaveChanges();
  237. }
  238. AddSysLog("0", "Developers", "Import");
  239. return "success";
  240. }
  241. #endregion
  242. #region 导出Excel
  243. /// <summary>
  244. /// 导出Excel
  245. /// </summary>
  246. /// <returns></returns>
  247. public JsonResult ExportExcel(Developers data, string UserIdRealName, string UserIdMobile)
  248. {
  249. Dictionary<string, string> Fields = new Dictionary<string, string>();
  250. Fields.Add("NickName", "1"); //昵称
  251. Fields.Add("CreateDate", "3"); //时间
  252. Fields.Add("RealName", "1"); //真实姓名
  253. Fields.Add("Mobile", "1"); //手机号
  254. string condition = " and Status>-1";
  255. //所属用户真实姓名
  256. if (!string.IsNullOrEmpty(UserIdRealName))
  257. {
  258. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  259. }
  260. //所属用户手机号
  261. if (!string.IsNullOrEmpty(UserIdMobile))
  262. {
  263. condition += " and UserId in (select UserId from UsersForMobile where Mobile='" + UserIdMobile + "')";
  264. }
  265. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).IndexData("Developers", Fields, "Id desc", "0", 1, 20000, condition, "", false);
  266. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  267. foreach (Dictionary<string, object> dic in diclist)
  268. {
  269. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  270. //所属用户
  271. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  272. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  273. dic["UserIdRealName"] = userid_Users.RealName;
  274. dic["UserIdMobile"] = userid_Users.Mobile;
  275. dic.Remove("UserId");
  276. }
  277. Dictionary<string, object> result = new Dictionary<string, object>();
  278. result.Add("Status", "1");
  279. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  280. result.Add("Obj", diclist);
  281. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  282. result.Add("Fields", ReturnFields);
  283. AddSysLog("0", "Developers", "ExportExcel");
  284. return Json(result);
  285. }
  286. #endregion
  287. }
  288. }