HelpProfitExchangeController.cs 12 KB

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