LeaderReserveRecordController.cs 16 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 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. //变动类型
  94. int ChangeType = int.Parse(function.CheckInt(dic["ChangeType"].ToString()));
  95. if (ChangeType == 1) dic["ChangeTypeName"] = "增加";
  96. if (ChangeType == 2) dic["ChangeTypeName"] = "减少";
  97. // else
  98. // {
  99. // int OrderId = int.Parse(function.CheckInt(dic["OrderId"].ToString()));
  100. // var order = db.Orders.FirstOrDefault(m => m.Id == OrderId) ?? new Orders();
  101. // Users sourceUser = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  102. // dic["SourceMakerCode"] = sourceUser.MakerCode;
  103. // dic.Remove("OrderId");
  104. // }
  105. // //购券创客
  106. // int SourceUserId = int.Parse(function.CheckInt(dic["SourceUserId"].ToString()));
  107. // Users sourceUser = db.Users.FirstOrDefault(m => m.Id == SourceUserId) ?? new Users();
  108. // dic["SourceMakerCode"] = sourceUser.MakerCode;
  109. // dic.Remove("SourceUserId");
  110. // //订单来源创客
  111. // int OrderId = int.Parse(function.CheckInt(dic["OrderId"].ToString()));
  112. // var order = db.Orders.FirstOrDefault(m => m.Id == OrderId) ?? new Orders();
  113. // Users sourceOrderUser = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  114. // dic["SourceOrderMakerCode"] = sourceOrderUser.MakerCode;
  115. // dic.Remove("OrderId");
  116. //订单信息
  117. JsonData ApplyList = JsonMapper.ToObject(dic["SeoTitle"].ToString());//申请数据
  118. dic["dPosCoupons"] = "";
  119. dic["bPosCoupons"] = "";
  120. if (!string.IsNullOrEmpty(dic["SeoTitle"].ToString()))
  121. {
  122. for (int i = 0; i < ApplyList.Count; i++)
  123. {
  124. int num = Convert.ToInt32(ApplyList[i]["Num"].ToString());
  125. int type = Convert.ToInt32(ApplyList[i]["Type"].ToString());
  126. if (type == 1)
  127. {
  128. dic["dPosCoupons"] = num + "张";
  129. }
  130. else
  131. {
  132. dic["bPosCoupons"] = num + "张";
  133. }
  134. }
  135. }
  136. //券码
  137. int OrderId = int.Parse(function.CheckInt(dic["Id"].ToString()));
  138. if (OrderId >= 2300)
  139. {
  140. var info = db.UserSnDelayChange.Where(m => m.QueryCount == OrderId).ToList();
  141. var PosCoupons = "";
  142. foreach (var item in info)
  143. {
  144. PosCoupons += item.SnNo + ",";
  145. }
  146. dic["PosCoupons"] = PosCoupons;
  147. }
  148. else
  149. {
  150. dic["PosCoupons"] = dic["SeoDescription"].ToString();
  151. }
  152. }
  153. return Json(obj);
  154. }
  155. #endregion
  156. #region 快捷导出Excel
  157. public IActionResult QuickExportExcel(string right)
  158. {
  159. ViewBag.RightInfo = RightInfo;
  160. ViewBag.right = right;
  161. return View();
  162. }
  163. [HttpPost]
  164. public string QuickExportExcelDo(string UserIdMakerCode, string SourceMakerCode, string RemarkSelect, string CreateDateData, string SeoKeyword)
  165. {
  166. string SqlString = " and Status>-1";
  167. //创客编号
  168. if (!string.IsNullOrEmpty(UserIdMakerCode))
  169. {
  170. SqlString += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  171. }
  172. //购券创客
  173. if (!string.IsNullOrEmpty(SourceMakerCode))
  174. {
  175. SqlString += " and SourceUserId in (select UserId from UserForMakerCode where MakerCode='" + SourceMakerCode + "')";
  176. }
  177. //变动类型
  178. if (!string.IsNullOrEmpty(RemarkSelect))
  179. {
  180. SqlString += " and Remark='" + RemarkSelect + "'";
  181. }
  182. //创建时间
  183. if (!string.IsNullOrEmpty(CreateDateData))
  184. {
  185. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  186. string start = datelist[0];
  187. string end = datelist[1];
  188. SqlString += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  189. }
  190. //订单编号
  191. if (!string.IsNullOrEmpty(SeoKeyword))
  192. {
  193. SqlString += " and SeoKeyword=" + SeoKeyword;
  194. }
  195. var Sql = "SELECT c.MakerCode '创客编号',c.RealName '创客姓名',DATE_FORMAT(c.CreateDate,'%Y-%m-%d %H:%i:%s') '创建时间',c.Remark '变动类型',c.Type1Num '电签兑换券张数',c.Type2Num '大POS兑换券张数',d.LeaderBalanceAmount '可提现余额',c.ChangeAmt '使用额度',c.BeforeAmt '使用前剩余额度',c.AfterAmt '使用后剩余额度' FROM(SELECT a.*,b.MakerCode,b.RealName FROM(SELECT Id,UserId,CreateDate,ChangeAmt,BeforeAmt,AfterAmt,Remark,REPLACE (JSON_EXTRACT (SeoTitle, '$[0].Num'),'\\\"','') AS 'Type1Num', REPLACE (JSON_EXTRACT (SeoTitle, '$[1].Num'),'\\\"','') AS 'Type2Num' FROM LeaderReserveRecord WHERE 1=1 " + SqlString + ") a LEFT JOIN Users b ON a.UserId=b.Id) c LEFT JOIN UserAccount d ON c.UserId=d.Id";
  196. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
  197. var FileName = "盟主储蓄金变动记录" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  198. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  199. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  200. return "success";
  201. }
  202. #endregion
  203. #region 导出Excel
  204. /// <summary>
  205. /// 导出Excel
  206. /// </summary>
  207. /// <returns></returns>
  208. public JsonResult ExportExcel(LeaderReserveRecord data, string UserIdMakerCode, string SourceMakerCode, string RemarkSelect, string CreateDateData, string SeoKeyword)
  209. {
  210. Dictionary<string, string> Fields = new Dictionary<string, string>();
  211. string condition = " and Status>-1";
  212. //创客编号
  213. if (!string.IsNullOrEmpty(UserIdMakerCode))
  214. {
  215. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  216. }
  217. //购券创客
  218. if (!string.IsNullOrEmpty(SourceMakerCode))
  219. {
  220. condition += " and SourceUserId in (select UserId from UserForMakerCode where MakerCode='" + SourceMakerCode + "')";
  221. }
  222. //变动类型
  223. if (!string.IsNullOrEmpty(RemarkSelect))
  224. {
  225. condition += " and Remark='" + RemarkSelect + "'";
  226. }
  227. //创建时间
  228. if (!string.IsNullOrEmpty(CreateDateData))
  229. {
  230. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  231. string start = datelist[0];
  232. string end = datelist[1];
  233. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  234. }
  235. //订单编号
  236. if (!string.IsNullOrEmpty(SeoKeyword))
  237. {
  238. condition += " and SeoKeyword='" + SeoKeyword + "'";
  239. }
  240. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("LeaderReserveRecord", Fields, "Id desc", "0", 1, 20000, condition, "Id", false);
  241. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  242. foreach (Dictionary<string, object> dic in diclist)
  243. {
  244. int Id = int.Parse(function.CheckInt(dic["Id"].ToString()));
  245. var leaderReserveRecord = db.LeaderReserveRecord.FirstOrDefault(m => m.Id == Id) ?? new LeaderReserveRecord();
  246. dic["BeforeAmount"] = leaderReserveRecord.BeforeAmt;
  247. dic["AfterAmount"] = leaderReserveRecord.AfterAmt;
  248. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == leaderReserveRecord.UserId) ?? new Users();
  249. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == leaderReserveRecord.UserId) ?? new UserAccount();
  250. dic["MakerCode"] = userid_Users.MakerCode;
  251. dic["RealName"] = userid_Users.RealName;
  252. dic["LeaderBalanceAmount"] = userAccount.LeaderBalanceAmount;
  253. dic["Remark"] = leaderReserveRecord.Remark;
  254. dic["CreateDate"] = leaderReserveRecord.CreateDate;
  255. //变动类型
  256. int ChangeType = leaderReserveRecord.ChangeType;
  257. if (ChangeType == 1) dic["ChangeTypeName"] = "增加";
  258. if (ChangeType == 2) dic["ChangeTypeName"] = "减少";
  259. // //盟主等级
  260. // int LeaderLevel = userid_Users.LeaderLevel;
  261. // if (LeaderLevel == 1) dic["LeaderLevel"] = "小盟主";
  262. // if (LeaderLevel == 2) dic["LeaderLevel"] = "大盟主";
  263. // if (LeaderLevel == 0) dic["LeaderLevel"] = "";
  264. //订单信息
  265. dic["dPosCoupons"] = "";
  266. dic["bPosCoupons"] = "";
  267. if (!string.IsNullOrEmpty(leaderReserveRecord.SeoTitle))
  268. {
  269. JsonData ApplyList = JsonMapper.ToObject(leaderReserveRecord.SeoTitle);//申请数据
  270. for (int i = 0; i < ApplyList.Count; i++)
  271. {
  272. int num = Convert.ToInt32(ApplyList[i]["Num"].ToString());
  273. int type = Convert.ToInt32(ApplyList[i]["Type"].ToString());
  274. if (type == 1)
  275. {
  276. dic["dPosCoupons"] = num + "张";
  277. }
  278. else
  279. {
  280. dic["bPosCoupons"] = num + "张";
  281. }
  282. }
  283. }
  284. dic.Remove("Id");
  285. }
  286. // 导出表格包含创客姓名、创客编号、创建时间、变动类型、电签兑换券张数、大POS兑换券张数、可提现余额、使用前剩余额度、使用后剩余额度
  287. Dictionary<string, object> result = new Dictionary<string, object>();
  288. result.Add("Status", "1");
  289. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  290. result.Add("Obj", diclist);
  291. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  292. ReturnFields.Add("MakerCode", "创客编号");
  293. ReturnFields.Add("RealName", "创客姓名");
  294. ReturnFields.Add("CreateDate", "创建时间");
  295. ReturnFields.Add("Remark", "变动类型");
  296. ReturnFields.Add("ChangeTypeName", "操作类型");
  297. ReturnFields.Add("dPosCoupons", "电签兑换券张数");
  298. ReturnFields.Add("bPosCoupons", "大POS兑换券张数");
  299. ReturnFields.Add("LeaderBalanceAmount", "可提现余额");
  300. ReturnFields.Add("BeforeAmount", "使用前剩余额度");
  301. ReturnFields.Add("AfterAmount", "使用后剩余额度");
  302. result.Add("Fields", ReturnFields);
  303. AddSysLog("0", "LeaderReserveRecord", "ExportExcel");
  304. return Json(result);
  305. }
  306. #endregion
  307. }
  308. }