UsersController.cs 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671
  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 sort = "Id desc";
  1228. //创客编号
  1229. if (!string.IsNullOrEmpty(MakerCode))
  1230. {
  1231. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  1232. }
  1233. if (ParentId > 0)
  1234. {
  1235. condition += " and ParentUserId=" + ParentId + " or Id=" + ParentId;
  1236. }
  1237. if (!string.IsNullOrEmpty(CreateDateData))
  1238. {
  1239. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1240. start = datelist[0].Replace("-", "");
  1241. end = datelist[1].Replace("-", "");
  1242. condition += " and TradeDate>='" + start + " 00:00:00' and TradeDate<='" + end + " 23:59:59'";
  1243. }
  1244. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, sort, "True", page, limit, condition);
  1245. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1246. foreach (Dictionary<string, object> dic in diclist)
  1247. {
  1248. int UId = int.Parse(dic["Id"].ToString());
  1249. var Info = GetMonthTradeForBrand(UId, start, end, BrandId);
  1250. dic["TotalAmtfc"] = Convert.ToDecimal(Info["TotalAmtfc"].ToString()) + Convert.ToDecimal(Info["YAmtfc"].ToString());
  1251. dic["DAmtfc"] = Convert.ToDecimal(Info["DAmtfc"].ToString());
  1252. dic["JAmtfc"] = Convert.ToDecimal(Info["JAmtfc"].ToString());
  1253. dic["JfAmtfc"] = Convert.ToDecimal(Info["JfAmtfc"].ToString());
  1254. dic["JCountfc"] = Convert.ToInt32(Info["JCountfc"].ToString());
  1255. dic["YAmtfc"] = Convert.ToDecimal(Info["YAmtfc"].ToString());
  1256. dic["TotalAmtwd"] = Convert.ToDecimal(Info["TotalAmtwd"].ToString()) + Convert.ToDecimal(Info["YAmtwd"].ToString());
  1257. dic["DAmtwd"] = Convert.ToDecimal(Info["DAmtwd"].ToString());
  1258. dic["JAmtwd"] = Convert.ToDecimal(Info["JAmtwd"].ToString());
  1259. dic["JfAmtwd"] = Convert.ToDecimal(Info["JfAmtwd"].ToString());
  1260. dic["JCountwd"] = Convert.ToInt32(Info["JCountwd"].ToString());
  1261. dic["YAmtwd"] = Convert.ToDecimal(Info["YAmtwd"].ToString());
  1262. dic["BCount"] = Info["BCount"].ToString();
  1263. dic["ACount"] = Info["ACount"].ToString();
  1264. }
  1265. //扶持期
  1266. decimal TotalAmtfc = 0;
  1267. decimal DAmtfc = 0;
  1268. decimal JAmtfc = 0;
  1269. decimal JfAmtfc = 0;
  1270. int JCountfc = 0;
  1271. decimal YAmtfc = 0;
  1272. //稳定期
  1273. decimal TotalAmtwd = 0;
  1274. decimal DAmtwd = 0;
  1275. decimal JAmtwd = 0;
  1276. decimal JfAmtwd = 0;
  1277. int JCountwd = 0;
  1278. decimal YAmtwd = 0;
  1279. int BCount = 0;
  1280. int ACount = 0;
  1281. WebCMSEntities db = new WebCMSEntities();
  1282. Dictionary<string, object> other = new Dictionary<string, object>();
  1283. DataTable dt = OtherMySqlConn.dtable("select Sum(HelpDirectTradeAmt + HelpDirectDebitTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'");
  1284. if (dt.Rows.Count > 0)
  1285. {
  1286. TotalAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1287. }
  1288. dt = OtherMySqlConn.dtable("select Sum(HelpDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'");
  1289. if (dt.Rows.Count > 0)
  1290. {
  1291. DAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1292. }
  1293. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitTradeAmt),Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'");
  1294. if (dt.Rows.Count > 0)
  1295. {
  1296. JAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1297. }
  1298. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'");
  1299. if (dt.Rows.Count > 0)
  1300. {
  1301. JfAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1302. }
  1303. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'");
  1304. if (dt.Rows.Count > 0)
  1305. {
  1306. JCountfc = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1307. }
  1308. dt = OtherMySqlConn.dtable("select Sum(HelpDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='self' and UserId= '" + ParentId + "'");
  1309. if (dt.Rows.Count > 0)
  1310. {
  1311. YAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1312. }
  1313. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectTradeAmt + NotHelpDirectDebitTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'");
  1314. if (dt.Rows.Count > 0)
  1315. {
  1316. TotalAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1317. }
  1318. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'");
  1319. if (dt.Rows.Count > 0)
  1320. {
  1321. DAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1322. }
  1323. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitTradeAmt),Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'");
  1324. if (dt.Rows.Count > 0)
  1325. {
  1326. JAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1327. }
  1328. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'");
  1329. if (dt.Rows.Count > 0)
  1330. {
  1331. JfAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1332. }
  1333. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'");
  1334. if (dt.Rows.Count > 0)
  1335. {
  1336. JCountwd = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1337. }
  1338. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='self' and UserId= '" + ParentId + "'");
  1339. if (dt.Rows.Count > 0)
  1340. {
  1341. YAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1342. }
  1343. other.Add("TotalAmtfc", TotalAmtfc);
  1344. other.Add("DAmtfc", DAmtfc);
  1345. other.Add("JAmtfc", JAmtfc);
  1346. other.Add("JfAmtfc", JfAmtfc);
  1347. other.Add("JCountfc", JCountfc);
  1348. other.Add("YAmtfc", YAmtfc);
  1349. other.Add("TotalAmtwd", TotalAmtwd);
  1350. other.Add("DAmtwd", DAmtwd);
  1351. other.Add("JAmtwd", JAmtwd);
  1352. other.Add("JfAmtwd", JfAmtwd);
  1353. other.Add("JCountwd", JCountwd);
  1354. other.Add("YAmtwd", YAmtwd);
  1355. other.Add("BCount", BCount);
  1356. other.Add("ACount", ACount);
  1357. db.Dispose();
  1358. obj.Add("other", other);
  1359. return Json(obj);
  1360. }
  1361. public Dictionary<string, object> GetMonthTradeForBrand(int UserId, string sTradeDate, string eTradeDate, int BrandId)
  1362. {
  1363. string condition = " and Status>-1";
  1364. //产品类型
  1365. if (!string.IsNullOrEmpty(BrandId.ToString()) && BrandId > 0)
  1366. {
  1367. condition += " and BrandId =" + BrandId;
  1368. }
  1369. //创客Id
  1370. if (!string.IsNullOrEmpty(UserId.ToString()))
  1371. {
  1372. condition += " and UserId =" + UserId;
  1373. }
  1374. //开始时间
  1375. if (!string.IsNullOrEmpty(sTradeDate))
  1376. {
  1377. condition += " and TradeDate >=" + Convert.ToInt32(sTradeDate);
  1378. }
  1379. //结束时间
  1380. if (!string.IsNullOrEmpty(eTradeDate))
  1381. {
  1382. condition += " and TradeDate <=" + Convert.ToInt32(eTradeDate);
  1383. }
  1384. //扶持期
  1385. decimal TotalAmtfc = 0;
  1386. decimal DAmtfc = 0;
  1387. decimal JAmtfc = 0;
  1388. decimal JfAmtfc = 0;
  1389. int JCountfc = 0;
  1390. decimal YAmtfc = 0;
  1391. //稳定期
  1392. decimal TotalAmtwd = 0;
  1393. decimal DAmtwd = 0;
  1394. decimal JAmtwd = 0;
  1395. decimal JfAmtwd = 0;
  1396. int JCountwd = 0;
  1397. decimal YAmtwd = 0;
  1398. int BCount = 0;
  1399. int ACount = 0;
  1400. WebCMSEntities db = new WebCMSEntities();
  1401. Dictionary<string, object> obj = new Dictionary<string, object>();
  1402. DataTable dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt + HelpNonDirectDebitTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1403. if (dt.Rows.Count > 0)
  1404. {
  1405. TotalAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1406. }
  1407. dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1408. if (dt.Rows.Count > 0)
  1409. {
  1410. DAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1411. }
  1412. dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectDebitTradeAmt),Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1413. if (dt.Rows.Count > 0)
  1414. {
  1415. JAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1416. }
  1417. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1418. if (dt.Rows.Count > 0)
  1419. {
  1420. JfAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1421. }
  1422. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1423. if (dt.Rows.Count > 0)
  1424. {
  1425. JCountfc = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1426. }
  1427. dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='team'" + condition);
  1428. if (dt.Rows.Count > 0)
  1429. {
  1430. YAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1431. }
  1432. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt + NotHelpNonDirectDebitTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1433. if (dt.Rows.Count > 0)
  1434. {
  1435. TotalAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1436. }
  1437. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1438. if (dt.Rows.Count > 0)
  1439. {
  1440. DAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1441. }
  1442. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectDebitTradeAmt),Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1443. if (dt.Rows.Count > 0)
  1444. {
  1445. JAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1446. }
  1447. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1448. if (dt.Rows.Count > 0)
  1449. {
  1450. JfAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1451. }
  1452. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1453. if (dt.Rows.Count > 0)
  1454. {
  1455. JCountwd = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1456. }
  1457. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='team'" + condition);
  1458. if (dt.Rows.Count > 0)
  1459. {
  1460. YAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1461. }
  1462. obj.Add("TotalAmtfc", TotalAmtfc);
  1463. obj.Add("DAmtfc", DAmtfc);
  1464. obj.Add("JAmtfc", JAmtfc);
  1465. obj.Add("JfAmtfc", JfAmtfc);
  1466. obj.Add("JCountfc", JCountfc);
  1467. obj.Add("YAmtfc", YAmtfc);
  1468. obj.Add("TotalAmtwd", TotalAmtwd);
  1469. obj.Add("DAmtwd", DAmtwd);
  1470. obj.Add("JAmtwd", JAmtwd);
  1471. obj.Add("JfAmtwd", JfAmtwd);
  1472. obj.Add("JCountwd", JCountwd);
  1473. obj.Add("YAmtwd", YAmtwd);
  1474. obj.Add("BCount", BCount);
  1475. obj.Add("ACount", ACount);
  1476. db.Dispose();
  1477. return obj;
  1478. }
  1479. #endregion
  1480. }
  1481. }