UsersController.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672
  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. /// <summary>
  511. /// 一键企业创客
  512. /// </summary>
  513. /// <returns></returns>
  514. public string OpenEnterpriseMaker(string Id)
  515. {
  516. string[] idlist = Id.Split(new char[] { ',' });
  517. AddSysLog(Id, "Users", "OpenEnterpriseMaker");
  518. foreach (string subid in idlist)
  519. {
  520. int id = int.Parse(subid);
  521. Dictionary<string, object> Fields = new Dictionary<string, object>();
  522. Fields.Add("BusinessFlag", 1);
  523. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  524. }
  525. db.SaveChanges();
  526. return "success";
  527. }
  528. #endregion
  529. #region 关闭企业创客
  530. /// <summary>
  531. /// 关闭企业创客
  532. /// </summary>
  533. /// <returns></returns>
  534. public string CloseEnterpriseMaker(string Id)
  535. {
  536. string[] idlist = Id.Split(new char[] { ',' });
  537. AddSysLog(Id, "Users", "CloseEnterpriseMaker");
  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("BusinessFlag", 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 IActionResult Risk(string right, int Id = 0)
  551. {
  552. ViewBag.RightInfo = RightInfo;
  553. ViewBag.right = right;
  554. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  555. ViewBag.data = editData;
  556. return View();
  557. }
  558. #endregion
  559. #region 风控
  560. [HttpPost]
  561. public string Risk(Users data)
  562. {
  563. Users user = db.Users.FirstOrDefault(m => m.Id == data.Id);
  564. if (user != null)
  565. {
  566. user.RiskFlag = data.RiskFlag;
  567. user.RiskRemark = data.RiskRemark;
  568. db.SaveChanges();
  569. }
  570. return "success";
  571. }
  572. #endregion
  573. #region 解除风控
  574. public string UnRisk(string Id)
  575. {
  576. string[] idlist = Id.Split(new char[] { ',' });
  577. AddSysLog(Id, "Users", "UnRisk");
  578. foreach (string subid in idlist)
  579. {
  580. int id = int.Parse(subid);
  581. Dictionary<string, object> Fields = new Dictionary<string, object>();
  582. Fields.Add("RiskFlag", 0);
  583. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  584. }
  585. db.SaveChanges();
  586. return "success";
  587. }
  588. #endregion
  589. #region 重置密码
  590. public string ResetPwd(int Id)
  591. {
  592. string NewPwd = function.get_Random(6);
  593. Dictionary<string, object> Fields = new Dictionary<string, object>();
  594. Fields.Add("LoginPwd", function.MD532(NewPwd));
  595. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, Id);
  596. AddSysLog(Id, "Users", "ResetPwd");
  597. RedisDbconn.Instance.Clear("Users:" + Id);
  598. return "success|" + NewPwd;
  599. }
  600. #endregion
  601. #region 排序
  602. /// <summary>
  603. /// 排序
  604. /// </summary>
  605. /// <param name="Id"></param>
  606. public string Sort(int Id, int Sort)
  607. {
  608. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("Users", Sort, Id);
  609. AddSysLog(Id.ToString(), "Users", "sort");
  610. return "success";
  611. }
  612. #endregion
  613. #region 导入数据
  614. /// <summary>
  615. /// 导入数据
  616. /// </summary>
  617. /// <param name="ExcelData"></param>
  618. public string Import(string ExcelData, int Kind = 0)
  619. {
  620. ExcelData = HttpUtility.UrlDecode(ExcelData);
  621. JsonData list = JsonMapper.ToObject(ExcelData);
  622. if (Kind == 1)
  623. {
  624. for (int i = 1; i < list.Count; i++)
  625. {
  626. JsonData dr = list[i];
  627. string MakerCode = dr[0].ToString();
  628. string SettleAmount = dr[2].ToString();
  629. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  630. if (UserCode != null)
  631. {
  632. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  633. if (User != null)
  634. {
  635. User.SettleAmount = decimal.Parse(function.CheckInt(SettleAmount));
  636. }
  637. }
  638. }
  639. db.SaveChanges();
  640. }
  641. else if (Kind == 2)
  642. {
  643. for (int i = 1; i < list.Count; i++)
  644. {
  645. JsonData dr = list[i];
  646. string MakerCode = dr[0].ToString();
  647. string CashFreezeAmt = dr[2].ToString();
  648. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  649. if (UserCode != null)
  650. {
  651. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  652. if (User != null)
  653. {
  654. User.CashFreezeAmt = decimal.Parse(function.CheckInt(CashFreezeAmt));
  655. }
  656. }
  657. }
  658. db.SaveChanges();
  659. }
  660. else if (Kind == 3)
  661. {
  662. for (int i = 1; i < list.Count; i++)
  663. {
  664. JsonData dr = list[i];
  665. string MakerCode = dr[0].ToString();
  666. string RiskFlag = dr[2].ToString();
  667. string RiskNote = dr[3].ToString();
  668. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  669. if (UserCode != null)
  670. {
  671. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  672. if (User != null)
  673. {
  674. User.RiskFlag = ulong.Parse(function.CheckInt(RiskFlag));
  675. User.RiskRemark = RiskNote;
  676. }
  677. }
  678. }
  679. db.SaveChanges();
  680. }
  681. else if (Kind == 4)
  682. {
  683. string error = "";
  684. for (int i = 1; i < list.Count; i++)
  685. {
  686. JsonData dr = list[i];
  687. string MakerCode = dr[0].ToString();
  688. string OperationAmt = dr[2].ToString();//操作金额
  689. string OperationType = dr[3].ToString();//操作类型
  690. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  691. if (UserCode != null)
  692. {
  693. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  694. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == User.Id);
  695. if (account == null)
  696. {
  697. account = db.UserAccount.Add(new UserAccount()
  698. {
  699. Id = User.Id,
  700. UserId = User.Id,
  701. }).Entity;
  702. db.SaveChanges();
  703. }
  704. if (User != null)
  705. {
  706. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  707. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  708. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  709. int ChangeType = 0;
  710. if (OperationType == "1" && Convert.ToDecimal(OperationAmt) <= account.BalanceAmount)
  711. {
  712. account.BalanceAmount -= Convert.ToDecimal(OperationAmt);
  713. account.FreezeAmount += Convert.ToDecimal(OperationAmt);
  714. ChangeType = 61;
  715. }
  716. else if (OperationType == "1" && Convert.ToDecimal(OperationAmt) > account.BalanceAmount)
  717. {
  718. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "冻结金额大于余额" + '|' + '\n';
  719. }
  720. else if (OperationType == "2" && Convert.ToDecimal(OperationAmt) <= account.FreezeAmount)
  721. {
  722. account.BalanceAmount += Convert.ToDecimal(OperationAmt);
  723. account.FreezeAmount -= Convert.ToDecimal(OperationAmt);
  724. ChangeType = 62;
  725. }
  726. else if (OperationType == "2" && Convert.ToDecimal(OperationAmt) > account.FreezeAmount)
  727. {
  728. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "解冻金额大于冻结金额" + '|' + '\n';
  729. }
  730. else if (OperationType == "3" && Convert.ToDecimal(OperationAmt) <= account.BalanceAmount)
  731. {
  732. account.TotalAmount -= Convert.ToDecimal(OperationAmt);
  733. account.BalanceAmount -= Convert.ToDecimal(OperationAmt);
  734. ChangeType = 63;
  735. }
  736. else if (OperationType == "3" && Convert.ToDecimal(OperationAmt) > account.BalanceAmount)
  737. {
  738. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "扣减金额大于余额" + '|' + '\n';
  739. }
  740. else if (OperationType == "4")
  741. {
  742. account.TotalAmount += Convert.ToDecimal(OperationAmt);
  743. account.BalanceAmount += Convert.ToDecimal(OperationAmt);
  744. ChangeType = 64;
  745. }
  746. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  747. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  748. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  749. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  750. {
  751. CreateDate = DateTime.Now,
  752. UpdateDate = DateTime.Now,
  753. UserId = User.Id, //创客
  754. ChangeType = ChangeType, //变动类型
  755. ChangeAmount = Convert.ToDecimal(OperationAmt), //变更金额
  756. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  757. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  758. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  759. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  760. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  761. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  762. Remark = dr[4].ToString(),
  763. }).Entity;
  764. db.SaveChanges();
  765. AddSysLog(User.Id.ToString(), "Users", "ChangeCashFreezeAmts");
  766. db.SaveChanges();
  767. }
  768. }
  769. }
  770. db.SaveChanges();
  771. return "warning" + error;
  772. }
  773. AddSysLog("0", "Users", "Import");
  774. return "success";
  775. }
  776. #endregion
  777. #region 导出Excel
  778. /// <summary>
  779. /// 导出Excel
  780. /// </summary>
  781. /// <returns></returns>
  782. 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)
  783. {
  784. Dictionary<string, string> Fields = new Dictionary<string, string>();
  785. Fields.Add("MakerCode", "1"); //创客编号
  786. Fields.Add("RealName", "1"); //创客名称
  787. Fields.Add("Mobile", "1"); //手机号
  788. Fields.Add("CertId", "1"); //身份证号码
  789. Fields.Add("CreateDate", "3"); //注册时间
  790. Fields.Add("SettleAmount", "3"); //结算金额
  791. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  792. Fields.Add("UserLevel", "0"); //创客等级
  793. string condition = " and Status>-1";
  794. //直属创客编号
  795. if (!string.IsNullOrEmpty(ParentMakerCode))
  796. {
  797. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  798. }
  799. //直属创客名称
  800. if (!string.IsNullOrEmpty(ParentRealName))
  801. {
  802. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  803. }
  804. //实名状态
  805. if (!string.IsNullOrEmpty(AuthFlagSelect))
  806. {
  807. condition += " and AuthFlag=" + AuthFlagSelect;
  808. }
  809. //顶级创客
  810. if (TopUserId > 0)
  811. {
  812. condition += " and ParentNav like '," + TopUserId + ",%'";
  813. }
  814. //风控标识
  815. if (!string.IsNullOrEmpty(RiskFlagSelect))
  816. {
  817. condition += " and RiskFlag=" + RiskFlagSelect;
  818. }
  819. //商户创客类型
  820. if (!string.IsNullOrEmpty(MerchantTypeSelect))
  821. {
  822. condition += " and MerchantType=" + MerchantTypeSelect;
  823. }
  824. if (SelfId > 0)
  825. {
  826. Users self = db.Users.FirstOrDefault(m => m.Id == SelfId);
  827. if (self != null)
  828. {
  829. string ParentNav = function.CheckNull(self.ParentNav);
  830. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  831. }
  832. }
  833. if (ParentId > 0)
  834. {
  835. condition += " and ParentUserId=" + ParentId;
  836. }
  837. 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);
  838. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  839. foreach (Dictionary<string, object> dic in diclist)
  840. {
  841. dic["AuthFlag"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  842. dic["RiskFlag"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  843. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  844. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  845. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  846. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  847. dic["ParentMakerCode"] = puser.MakerCode;
  848. dic["ParentRealName"] = puser.RealName;
  849. string ParentNav = dic["ParentNav"].ToString();
  850. if (!string.IsNullOrEmpty(ParentNav))
  851. {
  852. string[] list = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  853. if (list.Length > 1)
  854. {
  855. int TopId = int.Parse(function.CheckInt(list[1]));
  856. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  857. dic["TopMakerCode"] = tuser.MakerCode;
  858. dic["TopRealName"] = tuser.RealName;
  859. }
  860. }
  861. dic.Remove("ParentUserId");
  862. dic.Remove("ParentNav");
  863. }
  864. Dictionary<string, object> result = new Dictionary<string, object>();
  865. result.Add("Status", "1");
  866. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  867. result.Add("Obj", diclist);
  868. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  869. ReturnFields.Add("MakerCode", "创客编号");
  870. ReturnFields.Add("RealName", "创客姓名");
  871. ReturnFields.Add("UserLevel", "创客等级");
  872. ReturnFields.Add("SettleAmount", "提现金额(元)");
  873. ReturnFields.Add("CashFreezeAmt", "冻结金额(元)");
  874. ReturnFields.Add("CertId", "身份证号");
  875. ReturnFields.Add("Mobile", "联系手机");
  876. ReturnFields.Add("MerchantType", "商户创客类型");
  877. ReturnFields.Add("MerchantDate", "成为商户创客时间");
  878. ReturnFields.Add("ParentMakerCode", "直属创客编号");
  879. ReturnFields.Add("ParentRealName", "直属创客名称");
  880. ReturnFields.Add("TopMakerCode", "顶级创客编号");
  881. ReturnFields.Add("TopRealName", "顶级创客名称");
  882. ReturnFields.Add("AuthFlag", "实名状态");
  883. ReturnFields.Add("RiskFlag", "风控状态");
  884. ReturnFields.Add("CreateDate", "注册时间");
  885. result.Add("Fields", ReturnFields);
  886. AddSysLog("0", "Users", "ExportExcel");
  887. return Json(result);
  888. }
  889. #endregion
  890. #region 直属创客导出Excel
  891. /// <summary>
  892. /// 直属创客导出Excel
  893. /// </summary>
  894. /// <returns></returns>
  895. public JsonResult ExportZSExcel(Users data, string MakerCode, string ParentMakerCode)
  896. {
  897. Dictionary<string, string> Fields = new Dictionary<string, string>();
  898. string condition = " and Status>-1";
  899. //创客编号
  900. if (!string.IsNullOrEmpty(MakerCode))
  901. {
  902. condition += " and ParentUserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  903. }
  904. //直属创客编号
  905. if (!string.IsNullOrEmpty(ParentMakerCode))
  906. {
  907. condition += " and ParentUserId in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  908. }
  909. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", 1, 20000, condition, "Id,MakerCode,RealName,UserLevel", false);
  910. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  911. foreach (Dictionary<string, object> dic in diclist)
  912. {
  913. int Id = int.Parse(dic["Id"].ToString());
  914. Users userZS = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  915. dic["MakerCode"] = userZS.MakerCode;
  916. dic["RealName"] = userZS.RealName;
  917. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  918. }
  919. Dictionary<string, object> result = new Dictionary<string, object>();
  920. result.Add("Status", "1");
  921. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  922. result.Add("Obj", diclist);
  923. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  924. ReturnFields.Add("Id", "Id");
  925. ReturnFields.Add("MakerCode", "创客编号");
  926. ReturnFields.Add("RealName", "创客姓名");
  927. ReturnFields.Add("UserLevel", "创客等级");
  928. result.Add("Fields", ReturnFields);
  929. AddSysLog("0", "Users", "ExportZSExcel");
  930. return Json(result);
  931. }
  932. #endregion
  933. #region 上级创客导出Excel
  934. /// <summary>
  935. /// 上级创客导出Excel
  936. /// </summary>
  937. /// <returns></returns>
  938. public JsonResult ExportSJExcel(Users data, string MakerCode, string ParentMakerCode)
  939. {
  940. Dictionary<string, string> Fields = new Dictionary<string, string>();
  941. string condition = " and Status>-1";
  942. //创客编号
  943. if (!string.IsNullOrEmpty(MakerCode))
  944. {
  945. var query = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  946. Users self = db.Users.FirstOrDefault(m => m.Id == query.UserId);
  947. if (self != null)
  948. {
  949. string ParentNav = function.CheckNull(self.ParentNav);
  950. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  951. }
  952. }
  953. //直属创客编号
  954. if (!string.IsNullOrEmpty(ParentMakerCode))
  955. {
  956. var query = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ParentMakerCode);
  957. Users self = db.Users.FirstOrDefault(m => m.Id == query.UserId);
  958. if (self != null)
  959. {
  960. string ParentNav = function.CheckNull(self.ParentNav);
  961. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  962. }
  963. }
  964. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", 1, 20000, condition, "Id,MakerCode,RealName,UserLevel", false);
  965. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  966. foreach (Dictionary<string, object> dic in diclist)
  967. {
  968. int Id = int.Parse(dic["Id"].ToString());
  969. Users userSJ = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  970. dic["MakerCode"] = userSJ.MakerCode;
  971. dic["RealName"] = userSJ.RealName;
  972. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  973. }
  974. Dictionary<string, object> result = new Dictionary<string, object>();
  975. result.Add("Status", "1");
  976. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  977. result.Add("Obj", diclist);
  978. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  979. ReturnFields.Add("Id", "Id");
  980. ReturnFields.Add("MakerCode", "创客编号");
  981. ReturnFields.Add("RealName", "创客姓名");
  982. ReturnFields.Add("UserLevel", "创客等级");
  983. result.Add("Fields", ReturnFields);
  984. AddSysLog("0", "Users", "ExportExcel");
  985. return Json(result);
  986. }
  987. #endregion
  988. #region 同步数据
  989. /// <summary>
  990. /// 同步数据
  991. /// </summary>
  992. /// <returns></returns>
  993. public string SycnData(int Id = 0)
  994. {
  995. var Brands = db.KqProducts.Where(m => m.Status == 1).ToList();
  996. foreach (var Brand in Brands)
  997. {
  998. PublicFunction.SycnMachineCount(Id, Brand.Id);
  999. // RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, machineData);
  1000. // RedisDbconn.Instance.SetExpire("UserMachineData:" + IdBrand, function.get_Random(1800, 5400));
  1001. }
  1002. AddSysLog(Id, "Users", "SycnData");
  1003. db.SaveChanges();
  1004. return "success";
  1005. }
  1006. #endregion
  1007. #region 同步交易额
  1008. public IActionResult SycnTradeAmount(string right, int Id = 0)
  1009. {
  1010. ViewBag.RightInfo = RightInfo;
  1011. ViewBag.right = right;
  1012. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  1013. ViewBag.data = editData;
  1014. return View();
  1015. }
  1016. #endregion
  1017. #region 同步交易额
  1018. [HttpPost]
  1019. public string SycnTradeAmountDo(DateTime sdate, DateTime edate, int UserId, int BrandId)
  1020. {
  1021. if (sdate.AddMonths(1) < edate)
  1022. {
  1023. return "时间间隔不能超过1个月";
  1024. }
  1025. if (edate >= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"))
  1026. {
  1027. return "结束时间只能是今天之前";
  1028. }
  1029. string check = RedisDbconn.Instance.Get<string>("ResetUserTradeQueue:" + UserId + ":" + BrandId);
  1030. if (!string.IsNullOrEmpty(check))
  1031. {
  1032. return "请稍后再试";
  1033. }
  1034. try
  1035. {
  1036. 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);
  1037. RedisDbconn.Instance.Set("ResetUserTradeQueue:" + UserId + ":" + BrandId, "wait");
  1038. RedisDbconn.Instance.SetExpire("ResetUserTradeQueue:" + UserId + ":" + BrandId, 3600);
  1039. }
  1040. catch (Exception ex)
  1041. {
  1042. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计创客的交易额异常");
  1043. return "同步异常";
  1044. }
  1045. return "success";
  1046. }
  1047. #endregion
  1048. #region 创客展业城市
  1049. public IActionResult City(Users data, string right)
  1050. {
  1051. ViewBag.RightInfo = RightInfo;
  1052. ViewBag.right = right;
  1053. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  1054. ViewBag.TopUsers = TopUsers;
  1055. return View();
  1056. }
  1057. #endregion
  1058. #region 根据条件查询创客展业城市
  1059. public JsonResult CityData(Users data, string ParentMakerCode, string ParentRealName, int TopUserId, string Areas, int page = 1, int limit = 30)
  1060. {
  1061. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1062. Fields.Add("MakerCode", "1"); //创客编号
  1063. Fields.Add("RealName", "1"); //创客名称
  1064. Fields.Add("CitySetDate", "3"); //创建时间
  1065. Fields.Add("Areas", "2"); //省市
  1066. string condition = " and Status>-1";
  1067. //直属创客编号
  1068. if (!string.IsNullOrEmpty(ParentMakerCode))
  1069. {
  1070. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  1071. }
  1072. //直属创客名称
  1073. if (!string.IsNullOrEmpty(ParentRealName))
  1074. {
  1075. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  1076. }
  1077. //顶级创客
  1078. if (TopUserId > 0)
  1079. {
  1080. condition += " and ParentNav like '," + TopUserId + ",%'";
  1081. }
  1082. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", page, limit, condition);
  1083. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1084. foreach (Dictionary<string, object> dic in diclist)
  1085. {
  1086. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  1087. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1088. dic["ParentMakerCode"] = puser.MakerCode;
  1089. dic["ParentRealName"] = puser.RealName;
  1090. string ParentNav = dic["ParentNav"].ToString();
  1091. if (!string.IsNullOrEmpty(ParentNav))
  1092. {
  1093. int TopId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  1094. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1095. dic["TopMakerCode"] = tuser.MakerCode;
  1096. dic["TopRealName"] = tuser.RealName;
  1097. }
  1098. }
  1099. return Json(obj);
  1100. }
  1101. #endregion
  1102. #region 导出展业城市
  1103. public JsonResult ExportCity(Users data, string CreateDate, string ParentMakerCode, string ParentRealName, string AuthFlagSelect, int TopUserId, string RiskFlagSelect, string MerchantTypeSelect)
  1104. {
  1105. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1106. Fields.Add("MakerCode", "1"); //创客编号
  1107. Fields.Add("RealName", "1"); //创客名称
  1108. Fields.Add("Mobile", "1"); //手机号
  1109. Fields.Add("CertId", "1"); //身份证号码
  1110. Fields.Add("CreateDate", "3"); //注册时间
  1111. Fields.Add("SettleAmount", "3"); //结算金额
  1112. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  1113. Fields.Add("UserLevel", "0"); //创客等级
  1114. string condition = " and Status>-1";
  1115. //直属创客编号
  1116. if (!string.IsNullOrEmpty(ParentMakerCode))
  1117. {
  1118. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  1119. }
  1120. //直属创客名称
  1121. if (!string.IsNullOrEmpty(ParentRealName))
  1122. {
  1123. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  1124. }
  1125. //实名状态
  1126. if (!string.IsNullOrEmpty(AuthFlagSelect))
  1127. {
  1128. condition += " and AuthFlag=" + AuthFlagSelect;
  1129. }
  1130. //顶级创客
  1131. if (TopUserId > 0)
  1132. {
  1133. condition += " and ParentNav like '," + TopUserId + ",%'";
  1134. }
  1135. //风控标识
  1136. if (!string.IsNullOrEmpty(RiskFlagSelect))
  1137. {
  1138. condition += " and RiskFlag=" + RiskFlagSelect;
  1139. }
  1140. //商户创客类型
  1141. if (!string.IsNullOrEmpty(MerchantTypeSelect))
  1142. {
  1143. condition += " and MerchantType=" + MerchantTypeSelect;
  1144. }
  1145. 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);
  1146. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1147. foreach (Dictionary<string, object> dic in diclist)
  1148. {
  1149. dic["AuthFlag"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  1150. dic["RiskFlag"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  1151. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1152. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  1153. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  1154. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1155. dic["ParentMakerCode"] = puser.MakerCode;
  1156. dic["ParentRealName"] = puser.RealName;
  1157. string ParentNav = dic["ParentNav"].ToString();
  1158. if (!string.IsNullOrEmpty(ParentNav))
  1159. {
  1160. int TopId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  1161. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1162. dic["TopMakerCode"] = tuser.MakerCode;
  1163. dic["TopRealName"] = tuser.RealName;
  1164. }
  1165. dic.Remove("ParentUserId");
  1166. dic.Remove("ParentNav");
  1167. }
  1168. Dictionary<string, object> result = new Dictionary<string, object>();
  1169. result.Add("Status", "1");
  1170. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1171. result.Add("Obj", diclist);
  1172. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1173. ReturnFields.Add("MakerCode", "创客编号");
  1174. ReturnFields.Add("RealName", "创客姓名");
  1175. ReturnFields.Add("UserLevel", "创客等级");
  1176. ReturnFields.Add("SettleAmount", "提现金额(元)");
  1177. ReturnFields.Add("CashFreezeAmt", "冻结金额(元)");
  1178. ReturnFields.Add("CertId", "身份证号");
  1179. ReturnFields.Add("Mobile", "联系手机");
  1180. ReturnFields.Add("MerchantType", "商户创客类型");
  1181. ReturnFields.Add("MerchantDate", "成为商户创客时间");
  1182. ReturnFields.Add("ParentMakerCode", "直属创客编号");
  1183. ReturnFields.Add("ParentRealName", "直属创客名称");
  1184. ReturnFields.Add("TopMakerCode", "顶级创客编号");
  1185. ReturnFields.Add("TopRealName", "顶级创客名称");
  1186. ReturnFields.Add("AuthFlag", "实名状态");
  1187. ReturnFields.Add("RiskFlag", "风控状态");
  1188. ReturnFields.Add("CreateDate", "注册时间");
  1189. result.Add("Fields", ReturnFields);
  1190. AddSysLog("0", "Users", "ExportExcel");
  1191. return Json(result);
  1192. }
  1193. #endregion
  1194. #region 根据条件查询直属创客交易额列表
  1195. /// <summary>
  1196. /// 直属创客交易额列表
  1197. /// </summary>
  1198. /// <returns></returns>
  1199. public IActionResult Children(Users data, string right, int ParentId = 0, string MakerCode = "")
  1200. {
  1201. ViewBag.RightInfo = RightInfo;
  1202. ViewBag.right = right;
  1203. ViewBag.ParentId = ParentId.ToString();
  1204. ViewBag.MakerCode = MakerCode;
  1205. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  1206. ViewBag.TopUsers = TopUsers;
  1207. List<UserLevelSet> Levels = db.UserLevelSet.OrderBy(m => m.Id).ToList();
  1208. ViewBag.Levels = Levels;
  1209. List<KqProducts> Brands = db.KqProducts.OrderBy(m => m.Id).ToList();
  1210. ViewBag.Brands = Brands;
  1211. return View();
  1212. }
  1213. #endregion
  1214. #region 根据条件查询直属创客交易额列表
  1215. /// <summary>
  1216. /// 直属创客交易额列表
  1217. /// </summary>
  1218. /// <returns></returns>
  1219. public JsonResult ChildrenData(Users data, int BrandSelect, string MakerCode, string CreateDateData, int ParentId = 0, int page = 1, int limit = 30)
  1220. {
  1221. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1222. Fields.Add("MakerCode", "1"); //创客编号
  1223. int BrandId = BrandSelect;
  1224. string start = "";
  1225. string end = "";
  1226. string condition = " and Status>-1";
  1227. string con = " and Status>-1";
  1228. string sort = "Id desc";
  1229. //创客编号
  1230. if (!string.IsNullOrEmpty(MakerCode))
  1231. {
  1232. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  1233. }
  1234. if (ParentId > 0)
  1235. {
  1236. condition += " and ParentUserId=" + ParentId + " or Id=" + ParentId;
  1237. }
  1238. if (!string.IsNullOrEmpty(CreateDateData))
  1239. {
  1240. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1241. start = datelist[0].Replace("-", "");
  1242. end = datelist[1].Replace("-", "");
  1243. con += " and TradeDate>='" + start + "' and TradeDate<='" + end + "'";
  1244. }
  1245. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, sort, "True", page, limit, condition);
  1246. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1247. foreach (Dictionary<string, object> dic in diclist)
  1248. {
  1249. int UId = int.Parse(dic["Id"].ToString());
  1250. var Info = GetMonthTradeForBrand(UId, start, end, BrandId);
  1251. dic["TotalAmtfc"] = Convert.ToDecimal(Info["TotalAmtfc"].ToString()) + Convert.ToDecimal(Info["YAmtfc"].ToString());
  1252. dic["DAmtfc"] = Convert.ToDecimal(Info["DAmtfc"].ToString());
  1253. dic["JAmtfc"] = Convert.ToDecimal(Info["JAmtfc"].ToString());
  1254. dic["JfAmtfc"] = Convert.ToDecimal(Info["JfAmtfc"].ToString());
  1255. dic["JCountfc"] = Convert.ToInt32(Info["JCountfc"].ToString());
  1256. dic["YAmtfc"] = Convert.ToDecimal(Info["YAmtfc"].ToString());
  1257. dic["TotalAmtwd"] = Convert.ToDecimal(Info["TotalAmtwd"].ToString()) + Convert.ToDecimal(Info["YAmtwd"].ToString());
  1258. dic["DAmtwd"] = Convert.ToDecimal(Info["DAmtwd"].ToString());
  1259. dic["JAmtwd"] = Convert.ToDecimal(Info["JAmtwd"].ToString());
  1260. dic["JfAmtwd"] = Convert.ToDecimal(Info["JfAmtwd"].ToString());
  1261. dic["JCountwd"] = Convert.ToInt32(Info["JCountwd"].ToString());
  1262. dic["YAmtwd"] = Convert.ToDecimal(Info["YAmtwd"].ToString());
  1263. dic["BCount"] = Info["BCount"].ToString();
  1264. dic["ACount"] = Info["ACount"].ToString();
  1265. }
  1266. //扶持期
  1267. decimal TotalAmtfc = 0;
  1268. decimal DAmtfc = 0;
  1269. decimal JAmtfc = 0;
  1270. decimal JfAmtfc = 0;
  1271. int JCountfc = 0;
  1272. decimal YAmtfc = 0;
  1273. //稳定期
  1274. decimal TotalAmtwd = 0;
  1275. decimal DAmtwd = 0;
  1276. decimal JAmtwd = 0;
  1277. decimal JfAmtwd = 0;
  1278. int JCountwd = 0;
  1279. decimal YAmtwd = 0;
  1280. int BCount = 0;
  1281. int ACount = 0;
  1282. WebCMSEntities db = new WebCMSEntities();
  1283. Dictionary<string, object> other = new Dictionary<string, object>();
  1284. DataTable dt = OtherMySqlConn.dtable("select Sum(HelpDirectTradeAmt + HelpDirectDebitTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1285. if (dt.Rows.Count > 0)
  1286. {
  1287. TotalAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1288. }
  1289. dt = OtherMySqlConn.dtable("select Sum(HelpDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1290. if (dt.Rows.Count > 0)
  1291. {
  1292. DAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1293. }
  1294. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitTradeAmt),Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1295. if (dt.Rows.Count > 0)
  1296. {
  1297. JAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1298. }
  1299. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1300. if (dt.Rows.Count > 0)
  1301. {
  1302. JfAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1303. }
  1304. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1305. if (dt.Rows.Count > 0)
  1306. {
  1307. JCountfc = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1308. }
  1309. dt = OtherMySqlConn.dtable("select Sum(HelpDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1310. if (dt.Rows.Count > 0)
  1311. {
  1312. YAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1313. }
  1314. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectTradeAmt + NotHelpDirectDebitTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1315. if (dt.Rows.Count > 0)
  1316. {
  1317. TotalAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1318. }
  1319. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1320. if (dt.Rows.Count > 0)
  1321. {
  1322. DAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1323. }
  1324. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitTradeAmt),Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1325. if (dt.Rows.Count > 0)
  1326. {
  1327. JAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1328. }
  1329. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1330. if (dt.Rows.Count > 0)
  1331. {
  1332. JfAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1333. }
  1334. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1335. if (dt.Rows.Count > 0)
  1336. {
  1337. JCountwd = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1338. }
  1339. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1340. if (dt.Rows.Count > 0)
  1341. {
  1342. YAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1343. }
  1344. other.Add("TotalAmtfc", TotalAmtfc);
  1345. other.Add("DAmtfc", DAmtfc);
  1346. other.Add("JAmtfc", JAmtfc);
  1347. other.Add("JfAmtfc", JfAmtfc);
  1348. other.Add("JCountfc", JCountfc);
  1349. other.Add("YAmtfc", YAmtfc);
  1350. other.Add("TotalAmtwd", TotalAmtwd);
  1351. other.Add("DAmtwd", DAmtwd);
  1352. other.Add("JAmtwd", JAmtwd);
  1353. other.Add("JfAmtwd", JfAmtwd);
  1354. other.Add("JCountwd", JCountwd);
  1355. other.Add("YAmtwd", YAmtwd);
  1356. other.Add("BCount", BCount);
  1357. other.Add("ACount", ACount);
  1358. db.Dispose();
  1359. obj.Add("other", other);
  1360. return Json(obj);
  1361. }
  1362. public Dictionary<string, object> GetMonthTradeForBrand(int UserId, string sTradeDate, string eTradeDate, int BrandId)
  1363. {
  1364. string condition = " and Status>-1";
  1365. //产品类型
  1366. if (!string.IsNullOrEmpty(BrandId.ToString()) && BrandId > 0)
  1367. {
  1368. condition += " and BrandId =" + BrandId;
  1369. }
  1370. //创客Id
  1371. if (!string.IsNullOrEmpty(UserId.ToString()))
  1372. {
  1373. condition += " and UserId =" + UserId;
  1374. }
  1375. //开始时间
  1376. if (!string.IsNullOrEmpty(sTradeDate))
  1377. {
  1378. condition += " and TradeDate >=" + Convert.ToInt32(sTradeDate);
  1379. }
  1380. //结束时间
  1381. if (!string.IsNullOrEmpty(eTradeDate))
  1382. {
  1383. condition += " and TradeDate <=" + Convert.ToInt32(eTradeDate);
  1384. }
  1385. //扶持期
  1386. decimal TotalAmtfc = 0;
  1387. decimal DAmtfc = 0;
  1388. decimal JAmtfc = 0;
  1389. decimal JfAmtfc = 0;
  1390. int JCountfc = 0;
  1391. decimal YAmtfc = 0;
  1392. //稳定期
  1393. decimal TotalAmtwd = 0;
  1394. decimal DAmtwd = 0;
  1395. decimal JAmtwd = 0;
  1396. decimal JfAmtwd = 0;
  1397. int JCountwd = 0;
  1398. decimal YAmtwd = 0;
  1399. int BCount = 0;
  1400. int ACount = 0;
  1401. WebCMSEntities db = new WebCMSEntities();
  1402. Dictionary<string, object> obj = new Dictionary<string, object>();
  1403. DataTable dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt + HelpNonDirectDebitTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1404. if (dt.Rows.Count > 0)
  1405. {
  1406. TotalAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1407. }
  1408. dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1409. if (dt.Rows.Count > 0)
  1410. {
  1411. DAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1412. }
  1413. dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectDebitTradeAmt),Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1414. if (dt.Rows.Count > 0)
  1415. {
  1416. JAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1417. }
  1418. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1419. if (dt.Rows.Count > 0)
  1420. {
  1421. JfAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1422. }
  1423. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1424. if (dt.Rows.Count > 0)
  1425. {
  1426. JCountfc = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1427. }
  1428. dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='team'" + condition);
  1429. if (dt.Rows.Count > 0)
  1430. {
  1431. YAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1432. }
  1433. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt + NotHelpNonDirectDebitTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1434. if (dt.Rows.Count > 0)
  1435. {
  1436. TotalAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1437. }
  1438. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1439. if (dt.Rows.Count > 0)
  1440. {
  1441. DAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1442. }
  1443. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectDebitTradeAmt),Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1444. if (dt.Rows.Count > 0)
  1445. {
  1446. JAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1447. }
  1448. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1449. if (dt.Rows.Count > 0)
  1450. {
  1451. JfAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1452. }
  1453. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1454. if (dt.Rows.Count > 0)
  1455. {
  1456. JCountwd = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1457. }
  1458. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='team'" + condition);
  1459. if (dt.Rows.Count > 0)
  1460. {
  1461. YAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1462. }
  1463. obj.Add("TotalAmtfc", TotalAmtfc);
  1464. obj.Add("DAmtfc", DAmtfc);
  1465. obj.Add("JAmtfc", JAmtfc);
  1466. obj.Add("JfAmtfc", JfAmtfc);
  1467. obj.Add("JCountfc", JCountfc);
  1468. obj.Add("YAmtfc", YAmtfc);
  1469. obj.Add("TotalAmtwd", TotalAmtwd);
  1470. obj.Add("DAmtwd", DAmtwd);
  1471. obj.Add("JAmtwd", JAmtwd);
  1472. obj.Add("JfAmtwd", JfAmtwd);
  1473. obj.Add("JCountwd", JCountwd);
  1474. obj.Add("YAmtwd", YAmtwd);
  1475. obj.Add("BCount", BCount);
  1476. obj.Add("ACount", ACount);
  1477. db.Dispose();
  1478. return obj;
  1479. }
  1480. #endregion
  1481. }
  1482. }