LeaderReserveRecordController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 LeaderReserveRecordController : BaseController
  23. {
  24. public LeaderReserveRecordController(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(LeaderReserveRecord 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(LeaderReserveRecord data, string UserIdMakerCode, string SourceMakerCode, string RemarkSelect, string CreateDateData, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("SeoKeyword", "1"); //订单编号
  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(SourceMakerCode))
  57. {
  58. condition += " and SourceUserId in (select UserId from UserForMakerCode where MakerCode='" + SourceMakerCode + "')";
  59. }
  60. //变动类型
  61. if (!string.IsNullOrEmpty(RemarkSelect))
  62. {
  63. condition += " and Remark='" + RemarkSelect + "'";
  64. }
  65. //创建时间
  66. if (!string.IsNullOrEmpty(CreateDateData))
  67. {
  68. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  69. string start = datelist[0];
  70. string end = datelist[1];
  71. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  72. }
  73. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("LeaderReserveRecord", Fields, "Id desc", "0", page, limit, condition);
  74. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  75. foreach (Dictionary<string, object> dic in diclist)
  76. {
  77. //创客
  78. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  79. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  80. UserAccount userAccount = db.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount();
  81. dic["LeaderBalanceAmount"] = userAccount.LeaderBalanceAmount;
  82. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  83. dic["UserIdRealName"] = userid_Users.RealName;
  84. dic.Remove("UserId");
  85. //购券创客
  86. int SourceUserId = int.Parse(function.CheckInt(dic["SourceUserId"].ToString()));
  87. if (SourceUserId > 0)
  88. {
  89. Users sourceUser = db.Users.FirstOrDefault(m => m.Id == SourceUserId) ?? new Users();
  90. dic["SourceMakerCode"] = sourceUser.MakerCode;
  91. dic.Remove("SourceUserId");
  92. }
  93. // else
  94. // {
  95. // int OrderId = int.Parse(function.CheckInt(dic["OrderId"].ToString()));
  96. // var order = db.Orders.FirstOrDefault(m => m.Id == OrderId) ?? new Orders();
  97. // Users sourceUser = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  98. // dic["SourceMakerCode"] = sourceUser.MakerCode;
  99. // dic.Remove("OrderId");
  100. // }
  101. // //购券创客
  102. // int SourceUserId = int.Parse(function.CheckInt(dic["SourceUserId"].ToString()));
  103. // Users sourceUser = db.Users.FirstOrDefault(m => m.Id == SourceUserId) ?? new Users();
  104. // dic["SourceMakerCode"] = sourceUser.MakerCode;
  105. // dic.Remove("SourceUserId");
  106. // //订单来源创客
  107. // int OrderId = int.Parse(function.CheckInt(dic["OrderId"].ToString()));
  108. // var order = db.Orders.FirstOrDefault(m => m.Id == OrderId) ?? new Orders();
  109. // Users sourceOrderUser = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  110. // dic["SourceOrderMakerCode"] = sourceOrderUser.MakerCode;
  111. // dic.Remove("OrderId");
  112. //订单信息
  113. JsonData ApplyList = JsonMapper.ToObject(dic["SeoTitle"].ToString());//申请数据
  114. dic["dPosCoupons"] = "";
  115. dic["bPosCoupons"] = "";
  116. if (!string.IsNullOrEmpty(dic["SeoTitle"].ToString()))
  117. {
  118. for (int i = 0; i < ApplyList.Count; i++)
  119. {
  120. int num = Convert.ToInt32(ApplyList[i]["Num"].ToString());
  121. int type = Convert.ToInt32(ApplyList[i]["Type"].ToString());
  122. if (type == 1)
  123. {
  124. dic["dPosCoupons"] = num + "张";
  125. }
  126. else
  127. {
  128. dic["bPosCoupons"] = num + "张";
  129. }
  130. }
  131. }
  132. //券码
  133. int OrderId = int.Parse(function.CheckInt(dic["Id"].ToString()));
  134. if (OrderId >= 2300)
  135. {
  136. var info = db.UserSnDelayChange.Where(m => m.QueryCount == OrderId).ToList();
  137. var PosCoupons = "";
  138. foreach (var item in info)
  139. {
  140. PosCoupons += item.SnNo + ",";
  141. }
  142. dic["PosCoupons"] = PosCoupons;
  143. }
  144. else
  145. {
  146. dic["PosCoupons"] = dic["SeoDescription"].ToString();
  147. }
  148. }
  149. return Json(obj);
  150. }
  151. #endregion
  152. #region 快捷导出Excel
  153. public JsonResult QuickExportExcel(LeaderReserveRecord data, string UserIdMakerCode, string SourceMakerCode, string RemarkSelect, string CreateDateData, string SeoKeyword)
  154. {
  155. string SqlString = " and Status>-1";
  156. //创客编号
  157. if (!string.IsNullOrEmpty(UserIdMakerCode))
  158. {
  159. SqlString += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  160. }
  161. //购券创客
  162. if (!string.IsNullOrEmpty(SourceMakerCode))
  163. {
  164. SqlString += " and SourceUserId in (select UserId from UserForMakerCode where MakerCode='" + SourceMakerCode + "')";
  165. }
  166. //变动类型
  167. if (!string.IsNullOrEmpty(RemarkSelect))
  168. {
  169. SqlString += " and Remark='" + RemarkSelect + "'";
  170. }
  171. //创建时间
  172. if (!string.IsNullOrEmpty(CreateDateData))
  173. {
  174. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  175. string start = datelist[0];
  176. string end = datelist[1];
  177. SqlString += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  178. }
  179. //订单编号
  180. if (!string.IsNullOrEmpty(SeoKeyword))
  181. {
  182. SqlString += " and SeoKeyword=" + SeoKeyword;
  183. }
  184. // 创客姓名、创客编号、创建时间、变动类型、电签兑换券张数、大POS兑换券张数、可提现余额、使用前剩余额度、使用后剩余额度
  185. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
  186. var FileName = "盟主储蓄金变动记录";
  187. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + SqlString + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  188. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  189. return Json("result");
  190. }
  191. #endregion
  192. #region 导出Excel
  193. /// <summary>
  194. /// 导出Excel
  195. /// </summary>
  196. /// <returns></returns>
  197. public JsonResult ExportExcel(LeaderReserveRecord data, string UserIdMakerCode, string CreateDateData, string LeaderLevelSelect)
  198. {
  199. Dictionary<string, string> Fields = new Dictionary<string, string>();
  200. string condition = " and Status>-1";
  201. //创客创客编号
  202. if (!string.IsNullOrEmpty(UserIdMakerCode))
  203. {
  204. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  205. }
  206. //盟主等级
  207. if (!string.IsNullOrEmpty(LeaderLevelSelect))
  208. {
  209. condition += " and LeaderLevel=" + LeaderLevelSelect;
  210. }
  211. //创建时间
  212. if (!string.IsNullOrEmpty(CreateDateData))
  213. {
  214. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  215. string start = datelist[0];
  216. string end = datelist[1];
  217. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  218. }
  219. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Leaders", Fields, "Id desc", "0", 1, 20000, condition, "UserId,LeaderLevel,CreateDate", false);
  220. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  221. foreach (Dictionary<string, object> dic in diclist)
  222. {
  223. //创客
  224. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  225. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  226. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  227. dic["UserIdRealName"] = userid_Users.RealName;
  228. dic.Remove("UserId");
  229. //盟主等级
  230. int LeaderLevel = int.Parse(dic["LeaderLevel"].ToString());
  231. if (LeaderLevel == 1) dic["LeaderLevel"] = "小盟主";
  232. if (LeaderLevel == 2) dic["LeaderLevel"] = "大盟主";
  233. if (LeaderLevel == 0) dic["LeaderLevel"] = "";
  234. }
  235. Dictionary<string, object> result = new Dictionary<string, object>();
  236. result.Add("Status", "1");
  237. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  238. result.Add("Obj", diclist);
  239. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  240. ReturnFields.Add("UserIdMakerCode", "创客创客编号");
  241. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  242. ReturnFields.Add("LeaderLevel", "盟主等级");
  243. ReturnFields.Add("CreateDate", "创建时间");
  244. result.Add("Fields", ReturnFields);
  245. AddSysLog("0", "Leaders", "ExportExcel");
  246. return Json(result);
  247. }
  248. #endregion
  249. }
  250. }