ProjectVersionController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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 ProjectVersionController : BaseController
  23. {
  24. public ProjectVersionController(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(ProjectVersion 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(ProjectVersion data, string ProjectIdSelect, string UserIdRealName, string UserIdMobile, string DeveloperIdNickName, string DeveloperIdRealName, string DeveloperIdMobile, int page = 1, int limit = 30)
  45. {
  46. Dictionary<string, string> Fields = new Dictionary<string, string>();
  47. Fields.Add("CreateDate", "3"); //时间
  48. string condition = " and Status>-1";
  49. //小程序项目
  50. if (!string.IsNullOrEmpty(ProjectIdSelect))
  51. {
  52. condition += " and ProjectId=" + ProjectIdSelect;
  53. }
  54. //所属用户真实姓名
  55. if (!string.IsNullOrEmpty(UserIdRealName))
  56. {
  57. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  58. }
  59. //所属用户手机号
  60. if (!string.IsNullOrEmpty(UserIdMobile))
  61. {
  62. condition += " and UserId in (select UserId from UsersForMobile where Mobile='" + UserIdMobile + "')";
  63. }
  64. //开发者昵称
  65. if (!string.IsNullOrEmpty(DeveloperIdNickName))
  66. {
  67. condition += " and DeveloperId in (select DeveloperId from DevelopersForNickName where NickName='" + DeveloperIdNickName + "')";
  68. }
  69. //开发者真实姓名
  70. if (!string.IsNullOrEmpty(DeveloperIdRealName))
  71. {
  72. condition += " and DeveloperId in (select DeveloperId from DevelopersForRealName where RealName='" + DeveloperIdRealName + "')";
  73. }
  74. //开发者手机号
  75. if (!string.IsNullOrEmpty(DeveloperIdMobile))
  76. {
  77. condition += " and DeveloperId in (select DeveloperId from DevelopersForMobile where Mobile='" + DeveloperIdMobile + "')";
  78. }
  79. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).IndexData("ProjectVersion", 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. // dic["ProjectId"] = RelationClass.GetProjectsInfo(int.Parse(dic["ProjectId"].ToString()));
  85. //所属用户
  86. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  87. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  88. dic["UserIdRealName"] = userid_Users.RealName;
  89. dic["UserIdMobile"] = userid_Users.Mobile;
  90. dic.Remove("UserId");
  91. //开发者
  92. int DeveloperId = int.Parse(function.CheckInt(dic["DeveloperId"].ToString()));
  93. Developers developerid_Developers = db.Developers.FirstOrDefault(m => m.Id == DeveloperId) ?? new Developers();
  94. dic["DeveloperIdNickName"] = developerid_Developers.NickName;
  95. dic["DeveloperIdRealName"] = developerid_Developers.RealName;
  96. dic["DeveloperIdMobile"] = developerid_Developers.Mobile;
  97. dic.Remove("DeveloperId");
  98. }
  99. return Json(obj);
  100. }
  101. #endregion
  102. #region 增加小程序版本
  103. /// <summary>
  104. /// 增加或修改小程序版本信息
  105. /// </summary>
  106. /// <returns></returns>
  107. public IActionResult Add(string right)
  108. {
  109. ViewBag.RightInfo = RightInfo;
  110. ViewBag.right = right;
  111. return View();
  112. }
  113. #endregion
  114. #region 增加小程序版本
  115. /// <summary>
  116. /// 增加或修改小程序版本信息
  117. /// </summary>
  118. /// <returns></returns>
  119. [HttpPost]
  120. public string Add(ProjectVersion data)
  121. {
  122. Dictionary<string, object> Fields = new Dictionary<string, object>();
  123. Fields.Add("ProjectId", data.ProjectId); //小程序项目
  124. Fields.Add("UserId", data.UserId); //所属用户
  125. Fields.Add("DeveloperId", data.DeveloperId); //开发者
  126. Fields.Add("VerNum", data.VerNum); //版本号
  127. Fields.Add("UpdateNote", data.UpdateNote); //更新说明
  128. Fields.Add("ReturnNote", data.ReturnNote); //反馈意见
  129. Fields.Add("FilePath", data.FilePath); //模板文件路径
  130. Fields.Add("SeoTitle", data.SeoTitle);
  131. Fields.Add("SeoKeyword", data.SeoKeyword);
  132. Fields.Add("SeoDescription", data.SeoDescription);
  133. int Id = new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Add("ProjectVersion", Fields, 0);
  134. AddSysLog(data.Id.ToString(), "ProjectVersion", "add");
  135. db.SaveChanges();
  136. return "success";
  137. }
  138. #endregion
  139. #region 修改小程序版本
  140. /// <summary>
  141. /// 增加或修改小程序版本信息
  142. /// </summary>
  143. /// <returns></returns>
  144. public IActionResult Edit(string right, int Id = 0)
  145. {
  146. ViewBag.RightInfo = RightInfo;
  147. ViewBag.right = right;
  148. ProjectVersion editData = db.ProjectVersion.FirstOrDefault(m => m.Id == Id) ?? new ProjectVersion();
  149. ViewBag.data = editData;
  150. return View();
  151. }
  152. #endregion
  153. #region 修改小程序版本
  154. /// <summary>
  155. /// 增加或修改小程序版本信息
  156. /// </summary>
  157. /// <returns></returns>
  158. [HttpPost]
  159. public string Edit(ProjectVersion data)
  160. {
  161. Dictionary<string, object> Fields = new Dictionary<string, object>();
  162. Fields.Add("ProjectId", data.ProjectId); //小程序项目
  163. Fields.Add("UserId", data.UserId); //所属用户
  164. Fields.Add("DeveloperId", data.DeveloperId); //开发者
  165. Fields.Add("VerNum", data.VerNum); //版本号
  166. Fields.Add("UpdateNote", data.UpdateNote); //更新说明
  167. Fields.Add("ReturnNote", data.ReturnNote); //反馈意见
  168. Fields.Add("FilePath", data.FilePath); //模板文件路径
  169. Fields.Add("SeoTitle", data.SeoTitle);
  170. Fields.Add("SeoKeyword", data.SeoKeyword);
  171. Fields.Add("SeoDescription", data.SeoDescription);
  172. new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("ProjectVersion", Fields, data.Id);
  173. AddSysLog(data.Id.ToString(),"ProjectVersion","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,"ProjectVersion","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 AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("ProjectVersion", 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,"ProjectVersion","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 AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("ProjectVersion", 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,"ProjectVersion","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 AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Edit("ProjectVersion", 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 AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).Sort("ProjectVersion", Sort, Id);
  246. AddSysLog(Id.ToString(), "ProjectVersion", "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.ProjectVersion.Add(new ProjectVersion()
  263. {
  264. CreateDate = DateTime.Now,
  265. UpdateDate = DateTime.Now,
  266. });
  267. db.SaveChanges();
  268. }
  269. AddSysLog("0", "ProjectVersion", "Import");
  270. return "success";
  271. }
  272. #endregion
  273. #region 导出Excel
  274. /// <summary>
  275. /// 导出Excel
  276. /// </summary>
  277. /// <returns></returns>
  278. public JsonResult ExportExcel(ProjectVersion data, string ProjectIdSelect, string UserIdRealName, string UserIdMobile, string DeveloperIdNickName, string DeveloperIdRealName, string DeveloperIdMobile)
  279. {
  280. Dictionary<string, string> Fields = new Dictionary<string, string>();
  281. Fields.Add("CreateDate", "3"); //时间
  282. string condition = " and Status>-1";
  283. //小程序项目
  284. if (!string.IsNullOrEmpty(ProjectIdSelect))
  285. {
  286. condition += " and ProjectId=" + ProjectIdSelect;
  287. }
  288. //所属用户真实姓名
  289. if (!string.IsNullOrEmpty(UserIdRealName))
  290. {
  291. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  292. }
  293. //所属用户手机号
  294. if (!string.IsNullOrEmpty(UserIdMobile))
  295. {
  296. condition += " and UserId in (select UserId from UsersForMobile where Mobile='" + UserIdMobile + "')";
  297. }
  298. //开发者昵称
  299. if (!string.IsNullOrEmpty(DeveloperIdNickName))
  300. {
  301. condition += " and DeveloperId in (select DeveloperId from DevelopersForNickName where NickName='" + DeveloperIdNickName + "')";
  302. }
  303. //开发者真实姓名
  304. if (!string.IsNullOrEmpty(DeveloperIdRealName))
  305. {
  306. condition += " and DeveloperId in (select DeveloperId from DevelopersForRealName where RealName='" + DeveloperIdRealName + "')";
  307. }
  308. //开发者手机号
  309. if (!string.IsNullOrEmpty(DeveloperIdMobile))
  310. {
  311. condition += " and DeveloperId in (select DeveloperId from DevelopersForMobile where Mobile='" + DeveloperIdMobile + "')";
  312. }
  313. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, SystemPublicFuction.dbtables).IndexData("ProjectVersion", Fields, "Id desc", "0", 1, 20000, condition, "", false);
  314. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  315. foreach (Dictionary<string, object> dic in diclist)
  316. {
  317. //小程序项目
  318. // dic["ProjectId"] = RelationClass.GetProjectsInfo(int.Parse(dic["ProjectId"].ToString()));
  319. //所属用户
  320. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  321. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  322. dic["UserIdRealName"] = userid_Users.RealName;
  323. dic["UserIdMobile"] = userid_Users.Mobile;
  324. dic.Remove("UserId");
  325. //开发者
  326. int DeveloperId = int.Parse(function.CheckInt(dic["DeveloperId"].ToString()));
  327. Developers developerid_Developers = db.Developers.FirstOrDefault(m => m.Id == DeveloperId) ?? new Developers();
  328. dic["DeveloperIdNickName"] = developerid_Developers.NickName;
  329. dic["DeveloperIdRealName"] = developerid_Developers.RealName;
  330. dic["DeveloperIdMobile"] = developerid_Developers.Mobile;
  331. dic.Remove("DeveloperId");
  332. }
  333. Dictionary<string, object> result = new Dictionary<string, object>();
  334. result.Add("Status", "1");
  335. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  336. result.Add("Obj", diclist);
  337. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  338. result.Add("Fields", ReturnFields);
  339. AddSysLog("0", "ProjectVersion", "ExportExcel");
  340. return Json(result);
  341. }
  342. #endregion
  343. }
  344. }