LeadersController.cs 36 KB

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