LeadersController.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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 LeadersController : BaseController
  23. {
  24. public LeadersController(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(Leaders 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(Leaders data, string UserIdMakerCode, string LeaderLevelSelect, string LeaderStatusSelect, string LastBuyDateData, string ExpiredDateData, 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 UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  53. }
  54. //盟主等级
  55. if (!string.IsNullOrEmpty(LeaderLevelSelect))
  56. {
  57. condition += " and LeaderLevel=" + LeaderLevelSelect;
  58. }
  59. //状态
  60. if (!string.IsNullOrEmpty(LeaderStatusSelect))
  61. {
  62. var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  63. if (LeaderStatusSelect == "0")
  64. {
  65. condition += " and ExpiredDate>'" + time + "'";
  66. }
  67. else
  68. {
  69. condition += " and ExpiredDate<='" + time + "'";
  70. }
  71. }
  72. //首次购买时间
  73. if (!string.IsNullOrEmpty(CreateDateData))
  74. {
  75. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  76. string start = datelist[0];
  77. string end = datelist[1];
  78. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  79. }
  80. //最后购买时间
  81. if (!string.IsNullOrEmpty(LastBuyDateData))
  82. {
  83. string[] datelist = LastBuyDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  84. string start = datelist[0];
  85. string end = datelist[1];
  86. condition += " and LastBuyDate>='" + start + " 00:00:00' and LastBuyDate<='" + end + " 23:59:59'";
  87. }
  88. //盟主到期时间
  89. if (!string.IsNullOrEmpty(ExpiredDateData))
  90. {
  91. string[] datelist = ExpiredDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  92. string start = datelist[0];
  93. string end = datelist[1];
  94. condition += " and ExpiredDate>='" + start + " 00:00:00' and ExpiredDate<='" + end + " 23:59:59'";
  95. }
  96. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Leaders", Fields, "Id desc", "0", page, limit, condition);
  97. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  98. foreach (Dictionary<string, object> dic in diclist)
  99. {
  100. //创客
  101. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  102. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  103. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount();
  104. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  105. dic["UserIdRealName"] = userid_Users.RealName;
  106. dic["LeaderReserve"] = userAccount.LeaderReserve;
  107. dic["LeaderBalanceAmount"] = userAccount.LeaderBalanceAmount;
  108. var lastMonth = DateTime.Now.AddMonths(-1).ToString("yyyy-MM");
  109. var leaderReconRecord = db.LeaderReconRecord.FirstOrDefault(m => m.UserId == UserId && m.StatMonth == lastMonth) ?? new LeaderReconRecord();
  110. dic["LastMonthReserve"] = leaderReconRecord.ReserveAmount;
  111. dic["LastMonthBalanceAmount"] = leaderReconRecord.BalanceAmount;
  112. var ExpiredDate = DateTime.Parse(dic["ExpiredDate"].ToString());
  113. if (ExpiredDate > DateTime.Now)
  114. {
  115. dic["LeaderStatus"] = "未过期";
  116. }
  117. else
  118. {
  119. dic["LeaderStatus"] = "已过期";
  120. }
  121. dic.Remove("UserId");
  122. //盟主等级
  123. int LeaderLevel = int.Parse(dic["LeaderLevel"].ToString());
  124. if (LeaderLevel == 1) dic["LeaderLevel"] = "小盟主";
  125. if (LeaderLevel == 2) dic["LeaderLevel"] = "大盟主";
  126. if (LeaderLevel == 0) dic["LeaderLevel"] = "";
  127. }
  128. return Json(obj);
  129. }
  130. #endregion
  131. #region 增加盟主管理
  132. /// <summary>
  133. /// 增加或修改盟主管理信息
  134. /// </summary>
  135. /// <returns></returns>
  136. public IActionResult Add(string right)
  137. {
  138. ViewBag.RightInfo = RightInfo;
  139. ViewBag.right = right;
  140. return View();
  141. }
  142. #endregion
  143. #region 增加盟主管理
  144. /// <summary>
  145. /// 增加或修改盟主管理信息
  146. /// </summary>
  147. /// <returns></returns>
  148. [HttpPost]
  149. public string Add(Leaders data, string MakerCode)
  150. {
  151. Dictionary<string, object> Fields = new Dictionary<string, object>();
  152. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  153. if (userForMakerCode.UserId > 0)
  154. {
  155. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  156. if (user.Id > 0)
  157. {
  158. user.LeaderLevel = data.LeaderLevel;
  159. Fields.Add("UserId", userForMakerCode.UserId); //创客
  160. Fields.Add("LeaderLevel", data.LeaderLevel); //盟主等级
  161. Fields.Add("SeoKeyword", data.SeoKeyword);//附件
  162. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("Leaders", Fields, 0);
  163. AddSysLog(data.Id.ToString(), "Leaders", "add");
  164. db.SaveChanges();
  165. }
  166. }
  167. return "success";
  168. }
  169. #endregion
  170. #region 修改盟主管理
  171. /// <summary>
  172. /// 增加或修改盟主管理信息
  173. /// </summary>
  174. /// <returns></returns>
  175. public IActionResult Edit(string right, int Id = 0)
  176. {
  177. ViewBag.RightInfo = RightInfo;
  178. ViewBag.right = right;
  179. Leaders editData = db.Leaders.FirstOrDefault(m => m.Id == Id) ?? new Leaders();
  180. Users editDatas = db.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
  181. ViewBag.data = editData;
  182. ViewBag.datas = editDatas;
  183. return View();
  184. }
  185. #endregion
  186. #region 修改盟主管理
  187. /// <summary>
  188. /// 增加或修改盟主管理信息
  189. /// </summary>
  190. /// <returns></returns>
  191. [HttpPost]
  192. public string Edit(Leaders data, string MakerCode)
  193. {
  194. Dictionary<string, object> Fields = new Dictionary<string, object>();
  195. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  196. if (userForMakerCode.UserId > 0)
  197. {
  198. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  199. if (user.Id > 0)
  200. {
  201. user.LeaderLevel = data.LeaderLevel;
  202. Fields.Add("UserId", userForMakerCode.UserId); //创客
  203. Fields.Add("LeaderLevel", data.LeaderLevel); //盟主等级
  204. Fields.Add("SeoKeyword", data.SeoKeyword);
  205. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Leaders", Fields, data.Id);
  206. var leader = db.Leaders.FirstOrDefault(m => m.Id == data.Id) ?? new Leaders();
  207. if (leader.Id > 0)
  208. {
  209. leader.CreateDate = leader.CreateDate;
  210. }
  211. AddSysLog(data.Id.ToString(), "Leaders", "update");
  212. db.SaveChanges();
  213. }
  214. }
  215. return "success";
  216. }
  217. #endregion
  218. #region 修改盟主金额
  219. public IActionResult ChangeLeaderAmount(string right, int Id = 0)
  220. {
  221. ViewBag.RightInfo = RightInfo;
  222. ViewBag.right = right;
  223. Leaders leaders = db.Leaders.FirstOrDefault(m => m.Id == Id) ?? new Leaders();
  224. Users editData = db.Users.FirstOrDefault(m => m.Id == leaders.UserId) ?? new Users();
  225. ViewBag.data = editData;
  226. return View();
  227. }
  228. #endregion
  229. #region 修改盟主金额
  230. [HttpPost]
  231. public string ChangeLeaderAmount(Leaders data, string ChangeAmount, int AmountType, string Note, int Kind)
  232. {
  233. int UserId = data.Id;
  234. var Amount = Convert.ToDecimal(ChangeAmount);
  235. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  236. if (account == null)
  237. {
  238. account = db.UserAccount.Add(new UserAccount()
  239. {
  240. Id = UserId,
  241. CreateDate = DateTime.Now,
  242. CreateMan = SysUserName + "-" + SysRealName,
  243. UserId = UserId,
  244. }).Entity;
  245. db.SaveChanges();
  246. }
  247. //盟主储蓄金
  248. if (AmountType == 1)
  249. {
  250. if ((Kind == 1 || Kind == 3) && Amount > account.LeaderReserve)
  251. {
  252. return "盟主储蓄金不足";
  253. }
  254. decimal BeforeLeaderReserve = account.LeaderReserve; //变更前盟主储蓄金
  255. decimal BeforeLeaderBalanceAmount = account.LeaderBalanceAmount; //变更前盟主可提现余额
  256. int ChangeType = 0;
  257. if (Kind == 1 && Amount <= account.LeaderReserve)
  258. {
  259. account.LeaderReserve -= Amount;
  260. account.TotalProfit += Amount;
  261. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统冻结(盟主储蓄金)',Time'" + DateTime.Now + "'");
  262. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  263. }
  264. else if (Kind == 1 && Amount > account.LeaderReserve)
  265. {
  266. return "冻结金额大于盟主储蓄金";
  267. }
  268. else if (Kind == 2 && Amount <= account.TotalProfit)
  269. {
  270. account.LeaderReserve += Amount;
  271. account.TotalProfit -= Amount;
  272. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统解冻(盟主储蓄金)',Time'" + DateTime.Now + "'");
  273. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  274. }
  275. else if (Kind == 2 && Amount > account.TotalProfit)
  276. {
  277. return "解冻金额大于冻结金额";
  278. }
  279. else if (Kind == 3 && Amount <= account.LeaderReserve)
  280. {
  281. account.LeaderReserve -= Amount;
  282. ChangeType = 2;
  283. decimal AfterLeaderReserve = account.LeaderReserve; //变更后盟主储蓄金
  284. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后盟主可提现余额
  285. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  286. {
  287. CreateDate = DateTime.Now, //创建时间
  288. UserId = UserId, //创客
  289. Remark = "系统扣减(盟主储蓄金)",
  290. ChangeType = ChangeType,
  291. BeforeAmt = BeforeLeaderReserve,
  292. AfterAmt = AfterLeaderReserve,
  293. ChangeAmt = Amount,
  294. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  295. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  296. }).Entity;
  297. db.SaveChanges();
  298. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统扣减(盟主储蓄金)',Time'" + DateTime.Now + "'");
  299. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  300. }
  301. else if (Kind == 3 && Amount > account.LeaderReserve)
  302. {
  303. return "扣减金额大于盟主储蓄金";
  304. }
  305. else if (Kind == 4)
  306. {
  307. account.LeaderReserve += Amount;
  308. ChangeType = 1;
  309. decimal AfterLeaderReserve = account.LeaderReserve; //变更后总金额
  310. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后冻结金额
  311. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  312. {
  313. CreateDate = DateTime.Now, //创建时间
  314. UserId = UserId, //创客
  315. Remark = "系统增加(盟主储蓄金)",
  316. ChangeType = ChangeType,
  317. BeforeAmt = BeforeLeaderReserve,
  318. AfterAmt = AfterLeaderReserve,
  319. ChangeAmt = Amount,
  320. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  321. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  322. }).Entity;
  323. db.SaveChanges();
  324. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统增加(盟主储蓄金)',Time'" + DateTime.Now + "'");
  325. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  326. }
  327. AddSysLog(data.Id.ToString(), "Leaders", "ChangeLeaderAmount");
  328. db.SaveChanges();
  329. }
  330. //盟主可提现余额
  331. if (AmountType == 2)
  332. {
  333. if ((Kind == 1 || Kind == 3) && Amount > account.LeaderBalanceAmount)
  334. {
  335. return "盟主可提现余额不足";
  336. }
  337. decimal BeforeLeaderReserve = account.LeaderReserve; //变更前盟主储蓄金
  338. decimal BeforeLeaderBalanceAmount = account.LeaderBalanceAmount; //变更前盟主可提现余额
  339. int ChangeType = 0;
  340. if (Kind == 1 && Amount <= account.LeaderReserve)
  341. {
  342. account.LeaderBalanceAmount -= Amount;
  343. account.TotalServiceProfit += Amount;
  344. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统冻结(盟主可提现余额)',Time'" + DateTime.Now + "'");
  345. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  346. }
  347. else if (Kind == 1 && Amount > account.LeaderBalanceAmount)
  348. {
  349. return "冻结金额大于盟主可提现余额";
  350. }
  351. else if (Kind == 2 && Amount <= account.TotalServiceProfit)
  352. {
  353. account.LeaderBalanceAmount += Amount;
  354. account.TotalServiceProfit -= Amount;
  355. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统解冻(盟主可提现余额)',Time'" + DateTime.Now + "'");
  356. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  357. }
  358. else if (Kind == 2 && Amount > account.TotalServiceProfit)
  359. {
  360. return "解冻金额大于冻结金额";
  361. }
  362. else if (Kind == 3 && Amount <= account.LeaderBalanceAmount)
  363. {
  364. account.LeaderBalanceAmount -= Amount;
  365. ChangeType = 2;
  366. decimal AfterLeaderReserve = account.LeaderReserve; //变更后总金额
  367. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后冻结金额
  368. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  369. {
  370. CreateDate = DateTime.Now, //创建时间
  371. UserId = UserId, //创客
  372. Remark = "系统扣减(盟主可提现余额)",
  373. ChangeType = ChangeType,
  374. BeforeAmt = BeforeLeaderBalanceAmount,
  375. AfterAmt = AfterLeaderBalanceAmount,
  376. ChangeAmt = Amount,
  377. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  378. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  379. }).Entity;
  380. db.SaveChanges();
  381. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统扣减(盟主可提现余额)',Time'" + DateTime.Now + "'");
  382. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  383. }
  384. else if (Kind == 3 && Amount > account.LeaderBalanceAmount)
  385. {
  386. return "扣减金额大于盟主可提现余额";
  387. }
  388. else if (Kind == 4)
  389. {
  390. account.LeaderBalanceAmount += Amount;
  391. ChangeType = 1;
  392. decimal AfterLeaderReserve = account.LeaderReserve; //变更后总金额
  393. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后冻结金额
  394. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  395. {
  396. CreateDate = DateTime.Now, //创建时间
  397. UserId = UserId, //创客
  398. Remark = "系统增加(盟主可提现余额)",
  399. ChangeType = ChangeType,
  400. BeforeAmt = BeforeLeaderBalanceAmount,
  401. AfterAmt = AfterLeaderBalanceAmount,
  402. ChangeAmt = Amount,
  403. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  404. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  405. }).Entity;
  406. db.SaveChanges();
  407. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统增加(盟主可提现余额)',Time'" + DateTime.Now + "'");
  408. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  409. }
  410. AddSysLog(data.Id.ToString(), "Leaders", "ChangeLeaderAmount");
  411. db.SaveChanges();
  412. }
  413. return "success";
  414. }
  415. #endregion
  416. #region 删除盟主管理信息
  417. /// <summary>
  418. /// 删除盟主管理信息
  419. /// </summary>
  420. /// <returns></returns>
  421. public string Delete(string Id)
  422. {
  423. string[] idlist = Id.Split(new char[] { ',' });
  424. AddSysLog(Id, "Leaders", "del");
  425. foreach (string subid in idlist)
  426. {
  427. int id = int.Parse(subid);
  428. Dictionary<string, object> Fields = new Dictionary<string, object>();
  429. Fields.Add("Status", -1);
  430. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Leaders", Fields, id);
  431. }
  432. db.SaveChanges();
  433. return "success";
  434. }
  435. #endregion
  436. #region 开启
  437. /// <summary>
  438. /// 开启
  439. /// </summary>
  440. /// <returns></returns>
  441. public string Open(string Id)
  442. {
  443. string[] idlist = Id.Split(new char[] { ',' });
  444. AddSysLog(Id, "Leaders", "open");
  445. foreach (string subid in idlist)
  446. {
  447. int id = int.Parse(subid);
  448. Dictionary<string, object> Fields = new Dictionary<string, object>();
  449. Fields.Add("Status", 1);
  450. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Leaders", Fields, id);
  451. }
  452. db.SaveChanges();
  453. return "success";
  454. }
  455. #endregion
  456. #region 关闭
  457. /// <summary>
  458. /// 关闭
  459. /// </summary>
  460. /// <returns></returns>
  461. public string Close(string Id)
  462. {
  463. string[] idlist = Id.Split(new char[] { ',' });
  464. AddSysLog(Id, "Leaders", "close");
  465. foreach (string subid in idlist)
  466. {
  467. int id = int.Parse(subid);
  468. Dictionary<string, object> Fields = new Dictionary<string, object>();
  469. Fields.Add("Status", 0);
  470. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Leaders", Fields, id);
  471. }
  472. db.SaveChanges();
  473. return "success";
  474. }
  475. #endregion
  476. #region 排序
  477. /// <summary>
  478. /// 排序
  479. /// </summary>
  480. /// <param name="Id"></param>
  481. public string Sort(int Id, int Sort)
  482. {
  483. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("Leaders", Sort, Id);
  484. AddSysLog(Id.ToString(), "Leaders", "sort");
  485. return "success";
  486. }
  487. #endregion
  488. #region 导入数据
  489. /// <summary>
  490. /// 导入数据
  491. /// </summary>
  492. /// <param name="ExcelData"></param>
  493. public string Import(string ExcelData)
  494. {
  495. ExcelData = HttpUtility.UrlDecode(ExcelData);
  496. JsonData list = JsonMapper.ToObject(ExcelData);
  497. for (int i = 1; i < list.Count; i++)
  498. {
  499. JsonData dr = list[i];
  500. db.Leaders.Add(new Leaders()
  501. {
  502. CreateDate = DateTime.Now,
  503. UpdateDate = DateTime.Now,
  504. });
  505. db.SaveChanges();
  506. }
  507. AddSysLog("0", "Leaders", "Import");
  508. return "success";
  509. }
  510. #endregion
  511. #region 导出Excel
  512. /// <summary>
  513. /// 导出Excel
  514. /// </summary>
  515. /// <returns></returns>
  516. public JsonResult ExportExcel(Leaders data, string UserIdMakerCode, string LeaderLevelSelect, string LeaderStatusSelect, string LastBuyDateData, string ExpiredDateData, string CreateDateData)
  517. {
  518. Dictionary<string, string> Fields = new Dictionary<string, string>();
  519. string condition = " and Status>-1";
  520. //创客编号
  521. if (!string.IsNullOrEmpty(UserIdMakerCode))
  522. {
  523. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  524. }
  525. //盟主等级
  526. if (!string.IsNullOrEmpty(LeaderLevelSelect))
  527. {
  528. condition += " and LeaderLevel=" + LeaderLevelSelect;
  529. }
  530. //状态
  531. if (!string.IsNullOrEmpty(LeaderStatusSelect))
  532. {
  533. var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  534. if (LeaderStatusSelect == "0")
  535. {
  536. condition += " and ExpiredDate>'" + time + "'";
  537. }
  538. else
  539. {
  540. condition += " and ExpiredDate<='" + time + "'";
  541. }
  542. }
  543. //首次购买时间
  544. if (!string.IsNullOrEmpty(CreateDateData))
  545. {
  546. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  547. string start = datelist[0];
  548. string end = datelist[1];
  549. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  550. }
  551. //最后购买时间
  552. if (!string.IsNullOrEmpty(LastBuyDateData))
  553. {
  554. string[] datelist = LastBuyDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  555. string start = datelist[0];
  556. string end = datelist[1];
  557. condition += " and LastBuyDate>='" + start + " 00:00:00' and LastBuyDate<='" + end + " 23:59:59'";
  558. }
  559. //盟主到期时间
  560. if (!string.IsNullOrEmpty(ExpiredDateData))
  561. {
  562. string[] datelist = ExpiredDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  563. string start = datelist[0];
  564. string end = datelist[1];
  565. condition += " and ExpiredDate>='" + start + " 00:00:00' and ExpiredDate<='" + end + " 23:59:59'";
  566. }
  567. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Leaders", Fields, "Id desc", "0", 1, 20000, condition, "UserId,LeaderLevel,CreateDate", false);
  568. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  569. foreach (Dictionary<string, object> dic in diclist)
  570. {
  571. //创客
  572. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  573. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  574. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  575. dic["UserIdRealName"] = userid_Users.RealName;
  576. dic.Remove("UserId");
  577. //盟主等级
  578. int LeaderLevel = int.Parse(dic["LeaderLevel"].ToString());
  579. if (LeaderLevel == 1) dic["LeaderLevel"] = "小盟主";
  580. if (LeaderLevel == 2) dic["LeaderLevel"] = "大盟主";
  581. if (LeaderLevel == 0) dic["LeaderLevel"] = "";
  582. }
  583. Dictionary<string, object> result = new Dictionary<string, object>();
  584. result.Add("Status", "1");
  585. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  586. result.Add("Obj", diclist);
  587. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  588. ReturnFields.Add("UserIdMakerCode", "创客创客编号");
  589. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  590. ReturnFields.Add("LeaderLevel", "盟主等级");
  591. ReturnFields.Add("CreateDate", "创建时间");
  592. result.Add("Fields", ReturnFields);
  593. AddSysLog("0", "Leaders", "ExportExcel");
  594. return Json(result);
  595. }
  596. #endregion
  597. #region 快捷导出Excel
  598. public IActionResult QuickExportExcel(string right)
  599. {
  600. ViewBag.RightInfo = RightInfo;
  601. ViewBag.right = right;
  602. return View();
  603. }
  604. [HttpPost]
  605. public string QuickExportExcelDo(string UserIdMakerCode, string LeaderLevelSelect, string LeaderStatusSelect, string LastBuyDateData, string ExpiredDateData, string CreateDateData)
  606. {
  607. var lastMonth = DateTime.Now.AddMonths(-1).ToString("yyyy-MM");
  608. string condition = " and a.Status>-1 and d.StatMonth='" + lastMonth + "'";
  609. //创客编号
  610. if (!string.IsNullOrEmpty(UserIdMakerCode))
  611. {
  612. condition += " and a.UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  613. }
  614. //盟主等级
  615. if (!string.IsNullOrEmpty(LeaderLevelSelect))
  616. {
  617. condition += " and a.LeaderLevel=" + LeaderLevelSelect;
  618. }
  619. //状态
  620. if (!string.IsNullOrEmpty(LeaderStatusSelect))
  621. {
  622. var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  623. if (LeaderStatusSelect == "0")
  624. {
  625. condition += " and a.ExpiredDate>'" + time + "'";
  626. }
  627. else
  628. {
  629. condition += " and a.ExpiredDate<='" + time + "'";
  630. }
  631. }
  632. //首次购买时间
  633. if (!string.IsNullOrEmpty(CreateDateData))
  634. {
  635. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  636. string start = datelist[0];
  637. string end = datelist[1];
  638. condition += " and a.CreateDate>='" + start + " 00:00:00' and a.CreateDate<='" + end + " 23:59:59'";
  639. }
  640. //最后购买时间
  641. if (!string.IsNullOrEmpty(LastBuyDateData))
  642. {
  643. string[] datelist = LastBuyDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  644. string start = datelist[0];
  645. string end = datelist[1];
  646. condition += " and a.LastBuyDate>='" + start + " 00:00:00' and a.LastBuyDate<='" + end + " 23:59:59'";
  647. }
  648. //盟主到期时间
  649. if (!string.IsNullOrEmpty(ExpiredDateData))
  650. {
  651. string[] datelist = ExpiredDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  652. string start = datelist[0];
  653. string end = datelist[1];
  654. condition += " and a.ExpiredDate>='" + start + " 00:00:00' and a.ExpiredDate<='" + end + " 23:59:59'";
  655. }
  656. var Sql = "SELECT c.MakerCode '创客编号',c.RealName '真实姓名',DATE_FORMAT(a.CreateDate,'%Y-%m-%d %H:%i:%s') '首次购买时间',DATE_FORMAT(a.LastBuyDate,'%Y-%m-%d %H:%i:%s') '最后购买时间',DATE_FORMAT(a.ExpiredDate,'%Y-%m-%d %H:%i:%s') '盟主到期时间',(CASE WHEN a.ExpiredDate>NOW() THEN '未过期' ELSE '已过期' end) '状态',(CASE WHEN a.LeaderLevel=1 THEN '小盟主' WHEN a.LeaderLevel=2 THEN '大盟主' ELSE '' end) '盟主等级',b.LeaderReserve '盟主储蓄金',b.LeaderBalanceAmount '盟主可提现余额',d.ReserveAmount '上月盟主储蓄金',d.BalanceAmount '上月可提现余额' FROM Leaders a LEFT JOIN UserAccount b ON a.Id=b.Id LEFT JOIN Users c ON a.Id=c.Id LEFT JOIN LeaderReconRecord d ON a.Id=d.UserId WHERE 1=1" + condition;
  657. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
  658. var FileName = "盟主记录" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  659. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  660. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  661. return "success";
  662. }
  663. #endregion
  664. }
  665. }