LeadersController.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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. Sort = 11, //类型
  289. //11:盟主储蓄金增减单(兑换机具券 机具券兑换 系统增加(盟主储蓄金) 系统扣减(盟主储蓄金) 储备金购买)
  290. // 示例:+/-金额
  291. // 盟主储蓄金:剩余盟主储蓄金
  292. // 12:可提现余额增减单(系统增加(可提现余额) 系统扣减(可提现余额))
  293. // 示例:+/-金额
  294. // 可提现余额:剩余可提现余额
  295. // 13:盟主储蓄金减少可提现余额增加(推荐大/小盟主 商城购机 购机奖励)
  296. // 示例:-金额
  297. // 盟主储蓄金:剩余盟主储蓄金
  298. // 可提现余额:+金额
  299. UserId = UserId, //创客
  300. Remark = "系统扣减(盟主储蓄金)",
  301. ChangeType = ChangeType,
  302. BeforeAmt = BeforeLeaderReserve,
  303. AfterAmt = AfterLeaderReserve,
  304. ChangeAmt = Amount,
  305. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  306. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  307. }).Entity;
  308. db.SaveChanges();
  309. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统扣减(盟主储蓄金)',Time'" + DateTime.Now + "'");
  310. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  311. }
  312. else if (Kind == 3 && Amount > account.LeaderReserve)
  313. {
  314. return "扣减金额大于盟主储蓄金";
  315. }
  316. else if (Kind == 4)
  317. {
  318. account.LeaderReserve += Amount;
  319. ChangeType = 1;
  320. decimal AfterLeaderReserve = account.LeaderReserve; //变更后总金额
  321. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后冻结金额
  322. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  323. {
  324. CreateDate = DateTime.Now, //创建时间
  325. Sort = 11, //类型
  326. //11:盟主储蓄金增减单(兑换机具券 机具券兑换 系统增加(盟主储蓄金) 系统扣减(盟主储蓄金) 储备金购买)
  327. // 示例:+/-金额
  328. // 盟主储蓄金:剩余盟主储蓄金
  329. // 12:可提现余额增减单(系统增加(可提现余额) 系统扣减(可提现余额))
  330. // 示例:+/-金额
  331. // 可提现余额:剩余可提现余额
  332. // 13:盟主储蓄金减少可提现余额增加(推荐大/小盟主 商城购机 购机奖励)
  333. // 示例:-金额
  334. // 盟主储蓄金:剩余盟主储蓄金
  335. // 可提现余额:+金额
  336. UserId = UserId, //创客
  337. Remark = "系统增加(盟主储蓄金)",
  338. ChangeType = ChangeType,
  339. BeforeAmt = BeforeLeaderReserve,
  340. AfterAmt = AfterLeaderReserve,
  341. ChangeAmt = Amount,
  342. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  343. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  344. }).Entity;
  345. db.SaveChanges();
  346. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统增加(盟主储蓄金)',Time'" + DateTime.Now + "'");
  347. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  348. }
  349. AddSysLog(data.Id.ToString(), "Leaders", "ChangeLeaderAmount");
  350. db.SaveChanges();
  351. }
  352. //盟主可提现余额
  353. if (AmountType == 2)
  354. {
  355. if ((Kind == 1 || Kind == 3) && Amount > account.LeaderBalanceAmount)
  356. {
  357. return "盟主可提现余额不足";
  358. }
  359. decimal BeforeLeaderReserve = account.LeaderReserve; //变更前盟主储蓄金
  360. decimal BeforeLeaderBalanceAmount = account.LeaderBalanceAmount; //变更前盟主可提现余额
  361. int ChangeType = 0;
  362. if (Kind == 1 && Amount <= account.LeaderReserve)
  363. {
  364. account.LeaderBalanceAmount -= Amount;
  365. account.TotalServiceProfit += Amount;
  366. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统冻结(盟主可提现余额)',Time'" + DateTime.Now + "'");
  367. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  368. }
  369. else if (Kind == 1 && Amount > account.LeaderBalanceAmount)
  370. {
  371. return "冻结金额大于盟主可提现余额";
  372. }
  373. else if (Kind == 2 && Amount <= account.TotalServiceProfit)
  374. {
  375. account.LeaderBalanceAmount += Amount;
  376. account.TotalServiceProfit -= Amount;
  377. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统解冻(盟主可提现余额)',Time'" + DateTime.Now + "'");
  378. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  379. }
  380. else if (Kind == 2 && Amount > account.TotalServiceProfit)
  381. {
  382. return "解冻金额大于冻结金额";
  383. }
  384. else if (Kind == 3 && Amount <= account.LeaderBalanceAmount)
  385. {
  386. account.LeaderBalanceAmount -= Amount;
  387. ChangeType = 2;
  388. decimal AfterLeaderReserve = account.LeaderReserve; //变更后总金额
  389. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后冻结金额
  390. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  391. {
  392. CreateDate = DateTime.Now, //创建时间
  393. Sort = 12, //类型
  394. //11:盟主储蓄金增减单(兑换机具券 机具券兑换 系统增加(盟主储蓄金) 系统扣减(盟主储蓄金) 储备金购买)
  395. // 示例:+/-金额
  396. // 盟主储蓄金:剩余盟主储蓄金
  397. // 12:可提现余额增减单(系统增加(可提现余额) 系统扣减(可提现余额))
  398. // 示例:+/-金额
  399. // 可提现余额:剩余可提现余额
  400. // 13:盟主储蓄金减少可提现余额增加(推荐大/小盟主 商城购机 购机奖励)
  401. // 示例:-金额
  402. // 盟主储蓄金:剩余盟主储蓄金
  403. // 可提现余额:+金额
  404. UserId = UserId, //创客
  405. Remark = "系统扣减(盟主可提现余额)",
  406. ChangeType = ChangeType,
  407. BeforeAmt = BeforeLeaderBalanceAmount,
  408. AfterAmt = AfterLeaderBalanceAmount,
  409. ChangeAmt = Amount,
  410. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  411. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  412. }).Entity;
  413. db.SaveChanges();
  414. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统扣减(盟主可提现余额)',Time'" + DateTime.Now + "'");
  415. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  416. }
  417. else if (Kind == 3 && Amount > account.LeaderBalanceAmount)
  418. {
  419. return "扣减金额大于盟主可提现余额";
  420. }
  421. else if (Kind == 4)
  422. {
  423. account.LeaderBalanceAmount += Amount;
  424. ChangeType = 1;
  425. decimal AfterLeaderReserve = account.LeaderReserve; //变更后总金额
  426. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后冻结金额
  427. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  428. {
  429. CreateDate = DateTime.Now, //创建时间
  430. Sort = 12, //类型
  431. //11:盟主储蓄金增减单(兑换机具券 机具券兑换 系统增加(盟主储蓄金) 系统扣减(盟主储蓄金) 储备金购买)
  432. // 示例:+/-金额
  433. // 盟主储蓄金:剩余盟主储蓄金
  434. // 12:可提现余额增减单(系统增加(可提现余额) 系统扣减(可提现余额))
  435. // 示例:+/-金额
  436. // 可提现余额:剩余可提现余额
  437. // 13:盟主储蓄金减少可提现余额增加(推荐大/小盟主 商城购机 购机奖励)
  438. // 示例:-金额
  439. // 盟主储蓄金:剩余盟主储蓄金
  440. // 可提现余额:+金额
  441. UserId = UserId, //创客
  442. Remark = "系统增加(盟主可提现余额)",
  443. ChangeType = ChangeType,
  444. BeforeAmt = BeforeLeaderBalanceAmount,
  445. AfterAmt = AfterLeaderBalanceAmount,
  446. ChangeAmt = Amount,
  447. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  448. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  449. }).Entity;
  450. db.SaveChanges();
  451. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统增加(盟主可提现余额)',Time'" + DateTime.Now + "'");
  452. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  453. }
  454. AddSysLog(data.Id.ToString(), "Leaders", "ChangeLeaderAmount");
  455. db.SaveChanges();
  456. }
  457. return "success";
  458. }
  459. #endregion
  460. #region 删除盟主管理信息
  461. /// <summary>
  462. /// 删除盟主管理信息
  463. /// </summary>
  464. /// <returns></returns>
  465. public string Delete(string Id)
  466. {
  467. string[] idlist = Id.Split(new char[] { ',' });
  468. AddSysLog(Id, "Leaders", "del");
  469. foreach (string subid in idlist)
  470. {
  471. int id = int.Parse(subid);
  472. Dictionary<string, object> Fields = new Dictionary<string, object>();
  473. Fields.Add("Status", -1);
  474. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Leaders", Fields, id);
  475. }
  476. db.SaveChanges();
  477. return "success";
  478. }
  479. #endregion
  480. #region 开启
  481. /// <summary>
  482. /// 开启
  483. /// </summary>
  484. /// <returns></returns>
  485. public string Open(string Id)
  486. {
  487. string[] idlist = Id.Split(new char[] { ',' });
  488. AddSysLog(Id, "Leaders", "open");
  489. foreach (string subid in idlist)
  490. {
  491. int id = int.Parse(subid);
  492. Dictionary<string, object> Fields = new Dictionary<string, object>();
  493. Fields.Add("Status", 1);
  494. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Leaders", Fields, id);
  495. }
  496. db.SaveChanges();
  497. return "success";
  498. }
  499. #endregion
  500. #region 关闭
  501. /// <summary>
  502. /// 关闭
  503. /// </summary>
  504. /// <returns></returns>
  505. public string Close(string Id)
  506. {
  507. string[] idlist = Id.Split(new char[] { ',' });
  508. AddSysLog(Id, "Leaders", "close");
  509. foreach (string subid in idlist)
  510. {
  511. int id = int.Parse(subid);
  512. Dictionary<string, object> Fields = new Dictionary<string, object>();
  513. Fields.Add("Status", 0);
  514. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Leaders", Fields, id);
  515. }
  516. db.SaveChanges();
  517. return "success";
  518. }
  519. #endregion
  520. #region 排序
  521. /// <summary>
  522. /// 排序
  523. /// </summary>
  524. /// <param name="Id"></param>
  525. public string Sort(int Id, int Sort)
  526. {
  527. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("Leaders", Sort, Id);
  528. AddSysLog(Id.ToString(), "Leaders", "sort");
  529. return "success";
  530. }
  531. #endregion
  532. #region 导入数据
  533. /// <summary>
  534. /// 导入数据
  535. /// </summary>
  536. /// <param name="ExcelData"></param>
  537. public string Import(string ExcelData)
  538. {
  539. ExcelData = HttpUtility.UrlDecode(ExcelData);
  540. JsonData list = JsonMapper.ToObject(ExcelData);
  541. for (int i = 1; i < list.Count; i++)
  542. {
  543. JsonData dr = list[i];
  544. db.Leaders.Add(new Leaders()
  545. {
  546. CreateDate = DateTime.Now,
  547. UpdateDate = DateTime.Now,
  548. });
  549. db.SaveChanges();
  550. }
  551. AddSysLog("0", "Leaders", "Import");
  552. return "success";
  553. }
  554. #endregion
  555. #region 导出Excel
  556. /// <summary>
  557. /// 导出Excel
  558. /// </summary>
  559. /// <returns></returns>
  560. public JsonResult ExportExcel(Leaders data, string UserIdMakerCode, string LeaderLevelSelect, string LeaderStatusSelect, string LastBuyDateData, string ExpiredDateData, string CreateDateData)
  561. {
  562. Dictionary<string, string> Fields = new Dictionary<string, string>();
  563. string condition = " and Status>-1";
  564. //创客编号
  565. if (!string.IsNullOrEmpty(UserIdMakerCode))
  566. {
  567. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  568. }
  569. //盟主等级
  570. if (!string.IsNullOrEmpty(LeaderLevelSelect))
  571. {
  572. condition += " and LeaderLevel=" + LeaderLevelSelect;
  573. }
  574. //状态
  575. if (!string.IsNullOrEmpty(LeaderStatusSelect))
  576. {
  577. var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  578. if (LeaderStatusSelect == "0")
  579. {
  580. condition += " and ExpiredDate>'" + time + "'";
  581. }
  582. else
  583. {
  584. condition += " and ExpiredDate<='" + time + "'";
  585. }
  586. }
  587. //首次购买时间
  588. if (!string.IsNullOrEmpty(CreateDateData))
  589. {
  590. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  591. string start = datelist[0];
  592. string end = datelist[1];
  593. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  594. }
  595. //最后购买时间
  596. if (!string.IsNullOrEmpty(LastBuyDateData))
  597. {
  598. string[] datelist = LastBuyDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  599. string start = datelist[0];
  600. string end = datelist[1];
  601. condition += " and LastBuyDate>='" + start + " 00:00:00' and LastBuyDate<='" + end + " 23:59:59'";
  602. }
  603. //盟主到期时间
  604. if (!string.IsNullOrEmpty(ExpiredDateData))
  605. {
  606. string[] datelist = ExpiredDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  607. string start = datelist[0];
  608. string end = datelist[1];
  609. condition += " and ExpiredDate>='" + start + " 00:00:00' and ExpiredDate<='" + end + " 23:59:59'";
  610. }
  611. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Leaders", Fields, "Id desc", "0", 1, 20000, condition, "UserId,LeaderLevel,CreateDate", false);
  612. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  613. foreach (Dictionary<string, object> dic in diclist)
  614. {
  615. //创客
  616. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  617. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  618. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  619. dic["UserIdRealName"] = userid_Users.RealName;
  620. dic.Remove("UserId");
  621. //盟主等级
  622. int LeaderLevel = int.Parse(dic["LeaderLevel"].ToString());
  623. if (LeaderLevel == 1) dic["LeaderLevel"] = "小盟主";
  624. if (LeaderLevel == 2) dic["LeaderLevel"] = "大盟主";
  625. if (LeaderLevel == 0) dic["LeaderLevel"] = "";
  626. }
  627. Dictionary<string, object> result = new Dictionary<string, object>();
  628. result.Add("Status", "1");
  629. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  630. result.Add("Obj", diclist);
  631. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  632. ReturnFields.Add("UserIdMakerCode", "创客创客编号");
  633. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  634. ReturnFields.Add("LeaderLevel", "盟主等级");
  635. ReturnFields.Add("CreateDate", "创建时间");
  636. result.Add("Fields", ReturnFields);
  637. AddSysLog("0", "Leaders", "ExportExcel");
  638. return Json(result);
  639. }
  640. #endregion
  641. #region 快捷导出Excel
  642. public IActionResult QuickExportExcel(string right)
  643. {
  644. ViewBag.RightInfo = RightInfo;
  645. ViewBag.right = right;
  646. return View();
  647. }
  648. [HttpPost]
  649. public string QuickExportExcelDo(string UserIdMakerCode, string LeaderLevelSelect, string LeaderStatusSelect, string LastBuyDateData, string ExpiredDateData, string CreateDateData)
  650. {
  651. var lastMonth = DateTime.Now.AddMonths(-1).ToString("yyyy-MM");
  652. string condition = " and a.Status>-1 and d.StatMonth='" + lastMonth + "'";
  653. //创客编号
  654. if (!string.IsNullOrEmpty(UserIdMakerCode))
  655. {
  656. condition += " and a.UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  657. }
  658. //盟主等级
  659. if (!string.IsNullOrEmpty(LeaderLevelSelect))
  660. {
  661. condition += " and a.LeaderLevel=" + LeaderLevelSelect;
  662. }
  663. //状态
  664. if (!string.IsNullOrEmpty(LeaderStatusSelect))
  665. {
  666. var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  667. if (LeaderStatusSelect == "0")
  668. {
  669. condition += " and a.ExpiredDate>'" + time + "'";
  670. }
  671. else
  672. {
  673. condition += " and a.ExpiredDate<='" + time + "'";
  674. }
  675. }
  676. //首次购买时间
  677. if (!string.IsNullOrEmpty(CreateDateData))
  678. {
  679. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  680. string start = datelist[0];
  681. string end = datelist[1];
  682. condition += " and a.CreateDate>='" + start + " 00:00:00' and a.CreateDate<='" + end + " 23:59:59'";
  683. }
  684. //最后购买时间
  685. if (!string.IsNullOrEmpty(LastBuyDateData))
  686. {
  687. string[] datelist = LastBuyDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  688. string start = datelist[0];
  689. string end = datelist[1];
  690. condition += " and a.LastBuyDate>='" + start + " 00:00:00' and a.LastBuyDate<='" + end + " 23:59:59'";
  691. }
  692. //盟主到期时间
  693. if (!string.IsNullOrEmpty(ExpiredDateData))
  694. {
  695. string[] datelist = ExpiredDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  696. string start = datelist[0];
  697. string end = datelist[1];
  698. condition += " and a.ExpiredDate>='" + start + " 00:00:00' and a.ExpiredDate<='" + end + " 23:59:59'";
  699. }
  700. 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;
  701. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
  702. var FileName = "盟主记录" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  703. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  704. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  705. return "success";
  706. }
  707. #endregion
  708. }
  709. }