HelpProfitExchangeDetailController.cs 13 KB

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