ProjectForDevelopController.cs 13 KB

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