ProjectVersionController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 MySystem;
  18. using MySystemLib;
  19. namespace MySystem.Areas.Admin.Controllers
  20. {
  21. [Area("Admin")]
  22. [Route("Admin/[controller]/[action]")]
  23. public class ProjectVersionController : BaseController
  24. {
  25. public ProjectVersionController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  26. {
  27. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  28. }
  29. #region 小程序版本列表
  30. /// <summary>
  31. /// 根据条件查询小程序版本列表
  32. /// </summary>
  33. /// <returns></returns>
  34. public IActionResult Index(ProjectVersion data, string right)
  35. {
  36. ViewBag.RightInfo = RightInfo;
  37. ViewBag.right = right;
  38. return View();
  39. }
  40. #endregion
  41. #region 根据条件查询小程序版本列表
  42. /// <summary>
  43. /// 小程序版本列表
  44. /// </summary>
  45. /// <returns></returns>
  46. public JsonResult IndexData(ProjectVersion data, string ProjectIdSelect, string UserIdRealName, string UserIdMobile, string DeveloperIdNickName, string DeveloperIdRealName, string DeveloperIdMobile, int page = 1, int limit = 30)
  47. {
  48. Dictionary<string, string> Fields = new Dictionary<string, string>();
  49. Fields.Add("CreateDate", "3"); //时间
  50. string condition = " and Status>-1";
  51. //小程序项目
  52. if (!string.IsNullOrEmpty(ProjectIdSelect))
  53. {
  54. condition += " and ProjectId=" + ProjectIdSelect;
  55. }
  56. //所属用户真实姓名
  57. if (!string.IsNullOrEmpty(UserIdRealName))
  58. {
  59. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  60. }
  61. //所属用户手机号
  62. if (!string.IsNullOrEmpty(UserIdMobile))
  63. {
  64. condition += " and UserId in (select UserId from UsersForMobile where Mobile='" + UserIdMobile + "')";
  65. }
  66. //开发者昵称
  67. if (!string.IsNullOrEmpty(DeveloperIdNickName))
  68. {
  69. condition += " and DeveloperId in (select DeveloperId from DevelopersForNickName where NickName='" + DeveloperIdNickName + "')";
  70. }
  71. //开发者真实姓名
  72. if (!string.IsNullOrEmpty(DeveloperIdRealName))
  73. {
  74. condition += " and DeveloperId in (select DeveloperId from DevelopersForRealName where RealName='" + DeveloperIdRealName + "')";
  75. }
  76. //开发者手机号
  77. if (!string.IsNullOrEmpty(DeveloperIdMobile))
  78. {
  79. condition += " and DeveloperId in (select DeveloperId from DevelopersForMobile where Mobile='" + DeveloperIdMobile + "')";
  80. }
  81. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ProjectVersion", Fields, "Id desc", "0", page, limit, condition);
  82. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  83. foreach (Dictionary<string, object> dic in diclist)
  84. {
  85. //小程序项目
  86. // dic["ProjectId"] = RelationClass.GetProjectsInfo(int.Parse(dic["ProjectId"].ToString()));
  87. //所属用户
  88. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  89. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  90. dic["UserIdRealName"] = userid_Users.RealName;
  91. dic["UserIdMobile"] = userid_Users.Mobile;
  92. dic.Remove("UserId");
  93. //开发者
  94. int DeveloperId = int.Parse(function.CheckInt(dic["DeveloperId"].ToString()));
  95. Developers developerid_Developers = db.Developers.FirstOrDefault(m => m.Id == DeveloperId) ?? new Developers();
  96. dic["DeveloperIdNickName"] = developerid_Developers.NickName;
  97. dic["DeveloperIdRealName"] = developerid_Developers.RealName;
  98. dic["DeveloperIdMobile"] = developerid_Developers.Mobile;
  99. dic.Remove("DeveloperId");
  100. }
  101. return Json(obj);
  102. }
  103. #endregion
  104. #region 增加小程序版本
  105. /// <summary>
  106. /// 增加或修改小程序版本信息
  107. /// </summary>
  108. /// <returns></returns>
  109. public IActionResult Add(string right)
  110. {
  111. ViewBag.RightInfo = RightInfo;
  112. ViewBag.right = right;
  113. return View();
  114. }
  115. #endregion
  116. #region 增加小程序版本
  117. /// <summary>
  118. /// 增加或修改小程序版本信息
  119. /// </summary>
  120. /// <returns></returns>
  121. [HttpPost]
  122. public string Add(ProjectVersion data)
  123. {
  124. Dictionary<string, object> Fields = new Dictionary<string, object>();
  125. Fields.Add("ProjectId", data.ProjectId); //小程序项目
  126. Fields.Add("UserId", data.UserId); //所属用户
  127. Fields.Add("DeveloperId", data.DeveloperId); //开发者
  128. Fields.Add("VerNum", data.VerNum); //版本号
  129. Fields.Add("UpdateNote", data.UpdateNote); //更新说明
  130. Fields.Add("ReturnNote", data.ReturnNote); //反馈意见
  131. Fields.Add("FilePath", data.FilePath); //模板文件路径
  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("ProjectVersion", Fields, 0);
  136. AddSysLog(data.Id.ToString(), "ProjectVersion", "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. ProjectVersion editData = db.ProjectVersion.FirstOrDefault(m => m.Id == Id) ?? new ProjectVersion();
  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(ProjectVersion data)
  162. {
  163. Dictionary<string, object> Fields = new Dictionary<string, object>();
  164. Fields.Add("ProjectId", data.ProjectId); //小程序项目
  165. Fields.Add("UserId", data.UserId); //所属用户
  166. Fields.Add("DeveloperId", data.DeveloperId); //开发者
  167. Fields.Add("VerNum", data.VerNum); //版本号
  168. Fields.Add("UpdateNote", data.UpdateNote); //更新说明
  169. Fields.Add("ReturnNote", data.ReturnNote); //反馈意见
  170. Fields.Add("FilePath", data.FilePath); //模板文件路径
  171. Fields.Add("SeoTitle", data.SeoTitle);
  172. Fields.Add("SeoKeyword", data.SeoKeyword);
  173. Fields.Add("SeoDescription", data.SeoDescription);
  174. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProjectVersion", Fields, data.Id);
  175. AddSysLog(data.Id.ToString(), "ProjectVersion", "update");
  176. db.SaveChanges();
  177. return "success";
  178. }
  179. #endregion
  180. #region 删除小程序版本信息
  181. /// <summary>
  182. /// 删除小程序版本信息
  183. /// </summary>
  184. /// <returns></returns>
  185. public string Delete(string Id)
  186. {
  187. string[] idlist = Id.Split(new char[] { ',' });
  188. AddSysLog(Id, "ProjectVersion", "del");
  189. foreach (string subid in idlist)
  190. {
  191. int id = int.Parse(subid);
  192. Dictionary<string, object> Fields = new Dictionary<string, object>();
  193. Fields.Add("Status", -1);
  194. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProjectVersion", Fields, id);
  195. }
  196. db.SaveChanges();
  197. return "success";
  198. }
  199. #endregion
  200. #region 开启
  201. /// <summary>
  202. /// 开启
  203. /// </summary>
  204. /// <returns></returns>
  205. public string Open(string Id)
  206. {
  207. string[] idlist = Id.Split(new char[] { ',' });
  208. AddSysLog(Id, "ProjectVersion", "open");
  209. foreach (string subid in idlist)
  210. {
  211. int id = int.Parse(subid);
  212. Dictionary<string, object> Fields = new Dictionary<string, object>();
  213. Fields.Add("Status", 1);
  214. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProjectVersion", Fields, id);
  215. }
  216. db.SaveChanges();
  217. return "success";
  218. }
  219. #endregion
  220. #region 关闭
  221. /// <summary>
  222. /// 关闭
  223. /// </summary>
  224. /// <returns></returns>
  225. public string Close(string Id)
  226. {
  227. string[] idlist = Id.Split(new char[] { ',' });
  228. AddSysLog(Id, "ProjectVersion", "close");
  229. foreach (string subid in idlist)
  230. {
  231. int id = int.Parse(subid);
  232. Dictionary<string, object> Fields = new Dictionary<string, object>();
  233. Fields.Add("Status", 0);
  234. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProjectVersion", Fields, id);
  235. }
  236. db.SaveChanges();
  237. return "success";
  238. }
  239. #endregion
  240. #region 排序
  241. /// <summary>
  242. /// 排序
  243. /// </summary>
  244. /// <param name="Id"></param>
  245. public string Sort(int Id, int Sort)
  246. {
  247. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("ProjectVersion", Sort, Id);
  248. AddSysLog(Id.ToString(), "ProjectVersion", "sort");
  249. return "success";
  250. }
  251. #endregion
  252. #region 导入数据
  253. /// <summary>
  254. /// 导入数据
  255. /// </summary>
  256. /// <param name="ExcelData"></param>
  257. public string Import(string ExcelData)
  258. {
  259. ExcelData = HttpUtility.UrlDecode(ExcelData);
  260. JsonData list = JsonMapper.ToObject(ExcelData);
  261. for (int i = 1; i < list.Count; i++)
  262. {
  263. JsonData dr = list[i];
  264. db.ProjectVersion.Add(new ProjectVersion()
  265. {
  266. CreateDate = DateTime.Now,
  267. UpdateDate = DateTime.Now,
  268. });
  269. db.SaveChanges();
  270. }
  271. AddSysLog("0", "ProjectVersion", "Import");
  272. return "success";
  273. }
  274. #endregion
  275. #region 导出Excel
  276. /// <summary>
  277. /// 导出Excel
  278. /// </summary>
  279. /// <returns></returns>
  280. public JsonResult ExportExcel(ProjectVersion data, string ProjectIdSelect, string UserIdRealName, string UserIdMobile, string DeveloperIdNickName, string DeveloperIdRealName, string DeveloperIdMobile)
  281. {
  282. Dictionary<string, string> Fields = new Dictionary<string, string>();
  283. Fields.Add("CreateDate", "3"); //时间
  284. string condition = " and Status>-1";
  285. //小程序项目
  286. if (!string.IsNullOrEmpty(ProjectIdSelect))
  287. {
  288. condition += " and ProjectId=" + ProjectIdSelect;
  289. }
  290. //所属用户真实姓名
  291. if (!string.IsNullOrEmpty(UserIdRealName))
  292. {
  293. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  294. }
  295. //所属用户手机号
  296. if (!string.IsNullOrEmpty(UserIdMobile))
  297. {
  298. condition += " and UserId in (select UserId from UsersForMobile where Mobile='" + UserIdMobile + "')";
  299. }
  300. //开发者昵称
  301. if (!string.IsNullOrEmpty(DeveloperIdNickName))
  302. {
  303. condition += " and DeveloperId in (select DeveloperId from DevelopersForNickName where NickName='" + DeveloperIdNickName + "')";
  304. }
  305. //开发者真实姓名
  306. if (!string.IsNullOrEmpty(DeveloperIdRealName))
  307. {
  308. condition += " and DeveloperId in (select DeveloperId from DevelopersForRealName where RealName='" + DeveloperIdRealName + "')";
  309. }
  310. //开发者手机号
  311. if (!string.IsNullOrEmpty(DeveloperIdMobile))
  312. {
  313. condition += " and DeveloperId in (select DeveloperId from DevelopersForMobile where Mobile='" + DeveloperIdMobile + "')";
  314. }
  315. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ProjectVersion", Fields, "Id desc", "0", 1, 20000, condition, "", false);
  316. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  317. foreach (Dictionary<string, object> dic in diclist)
  318. {
  319. //小程序项目
  320. // dic["ProjectId"] = RelationClass.GetProjectsInfo(int.Parse(dic["ProjectId"].ToString()));
  321. //所属用户
  322. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  323. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  324. dic["UserIdRealName"] = userid_Users.RealName;
  325. dic["UserIdMobile"] = userid_Users.Mobile;
  326. dic.Remove("UserId");
  327. //开发者
  328. int DeveloperId = int.Parse(function.CheckInt(dic["DeveloperId"].ToString()));
  329. Developers developerid_Developers = db.Developers.FirstOrDefault(m => m.Id == DeveloperId) ?? new Developers();
  330. dic["DeveloperIdNickName"] = developerid_Developers.NickName;
  331. dic["DeveloperIdRealName"] = developerid_Developers.RealName;
  332. dic["DeveloperIdMobile"] = developerid_Developers.Mobile;
  333. dic.Remove("DeveloperId");
  334. }
  335. Dictionary<string, object> result = new Dictionary<string, object>();
  336. result.Add("Status", "1");
  337. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  338. result.Add("Obj", diclist);
  339. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  340. result.Add("Fields", ReturnFields);
  341. AddSysLog("0", "ProjectVersion", "ExportExcel");
  342. return Json(result);
  343. }
  344. #endregion
  345. }
  346. }