UsersController.cs 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  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, string CreateDateData, int TopUserId, string RiskFlagSelect, string MerchantTypeSelect, int? sSettleAmount, int? eSettleAmount, int? sCashFreezeAmt, int? eCashFreezeAmt, int UserId, 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("SettleAmount", "3"); //结算金额
  61. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  62. Fields.Add("UserLevel", "0"); //创客等级
  63. string condition = " and Status>-1";
  64. string sort = "Id desc";
  65. //直属创客编号
  66. if (!string.IsNullOrEmpty(ParentMakerCode))
  67. {
  68. condition += " and ParentUserId in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  69. }
  70. //直属创客名称
  71. if (!string.IsNullOrEmpty(ParentRealName))
  72. {
  73. condition += " and ParentUserId in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  74. }
  75. //实名状态
  76. if (!string.IsNullOrEmpty(AuthFlagSelect))
  77. {
  78. condition += " and AuthFlag=" + AuthFlagSelect;
  79. }
  80. //顶级创客
  81. if (TopUserId > 0)
  82. {
  83. condition += " and ParentNav like '," + TopUserId + ",%'";
  84. }
  85. //风控标识
  86. if (!string.IsNullOrEmpty(RiskFlagSelect))
  87. {
  88. condition += " and RiskFlag=" + RiskFlagSelect;
  89. }
  90. //商户创客类型
  91. if (!string.IsNullOrEmpty(MerchantTypeSelect))
  92. {
  93. condition += " and MerchantType=" + MerchantTypeSelect;
  94. }
  95. if (sSettleAmount != null)
  96. {
  97. condition += " and SettleAmount>=" + sSettleAmount.Value;
  98. }
  99. if (eSettleAmount != null)
  100. {
  101. condition += " and SettleAmount<=" + eSettleAmount.Value;
  102. }
  103. if (sCashFreezeAmt != null)
  104. {
  105. condition += " and CashFreezeAmt>=" + sCashFreezeAmt.Value;
  106. }
  107. if (eCashFreezeAmt != null)
  108. {
  109. condition += " and CashFreezeAmt<=" + eCashFreezeAmt.Value;
  110. }
  111. if (SelfId > 0)
  112. {
  113. Users self = db.Users.FirstOrDefault(m => m.Id == SelfId);
  114. if (self != null)
  115. {
  116. string ParentNav = function.CheckNull(self.ParentNav);
  117. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  118. sort = "ParentNav asc";
  119. }
  120. }
  121. if (ParentId > 0)
  122. {
  123. condition += " and ParentUserId=" + ParentId;
  124. }
  125. if (UserId > 0)
  126. {
  127. condition += " and Id=" + UserId;
  128. }
  129. if (!string.IsNullOrEmpty(CreateDateData))
  130. {
  131. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  132. string start = datelist[0];
  133. string end = datelist[1];
  134. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  135. }
  136. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, sort, "True", page, limit, condition);
  137. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  138. foreach (Dictionary<string, object> dic in diclist)
  139. {
  140. dic["AuthFlagName"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  141. dic["RiskFlagName"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  142. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  143. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  144. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  145. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  146. dic["ParentMakerCode"] = puser.MakerCode;
  147. dic["ParentRealName"] = puser.RealName;
  148. string ParentNav = dic["ParentNav"].ToString();
  149. if (!string.IsNullOrEmpty(ParentNav))
  150. {
  151. string[] list = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  152. if (list.Length > 1)
  153. {
  154. int TopId = int.Parse(function.CheckInt(list[1]));
  155. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  156. dic["TopMakerCode"] = tuser.MakerCode;
  157. dic["TopRealName"] = tuser.RealName;
  158. }
  159. }
  160. }
  161. return Json(obj);
  162. }
  163. #endregion
  164. #region 增加创客
  165. /// <summary>
  166. /// 增加或修改创客信息
  167. /// </summary>
  168. /// <returns></returns>
  169. public IActionResult Add(string right)
  170. {
  171. ViewBag.RightInfo = RightInfo;
  172. ViewBag.right = right;
  173. return View();
  174. }
  175. #endregion
  176. #region 增加创客
  177. /// <summary>
  178. /// 增加或修改创客信息
  179. /// </summary>
  180. /// <returns></returns>
  181. [HttpPost]
  182. public string Add(Users data, string ParentMakerCode)
  183. {
  184. bool check = db.UserForMobile.Any(m => m.Mobile == data.Mobile);
  185. if (check)
  186. {
  187. return "手机号已存在,请重新输入";
  188. }
  189. check = db.UserForRealName.Any(m => m.RealName == data.RealName);
  190. if (check)
  191. {
  192. return "姓名已存在,请重新输入";
  193. }
  194. if (!string.IsNullOrEmpty(data.MakerCode))
  195. {
  196. check = db.UserForMakerCode.Any(m => m.MakerCode == data.MakerCode);
  197. if (check)
  198. {
  199. return "创客编码已存在,请重新输入";
  200. }
  201. }
  202. Dictionary<string, object> Fields = new Dictionary<string, object>();
  203. Fields.Add("RealName", data.RealName); //真实姓名
  204. Fields.Add("CertId", data.CertId); //身份证号
  205. Fields.Add("Mobile", data.Mobile); //手机号
  206. Fields.Add("LoginPwd", function.MD532(data.LoginPwd)); //登录密码
  207. Fields.Add("SettleBankCardNo", data.SettleBankCardNo); //结算银行卡号
  208. if (!string.IsNullOrEmpty(ParentMakerCode))
  209. {
  210. UserForMakerCode userFor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ParentMakerCode) ?? new UserForMakerCode();
  211. Users puser = db.Users.FirstOrDefault(m => m.Id == userFor.UserId) ?? new Users();
  212. Fields.Add("ParentUserId", userFor.UserId);
  213. Fields.Add("ParentNav", puser.ParentNav + "," + userFor.UserId + ",");
  214. }
  215. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("Users", Fields, 0);
  216. if (string.IsNullOrEmpty(ParentMakerCode))
  217. {
  218. string MakerCode = Id.ToString();
  219. for (int i = 0; i < 7 - Id.ToString().Length; i++)
  220. {
  221. MakerCode = "0" + MakerCode;
  222. }
  223. MakerCode = "K" + MakerCode;
  224. Fields = new Dictionary<string, object>();
  225. Fields.Add("MakerCode", MakerCode); //编号
  226. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, Id);
  227. }
  228. db.UserDetail.Add(new UserDetail() { Id = Id });
  229. db.UserData.Add(new UserData() { UserId = Id });
  230. AddSysLog(data.Id.ToString(), "Users", "add");
  231. db.SaveChanges();
  232. return "success";
  233. }
  234. #endregion
  235. #region 修改创客
  236. /// <summary>
  237. /// 增加或修改创客信息
  238. /// </summary>
  239. /// <returns></returns>
  240. public IActionResult Edit(string right, int Id = 0)
  241. {
  242. ViewBag.RightInfo = RightInfo;
  243. ViewBag.right = right;
  244. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  245. ViewBag.data = editData;
  246. return View();
  247. }
  248. #endregion
  249. #region 修改创客
  250. /// <summary>
  251. /// 增加或修改创客信息
  252. /// </summary>
  253. /// <returns></returns>
  254. [HttpPost]
  255. public string Edit(Users data, UserDetail userdetail, UserData userdata)
  256. {
  257. Dictionary<string, object> Fields = new Dictionary<string, object>();
  258. Fields.Add("RealName", data.RealName); //真实姓名
  259. Fields.Add("CertId", data.CertId); //身份证号
  260. Fields.Add("Mobile", data.Mobile); //手机号
  261. Fields.Add("SettleBankName", data.SettleBankName); //结算银行名称
  262. Fields.Add("SettleBankCardNo", data.SettleBankCardNo); //结算银行卡号
  263. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, data.Id);
  264. AddSysLog(data.Id.ToString(), "Users", "update");
  265. db.SaveChanges();
  266. return "success";
  267. }
  268. #endregion
  269. #region 修改结算金额
  270. public IActionResult EditSettleAmount(string right, int Id = 0)
  271. {
  272. ViewBag.RightInfo = RightInfo;
  273. ViewBag.right = right;
  274. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  275. ViewBag.data = editData;
  276. return View();
  277. }
  278. #endregion
  279. #region 修改结算金额
  280. [HttpPost]
  281. public string EditSettleAmount(Users data)
  282. {
  283. Dictionary<string, object> Fields = new Dictionary<string, object>();
  284. Fields.Add("SettleAmount", data.SettleAmount);
  285. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, data.Id);
  286. AddSysLog(data.Id.ToString(), "Users", "EditSettleAmount");
  287. db.SaveChanges();
  288. return "success";
  289. }
  290. #endregion
  291. #region 修改账户金额
  292. public IActionResult EditCashFreezeAmt(string right, int Id = 0)
  293. {
  294. ViewBag.RightInfo = RightInfo;
  295. ViewBag.right = right;
  296. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  297. ViewBag.data = editData;
  298. return View();
  299. }
  300. #endregion
  301. #region 修改账户金额
  302. [HttpPost]
  303. public string EditCashFreezeAmt(Users data, string Note, int Kind)
  304. {
  305. int UserId = data.Id;
  306. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  307. if (account == null)
  308. {
  309. account = db.UserAccount.Add(new UserAccount()
  310. {
  311. Id = UserId,
  312. UserId = UserId,
  313. }).Entity;
  314. db.SaveChanges();
  315. }
  316. if ((Kind == 1 || Kind == 3) && data.CashFreezeAmt > account.BalanceAmount)
  317. {
  318. return "账号余额不足";
  319. }
  320. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  321. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  322. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  323. int ChangeType = 0;
  324. if (Kind == 1 && data.CashFreezeAmt <= account.BalanceAmount)
  325. {
  326. account.BalanceAmount -= data.CashFreezeAmt;
  327. account.FreezeAmount += data.CashFreezeAmt;
  328. ChangeType = 61;
  329. }
  330. else if (Kind == 1 && data.CashFreezeAmt > account.BalanceAmount)
  331. {
  332. return "冻结金额大于余额";
  333. }
  334. else if (Kind == 2 && data.CashFreezeAmt <= account.FreezeAmount)
  335. {
  336. account.BalanceAmount += data.CashFreezeAmt;
  337. account.FreezeAmount -= data.CashFreezeAmt;
  338. ChangeType = 62;
  339. }
  340. else if (Kind == 2 && data.CashFreezeAmt > account.FreezeAmount)
  341. {
  342. return "解冻金额大于冻结金额";
  343. }
  344. else if (Kind == 3 && data.CashFreezeAmt <= account.BalanceAmount)
  345. {
  346. account.TotalAmount -= data.CashFreezeAmt;
  347. account.BalanceAmount -= data.CashFreezeAmt;
  348. ChangeType = 63;
  349. }
  350. else if (Kind == 3 && data.CashFreezeAmt > account.BalanceAmount)
  351. {
  352. return "扣减金额大于余额";
  353. }
  354. else if (Kind == 4)
  355. {
  356. account.TotalAmount += data.CashFreezeAmt;
  357. account.BalanceAmount += data.CashFreezeAmt;
  358. ChangeType = 64;
  359. }
  360. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  361. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  362. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  363. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  364. {
  365. CreateDate = DateTime.Now,
  366. UpdateDate = DateTime.Now,
  367. UserId = UserId, //创客
  368. ChangeType = ChangeType, //变动类型
  369. ChangeAmount = data.CashFreezeAmt, //变更金额
  370. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  371. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  372. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  373. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  374. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  375. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  376. Remark = Note,
  377. }).Entity;
  378. db.SaveChanges();
  379. RedisDbconn.Instance.Set("UserAccount:" + UserId, account);
  380. AddSysLog(data.Id.ToString(), "Users", "EditCashFreezeAmt");
  381. db.SaveChanges();
  382. return "success";
  383. }
  384. #endregion
  385. #region 账户操作
  386. public IActionResult EditBalance(string right, int Id = 0)
  387. {
  388. ViewBag.RightInfo = RightInfo;
  389. ViewBag.right = right;
  390. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  391. ViewBag.data = editData;
  392. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == Id) ?? new UserAccount();
  393. ViewBag.account = account;
  394. return View();
  395. }
  396. #endregion
  397. #region 账户操作
  398. [HttpPost]
  399. public string EditBalance(UserAccount data)
  400. {
  401. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == data.Id);
  402. if (account != null)
  403. {
  404. decimal amount = data.BalanceAmount - account.BalanceAmount;
  405. if (amount != 0)
  406. {
  407. account.BalanceAmount += amount;
  408. account.TotalAmount += amount;
  409. AddSysLog(data.Id.ToString(), "UserAccount", "EditBalance");
  410. db.SaveChanges();
  411. }
  412. }
  413. return "success";
  414. }
  415. #endregion
  416. #region 详情
  417. public IActionResult Detail(string right, int Id = 0)
  418. {
  419. ViewBag.RightInfo = RightInfo;
  420. ViewBag.right = right;
  421. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  422. ViewBag.AuthDate = editData.AuthDate == null ? "" : editData.AuthDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  423. string Age = "";
  424. if (!string.IsNullOrEmpty(editData.CertId))
  425. {
  426. int year = DateTime.Now.Year - int.Parse(editData.CertId.Substring(6, 4));
  427. Age = year.ToString();
  428. }
  429. ViewBag.Age = Age;
  430. ViewBag.QrCode = string.IsNullOrEmpty(editData.ReferenceQrCode) ? defaultImage : SourceHost + editData.ReferenceQrCode;
  431. return View();
  432. }
  433. #endregion
  434. #region 三/四要素验证
  435. public IActionResult ThreeElement(string right)
  436. {
  437. ViewBag.RightInfo = RightInfo;
  438. ViewBag.right = right;
  439. return View();
  440. }
  441. #endregion
  442. #region 三/四要素验证
  443. [HttpPost]
  444. public string ThreeElement(string Name, string CertId, string CardNo, string Mobile)
  445. {
  446. return "success";
  447. }
  448. #endregion
  449. #region 删除创客信息
  450. /// <summary>
  451. /// 删除创客信息
  452. /// </summary>
  453. /// <returns></returns>
  454. public string Delete(string Id)
  455. {
  456. string[] idlist = Id.Split(new char[] { ',' });
  457. AddSysLog(Id, "Users", "del");
  458. foreach (string subid in idlist)
  459. {
  460. int id = int.Parse(subid);
  461. Dictionary<string, object> Fields = new Dictionary<string, object>();
  462. Fields.Add("Status", -1);
  463. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  464. }
  465. db.SaveChanges();
  466. return "success";
  467. }
  468. #endregion
  469. #region 开启
  470. /// <summary>
  471. /// 开启
  472. /// </summary>
  473. /// <returns></returns>
  474. public string Open(string Id)
  475. {
  476. string[] idlist = Id.Split(new char[] { ',' });
  477. AddSysLog(Id, "Users", "open");
  478. foreach (string subid in idlist)
  479. {
  480. int id = int.Parse(subid);
  481. Dictionary<string, object> Fields = new Dictionary<string, object>();
  482. Fields.Add("Status", 1);
  483. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  484. }
  485. db.SaveChanges();
  486. return "success";
  487. }
  488. #endregion
  489. #region 关闭
  490. /// <summary>
  491. /// 关闭
  492. /// </summary>
  493. /// <returns></returns>
  494. public string Close(string Id)
  495. {
  496. string[] idlist = Id.Split(new char[] { ',' });
  497. AddSysLog(Id, "Users", "close");
  498. foreach (string subid in idlist)
  499. {
  500. int id = int.Parse(subid);
  501. Dictionary<string, object> Fields = new Dictionary<string, object>();
  502. Fields.Add("Status", 0);
  503. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  504. }
  505. db.SaveChanges();
  506. return "success";
  507. }
  508. #endregion
  509. #region 风控
  510. public IActionResult Risk(string right, int Id = 0)
  511. {
  512. ViewBag.RightInfo = RightInfo;
  513. ViewBag.right = right;
  514. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  515. ViewBag.data = editData;
  516. return View();
  517. }
  518. #endregion
  519. #region 风控
  520. [HttpPost]
  521. public string Risk(Users data)
  522. {
  523. Users user = db.Users.FirstOrDefault(m => m.Id == data.Id);
  524. if (user != null)
  525. {
  526. user.RiskFlag = data.RiskFlag;
  527. user.RiskRemark = data.RiskRemark;
  528. db.SaveChanges();
  529. }
  530. return "success";
  531. }
  532. #endregion
  533. #region 解除风控
  534. public string UnRisk(string Id)
  535. {
  536. string[] idlist = Id.Split(new char[] { ',' });
  537. AddSysLog(Id, "Users", "UnRisk");
  538. foreach (string subid in idlist)
  539. {
  540. int id = int.Parse(subid);
  541. Dictionary<string, object> Fields = new Dictionary<string, object>();
  542. Fields.Add("RiskFlag", 0);
  543. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  544. }
  545. db.SaveChanges();
  546. return "success";
  547. }
  548. #endregion
  549. #region 重置密码
  550. public string ResetPwd(int Id)
  551. {
  552. string NewPwd = function.get_Random(6);
  553. Dictionary<string, object> Fields = new Dictionary<string, object>();
  554. Fields.Add("LoginPwd", function.MD532(NewPwd));
  555. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, Id);
  556. AddSysLog(Id, "Users", "ResetPwd");
  557. RedisDbconn.Instance.Clear("Users:" + Id);
  558. return "success|" + NewPwd;
  559. }
  560. #endregion
  561. #region 排序
  562. /// <summary>
  563. /// 排序
  564. /// </summary>
  565. /// <param name="Id"></param>
  566. public string Sort(int Id, int Sort)
  567. {
  568. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("Users", Sort, Id);
  569. AddSysLog(Id.ToString(), "Users", "sort");
  570. return "success";
  571. }
  572. #endregion
  573. #region 导入数据
  574. /// <summary>
  575. /// 导入数据
  576. /// </summary>
  577. /// <param name="ExcelData"></param>
  578. public string Import(string ExcelData, int Kind = 0)
  579. {
  580. ExcelData = HttpUtility.UrlDecode(ExcelData);
  581. JsonData list = JsonMapper.ToObject(ExcelData);
  582. if (Kind == 1)
  583. {
  584. for (int i = 1; i < list.Count; i++)
  585. {
  586. JsonData dr = list[i];
  587. string MakerCode = dr[0].ToString();
  588. string SettleAmount = dr[2].ToString();
  589. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  590. if (UserCode != null)
  591. {
  592. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  593. if (User != null)
  594. {
  595. User.SettleAmount = decimal.Parse(function.CheckInt(SettleAmount));
  596. }
  597. }
  598. }
  599. db.SaveChanges();
  600. }
  601. else if (Kind == 2)
  602. {
  603. for (int i = 1; i < list.Count; i++)
  604. {
  605. JsonData dr = list[i];
  606. string MakerCode = dr[0].ToString();
  607. string CashFreezeAmt = dr[2].ToString();
  608. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  609. if (UserCode != null)
  610. {
  611. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  612. if (User != null)
  613. {
  614. User.CashFreezeAmt = decimal.Parse(function.CheckInt(CashFreezeAmt));
  615. }
  616. }
  617. }
  618. db.SaveChanges();
  619. }
  620. else if (Kind == 3)
  621. {
  622. for (int i = 1; i < list.Count; i++)
  623. {
  624. JsonData dr = list[i];
  625. string MakerCode = dr[0].ToString();
  626. string RiskFlag = dr[2].ToString();
  627. string RiskNote = dr[3].ToString();
  628. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  629. if (UserCode != null)
  630. {
  631. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  632. if (User != null)
  633. {
  634. User.RiskFlag = ulong.Parse(function.CheckInt(RiskFlag));
  635. User.RiskRemark = RiskNote;
  636. }
  637. }
  638. }
  639. db.SaveChanges();
  640. }
  641. else if (Kind == 4)
  642. {
  643. string error = "";
  644. for (int i = 1; i < list.Count; i++)
  645. {
  646. JsonData dr = list[i];
  647. string MakerCode = dr[0].ToString();
  648. string OperationAmt = dr[2].ToString();//操作金额
  649. string OperationType = dr[3].ToString();//操作类型
  650. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  651. if (UserCode != null)
  652. {
  653. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  654. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == User.Id);
  655. if (account == null)
  656. {
  657. account = db.UserAccount.Add(new UserAccount()
  658. {
  659. Id = User.Id,
  660. UserId = User.Id,
  661. }).Entity;
  662. db.SaveChanges();
  663. }
  664. if (User != null)
  665. {
  666. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  667. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  668. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  669. int ChangeType = 0;
  670. if (OperationType == "1" && Convert.ToDecimal(OperationAmt) <= account.BalanceAmount)
  671. {
  672. account.BalanceAmount -= Convert.ToDecimal(OperationAmt);
  673. account.FreezeAmount += Convert.ToDecimal(OperationAmt);
  674. ChangeType = 61;
  675. }
  676. else if (OperationType == "1" && Convert.ToDecimal(OperationAmt) > account.BalanceAmount)
  677. {
  678. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "冻结金额大于余额" + '|' + '\n';
  679. }
  680. else if (OperationType == "2" && Convert.ToDecimal(OperationAmt) <= account.FreezeAmount)
  681. {
  682. account.BalanceAmount += Convert.ToDecimal(OperationAmt);
  683. account.FreezeAmount -= Convert.ToDecimal(OperationAmt);
  684. ChangeType = 62;
  685. }
  686. else if (OperationType == "2" && Convert.ToDecimal(OperationAmt) > account.FreezeAmount)
  687. {
  688. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "解冻金额大于冻结金额" + '|' + '\n';
  689. }
  690. else if (OperationType == "3" && Convert.ToDecimal(OperationAmt) <= account.BalanceAmount)
  691. {
  692. account.TotalAmount -= Convert.ToDecimal(OperationAmt);
  693. account.BalanceAmount -= Convert.ToDecimal(OperationAmt);
  694. ChangeType = 63;
  695. }
  696. else if (OperationType == "3" && Convert.ToDecimal(OperationAmt) > account.BalanceAmount)
  697. {
  698. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "扣减金额大于余额" + '|' + '\n';
  699. }
  700. else if (OperationType == "4")
  701. {
  702. account.TotalAmount += Convert.ToDecimal(OperationAmt);
  703. account.BalanceAmount += Convert.ToDecimal(OperationAmt);
  704. ChangeType = 64;
  705. }
  706. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  707. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  708. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  709. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  710. {
  711. CreateDate = DateTime.Now,
  712. UpdateDate = DateTime.Now,
  713. UserId = User.Id, //创客
  714. ChangeType = ChangeType, //变动类型
  715. ChangeAmount = Convert.ToDecimal(OperationAmt), //变更金额
  716. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  717. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  718. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  719. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  720. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  721. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  722. Remark = dr[4].ToString(),
  723. }).Entity;
  724. db.SaveChanges();
  725. AddSysLog(User.Id.ToString(), "Users", "ChangeCashFreezeAmts");
  726. db.SaveChanges();
  727. }
  728. }
  729. }
  730. db.SaveChanges();
  731. return "warning" + error;
  732. }
  733. AddSysLog("0", "Users", "Import");
  734. return "success";
  735. }
  736. #endregion
  737. #region 导出Excel
  738. /// <summary>
  739. /// 导出Excel
  740. /// </summary>
  741. /// <returns></returns>
  742. 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)
  743. {
  744. Dictionary<string, string> Fields = new Dictionary<string, string>();
  745. Fields.Add("MakerCode", "1"); //创客编号
  746. Fields.Add("RealName", "1"); //创客名称
  747. Fields.Add("Mobile", "1"); //手机号
  748. Fields.Add("CertId", "1"); //身份证号码
  749. Fields.Add("CreateDate", "3"); //注册时间
  750. Fields.Add("SettleAmount", "3"); //结算金额
  751. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  752. Fields.Add("UserLevel", "0"); //创客等级
  753. string condition = " and Status>-1";
  754. //直属创客编号
  755. if (!string.IsNullOrEmpty(ParentMakerCode))
  756. {
  757. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  758. }
  759. //直属创客名称
  760. if (!string.IsNullOrEmpty(ParentRealName))
  761. {
  762. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  763. }
  764. //实名状态
  765. if (!string.IsNullOrEmpty(AuthFlagSelect))
  766. {
  767. condition += " and AuthFlag=" + AuthFlagSelect;
  768. }
  769. //顶级创客
  770. if (TopUserId > 0)
  771. {
  772. condition += " and ParentNav like '," + TopUserId + ",%'";
  773. }
  774. //风控标识
  775. if (!string.IsNullOrEmpty(RiskFlagSelect))
  776. {
  777. condition += " and RiskFlag=" + RiskFlagSelect;
  778. }
  779. //商户创客类型
  780. if (!string.IsNullOrEmpty(MerchantTypeSelect))
  781. {
  782. condition += " and MerchantType=" + MerchantTypeSelect;
  783. }
  784. if (SelfId > 0)
  785. {
  786. Users self = db.Users.FirstOrDefault(m => m.Id == SelfId);
  787. if (self != null)
  788. {
  789. string ParentNav = function.CheckNull(self.ParentNav);
  790. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  791. }
  792. }
  793. if (ParentId > 0)
  794. {
  795. condition += " and ParentUserId=" + ParentId;
  796. }
  797. 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);
  798. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  799. foreach (Dictionary<string, object> dic in diclist)
  800. {
  801. dic["AuthFlag"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  802. dic["RiskFlag"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  803. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  804. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  805. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  806. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  807. dic["ParentMakerCode"] = puser.MakerCode;
  808. dic["ParentRealName"] = puser.RealName;
  809. string ParentNav = dic["ParentNav"].ToString();
  810. if (!string.IsNullOrEmpty(ParentNav))
  811. {
  812. string[] list = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  813. if (list.Length > 1)
  814. {
  815. int TopId = int.Parse(function.CheckInt(list[1]));
  816. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  817. dic["TopMakerCode"] = tuser.MakerCode;
  818. dic["TopRealName"] = tuser.RealName;
  819. }
  820. }
  821. dic.Remove("ParentUserId");
  822. dic.Remove("ParentNav");
  823. }
  824. Dictionary<string, object> result = new Dictionary<string, object>();
  825. result.Add("Status", "1");
  826. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  827. result.Add("Obj", diclist);
  828. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  829. ReturnFields.Add("MakerCode", "创客编号");
  830. ReturnFields.Add("RealName", "创客姓名");
  831. ReturnFields.Add("UserLevel", "创客等级");
  832. ReturnFields.Add("SettleAmount", "提现金额(元)");
  833. ReturnFields.Add("CashFreezeAmt", "冻结金额(元)");
  834. ReturnFields.Add("CertId", "身份证号");
  835. ReturnFields.Add("Mobile", "联系手机");
  836. ReturnFields.Add("MerchantType", "商户创客类型");
  837. ReturnFields.Add("MerchantDate", "成为商户创客时间");
  838. ReturnFields.Add("ParentMakerCode", "直属创客编号");
  839. ReturnFields.Add("ParentRealName", "直属创客名称");
  840. ReturnFields.Add("TopMakerCode", "顶级创客编号");
  841. ReturnFields.Add("TopRealName", "顶级创客名称");
  842. ReturnFields.Add("AuthFlag", "实名状态");
  843. ReturnFields.Add("RiskFlag", "风控状态");
  844. ReturnFields.Add("CreateDate", "注册时间");
  845. result.Add("Fields", ReturnFields);
  846. AddSysLog("0", "Users", "ExportExcel");
  847. return Json(result);
  848. }
  849. #endregion
  850. #region 同步数据
  851. /// <summary>
  852. /// 同步数据
  853. /// </summary>
  854. /// <returns></returns>
  855. public string SycnData(int Id = 0)
  856. {
  857. var Brands = db.KqProducts.Where(m => m.Status == 1).ToList();
  858. foreach (var Brand in Brands)
  859. {
  860. PublicFunction.SycnMachineCount(Id, Brand.Id);
  861. // RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, machineData);
  862. // RedisDbconn.Instance.SetExpire("UserMachineData:" + IdBrand, function.get_Random(1800, 5400));
  863. }
  864. AddSysLog(Id, "Users", "SycnData");
  865. db.SaveChanges();
  866. return "success";
  867. }
  868. #endregion
  869. #region 同步交易额
  870. public IActionResult SycnTradeAmount(string right, int Id = 0)
  871. {
  872. ViewBag.RightInfo = RightInfo;
  873. ViewBag.right = right;
  874. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  875. ViewBag.data = editData;
  876. return View();
  877. }
  878. #endregion
  879. #region 同步交易额
  880. [HttpPost]
  881. public string SycnTradeAmountDo(DateTime sdate, DateTime edate, int UserId, int BrandId)
  882. {
  883. if (sdate.AddMonths(1) < edate)
  884. {
  885. return "时间间隔不能超过1个月";
  886. }
  887. if (edate >= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"))
  888. {
  889. return "结束时间只能是今天之前";
  890. }
  891. string check = RedisDbconn.Instance.Get<string>("ResetUserTradeQueue:" + UserId + ":" + BrandId);
  892. if (!string.IsNullOrEmpty(check))
  893. {
  894. return "请稍后再试";
  895. }
  896. try
  897. {
  898. 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);
  899. RedisDbconn.Instance.Set("ResetUserTradeQueue:" + UserId + ":" + BrandId, "wait");
  900. RedisDbconn.Instance.SetExpire("ResetUserTradeQueue:" + UserId + ":" + BrandId, 3600);
  901. }
  902. catch (Exception ex)
  903. {
  904. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计创客的交易额异常");
  905. return "同步异常";
  906. }
  907. return "success";
  908. }
  909. #endregion
  910. #region 创客展业城市
  911. public IActionResult City(Users data, string right)
  912. {
  913. ViewBag.RightInfo = RightInfo;
  914. ViewBag.right = right;
  915. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  916. ViewBag.TopUsers = TopUsers;
  917. return View();
  918. }
  919. #endregion
  920. #region 根据条件查询创客展业城市
  921. public JsonResult CityData(Users data, string ParentMakerCode, string ParentRealName, int TopUserId, string Areas, int page = 1, int limit = 30)
  922. {
  923. Dictionary<string, string> Fields = new Dictionary<string, string>();
  924. Fields.Add("MakerCode", "1"); //创客编号
  925. Fields.Add("RealName", "1"); //创客名称
  926. Fields.Add("CitySetDate", "3"); //创建时间
  927. Fields.Add("Areas", "2"); //省市
  928. string condition = " and Status>-1";
  929. //直属创客编号
  930. if (!string.IsNullOrEmpty(ParentMakerCode))
  931. {
  932. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  933. }
  934. //直属创客名称
  935. if (!string.IsNullOrEmpty(ParentRealName))
  936. {
  937. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  938. }
  939. //顶级创客
  940. if (TopUserId > 0)
  941. {
  942. condition += " and ParentNav like '," + TopUserId + ",%'";
  943. }
  944. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", page, limit, condition);
  945. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  946. foreach (Dictionary<string, object> dic in diclist)
  947. {
  948. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  949. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  950. dic["ParentMakerCode"] = puser.MakerCode;
  951. dic["ParentRealName"] = puser.RealName;
  952. string ParentNav = dic["ParentNav"].ToString();
  953. if (!string.IsNullOrEmpty(ParentNav))
  954. {
  955. int TopId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  956. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  957. dic["TopMakerCode"] = tuser.MakerCode;
  958. dic["TopRealName"] = tuser.RealName;
  959. }
  960. }
  961. return Json(obj);
  962. }
  963. #endregion
  964. #region 导出展业城市
  965. public JsonResult ExportCity(Users data, string CreateDate, string ParentMakerCode, string ParentRealName, string AuthFlagSelect, int TopUserId, string RiskFlagSelect, string MerchantTypeSelect)
  966. {
  967. Dictionary<string, string> Fields = new Dictionary<string, string>();
  968. Fields.Add("MakerCode", "1"); //创客编号
  969. Fields.Add("RealName", "1"); //创客名称
  970. Fields.Add("Mobile", "1"); //手机号
  971. Fields.Add("CertId", "1"); //身份证号码
  972. Fields.Add("CreateDate", "3"); //注册时间
  973. Fields.Add("SettleAmount", "3"); //结算金额
  974. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  975. Fields.Add("UserLevel", "0"); //创客等级
  976. string condition = " and Status>-1";
  977. //直属创客编号
  978. if (!string.IsNullOrEmpty(ParentMakerCode))
  979. {
  980. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  981. }
  982. //直属创客名称
  983. if (!string.IsNullOrEmpty(ParentRealName))
  984. {
  985. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  986. }
  987. //实名状态
  988. if (!string.IsNullOrEmpty(AuthFlagSelect))
  989. {
  990. condition += " and AuthFlag=" + AuthFlagSelect;
  991. }
  992. //顶级创客
  993. if (TopUserId > 0)
  994. {
  995. condition += " and ParentNav like '," + TopUserId + ",%'";
  996. }
  997. //风控标识
  998. if (!string.IsNullOrEmpty(RiskFlagSelect))
  999. {
  1000. condition += " and RiskFlag=" + RiskFlagSelect;
  1001. }
  1002. //商户创客类型
  1003. if (!string.IsNullOrEmpty(MerchantTypeSelect))
  1004. {
  1005. condition += " and MerchantType=" + MerchantTypeSelect;
  1006. }
  1007. 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);
  1008. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1009. foreach (Dictionary<string, object> dic in diclist)
  1010. {
  1011. dic["AuthFlag"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  1012. dic["RiskFlag"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  1013. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1014. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  1015. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  1016. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1017. dic["ParentMakerCode"] = puser.MakerCode;
  1018. dic["ParentRealName"] = puser.RealName;
  1019. string ParentNav = dic["ParentNav"].ToString();
  1020. if (!string.IsNullOrEmpty(ParentNav))
  1021. {
  1022. int TopId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  1023. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1024. dic["TopMakerCode"] = tuser.MakerCode;
  1025. dic["TopRealName"] = tuser.RealName;
  1026. }
  1027. dic.Remove("ParentUserId");
  1028. dic.Remove("ParentNav");
  1029. }
  1030. Dictionary<string, object> result = new Dictionary<string, object>();
  1031. result.Add("Status", "1");
  1032. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1033. result.Add("Obj", diclist);
  1034. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1035. ReturnFields.Add("MakerCode", "创客编号");
  1036. ReturnFields.Add("RealName", "创客姓名");
  1037. ReturnFields.Add("UserLevel", "创客等级");
  1038. ReturnFields.Add("SettleAmount", "提现金额(元)");
  1039. ReturnFields.Add("CashFreezeAmt", "冻结金额(元)");
  1040. ReturnFields.Add("CertId", "身份证号");
  1041. ReturnFields.Add("Mobile", "联系手机");
  1042. ReturnFields.Add("MerchantType", "商户创客类型");
  1043. ReturnFields.Add("MerchantDate", "成为商户创客时间");
  1044. ReturnFields.Add("ParentMakerCode", "直属创客编号");
  1045. ReturnFields.Add("ParentRealName", "直属创客名称");
  1046. ReturnFields.Add("TopMakerCode", "顶级创客编号");
  1047. ReturnFields.Add("TopRealName", "顶级创客名称");
  1048. ReturnFields.Add("AuthFlag", "实名状态");
  1049. ReturnFields.Add("RiskFlag", "风控状态");
  1050. ReturnFields.Add("CreateDate", "注册时间");
  1051. result.Add("Fields", ReturnFields);
  1052. AddSysLog("0", "Users", "ExportExcel");
  1053. return Json(result);
  1054. }
  1055. #endregion
  1056. #region 根据条件查询直属创客交易额列表
  1057. /// <summary>
  1058. /// 直属创客交易额列表
  1059. /// </summary>
  1060. /// <returns></returns>
  1061. public IActionResult Children(Users data, string right, int ParentId = 0, string MakerCode = "")
  1062. {
  1063. ViewBag.RightInfo = RightInfo;
  1064. ViewBag.right = right;
  1065. ViewBag.ParentId = ParentId.ToString();
  1066. ViewBag.MakerCode = MakerCode;
  1067. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  1068. ViewBag.TopUsers = TopUsers;
  1069. List<UserLevelSet> Levels = db.UserLevelSet.OrderBy(m => m.Id).ToList();
  1070. ViewBag.Levels = Levels;
  1071. List<KqProducts> Brands = db.KqProducts.OrderBy(m => m.Id).ToList();
  1072. ViewBag.Brands = Brands;
  1073. return View();
  1074. }
  1075. #endregion
  1076. #region 根据条件查询直属创客交易额列表
  1077. /// <summary>
  1078. /// 直属创客交易额列表
  1079. /// </summary>
  1080. /// <returns></returns>
  1081. public JsonResult ChildrenData(Users data, int BrandSelect, string MakerCode, string CreateDateData, int ParentId = 0, int page = 1, int limit = 30)
  1082. {
  1083. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1084. Fields.Add("MakerCode", "1"); //创客编号
  1085. int BrandId = BrandSelect;
  1086. string start = "";
  1087. string end = "";
  1088. string condition = " and Status>-1";
  1089. string sort = "Id desc";
  1090. //创客编号
  1091. if (!string.IsNullOrEmpty(MakerCode))
  1092. {
  1093. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  1094. }
  1095. if (ParentId > 0)
  1096. {
  1097. condition += " and ParentUserId=" + ParentId + " or Id=" + ParentId;
  1098. }
  1099. if (!string.IsNullOrEmpty(CreateDateData))
  1100. {
  1101. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1102. start = datelist[0].Replace("-", "");
  1103. end = datelist[1].Replace("-", "");
  1104. }
  1105. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, sort, "True", page, limit, condition);
  1106. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1107. foreach (Dictionary<string, object> dic in diclist)
  1108. {
  1109. int UId = int.Parse(dic["Id"].ToString());
  1110. var Info = GetMonthTradeForBrand(UId, start, end, BrandId);
  1111. dic["TotalAmtfc"] = Convert.ToDecimal(Info["TotalAmtfc"].ToString()) + Convert.ToDecimal(Info["YAmtfc"].ToString());
  1112. dic["DAmtfc"] = Convert.ToDecimal(Info["DAmtfc"].ToString());
  1113. dic["JAmtfc"] = Convert.ToDecimal(Info["JAmtfc"].ToString());
  1114. dic["JfAmtfc"] = Convert.ToDecimal(Info["JfAmtfc"].ToString());
  1115. dic["JCountfc"] = Convert.ToInt32(Info["JCountfc"].ToString());
  1116. dic["YAmtfc"] = Convert.ToDecimal(Info["YAmtfc"].ToString());
  1117. dic["TotalAmtwd"] = Convert.ToDecimal(Info["TotalAmtwd"].ToString()) + Convert.ToDecimal(Info["YAmtwd"].ToString());
  1118. dic["DAmtwd"] = Convert.ToDecimal(Info["DAmtwd"].ToString());
  1119. dic["JAmtwd"] = Convert.ToDecimal(Info["JAmtwd"].ToString());
  1120. dic["JfAmtwd"] = Convert.ToDecimal(Info["JfAmtwd"].ToString());
  1121. dic["JCountwd"] = Convert.ToInt32(Info["JCountwd"].ToString());
  1122. dic["YAmtwd"] = Convert.ToDecimal(Info["YAmtwd"].ToString());
  1123. dic["BCount"] = Info["BCount"].ToString();
  1124. dic["ACount"] = Info["ACount"].ToString();
  1125. }
  1126. return Json(obj);
  1127. }
  1128. public Dictionary<string, object> GetMonthTradeForBrand(int UserId, string sTradeDate, string eTradeDate, int BrandId)
  1129. {
  1130. string condition = " and Status>-1";
  1131. //产品类型
  1132. if (!string.IsNullOrEmpty(BrandId.ToString()) && BrandId > 0)
  1133. {
  1134. condition += " and BrandId =" + BrandId;
  1135. }
  1136. //创客Id
  1137. if (!string.IsNullOrEmpty(UserId.ToString()))
  1138. {
  1139. condition += " and UserId =" + UserId;
  1140. }
  1141. //开始时间
  1142. if (!string.IsNullOrEmpty(sTradeDate))
  1143. {
  1144. condition += " and TradeDate >=" + Convert.ToInt32(sTradeDate);
  1145. }
  1146. //结束时间
  1147. if (!string.IsNullOrEmpty(eTradeDate))
  1148. {
  1149. condition += " and TradeDate <=" + Convert.ToInt32(eTradeDate);
  1150. }
  1151. //扶持期
  1152. decimal TotalAmtfc = 0;
  1153. decimal DAmtfc = 0;
  1154. decimal JAmtfc = 0;
  1155. decimal JfAmtfc = 0;
  1156. int JCountfc = 0;
  1157. decimal YAmtfc = 0;
  1158. //稳定期
  1159. decimal TotalAmtwd = 0;
  1160. decimal DAmtwd = 0;
  1161. decimal JAmtwd = 0;
  1162. decimal JfAmtwd = 0;
  1163. int JCountwd = 0;
  1164. decimal YAmtwd = 0;
  1165. int BCount = 0;
  1166. int ACount = 0;
  1167. WebCMSEntities db = new WebCMSEntities();
  1168. Dictionary<string, object> obj = new Dictionary<string, object>();
  1169. DataTable dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt + HelpNonDirectDebitTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'"+ condition);
  1170. if (dt.Rows.Count > 0)
  1171. {
  1172. TotalAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1173. }
  1174. dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'"+ condition);
  1175. if (dt.Rows.Count > 0)
  1176. {
  1177. DAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1178. }
  1179. dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectDebitTradeAmt),Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'"+ condition);
  1180. if (dt.Rows.Count > 0)
  1181. {
  1182. JAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1183. }
  1184. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'"+ condition);
  1185. if (dt.Rows.Count > 0)
  1186. {
  1187. JfAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1188. }
  1189. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='team'"+ condition);
  1190. if (dt.Rows.Count > 0)
  1191. {
  1192. JCountfc = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1193. }
  1194. dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='team'"+ condition);
  1195. if (dt.Rows.Count > 0)
  1196. {
  1197. YAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1198. }
  1199. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt + NotHelpNonDirectDebitTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'"+ condition);
  1200. if (dt.Rows.Count > 0)
  1201. {
  1202. TotalAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1203. }
  1204. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'"+ condition);
  1205. if (dt.Rows.Count > 0)
  1206. {
  1207. DAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1208. }
  1209. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectDebitTradeAmt),Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'"+ condition);
  1210. if (dt.Rows.Count > 0)
  1211. {
  1212. JAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1213. }
  1214. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'"+ condition);
  1215. if (dt.Rows.Count > 0)
  1216. {
  1217. JfAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1218. }
  1219. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='team'"+ condition);
  1220. if (dt.Rows.Count > 0)
  1221. {
  1222. JCountwd = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1223. }
  1224. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='team'"+ condition);
  1225. if (dt.Rows.Count > 0)
  1226. {
  1227. YAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1228. }
  1229. // dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='team'"+ condition);
  1230. // if (dt.Rows.Count > 0)
  1231. // {
  1232. // BCount = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1233. // }
  1234. // dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='team'"+ condition);
  1235. // if (dt.Rows.Count > 0)
  1236. // {
  1237. // ACount = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1238. // }
  1239. obj.Add("TotalAmtfc", TotalAmtfc);
  1240. obj.Add("DAmtfc", DAmtfc);
  1241. obj.Add("JAmtfc", JAmtfc);
  1242. obj.Add("JfAmtfc", JfAmtfc);
  1243. obj.Add("JCountfc", JCountfc);
  1244. obj.Add("YAmtfc", YAmtfc);
  1245. obj.Add("TotalAmtwd", TotalAmtwd);
  1246. obj.Add("DAmtwd", DAmtwd);
  1247. obj.Add("JAmtwd", JAmtwd);
  1248. obj.Add("JfAmtwd", JfAmtwd);
  1249. obj.Add("JCountwd", JCountwd);
  1250. obj.Add("YAmtwd", YAmtwd);
  1251. obj.Add("BCount", BCount);
  1252. obj.Add("ACount", ACount);
  1253. db.Dispose();
  1254. return obj;
  1255. }
  1256. #endregion
  1257. }
  1258. }