UsersController.cs 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  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.Data;
  10. using System.Threading.Tasks;
  11. using Microsoft.AspNetCore.Mvc;
  12. using Microsoft.AspNetCore.Http;
  13. using Microsoft.Extensions.Logging;
  14. using Microsoft.Extensions.Options;
  15. using MySystem.Models;
  16. using Library;
  17. using LitJson;
  18. using MySystemLib;
  19. namespace MySystem.Areas.Admin.Controllers
  20. {
  21. [Area("Admin")]
  22. [Route("Admin/[controller]/[action]")]
  23. public class UsersController : BaseController
  24. {
  25. public UsersController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  26. {
  27. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  28. }
  29. #region 创客列表
  30. /// <summary>
  31. /// 根据条件查询创客列表
  32. /// </summary>
  33. /// <returns></returns>
  34. public IActionResult Index(Users data, string right, int SelfId = 0, int ParentId = 0, string MakerCode = "")
  35. {
  36. ViewBag.RightInfo = RightInfo;
  37. ViewBag.right = right;
  38. ViewBag.SelfId = SelfId.ToString();
  39. ViewBag.ParentId = ParentId.ToString();
  40. ViewBag.MakerCode = MakerCode;
  41. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  42. ViewBag.TopUsers = TopUsers;
  43. List<UserLevelSet> Levels = db.UserLevelSet.OrderBy(m => m.Id).ToList();
  44. ViewBag.Levels = Levels;
  45. return View();
  46. }
  47. #endregion
  48. #region 根据条件查询创客列表
  49. /// <summary>
  50. /// 创客列表
  51. /// </summary>
  52. /// <returns></returns>
  53. public JsonResult IndexData(Users data, string ParentMakerCode, string ParentRealName, string AuthFlagSelect, int TopUserId, string RiskFlagSelect, string MerchantTypeSelect, int SelfId = 0, int ParentId = 0, int page = 1, int limit = 30)
  54. {
  55. Dictionary<string, string> Fields = new Dictionary<string, string>();
  56. Fields.Add("MakerCode", "1"); //创客编号
  57. Fields.Add("RealName", "1"); //创客名称
  58. Fields.Add("Mobile", "1"); //手机号
  59. Fields.Add("CertId", "1"); //身份证号码
  60. Fields.Add("CreateDate", "3"); //注册时间
  61. Fields.Add("SettleAmount", "3"); //结算金额
  62. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  63. Fields.Add("UserLevel", "0"); //创客等级
  64. string condition = " and Status>-1";
  65. string sort = "Id desc";
  66. //直属创客编号
  67. if (!string.IsNullOrEmpty(ParentMakerCode))
  68. {
  69. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  70. }
  71. //直属创客名称
  72. if (!string.IsNullOrEmpty(ParentRealName))
  73. {
  74. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  75. }
  76. //实名状态
  77. if(!string.IsNullOrEmpty(AuthFlagSelect))
  78. {
  79. condition += " and AuthFlag=" + AuthFlagSelect;
  80. }
  81. //顶级创客
  82. if(TopUserId > 0)
  83. {
  84. condition += " and ParentNav like '," + TopUserId + ",%'";
  85. }
  86. //风控标识
  87. if(!string.IsNullOrEmpty(RiskFlagSelect))
  88. {
  89. condition += " and RiskFlag=" + RiskFlagSelect;
  90. }
  91. //商户创客类型
  92. if(!string.IsNullOrEmpty(MerchantTypeSelect))
  93. {
  94. condition += " and MerchantType=" + MerchantTypeSelect;
  95. }
  96. if (SelfId > 0)
  97. {
  98. Users self = db.Users.FirstOrDefault(m => m.Id == SelfId);
  99. if (self != null)
  100. {
  101. string ParentNav = function.CheckNull(self.ParentNav);
  102. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  103. sort = "ParentNav asc";
  104. }
  105. }
  106. if (ParentId > 0)
  107. {
  108. condition += " and ParentUserId=" + ParentId;
  109. }
  110. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, sort, "True", page, limit, condition);
  111. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  112. foreach (Dictionary<string, object> dic in diclist)
  113. {
  114. dic["AuthFlagName"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  115. dic["RiskFlagName"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  116. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  117. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  118. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  119. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  120. dic["ParentMakerCode"] = puser.MakerCode;
  121. dic["ParentRealName"] = puser.RealName;
  122. string ParentNav = dic["ParentNav"].ToString();
  123. if (!string.IsNullOrEmpty(ParentNav))
  124. {
  125. string[] list = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  126. if (list.Length > 1)
  127. {
  128. int TopId = int.Parse(function.CheckInt(list[1]));
  129. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  130. dic["TopMakerCode"] = tuser.MakerCode;
  131. dic["TopRealName"] = tuser.RealName;
  132. }
  133. }
  134. }
  135. return Json(obj);
  136. }
  137. #endregion
  138. #region 增加创客
  139. /// <summary>
  140. /// 增加或修改创客信息
  141. /// </summary>
  142. /// <returns></returns>
  143. public IActionResult Add(string right)
  144. {
  145. ViewBag.RightInfo = RightInfo;
  146. ViewBag.right = right;
  147. return View();
  148. }
  149. #endregion
  150. #region 增加创客
  151. /// <summary>
  152. /// 增加或修改创客信息
  153. /// </summary>
  154. /// <returns></returns>
  155. [HttpPost]
  156. public string Add(Users data, string ParentMakerCode)
  157. {
  158. bool check = db.UserForMobile.Any(m => m.Mobile == data.Mobile);
  159. if (check)
  160. {
  161. return "手机号已存在,请重新输入";
  162. }
  163. check = db.UserForRealName.Any(m => m.RealName == data.RealName);
  164. if (check)
  165. {
  166. return "姓名已存在,请重新输入";
  167. }
  168. if (!string.IsNullOrEmpty(data.MakerCode))
  169. {
  170. check = db.UserForMakerCode.Any(m => m.MakerCode == data.MakerCode);
  171. if (check)
  172. {
  173. return "创客编码已存在,请重新输入";
  174. }
  175. }
  176. Dictionary<string, object> Fields = new Dictionary<string, object>();
  177. Fields.Add("RealName", data.RealName); //真实姓名
  178. Fields.Add("CertId", data.CertId); //身份证号
  179. Fields.Add("Mobile", data.Mobile); //手机号
  180. Fields.Add("LoginPwd", function.MD532(data.LoginPwd)); //登录密码
  181. Fields.Add("SettleBankCardNo", data.SettleBankCardNo); //结算银行卡号
  182. if (!string.IsNullOrEmpty(ParentMakerCode))
  183. {
  184. UserForMakerCode userFor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ParentMakerCode) ?? new UserForMakerCode();
  185. Users puser = db.Users.FirstOrDefault(m => m.Id == userFor.UserId) ?? new Users();
  186. Fields.Add("ParentUserId", userFor.UserId);
  187. Fields.Add("ParentNav", puser.ParentNav + "," + userFor.UserId + ",");
  188. }
  189. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("Users", Fields, 0);
  190. if (string.IsNullOrEmpty(ParentMakerCode))
  191. {
  192. string MakerCode = Id.ToString();
  193. for (int i = 0; i < 7 - Id.ToString().Length; i++)
  194. {
  195. MakerCode = "0" + MakerCode;
  196. }
  197. MakerCode = "K" + MakerCode;
  198. Fields = new Dictionary<string, object>();
  199. Fields.Add("MakerCode", MakerCode); //编号
  200. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, Id);
  201. }
  202. db.UserDetail.Add(new UserDetail() { Id = Id });
  203. db.UserData.Add(new UserData() { UserId = Id });
  204. AddSysLog(data.Id.ToString(), "Users", "add");
  205. db.SaveChanges();
  206. return "success";
  207. }
  208. #endregion
  209. #region 修改创客
  210. /// <summary>
  211. /// 增加或修改创客信息
  212. /// </summary>
  213. /// <returns></returns>
  214. public IActionResult Edit(string right, int Id = 0)
  215. {
  216. ViewBag.RightInfo = RightInfo;
  217. ViewBag.right = right;
  218. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  219. ViewBag.data = editData;
  220. return View();
  221. }
  222. #endregion
  223. #region 修改创客
  224. /// <summary>
  225. /// 增加或修改创客信息
  226. /// </summary>
  227. /// <returns></returns>
  228. [HttpPost]
  229. public string Edit(Users data, UserDetail userdetail, UserData userdata)
  230. {
  231. Dictionary<string, object> Fields = new Dictionary<string, object>();
  232. Fields.Add("RealName", data.RealName); //真实姓名
  233. Fields.Add("CertId", data.CertId); //身份证号
  234. Fields.Add("Mobile", data.Mobile); //手机号
  235. Fields.Add("SettleBankName", data.SettleBankName); //结算银行名称
  236. Fields.Add("SettleBankCardNo", data.SettleBankCardNo); //结算银行卡号
  237. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, data.Id);
  238. AddSysLog(data.Id.ToString(), "Users", "update");
  239. db.SaveChanges();
  240. return "success";
  241. }
  242. #endregion
  243. #region 修改结算金额
  244. public IActionResult EditSettleAmount(string right, int Id = 0)
  245. {
  246. ViewBag.RightInfo = RightInfo;
  247. ViewBag.right = right;
  248. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  249. ViewBag.data = editData;
  250. return View();
  251. }
  252. #endregion
  253. #region 修改结算金额
  254. [HttpPost]
  255. public string EditSettleAmount(Users data)
  256. {
  257. Dictionary<string, object> Fields = new Dictionary<string, object>();
  258. Fields.Add("SettleAmount", data.SettleAmount);
  259. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, data.Id);
  260. AddSysLog(data.Id.ToString(), "Users", "EditSettleAmount");
  261. db.SaveChanges();
  262. return "success";
  263. }
  264. #endregion
  265. #region 修改账户金额
  266. public IActionResult EditCashFreezeAmt(string right, int Id = 0)
  267. {
  268. ViewBag.RightInfo = RightInfo;
  269. ViewBag.right = right;
  270. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  271. ViewBag.data = editData;
  272. return View();
  273. }
  274. #endregion
  275. #region 修改账户金额
  276. [HttpPost]
  277. public string EditCashFreezeAmt(Users data, string Note, int Kind)
  278. {
  279. int UserId = data.Id;
  280. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  281. if (account == null)
  282. {
  283. account = db.UserAccount.Add(new UserAccount()
  284. {
  285. Id = UserId,
  286. UserId = UserId,
  287. }).Entity;
  288. db.SaveChanges();
  289. }
  290. if ((Kind == 1 || Kind == 3) && data.CashFreezeAmt > account.BalanceAmount)
  291. {
  292. return "账号余额不足";
  293. }
  294. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  295. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  296. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  297. int ChangeType = 0;
  298. if (Kind == 1)
  299. {
  300. account.BalanceAmount -= data.CashFreezeAmt;
  301. account.FreezeAmount += data.CashFreezeAmt;
  302. ChangeType = 61;
  303. }
  304. else if (Kind == 2)
  305. {
  306. account.BalanceAmount += data.CashFreezeAmt;
  307. account.FreezeAmount -= data.CashFreezeAmt;
  308. ChangeType = 62;
  309. }
  310. else if (Kind == 3)
  311. {
  312. account.TotalAmount -= data.CashFreezeAmt;
  313. account.BalanceAmount -= data.CashFreezeAmt;
  314. ChangeType = 63;
  315. }
  316. else if (Kind == 4)
  317. {
  318. account.TotalAmount += data.CashFreezeAmt;
  319. account.BalanceAmount += data.CashFreezeAmt;
  320. ChangeType = 64;
  321. }
  322. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  323. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  324. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  325. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  326. {
  327. CreateDate = DateTime.Now,
  328. UpdateDate = DateTime.Now,
  329. UserId = UserId, //创客
  330. ChangeType = ChangeType, //变动类型
  331. ChangeAmount = data.CashFreezeAmt, //变更金额
  332. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  333. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  334. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  335. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  336. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  337. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  338. Remark = Note,
  339. }).Entity;
  340. db.SaveChanges();
  341. RedisDbconn.Instance.Set("UserAccount:" + UserId, account);
  342. AddSysLog(data.Id.ToString(), "Users", "EditCashFreezeAmt");
  343. db.SaveChanges();
  344. return "success";
  345. }
  346. #endregion
  347. #region 账户操作
  348. public IActionResult EditBalance(string right, int Id = 0)
  349. {
  350. ViewBag.RightInfo = RightInfo;
  351. ViewBag.right = right;
  352. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  353. ViewBag.data = editData;
  354. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == Id) ?? new UserAccount();
  355. ViewBag.account = account;
  356. return View();
  357. }
  358. #endregion
  359. #region 账户操作
  360. [HttpPost]
  361. public string EditBalance(UserAccount data)
  362. {
  363. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == data.Id);
  364. if (account != null)
  365. {
  366. decimal amount = data.BalanceAmount - account.BalanceAmount;
  367. if (amount != 0)
  368. {
  369. account.BalanceAmount += amount;
  370. account.TotalAmount += amount;
  371. AddSysLog(data.Id.ToString(), "UserAccount", "EditBalance");
  372. db.SaveChanges();
  373. }
  374. }
  375. return "success";
  376. }
  377. #endregion
  378. #region 详情
  379. public IActionResult Detail(string right, int Id = 0)
  380. {
  381. ViewBag.RightInfo = RightInfo;
  382. ViewBag.right = right;
  383. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  384. ViewBag.AuthDate = editData.AuthDate == null ? "" : editData.AuthDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  385. string Age = "";
  386. if (!string.IsNullOrEmpty(editData.CertId))
  387. {
  388. int year = DateTime.Now.Year - int.Parse(editData.CertId.Substring(6, 4));
  389. Age = year.ToString();
  390. }
  391. ViewBag.Age = Age;
  392. ViewBag.QrCode = string.IsNullOrEmpty(editData.ReferenceQrCode) ? defaultImage : SourceHost + editData.ReferenceQrCode;
  393. return View();
  394. }
  395. #endregion
  396. #region 三/四要素验证
  397. public IActionResult ThreeElement(string right)
  398. {
  399. ViewBag.RightInfo = RightInfo;
  400. ViewBag.right = right;
  401. return View();
  402. }
  403. #endregion
  404. #region 三/四要素验证
  405. [HttpPost]
  406. public string ThreeElement(string Name, string CertId, string CardNo, string Mobile)
  407. {
  408. return "success";
  409. }
  410. #endregion
  411. #region 删除创客信息
  412. /// <summary>
  413. /// 删除创客信息
  414. /// </summary>
  415. /// <returns></returns>
  416. public string Delete(string Id)
  417. {
  418. string[] idlist = Id.Split(new char[] { ',' });
  419. AddSysLog(Id, "Users", "del");
  420. foreach (string subid in idlist)
  421. {
  422. int id = int.Parse(subid);
  423. Dictionary<string, object> Fields = new Dictionary<string, object>();
  424. Fields.Add("Status", -1);
  425. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  426. }
  427. db.SaveChanges();
  428. return "success";
  429. }
  430. #endregion
  431. #region 开启
  432. /// <summary>
  433. /// 开启
  434. /// </summary>
  435. /// <returns></returns>
  436. public string Open(string Id)
  437. {
  438. string[] idlist = Id.Split(new char[] { ',' });
  439. AddSysLog(Id, "Users", "open");
  440. foreach (string subid in idlist)
  441. {
  442. int id = int.Parse(subid);
  443. Dictionary<string, object> Fields = new Dictionary<string, object>();
  444. Fields.Add("Status", 1);
  445. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  446. }
  447. db.SaveChanges();
  448. return "success";
  449. }
  450. #endregion
  451. #region 关闭
  452. /// <summary>
  453. /// 关闭
  454. /// </summary>
  455. /// <returns></returns>
  456. public string Close(string Id)
  457. {
  458. string[] idlist = Id.Split(new char[] { ',' });
  459. AddSysLog(Id, "Users", "close");
  460. foreach (string subid in idlist)
  461. {
  462. int id = int.Parse(subid);
  463. Dictionary<string, object> Fields = new Dictionary<string, object>();
  464. Fields.Add("Status", 0);
  465. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  466. }
  467. db.SaveChanges();
  468. return "success";
  469. }
  470. #endregion
  471. #region 风控
  472. public IActionResult Risk(string right, int Id = 0)
  473. {
  474. ViewBag.RightInfo = RightInfo;
  475. ViewBag.right = right;
  476. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  477. ViewBag.data = editData;
  478. return View();
  479. }
  480. #endregion
  481. #region 风控
  482. [HttpPost]
  483. public string Risk(Users data)
  484. {
  485. Users user = db.Users.FirstOrDefault(m => m.Id == data.Id);
  486. if (user != null)
  487. {
  488. user.RiskFlag = data.RiskFlag;
  489. user.RiskRemark = data.RiskRemark;
  490. db.SaveChanges();
  491. }
  492. return "success";
  493. }
  494. #endregion
  495. #region 解除风控
  496. public string UnRisk(string Id)
  497. {
  498. string[] idlist = Id.Split(new char[] { ',' });
  499. AddSysLog(Id, "Users", "UnRisk");
  500. foreach (string subid in idlist)
  501. {
  502. int id = int.Parse(subid);
  503. Dictionary<string, object> Fields = new Dictionary<string, object>();
  504. Fields.Add("RiskFlag", 0);
  505. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  506. }
  507. db.SaveChanges();
  508. return "success";
  509. }
  510. #endregion
  511. #region 重置密码
  512. public string ResetPwd(int Id)
  513. {
  514. string NewPwd = function.get_Random(6);
  515. Dictionary<string, object> Fields = new Dictionary<string, object>();
  516. Fields.Add("LoginPwd", function.MD532(NewPwd));
  517. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, Id);
  518. AddSysLog(Id, "Users", "ResetPwd");
  519. RedisDbconn.Instance.Clear("Users:" + Id);
  520. return "success|" + NewPwd;
  521. }
  522. #endregion
  523. #region 排序
  524. /// <summary>
  525. /// 排序
  526. /// </summary>
  527. /// <param name="Id"></param>
  528. public string Sort(int Id, int Sort)
  529. {
  530. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("Users", Sort, Id);
  531. AddSysLog(Id.ToString(), "Users", "sort");
  532. return "success";
  533. }
  534. #endregion
  535. #region 导入数据
  536. /// <summary>
  537. /// 导入数据
  538. /// </summary>
  539. /// <param name="ExcelData"></param>
  540. public string Import(string ExcelData, int Kind = 0)
  541. {
  542. ExcelData = HttpUtility.UrlDecode(ExcelData);
  543. JsonData list = JsonMapper.ToObject(ExcelData);
  544. if (Kind == 1)
  545. {
  546. for (int i = 1; i < list.Count; i++)
  547. {
  548. JsonData dr = list[i];
  549. string MakerCode = dr[0].ToString();
  550. string SettleAmount = dr[2].ToString();
  551. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  552. if (UserCode != null)
  553. {
  554. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  555. if (User != null)
  556. {
  557. User.SettleAmount = decimal.Parse(function.CheckInt(SettleAmount));
  558. }
  559. }
  560. }
  561. db.SaveChanges();
  562. }
  563. else if (Kind == 2)
  564. {
  565. for (int i = 1; i < list.Count; i++)
  566. {
  567. JsonData dr = list[i];
  568. string MakerCode = dr[0].ToString();
  569. string CashFreezeAmt = dr[2].ToString();
  570. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  571. if (UserCode != null)
  572. {
  573. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  574. if (User != null)
  575. {
  576. User.CashFreezeAmt = decimal.Parse(function.CheckInt(CashFreezeAmt));
  577. }
  578. }
  579. }
  580. db.SaveChanges();
  581. }
  582. else if (Kind == 3)
  583. {
  584. for (int i = 1; i < list.Count; i++)
  585. {
  586. JsonData dr = list[i];
  587. string MakerCode = dr[0].ToString();
  588. string RiskFlag = dr[2].ToString();
  589. string RiskNote = dr[3].ToString();
  590. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  591. if (UserCode != null)
  592. {
  593. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  594. if (User != null)
  595. {
  596. User.RiskFlag = ulong.Parse(function.CheckInt(RiskFlag));
  597. User.RiskRemark = RiskNote;
  598. }
  599. }
  600. }
  601. db.SaveChanges();
  602. }
  603. AddSysLog("0", "Users", "Import");
  604. return "success";
  605. }
  606. #endregion
  607. #region 导出Excel
  608. /// <summary>
  609. /// 导出Excel
  610. /// </summary>
  611. /// <returns></returns>
  612. public JsonResult ExportExcel(Users data, string CreateDate, string ParentMakerCode, string ParentRealName, string AuthFlagSelect, int TopUserId, string RiskFlagSelect, string MerchantTypeSelect, int SelfId = 0, int ParentId = 0)
  613. {
  614. Dictionary<string, string> Fields = new Dictionary<string, string>();
  615. Fields.Add("MakerCode", "1"); //创客编号
  616. Fields.Add("RealName", "1"); //创客名称
  617. Fields.Add("Mobile", "1"); //手机号
  618. Fields.Add("CertId", "1"); //身份证号码
  619. Fields.Add("CreateDate", "3"); //注册时间
  620. Fields.Add("SettleAmount", "3"); //结算金额
  621. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  622. Fields.Add("UserLevel", "0"); //创客等级
  623. string condition = " and Status>-1";
  624. //直属创客编号
  625. if (!string.IsNullOrEmpty(ParentMakerCode))
  626. {
  627. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  628. }
  629. //直属创客名称
  630. if (!string.IsNullOrEmpty(ParentRealName))
  631. {
  632. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  633. }
  634. //实名状态
  635. if(!string.IsNullOrEmpty(AuthFlagSelect))
  636. {
  637. condition += " and AuthFlag=" + AuthFlagSelect;
  638. }
  639. //顶级创客
  640. if(TopUserId > 0)
  641. {
  642. condition += " and ParentNav like '," + TopUserId + ",%'";
  643. }
  644. //风控标识
  645. if(!string.IsNullOrEmpty(RiskFlagSelect))
  646. {
  647. condition += " and RiskFlag=" + RiskFlagSelect;
  648. }
  649. //商户创客类型
  650. if(!string.IsNullOrEmpty(MerchantTypeSelect))
  651. {
  652. condition += " and MerchantType=" + MerchantTypeSelect;
  653. }
  654. if (SelfId > 0)
  655. {
  656. Users self = db.Users.FirstOrDefault(m => m.Id == SelfId);
  657. if (self != null)
  658. {
  659. string ParentNav = function.CheckNull(self.ParentNav);
  660. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  661. }
  662. }
  663. if (ParentId > 0)
  664. {
  665. condition += " and ParentUserId=" + ParentId;
  666. }
  667. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", 1, 20000, condition, "ParentUserId,ParentNav,UserLevel,SettleAmount,CashFreezeAmt,CertId,Mobile,MerchantType,MerchantDate,AuthFlag,RiskFlag,CreateDate", false);
  668. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  669. foreach (Dictionary<string, object> dic in diclist)
  670. {
  671. dic["AuthFlag"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  672. dic["RiskFlag"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  673. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  674. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  675. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  676. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  677. dic["ParentMakerCode"] = puser.MakerCode;
  678. dic["ParentRealName"] = puser.RealName;
  679. string ParentNav = dic["ParentNav"].ToString();
  680. if (!string.IsNullOrEmpty(ParentNav))
  681. {
  682. string[] list = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  683. if (list.Length > 1)
  684. {
  685. int TopId = int.Parse(function.CheckInt(list[1]));
  686. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  687. dic["TopMakerCode"] = tuser.MakerCode;
  688. dic["TopRealName"] = tuser.RealName;
  689. }
  690. }
  691. dic.Remove("ParentUserId");
  692. dic.Remove("ParentNav");
  693. }
  694. Dictionary<string, object> result = new Dictionary<string, object>();
  695. result.Add("Status", "1");
  696. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  697. result.Add("Obj", diclist);
  698. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  699. ReturnFields.Add("MakerCode", "创客编号");
  700. ReturnFields.Add("RealName", "创客姓名");
  701. ReturnFields.Add("UserLevel", "创客等级");
  702. ReturnFields.Add("SettleAmount", "提现金额(元)");
  703. ReturnFields.Add("CashFreezeAmt", "冻结金额(元)");
  704. ReturnFields.Add("CertId", "身份证号");
  705. ReturnFields.Add("Mobile", "联系手机");
  706. ReturnFields.Add("MerchantType", "商户创客类型");
  707. ReturnFields.Add("MerchantDate", "成为商户创客时间");
  708. ReturnFields.Add("ParentMakerCode", "直属创客编号");
  709. ReturnFields.Add("ParentRealName", "直属创客名称");
  710. ReturnFields.Add("TopMakerCode", "顶级创客编号");
  711. ReturnFields.Add("TopRealName", "顶级创客名称");
  712. ReturnFields.Add("AuthFlag", "实名状态");
  713. ReturnFields.Add("RiskFlag", "风控状态");
  714. ReturnFields.Add("CreateDate", "注册时间");
  715. result.Add("Fields", ReturnFields);
  716. AddSysLog("0", "Users", "ExportExcel");
  717. return Json(result);
  718. }
  719. #endregion
  720. #region 同步数据
  721. /// <summary>
  722. /// 同步数据
  723. /// </summary>
  724. /// <returns></returns>
  725. public string SycnData(int Id = 0)
  726. {
  727. var Brands = db.KqProducts.Where(m => m.Status == 1).ToList();
  728. foreach (var Brand in Brands)
  729. {
  730. string IdBrand = Id + "_" + Brand.Id;
  731. UserMachineData machineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  732. if (machineData == null)
  733. {
  734. machineData = db.UserMachineData.Add(new UserMachineData()
  735. {
  736. IdBrand = IdBrand
  737. }).Entity;
  738. db.SaveChanges();
  739. }
  740. machineData.BindCount = db.PosMachinesTwo.Count(m => m.BuyUserId == Id && m.BrandId == Brand.Id && m.BindingState == 1);
  741. machineData.UnBindCount = db.PosMachinesTwo.Count(m => m.BuyUserId == Id && m.BrandId == Brand.Id && m.BindingState == 0);
  742. machineData.TotalMachineCount = machineData.BindCount + machineData.UnBindCount;
  743. db.SaveChanges();
  744. // RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, machineData);
  745. // RedisDbconn.Instance.SetExpire("UserMachineData:" + IdBrand, function.get_Random(1800, 5400));
  746. }
  747. AddSysLog(Id, "Users", "SycnData");
  748. db.SaveChanges();
  749. return "success";
  750. }
  751. #endregion
  752. #region 同步交易额
  753. public IActionResult SycnTradeAmount(string right, int Id = 0)
  754. {
  755. ViewBag.RightInfo = RightInfo;
  756. ViewBag.right = right;
  757. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  758. ViewBag.data = editData;
  759. return View();
  760. }
  761. #endregion
  762. #region 同步交易额
  763. [HttpPost]
  764. public string SycnTradeAmountDo(DateTime sdate, DateTime edate, int UserId, int BrandId)
  765. {
  766. if (sdate.AddMonths(1) < edate)
  767. {
  768. return "时间间隔不能超过1个月";
  769. }
  770. if (edate >= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"))
  771. {
  772. return "结束时间只能是今天之前";
  773. }
  774. string check = RedisDbconn.Instance.Get<string>("ResetUserTradeQueue:" + UserId + ":" + BrandId);
  775. if (!string.IsNullOrEmpty(check))
  776. {
  777. return "请稍后再试";
  778. }
  779. try
  780. {
  781. RedisDbconn.Instance.AddList("ResetUserTradeQueue", UserId + "#cut#" + sdate.ToString("yyyy-MM-dd HH:mm:ss") + "#cut#" + edate.ToString("yyyy-MM-dd HH:mm:ss") + "#cut#" + BrandId);
  782. RedisDbconn.Instance.Set("ResetUserTradeQueue:" + UserId + ":" + BrandId, "wait");
  783. RedisDbconn.Instance.SetExpire("ResetUserTradeQueue:" + UserId + ":" + BrandId, 3600);
  784. }
  785. catch (Exception ex)
  786. {
  787. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计创客的交易额异常");
  788. return "同步异常";
  789. }
  790. return "success";
  791. }
  792. #endregion
  793. #region 创客展业城市
  794. public IActionResult City(Users data, string right)
  795. {
  796. ViewBag.RightInfo = RightInfo;
  797. ViewBag.right = right;
  798. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  799. ViewBag.TopUsers = TopUsers;
  800. return View();
  801. }
  802. #endregion
  803. #region 根据条件查询创客展业城市
  804. public JsonResult CityData(Users data, string ParentMakerCode, string ParentRealName, int TopUserId, string Areas, int page = 1, int limit = 30)
  805. {
  806. Dictionary<string, string> Fields = new Dictionary<string, string>();
  807. Fields.Add("MakerCode", "1"); //创客编号
  808. Fields.Add("RealName", "1"); //创客名称
  809. Fields.Add("CitySetDate", "3"); //创建时间
  810. Fields.Add("Areas", "2"); //省市
  811. string condition = " and Status>-1";
  812. //直属创客编号
  813. if (!string.IsNullOrEmpty(ParentMakerCode))
  814. {
  815. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  816. }
  817. //直属创客名称
  818. if (!string.IsNullOrEmpty(ParentRealName))
  819. {
  820. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  821. }
  822. //顶级创客
  823. if(TopUserId > 0)
  824. {
  825. condition += " and ParentNav like '," + TopUserId + ",%'";
  826. }
  827. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", page, limit, condition);
  828. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  829. foreach (Dictionary<string, object> dic in diclist)
  830. {
  831. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  832. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  833. dic["ParentMakerCode"] = puser.MakerCode;
  834. dic["ParentRealName"] = puser.RealName;
  835. string ParentNav = dic["ParentNav"].ToString();
  836. if (!string.IsNullOrEmpty(ParentNav))
  837. {
  838. int TopId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  839. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  840. dic["TopMakerCode"] = tuser.MakerCode;
  841. dic["TopRealName"] = tuser.RealName;
  842. }
  843. }
  844. return Json(obj);
  845. }
  846. #endregion
  847. #region 导出展业城市
  848. public JsonResult ExportCity(Users data, string CreateDate, string ParentMakerCode, string ParentRealName, string AuthFlagSelect, int TopUserId, string RiskFlagSelect, string MerchantTypeSelect)
  849. {
  850. Dictionary<string, string> Fields = new Dictionary<string, string>();
  851. Fields.Add("MakerCode", "1"); //创客编号
  852. Fields.Add("RealName", "1"); //创客名称
  853. Fields.Add("Mobile", "1"); //手机号
  854. Fields.Add("CertId", "1"); //身份证号码
  855. Fields.Add("CreateDate", "3"); //注册时间
  856. Fields.Add("SettleAmount", "3"); //结算金额
  857. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  858. Fields.Add("UserLevel", "0"); //创客等级
  859. string condition = " and Status>-1";
  860. //直属创客编号
  861. if (!string.IsNullOrEmpty(ParentMakerCode))
  862. {
  863. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  864. }
  865. //直属创客名称
  866. if (!string.IsNullOrEmpty(ParentRealName))
  867. {
  868. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  869. }
  870. //实名状态
  871. if(!string.IsNullOrEmpty(AuthFlagSelect))
  872. {
  873. condition += " and AuthFlag=" + AuthFlagSelect;
  874. }
  875. //顶级创客
  876. if(TopUserId > 0)
  877. {
  878. condition += " and ParentNav like '," + TopUserId + ",%'";
  879. }
  880. //风控标识
  881. if(!string.IsNullOrEmpty(RiskFlagSelect))
  882. {
  883. condition += " and RiskFlag=" + RiskFlagSelect;
  884. }
  885. //商户创客类型
  886. if(!string.IsNullOrEmpty(MerchantTypeSelect))
  887. {
  888. condition += " and MerchantType=" + MerchantTypeSelect;
  889. }
  890. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", 1, 20000, condition, "ParentUserId,ParentNav,UserLevel,SettleAmount,CashFreezeAmt,CertId,Mobile,MerchantType,MerchantDate,AuthFlag,RiskFlag,CreateDate", false);
  891. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  892. foreach (Dictionary<string, object> dic in diclist)
  893. {
  894. dic["AuthFlag"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  895. dic["RiskFlag"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  896. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  897. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  898. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  899. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  900. dic["ParentMakerCode"] = puser.MakerCode;
  901. dic["ParentRealName"] = puser.RealName;
  902. string ParentNav = dic["ParentNav"].ToString();
  903. if (!string.IsNullOrEmpty(ParentNav))
  904. {
  905. int TopId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  906. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  907. dic["TopMakerCode"] = tuser.MakerCode;
  908. dic["TopRealName"] = tuser.RealName;
  909. }
  910. dic.Remove("ParentUserId");
  911. dic.Remove("ParentNav");
  912. }
  913. Dictionary<string, object> result = new Dictionary<string, object>();
  914. result.Add("Status", "1");
  915. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  916. result.Add("Obj", diclist);
  917. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  918. ReturnFields.Add("MakerCode", "创客编号");
  919. ReturnFields.Add("RealName", "创客姓名");
  920. ReturnFields.Add("UserLevel", "创客等级");
  921. ReturnFields.Add("SettleAmount", "提现金额(元)");
  922. ReturnFields.Add("CashFreezeAmt", "冻结金额(元)");
  923. ReturnFields.Add("CertId", "身份证号");
  924. ReturnFields.Add("Mobile", "联系手机");
  925. ReturnFields.Add("MerchantType", "商户创客类型");
  926. ReturnFields.Add("MerchantDate", "成为商户创客时间");
  927. ReturnFields.Add("ParentMakerCode", "直属创客编号");
  928. ReturnFields.Add("ParentRealName", "直属创客名称");
  929. ReturnFields.Add("TopMakerCode", "顶级创客编号");
  930. ReturnFields.Add("TopRealName", "顶级创客名称");
  931. ReturnFields.Add("AuthFlag", "实名状态");
  932. ReturnFields.Add("RiskFlag", "风控状态");
  933. ReturnFields.Add("CreateDate", "注册时间");
  934. result.Add("Fields", ReturnFields);
  935. AddSysLog("0", "Users", "ExportExcel");
  936. return Json(result);
  937. }
  938. #endregion
  939. }
  940. }