ProjectVersionController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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("VersionNo", data.VersionNo);
  169. // Fields.Add("UpdateNote", data.UpdateNote); //更新说明
  170. // Fields.Add("ReturnNote", data.ReturnNote); //反馈意见
  171. Fields.Add("FilePath", data.FilePath); //模板文件路径
  172. Fields.Add("SeoTitle", data.SeoTitle);
  173. Fields.Add("SeoKeyword", data.SeoKeyword);
  174. Fields.Add("SeoDescription", data.SeoDescription);
  175. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProjectVersion", Fields, data.Id);
  176. AddSysLog(data.Id.ToString(), "ProjectVersion", "update");
  177. db.SaveChanges();
  178. return "success";
  179. }
  180. #endregion
  181. #region 删除小程序版本信息
  182. /// <summary>
  183. /// 删除小程序版本信息
  184. /// </summary>
  185. /// <returns></returns>
  186. public string Delete(string Id)
  187. {
  188. string[] idlist = Id.Split(new char[] { ',' });
  189. AddSysLog(Id, "ProjectVersion", "del");
  190. foreach (string subid in idlist)
  191. {
  192. int id = int.Parse(subid);
  193. Dictionary<string, object> Fields = new Dictionary<string, object>();
  194. Fields.Add("Status", -1);
  195. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProjectVersion", Fields, id);
  196. }
  197. db.SaveChanges();
  198. return "success";
  199. }
  200. #endregion
  201. #region 开启
  202. /// <summary>
  203. /// 开启
  204. /// </summary>
  205. /// <returns></returns>
  206. public string Open(string Id)
  207. {
  208. string[] idlist = Id.Split(new char[] { ',' });
  209. AddSysLog(Id, "ProjectVersion", "open");
  210. foreach (string subid in idlist)
  211. {
  212. int id = int.Parse(subid);
  213. Dictionary<string, object> Fields = new Dictionary<string, object>();
  214. Fields.Add("Status", 1);
  215. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProjectVersion", Fields, id);
  216. }
  217. db.SaveChanges();
  218. return "success";
  219. }
  220. #endregion
  221. #region 关闭
  222. /// <summary>
  223. /// 关闭
  224. /// </summary>
  225. /// <returns></returns>
  226. public string Close(string Id)
  227. {
  228. string[] idlist = Id.Split(new char[] { ',' });
  229. AddSysLog(Id, "ProjectVersion", "close");
  230. foreach (string subid in idlist)
  231. {
  232. int id = int.Parse(subid);
  233. Dictionary<string, object> Fields = new Dictionary<string, object>();
  234. Fields.Add("Status", 0);
  235. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProjectVersion", Fields, id);
  236. }
  237. db.SaveChanges();
  238. return "success";
  239. }
  240. #endregion
  241. #region 排序
  242. /// <summary>
  243. /// 排序
  244. /// </summary>
  245. /// <param name="Id"></param>
  246. public string Sort(int Id, int Sort)
  247. {
  248. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("ProjectVersion", Sort, Id);
  249. AddSysLog(Id.ToString(), "ProjectVersion", "sort");
  250. return "success";
  251. }
  252. #endregion
  253. #region 导入数据
  254. /// <summary>
  255. /// 导入数据
  256. /// </summary>
  257. /// <param name="ExcelData"></param>
  258. public string Import(string ExcelData)
  259. {
  260. ExcelData = HttpUtility.UrlDecode(ExcelData);
  261. JsonData list = JsonMapper.ToObject(ExcelData);
  262. for (int i = 1; i < list.Count; i++)
  263. {
  264. JsonData dr = list[i];
  265. db.ProjectVersion.Add(new ProjectVersion()
  266. {
  267. CreateDate = DateTime.Now,
  268. UpdateDate = DateTime.Now,
  269. });
  270. db.SaveChanges();
  271. }
  272. AddSysLog("0", "ProjectVersion", "Import");
  273. return "success";
  274. }
  275. #endregion
  276. #region 导出Excel
  277. /// <summary>
  278. /// 导出Excel
  279. /// </summary>
  280. /// <returns></returns>
  281. public JsonResult ExportExcel(ProjectVersion data, string ProjectIdSelect, string UserIdRealName, string UserIdMobile, string DeveloperIdNickName, string DeveloperIdRealName, string DeveloperIdMobile)
  282. {
  283. Dictionary<string, string> Fields = new Dictionary<string, string>();
  284. Fields.Add("CreateDate", "3"); //时间
  285. string condition = " and Status>-1";
  286. //小程序项目
  287. if (!string.IsNullOrEmpty(ProjectIdSelect))
  288. {
  289. condition += " and ProjectId=" + ProjectIdSelect;
  290. }
  291. //所属用户真实姓名
  292. if (!string.IsNullOrEmpty(UserIdRealName))
  293. {
  294. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  295. }
  296. //所属用户手机号
  297. if (!string.IsNullOrEmpty(UserIdMobile))
  298. {
  299. condition += " and UserId in (select UserId from UsersForMobile where Mobile='" + UserIdMobile + "')";
  300. }
  301. //开发者昵称
  302. if (!string.IsNullOrEmpty(DeveloperIdNickName))
  303. {
  304. condition += " and DeveloperId in (select DeveloperId from DevelopersForNickName where NickName='" + DeveloperIdNickName + "')";
  305. }
  306. //开发者真实姓名
  307. if (!string.IsNullOrEmpty(DeveloperIdRealName))
  308. {
  309. condition += " and DeveloperId in (select DeveloperId from DevelopersForRealName where RealName='" + DeveloperIdRealName + "')";
  310. }
  311. //开发者手机号
  312. if (!string.IsNullOrEmpty(DeveloperIdMobile))
  313. {
  314. condition += " and DeveloperId in (select DeveloperId from DevelopersForMobile where Mobile='" + DeveloperIdMobile + "')";
  315. }
  316. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ProjectVersion", Fields, "Id desc", "0", 1, 20000, condition, "", false);
  317. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  318. foreach (Dictionary<string, object> dic in diclist)
  319. {
  320. //小程序项目
  321. // dic["ProjectId"] = RelationClass.GetProjectsInfo(int.Parse(dic["ProjectId"].ToString()));
  322. //所属用户
  323. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  324. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  325. dic["UserIdRealName"] = userid_Users.RealName;
  326. dic["UserIdMobile"] = userid_Users.Mobile;
  327. dic.Remove("UserId");
  328. //开发者
  329. int DeveloperId = int.Parse(function.CheckInt(dic["DeveloperId"].ToString()));
  330. Developers developerid_Developers = db.Developers.FirstOrDefault(m => m.Id == DeveloperId) ?? new Developers();
  331. dic["DeveloperIdNickName"] = developerid_Developers.NickName;
  332. dic["DeveloperIdRealName"] = developerid_Developers.RealName;
  333. dic["DeveloperIdMobile"] = developerid_Developers.Mobile;
  334. dic.Remove("DeveloperId");
  335. }
  336. Dictionary<string, object> result = new Dictionary<string, object>();
  337. result.Add("Status", "1");
  338. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  339. result.Add("Obj", diclist);
  340. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  341. result.Add("Fields", ReturnFields);
  342. AddSysLog("0", "ProjectVersion", "ExportExcel");
  343. return Json(result);
  344. }
  345. #endregion
  346. }
  347. }