UsersController.cs 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  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. // 1、未实名创客;
  471. // 2、已实名创客,无开通商户;
  472. // 3、近7天未在商城下单过商品;
  473. // 4、名下无未绑定机具、机具券,无未申请的循环机;
  474. public string Cancel(string UserId)
  475. {
  476. Users user = db.Users.FirstOrDefault(m => m.Id == Convert.ToInt32(UserId));
  477. if (user != null)
  478. {
  479. if (user.AuthFlag == 1)
  480. {
  481. bool check = db.PosMachinesTwo.Any(m => m.BuyUserId == user.Id && m.BindingState == 1);
  482. if (check)
  483. {
  484. // return Json(new AppResultJson() { Status = "-1", Info = "注销失败,未满足条件:已实名创客,无开通商户。如有疑问,请联系客服" });
  485. return "注销失败,未满足条件:已实名创客,无开通商户。如有疑问,请联系客服";
  486. }
  487. DateTime checkDate = DateTime.Now.AddDays(-7);
  488. check = db.Orders.Any(m => m.CreateDate >= checkDate && m.Status > 0 && m.UserId == user.Id);
  489. if (check)
  490. {
  491. // return Json(new AppResultJson() { Status = "-1", Info = "注销失败,未满足条件:近7天未在商城下单过商品。如有疑问,请联系客服" });
  492. return "注销失败,未满足条件:近7天未在商城下单过商品。如有疑问,请联系客服";
  493. }
  494. check = db.PosMachinesTwo.Any(m => m.BuyUserId == user.Id && m.IsPurchase == 0);
  495. if (check)
  496. {
  497. // return Json(new AppResultJson() { Status = "-1", Info = "注销失败,未满足条件:名下无未绑定机具、机具券,无未申请的循环机。如有疑问,请联系客服" });
  498. return "注销失败,未满足条件:名下无未绑定机具、机具券,无未申请的循环机。如有疑问,请联系客服";
  499. }
  500. check = db.PosCoupons.Any(m => m.UserId == user.Id && m.IsUse == 0);
  501. if (check)
  502. {
  503. // return Json(new AppResultJson() { Status = "-1", Info = "注销失败,未满足条件:名下无未绑定机具、机具券,无未申请的循环机。如有疑问,请联系客服" });
  504. return "注销失败,未满足条件:名下无未绑定机具、机具券,无未申请的循环机。如有疑问,请联系客服";
  505. }
  506. }
  507. UserForMobile forMobile = db.UserForMobile.FirstOrDefault(m => m.Mobile == user.Mobile);
  508. if (forMobile != null)
  509. {
  510. db.UserForMobile.Remove(forMobile);
  511. }
  512. UserForMakerCode forCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == user.MakerCode);
  513. if (forCode != null)
  514. {
  515. db.UserForMakerCode.Remove(forCode);
  516. }
  517. user.Status = -1;
  518. user.Mobile += "d";
  519. user.CertId += "d";
  520. function.WriteLog(user.Id + "于" + DateTime.Now.ToString() + "注销账号", "创客注销日志");
  521. // TODO: 每月扫描一次注销的创客,把注销创客伞下创客全部挂到注销创客的上级
  522. // TODO: 清除token,token登录返回
  523. db.SaveChanges();
  524. }
  525. return "success";
  526. }
  527. #endregion
  528. #region 开启
  529. /// <summary>
  530. /// 开启
  531. /// </summary>
  532. /// <returns></returns>
  533. public string Open(string Id)
  534. {
  535. string[] idlist = Id.Split(new char[] { ',' });
  536. AddSysLog(Id, "Users", "open");
  537. foreach (string subid in idlist)
  538. {
  539. int id = int.Parse(subid);
  540. Dictionary<string, object> Fields = new Dictionary<string, object>();
  541. Fields.Add("Status", 1);
  542. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  543. }
  544. db.SaveChanges();
  545. return "success";
  546. }
  547. #endregion
  548. #region 关闭
  549. /// <summary>
  550. /// 关闭
  551. /// </summary>
  552. /// <returns></returns>
  553. public string Close(string Id)
  554. {
  555. string[] idlist = Id.Split(new char[] { ',' });
  556. AddSysLog(Id, "Users", "close");
  557. foreach (string subid in idlist)
  558. {
  559. int id = int.Parse(subid);
  560. Dictionary<string, object> Fields = new Dictionary<string, object>();
  561. Fields.Add("Status", 0);
  562. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  563. }
  564. db.SaveChanges();
  565. return "success";
  566. }
  567. #endregion
  568. #region 一键企业创客
  569. /// <summary>
  570. /// 一键企业创客
  571. /// </summary>
  572. /// <returns></returns>
  573. public string OpenEnterpriseMaker(string Id)
  574. {
  575. string[] idlist = Id.Split(new char[] { ',' });
  576. AddSysLog(Id, "Users", "OpenEnterpriseMaker");
  577. foreach (string subid in idlist)
  578. {
  579. int id = int.Parse(subid);
  580. Dictionary<string, object> Fields = new Dictionary<string, object>();
  581. Fields.Add("BusinessFlag", 1);
  582. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  583. }
  584. db.SaveChanges();
  585. return "success";
  586. }
  587. #endregion
  588. #region 关闭企业创客
  589. /// <summary>
  590. /// 关闭企业创客
  591. /// </summary>
  592. /// <returns></returns>
  593. public string CloseEnterpriseMaker(string Id)
  594. {
  595. string[] idlist = Id.Split(new char[] { ',' });
  596. AddSysLog(Id, "Users", "CloseEnterpriseMaker");
  597. foreach (string subid in idlist)
  598. {
  599. int id = int.Parse(subid);
  600. Dictionary<string, object> Fields = new Dictionary<string, object>();
  601. Fields.Add("BusinessFlag", 0);
  602. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  603. }
  604. db.SaveChanges();
  605. return "success";
  606. }
  607. #endregion
  608. #region 一键大盟主
  609. /// <summary>
  610. /// 一键大盟主
  611. /// </summary>
  612. /// <returns></returns>
  613. public string SetBigLeader(string Id)
  614. {
  615. string[] idlist = Id.Split(new char[] { ',' });
  616. AddSysLog(Id, "Users", "SetBigLeader");
  617. foreach (string subid in idlist)
  618. {
  619. int id = int.Parse(subid);
  620. Dictionary<string, object> Fields = new Dictionary<string, object>();
  621. Fields.Add("LeaderLevel", 2);
  622. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  623. }
  624. db.SaveChanges();
  625. return "success";
  626. }
  627. #endregion
  628. #region 一键小盟主
  629. /// <summary>
  630. /// 一键小盟主
  631. /// </summary>
  632. /// <returns></returns>
  633. public string SetSmallLeader(string Id)
  634. {
  635. string[] idlist = Id.Split(new char[] { ',' });
  636. AddSysLog(Id, "Users", "SetSmallLeader");
  637. foreach (string subid in idlist)
  638. {
  639. int id = int.Parse(subid);
  640. Dictionary<string, object> Fields = new Dictionary<string, object>();
  641. Fields.Add("LeaderLevel", 1);
  642. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  643. }
  644. db.SaveChanges();
  645. return "success";
  646. }
  647. #endregion
  648. #region 风控
  649. public IActionResult Risk(string right, int Id = 0)
  650. {
  651. ViewBag.RightInfo = RightInfo;
  652. ViewBag.right = right;
  653. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  654. ViewBag.data = editData;
  655. return View();
  656. }
  657. #endregion
  658. #region 风控
  659. [HttpPost]
  660. public string Risk(Users data)
  661. {
  662. Users user = db.Users.FirstOrDefault(m => m.Id == data.Id);
  663. if (user != null)
  664. {
  665. user.RiskFlag = data.RiskFlag;
  666. user.RiskRemark = data.RiskRemark;
  667. db.SaveChanges();
  668. }
  669. return "success";
  670. }
  671. #endregion
  672. #region 解除风控
  673. public string UnRisk(string Id)
  674. {
  675. string[] idlist = Id.Split(new char[] { ',' });
  676. AddSysLog(Id, "Users", "UnRisk");
  677. foreach (string subid in idlist)
  678. {
  679. int id = int.Parse(subid);
  680. Dictionary<string, object> Fields = new Dictionary<string, object>();
  681. Fields.Add("RiskFlag", 0);
  682. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  683. }
  684. db.SaveChanges();
  685. return "success";
  686. }
  687. #endregion
  688. #region 重置密码
  689. public string ResetPwd(int Id)
  690. {
  691. string NewPwd = function.get_Random(6);
  692. Dictionary<string, object> Fields = new Dictionary<string, object>();
  693. Fields.Add("LoginPwd", function.MD532(NewPwd));
  694. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, Id);
  695. AddSysLog(Id, "Users", "ResetPwd");
  696. return "success|" + NewPwd;
  697. }
  698. #endregion
  699. #region 排序
  700. /// <summary>
  701. /// 排序
  702. /// </summary>
  703. /// <param name="Id"></param>
  704. public string Sort(int Id, int Sort)
  705. {
  706. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("Users", Sort, Id);
  707. AddSysLog(Id.ToString(), "Users", "sort");
  708. return "success";
  709. }
  710. #endregion
  711. #region 导入数据
  712. /// <summary>
  713. /// 导入数据
  714. /// </summary>
  715. /// <param name="ExcelData"></param>
  716. public string Import(string ExcelData, int Kind = 0)
  717. {
  718. ExcelData = HttpUtility.UrlDecode(ExcelData);
  719. JsonData list = JsonMapper.ToObject(ExcelData);
  720. if (Kind == 1)
  721. {
  722. for (int i = 1; i < list.Count; i++)
  723. {
  724. JsonData dr = list[i];
  725. string MakerCode = dr[0].ToString();
  726. string SettleAmount = dr[2].ToString();
  727. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  728. if (UserCode != null)
  729. {
  730. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  731. if (User != null)
  732. {
  733. User.SettleAmount = decimal.Parse(function.CheckInt(SettleAmount));
  734. }
  735. }
  736. }
  737. db.SaveChanges();
  738. }
  739. else if (Kind == 2)
  740. {
  741. for (int i = 1; i < list.Count; i++)
  742. {
  743. JsonData dr = list[i];
  744. string MakerCode = dr[0].ToString();
  745. string CashFreezeAmt = dr[2].ToString();
  746. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  747. if (UserCode != null)
  748. {
  749. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  750. if (User != null)
  751. {
  752. User.CashFreezeAmt = decimal.Parse(function.CheckInt(CashFreezeAmt));
  753. }
  754. }
  755. }
  756. db.SaveChanges();
  757. }
  758. else if (Kind == 3)
  759. {
  760. for (int i = 1; i < list.Count; i++)
  761. {
  762. JsonData dr = list[i];
  763. string MakerCode = dr[0].ToString();
  764. string RiskFlag = dr[2].ToString();
  765. string RiskNote = dr[3].ToString();
  766. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  767. if (UserCode != null)
  768. {
  769. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  770. if (User != null)
  771. {
  772. User.RiskFlag = ulong.Parse(function.CheckInt(RiskFlag));
  773. User.RiskRemark = RiskNote;
  774. }
  775. }
  776. }
  777. db.SaveChanges();
  778. }
  779. else if (Kind == 4)
  780. {
  781. string error = "";
  782. for (int i = 1; i < list.Count; i++)
  783. {
  784. JsonData dr = list[i];
  785. string MakerCode = dr[0].ToString();
  786. string OperationAmt = dr[2].ToString();//操作金额
  787. string OperationType = dr[3].ToString();//操作类型
  788. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  789. if (UserCode != null)
  790. {
  791. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  792. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == User.Id);
  793. if (account == null)
  794. {
  795. account = db.UserAccount.Add(new UserAccount()
  796. {
  797. Id = User.Id,
  798. UserId = User.Id,
  799. }).Entity;
  800. db.SaveChanges();
  801. }
  802. if (User != null)
  803. {
  804. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  805. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  806. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  807. int ChangeType = 0;
  808. if (OperationType == "1" && Convert.ToDecimal(OperationAmt) <= account.BalanceAmount)
  809. {
  810. account.BalanceAmount -= Convert.ToDecimal(OperationAmt);
  811. account.FreezeAmount += Convert.ToDecimal(OperationAmt);
  812. ChangeType = 61;
  813. }
  814. else if (OperationType == "1" && Convert.ToDecimal(OperationAmt) > account.BalanceAmount)
  815. {
  816. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "冻结金额大于余额" + '|' + '\n';
  817. }
  818. else if (OperationType == "2" && Convert.ToDecimal(OperationAmt) <= account.FreezeAmount)
  819. {
  820. account.BalanceAmount += Convert.ToDecimal(OperationAmt);
  821. account.FreezeAmount -= Convert.ToDecimal(OperationAmt);
  822. ChangeType = 62;
  823. }
  824. else if (OperationType == "2" && Convert.ToDecimal(OperationAmt) > account.FreezeAmount)
  825. {
  826. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "解冻金额大于冻结金额" + '|' + '\n';
  827. }
  828. else if (OperationType == "3" && Convert.ToDecimal(OperationAmt) <= account.BalanceAmount)
  829. {
  830. account.TotalAmount -= Convert.ToDecimal(OperationAmt);
  831. account.BalanceAmount -= Convert.ToDecimal(OperationAmt);
  832. ChangeType = 63;
  833. }
  834. else if (OperationType == "3" && Convert.ToDecimal(OperationAmt) > account.BalanceAmount)
  835. {
  836. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "扣减金额大于余额" + '|' + '\n';
  837. }
  838. else if (OperationType == "4")
  839. {
  840. account.TotalAmount += Convert.ToDecimal(OperationAmt);
  841. account.BalanceAmount += Convert.ToDecimal(OperationAmt);
  842. ChangeType = 64;
  843. }
  844. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  845. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  846. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  847. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  848. {
  849. CreateDate = DateTime.Now,
  850. UpdateDate = DateTime.Now,
  851. UserId = User.Id, //创客
  852. ChangeType = ChangeType, //变动类型
  853. ChangeAmount = Convert.ToDecimal(OperationAmt), //变更金额
  854. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  855. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  856. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  857. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  858. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  859. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  860. Remark = dr[4].ToString(),
  861. }).Entity;
  862. db.SaveChanges();
  863. AddSysLog(User.Id.ToString(), "Users", "ChangeCashFreezeAmts");
  864. db.SaveChanges();
  865. }
  866. }
  867. }
  868. db.SaveChanges();
  869. return "warning" + error;
  870. }
  871. AddSysLog("0", "Users", "Import");
  872. return "success";
  873. }
  874. #endregion
  875. #region 导出Excel
  876. /// <summary>
  877. /// 导出Excel
  878. /// </summary>
  879. /// <returns></returns>
  880. 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)
  881. {
  882. Dictionary<string, string> Fields = new Dictionary<string, string>();
  883. Fields.Add("MakerCode", "1"); //创客编号
  884. Fields.Add("RealName", "1"); //创客名称
  885. Fields.Add("Mobile", "1"); //手机号
  886. Fields.Add("CertId", "1"); //身份证号码
  887. Fields.Add("CreateDate", "3"); //注册时间
  888. Fields.Add("SettleAmount", "3"); //结算金额
  889. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  890. Fields.Add("UserLevel", "0"); //创客等级
  891. string condition = " and Status>-1";
  892. //直属创客编号
  893. if (!string.IsNullOrEmpty(ParentMakerCode))
  894. {
  895. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  896. }
  897. //直属创客名称
  898. if (!string.IsNullOrEmpty(ParentRealName))
  899. {
  900. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  901. }
  902. //实名状态
  903. if (!string.IsNullOrEmpty(AuthFlagSelect))
  904. {
  905. condition += " and AuthFlag=" + AuthFlagSelect;
  906. }
  907. //顶级创客
  908. if (TopUserId > 0)
  909. {
  910. condition += " and ParentNav like '," + TopUserId + ",%'";
  911. }
  912. //风控标识
  913. if (!string.IsNullOrEmpty(RiskFlagSelect))
  914. {
  915. condition += " and RiskFlag=" + RiskFlagSelect;
  916. }
  917. //商户创客类型
  918. if (!string.IsNullOrEmpty(MerchantTypeSelect))
  919. {
  920. condition += " and MerchantType=" + MerchantTypeSelect;
  921. }
  922. if (SelfId > 0)
  923. {
  924. Users self = db.Users.FirstOrDefault(m => m.Id == SelfId);
  925. if (self != null)
  926. {
  927. string ParentNav = function.CheckNull(self.ParentNav);
  928. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  929. }
  930. }
  931. if (ParentId > 0)
  932. {
  933. condition += " and ParentUserId=" + ParentId;
  934. }
  935. 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);
  936. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  937. foreach (Dictionary<string, object> dic in diclist)
  938. {
  939. dic["AuthFlag"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  940. dic["RiskFlag"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  941. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  942. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  943. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  944. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  945. dic["ParentMakerCode"] = puser.MakerCode;
  946. dic["ParentRealName"] = puser.RealName;
  947. string ParentNav = dic["ParentNav"].ToString();
  948. if (!string.IsNullOrEmpty(ParentNav))
  949. {
  950. string[] list = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  951. if (list.Length > 1)
  952. {
  953. int TopId = int.Parse(function.CheckInt(list[1]));
  954. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  955. dic["TopMakerCode"] = tuser.MakerCode;
  956. dic["TopRealName"] = tuser.RealName;
  957. }
  958. }
  959. dic.Remove("ParentUserId");
  960. dic.Remove("ParentNav");
  961. }
  962. Dictionary<string, object> result = new Dictionary<string, object>();
  963. result.Add("Status", "1");
  964. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  965. result.Add("Obj", diclist);
  966. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  967. ReturnFields.Add("MakerCode", "创客编号");
  968. ReturnFields.Add("RealName", "创客姓名");
  969. ReturnFields.Add("UserLevel", "创客等级");
  970. ReturnFields.Add("SettleAmount", "提现金额(元)");
  971. ReturnFields.Add("CashFreezeAmt", "冻结金额(元)");
  972. ReturnFields.Add("CertId", "身份证号");
  973. ReturnFields.Add("Mobile", "联系手机");
  974. ReturnFields.Add("MerchantType", "商户创客类型");
  975. ReturnFields.Add("MerchantDate", "成为商户创客时间");
  976. ReturnFields.Add("ParentMakerCode", "直属创客编号");
  977. ReturnFields.Add("ParentRealName", "直属创客名称");
  978. ReturnFields.Add("TopMakerCode", "顶级创客编号");
  979. ReturnFields.Add("TopRealName", "顶级创客名称");
  980. ReturnFields.Add("AuthFlag", "实名状态");
  981. ReturnFields.Add("RiskFlag", "风控状态");
  982. ReturnFields.Add("CreateDate", "注册时间");
  983. result.Add("Fields", ReturnFields);
  984. AddSysLog("0", "Users", "ExportExcel");
  985. return Json(result);
  986. }
  987. #endregion
  988. #region 直属创客导出Excel
  989. /// <summary>
  990. /// 直属创客导出Excel
  991. /// </summary>
  992. /// <returns></returns>
  993. public JsonResult ExportZSExcel(Users data, string MakerCode, string ParentMakerCode)
  994. {
  995. Dictionary<string, string> Fields = new Dictionary<string, string>();
  996. string condition = " and Status>-1";
  997. //创客编号
  998. if (!string.IsNullOrEmpty(MakerCode))
  999. {
  1000. condition += " and ParentUserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  1001. }
  1002. //直属创客编号
  1003. if (!string.IsNullOrEmpty(ParentMakerCode))
  1004. {
  1005. condition += " and ParentUserId in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  1006. }
  1007. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", 1, 20000, condition, "Id,MakerCode,RealName,UserLevel", false);
  1008. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1009. foreach (Dictionary<string, object> dic in diclist)
  1010. {
  1011. int Id = int.Parse(dic["Id"].ToString());
  1012. Users userZS = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  1013. dic["MakerCode"] = userZS.MakerCode;
  1014. dic["RealName"] = userZS.RealName;
  1015. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1016. }
  1017. Dictionary<string, object> result = new Dictionary<string, object>();
  1018. result.Add("Status", "1");
  1019. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1020. result.Add("Obj", diclist);
  1021. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1022. ReturnFields.Add("Id", "Id");
  1023. ReturnFields.Add("MakerCode", "创客编号");
  1024. ReturnFields.Add("RealName", "创客姓名");
  1025. ReturnFields.Add("UserLevel", "创客等级");
  1026. result.Add("Fields", ReturnFields);
  1027. AddSysLog("0", "Users", "ExportZSExcel");
  1028. return Json(result);
  1029. }
  1030. #endregion
  1031. #region 上级创客导出Excel
  1032. /// <summary>
  1033. /// 上级创客导出Excel
  1034. /// </summary>
  1035. /// <returns></returns>
  1036. public JsonResult ExportSJExcel(Users data, string MakerCode, string ParentMakerCode)
  1037. {
  1038. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1039. string condition = " and Status>-1";
  1040. //创客编号
  1041. if (!string.IsNullOrEmpty(MakerCode))
  1042. {
  1043. var query = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1044. Users self = db.Users.FirstOrDefault(m => m.Id == query.UserId);
  1045. if (self != null)
  1046. {
  1047. string ParentNav = function.CheckNull(self.ParentNav);
  1048. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  1049. }
  1050. }
  1051. //直属创客编号
  1052. if (!string.IsNullOrEmpty(ParentMakerCode))
  1053. {
  1054. var query = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ParentMakerCode);
  1055. Users self = db.Users.FirstOrDefault(m => m.Id == query.UserId);
  1056. if (self != null)
  1057. {
  1058. string ParentNav = function.CheckNull(self.ParentNav);
  1059. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  1060. }
  1061. }
  1062. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", 1, 20000, condition, "Id,MakerCode,RealName,UserLevel", false);
  1063. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1064. foreach (Dictionary<string, object> dic in diclist)
  1065. {
  1066. int Id = int.Parse(dic["Id"].ToString());
  1067. Users userSJ = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  1068. dic["MakerCode"] = userSJ.MakerCode;
  1069. dic["RealName"] = userSJ.RealName;
  1070. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1071. }
  1072. Dictionary<string, object> result = new Dictionary<string, object>();
  1073. result.Add("Status", "1");
  1074. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1075. result.Add("Obj", diclist);
  1076. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1077. ReturnFields.Add("Id", "Id");
  1078. ReturnFields.Add("MakerCode", "创客编号");
  1079. ReturnFields.Add("RealName", "创客姓名");
  1080. ReturnFields.Add("UserLevel", "创客等级");
  1081. result.Add("Fields", ReturnFields);
  1082. AddSysLog("0", "Users", "ExportExcel");
  1083. return Json(result);
  1084. }
  1085. #endregion
  1086. #region 同步数据
  1087. /// <summary>
  1088. /// 同步数据
  1089. /// </summary>
  1090. /// <returns></returns>
  1091. public string SycnData(int Id = 0)
  1092. {
  1093. var Brands = db.KqProducts.Where(m => m.Status == 1).ToList();
  1094. foreach (var Brand in Brands)
  1095. {
  1096. PublicFunction.SycnMachineCount(Id, Brand.Id);
  1097. }
  1098. AddSysLog(Id, "Users", "SycnData");
  1099. db.SaveChanges();
  1100. return "success";
  1101. }
  1102. #endregion
  1103. #region 同步交易额
  1104. public IActionResult SycnTradeAmount(string right, int Id = 0)
  1105. {
  1106. ViewBag.RightInfo = RightInfo;
  1107. ViewBag.right = right;
  1108. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  1109. ViewBag.data = editData;
  1110. return View();
  1111. }
  1112. #endregion
  1113. #region 同步交易额
  1114. [HttpPost]
  1115. public string SycnTradeAmountDo(DateTime sdate, DateTime edate, int UserId, int BrandId)
  1116. {
  1117. if (sdate.AddMonths(1) < edate)
  1118. {
  1119. return "时间间隔不能超过1个月";
  1120. }
  1121. if (edate >= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"))
  1122. {
  1123. return "结束时间只能是今天之前";
  1124. }
  1125. string check = RedisDbconn.Instance.Get<string>("ResetUserTradeQueue:" + UserId + ":" + BrandId);
  1126. if (!string.IsNullOrEmpty(check))
  1127. {
  1128. return "请稍后再试";
  1129. }
  1130. try
  1131. {
  1132. 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);
  1133. RedisDbconn.Instance.Set("ResetUserTradeQueue:" + UserId + ":" + BrandId, "wait");
  1134. RedisDbconn.Instance.SetExpire("ResetUserTradeQueue:" + UserId + ":" + BrandId, 3600);
  1135. }
  1136. catch (Exception ex)
  1137. {
  1138. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计创客的交易额异常");
  1139. return "同步异常";
  1140. }
  1141. return "success";
  1142. }
  1143. #endregion
  1144. #region 创客展业城市
  1145. public IActionResult City(Users data, string right)
  1146. {
  1147. ViewBag.RightInfo = RightInfo;
  1148. ViewBag.right = right;
  1149. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  1150. ViewBag.TopUsers = TopUsers;
  1151. return View();
  1152. }
  1153. #endregion
  1154. #region 根据条件查询创客展业城市
  1155. public JsonResult CityData(Users data, string ParentMakerCode, string ParentRealName, int TopUserId, string Areas, int page = 1, int limit = 30)
  1156. {
  1157. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1158. Fields.Add("MakerCode", "1"); //创客编号
  1159. Fields.Add("RealName", "1"); //创客名称
  1160. Fields.Add("CitySetDate", "3"); //创建时间
  1161. Fields.Add("Areas", "2"); //省市
  1162. string condition = " and Status>-1";
  1163. //直属创客编号
  1164. if (!string.IsNullOrEmpty(ParentMakerCode))
  1165. {
  1166. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  1167. }
  1168. //直属创客名称
  1169. if (!string.IsNullOrEmpty(ParentRealName))
  1170. {
  1171. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  1172. }
  1173. //顶级创客
  1174. if (TopUserId > 0)
  1175. {
  1176. condition += " and ParentNav like '," + TopUserId + ",%'";
  1177. }
  1178. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", page, limit, condition);
  1179. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1180. foreach (Dictionary<string, object> dic in diclist)
  1181. {
  1182. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  1183. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1184. dic["ParentMakerCode"] = puser.MakerCode;
  1185. dic["ParentRealName"] = puser.RealName;
  1186. string ParentNav = dic["ParentNav"].ToString();
  1187. if (!string.IsNullOrEmpty(ParentNav))
  1188. {
  1189. int TopId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  1190. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1191. dic["TopMakerCode"] = tuser.MakerCode;
  1192. dic["TopRealName"] = tuser.RealName;
  1193. }
  1194. }
  1195. return Json(obj);
  1196. }
  1197. #endregion
  1198. #region 导出展业城市
  1199. public JsonResult ExportCity(Users data, string CreateDate, string ParentMakerCode, string ParentRealName, string AuthFlagSelect, int TopUserId, string RiskFlagSelect, string MerchantTypeSelect)
  1200. {
  1201. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1202. Fields.Add("MakerCode", "1"); //创客编号
  1203. Fields.Add("RealName", "1"); //创客名称
  1204. Fields.Add("Mobile", "1"); //手机号
  1205. Fields.Add("CertId", "1"); //身份证号码
  1206. Fields.Add("CreateDate", "3"); //注册时间
  1207. Fields.Add("SettleAmount", "3"); //结算金额
  1208. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  1209. Fields.Add("UserLevel", "0"); //创客等级
  1210. string condition = " and Status>-1";
  1211. //直属创客编号
  1212. if (!string.IsNullOrEmpty(ParentMakerCode))
  1213. {
  1214. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  1215. }
  1216. //直属创客名称
  1217. if (!string.IsNullOrEmpty(ParentRealName))
  1218. {
  1219. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  1220. }
  1221. //实名状态
  1222. if (!string.IsNullOrEmpty(AuthFlagSelect))
  1223. {
  1224. condition += " and AuthFlag=" + AuthFlagSelect;
  1225. }
  1226. //顶级创客
  1227. if (TopUserId > 0)
  1228. {
  1229. condition += " and ParentNav like '," + TopUserId + ",%'";
  1230. }
  1231. //风控标识
  1232. if (!string.IsNullOrEmpty(RiskFlagSelect))
  1233. {
  1234. condition += " and RiskFlag=" + RiskFlagSelect;
  1235. }
  1236. //商户创客类型
  1237. if (!string.IsNullOrEmpty(MerchantTypeSelect))
  1238. {
  1239. condition += " and MerchantType=" + MerchantTypeSelect;
  1240. }
  1241. 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);
  1242. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1243. foreach (Dictionary<string, object> dic in diclist)
  1244. {
  1245. dic["AuthFlag"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  1246. dic["RiskFlag"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  1247. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1248. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  1249. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  1250. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1251. dic["ParentMakerCode"] = puser.MakerCode;
  1252. dic["ParentRealName"] = puser.RealName;
  1253. string ParentNav = dic["ParentNav"].ToString();
  1254. if (!string.IsNullOrEmpty(ParentNav))
  1255. {
  1256. int TopId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  1257. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1258. dic["TopMakerCode"] = tuser.MakerCode;
  1259. dic["TopRealName"] = tuser.RealName;
  1260. }
  1261. dic.Remove("ParentUserId");
  1262. dic.Remove("ParentNav");
  1263. }
  1264. Dictionary<string, object> result = new Dictionary<string, object>();
  1265. result.Add("Status", "1");
  1266. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1267. result.Add("Obj", diclist);
  1268. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1269. ReturnFields.Add("MakerCode", "创客编号");
  1270. ReturnFields.Add("RealName", "创客姓名");
  1271. ReturnFields.Add("UserLevel", "创客等级");
  1272. ReturnFields.Add("SettleAmount", "提现金额(元)");
  1273. ReturnFields.Add("CashFreezeAmt", "冻结金额(元)");
  1274. ReturnFields.Add("CertId", "身份证号");
  1275. ReturnFields.Add("Mobile", "联系手机");
  1276. ReturnFields.Add("MerchantType", "商户创客类型");
  1277. ReturnFields.Add("MerchantDate", "成为商户创客时间");
  1278. ReturnFields.Add("ParentMakerCode", "直属创客编号");
  1279. ReturnFields.Add("ParentRealName", "直属创客名称");
  1280. ReturnFields.Add("TopMakerCode", "顶级创客编号");
  1281. ReturnFields.Add("TopRealName", "顶级创客名称");
  1282. ReturnFields.Add("AuthFlag", "实名状态");
  1283. ReturnFields.Add("RiskFlag", "风控状态");
  1284. ReturnFields.Add("CreateDate", "注册时间");
  1285. result.Add("Fields", ReturnFields);
  1286. AddSysLog("0", "Users", "ExportExcel");
  1287. return Json(result);
  1288. }
  1289. #endregion
  1290. #region 根据条件查询直属创客交易额列表
  1291. /// <summary>
  1292. /// 直属创客交易额列表
  1293. /// </summary>
  1294. /// <returns></returns>
  1295. public IActionResult Children(Users data, string right, int ParentId = 0, string MakerCode = "")
  1296. {
  1297. ViewBag.RightInfo = RightInfo;
  1298. ViewBag.right = right;
  1299. ViewBag.ParentId = ParentId.ToString();
  1300. ViewBag.MakerCode = MakerCode;
  1301. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  1302. ViewBag.TopUsers = TopUsers;
  1303. List<UserLevelSet> Levels = db.UserLevelSet.OrderBy(m => m.Id).ToList();
  1304. ViewBag.Levels = Levels;
  1305. List<KqProducts> Brands = db.KqProducts.OrderBy(m => m.Id).ToList();
  1306. ViewBag.Brands = Brands;
  1307. return View();
  1308. }
  1309. #endregion
  1310. #region 根据条件查询直属创客交易额列表
  1311. /// <summary>
  1312. /// 直属创客交易额列表
  1313. /// </summary>
  1314. /// <returns></returns>
  1315. public JsonResult ChildrenData(Users data, int BrandSelect, string MakerCode, string CreateDateData, int ParentId = 0, int page = 1, int limit = 30)
  1316. {
  1317. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1318. Fields.Add("MakerCode", "1"); //创客编号
  1319. int BrandId = BrandSelect;
  1320. string start = "";
  1321. string end = "";
  1322. string condition = " and Status>-1 and AuthFlag >0";
  1323. string con = " and Status>-1";
  1324. string cons = " and Status>=-1";
  1325. string sort = "Id desc";
  1326. //创客编号
  1327. if (!string.IsNullOrEmpty(MakerCode))
  1328. {
  1329. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  1330. }
  1331. if (ParentId > 0)
  1332. {
  1333. condition += " and ParentUserId=" + ParentId + " or Id=" + ParentId;
  1334. }
  1335. if (!string.IsNullOrEmpty(CreateDateData))
  1336. {
  1337. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1338. start = datelist[0].Replace("-", "");
  1339. end = datelist[1].Replace("-", "");
  1340. con += " and TradeDate>='" + start + "' and TradeDate<='" + end + "'";
  1341. cons += " and DATE_FORMAT(BindingTime,'%Y%m%d') >=" + start + " and DATE_FORMAT(BindingTime,'%Y%m%d') <=" + end;
  1342. }
  1343. if (!string.IsNullOrEmpty(BrandSelect.ToString()) && BrandId > 0)
  1344. {
  1345. con += " and BrandId='" + BrandId + "'";
  1346. cons += " and BrandId='" + BrandId + "'";
  1347. }
  1348. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, sort, "True", page, limit, condition);
  1349. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1350. foreach (Dictionary<string, object> dic in diclist)
  1351. {
  1352. int UId = int.Parse(dic["Id"].ToString());
  1353. var Info = GetMonthTradeForBrand(UId, start, end, BrandId);
  1354. dic["TotalAmtfc"] = Convert.ToDecimal(Info["TotalAmtfc"].ToString()) + Convert.ToDecimal(Info["YAmtfc"].ToString());
  1355. dic["DAmtfc"] = Convert.ToDecimal(Info["DAmtfc"].ToString());
  1356. dic["JAmtfc"] = Convert.ToDecimal(Info["JAmtfc"].ToString());
  1357. dic["JfAmtfc"] = Convert.ToDecimal(Info["JfAmtfc"].ToString());
  1358. dic["JCountfc"] = Convert.ToInt32(Info["JCountfc"].ToString());
  1359. dic["YAmtfc"] = Convert.ToDecimal(Info["YAmtfc"].ToString());
  1360. dic["TotalAmtwd"] = Convert.ToDecimal(Info["TotalAmtwd"].ToString()) + Convert.ToDecimal(Info["YAmtwd"].ToString());
  1361. dic["DAmtwd"] = Convert.ToDecimal(Info["DAmtwd"].ToString());
  1362. dic["JAmtwd"] = Convert.ToDecimal(Info["JAmtwd"].ToString());
  1363. dic["JfAmtwd"] = Convert.ToDecimal(Info["JfAmtwd"].ToString());
  1364. dic["JCountwd"] = Convert.ToInt32(Info["JCountwd"].ToString());
  1365. dic["YAmtwd"] = Convert.ToDecimal(Info["YAmtwd"].ToString());
  1366. dic["TBCount"] = Info["TBCount"].ToString();
  1367. dic["TACount"] = Info["TACount"].ToString();
  1368. // dic["BCount"] = Info["BCount"].ToString();
  1369. // dic["ACount"] = Info["ACount"].ToString();
  1370. }
  1371. //个人
  1372. //扶持期
  1373. decimal TotalAmtfc = 0;
  1374. decimal DAmtfc = 0;
  1375. decimal JAmtfc = 0;
  1376. decimal JfAmtfc = 0;
  1377. int JCountfc = 0;
  1378. decimal YAmtfc = 0;
  1379. //稳定期
  1380. decimal TotalAmtwd = 0;
  1381. decimal DAmtwd = 0;
  1382. decimal JAmtwd = 0;
  1383. decimal JfAmtwd = 0;
  1384. int JCountwd = 0;
  1385. decimal YAmtwd = 0;
  1386. //团队
  1387. //扶持期
  1388. decimal TotalAmtfc1 = 0;
  1389. decimal DAmtfc1 = 0;
  1390. decimal JAmtfc1 = 0;
  1391. decimal JfAmtfc1 = 0;
  1392. int JCountfc1 = 0;
  1393. decimal YAmtfc1 = 0;
  1394. //稳定期
  1395. decimal TotalAmtwd1 = 0;
  1396. decimal DAmtwd1 = 0;
  1397. decimal JAmtwd1 = 0;
  1398. decimal JfAmtwd1 = 0;
  1399. int JCountwd1 = 0;
  1400. decimal YAmtwd1 = 0;
  1401. int PBCount = 0;
  1402. int PACount = 0;
  1403. int TBCount = 0;
  1404. int TACount = 0;
  1405. WebCMSEntities db = new WebCMSEntities();
  1406. Dictionary<string, object> other = new Dictionary<string, object>();
  1407. DataTable dt = OtherMySqlConn.dtable("select Sum(HelpDirectTradeAmt + HelpDirectDebitTradeAmt) from TradeDaySummary where SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1408. if (dt.Rows.Count > 0)
  1409. {
  1410. TotalAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1411. }
  1412. dt = OtherMySqlConn.dtable("select Sum(HelpDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1413. if (dt.Rows.Count > 0)
  1414. {
  1415. DAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1416. }
  1417. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitTradeAmt),Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1418. if (dt.Rows.Count > 0)
  1419. {
  1420. JAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1421. }
  1422. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1423. if (dt.Rows.Count > 0)
  1424. {
  1425. JfAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1426. }
  1427. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1428. if (dt.Rows.Count > 0)
  1429. {
  1430. JCountfc = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1431. }
  1432. dt = OtherMySqlConn.dtable("select Sum(HelpDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1433. if (dt.Rows.Count > 0)
  1434. {
  1435. YAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1436. }
  1437. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectTradeAmt + NotHelpDirectDebitTradeAmt) from TradeDaySummary where SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1438. if (dt.Rows.Count > 0)
  1439. {
  1440. TotalAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1441. }
  1442. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1443. if (dt.Rows.Count > 0)
  1444. {
  1445. DAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1446. }
  1447. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitTradeAmt),Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1448. if (dt.Rows.Count > 0)
  1449. {
  1450. JAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1451. }
  1452. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1453. if (dt.Rows.Count > 0)
  1454. {
  1455. JfAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1456. }
  1457. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1458. if (dt.Rows.Count > 0)
  1459. {
  1460. JCountwd = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1461. }
  1462. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='self' and UserId= '" + ParentId + "'" + con);
  1463. if (dt.Rows.Count > 0)
  1464. {
  1465. YAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1466. }
  1467. //TODO: 统计激活绑定数(个人)
  1468. dt = OtherMySqlConn.dtable("SELECT COUNT(0) count FROM PosMachinesTwo WHERE BindingState=1 AND BuyUserId= '" + ParentId + "'" + cons);
  1469. if (dt.Rows.Count > 0)
  1470. {
  1471. PBCount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1472. }
  1473. dt = OtherMySqlConn.dtable("SELECT SUM(DirectDebitCapNum) sum FROM UserTradeDaySummary WHERE SeoTitle='self' AND UserId= '" + ParentId + "'" + con);
  1474. if (dt.Rows.Count > 0)
  1475. {
  1476. PACount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1477. }
  1478. //TODO: 统计激活绑定数(团队)
  1479. dt = OtherMySqlConn.dtable("SELECT COUNT(0) count FROM PosMachinesTwo WHERE BindingState=1 AND BuyUserId IN (SELECT Id FROM Users WHERE ParentNav LIKE '%," + ParentId + ",%' OR Id=" + ParentId + ")" + cons);
  1480. if (dt.Rows.Count > 0)
  1481. {
  1482. TBCount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1483. }
  1484. dt = OtherMySqlConn.dtable("SELECT SUM(NonDirectDebitCapNum) sum FROM UserTradeDaySummary WHERE SeoTitle='team' AND UserId= '" + ParentId + "'" + con);
  1485. if (dt.Rows.Count > 0)
  1486. {
  1487. TACount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1488. }
  1489. DataTable dts = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt + HelpNonDirectDebitTradeAmt) from TradeDaySummary where SeoTitle='team' and UserId= '" + ParentId + "'" + con);
  1490. if (dts.Rows.Count > 0)
  1491. {
  1492. TotalAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][0].ToString()));
  1493. }
  1494. dts = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team' and UserId= '" + ParentId + "'" + con);
  1495. if (dt.Rows.Count > 0)
  1496. {
  1497. DAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][0].ToString()));
  1498. }
  1499. dts = OtherMySqlConn.dtable("select Sum(HelpNonDirectDebitTradeAmt),Sum(HelpNonDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team' and UserId= '" + ParentId + "'" + con);
  1500. if (dt.Rows.Count > 0)
  1501. {
  1502. JAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dts.Rows[0][1].ToString()));
  1503. }
  1504. dts = OtherMySqlConn.dtable("select Sum(HelpNonDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team' and UserId= '" + ParentId + "'" + con);
  1505. if (dts.Rows.Count > 0)
  1506. {
  1507. JfAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][0].ToString()));
  1508. }
  1509. dts = OtherMySqlConn.dtable("select Sum(HelpNoonDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='team' and UserId= '" + ParentId + "'" + con);
  1510. if (dts.Rows.Count > 0)
  1511. {
  1512. JCountfc1 = Convert.ToInt32(function.CheckInt(dts.Rows[0][0].ToString()));
  1513. }
  1514. dts = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='team' and UserId= '" + ParentId + "'" + con);
  1515. if (dts.Rows.Count > 0)
  1516. {
  1517. YAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][0].ToString()));
  1518. }
  1519. dts = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt + NotHelpNonDirectDebitTradeAmt) from TradeDaySummary where SeoTitle='team' and UserId= '" + ParentId + "'" + con);
  1520. if (dts.Rows.Count > 0)
  1521. {
  1522. TotalAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][0].ToString()));
  1523. }
  1524. dts = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team' and UserId= '" + ParentId + "'" + con);
  1525. if (dts.Rows.Count > 0)
  1526. {
  1527. DAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][0].ToString()));
  1528. }
  1529. dts = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectDebitTradeAmt),Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team' and UserId= '" + ParentId + "'" + con);
  1530. if (dts.Rows.Count > 0)
  1531. {
  1532. JAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dts.Rows[0][1].ToString()));
  1533. }
  1534. dts = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team' and UserId= '" + ParentId + "'" + con);
  1535. if (dts.Rows.Count > 0)
  1536. {
  1537. JfAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][0].ToString()));
  1538. }
  1539. dts = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='team' and UserId= '" + ParentId + "'" + con);
  1540. if (dts.Rows.Count > 0)
  1541. {
  1542. JCountwd1 = Convert.ToInt32(function.CheckInt(dts.Rows[0][0].ToString()));
  1543. }
  1544. dts = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='team' and UserId= '" + ParentId + "'" + con);
  1545. if (dts.Rows.Count > 0)
  1546. {
  1547. YAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][0].ToString()));
  1548. }
  1549. other.Add("TotalAmtfc", TotalAmtfc);
  1550. other.Add("DAmtfc", DAmtfc);
  1551. other.Add("JAmtfc", JAmtfc);
  1552. other.Add("JfAmtfc", JfAmtfc);
  1553. other.Add("JCountfc", JCountfc);
  1554. other.Add("YAmtfc", YAmtfc);
  1555. other.Add("TotalAmtwd", TotalAmtwd);
  1556. other.Add("DAmtwd", DAmtwd);
  1557. other.Add("JAmtwd", JAmtwd);
  1558. other.Add("JfAmtwd", JfAmtwd);
  1559. other.Add("JCountwd", JCountwd);
  1560. other.Add("YAmtwd", YAmtwd);
  1561. other.Add("TotalAmtfc1", TotalAmtfc1);
  1562. other.Add("DAmtfc1", DAmtfc1);
  1563. other.Add("JAmtfc1", JAmtfc1);
  1564. other.Add("JfAmtfc1", JfAmtfc1);
  1565. other.Add("JCountfc1", JCountfc1);
  1566. other.Add("YAmtfc1", YAmtfc1);
  1567. other.Add("TotalAmtwd1", TotalAmtwd1);
  1568. other.Add("DAmtwd1", DAmtwd1);
  1569. other.Add("JAmtwd1", JAmtwd1);
  1570. other.Add("JfAmtwd1", JfAmtwd1);
  1571. other.Add("JCountwd1", JCountwd1);
  1572. other.Add("YAmtwd1", YAmtwd1);
  1573. other.Add("PBCount", PBCount);
  1574. other.Add("PACount", PACount);
  1575. other.Add("TBCount", TBCount);
  1576. other.Add("TACount", TACount);
  1577. db.Dispose();
  1578. obj.Add("other", other);
  1579. return Json(obj);
  1580. }
  1581. public Dictionary<string, object> GetMonthTradeForBrand(int UserId, string sTradeDate, string eTradeDate, int BrandId)
  1582. {
  1583. string condition = " and Status>-1";
  1584. string cons = " and Status>=-1";
  1585. string con = " and Status>=-1";
  1586. //产品类型
  1587. if (!string.IsNullOrEmpty(BrandId.ToString()) && BrandId > 0)
  1588. {
  1589. condition += " and BrandId =" + BrandId;
  1590. cons += " and BrandId =" + BrandId;
  1591. con += " and BrandId =" + BrandId;
  1592. }
  1593. //创客Id
  1594. if (!string.IsNullOrEmpty(UserId.ToString()))
  1595. {
  1596. condition += " and UserId =" + UserId;
  1597. }
  1598. //开始时间
  1599. if (!string.IsNullOrEmpty(sTradeDate))
  1600. {
  1601. condition += " and TradeDate >=" + Convert.ToInt32(sTradeDate);
  1602. cons += " and DATE_FORMAT(BindingTime,'%Y%m%d') >=" + Convert.ToInt32(sTradeDate);
  1603. con += " and TradeDate >=" + Convert.ToInt32(sTradeDate);
  1604. }
  1605. //结束时间
  1606. if (!string.IsNullOrEmpty(eTradeDate))
  1607. {
  1608. condition += " and TradeDate <=" + Convert.ToInt32(eTradeDate);
  1609. cons += " and DATE_FORMAT(BindingTime,'%Y%m%d') <=" + Convert.ToInt32(eTradeDate);
  1610. con += " and TradeDate <=" + Convert.ToInt32(eTradeDate);
  1611. }
  1612. //扶持期
  1613. decimal TotalAmtfc = 0;
  1614. decimal DAmtfc = 0;
  1615. decimal JAmtfc = 0;
  1616. decimal JfAmtfc = 0;
  1617. int JCountfc = 0;
  1618. decimal YAmtfc = 0;
  1619. //稳定期
  1620. decimal TotalAmtwd = 0;
  1621. decimal DAmtwd = 0;
  1622. decimal JAmtwd = 0;
  1623. decimal JfAmtwd = 0;
  1624. int JCountwd = 0;
  1625. decimal YAmtwd = 0;
  1626. int BCount = 0;
  1627. int ACount = 0;
  1628. int PBCount = 0;
  1629. int PACount = 0;
  1630. int TBCount = 0;
  1631. int TACount = 0;
  1632. WebCMSEntities db = new WebCMSEntities();
  1633. Dictionary<string, object> obj = new Dictionary<string, object>();
  1634. DataTable dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt + HelpNonDirectDebitTradeAmt) from TradeDaySummary where SeoTitle='team'" + condition);
  1635. if (dt.Rows.Count > 0)
  1636. {
  1637. TotalAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1638. }
  1639. dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1640. if (dt.Rows.Count > 0)
  1641. {
  1642. DAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1643. }
  1644. dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectDebitTradeAmt),Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1645. if (dt.Rows.Count > 0)
  1646. {
  1647. JAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1648. }
  1649. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1650. if (dt.Rows.Count > 0)
  1651. {
  1652. JfAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1653. }
  1654. dt = OtherMySqlConn.dtable("select Sum(HelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1655. if (dt.Rows.Count > 0)
  1656. {
  1657. JCountfc = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1658. }
  1659. dt = OtherMySqlConn.dtable("select Sum(HelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='team'" + condition);
  1660. if (dt.Rows.Count > 0)
  1661. {
  1662. YAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1663. }
  1664. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt + NotHelpNonDirectDebitTradeAmt) from TradeDaySummary where SeoTitle='team'" + condition);
  1665. if (dt.Rows.Count > 0)
  1666. {
  1667. TotalAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1668. }
  1669. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1670. if (dt.Rows.Count > 0)
  1671. {
  1672. DAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1673. }
  1674. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectDebitTradeAmt),Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1675. if (dt.Rows.Count > 0)
  1676. {
  1677. JAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString())) - Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1678. }
  1679. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapTradeAmt) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1680. if (dt.Rows.Count > 0)
  1681. {
  1682. JfAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1683. }
  1684. dt = OtherMySqlConn.dtable("select Sum(NotHelpDirectDebitCapNum) from TradeDaySummary where QueryCount=0 and SeoTitle='team'" + condition);
  1685. if (dt.Rows.Count > 0)
  1686. {
  1687. JCountwd = Convert.ToInt32(function.CheckInt(dt.Rows[0][0].ToString()));
  1688. }
  1689. dt = OtherMySqlConn.dtable("select Sum(NotHelpNonDirectTradeAmt) from TradeDaySummary where QueryCount=1 and SeoTitle='team'" + condition);
  1690. if (dt.Rows.Count > 0)
  1691. {
  1692. YAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1693. }
  1694. dt = OtherMySqlConn.dtable("SELECT SUM(NonDirectDebitCapNum) sum FROM UserTradeDaySummary WHERE SeoTitle='team' AND UserId= '" + UserId + "'" + cons);
  1695. if (dt.Rows.Count > 0)
  1696. {
  1697. BCount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1698. }
  1699. dt = OtherMySqlConn.dtable("SELECT SUM(NonDirectDebitCapNum) sum FROM UserTradeDaySummary WHERE SeoTitle='team' AND UserId= '" + UserId + "'" + cons);
  1700. if (dt.Rows.Count > 0)
  1701. {
  1702. ACount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1703. }
  1704. //TODO: 统计激活绑定数(个人)
  1705. dt = OtherMySqlConn.dtable("SELECT COUNT(0) count FROM PosMachinesTwo WHERE BindingState=1 AND BuyUserId= '" + UserId + "'" + cons);
  1706. if (dt.Rows.Count > 0)
  1707. {
  1708. PBCount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1709. }
  1710. dt = OtherMySqlConn.dtable("SELECT SUM(DirectDebitCapNum) sum FROM UserTradeDaySummary WHERE SeoTitle='self' AND UserId= '" + UserId + "'" + con);
  1711. if (dt.Rows.Count > 0)
  1712. {
  1713. PACount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1714. }
  1715. //TODO: 统计激活绑定数(团队)
  1716. dt = OtherMySqlConn.dtable("SELECT COUNT(0) count FROM PosMachinesTwo WHERE BindingState=1 AND BuyUserId IN (SELECT Id FROM Users WHERE ParentNav LIKE '%," + UserId + ",%' OR Id=" + UserId + ")" + cons);
  1717. if (dt.Rows.Count > 0)
  1718. {
  1719. TBCount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1720. }
  1721. dt = OtherMySqlConn.dtable("SELECT SUM(NonDirectDebitCapNum) sum FROM UserTradeDaySummary WHERE SeoTitle='team' AND UserId= '" + UserId + "'" + con);
  1722. if (dt.Rows.Count > 0)
  1723. {
  1724. TACount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1725. }
  1726. obj.Add("TotalAmtfc", TotalAmtfc);
  1727. obj.Add("DAmtfc", DAmtfc);
  1728. obj.Add("JAmtfc", JAmtfc);
  1729. obj.Add("JfAmtfc", JfAmtfc);
  1730. obj.Add("JCountfc", JCountfc);
  1731. obj.Add("YAmtfc", YAmtfc);
  1732. obj.Add("TotalAmtwd", TotalAmtwd);
  1733. obj.Add("DAmtwd", DAmtwd);
  1734. obj.Add("JAmtwd", JAmtwd);
  1735. obj.Add("JfAmtwd", JfAmtwd);
  1736. obj.Add("JCountwd", JCountwd);
  1737. obj.Add("YAmtwd", YAmtwd);
  1738. obj.Add("BCount", BCount);
  1739. obj.Add("ACount", ACount);
  1740. obj.Add("PBCount", PBCount);
  1741. obj.Add("PACount", PACount);
  1742. obj.Add("TBCount", TBCount);
  1743. obj.Add("TACount", TACount);
  1744. db.Dispose();
  1745. return obj;
  1746. }
  1747. #endregion
  1748. }
  1749. }