LeadersController.cs 27 KB

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