LeadersController.cs 29 KB

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