UsersController.cs 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357
  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 ShowFlag = 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. if (SelfId == 0 && ParentId == 0)
  64. {
  65. if (ShowFlag == 0)
  66. {
  67. Dictionary<string, object> objs = new Dictionary<string, object>();
  68. return Json(objs);
  69. }
  70. }
  71. string condition = " and Status>-1";
  72. string sort = "Id desc";
  73. //直属创客编号
  74. if (!string.IsNullOrEmpty(ParentMakerCode))
  75. {
  76. condition += " and ParentUserId in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  77. }
  78. //直属创客名称
  79. if (!string.IsNullOrEmpty(ParentRealName))
  80. {
  81. condition += " and ParentUserId in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  82. }
  83. //实名状态
  84. if (!string.IsNullOrEmpty(AuthFlagSelect))
  85. {
  86. condition += " and AuthFlag=" + AuthFlagSelect;
  87. }
  88. //顶级创客
  89. if (TopUserId > 0)
  90. {
  91. condition += " and ParentNav like '," + TopUserId + ",%'";
  92. }
  93. //风控标识
  94. if (!string.IsNullOrEmpty(RiskFlagSelect))
  95. {
  96. condition += " and RiskFlag=" + RiskFlagSelect;
  97. }
  98. //商户创客类型
  99. if (!string.IsNullOrEmpty(MerchantTypeSelect))
  100. {
  101. condition += " and MerchantType=" + MerchantTypeSelect;
  102. }
  103. if (sSettleAmount != null)
  104. {
  105. condition += " and SettleAmount>=" + sSettleAmount.Value;
  106. }
  107. if (eSettleAmount != null)
  108. {
  109. condition += " and SettleAmount<=" + eSettleAmount.Value;
  110. }
  111. if (sCashFreezeAmt != null)
  112. {
  113. condition += " and CashFreezeAmt>=" + sCashFreezeAmt.Value;
  114. }
  115. if (eCashFreezeAmt != null)
  116. {
  117. condition += " and CashFreezeAmt<=" + eCashFreezeAmt.Value;
  118. }
  119. if (SelfId > 0)
  120. {
  121. Users self = db.Users.FirstOrDefault(m => m.Id == SelfId);
  122. if (self != null)
  123. {
  124. string ParentNav = function.CheckNull(self.ParentNav);
  125. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  126. sort = "ParentNav asc";
  127. }
  128. }
  129. if (ParentId > 0)
  130. {
  131. condition += " and ParentUserId=" + ParentId;
  132. }
  133. if (UserId > 0)
  134. {
  135. condition += " and Id=" + UserId;
  136. }
  137. if (!string.IsNullOrEmpty(CreateDateData))
  138. {
  139. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  140. string start = datelist[0];
  141. string end = datelist[1];
  142. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  143. }
  144. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, sort, "True", page, limit, condition);
  145. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  146. foreach (Dictionary<string, object> dic in diclist)
  147. {
  148. dic["AuthFlagName"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  149. dic["RiskFlagName"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  150. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  151. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  152. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  153. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  154. dic["ParentMakerCode"] = puser.MakerCode;
  155. dic["ParentRealName"] = puser.RealName;
  156. string ParentNav = dic["ParentNav"].ToString();
  157. if (!string.IsNullOrEmpty(ParentNav))
  158. {
  159. string[] list = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  160. if (list.Length > 1)
  161. {
  162. int TopId = int.Parse(function.CheckInt(list[1]));
  163. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  164. dic["TopMakerCode"] = tuser.MakerCode;
  165. dic["TopRealName"] = tuser.RealName;
  166. }
  167. }
  168. }
  169. return Json(obj);
  170. }
  171. #endregion
  172. #region 增加创客
  173. /// <summary>
  174. /// 增加或修改创客信息
  175. /// </summary>
  176. /// <returns></returns>
  177. public IActionResult Add(string right)
  178. {
  179. ViewBag.RightInfo = RightInfo;
  180. ViewBag.right = right;
  181. return View();
  182. }
  183. #endregion
  184. #region 增加创客
  185. /// <summary>
  186. /// 增加或修改创客信息
  187. /// </summary>
  188. /// <returns></returns>
  189. [HttpPost]
  190. public string Add(Users data, string ParentMakerCode)
  191. {
  192. bool check = db.UserForMobile.Any(m => m.Mobile == data.Mobile);
  193. if (check)
  194. {
  195. return "手机号已存在,请重新输入";
  196. }
  197. check = db.UserForRealName.Any(m => m.RealName == data.RealName);
  198. if (check)
  199. {
  200. return "姓名已存在,请重新输入";
  201. }
  202. if (!string.IsNullOrEmpty(data.MakerCode))
  203. {
  204. check = db.UserForMakerCode.Any(m => m.MakerCode == data.MakerCode);
  205. if (check)
  206. {
  207. return "创客编码已存在,请重新输入";
  208. }
  209. }
  210. Dictionary<string, object> Fields = new Dictionary<string, object>();
  211. Fields.Add("RealName", data.RealName); //真实姓名
  212. Fields.Add("CertId", data.CertId); //身份证号
  213. Fields.Add("Mobile", data.Mobile); //手机号
  214. Fields.Add("LoginPwd", function.MD532(data.LoginPwd)); //登录密码
  215. Fields.Add("SettleBankCardNo", data.SettleBankCardNo); //结算银行卡号
  216. if (!string.IsNullOrEmpty(ParentMakerCode))
  217. {
  218. UserForMakerCode userFor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ParentMakerCode) ?? new UserForMakerCode();
  219. Users puser = db.Users.FirstOrDefault(m => m.Id == userFor.UserId) ?? new Users();
  220. Fields.Add("ParentUserId", userFor.UserId);
  221. Fields.Add("ParentNav", puser.ParentNav + "," + userFor.UserId + ",");
  222. }
  223. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("Users", Fields, 0);
  224. if (string.IsNullOrEmpty(ParentMakerCode))
  225. {
  226. string MakerCode = Id.ToString();
  227. for (int i = 0; i < 7 - Id.ToString().Length; i++)
  228. {
  229. MakerCode = "0" + MakerCode;
  230. }
  231. MakerCode = "K" + MakerCode;
  232. Fields = new Dictionary<string, object>();
  233. Fields.Add("MakerCode", MakerCode); //编号
  234. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, Id);
  235. }
  236. db.UserDetail.Add(new UserDetail() { Id = Id });
  237. db.UserData.Add(new UserData() { UserId = Id });
  238. AddSysLog(data.Id.ToString(), "Users", "add");
  239. db.SaveChanges();
  240. return "success";
  241. }
  242. #endregion
  243. #region 修改创客
  244. /// <summary>
  245. /// 增加或修改创客信息
  246. /// </summary>
  247. /// <returns></returns>
  248. public IActionResult Edit(string right, int Id = 0)
  249. {
  250. ViewBag.RightInfo = RightInfo;
  251. ViewBag.right = right;
  252. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  253. ViewBag.data = editData;
  254. return View();
  255. }
  256. #endregion
  257. #region 修改创客
  258. /// <summary>
  259. /// 增加或修改创客信息
  260. /// </summary>
  261. /// <returns></returns>
  262. [HttpPost]
  263. public string Edit(Users data, UserDetail userdetail, UserData userdata)
  264. {
  265. Dictionary<string, object> Fields = new Dictionary<string, object>();
  266. Fields.Add("RealName", data.RealName); //真实姓名
  267. Fields.Add("CertId", data.CertId); //身份证号
  268. Fields.Add("Mobile", data.Mobile); //手机号
  269. Fields.Add("SettleBankName", data.SettleBankName); //结算银行名称
  270. Fields.Add("SettleBankCardNo", data.SettleBankCardNo); //结算银行卡号
  271. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, data.Id);
  272. AddSysLog(data.Id.ToString(), "Users", "update");
  273. db.SaveChanges();
  274. return "success";
  275. }
  276. #endregion
  277. #region 修改结算金额
  278. public IActionResult EditSettleAmount(string right, int Id = 0)
  279. {
  280. ViewBag.RightInfo = RightInfo;
  281. ViewBag.right = right;
  282. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  283. ViewBag.data = editData;
  284. return View();
  285. }
  286. #endregion
  287. #region 修改结算金额
  288. [HttpPost]
  289. public string EditSettleAmount(Users data)
  290. {
  291. Dictionary<string, object> Fields = new Dictionary<string, object>();
  292. Fields.Add("SettleAmount", data.SettleAmount);
  293. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, data.Id);
  294. AddSysLog(data.Id.ToString(), "Users", "EditSettleAmount");
  295. db.SaveChanges();
  296. return "success";
  297. }
  298. #endregion
  299. #region 修改账户金额
  300. public IActionResult EditCashFreezeAmt(string right, int Id = 0)
  301. {
  302. ViewBag.RightInfo = RightInfo;
  303. ViewBag.right = right;
  304. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  305. ViewBag.data = editData;
  306. return View();
  307. }
  308. #endregion
  309. #region 修改账户金额
  310. [HttpPost]
  311. public string EditCashFreezeAmt(Users data, string Note, int Kind)
  312. {
  313. int UserId = data.Id;
  314. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  315. if (account == null)
  316. {
  317. account = db.UserAccount.Add(new UserAccount()
  318. {
  319. Id = UserId,
  320. UserId = UserId,
  321. }).Entity;
  322. db.SaveChanges();
  323. }
  324. if ((Kind == 1 || Kind == 3) && data.CashFreezeAmt > account.BalanceAmount)
  325. {
  326. return "账号余额不足";
  327. }
  328. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  329. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  330. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  331. int ChangeType = 0;
  332. if (Kind == 1 && data.CashFreezeAmt <= account.BalanceAmount)
  333. {
  334. account.BalanceAmount -= data.CashFreezeAmt;
  335. account.FreezeAmount += data.CashFreezeAmt;
  336. ChangeType = 61;
  337. }
  338. else if (Kind == 1 && data.CashFreezeAmt > account.BalanceAmount)
  339. {
  340. return "冻结金额大于余额";
  341. }
  342. else if (Kind == 2 && data.CashFreezeAmt <= account.FreezeAmount)
  343. {
  344. account.BalanceAmount += data.CashFreezeAmt;
  345. account.FreezeAmount -= data.CashFreezeAmt;
  346. ChangeType = 62;
  347. }
  348. else if (Kind == 2 && data.CashFreezeAmt > account.FreezeAmount)
  349. {
  350. return "解冻金额大于冻结金额";
  351. }
  352. else if (Kind == 3 && data.CashFreezeAmt <= account.BalanceAmount)
  353. {
  354. account.TotalAmount -= data.CashFreezeAmt;
  355. account.BalanceAmount -= data.CashFreezeAmt;
  356. ChangeType = 63;
  357. }
  358. else if (Kind == 3 && data.CashFreezeAmt > account.BalanceAmount)
  359. {
  360. return "扣减金额大于余额";
  361. }
  362. else if (Kind == 4)
  363. {
  364. account.TotalAmount += data.CashFreezeAmt;
  365. account.BalanceAmount += data.CashFreezeAmt;
  366. ChangeType = 64;
  367. }
  368. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  369. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  370. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  371. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  372. {
  373. CreateDate = DateTime.Now,
  374. UpdateDate = DateTime.Now,
  375. UserId = UserId, //创客
  376. ChangeType = ChangeType, //变动类型
  377. ChangeAmount = data.CashFreezeAmt, //变更金额
  378. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  379. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  380. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  381. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  382. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  383. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  384. Remark = Note,
  385. }).Entity;
  386. db.SaveChanges();
  387. RedisDbconn.Instance.Set("UserAccount:" + UserId, account);
  388. AddSysLog(data.Id.ToString(), "Users", "EditCashFreezeAmt");
  389. db.SaveChanges();
  390. return "success";
  391. }
  392. #endregion
  393. #region 账户操作
  394. public IActionResult EditBalance(string right, int Id = 0)
  395. {
  396. ViewBag.RightInfo = RightInfo;
  397. ViewBag.right = right;
  398. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  399. ViewBag.data = editData;
  400. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == Id) ?? new UserAccount();
  401. ViewBag.account = account;
  402. return View();
  403. }
  404. #endregion
  405. #region 账户操作
  406. [HttpPost]
  407. public string EditBalance(UserAccount data)
  408. {
  409. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == data.Id);
  410. if (account != null)
  411. {
  412. decimal amount = data.BalanceAmount - account.BalanceAmount;
  413. if (amount != 0)
  414. {
  415. account.BalanceAmount += amount;
  416. account.TotalAmount += amount;
  417. AddSysLog(data.Id.ToString(), "UserAccount", "EditBalance");
  418. db.SaveChanges();
  419. }
  420. }
  421. return "success";
  422. }
  423. #endregion
  424. #region 详情
  425. public IActionResult Detail(string right, int Id = 0)
  426. {
  427. ViewBag.RightInfo = RightInfo;
  428. ViewBag.right = right;
  429. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  430. ViewBag.AuthDate = editData.AuthDate == null ? "" : editData.AuthDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  431. string Age = "";
  432. if (!string.IsNullOrEmpty(editData.CertId))
  433. {
  434. int year = DateTime.Now.Year - int.Parse(editData.CertId.Substring(6, 4));
  435. Age = year.ToString();
  436. }
  437. ViewBag.Age = Age;
  438. ViewBag.QrCode = string.IsNullOrEmpty(editData.ReferenceQrCode) ? defaultImage : SourceHost + editData.ReferenceQrCode;
  439. return View();
  440. }
  441. #endregion
  442. #region 三/四要素验证
  443. public IActionResult ThreeElement(string right)
  444. {
  445. ViewBag.RightInfo = RightInfo;
  446. ViewBag.right = right;
  447. return View();
  448. }
  449. #endregion
  450. #region 三/四要素验证
  451. [HttpPost]
  452. public string ThreeElement(string Name, string CertId, string CardNo, string Mobile)
  453. {
  454. return "success";
  455. }
  456. #endregion
  457. #region 删除创客信息
  458. /// <summary>
  459. /// 删除创客信息
  460. /// </summary>
  461. /// <returns></returns>
  462. public string Delete(string Id)
  463. {
  464. string[] idlist = Id.Split(new char[] { ',' });
  465. AddSysLog(Id, "Users", "del");
  466. foreach (string subid in idlist)
  467. {
  468. int id = int.Parse(subid);
  469. Dictionary<string, object> Fields = new Dictionary<string, object>();
  470. Fields.Add("Status", -1);
  471. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  472. }
  473. db.SaveChanges();
  474. return "success";
  475. }
  476. #endregion
  477. #region 注销
  478. // 1.创客名下无未绑定机具且没有申请中的机具循环及兑换订单
  479. // 2.创客名下无预发机
  480. // 3.创客名下无分仓及运营中心
  481. // 满足以上全部条件的用户可申请注销,申请后用户二次填写确认填写信息(姓名、手机号、身份证号)即可完成注销
  482. public string Cancel(string UserId)
  483. {
  484. Users user = db.Users.FirstOrDefault(m => m.Id == Convert.ToInt32(UserId));
  485. if (user != null)
  486. {
  487. if (user.AuthFlag == 1)
  488. {
  489. // bool check = db.PosMachinesTwo.Any(m => m.BuyUserId == user.Id && m.BindingState == 1);
  490. // if (check)
  491. // {
  492. // return "注销失败,未满足条件:已实名创客,无开通商户。如有疑问,请联系客服";
  493. // }
  494. // DateTime checkDate = DateTime.Now.AddDays(-7);
  495. // check = db.Orders.Any(m => m.CreateDate >= checkDate && m.Status > 0 && m.UserId == user.Id);
  496. // if (check)
  497. // {
  498. // return "注销失败,未满足条件:近7天未在商城下单过商品。如有疑问,请联系客服";
  499. // }
  500. // check = db.PosMachinesTwo.Any(m => m.BuyUserId == user.Id && m.IsPurchase == 0);
  501. // if (check)
  502. // {
  503. // return "注销失败,未满足条件:名下无未绑定机具、机具券,无未申请的循环机。如有疑问,请联系客服";
  504. // }
  505. // check = db.PosCoupons.Any(m => m.UserId == user.Id && m.IsUse == 0);
  506. // if (check)
  507. // {
  508. // return "注销失败,未满足条件:名下无未绑定机具、机具券,无未申请的循环机。如有疑问,请联系客服";
  509. // }
  510. bool check = db.PosMachinesTwo.Any(m => m.BuyUserId == user.Id && m.BindingState == 0);
  511. if (check)
  512. {
  513. return "注销失败,未满足条件:名下存在未绑定机具。如有疑问,请联系客服";
  514. }
  515. check = db.MachineApply.Any(m => m.Status == 0 && m.UserId == user.Id);
  516. if (check)
  517. {
  518. return "注销失败,未满足条件:名下存在未完成的机具循环兑换订单。如有疑问,请联系客服";
  519. }
  520. check = db.PreSendStockDetail.Any(m => m.Status == 1 && m.AuthFlag == 0 && m.ToUserId == user.Id);
  521. if (check)
  522. {
  523. return "注销失败,未满足条件:名下存在预发机。如有疑问,请联系客服";
  524. }
  525. if (user.UserType == 1)
  526. {
  527. return "注销失败,未满足条件:名下存在运营中心。如有疑问,请联系客服";
  528. }
  529. check = db.StoreHouse.Any(m => m.Status == 1 && m.UserId == user.Id);
  530. if (check)
  531. {
  532. return "注销失败,未满足条件:名下存在分仓。如有疑问,请联系客服";
  533. }
  534. UserForMobile forMobile = db.UserForMobile.FirstOrDefault(m => m.Mobile == user.Mobile);
  535. if (forMobile != null)
  536. {
  537. db.Remove(forMobile);
  538. }
  539. UserForMakerCode forCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == user.MakerCode);
  540. if (forCode != null)
  541. {
  542. db.UserForMakerCode.Remove(forCode);
  543. }
  544. user.Status = -1;
  545. user.Mobile += "d";
  546. user.CertId += "d";
  547. }
  548. else
  549. {
  550. UserForMobile forMobile = db.UserForMobile.FirstOrDefault(m => m.Mobile == user.Mobile);
  551. if (forMobile != null)
  552. {
  553. db.UserForMobile.Remove(forMobile);
  554. }
  555. UserForMakerCode forCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == user.MakerCode);
  556. if (forCode != null)
  557. {
  558. db.UserForMakerCode.Remove(forCode);
  559. }
  560. user.Status = -1;
  561. user.Mobile += "d";
  562. user.CertId += "d";
  563. }
  564. function.WriteLog(user.Id + "于" + DateTime.Now.ToString() + "注销账号", "创客注销日志");
  565. // TODO: 每月扫描一次注销的创客,把注销创客伞下创客全部挂到注销创客的上级
  566. // TODO: 清除token,token登录返回
  567. db.SaveChanges();
  568. }
  569. return "success";
  570. }
  571. #endregion
  572. #region 开启
  573. /// <summary>
  574. /// 开启
  575. /// </summary>
  576. /// <returns></returns>
  577. public string Open(string Id)
  578. {
  579. string[] idlist = Id.Split(new char[] { ',' });
  580. AddSysLog(Id, "Users", "open");
  581. foreach (string subid in idlist)
  582. {
  583. int id = int.Parse(subid);
  584. Dictionary<string, object> Fields = new Dictionary<string, object>();
  585. Fields.Add("Status", 1);
  586. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  587. }
  588. db.SaveChanges();
  589. return "success";
  590. }
  591. #endregion
  592. #region 关闭
  593. /// <summary>
  594. /// 关闭
  595. /// </summary>
  596. /// <returns></returns>
  597. public string Close(string Id)
  598. {
  599. string[] idlist = Id.Split(new char[] { ',' });
  600. AddSysLog(Id, "Users", "close");
  601. foreach (string subid in idlist)
  602. {
  603. int id = int.Parse(subid);
  604. Dictionary<string, object> Fields = new Dictionary<string, object>();
  605. Fields.Add("Status", 0);
  606. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  607. }
  608. db.SaveChanges();
  609. return "success";
  610. }
  611. #endregion
  612. #region 一键企业创客
  613. /// <summary>
  614. /// 一键企业创客
  615. /// </summary>
  616. /// <returns></returns>
  617. public string OpenEnterpriseMaker(string Id)
  618. {
  619. string[] idlist = Id.Split(new char[] { ',' });
  620. AddSysLog(Id, "Users", "OpenEnterpriseMaker");
  621. foreach (string subid in idlist)
  622. {
  623. int id = int.Parse(subid);
  624. Dictionary<string, object> Fields = new Dictionary<string, object>();
  625. Fields.Add("BusinessFlag", 1);
  626. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  627. }
  628. db.SaveChanges();
  629. return "success";
  630. }
  631. #endregion
  632. #region 关闭企业创客
  633. /// <summary>
  634. /// 关闭企业创客
  635. /// </summary>
  636. /// <returns></returns>
  637. public string CloseEnterpriseMaker(string Id)
  638. {
  639. string[] idlist = Id.Split(new char[] { ',' });
  640. AddSysLog(Id, "Users", "CloseEnterpriseMaker");
  641. foreach (string subid in idlist)
  642. {
  643. int id = int.Parse(subid);
  644. Dictionary<string, object> Fields = new Dictionary<string, object>();
  645. Fields.Add("BusinessFlag", 0);
  646. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  647. }
  648. db.SaveChanges();
  649. return "success";
  650. }
  651. #endregion
  652. #region 一键大盟主
  653. /// <summary>
  654. /// 一键大盟主
  655. /// </summary>
  656. /// <returns></returns>
  657. public string SetBigLeader(string Id)
  658. {
  659. string[] idlist = Id.Split(new char[] { ',' });
  660. AddSysLog(Id, "Users", "SetBigLeader");
  661. foreach (string subid in idlist)
  662. {
  663. int id = int.Parse(subid);
  664. Dictionary<string, object> Fields = new Dictionary<string, object>();
  665. Fields.Add("LeaderLevel", 2);
  666. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  667. }
  668. db.SaveChanges();
  669. return "success";
  670. }
  671. #endregion
  672. #region 一键小盟主
  673. /// <summary>
  674. /// 一键小盟主
  675. /// </summary>
  676. /// <returns></returns>
  677. public string SetSmallLeader(string Id)
  678. {
  679. string[] idlist = Id.Split(new char[] { ',' });
  680. AddSysLog(Id, "Users", "SetSmallLeader");
  681. foreach (string subid in idlist)
  682. {
  683. int id = int.Parse(subid);
  684. Dictionary<string, object> Fields = new Dictionary<string, object>();
  685. Fields.Add("LeaderLevel", 1);
  686. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  687. }
  688. db.SaveChanges();
  689. return "success";
  690. }
  691. #endregion
  692. #region 风控
  693. public IActionResult Risk(string right, int Id = 0)
  694. {
  695. ViewBag.RightInfo = RightInfo;
  696. ViewBag.right = right;
  697. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  698. ViewBag.data = editData;
  699. return View();
  700. }
  701. #endregion
  702. #region 风控
  703. [HttpPost]
  704. public string Risk(Users data)
  705. {
  706. Users user = db.Users.FirstOrDefault(m => m.Id == data.Id);
  707. if (user != null)
  708. {
  709. user.RiskFlag = data.RiskFlag;
  710. user.RiskRemark = data.RiskRemark;
  711. db.SaveChanges();
  712. }
  713. return "success";
  714. }
  715. #endregion
  716. #region 解除风控
  717. public string UnRisk(string Id)
  718. {
  719. string[] idlist = Id.Split(new char[] { ',' });
  720. AddSysLog(Id, "Users", "UnRisk");
  721. foreach (string subid in idlist)
  722. {
  723. int id = int.Parse(subid);
  724. Dictionary<string, object> Fields = new Dictionary<string, object>();
  725. Fields.Add("RiskFlag", 0);
  726. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  727. }
  728. db.SaveChanges();
  729. return "success";
  730. }
  731. #endregion
  732. #region 重置密码
  733. public string ResetPwd(int Id)
  734. {
  735. string NewPwd = function.get_Random(6);
  736. Dictionary<string, object> Fields = new Dictionary<string, object>();
  737. Fields.Add("LoginPwd", function.MD532(NewPwd));
  738. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, Id);
  739. AddSysLog(Id, "Users", "ResetPwd");
  740. return "success|" + NewPwd;
  741. }
  742. #endregion
  743. #region 排序
  744. /// <summary>
  745. /// 排序
  746. /// </summary>
  747. /// <param name="Id"></param>
  748. public string Sort(int Id, int Sort)
  749. {
  750. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("Users", Sort, Id);
  751. AddSysLog(Id.ToString(), "Users", "sort");
  752. return "success";
  753. }
  754. #endregion
  755. #region 导入数据
  756. /// <summary>
  757. /// 导入数据
  758. /// </summary>
  759. /// <param name="ExcelData"></param>
  760. public string Import(string ExcelData, int Kind = 0)
  761. {
  762. ExcelData = HttpUtility.UrlDecode(ExcelData);
  763. JsonData list = JsonMapper.ToObject(ExcelData);
  764. if (Kind == 1)
  765. {
  766. for (int i = 1; i < list.Count; i++)
  767. {
  768. JsonData dr = list[i];
  769. string MakerCode = dr[0].ToString();
  770. string SettleAmount = dr[2].ToString();
  771. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  772. if (UserCode != null)
  773. {
  774. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  775. if (User != null)
  776. {
  777. User.SettleAmount = decimal.Parse(function.CheckInt(SettleAmount));
  778. }
  779. }
  780. }
  781. db.SaveChanges();
  782. }
  783. else if (Kind == 2)
  784. {
  785. for (int i = 1; i < list.Count; i++)
  786. {
  787. JsonData dr = list[i];
  788. string MakerCode = dr[0].ToString();
  789. string CashFreezeAmt = dr[2].ToString();
  790. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  791. if (UserCode != null)
  792. {
  793. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  794. if (User != null)
  795. {
  796. User.CashFreezeAmt = decimal.Parse(function.CheckInt(CashFreezeAmt));
  797. }
  798. }
  799. }
  800. db.SaveChanges();
  801. }
  802. else if (Kind == 3)
  803. {
  804. for (int i = 1; i < list.Count; i++)
  805. {
  806. JsonData dr = list[i];
  807. string MakerCode = dr[0].ToString();
  808. string RiskFlag = dr[2].ToString();
  809. string RiskNote = dr[3].ToString();
  810. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  811. if (UserCode != null)
  812. {
  813. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  814. if (User != null)
  815. {
  816. User.RiskFlag = ulong.Parse(function.CheckInt(RiskFlag));
  817. User.RiskRemark = RiskNote;
  818. }
  819. }
  820. }
  821. db.SaveChanges();
  822. }
  823. else if (Kind == 4)
  824. {
  825. string error = "";
  826. for (int i = 1; i < list.Count; i++)
  827. {
  828. JsonData dr = list[i];
  829. string MakerCode = dr[0].ToString();
  830. string OperationAmt = dr[2].ToString();//操作金额
  831. string OperationType = dr[3].ToString();//操作类型
  832. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  833. if (UserCode != null)
  834. {
  835. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  836. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == User.Id);
  837. if (account == null)
  838. {
  839. account = db.UserAccount.Add(new UserAccount()
  840. {
  841. Id = User.Id,
  842. UserId = User.Id,
  843. }).Entity;
  844. db.SaveChanges();
  845. }
  846. if (User != null)
  847. {
  848. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  849. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  850. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  851. int ChangeType = 0;
  852. if (OperationType == "1" && Convert.ToDecimal(OperationAmt) <= account.BalanceAmount)
  853. {
  854. account.BalanceAmount -= Convert.ToDecimal(OperationAmt);
  855. account.FreezeAmount += Convert.ToDecimal(OperationAmt);
  856. ChangeType = 61;
  857. }
  858. else if (OperationType == "1" && Convert.ToDecimal(OperationAmt) > account.BalanceAmount)
  859. {
  860. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "冻结金额大于余额" + '|' + '\n';
  861. }
  862. else if (OperationType == "2" && Convert.ToDecimal(OperationAmt) <= account.FreezeAmount)
  863. {
  864. account.BalanceAmount += Convert.ToDecimal(OperationAmt);
  865. account.FreezeAmount -= Convert.ToDecimal(OperationAmt);
  866. ChangeType = 62;
  867. }
  868. else if (OperationType == "2" && Convert.ToDecimal(OperationAmt) > account.FreezeAmount)
  869. {
  870. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "解冻金额大于冻结金额" + '|' + '\n';
  871. }
  872. else if (OperationType == "3" && Convert.ToDecimal(OperationAmt) <= account.BalanceAmount)
  873. {
  874. account.TotalAmount -= Convert.ToDecimal(OperationAmt);
  875. account.BalanceAmount -= Convert.ToDecimal(OperationAmt);
  876. ChangeType = 63;
  877. }
  878. else if (OperationType == "3" && Convert.ToDecimal(OperationAmt) > account.BalanceAmount)
  879. {
  880. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "扣减金额大于余额" + '|' + '\n';
  881. }
  882. else if (OperationType == "4")
  883. {
  884. account.TotalAmount += Convert.ToDecimal(OperationAmt);
  885. account.BalanceAmount += Convert.ToDecimal(OperationAmt);
  886. ChangeType = 64;
  887. }
  888. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  889. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  890. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  891. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  892. {
  893. CreateDate = DateTime.Now,
  894. UpdateDate = DateTime.Now,
  895. UserId = User.Id, //创客
  896. ChangeType = ChangeType, //变动类型
  897. ChangeAmount = Convert.ToDecimal(OperationAmt), //变更金额
  898. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  899. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  900. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  901. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  902. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  903. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  904. Remark = dr[4].ToString(),
  905. }).Entity;
  906. db.SaveChanges();
  907. AddSysLog(User.Id.ToString(), "Users", "ChangeCashFreezeAmts");
  908. db.SaveChanges();
  909. }
  910. }
  911. }
  912. db.SaveChanges();
  913. return "warning" + error;
  914. }
  915. AddSysLog("0", "Users", "Import");
  916. return "success";
  917. }
  918. #endregion
  919. #region 导出Excel
  920. /// <summary>
  921. /// 导出Excel
  922. /// </summary>
  923. /// <returns></returns>
  924. 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)
  925. {
  926. Dictionary<string, string> Fields = new Dictionary<string, string>();
  927. Fields.Add("MakerCode", "1"); //创客编号
  928. Fields.Add("RealName", "1"); //创客名称
  929. Fields.Add("Mobile", "1"); //手机号
  930. Fields.Add("CertId", "1"); //身份证号码
  931. Fields.Add("CreateDate", "3"); //注册时间
  932. Fields.Add("SettleAmount", "3"); //结算金额
  933. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  934. Fields.Add("UserLevel", "0"); //创客等级
  935. string condition = " and Status>-1";
  936. //直属创客编号
  937. if (!string.IsNullOrEmpty(ParentMakerCode))
  938. {
  939. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  940. }
  941. //直属创客名称
  942. if (!string.IsNullOrEmpty(ParentRealName))
  943. {
  944. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  945. }
  946. //实名状态
  947. if (!string.IsNullOrEmpty(AuthFlagSelect))
  948. {
  949. condition += " and AuthFlag=" + AuthFlagSelect;
  950. }
  951. //顶级创客
  952. if (TopUserId > 0)
  953. {
  954. condition += " and ParentNav like '," + TopUserId + ",%'";
  955. }
  956. //风控标识
  957. if (!string.IsNullOrEmpty(RiskFlagSelect))
  958. {
  959. condition += " and RiskFlag=" + RiskFlagSelect;
  960. }
  961. //商户创客类型
  962. if (!string.IsNullOrEmpty(MerchantTypeSelect))
  963. {
  964. condition += " and MerchantType=" + MerchantTypeSelect;
  965. }
  966. if (SelfId > 0)
  967. {
  968. Users self = db.Users.FirstOrDefault(m => m.Id == SelfId);
  969. if (self != null)
  970. {
  971. string ParentNav = function.CheckNull(self.ParentNav);
  972. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  973. }
  974. }
  975. if (ParentId > 0)
  976. {
  977. condition += " and ParentUserId=" + ParentId;
  978. }
  979. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", 1, 20000, condition, "MakerCode,RealName,ParentUserId,ParentNav,UserLevel,SettleAmount,CashFreezeAmt,CertId,Mobile,MerchantType,MerchantDate,AuthFlag,RiskFlag,CreateDate", false);
  980. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  981. foreach (Dictionary<string, object> dic in diclist)
  982. {
  983. dic["AuthFlag"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  984. dic["RiskFlag"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  985. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  986. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  987. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  988. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  989. dic["ParentMakerCode"] = puser.MakerCode;
  990. dic["ParentRealName"] = puser.RealName;
  991. string ParentNav = dic["ParentNav"].ToString();
  992. if (!string.IsNullOrEmpty(ParentNav))
  993. {
  994. string[] list = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  995. if (list.Length > 1)
  996. {
  997. int TopId = int.Parse(function.CheckInt(list[1]));
  998. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  999. dic["TopMakerCode"] = tuser.MakerCode;
  1000. dic["TopRealName"] = tuser.RealName;
  1001. }
  1002. }
  1003. dic.Remove("ParentUserId");
  1004. dic.Remove("ParentNav");
  1005. }
  1006. Dictionary<string, object> result = new Dictionary<string, object>();
  1007. result.Add("Status", "1");
  1008. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1009. result.Add("Obj", diclist);
  1010. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1011. ReturnFields.Add("MakerCode", "创客编号");
  1012. ReturnFields.Add("RealName", "创客姓名");
  1013. ReturnFields.Add("UserLevel", "创客等级");
  1014. ReturnFields.Add("SettleAmount", "提现金额(元)");
  1015. ReturnFields.Add("CashFreezeAmt", "冻结金额(元)");
  1016. ReturnFields.Add("CertId", "身份证号");
  1017. ReturnFields.Add("Mobile", "联系手机");
  1018. ReturnFields.Add("MerchantType", "商户创客类型");
  1019. ReturnFields.Add("MerchantDate", "成为商户创客时间");
  1020. ReturnFields.Add("ParentMakerCode", "直属创客编号");
  1021. ReturnFields.Add("ParentRealName", "直属创客名称");
  1022. ReturnFields.Add("TopMakerCode", "顶级创客编号");
  1023. ReturnFields.Add("TopRealName", "顶级创客名称");
  1024. ReturnFields.Add("AuthFlag", "实名状态");
  1025. ReturnFields.Add("RiskFlag", "风控状态");
  1026. ReturnFields.Add("CreateDate", "注册时间");
  1027. result.Add("Fields", ReturnFields);
  1028. AddSysLog("0", "Users", "ExportExcel");
  1029. return Json(result);
  1030. }
  1031. #endregion
  1032. #region 直属创客导出Excel
  1033. /// <summary>
  1034. /// 直属创客导出Excel
  1035. /// </summary>
  1036. /// <returns></returns>
  1037. public JsonResult ExportZSExcel(Users data, string MakerCode, string ParentMakerCode)
  1038. {
  1039. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1040. string condition = " and Status>-1";
  1041. //创客编号
  1042. if (!string.IsNullOrEmpty(MakerCode))
  1043. {
  1044. condition += " and ParentUserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  1045. }
  1046. //直属创客编号
  1047. if (!string.IsNullOrEmpty(ParentMakerCode))
  1048. {
  1049. condition += " and ParentUserId in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  1050. }
  1051. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", 1, 20000, condition, "Id,MakerCode,RealName,UserLevel", false);
  1052. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1053. foreach (Dictionary<string, object> dic in diclist)
  1054. {
  1055. int Id = int.Parse(dic["Id"].ToString());
  1056. Users userZS = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  1057. dic["MakerCode"] = userZS.MakerCode;
  1058. dic["RealName"] = userZS.RealName;
  1059. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1060. }
  1061. Dictionary<string, object> result = new Dictionary<string, object>();
  1062. result.Add("Status", "1");
  1063. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1064. result.Add("Obj", diclist);
  1065. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1066. ReturnFields.Add("Id", "Id");
  1067. ReturnFields.Add("MakerCode", "创客编号");
  1068. ReturnFields.Add("RealName", "创客姓名");
  1069. ReturnFields.Add("UserLevel", "创客等级");
  1070. result.Add("Fields", ReturnFields);
  1071. AddSysLog("0", "Users", "ExportZSExcel");
  1072. return Json(result);
  1073. }
  1074. #endregion
  1075. #region 上级创客导出Excel
  1076. /// <summary>
  1077. /// 上级创客导出Excel
  1078. /// </summary>
  1079. /// <returns></returns>
  1080. public JsonResult ExportSJExcel(Users data, string MakerCode, string ParentMakerCode)
  1081. {
  1082. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1083. string condition = " and Status>-1";
  1084. //创客编号
  1085. if (!string.IsNullOrEmpty(MakerCode))
  1086. {
  1087. var query = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1088. Users self = db.Users.FirstOrDefault(m => m.Id == query.UserId);
  1089. if (self != null)
  1090. {
  1091. string ParentNav = function.CheckNull(self.ParentNav);
  1092. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  1093. }
  1094. }
  1095. //直属创客编号
  1096. if (!string.IsNullOrEmpty(ParentMakerCode))
  1097. {
  1098. var query = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ParentMakerCode);
  1099. Users self = db.Users.FirstOrDefault(m => m.Id == query.UserId);
  1100. if (self != null)
  1101. {
  1102. string ParentNav = function.CheckNull(self.ParentNav);
  1103. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  1104. }
  1105. }
  1106. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", 1, 20000, condition, "Id,MakerCode,RealName,UserLevel", false);
  1107. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1108. foreach (Dictionary<string, object> dic in diclist)
  1109. {
  1110. int Id = int.Parse(dic["Id"].ToString());
  1111. Users userSJ = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  1112. dic["MakerCode"] = userSJ.MakerCode;
  1113. dic["RealName"] = userSJ.RealName;
  1114. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1115. }
  1116. Dictionary<string, object> result = new Dictionary<string, object>();
  1117. result.Add("Status", "1");
  1118. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1119. result.Add("Obj", diclist);
  1120. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1121. ReturnFields.Add("Id", "Id");
  1122. ReturnFields.Add("MakerCode", "创客编号");
  1123. ReturnFields.Add("RealName", "创客姓名");
  1124. ReturnFields.Add("UserLevel", "创客等级");
  1125. result.Add("Fields", ReturnFields);
  1126. AddSysLog("0", "Users", "ExportExcel");
  1127. return Json(result);
  1128. }
  1129. #endregion
  1130. #region 同步数据
  1131. /// <summary>
  1132. /// 同步数据
  1133. /// </summary>
  1134. /// <returns></returns>
  1135. public string SycnData(int Id = 0)
  1136. {
  1137. var Brands = db.KqProducts.Where(m => m.Status == 1).ToList();
  1138. foreach (var Brand in Brands)
  1139. {
  1140. PublicFunction.SycnMachineCount(Id, Brand.Id);
  1141. }
  1142. AddSysLog(Id, "Users", "SycnData");
  1143. db.SaveChanges();
  1144. return "success";
  1145. }
  1146. #endregion
  1147. #region 同步交易额
  1148. public IActionResult SycnTradeAmount(string right, int Id = 0)
  1149. {
  1150. ViewBag.RightInfo = RightInfo;
  1151. ViewBag.right = right;
  1152. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  1153. ViewBag.data = editData;
  1154. return View();
  1155. }
  1156. #endregion
  1157. #region 同步交易额
  1158. [HttpPost]
  1159. public string SycnTradeAmountDo(DateTime sdate, DateTime edate, int UserId, int BrandId)
  1160. {
  1161. if (sdate.AddMonths(1) < edate)
  1162. {
  1163. return "时间间隔不能超过1个月";
  1164. }
  1165. if (edate >= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"))
  1166. {
  1167. return "结束时间只能是今天之前";
  1168. }
  1169. string check = RedisDbconn.Instance.Get<string>("ResetUserTradeQueue:" + UserId + ":" + BrandId);
  1170. if (!string.IsNullOrEmpty(check))
  1171. {
  1172. return "请稍后再试";
  1173. }
  1174. try
  1175. {
  1176. 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);
  1177. RedisDbconn.Instance.Set("ResetUserTradeQueue:" + UserId + ":" + BrandId, "wait");
  1178. RedisDbconn.Instance.SetExpire("ResetUserTradeQueue:" + UserId + ":" + BrandId, 3600);
  1179. }
  1180. catch (Exception ex)
  1181. {
  1182. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计创客的交易额异常");
  1183. return "同步异常";
  1184. }
  1185. return "success";
  1186. }
  1187. #endregion
  1188. #region 创客展业城市
  1189. public IActionResult City(Users data, string right)
  1190. {
  1191. ViewBag.RightInfo = RightInfo;
  1192. ViewBag.right = right;
  1193. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  1194. ViewBag.TopUsers = TopUsers;
  1195. return View();
  1196. }
  1197. #endregion
  1198. #region 根据条件查询创客展业城市
  1199. public JsonResult CityData(Users data, string ParentMakerCode, string ParentRealName, int TopUserId, string Areas, int page = 1, int limit = 30)
  1200. {
  1201. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1202. Fields.Add("MakerCode", "1"); //创客编号
  1203. Fields.Add("RealName", "1"); //创客名称
  1204. Fields.Add("CitySetDate", "3"); //创建时间
  1205. Fields.Add("Areas", "2"); //省市
  1206. string condition = " and Status>-1";
  1207. //直属创客编号
  1208. if (!string.IsNullOrEmpty(ParentMakerCode))
  1209. {
  1210. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  1211. }
  1212. //直属创客名称
  1213. if (!string.IsNullOrEmpty(ParentRealName))
  1214. {
  1215. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  1216. }
  1217. //顶级创客
  1218. if (TopUserId > 0)
  1219. {
  1220. condition += " and ParentNav like '," + TopUserId + ",%'";
  1221. }
  1222. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", page, limit, condition);
  1223. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1224. foreach (Dictionary<string, object> dic in diclist)
  1225. {
  1226. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  1227. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1228. dic["ParentMakerCode"] = puser.MakerCode;
  1229. dic["ParentRealName"] = puser.RealName;
  1230. string ParentNav = dic["ParentNav"].ToString();
  1231. if (!string.IsNullOrEmpty(ParentNav))
  1232. {
  1233. int TopId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  1234. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1235. dic["TopMakerCode"] = tuser.MakerCode;
  1236. dic["TopRealName"] = tuser.RealName;
  1237. }
  1238. }
  1239. return Json(obj);
  1240. }
  1241. #endregion
  1242. #region 导出展业城市
  1243. public JsonResult ExportCity(Users data, string CreateDate, string ParentMakerCode, string ParentRealName, string AuthFlagSelect, int TopUserId, string RiskFlagSelect, string MerchantTypeSelect)
  1244. {
  1245. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1246. Fields.Add("MakerCode", "1"); //创客编号
  1247. Fields.Add("RealName", "1"); //创客名称
  1248. Fields.Add("Mobile", "1"); //手机号
  1249. Fields.Add("CertId", "1"); //身份证号码
  1250. Fields.Add("CreateDate", "3"); //注册时间
  1251. Fields.Add("SettleAmount", "3"); //结算金额
  1252. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  1253. Fields.Add("UserLevel", "0"); //创客等级
  1254. string condition = " and Status>-1";
  1255. //直属创客编号
  1256. if (!string.IsNullOrEmpty(ParentMakerCode))
  1257. {
  1258. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  1259. }
  1260. //直属创客名称
  1261. if (!string.IsNullOrEmpty(ParentRealName))
  1262. {
  1263. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  1264. }
  1265. //实名状态
  1266. if (!string.IsNullOrEmpty(AuthFlagSelect))
  1267. {
  1268. condition += " and AuthFlag=" + AuthFlagSelect;
  1269. }
  1270. //顶级创客
  1271. if (TopUserId > 0)
  1272. {
  1273. condition += " and ParentNav like '," + TopUserId + ",%'";
  1274. }
  1275. //风控标识
  1276. if (!string.IsNullOrEmpty(RiskFlagSelect))
  1277. {
  1278. condition += " and RiskFlag=" + RiskFlagSelect;
  1279. }
  1280. //商户创客类型
  1281. if (!string.IsNullOrEmpty(MerchantTypeSelect))
  1282. {
  1283. condition += " and MerchantType=" + MerchantTypeSelect;
  1284. }
  1285. 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);
  1286. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1287. foreach (Dictionary<string, object> dic in diclist)
  1288. {
  1289. dic["AuthFlag"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  1290. dic["RiskFlag"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  1291. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1292. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  1293. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  1294. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1295. dic["ParentMakerCode"] = puser.MakerCode;
  1296. dic["ParentRealName"] = puser.RealName;
  1297. string ParentNav = dic["ParentNav"].ToString();
  1298. if (!string.IsNullOrEmpty(ParentNav))
  1299. {
  1300. int TopId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  1301. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1302. dic["TopMakerCode"] = tuser.MakerCode;
  1303. dic["TopRealName"] = tuser.RealName;
  1304. }
  1305. dic.Remove("ParentUserId");
  1306. dic.Remove("ParentNav");
  1307. }
  1308. Dictionary<string, object> result = new Dictionary<string, object>();
  1309. result.Add("Status", "1");
  1310. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1311. result.Add("Obj", diclist);
  1312. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1313. ReturnFields.Add("MakerCode", "创客编号");
  1314. ReturnFields.Add("RealName", "创客姓名");
  1315. ReturnFields.Add("UserLevel", "创客等级");
  1316. ReturnFields.Add("SettleAmount", "提现金额(元)");
  1317. ReturnFields.Add("CashFreezeAmt", "冻结金额(元)");
  1318. ReturnFields.Add("CertId", "身份证号");
  1319. ReturnFields.Add("Mobile", "联系手机");
  1320. ReturnFields.Add("MerchantType", "商户创客类型");
  1321. ReturnFields.Add("MerchantDate", "成为商户创客时间");
  1322. ReturnFields.Add("ParentMakerCode", "直属创客编号");
  1323. ReturnFields.Add("ParentRealName", "直属创客名称");
  1324. ReturnFields.Add("TopMakerCode", "顶级创客编号");
  1325. ReturnFields.Add("TopRealName", "顶级创客名称");
  1326. ReturnFields.Add("AuthFlag", "实名状态");
  1327. ReturnFields.Add("RiskFlag", "风控状态");
  1328. ReturnFields.Add("CreateDate", "注册时间");
  1329. result.Add("Fields", ReturnFields);
  1330. AddSysLog("0", "Users", "ExportExcel");
  1331. return Json(result);
  1332. }
  1333. #endregion
  1334. #region 根据条件查询直属创客交易额列表
  1335. /// <summary>
  1336. /// 直属创客交易额列表
  1337. /// </summary>
  1338. /// <returns></returns>
  1339. public IActionResult Children(Users data, string right, int ParentId = 0, string MakerCode = "")
  1340. {
  1341. ViewBag.RightInfo = RightInfo;
  1342. ViewBag.right = right;
  1343. ViewBag.ParentId = ParentId.ToString();
  1344. ViewBag.MakerCode = MakerCode;
  1345. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  1346. ViewBag.TopUsers = TopUsers;
  1347. List<UserLevelSet> Levels = db.UserLevelSet.OrderBy(m => m.Id).ToList();
  1348. ViewBag.Levels = Levels;
  1349. List<KqProducts> Brands = db.KqProducts.OrderBy(m => m.Id).ToList();
  1350. ViewBag.Brands = Brands;
  1351. return View();
  1352. }
  1353. #endregion
  1354. #region 根据条件查询直属创客交易额列表
  1355. /// <summary>
  1356. /// 直属创客交易额列表
  1357. /// </summary>
  1358. /// <returns></returns>
  1359. public JsonResult ChildrenData(Users data, int BrandSelect, string MakerCode, string CreateDateData, int ParentId = 0, int page = 1, int limit = 30)
  1360. {
  1361. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1362. WebCMSEntities db = new WebCMSEntities();
  1363. Fields.Add("MakerCode", "1"); //创客编号
  1364. int BrandId = BrandSelect;
  1365. string start = "";
  1366. string end = "";
  1367. string condition = " and Status>-1 and AuthFlag >0";
  1368. string con = " and Status>-1";
  1369. string cons = " and Status>=-1";
  1370. string sort = "Id desc";
  1371. //创客编号
  1372. if (!string.IsNullOrEmpty(MakerCode))
  1373. {
  1374. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  1375. }
  1376. if (ParentId > 0)
  1377. {
  1378. condition += " and ParentUserId=" + ParentId + " or Id=" + ParentId;
  1379. }
  1380. //时间不为空
  1381. if (!string.IsNullOrEmpty(CreateDateData))
  1382. {
  1383. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1384. start = datelist[0].Replace("-", "");
  1385. end = datelist[1].Replace("-", "");
  1386. con += " and TradeDate>='" + start + "' and TradeDate<='" + end + "'";
  1387. cons += " and SeoKeyword >=" + start + " and SeoKeyword <=" + end;
  1388. }
  1389. //时间为空
  1390. else
  1391. {
  1392. start = DateTime.Now.ToString("yyyyMM") + "01";
  1393. end = DateTime.Now.AddMonths(1).ToString("yyyyMM") + "01";
  1394. con += " and TradeDate>='" + start + "' and TradeDate<'" + end + "'";
  1395. cons += " and SeoKeyword >=" + start + " and SeoKeyword <" + end;
  1396. }
  1397. if (!string.IsNullOrEmpty(BrandSelect.ToString()) && BrandId > 0)
  1398. {
  1399. con += " and BrandId='" + BrandId + "'";
  1400. cons += " and BrandId='" + BrandId + "'";
  1401. }
  1402. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, sort, "True", page, limit, condition);
  1403. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1404. foreach (Dictionary<string, object> dic in diclist)
  1405. {
  1406. int UId = int.Parse(dic["Id"].ToString());
  1407. var Info = GetMonthTradeForBrand(UId, start, end, BrandId);
  1408. dic["TotalAmtfc"] = Convert.ToDecimal(Info["TotalAmtfc"].ToString()) + Convert.ToDecimal(Info["YAmtfc"].ToString());
  1409. dic["DAmtfc"] = Convert.ToDecimal(Info["DAmtfc"].ToString());
  1410. dic["JAmtfc"] = Convert.ToDecimal(Info["JAmtfc"].ToString());
  1411. dic["JfAmtfc"] = Convert.ToDecimal(Info["JfAmtfc"].ToString());
  1412. dic["JCountfc"] = Convert.ToInt32(Info["JCountfc"].ToString());
  1413. dic["YAmtfc"] = Convert.ToDecimal(Info["YAmtfc"].ToString());
  1414. dic["TotalAmtwd"] = Convert.ToDecimal(Info["TotalAmtwd"].ToString()) + Convert.ToDecimal(Info["YAmtwd"].ToString());
  1415. dic["DAmtwd"] = Convert.ToDecimal(Info["DAmtwd"].ToString());
  1416. dic["JAmtwd"] = Convert.ToDecimal(Info["JAmtwd"].ToString());
  1417. dic["JfAmtwd"] = Convert.ToDecimal(Info["JfAmtwd"].ToString());
  1418. dic["JCountwd"] = Convert.ToInt32(Info["JCountwd"].ToString());
  1419. dic["YAmtwd"] = Convert.ToDecimal(Info["YAmtwd"].ToString());
  1420. dic["TotalAmtyl"] = Convert.ToDecimal(Info["TotalAmtyl"].ToString()) + Convert.ToDecimal(Info["YAmtyl"].ToString());
  1421. dic["DAmtyl"] = Convert.ToDecimal(Info["DAmtyl"].ToString());
  1422. dic["JAmtyl"] = Convert.ToDecimal(Info["JAmtyl"].ToString());
  1423. dic["JfAmtyl"] = Convert.ToDecimal(Info["JfAmtyl"].ToString());
  1424. dic["JCountyl"] = Convert.ToInt32(Info["JCountyl"].ToString());
  1425. dic["YAmtyl"] = Convert.ToDecimal(Info["YAmtyl"].ToString());
  1426. dic["TBCount"] = Info["TBCount"].ToString();
  1427. dic["TACount"] = Info["TACount"].ToString();
  1428. }
  1429. //个人
  1430. //扶持期
  1431. decimal TotalAmtfc = 0;
  1432. decimal DAmtfc = 0;
  1433. decimal JAmtfc = 0;
  1434. decimal JfAmtfc = 0;
  1435. int JCountfc = 0;
  1436. decimal YAmtfc = 0;
  1437. //稳定期
  1438. decimal TotalAmtwd = 0;
  1439. decimal DAmtwd = 0;
  1440. decimal JAmtwd = 0;
  1441. decimal JfAmtwd = 0;
  1442. int JCountwd = 0;
  1443. decimal YAmtwd = 0;
  1444. //盈利期
  1445. decimal TotalAmtyl = 0;
  1446. decimal DAmtyl = 0;
  1447. decimal JAmtyl = 0;
  1448. decimal JfAmtyl = 0;
  1449. int JCountyl = 0;
  1450. decimal YAmtyl = 0;
  1451. //团队
  1452. //扶持期
  1453. decimal TotalAmtfc1 = 0;
  1454. decimal DAmtfc1 = 0;
  1455. decimal JAmtfc1 = 0;
  1456. decimal JfAmtfc1 = 0;
  1457. int JCountfc1 = 0;
  1458. decimal YAmtfc1 = 0;
  1459. //稳定期
  1460. decimal TotalAmtwd1 = 0;
  1461. decimal DAmtwd1 = 0;
  1462. decimal JAmtwd1 = 0;
  1463. decimal JfAmtwd1 = 0;
  1464. int JCountwd1 = 0;
  1465. decimal YAmtwd1 = 0;
  1466. //盈利期
  1467. decimal TotalAmtyl1 = 0;
  1468. decimal DAmtyl1 = 0;
  1469. decimal JAmtyl1 = 0;
  1470. decimal JfAmtyl1 = 0;
  1471. int JCountyl1 = 0;
  1472. decimal YAmtyl1 = 0;
  1473. int PBCount = 0;
  1474. int PACount = 0;
  1475. int TBCount = 0;
  1476. int TACount = 0;
  1477. Dictionary<string, object> other = new Dictionary<string, object>();
  1478. DataTable dt = OtherMySqlConn.dtable("SELECT Sum(HelpDirectTradeAmt + HelpDirectDebitTradeAmt),Sum(if (QueryCount = 0,HelpDirectTradeAmt,0)),Sum(if (QueryCount = 0,HelpDirectDebitTradeAmt - HelpDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,HelpDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,HelpDirectDebitCapNum,0)),Sum(if (QueryCount = 1,HelpDirectTradeAmt,0)),Sum(NotHelpDirectTradeAmt + NotHelpDirectDebitTradeAmt),Sum(if (QueryCount = 0,NotHelpDirectTradeAmt,0)),Sum(if (QueryCount = 0,NotHelpDirectDebitTradeAmt - NotHelpDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,NotHelpDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,NotHelpDirectDebitCapNum,0)),Sum(if (QueryCount = 1,NotHelpDirectTradeAmt,0)),Sum(ProfitDirectTradeAmt + ProfitDirectDebitTradeAmt),Sum(if (QueryCount = 0,ProfitDirectTradeAmt,0)),Sum(if (QueryCount = 0,ProfitDirectDebitTradeAmt - ProfitDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,ProfitDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,ProfitDirectDebitCapNum,0)),Sum(if (QueryCount = 1,ProfitDirectTradeAmt,0))from TradeDaySummary where SeoTitle = 'self' and UserId =" + ParentId + "" + con);
  1479. if (dt.Rows.Count > 0)
  1480. {
  1481. TotalAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1482. DAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1483. JAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][2].ToString()));
  1484. JfAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][3].ToString()));
  1485. JCountfc = Convert.ToInt32(function.CheckInt(dt.Rows[0][4].ToString()));
  1486. YAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][5].ToString()));
  1487. TotalAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][6].ToString()));
  1488. DAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][7].ToString()));
  1489. JAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][8].ToString()));
  1490. JfAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][9].ToString()));
  1491. JCountwd = Convert.ToInt32(function.CheckInt(dt.Rows[0][10].ToString()));
  1492. YAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][11].ToString()));
  1493. TotalAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][12].ToString()));
  1494. DAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][13].ToString()));
  1495. JAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][14].ToString()));
  1496. JfAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][15].ToString()));
  1497. JCountyl = Convert.ToInt32(function.CheckInt(dt.Rows[0][16].ToString()));
  1498. YAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][17].ToString()));
  1499. }
  1500. //统计激活数(个人、团队)
  1501. dt = OtherMySqlConn.dtable("SELECT SUM(if(SeoTitle='self',ActiveBuddyMerStatus,0)),SUM(if(SeoTitle='team',ActiveBuddyMerStatus,0)) FROM UserTradeMonthSummary WHERE UserId= " + ParentId + "" + cons);
  1502. if (dt.Rows.Count > 0)
  1503. {
  1504. PACount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1505. TACount = Convert.ToInt32(function.CheckNum(dt.Rows[0][1].ToString()));
  1506. }
  1507. DataTable dts = OtherMySqlConn.dtable("SELECT Sum(HelpNonDirectTradeAmt + HelpNonDirectDebitTradeAmt),Sum(if (QueryCount = 0,HelpNonDirectTradeAmt,0)),Sum(if (QueryCount = 0,HelpNonDirectDebitTradeAmt - HelpNonDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,HelpNonDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,HelpNonDirectDebitCapNum,0)),Sum(if (QueryCount = 1,HelpNonDirectTradeAmt,0)),Sum(NotHelpNonDirectTradeAmt + NotHelpNonDirectDebitTradeAmt),Sum(if (QueryCount = 0,NotHelpNonDirectTradeAmt,0)),Sum(if (QueryCount = 0,NotHelpNonDirectDebitTradeAmt - NotHelpNonDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,NotHelpNonDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,NotHelpNonDirectDebitCapNum,0)),Sum(if (QueryCount = 1,NotHelpNonDirectTradeAmt,0)),Sum(ProfitNonDirectTradeAmt + ProfitNonDirectDebitTradeAmt),Sum(if (QueryCount = 0,ProfitNonDirectTradeAmt,0)),Sum(if (QueryCount = 0,ProfitNonDirectDebitTradeAmt - ProfitNonDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,ProfitNonDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,ProfitNonDirectDebitCapNum,0)),Sum(if (QueryCount = 1,ProfitNonDirectTradeAmt,0))from TradeDaySummary where SeoTitle = 'team' and UserId =" + ParentId + "" + con);
  1508. if (dts.Rows.Count > 0)
  1509. {
  1510. TotalAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][0].ToString()));
  1511. DAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][1].ToString()));
  1512. JAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][2].ToString()));
  1513. JfAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][3].ToString()));
  1514. JCountfc1 = Convert.ToInt32(function.CheckInt(dts.Rows[0][4].ToString()));
  1515. YAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][5].ToString()));
  1516. TotalAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][6].ToString()));
  1517. DAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][7].ToString()));
  1518. JAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][8].ToString()));
  1519. JfAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][9].ToString()));
  1520. JCountwd1 = Convert.ToInt32(function.CheckInt(dts.Rows[0][10].ToString()));
  1521. YAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][11].ToString()));
  1522. TotalAmtyl1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][12].ToString()));
  1523. DAmtyl1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][13].ToString()));
  1524. JAmtyl1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][14].ToString()));
  1525. JfAmtyl1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][15].ToString()));
  1526. JCountyl1 = Convert.ToInt32(function.CheckInt(dts.Rows[0][16].ToString()));
  1527. YAmtyl1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][17].ToString()));
  1528. }
  1529. other.Add("TotalAmtfc", TotalAmtfc);
  1530. other.Add("DAmtfc", DAmtfc);
  1531. other.Add("JAmtfc", JAmtfc);
  1532. other.Add("JfAmtfc", JfAmtfc);
  1533. other.Add("JCountfc", JCountfc);
  1534. other.Add("YAmtfc", YAmtfc);
  1535. other.Add("TotalAmtwd", TotalAmtwd);
  1536. other.Add("DAmtwd", DAmtwd);
  1537. other.Add("JAmtwd", JAmtwd);
  1538. other.Add("JfAmtwd", JfAmtwd);
  1539. other.Add("JCountwd", JCountwd);
  1540. other.Add("YAmtwd", YAmtwd);
  1541. other.Add("TotalAmtyl", TotalAmtyl);
  1542. other.Add("DAmtyl", DAmtyl);
  1543. other.Add("JAmtyl", JAmtyl);
  1544. other.Add("JfAmtyl", JfAmtyl);
  1545. other.Add("JCountyl", JCountyl);
  1546. other.Add("YAmtyl", YAmtyl);
  1547. other.Add("TotalAmtfc1", TotalAmtfc1);
  1548. other.Add("DAmtfc1", DAmtfc1);
  1549. other.Add("JAmtfc1", JAmtfc1);
  1550. other.Add("JfAmtfc1", JfAmtfc1);
  1551. other.Add("JCountfc1", JCountfc1);
  1552. other.Add("YAmtfc1", YAmtfc1);
  1553. other.Add("TotalAmtwd1", TotalAmtwd1);
  1554. other.Add("DAmtwd1", DAmtwd1);
  1555. other.Add("JAmtwd1", JAmtwd1);
  1556. other.Add("JfAmtwd1", JfAmtwd1);
  1557. other.Add("JCountwd1", JCountwd1);
  1558. other.Add("YAmtwd1", YAmtwd1);
  1559. other.Add("TotalAmtyl1", TotalAmtyl1);
  1560. other.Add("DAmtyl1", DAmtyl1);
  1561. other.Add("JAmtyl1", JAmtyl1);
  1562. other.Add("JfAmtyl1", JfAmtyl1);
  1563. other.Add("JCountyl1", JCountyl1);
  1564. other.Add("YAmtyl1", YAmtyl1);
  1565. other.Add("PBCount", PBCount);
  1566. other.Add("PACount", PACount);
  1567. other.Add("TBCount", TBCount);
  1568. other.Add("TACount", TACount);
  1569. db.Dispose();
  1570. obj.Add("other", other);
  1571. return Json(obj);
  1572. }
  1573. public Dictionary<string, object> GetMonthTradeForBrand(int UserId, string sTradeDate, string eTradeDate, int BrandId)
  1574. {
  1575. WebCMSEntities db = new WebCMSEntities();
  1576. string condition = " and Status>-1";
  1577. string cons = " and Status>=-1";
  1578. //产品类型
  1579. if (!string.IsNullOrEmpty(BrandId.ToString()) && BrandId > 0)
  1580. {
  1581. condition += " and BrandId =" + BrandId;
  1582. cons += " and BrandId =" + BrandId;
  1583. }
  1584. //创客Id
  1585. if (!string.IsNullOrEmpty(UserId.ToString()))
  1586. {
  1587. condition += " and UserId =" + UserId;
  1588. }
  1589. //开始时间
  1590. if (!string.IsNullOrEmpty(sTradeDate) && !string.IsNullOrEmpty(eTradeDate))
  1591. {
  1592. condition += " and TradeDate >=" + Convert.ToInt32(sTradeDate) + " and TradeDate <=" + Convert.ToInt32(eTradeDate);
  1593. cons += " and SeoKeyword >=" + Convert.ToInt32(sTradeDate) + " and SeoKeyword <=" + Convert.ToInt32(eTradeDate);
  1594. }
  1595. //结束时间
  1596. else
  1597. {
  1598. var start = DateTime.Now.ToString("yyyyMM") + "01";
  1599. condition += " and TradeDate >=" + Convert.ToInt32(start) + " and TradeDate <=" + Convert.ToInt32(eTradeDate);
  1600. cons += " and SeoKeyword >=" + Convert.ToInt32(start) + " and SeoKeyword <=" + Convert.ToInt32(eTradeDate);
  1601. }
  1602. //扶持期
  1603. decimal TotalAmtfc = 0;
  1604. decimal DAmtfc = 0;
  1605. decimal JAmtfc = 0;
  1606. decimal JfAmtfc = 0;
  1607. int JCountfc = 0;
  1608. decimal YAmtfc = 0;
  1609. //稳定期
  1610. decimal TotalAmtwd = 0;
  1611. decimal DAmtwd = 0;
  1612. decimal JAmtwd = 0;
  1613. decimal JfAmtwd = 0;
  1614. int JCountwd = 0;
  1615. decimal YAmtwd = 0;
  1616. //盈利期
  1617. decimal TotalAmtyl = 0;
  1618. decimal DAmtyl = 0;
  1619. decimal JAmtyl = 0;
  1620. decimal JfAmtyl = 0;
  1621. int JCountyl = 0;
  1622. decimal YAmtyl = 0;
  1623. int BCount = 0;
  1624. int ACount = 0;
  1625. int PBCount = 0;
  1626. int PACount = 0;
  1627. int TBCount = 0;
  1628. int TACount = 0;
  1629. Dictionary<string, object> obj = new Dictionary<string, object>();
  1630. DataTable dt = OtherMySqlConn.dtable("SELECT Sum(HelpNonDirectTradeAmt + HelpNonDirectDebitTradeAmt),Sum(if (QueryCount = 0,HelpNonDirectTradeAmt,0)),Sum(if (QueryCount = 0,HelpNonDirectDebitTradeAmt - HelpNonDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,HelpNonDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,HelpNonDirectDebitCapNum,0)),Sum(if (QueryCount = 1,HelpNonDirectTradeAmt,0)),Sum(NotHelpNonDirectTradeAmt + NotHelpNonDirectDebitTradeAmt),Sum(if (QueryCount = 0,NotHelpNonDirectTradeAmt,0)),Sum(if (QueryCount = 0,NotHelpNonDirectDebitTradeAmt - NotHelpNonDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,NotHelpNonDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,NotHelpNonDirectDebitCapNum,0)),Sum(if (QueryCount = 1,NotHelpNonDirectTradeAmt,0)),Sum(ProfitNonDirectTradeAmt + ProfitNonDirectDebitTradeAmt),Sum(if (QueryCount = 0,ProfitNonDirectTradeAmt,0)),Sum(if (QueryCount = 0,ProfitNonDirectDebitTradeAmt - ProfitNonDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,ProfitNonDirectDebitCapTradeAmt,0)),Sum(if (QueryCount = 0,ProfitNonDirectDebitCapNum,0)),Sum(if (QueryCount = 1,ProfitNonDirectTradeAmt,0))from TradeDaySummary where SeoTitle = 'team'" + condition);
  1631. if (dt.Rows.Count > 0)
  1632. {
  1633. TotalAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1634. DAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1635. JAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][2].ToString()));
  1636. JfAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][3].ToString()));
  1637. JCountfc = Convert.ToInt32(function.CheckInt(dt.Rows[0][4].ToString()));
  1638. YAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][5].ToString()));
  1639. TotalAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][6].ToString()));
  1640. DAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][7].ToString()));
  1641. JAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][8].ToString()));
  1642. JfAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][9].ToString()));
  1643. JCountwd = Convert.ToInt32(function.CheckInt(dt.Rows[0][10].ToString()));
  1644. YAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][11].ToString()));
  1645. TotalAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][12].ToString()));
  1646. DAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][13].ToString()));
  1647. JAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][14].ToString()));
  1648. JfAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][15].ToString()));
  1649. JCountyl = Convert.ToInt32(function.CheckInt(dt.Rows[0][16].ToString()));
  1650. YAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][17].ToString()));
  1651. }
  1652. //统计激活数(个人、团队)
  1653. dt = OtherMySqlConn.dtable("SELECT SUM(if(SeoTitle='team',ActiveBuddyMerStatus,0)) FROM UserTradeMonthSummary WHERE UserId= " + UserId + "" + cons);
  1654. if (dt.Rows.Count > 0)
  1655. {
  1656. TACount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1657. }
  1658. obj.Add("TotalAmtfc", TotalAmtfc);
  1659. obj.Add("DAmtfc", DAmtfc);
  1660. obj.Add("JAmtfc", JAmtfc);
  1661. obj.Add("JfAmtfc", JfAmtfc);
  1662. obj.Add("JCountfc", JCountfc);
  1663. obj.Add("YAmtfc", YAmtfc);
  1664. obj.Add("TotalAmtwd", TotalAmtwd);
  1665. obj.Add("DAmtwd", DAmtwd);
  1666. obj.Add("JAmtwd", JAmtwd);
  1667. obj.Add("JfAmtwd", JfAmtwd);
  1668. obj.Add("JCountwd", JCountwd);
  1669. obj.Add("YAmtwd", YAmtwd);
  1670. obj.Add("TotalAmtyl", TotalAmtyl);
  1671. obj.Add("DAmtyl", DAmtyl);
  1672. obj.Add("JAmtyl", JAmtyl);
  1673. obj.Add("JfAmtyl", JfAmtyl);
  1674. obj.Add("JCountyl", JCountyl);
  1675. obj.Add("YAmtyl", YAmtyl);
  1676. obj.Add("BCount", BCount);
  1677. obj.Add("ACount", ACount);
  1678. obj.Add("PBCount", PBCount);
  1679. obj.Add("PACount", PACount);
  1680. obj.Add("TBCount", TBCount);
  1681. obj.Add("TACount", TACount);
  1682. db.Dispose();
  1683. return obj;
  1684. }
  1685. #endregion
  1686. #region 未实名创客列表
  1687. /// <summary>
  1688. /// 根据条件查询未实名创客列表
  1689. /// </summary>
  1690. /// <returns></returns>
  1691. public IActionResult AuthIndex(Users data, string right)
  1692. {
  1693. ViewBag.RightInfo = RightInfo;
  1694. ViewBag.right = right;
  1695. return View();
  1696. }
  1697. #endregion
  1698. #region 根据条件查询未实名创客列表
  1699. /// <summary>
  1700. /// 未实名创客列表
  1701. /// </summary>
  1702. /// <returns></returns>
  1703. public JsonResult AuthIndexData(Users data, int page = 1, int limit = 30)
  1704. {
  1705. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1706. Fields.Add("MakerCode", "1"); //创客编号
  1707. string condition = " and Status>-1 and AuthFlag=0 and RealName is not null and CertId is not null and SettleBankCardNo is not null and SettleBankCardName is not null";
  1708. string sort = "Id desc";
  1709. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, sort, "True", page, limit, condition);
  1710. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1711. foreach (Dictionary<string, object> dic in diclist)
  1712. {
  1713. dic["AuthFlagName"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  1714. dic["RiskFlagName"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  1715. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1716. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  1717. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  1718. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1719. dic["ParentMakerCode"] = puser.MakerCode;
  1720. dic["ParentRealName"] = puser.RealName;
  1721. string ParentNav = dic["ParentNav"].ToString();
  1722. if (!string.IsNullOrEmpty(ParentNav))
  1723. {
  1724. string[] list = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1725. if (list.Length > 1)
  1726. {
  1727. int TopId = int.Parse(function.CheckInt(list[1]));
  1728. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1729. dic["TopMakerCode"] = tuser.MakerCode;
  1730. dic["TopRealName"] = tuser.RealName;
  1731. }
  1732. }
  1733. }
  1734. return Json(obj);
  1735. }
  1736. #endregion
  1737. #region 认证
  1738. /// <summary>
  1739. /// 认证
  1740. /// </summary>
  1741. /// <returns></returns>
  1742. public string Auth(string Id)
  1743. {
  1744. string[] idlist = Id.Split(new char[] { ',' });
  1745. AddSysLog(Id, "Users", "Auth");
  1746. foreach (string subid in idlist)
  1747. {
  1748. int id = int.Parse(subid);
  1749. Dictionary<string, object> Fields = new Dictionary<string, object>();
  1750. Fields.Add("AuthFlag", 1);
  1751. Fields.Add("AuthDate", DateTime.Now);
  1752. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  1753. }
  1754. db.SaveChanges();
  1755. return "success";
  1756. }
  1757. #endregion
  1758. #region 修改盟主金额
  1759. public IActionResult ChangeLeaderAmount(string right, int Id = 0)
  1760. {
  1761. ViewBag.RightInfo = RightInfo;
  1762. ViewBag.right = right;
  1763. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  1764. ViewBag.data = editData;
  1765. return View();
  1766. }
  1767. #endregion
  1768. #region 修改盟主金额
  1769. [HttpPost]
  1770. public string ChangeLeaderAmount(Users data, string ChangeAmount, int AmountType, string Note, int Kind)
  1771. {
  1772. int UserId = data.Id;
  1773. var Amount = Convert.ToDecimal(ChangeAmount);
  1774. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  1775. if (account == null)
  1776. {
  1777. account = db.UserAccount.Add(new UserAccount()
  1778. {
  1779. Id = UserId,
  1780. UserId = UserId,
  1781. }).Entity;
  1782. db.SaveChanges();
  1783. }
  1784. //盟主储蓄金
  1785. if (AmountType == 1)
  1786. {
  1787. if ((Kind == 1 || Kind == 3) && Amount > account.LeaderReserve)
  1788. {
  1789. return "盟主储蓄金不足";
  1790. }
  1791. decimal BeforeLeaderReserve = account.LeaderReserve; //变更前盟主储蓄金
  1792. decimal BeforeLeaderBalanceAmount = account.LeaderBalanceAmount; //变更前盟主可提现余额
  1793. int ChangeType = 0;
  1794. if (Kind == 1 && Amount <= account.LeaderReserve)
  1795. {
  1796. account.LeaderReserve -= Amount;
  1797. account.TotalProfit += Amount;
  1798. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统冻结(盟主储蓄金)',Time'" + DateTime.Now + "'");
  1799. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  1800. }
  1801. else if (Kind == 1 && Amount > account.LeaderReserve)
  1802. {
  1803. return "冻结金额大于盟主储蓄金";
  1804. }
  1805. else if (Kind == 2 && Amount <= account.TotalProfit)
  1806. {
  1807. account.LeaderReserve += Amount;
  1808. account.TotalProfit -= Amount;
  1809. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统解冻(盟主储蓄金)',Time'" + DateTime.Now + "'");
  1810. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  1811. }
  1812. else if (Kind == 2 && Amount > account.TotalProfit)
  1813. {
  1814. return "解冻金额大于冻结金额";
  1815. }
  1816. else if (Kind == 3 && Amount <= account.LeaderReserve)
  1817. {
  1818. account.LeaderReserve -= Amount;
  1819. ChangeType = 4;
  1820. decimal AfterLeaderReserve = account.LeaderReserve; //变更后盟主储蓄金
  1821. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后盟主可提现余额
  1822. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  1823. {
  1824. CreateDate = DateTime.Now, //创建时间
  1825. UserId = UserId, //创客
  1826. Remark = "系统扣减(盟主储蓄金)",
  1827. ChangeType = ChangeType,
  1828. BeforeAmt = BeforeLeaderReserve,
  1829. AfterAmt = AfterLeaderReserve,
  1830. ChangeAmt = Amount,
  1831. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  1832. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  1833. }).Entity;
  1834. db.SaveChanges();
  1835. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统扣减(盟主储蓄金)',Time'" + DateTime.Now + "'");
  1836. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  1837. }
  1838. else if (Kind == 3 && Amount > account.LeaderReserve)
  1839. {
  1840. return "扣减金额大于盟主储蓄金";
  1841. }
  1842. else if (Kind == 4)
  1843. {
  1844. account.LeaderReserve += Amount;
  1845. ChangeType = 1;
  1846. decimal AfterLeaderReserve = account.LeaderReserve; //变更后总金额
  1847. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后冻结金额
  1848. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  1849. {
  1850. CreateDate = DateTime.Now, //创建时间
  1851. UserId = UserId, //创客
  1852. Remark = "系统增加(盟主储蓄金)",
  1853. ChangeType = ChangeType,
  1854. BeforeAmt = BeforeLeaderReserve,
  1855. AfterAmt = AfterLeaderReserve,
  1856. ChangeAmt = Amount,
  1857. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  1858. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  1859. }).Entity;
  1860. db.SaveChanges();
  1861. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统增加(盟主储蓄金)',Time'" + DateTime.Now + "'");
  1862. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  1863. }
  1864. AddSysLog(data.Id.ToString(), "Users", "ChangeLeaderAmount");
  1865. db.SaveChanges();
  1866. }
  1867. //盟主可提现余额
  1868. if (AmountType == 2)
  1869. {
  1870. if ((Kind == 1 || Kind == 3) && Amount > account.LeaderBalanceAmount)
  1871. {
  1872. return "盟主可提现余额不足";
  1873. }
  1874. decimal BeforeLeaderReserve = account.LeaderReserve; //变更前盟主储蓄金
  1875. decimal BeforeLeaderBalanceAmount = account.LeaderBalanceAmount; //变更前盟主可提现余额
  1876. int ChangeType = 0;
  1877. if (Kind == 1 && Amount <= account.LeaderReserve)
  1878. {
  1879. account.LeaderBalanceAmount -= Amount;
  1880. account.TotalServiceProfit += Amount;
  1881. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统冻结(盟主可提现余额)',Time'" + DateTime.Now + "'");
  1882. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  1883. }
  1884. else if (Kind == 1 && Amount > account.LeaderBalanceAmount)
  1885. {
  1886. return "冻结金额大于盟主可提现余额";
  1887. }
  1888. else if (Kind == 2 && Amount <= account.TotalServiceProfit)
  1889. {
  1890. account.LeaderBalanceAmount += Amount;
  1891. account.TotalServiceProfit -= Amount;
  1892. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统解冻(盟主可提现余额)',Time'" + DateTime.Now + "'");
  1893. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  1894. }
  1895. else if (Kind == 2 && Amount > account.TotalServiceProfit)
  1896. {
  1897. return "解冻金额大于冻结金额";
  1898. }
  1899. else if (Kind == 3 && Amount <= account.LeaderBalanceAmount)
  1900. {
  1901. account.LeaderBalanceAmount -= Amount;
  1902. ChangeType = 6;
  1903. decimal AfterLeaderReserve = account.LeaderReserve; //变更后总金额
  1904. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后冻结金额
  1905. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  1906. {
  1907. CreateDate = DateTime.Now, //创建时间
  1908. UserId = UserId, //创客
  1909. Remark = "系统扣减(盟主可提现余额)",
  1910. ChangeType = ChangeType,
  1911. BeforeAmt = BeforeLeaderBalanceAmount,
  1912. AfterAmt = AfterLeaderBalanceAmount,
  1913. ChangeAmt = Amount,
  1914. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  1915. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  1916. }).Entity;
  1917. db.SaveChanges();
  1918. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统扣减(盟主可提现余额)',Time'" + DateTime.Now + "'");
  1919. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  1920. }
  1921. else if (Kind == 3 && Amount > account.LeaderBalanceAmount)
  1922. {
  1923. return "扣减金额大于盟主可提现余额";
  1924. }
  1925. else if (Kind == 4)
  1926. {
  1927. account.LeaderBalanceAmount += Amount;
  1928. ChangeType = 5;
  1929. decimal AfterLeaderReserve = account.LeaderReserve; //变更后总金额
  1930. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后冻结金额
  1931. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  1932. {
  1933. CreateDate = DateTime.Now, //创建时间
  1934. UserId = UserId, //创客
  1935. Remark = "系统增加(盟主可提现余额)",
  1936. ChangeType = ChangeType,
  1937. BeforeAmt = BeforeLeaderBalanceAmount,
  1938. AfterAmt = AfterLeaderBalanceAmount,
  1939. ChangeAmt = Amount,
  1940. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  1941. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  1942. }).Entity;
  1943. db.SaveChanges();
  1944. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统增加(盟主可提现余额)',Time'" + DateTime.Now + "'");
  1945. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  1946. }
  1947. AddSysLog(data.Id.ToString(), "Users", "ChangeLeaderAmount");
  1948. db.SaveChanges();
  1949. }
  1950. return "success";
  1951. }
  1952. #endregion
  1953. #region 伞下创客列表
  1954. /// <summary>
  1955. /// 根据条件查询伞下创客列表
  1956. /// </summary>
  1957. /// <returns></returns>
  1958. public IActionResult SanIndex(Users data, string right)
  1959. {
  1960. ViewBag.RightInfo = RightInfo;
  1961. ViewBag.right = right;
  1962. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  1963. ViewBag.TopUsers = TopUsers;
  1964. List<UserLevelSet> Levels = db.UserLevelSet.OrderBy(m => m.Id).ToList();
  1965. ViewBag.Levels = Levels;
  1966. return View();
  1967. }
  1968. #endregion
  1969. #region 根据条件查询伞下创客列表
  1970. /// <summary>
  1971. /// 伞下创客列表
  1972. /// </summary>
  1973. /// <returns></returns>
  1974. public JsonResult SanIndexData(Users data, string MakerCode, string IsLeader, string IsOp, string CreateDateData, string UserYsLevel, string UserLevel, int ShowFlag = 0, int page = 1, int limit = 30)
  1975. {
  1976. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1977. if (ShowFlag == 0)
  1978. {
  1979. Dictionary<string, object> objs = new Dictionary<string, object>();
  1980. return Json(objs);
  1981. }
  1982. string condition = " and Status>-1";
  1983. //创客编号
  1984. if (!string.IsNullOrEmpty(MakerCode))
  1985. {
  1986. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  1987. if (userForMakerCode.UserId == 0)
  1988. {
  1989. return Json(new AppResultJson() { Status = "-1", Info = "未找到创客" + MakerCode + "关联数据", Data = "" });
  1990. }
  1991. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  1992. if (user.Id == 0)
  1993. {
  1994. return Json(new AppResultJson() { Status = "-1", Info = "创客" + MakerCode + "不存在", Data = "" });
  1995. }
  1996. condition += " and ParentNav like '%," + user.Id + ",%'";
  1997. }
  1998. if (!string.IsNullOrEmpty(IsLeader))
  1999. {
  2000. condition += " and LeaderLevel=" + IsLeader;
  2001. }
  2002. if (!string.IsNullOrEmpty(UserYsLevel))
  2003. {
  2004. var UserIds = "";
  2005. var Rank = int.Parse(UserYsLevel);
  2006. var list = db.UserRankWhite.Where(m => m.Status > -1 && m.Rank == Rank).ToList();
  2007. foreach (var item in list)
  2008. {
  2009. UserIds += item.UserId + ",";
  2010. }
  2011. UserIds = UserIds.TrimEnd(',');
  2012. condition += " and Id IN(" + UserIds + ")";
  2013. }
  2014. if (!string.IsNullOrEmpty(UserLevel))
  2015. {
  2016. condition += " and UserLevel=" + UserLevel;
  2017. }
  2018. if (!string.IsNullOrEmpty(IsOp))
  2019. {
  2020. var UserIds = "";
  2021. DataTable dt = CustomerSqlConn.dtable("SELECT UserId FROM SysAdmin WHERE Status>-1 and Sort>0 and QueryCount>0 and AdminName!='admin'", OpConn);
  2022. foreach (DataRow item in dt.Rows)
  2023. {
  2024. UserIds += item["UserId"].ToString() + ",";
  2025. }
  2026. UserIds = UserIds.TrimEnd(',');
  2027. if (IsOp == "1")
  2028. {
  2029. condition += " and Id IN(" + UserIds + ")";
  2030. }
  2031. if (IsOp == "2")
  2032. {
  2033. condition += " and Id NOT IN(" + UserIds + ")";
  2034. }
  2035. }
  2036. if (!string.IsNullOrEmpty(CreateDateData))
  2037. {
  2038. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  2039. string start = datelist[0];
  2040. string end = datelist[1];
  2041. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  2042. }
  2043. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", page, limit, condition);
  2044. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  2045. foreach (Dictionary<string, object> dic in diclist)
  2046. {
  2047. dic["AuthFlagName"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  2048. dic["RiskFlagName"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  2049. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  2050. int UserId = int.Parse(dic["Id"].ToString());
  2051. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  2052. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  2053. dic["ParentMakerCode"] = puser.MakerCode;
  2054. dic["ParentRealName"] = puser.RealName;
  2055. var userRankWhite = db.UserRankWhite.FirstOrDefault(m => m.UserId == UserId) ?? new UserRankWhite();
  2056. dic["UserYsLevel"] = RelationClass.GetUserLevelSetInfo(userRankWhite.Rank);
  2057. int LeaderLevel = int.Parse(dic["LeaderLevel"].ToString());
  2058. if (LeaderLevel == 1)
  2059. {
  2060. dic["IsLeader"] = "小盟主";
  2061. }
  2062. else if (LeaderLevel == 2)
  2063. {
  2064. dic["IsLeader"] = "大盟主";
  2065. }
  2066. else
  2067. {
  2068. dic["IsLeader"] = "";
  2069. }
  2070. var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.Status > -1 && m.Sort > 0 && m.QueryCount > 0 && m.AdminName != "admin" && m.UserId == UserId) ?? new OpModels.SysAdmin();
  2071. if (sysAdmin.Id > 0)
  2072. {
  2073. dic["IsOp"] = sysAdmin.OpCode;
  2074. }
  2075. else
  2076. {
  2077. dic["IsOp"] = "";
  2078. }
  2079. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  2080. }
  2081. return Json(obj);
  2082. }
  2083. #endregion
  2084. #region 重置小分仓额度
  2085. /// <summary>
  2086. /// 重置小分仓额度
  2087. /// </summary>
  2088. /// <returns></returns>
  2089. public string SycnAmountData(int Id = 0)
  2090. {
  2091. if (Id > 0)
  2092. {
  2093. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == Id) ?? new UserAccount();
  2094. RedisDbconn.Instance.AddList("ResetSmallStoreByUserIdQueue", userAccount.Id);
  2095. }
  2096. AddSysLog(Id, "UserAccount", "SycnAmountData");
  2097. db.SaveChanges();
  2098. return "success";
  2099. }
  2100. #endregion
  2101. }
  2102. }