HelpProfitExchangeController.cs 12 KB

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