LeadersController.cs 37 KB

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