HelpProfitExchangeController.cs 12 KB

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