UsersController.cs 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874
  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. var topUserInfo = new Users();
  161. if (list.Length > 1)
  162. {
  163. topUserInfo = db.Users.FirstOrDefault(m => m.Id == int.Parse(list[1])) ?? new Users();
  164. }
  165. else
  166. {
  167. topUserInfo = db.Users.FirstOrDefault(m => m.Id == int.Parse(list[0])) ?? new Users();
  168. }
  169. dic["TopMakerCode"] = topUserInfo.MakerCode;
  170. dic["TopRealName"] = topUserInfo.RealName;
  171. }
  172. }
  173. return Json(obj);
  174. }
  175. #endregion
  176. #region 创客列表
  177. /// <summary>
  178. /// 根据条件查询创客列表
  179. /// </summary>
  180. /// <returns></returns>
  181. public IActionResult CancleUsers(Users data, string right, int SelfId = 0, int ParentId = 0, string MakerCode = "")
  182. {
  183. ViewBag.RightInfo = RightInfo;
  184. ViewBag.right = right;
  185. ViewBag.SelfId = SelfId.ToString();
  186. ViewBag.ParentId = ParentId.ToString();
  187. ViewBag.MakerCode = MakerCode;
  188. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  189. ViewBag.TopUsers = TopUsers;
  190. List<UserLevelSet> Levels = db.UserLevelSet.OrderBy(m => m.Id).ToList();
  191. ViewBag.Levels = Levels;
  192. return View();
  193. }
  194. #endregion
  195. #region 根据条件查询创客列表
  196. /// <summary>
  197. /// 创客列表
  198. /// </summary>
  199. /// <returns></returns>
  200. public JsonResult CancleUsersData(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)
  201. {
  202. Dictionary<string, string> Fields = new Dictionary<string, string>();
  203. Fields.Add("MakerCode", "1"); //创客编号
  204. Fields.Add("RealName", "1"); //创客名称
  205. Fields.Add("Mobile", "1"); //手机号
  206. Fields.Add("CertId", "1"); //身份证号码
  207. Fields.Add("SettleAmount", "3"); //结算金额
  208. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  209. Fields.Add("UserLevel", "0"); //创客等级
  210. string condition = " and Status=-1";
  211. string sort = "Id desc";
  212. //直属创客编号
  213. if (!string.IsNullOrEmpty(ParentMakerCode))
  214. {
  215. condition += " and ParentUserId in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  216. }
  217. //直属创客名称
  218. if (!string.IsNullOrEmpty(ParentRealName))
  219. {
  220. condition += " and ParentUserId in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  221. }
  222. //实名状态
  223. if (!string.IsNullOrEmpty(AuthFlagSelect))
  224. {
  225. condition += " and AuthFlag=" + AuthFlagSelect;
  226. }
  227. //顶级创客
  228. if (TopUserId > 0)
  229. {
  230. condition += " and ParentNav like '," + TopUserId + ",%'";
  231. }
  232. //风控标识
  233. if (!string.IsNullOrEmpty(RiskFlagSelect))
  234. {
  235. condition += " and RiskFlag=" + RiskFlagSelect;
  236. }
  237. //商户创客类型
  238. if (!string.IsNullOrEmpty(MerchantTypeSelect))
  239. {
  240. condition += " and MerchantType=" + MerchantTypeSelect;
  241. }
  242. if (sSettleAmount != null)
  243. {
  244. condition += " and SettleAmount>=" + sSettleAmount.Value;
  245. }
  246. if (eSettleAmount != null)
  247. {
  248. condition += " and SettleAmount<=" + eSettleAmount.Value;
  249. }
  250. if (sCashFreezeAmt != null)
  251. {
  252. condition += " and CashFreezeAmt>=" + sCashFreezeAmt.Value;
  253. }
  254. if (eCashFreezeAmt != null)
  255. {
  256. condition += " and CashFreezeAmt<=" + eCashFreezeAmt.Value;
  257. }
  258. if (SelfId > 0)
  259. {
  260. Users self = db.Users.FirstOrDefault(m => m.Id == SelfId);
  261. if (self != null)
  262. {
  263. string ParentNav = function.CheckNull(self.ParentNav);
  264. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  265. sort = "ParentNav asc";
  266. }
  267. }
  268. if (ParentId > 0)
  269. {
  270. condition += " and ParentUserId=" + ParentId;
  271. }
  272. if (UserId > 0)
  273. {
  274. condition += " and Id=" + UserId;
  275. }
  276. if (!string.IsNullOrEmpty(CreateDateData))
  277. {
  278. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  279. string start = datelist[0];
  280. string end = datelist[1];
  281. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  282. }
  283. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, sort, "True", page, limit, condition);
  284. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  285. foreach (Dictionary<string, object> dic in diclist)
  286. {
  287. dic["AuthFlagName"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  288. dic["RiskFlagName"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  289. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  290. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  291. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  292. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  293. dic["ParentMakerCode"] = puser.MakerCode;
  294. dic["ParentRealName"] = puser.RealName;
  295. string ParentNav = dic["ParentNav"].ToString();
  296. if (!string.IsNullOrEmpty(ParentNav))
  297. {
  298. string[] list = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  299. if (list.Length > 1)
  300. {
  301. int TopId = int.Parse(function.CheckInt(list[1]));
  302. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  303. dic["TopMakerCode"] = tuser.MakerCode;
  304. dic["TopRealName"] = tuser.RealName;
  305. }
  306. }
  307. }
  308. return Json(obj);
  309. }
  310. #endregion
  311. #region 增加创客
  312. /// <summary>
  313. /// 增加或修改创客信息
  314. /// </summary>
  315. /// <returns></returns>
  316. public IActionResult Add(string right)
  317. {
  318. ViewBag.RightInfo = RightInfo;
  319. ViewBag.right = right;
  320. return View();
  321. }
  322. #endregion
  323. #region 增加创客
  324. /// <summary>
  325. /// 增加或修改创客信息
  326. /// </summary>
  327. /// <returns></returns>
  328. [HttpPost]
  329. public string Add(Users data, string ParentMakerCode)
  330. {
  331. bool check = db.UserForMobile.Any(m => m.Mobile == data.Mobile);
  332. if (check)
  333. {
  334. return "手机号已存在,请重新输入";
  335. }
  336. check = db.UserForRealName.Any(m => m.RealName == data.RealName);
  337. if (check)
  338. {
  339. return "姓名已存在,请重新输入";
  340. }
  341. if (!string.IsNullOrEmpty(data.MakerCode))
  342. {
  343. check = db.UserForMakerCode.Any(m => m.MakerCode == data.MakerCode);
  344. if (check)
  345. {
  346. return "创客编码已存在,请重新输入";
  347. }
  348. }
  349. Dictionary<string, object> Fields = new Dictionary<string, object>();
  350. Fields.Add("RealName", data.RealName); //真实姓名
  351. Fields.Add("CertId", data.CertId); //身份证号
  352. Fields.Add("Mobile", data.Mobile); //手机号
  353. Fields.Add("LoginPwd", function.MD532(data.LoginPwd)); //登录密码
  354. Fields.Add("SettleBankCardNo", data.SettleBankCardNo); //结算银行卡号
  355. if (!string.IsNullOrEmpty(ParentMakerCode))
  356. {
  357. UserForMakerCode userFor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ParentMakerCode) ?? new UserForMakerCode();
  358. Users puser = db.Users.FirstOrDefault(m => m.Id == userFor.UserId) ?? new Users();
  359. Fields.Add("ParentUserId", userFor.UserId);
  360. Fields.Add("ParentNav", puser.ParentNav + "," + userFor.UserId + ",");
  361. }
  362. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("Users", Fields, 0);
  363. if (string.IsNullOrEmpty(ParentMakerCode))
  364. {
  365. string MakerCode = Id.ToString();
  366. for (int i = 0; i < 7 - Id.ToString().Length; i++)
  367. {
  368. MakerCode = "0" + MakerCode;
  369. }
  370. MakerCode = "K" + MakerCode;
  371. Fields = new Dictionary<string, object>();
  372. Fields.Add("MakerCode", MakerCode); //编号
  373. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, Id);
  374. }
  375. db.UserDetail.Add(new UserDetail() { Id = Id });
  376. db.UserData.Add(new UserData() { UserId = Id });
  377. AddSysLog(data.Id.ToString(), "Users", "add");
  378. db.SaveChanges();
  379. return "success";
  380. }
  381. #endregion
  382. #region 修改创客
  383. /// <summary>
  384. /// 增加或修改创客信息
  385. /// </summary>
  386. /// <returns></returns>
  387. public IActionResult Edit(string right, int Id = 0)
  388. {
  389. ViewBag.RightInfo = RightInfo;
  390. ViewBag.right = right;
  391. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  392. ViewBag.data = editData;
  393. return View();
  394. }
  395. #endregion
  396. #region 修改创客
  397. /// <summary>
  398. /// 增加或修改创客信息
  399. /// </summary>
  400. /// <returns></returns>
  401. [HttpPost]
  402. public string Edit(Users data, UserDetail userdetail, UserData userdata)
  403. {
  404. Dictionary<string, object> Fields = new Dictionary<string, object>();
  405. Fields.Add("RealName", data.RealName); //真实姓名
  406. Fields.Add("CertId", data.CertId); //身份证号
  407. Fields.Add("Mobile", data.Mobile); //手机号
  408. Fields.Add("SettleBankName", data.SettleBankName); //结算银行名称
  409. Fields.Add("SettleBankCardNo", data.SettleBankCardNo); //结算银行卡号
  410. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, data.Id);
  411. AddSysLog(data.Id.ToString(), "Users", "update");
  412. db.SaveChanges();
  413. return "success";
  414. }
  415. #endregion
  416. #region 重置小分仓机具数
  417. public string ResetSmallPosCount(string Id)
  418. {
  419. DataTable dt = OtherMySqlConn.dtable("update SmallStoreHouse s set TotalNum=(select count(Id) from PreSendStockDetail where ToUserId=s.UserId and ApplyFlag=0 and Status>-1 and Status<2),LaveNum=10-(select count(Id) from PreSendStockDetail where ToUserId=s.UserId and ApplyFlag=0 and Status>-1 and Status<2) where UserId=" + Id);
  420. string text = string.Format("重置小分仓机具数,UserId: '" + Id + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  421. function.WriteLog(text, "重置小分仓机具数");
  422. return "success";
  423. }
  424. #endregion
  425. #region 修改结算金额
  426. public IActionResult EditSettleAmount(string right, int Id = 0)
  427. {
  428. ViewBag.RightInfo = RightInfo;
  429. ViewBag.right = right;
  430. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  431. ViewBag.data = editData;
  432. return View();
  433. }
  434. #endregion
  435. #region 修改结算金额
  436. [HttpPost]
  437. public string EditSettleAmount(Users data)
  438. {
  439. Dictionary<string, object> Fields = new Dictionary<string, object>();
  440. Fields.Add("SettleAmount", data.SettleAmount);
  441. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, data.Id);
  442. AddSysLog(data.Id.ToString(), "Users", "EditSettleAmount");
  443. db.SaveChanges();
  444. return "success";
  445. }
  446. #endregion
  447. #region 修改账户金额
  448. public IActionResult EditCashFreezeAmt(string right, int Id = 0)
  449. {
  450. ViewBag.RightInfo = RightInfo;
  451. ViewBag.right = right;
  452. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  453. ViewBag.data = editData;
  454. return View();
  455. }
  456. #endregion
  457. #region 修改账户金额
  458. [HttpPost]
  459. public string EditCashFreezeAmt(Users data, string Note, int Kind)
  460. {
  461. int UserId = data.Id;
  462. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  463. if (account == null)
  464. {
  465. account = db.UserAccount.Add(new UserAccount()
  466. {
  467. Id = UserId,
  468. UserId = UserId,
  469. }).Entity;
  470. db.SaveChanges();
  471. }
  472. if ((Kind == 1 || Kind == 3) && data.CashFreezeAmt > account.BalanceAmount)
  473. {
  474. return "账号余额不足";
  475. }
  476. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  477. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  478. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  479. int ChangeType = 0;
  480. if (Kind == 1 && data.CashFreezeAmt <= account.BalanceAmount)
  481. {
  482. account.BalanceAmount -= data.CashFreezeAmt;
  483. account.FreezeAmount += data.CashFreezeAmt;
  484. ChangeType = 61;
  485. }
  486. else if (Kind == 1 && data.CashFreezeAmt > account.BalanceAmount)
  487. {
  488. return "冻结金额大于余额";
  489. }
  490. else if (Kind == 2 && data.CashFreezeAmt <= account.FreezeAmount)
  491. {
  492. account.BalanceAmount += data.CashFreezeAmt;
  493. account.FreezeAmount -= data.CashFreezeAmt;
  494. ChangeType = 62;
  495. }
  496. else if (Kind == 2 && data.CashFreezeAmt > account.FreezeAmount)
  497. {
  498. return "解冻金额大于冻结金额";
  499. }
  500. else if (Kind == 3 && data.CashFreezeAmt <= account.BalanceAmount)
  501. {
  502. account.TotalAmount -= data.CashFreezeAmt;
  503. account.BalanceAmount -= data.CashFreezeAmt;
  504. ChangeType = 63;
  505. }
  506. else if (Kind == 3 && data.CashFreezeAmt > account.BalanceAmount)
  507. {
  508. return "扣减金额大于余额";
  509. }
  510. else if (Kind == 4)
  511. {
  512. account.TotalAmount += data.CashFreezeAmt;
  513. account.BalanceAmount += data.CashFreezeAmt;
  514. ChangeType = 64;
  515. }
  516. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  517. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  518. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  519. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  520. {
  521. CreateDate = DateTime.Now,
  522. UpdateDate = DateTime.Now,
  523. UserId = UserId, //创客
  524. ChangeType = ChangeType, //变动类型
  525. ChangeAmount = data.CashFreezeAmt, //变更金额
  526. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  527. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  528. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  529. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  530. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  531. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  532. Remark = Note,
  533. }).Entity;
  534. db.SaveChanges();
  535. RedisDbconn.Instance.Set("UserAccount:" + UserId, account);
  536. AddSysLog(data.Id.ToString(), "Users", "EditCashFreezeAmt");
  537. db.SaveChanges();
  538. return "success";
  539. }
  540. #endregion
  541. #region 账户操作
  542. public IActionResult EditBalance(string right, int Id = 0)
  543. {
  544. ViewBag.RightInfo = RightInfo;
  545. ViewBag.right = right;
  546. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  547. ViewBag.data = editData;
  548. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == Id) ?? new UserAccount();
  549. ViewBag.account = account;
  550. return View();
  551. }
  552. #endregion
  553. #region 账户操作
  554. [HttpPost]
  555. public string EditBalance(UserAccount data)
  556. {
  557. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == data.Id);
  558. if (account != null)
  559. {
  560. decimal amount = data.BalanceAmount - account.BalanceAmount;
  561. if (amount != 0)
  562. {
  563. account.BalanceAmount += amount;
  564. account.TotalAmount += amount;
  565. AddSysLog(data.Id.ToString(), "UserAccount", "EditBalance");
  566. db.SaveChanges();
  567. }
  568. }
  569. return "success";
  570. }
  571. #endregion
  572. #region 详情
  573. public IActionResult Detail(string right, int Id = 0)
  574. {
  575. ViewBag.RightInfo = RightInfo;
  576. ViewBag.right = right;
  577. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  578. ViewBag.AuthDate = editData.AuthDate == null ? "" : editData.AuthDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  579. string Age = "";
  580. if (!string.IsNullOrEmpty(editData.CertId))
  581. {
  582. int year = DateTime.Now.Year - int.Parse(editData.CertId.Substring(6, 4));
  583. Age = year.ToString();
  584. }
  585. ViewBag.Age = Age;
  586. ViewBag.QrCode = string.IsNullOrEmpty(editData.ReferenceQrCode) ? defaultImage : SourceHost + editData.ReferenceQrCode;
  587. return View();
  588. }
  589. #endregion
  590. #region 三/四要素验证
  591. public IActionResult ThreeElement(string right)
  592. {
  593. ViewBag.RightInfo = RightInfo;
  594. ViewBag.right = right;
  595. return View();
  596. }
  597. #endregion
  598. #region 三/四要素验证
  599. [HttpPost]
  600. public string ThreeElement(string Name, string CertId, string CardNo, string Mobile)
  601. {
  602. return "success";
  603. }
  604. #endregion
  605. #region 删除创客信息
  606. /// <summary>
  607. /// 删除创客信息
  608. /// </summary>
  609. /// <returns></returns>
  610. public string Delete(string Id)
  611. {
  612. string[] idlist = Id.Split(new char[] { ',' });
  613. AddSysLog(Id, "Users", "del");
  614. foreach (string subid in idlist)
  615. {
  616. int id = int.Parse(subid);
  617. Dictionary<string, object> Fields = new Dictionary<string, object>();
  618. Fields.Add("Status", -1);
  619. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  620. }
  621. db.SaveChanges();
  622. return "success";
  623. }
  624. #endregion
  625. #region 注销
  626. // 1.创客名下无未绑定机具且没有申请中的机具循环及兑换订单
  627. // 2.创客名下无预发机
  628. // 3.创客名下无分仓及运营中心
  629. // 满足以上全部条件的用户可申请注销,申请后用户二次填写确认填写信息(姓名、手机号、身份证号)即可完成注销
  630. public string Cancel(string UserId)
  631. {
  632. Users user = db.Users.FirstOrDefault(m => m.Id == Convert.ToInt32(UserId));
  633. if (user != null)
  634. {
  635. if (user.AuthFlag == 1)
  636. {
  637. // bool check = db.PosMachinesTwo.Any(m => m.BuyUserId == user.Id && m.BindingState == 1);
  638. // if (check)
  639. // {
  640. // return "注销失败,未满足条件:已实名创客,无开通商户。如有疑问,请联系客服";
  641. // }
  642. // DateTime checkDate = DateTime.Now.AddDays(-7);
  643. // check = db.Orders.Any(m => m.CreateDate >= checkDate && m.Status > 0 && m.UserId == user.Id);
  644. // if (check)
  645. // {
  646. // return "注销失败,未满足条件:近7天未在商城下单过商品。如有疑问,请联系客服";
  647. // }
  648. // check = db.PosMachinesTwo.Any(m => m.BuyUserId == user.Id && m.IsPurchase == 0);
  649. // if (check)
  650. // {
  651. // return "注销失败,未满足条件:名下无未绑定机具、机具券,无未申请的循环机。如有疑问,请联系客服";
  652. // }
  653. // check = db.PosCoupons.Any(m => m.UserId == user.Id && m.IsUse == 0);
  654. // if (check)
  655. // {
  656. // return "注销失败,未满足条件:名下无未绑定机具、机具券,无未申请的循环机。如有疑问,请联系客服";
  657. // }
  658. bool check = db.PosMachinesTwo.Any(m => m.BuyUserId == user.Id && m.BindingState == 0);
  659. if (check)
  660. {
  661. return "注销失败,未满足条件:名下存在未绑定机具。如有疑问,请联系客服";
  662. }
  663. check = db.MachineApply.Any(m => m.Status == 0 && m.UserId == user.Id);
  664. if (check)
  665. {
  666. return "注销失败,未满足条件:名下存在未完成的机具循环兑换订单。如有疑问,请联系客服";
  667. }
  668. check = db.PreSendStockDetail.Any(m => m.Status == 1 && m.AuthFlag == 0 && m.ToUserId == user.Id);
  669. if (check)
  670. {
  671. return "注销失败,未满足条件:名下存在预发机。如有疑问,请联系客服";
  672. }
  673. if (user.UserType == 1)
  674. {
  675. return "注销失败,未满足条件:名下存在运营中心。如有疑问,请联系客服";
  676. }
  677. check = db.StoreHouse.Any(m => m.Status == 1 && m.UserId == user.Id);
  678. if (check)
  679. {
  680. return "注销失败,未满足条件:名下存在分仓。如有疑问,请联系客服";
  681. }
  682. UserForMobile forMobile = db.UserForMobile.FirstOrDefault(m => m.Mobile == user.Mobile);
  683. if (forMobile != null)
  684. {
  685. db.Remove(forMobile);
  686. }
  687. UserForMakerCode forCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == user.MakerCode);
  688. if (forCode != null)
  689. {
  690. db.UserForMakerCode.Remove(forCode);
  691. }
  692. user.Status = -1;
  693. user.Mobile += "d";
  694. user.CertId += "d";
  695. user.LogOutDate = DateTime.Now;
  696. }
  697. else
  698. {
  699. UserForMobile forMobile = db.UserForMobile.FirstOrDefault(m => m.Mobile == user.Mobile);
  700. if (forMobile != null)
  701. {
  702. db.UserForMobile.Remove(forMobile);
  703. }
  704. UserForMakerCode forCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == user.MakerCode);
  705. if (forCode != null)
  706. {
  707. db.UserForMakerCode.Remove(forCode);
  708. }
  709. user.Status = -1;
  710. user.Mobile += "d";
  711. user.CertId += "d";
  712. user.LogOutDate = DateTime.Now;
  713. }
  714. function.WriteLog(user.Id + "于" + DateTime.Now.ToString() + "注销账号", "创客注销日志");
  715. // TODO: 每月扫描一次注销的创客,把注销创客伞下创客全部挂到注销创客的上级
  716. // TODO: 清除token,token登录返回
  717. db.SaveChanges();
  718. }
  719. return "success";
  720. }
  721. #endregion
  722. #region 开启
  723. /// <summary>
  724. /// 开启
  725. /// </summary>
  726. /// <returns></returns>
  727. public string Open(string Id)
  728. {
  729. string[] idlist = Id.Split(new char[] { ',' });
  730. AddSysLog(Id, "Users", "open");
  731. foreach (string subid in idlist)
  732. {
  733. int id = int.Parse(subid);
  734. Dictionary<string, object> Fields = new Dictionary<string, object>();
  735. Fields.Add("Status", 1);
  736. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  737. }
  738. db.SaveChanges();
  739. return "success";
  740. }
  741. #endregion
  742. #region 关闭
  743. /// <summary>
  744. /// 关闭
  745. /// </summary>
  746. /// <returns></returns>
  747. public string Close(string Id)
  748. {
  749. string[] idlist = Id.Split(new char[] { ',' });
  750. AddSysLog(Id, "Users", "close");
  751. foreach (string subid in idlist)
  752. {
  753. int id = int.Parse(subid);
  754. Dictionary<string, object> Fields = new Dictionary<string, object>();
  755. Fields.Add("Status", 0);
  756. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  757. }
  758. db.SaveChanges();
  759. return "success";
  760. }
  761. #endregion
  762. #region 一键企业创客
  763. /// <summary>
  764. /// 一键企业创客
  765. /// </summary>
  766. /// <returns></returns>
  767. public string OpenEnterpriseMaker(string Id)
  768. {
  769. string[] idlist = Id.Split(new char[] { ',' });
  770. AddSysLog(Id, "Users", "OpenEnterpriseMaker");
  771. foreach (string subid in idlist)
  772. {
  773. int id = int.Parse(subid);
  774. Dictionary<string, object> Fields = new Dictionary<string, object>();
  775. Fields.Add("BusinessFlag", 1);
  776. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  777. }
  778. db.SaveChanges();
  779. return "success";
  780. }
  781. #endregion
  782. #region 关闭企业创客
  783. /// <summary>
  784. /// 关闭企业创客
  785. /// </summary>
  786. /// <returns></returns>
  787. public string CloseEnterpriseMaker(string Id)
  788. {
  789. string[] idlist = Id.Split(new char[] { ',' });
  790. AddSysLog(Id, "Users", "CloseEnterpriseMaker");
  791. foreach (string subid in idlist)
  792. {
  793. int id = int.Parse(subid);
  794. Dictionary<string, object> Fields = new Dictionary<string, object>();
  795. Fields.Add("BusinessFlag", 0);
  796. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  797. }
  798. db.SaveChanges();
  799. return "success";
  800. }
  801. #endregion
  802. #region 一键大盟主
  803. /// <summary>
  804. /// 一键大盟主
  805. /// </summary>
  806. /// <returns></returns>
  807. public string SetBigLeader(string Id)
  808. {
  809. string[] idlist = Id.Split(new char[] { ',' });
  810. AddSysLog(Id, "Users", "SetBigLeader");
  811. foreach (string subid in idlist)
  812. {
  813. int id = int.Parse(subid);
  814. Dictionary<string, object> Fields = new Dictionary<string, object>();
  815. Fields.Add("LeaderLevel", 2);
  816. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  817. }
  818. db.SaveChanges();
  819. return "success";
  820. }
  821. #endregion
  822. #region 一键小盟主
  823. /// <summary>
  824. /// 一键小盟主
  825. /// </summary>
  826. /// <returns></returns>
  827. public string SetSmallLeader(string Id)
  828. {
  829. string[] idlist = Id.Split(new char[] { ',' });
  830. AddSysLog(Id, "Users", "SetSmallLeader");
  831. foreach (string subid in idlist)
  832. {
  833. int id = int.Parse(subid);
  834. Dictionary<string, object> Fields = new Dictionary<string, object>();
  835. Fields.Add("LeaderLevel", 1);
  836. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  837. }
  838. db.SaveChanges();
  839. return "success";
  840. }
  841. #endregion
  842. #region 风控
  843. public IActionResult Risk(string right, int Id = 0)
  844. {
  845. ViewBag.RightInfo = RightInfo;
  846. ViewBag.right = right;
  847. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  848. ViewBag.data = editData;
  849. return View();
  850. }
  851. #endregion
  852. #region 风控
  853. [HttpPost]
  854. public string Risk(Users data)
  855. {
  856. Users user = db.Users.FirstOrDefault(m => m.Id == data.Id);
  857. if (user != null)
  858. {
  859. user.RiskFlag = data.RiskFlag;
  860. user.RiskRemark = data.RiskRemark;
  861. db.SaveChanges();
  862. }
  863. return "success";
  864. }
  865. #endregion
  866. #region 解除风控
  867. public string UnRisk(string Id)
  868. {
  869. string[] idlist = Id.Split(new char[] { ',' });
  870. AddSysLog(Id, "Users", "UnRisk");
  871. foreach (string subid in idlist)
  872. {
  873. int id = int.Parse(subid);
  874. Dictionary<string, object> Fields = new Dictionary<string, object>();
  875. Fields.Add("RiskFlag", 0);
  876. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  877. }
  878. db.SaveChanges();
  879. return "success";
  880. }
  881. #endregion
  882. #region 重置密码
  883. public string ResetPwd(int Id)
  884. {
  885. string NewPwd = function.get_Random(6);
  886. Dictionary<string, object> Fields = new Dictionary<string, object>();
  887. Fields.Add("LoginPwd", function.MD532(NewPwd));
  888. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, Id);
  889. AddSysLog(Id, "Users", "ResetPwd");
  890. return "success|" + NewPwd;
  891. }
  892. #endregion
  893. #region 排序
  894. /// <summary>
  895. /// 排序
  896. /// </summary>
  897. /// <param name="Id"></param>
  898. public string Sort(int Id, int Sort)
  899. {
  900. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("Users", Sort, Id);
  901. AddSysLog(Id.ToString(), "Users", "sort");
  902. return "success";
  903. }
  904. #endregion
  905. #region 导入数据
  906. /// <summary>
  907. /// 导入数据
  908. /// </summary>
  909. /// <param name="ExcelData"></param>
  910. public string Import(string ExcelData, int Kind = 0)
  911. {
  912. ExcelData = HttpUtility.UrlDecode(ExcelData);
  913. JsonData list = JsonMapper.ToObject(ExcelData);
  914. if (Kind == 1)
  915. {
  916. for (int i = 1; i < list.Count; i++)
  917. {
  918. JsonData dr = list[i];
  919. string MakerCode = dr[0].ToString();
  920. string SettleAmount = dr[2].ToString();
  921. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  922. if (UserCode != null)
  923. {
  924. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  925. if (User != null)
  926. {
  927. User.SettleAmount = decimal.Parse(function.CheckInt(SettleAmount));
  928. }
  929. }
  930. }
  931. db.SaveChanges();
  932. }
  933. else if (Kind == 2)
  934. {
  935. for (int i = 1; i < list.Count; i++)
  936. {
  937. JsonData dr = list[i];
  938. string MakerCode = dr[0].ToString();
  939. string CashFreezeAmt = dr[2].ToString();
  940. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  941. if (UserCode != null)
  942. {
  943. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  944. if (User != null)
  945. {
  946. User.CashFreezeAmt = decimal.Parse(function.CheckInt(CashFreezeAmt));
  947. }
  948. }
  949. }
  950. db.SaveChanges();
  951. }
  952. else if (Kind == 3)
  953. {
  954. for (int i = 1; i < list.Count; i++)
  955. {
  956. JsonData dr = list[i];
  957. string MakerCode = dr[0].ToString();
  958. string RiskFlag = dr[2].ToString();
  959. string RiskNote = dr[3].ToString();
  960. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  961. if (UserCode != null)
  962. {
  963. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  964. if (User != null)
  965. {
  966. User.RiskFlag = ulong.Parse(function.CheckInt(RiskFlag));
  967. User.RiskRemark = RiskNote;
  968. }
  969. }
  970. }
  971. db.SaveChanges();
  972. }
  973. else if (Kind == 4)
  974. {
  975. string error = "";
  976. for (int i = 1; i < list.Count; i++)
  977. {
  978. JsonData dr = list[i];
  979. string MakerCode = dr[0].ToString();
  980. string OperationAmt = dr[2].ToString();//操作金额
  981. string OperationType = dr[3].ToString();//操作类型
  982. UserForMakerCode UserCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  983. if (UserCode != null)
  984. {
  985. Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  986. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == User.Id);
  987. if (account == null)
  988. {
  989. account = db.UserAccount.Add(new UserAccount()
  990. {
  991. Id = User.Id,
  992. UserId = User.Id,
  993. }).Entity;
  994. db.SaveChanges();
  995. }
  996. if (User != null)
  997. {
  998. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  999. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  1000. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  1001. int ChangeType = 0;
  1002. if (OperationType == "1" && Convert.ToDecimal(OperationAmt) <= account.BalanceAmount)
  1003. {
  1004. account.BalanceAmount -= Convert.ToDecimal(OperationAmt);
  1005. account.FreezeAmount += Convert.ToDecimal(OperationAmt);
  1006. ChangeType = 61;
  1007. }
  1008. else if (OperationType == "1" && Convert.ToDecimal(OperationAmt) > account.BalanceAmount)
  1009. {
  1010. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "冻结金额大于余额" + '|' + '\n';
  1011. }
  1012. else if (OperationType == "2" && Convert.ToDecimal(OperationAmt) <= account.FreezeAmount)
  1013. {
  1014. account.BalanceAmount += Convert.ToDecimal(OperationAmt);
  1015. account.FreezeAmount -= Convert.ToDecimal(OperationAmt);
  1016. ChangeType = 62;
  1017. }
  1018. else if (OperationType == "2" && Convert.ToDecimal(OperationAmt) > account.FreezeAmount)
  1019. {
  1020. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "解冻金额大于冻结金额" + '|' + '\n';
  1021. }
  1022. else if (OperationType == "3" && Convert.ToDecimal(OperationAmt) <= account.BalanceAmount)
  1023. {
  1024. account.TotalAmount -= Convert.ToDecimal(OperationAmt);
  1025. account.BalanceAmount -= Convert.ToDecimal(OperationAmt);
  1026. ChangeType = 63;
  1027. }
  1028. else if (OperationType == "3" && Convert.ToDecimal(OperationAmt) > account.BalanceAmount)
  1029. {
  1030. error += "以下操作失败" + User.MakerCode + ',' + User.RealName + "扣减金额大于余额" + '|' + '\n';
  1031. }
  1032. else if (OperationType == "4")
  1033. {
  1034. account.TotalAmount += Convert.ToDecimal(OperationAmt);
  1035. account.BalanceAmount += Convert.ToDecimal(OperationAmt);
  1036. ChangeType = 64;
  1037. }
  1038. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  1039. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  1040. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  1041. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  1042. {
  1043. CreateDate = DateTime.Now,
  1044. UpdateDate = DateTime.Now,
  1045. UserId = User.Id, //创客
  1046. ChangeType = ChangeType, //变动类型
  1047. ChangeAmount = Convert.ToDecimal(OperationAmt), //变更金额
  1048. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  1049. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  1050. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  1051. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  1052. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  1053. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  1054. Remark = dr[4].ToString(),
  1055. }).Entity;
  1056. db.SaveChanges();
  1057. AddSysLog(User.Id.ToString(), "Users", "ChangeCashFreezeAmts");
  1058. db.SaveChanges();
  1059. }
  1060. }
  1061. }
  1062. db.SaveChanges();
  1063. return "warning" + error;
  1064. }
  1065. AddSysLog("0", "Users", "Import");
  1066. return "success";
  1067. }
  1068. #endregion
  1069. #region 通过队列导入数据
  1070. public IActionResult ImportByQueue(string right, string ExcelKind)
  1071. {
  1072. ViewBag.RightInfo = RightInfo;
  1073. ViewBag.right = right;
  1074. ViewBag.ExcelKind = ExcelKind;
  1075. return View();
  1076. }
  1077. /// <summary>
  1078. /// 通过队列导入数据
  1079. /// </summary>
  1080. /// <param name="ExcelPath"></param>
  1081. [HttpPost]
  1082. public string ImportByQueuePost(string ExcelPath, int Kind = 0)
  1083. {
  1084. string key = function.MD5_16(Guid.NewGuid().ToString());
  1085. RedisDbconn.Instance.AddList("BatchEditUserAmountQueue", ExcelPath + "#cut#" + Kind + "#cut#" + key + "#cut#" + SysUserName);
  1086. return "success|" + key;
  1087. }
  1088. public string CheckImport(string key)
  1089. {
  1090. string result = RedisDbconn.Instance.Get<string>("BatchEditUserAmountCheckImport:" + key);
  1091. if (!string.IsNullOrEmpty(result))
  1092. {
  1093. string[] datalist = result.Split('|');
  1094. if (datalist[0] == "success")
  1095. {
  1096. return result;
  1097. }
  1098. return datalist[0];
  1099. }
  1100. return "0";
  1101. }
  1102. public Dictionary<string, object> CheckImportV2(string key)
  1103. {
  1104. Dictionary<string, object> Obj = new Dictionary<string, object>();
  1105. string result = RedisDbconn.Instance.Get<string>("BatchEditUserAmountCheckImport:" + key);
  1106. if (!string.IsNullOrEmpty(result))
  1107. {
  1108. string[] datalist = result.Split('|');
  1109. if (datalist[0] == "success")
  1110. {
  1111. List<string> errList = RedisDbconn.Instance.GetList<string>("ErrList" + key);
  1112. if (errList.Count > 0)
  1113. {
  1114. Obj.Add("status", 2);
  1115. Obj.Add("errList", errList);
  1116. }
  1117. else
  1118. {
  1119. Obj.Add("status", 1);
  1120. Obj.Add("data", result);
  1121. }
  1122. return Obj;
  1123. }
  1124. Obj.Add("status", 0);
  1125. Obj.Add("data", datalist[0]);
  1126. return Obj;
  1127. }
  1128. Obj.Add("status", -1);
  1129. Obj.Add("data", "执行中...");
  1130. return Obj;
  1131. }
  1132. #endregion
  1133. #region 导出Excel
  1134. /// <summary>
  1135. /// 导出Excel
  1136. /// </summary>
  1137. /// <returns></returns>
  1138. 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)
  1139. {
  1140. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1141. Fields.Add("MakerCode", "1"); //创客编号
  1142. Fields.Add("RealName", "1"); //创客名称
  1143. Fields.Add("Mobile", "1"); //手机号
  1144. Fields.Add("CertId", "1"); //身份证号码
  1145. Fields.Add("CreateDate", "3"); //注册时间
  1146. Fields.Add("SettleAmount", "3"); //结算金额
  1147. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  1148. Fields.Add("UserLevel", "0"); //创客等级
  1149. string condition = " and Status>-1";
  1150. //直属创客编号
  1151. if (!string.IsNullOrEmpty(ParentMakerCode))
  1152. {
  1153. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  1154. }
  1155. //直属创客名称
  1156. if (!string.IsNullOrEmpty(ParentRealName))
  1157. {
  1158. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  1159. }
  1160. //实名状态
  1161. if (!string.IsNullOrEmpty(AuthFlagSelect))
  1162. {
  1163. condition += " and AuthFlag=" + AuthFlagSelect;
  1164. }
  1165. //顶级创客
  1166. if (TopUserId > 0)
  1167. {
  1168. condition += " and ParentNav like '," + TopUserId + ",%'";
  1169. }
  1170. //风控标识
  1171. if (!string.IsNullOrEmpty(RiskFlagSelect))
  1172. {
  1173. condition += " and RiskFlag=" + RiskFlagSelect;
  1174. }
  1175. //商户创客类型
  1176. if (!string.IsNullOrEmpty(MerchantTypeSelect))
  1177. {
  1178. condition += " and MerchantType=" + MerchantTypeSelect;
  1179. }
  1180. if (SelfId > 0)
  1181. {
  1182. Users self = db.Users.FirstOrDefault(m => m.Id == SelfId);
  1183. if (self != null)
  1184. {
  1185. string ParentNav = function.CheckNull(self.ParentNav);
  1186. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  1187. }
  1188. }
  1189. if (ParentId > 0)
  1190. {
  1191. condition += " and ParentUserId=" + ParentId;
  1192. }
  1193. 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);
  1194. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1195. foreach (Dictionary<string, object> dic in diclist)
  1196. {
  1197. dic["AuthFlag"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  1198. dic["RiskFlag"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  1199. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1200. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  1201. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  1202. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1203. dic["ParentMakerCode"] = puser.MakerCode;
  1204. dic["ParentRealName"] = puser.RealName;
  1205. string ParentNav = dic["ParentNav"].ToString();
  1206. if (!string.IsNullOrEmpty(ParentNav))
  1207. {
  1208. string[] list = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1209. if (list.Length > 1)
  1210. {
  1211. int TopId = int.Parse(function.CheckInt(list[1]));
  1212. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1213. dic["TopMakerCode"] = tuser.MakerCode;
  1214. dic["TopRealName"] = tuser.RealName;
  1215. }
  1216. }
  1217. dic.Remove("ParentUserId");
  1218. dic.Remove("ParentNav");
  1219. }
  1220. Dictionary<string, object> result = new Dictionary<string, object>();
  1221. result.Add("Status", "1");
  1222. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1223. result.Add("Obj", diclist);
  1224. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1225. ReturnFields.Add("MakerCode", "创客编号");
  1226. ReturnFields.Add("RealName", "创客姓名");
  1227. ReturnFields.Add("UserLevel", "创客等级");
  1228. ReturnFields.Add("SettleAmount", "提现金额(元)");
  1229. ReturnFields.Add("CashFreezeAmt", "冻结金额(元)");
  1230. ReturnFields.Add("CertId", "身份证号");
  1231. ReturnFields.Add("Mobile", "联系手机");
  1232. ReturnFields.Add("MerchantType", "商户创客类型");
  1233. ReturnFields.Add("MerchantDate", "成为商户创客时间");
  1234. ReturnFields.Add("ParentMakerCode", "直属创客编号");
  1235. ReturnFields.Add("ParentRealName", "直属创客名称");
  1236. ReturnFields.Add("TopMakerCode", "顶级创客编号");
  1237. ReturnFields.Add("TopRealName", "顶级创客名称");
  1238. ReturnFields.Add("AuthFlag", "实名状态");
  1239. ReturnFields.Add("RiskFlag", "风控状态");
  1240. ReturnFields.Add("CreateDate", "注册时间");
  1241. result.Add("Fields", ReturnFields);
  1242. AddSysLog("0", "Users", "ExportExcel");
  1243. return Json(result);
  1244. }
  1245. #endregion
  1246. #region 直属创客导出Excel
  1247. /// <summary>
  1248. /// 直属创客导出Excel
  1249. /// </summary>
  1250. /// <returns></returns>
  1251. public JsonResult ExportZSExcel(Users data, string MakerCode, string ParentMakerCode)
  1252. {
  1253. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1254. string condition = " and Status>-1";
  1255. //创客编号
  1256. if (!string.IsNullOrEmpty(MakerCode))
  1257. {
  1258. condition += " and ParentUserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  1259. }
  1260. //直属创客编号
  1261. if (!string.IsNullOrEmpty(ParentMakerCode))
  1262. {
  1263. condition += " and ParentUserId in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  1264. }
  1265. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", 1, 20000, condition, "Id,MakerCode,RealName,UserLevel", false);
  1266. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1267. foreach (Dictionary<string, object> dic in diclist)
  1268. {
  1269. int Id = int.Parse(dic["Id"].ToString());
  1270. Users userZS = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  1271. dic["MakerCode"] = userZS.MakerCode;
  1272. dic["RealName"] = userZS.RealName;
  1273. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1274. }
  1275. Dictionary<string, object> result = new Dictionary<string, object>();
  1276. result.Add("Status", "1");
  1277. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1278. result.Add("Obj", diclist);
  1279. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1280. ReturnFields.Add("Id", "Id");
  1281. ReturnFields.Add("MakerCode", "创客编号");
  1282. ReturnFields.Add("RealName", "创客姓名");
  1283. ReturnFields.Add("UserLevel", "创客等级");
  1284. result.Add("Fields", ReturnFields);
  1285. AddSysLog("0", "Users", "ExportZSExcel");
  1286. return Json(result);
  1287. }
  1288. #endregion
  1289. #region 上级创客导出Excel
  1290. /// <summary>
  1291. /// 上级创客导出Excel
  1292. /// </summary>
  1293. /// <returns></returns>
  1294. public JsonResult ExportSJExcel(Users data, string MakerCode, string ParentMakerCode)
  1295. {
  1296. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1297. string condition = " and Status>-1";
  1298. //创客编号
  1299. if (!string.IsNullOrEmpty(MakerCode))
  1300. {
  1301. var query = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1302. Users self = db.Users.FirstOrDefault(m => m.Id == query.UserId);
  1303. if (self != null)
  1304. {
  1305. string ParentNav = function.CheckNull(self.ParentNav);
  1306. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  1307. }
  1308. }
  1309. //直属创客编号
  1310. if (!string.IsNullOrEmpty(ParentMakerCode))
  1311. {
  1312. var query = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ParentMakerCode);
  1313. Users self = db.Users.FirstOrDefault(m => m.Id == query.UserId);
  1314. if (self != null)
  1315. {
  1316. string ParentNav = function.CheckNull(self.ParentNav);
  1317. condition += " and Id in (" + ParentNav.Trim(',').Replace(",,", ",") + ")";
  1318. }
  1319. }
  1320. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", 1, 20000, condition, "Id,MakerCode,RealName,UserLevel", false);
  1321. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1322. foreach (Dictionary<string, object> dic in diclist)
  1323. {
  1324. int Id = int.Parse(dic["Id"].ToString());
  1325. Users userSJ = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  1326. dic["MakerCode"] = userSJ.MakerCode;
  1327. dic["RealName"] = userSJ.RealName;
  1328. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1329. }
  1330. Dictionary<string, object> result = new Dictionary<string, object>();
  1331. result.Add("Status", "1");
  1332. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1333. result.Add("Obj", diclist);
  1334. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1335. ReturnFields.Add("Id", "Id");
  1336. ReturnFields.Add("MakerCode", "创客编号");
  1337. ReturnFields.Add("RealName", "创客姓名");
  1338. ReturnFields.Add("UserLevel", "创客等级");
  1339. result.Add("Fields", ReturnFields);
  1340. AddSysLog("0", "Users", "ExportExcel");
  1341. return Json(result);
  1342. }
  1343. #endregion
  1344. #region 同步数据
  1345. /// <summary>
  1346. /// 同步数据
  1347. /// </summary>
  1348. /// <returns></returns>
  1349. public string SycnData(int Id = 0)
  1350. {
  1351. var Brands = db.KqProducts.Where(m => m.Status == 1).ToList();
  1352. foreach (var Brand in Brands)
  1353. {
  1354. PublicFunction.SycnMachineCount(Id, Brand.Id);
  1355. }
  1356. AddSysLog(Id, "Users", "SycnData");
  1357. db.SaveChanges();
  1358. return "success";
  1359. }
  1360. #endregion
  1361. #region 同步交易额
  1362. public IActionResult SycnTradeAmount(string right, int Id = 0)
  1363. {
  1364. ViewBag.RightInfo = RightInfo;
  1365. ViewBag.right = right;
  1366. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  1367. ViewBag.data = editData;
  1368. return View();
  1369. }
  1370. #endregion
  1371. #region 同步交易额
  1372. [HttpPost]
  1373. public string SycnTradeAmountDo(DateTime sdate, DateTime edate, int UserId, int BrandId)
  1374. {
  1375. if (sdate.AddMonths(1) < edate)
  1376. {
  1377. return "时间间隔不能超过1个月";
  1378. }
  1379. if (edate >= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"))
  1380. {
  1381. return "结束时间只能是今天之前";
  1382. }
  1383. string check = RedisDbconn.Instance.Get<string>("ResetUserTradeQueue:" + UserId + ":" + BrandId);
  1384. if (!string.IsNullOrEmpty(check))
  1385. {
  1386. return "请稍后再试";
  1387. }
  1388. try
  1389. {
  1390. 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);
  1391. RedisDbconn.Instance.Set("ResetUserTradeQueue:" + UserId + ":" + BrandId, "wait");
  1392. RedisDbconn.Instance.SetExpire("ResetUserTradeQueue:" + UserId + ":" + BrandId, 3600);
  1393. }
  1394. catch (Exception ex)
  1395. {
  1396. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计创客的交易额异常");
  1397. return "同步异常";
  1398. }
  1399. return "success";
  1400. }
  1401. #endregion
  1402. #region 创客展业城市
  1403. public IActionResult City(Users data, string right)
  1404. {
  1405. ViewBag.RightInfo = RightInfo;
  1406. ViewBag.right = right;
  1407. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  1408. ViewBag.TopUsers = TopUsers;
  1409. return View();
  1410. }
  1411. #endregion
  1412. #region 根据条件查询创客展业城市
  1413. public JsonResult CityData(Users data, string ParentMakerCode, string ParentRealName, int TopUserId, string Areas, int page = 1, int limit = 30)
  1414. {
  1415. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1416. Fields.Add("MakerCode", "1"); //创客编号
  1417. Fields.Add("RealName", "1"); //创客名称
  1418. Fields.Add("CitySetDate", "3"); //创建时间
  1419. Fields.Add("Areas", "2"); //省市
  1420. string condition = " and Status>-1";
  1421. //直属创客编号
  1422. if (!string.IsNullOrEmpty(ParentMakerCode))
  1423. {
  1424. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  1425. }
  1426. //直属创客名称
  1427. if (!string.IsNullOrEmpty(ParentRealName))
  1428. {
  1429. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  1430. }
  1431. //顶级创客
  1432. if (TopUserId > 0)
  1433. {
  1434. condition += " and ParentNav like '," + TopUserId + ",%'";
  1435. }
  1436. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", page, limit, condition);
  1437. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1438. foreach (Dictionary<string, object> dic in diclist)
  1439. {
  1440. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  1441. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1442. dic["ParentMakerCode"] = puser.MakerCode;
  1443. dic["ParentRealName"] = puser.RealName;
  1444. string ParentNav = dic["ParentNav"].ToString();
  1445. if (!string.IsNullOrEmpty(ParentNav))
  1446. {
  1447. int TopId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  1448. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1449. dic["TopMakerCode"] = tuser.MakerCode;
  1450. dic["TopRealName"] = tuser.RealName;
  1451. }
  1452. }
  1453. return Json(obj);
  1454. }
  1455. #endregion
  1456. #region 导出展业城市
  1457. public JsonResult ExportCity(Users data, string CreateDate, string ParentMakerCode, string ParentRealName, string AuthFlagSelect, int TopUserId, string RiskFlagSelect, string MerchantTypeSelect)
  1458. {
  1459. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1460. Fields.Add("MakerCode", "1"); //创客编号
  1461. Fields.Add("RealName", "1"); //创客名称
  1462. Fields.Add("Mobile", "1"); //手机号
  1463. Fields.Add("CertId", "1"); //身份证号码
  1464. Fields.Add("CreateDate", "3"); //注册时间
  1465. Fields.Add("SettleAmount", "3"); //结算金额
  1466. Fields.Add("CashFreezeAmt", "3"); //冻结金额
  1467. Fields.Add("UserLevel", "0"); //创客等级
  1468. string condition = " and Status>-1";
  1469. //直属创客编号
  1470. if (!string.IsNullOrEmpty(ParentMakerCode))
  1471. {
  1472. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + ParentMakerCode + "')";
  1473. }
  1474. //直属创客名称
  1475. if (!string.IsNullOrEmpty(ParentRealName))
  1476. {
  1477. condition += " and Id in (select UserId from UserForRealName where RealName='" + ParentRealName + "')";
  1478. }
  1479. //实名状态
  1480. if (!string.IsNullOrEmpty(AuthFlagSelect))
  1481. {
  1482. condition += " and AuthFlag=" + AuthFlagSelect;
  1483. }
  1484. //顶级创客
  1485. if (TopUserId > 0)
  1486. {
  1487. condition += " and ParentNav like '," + TopUserId + ",%'";
  1488. }
  1489. //风控标识
  1490. if (!string.IsNullOrEmpty(RiskFlagSelect))
  1491. {
  1492. condition += " and RiskFlag=" + RiskFlagSelect;
  1493. }
  1494. //商户创客类型
  1495. if (!string.IsNullOrEmpty(MerchantTypeSelect))
  1496. {
  1497. condition += " and MerchantType=" + MerchantTypeSelect;
  1498. }
  1499. 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);
  1500. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1501. foreach (Dictionary<string, object> dic in diclist)
  1502. {
  1503. dic["AuthFlag"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  1504. dic["RiskFlag"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  1505. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1506. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  1507. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  1508. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1509. dic["ParentMakerCode"] = puser.MakerCode;
  1510. dic["ParentRealName"] = puser.RealName;
  1511. string ParentNav = dic["ParentNav"].ToString();
  1512. if (!string.IsNullOrEmpty(ParentNav))
  1513. {
  1514. int TopId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  1515. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1516. dic["TopMakerCode"] = tuser.MakerCode;
  1517. dic["TopRealName"] = tuser.RealName;
  1518. }
  1519. dic.Remove("ParentUserId");
  1520. dic.Remove("ParentNav");
  1521. }
  1522. Dictionary<string, object> result = new Dictionary<string, object>();
  1523. result.Add("Status", "1");
  1524. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1525. result.Add("Obj", diclist);
  1526. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1527. ReturnFields.Add("MakerCode", "创客编号");
  1528. ReturnFields.Add("RealName", "创客姓名");
  1529. ReturnFields.Add("UserLevel", "创客等级");
  1530. ReturnFields.Add("SettleAmount", "提现金额(元)");
  1531. ReturnFields.Add("CashFreezeAmt", "冻结金额(元)");
  1532. ReturnFields.Add("CertId", "身份证号");
  1533. ReturnFields.Add("Mobile", "联系手机");
  1534. ReturnFields.Add("MerchantType", "商户创客类型");
  1535. ReturnFields.Add("MerchantDate", "成为商户创客时间");
  1536. ReturnFields.Add("ParentMakerCode", "直属创客编号");
  1537. ReturnFields.Add("ParentRealName", "直属创客名称");
  1538. ReturnFields.Add("TopMakerCode", "顶级创客编号");
  1539. ReturnFields.Add("TopRealName", "顶级创客名称");
  1540. ReturnFields.Add("AuthFlag", "实名状态");
  1541. ReturnFields.Add("RiskFlag", "风控状态");
  1542. ReturnFields.Add("CreateDate", "注册时间");
  1543. result.Add("Fields", ReturnFields);
  1544. AddSysLog("0", "Users", "ExportExcel");
  1545. return Json(result);
  1546. }
  1547. #endregion
  1548. #region 根据条件查询直属创客交易额列表
  1549. /// <summary>
  1550. /// 直属创客交易额列表
  1551. /// </summary>
  1552. /// <returns></returns>
  1553. public IActionResult Children(Users data, string right, int ParentId = 0, string MakerCode = "")
  1554. {
  1555. ViewBag.RightInfo = RightInfo;
  1556. ViewBag.right = right;
  1557. ViewBag.ParentId = ParentId.ToString();
  1558. ViewBag.MakerCode = MakerCode;
  1559. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  1560. ViewBag.TopUsers = TopUsers;
  1561. List<UserLevelSet> Levels = db.UserLevelSet.OrderBy(m => m.Id).ToList();
  1562. ViewBag.Levels = Levels;
  1563. List<KqProducts> Brands = db.KqProducts.OrderBy(m => m.Id).ToList();
  1564. ViewBag.Brands = Brands;
  1565. return View();
  1566. }
  1567. #endregion
  1568. #region 根据条件查询直属创客交易额列表
  1569. /// <summary>
  1570. /// 直属创客交易额列表
  1571. /// </summary>
  1572. /// <returns></returns>
  1573. public JsonResult ChildrenData(Users data, int BrandSelect, string MakerCode, string CreateDateData, int ParentId = 0, int page = 1, int limit = 30)
  1574. {
  1575. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1576. WebCMSEntities db = new WebCMSEntities();
  1577. Fields.Add("MakerCode", "1"); //创客编号
  1578. int BrandId = BrandSelect;
  1579. string start = "";
  1580. string end = "";
  1581. string condition = " and Status>-1 and AuthFlag >0";
  1582. string con = " and Status>-1";
  1583. string cons = " and Status>=-1";
  1584. string sort = "Id desc";
  1585. //创客编号
  1586. if (!string.IsNullOrEmpty(MakerCode))
  1587. {
  1588. condition += " and Id in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  1589. }
  1590. if (ParentId > 0)
  1591. {
  1592. condition += " and ParentUserId=" + ParentId + " or Id=" + ParentId;
  1593. }
  1594. //时间不为空
  1595. if (!string.IsNullOrEmpty(CreateDateData))
  1596. {
  1597. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1598. start = datelist[0].Replace("-", "");
  1599. end = datelist[1].Replace("-", "");
  1600. con += " and TradeDate>='" + start + "' and TradeDate<='" + end + "'";
  1601. cons += " and SeoKeyword >=" + start + " and SeoKeyword <=" + end;
  1602. }
  1603. //时间为空
  1604. else
  1605. {
  1606. start = DateTime.Now.ToString("yyyyMM") + "01";
  1607. end = DateTime.Now.AddMonths(1).ToString("yyyyMM") + "01";
  1608. con += " and TradeDate>='" + start + "' and TradeDate<'" + end + "'";
  1609. cons += " and SeoKeyword >=" + start + " and SeoKeyword <" + end;
  1610. }
  1611. if (!string.IsNullOrEmpty(BrandSelect.ToString()) && BrandId > 0)
  1612. {
  1613. con += " and BrandId='" + BrandId + "'";
  1614. cons += " and BrandId='" + BrandId + "'";
  1615. }
  1616. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, sort, "True", page, limit, condition);
  1617. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1618. foreach (Dictionary<string, object> dic in diclist)
  1619. {
  1620. int UId = int.Parse(dic["Id"].ToString());
  1621. var Info = GetMonthTradeForBrand(UId, start, end, BrandId);
  1622. dic["TotalAmtfc"] = Convert.ToDecimal(Info["TotalAmtfc"].ToString()) + Convert.ToDecimal(Info["YAmtfc"].ToString());
  1623. dic["DAmtfc"] = Convert.ToDecimal(Info["DAmtfc"].ToString());
  1624. dic["JAmtfc"] = Convert.ToDecimal(Info["JAmtfc"].ToString());
  1625. dic["JfAmtfc"] = Convert.ToDecimal(Info["JfAmtfc"].ToString());
  1626. dic["JCountfc"] = Convert.ToInt32(Info["JCountfc"].ToString());
  1627. dic["YAmtfc"] = Convert.ToDecimal(Info["YAmtfc"].ToString());
  1628. dic["TotalAmtwd"] = Convert.ToDecimal(Info["TotalAmtwd"].ToString()) + Convert.ToDecimal(Info["YAmtwd"].ToString());
  1629. dic["DAmtwd"] = Convert.ToDecimal(Info["DAmtwd"].ToString());
  1630. dic["JAmtwd"] = Convert.ToDecimal(Info["JAmtwd"].ToString());
  1631. dic["JfAmtwd"] = Convert.ToDecimal(Info["JfAmtwd"].ToString());
  1632. dic["JCountwd"] = Convert.ToInt32(Info["JCountwd"].ToString());
  1633. dic["YAmtwd"] = Convert.ToDecimal(Info["YAmtwd"].ToString());
  1634. dic["TotalAmtyl"] = Convert.ToDecimal(Info["TotalAmtyl"].ToString()) + Convert.ToDecimal(Info["YAmtyl"].ToString());
  1635. dic["DAmtyl"] = Convert.ToDecimal(Info["DAmtyl"].ToString());
  1636. dic["JAmtyl"] = Convert.ToDecimal(Info["JAmtyl"].ToString());
  1637. dic["JfAmtyl"] = Convert.ToDecimal(Info["JfAmtyl"].ToString());
  1638. dic["JCountyl"] = Convert.ToInt32(Info["JCountyl"].ToString());
  1639. dic["YAmtyl"] = Convert.ToDecimal(Info["YAmtyl"].ToString());
  1640. dic["TBCount"] = Info["TBCount"].ToString();
  1641. dic["TACount"] = Info["TACount"].ToString();
  1642. }
  1643. //个人
  1644. //扶持期
  1645. decimal TotalAmtfc = 0;
  1646. decimal DAmtfc = 0;
  1647. decimal JAmtfc = 0;
  1648. decimal JfAmtfc = 0;
  1649. int JCountfc = 0;
  1650. decimal YAmtfc = 0;
  1651. //稳定期
  1652. decimal TotalAmtwd = 0;
  1653. decimal DAmtwd = 0;
  1654. decimal JAmtwd = 0;
  1655. decimal JfAmtwd = 0;
  1656. int JCountwd = 0;
  1657. decimal YAmtwd = 0;
  1658. //盈利期
  1659. decimal TotalAmtyl = 0;
  1660. decimal DAmtyl = 0;
  1661. decimal JAmtyl = 0;
  1662. decimal JfAmtyl = 0;
  1663. int JCountyl = 0;
  1664. decimal YAmtyl = 0;
  1665. //团队
  1666. //扶持期
  1667. decimal TotalAmtfc1 = 0;
  1668. decimal DAmtfc1 = 0;
  1669. decimal JAmtfc1 = 0;
  1670. decimal JfAmtfc1 = 0;
  1671. int JCountfc1 = 0;
  1672. decimal YAmtfc1 = 0;
  1673. //稳定期
  1674. decimal TotalAmtwd1 = 0;
  1675. decimal DAmtwd1 = 0;
  1676. decimal JAmtwd1 = 0;
  1677. decimal JfAmtwd1 = 0;
  1678. int JCountwd1 = 0;
  1679. decimal YAmtwd1 = 0;
  1680. //盈利期
  1681. decimal TotalAmtyl1 = 0;
  1682. decimal DAmtyl1 = 0;
  1683. decimal JAmtyl1 = 0;
  1684. decimal JfAmtyl1 = 0;
  1685. int JCountyl1 = 0;
  1686. decimal YAmtyl1 = 0;
  1687. int PBCount = 0;
  1688. int PACount = 0;
  1689. int TBCount = 0;
  1690. int TACount = 0;
  1691. Dictionary<string, object> other = new Dictionary<string, object>();
  1692. 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);
  1693. if (dt.Rows.Count > 0)
  1694. {
  1695. TotalAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1696. DAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1697. JAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][2].ToString()));
  1698. JfAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][3].ToString()));
  1699. JCountfc = Convert.ToInt32(function.CheckInt(dt.Rows[0][4].ToString()));
  1700. YAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][5].ToString()));
  1701. TotalAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][6].ToString()));
  1702. DAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][7].ToString()));
  1703. JAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][8].ToString()));
  1704. JfAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][9].ToString()));
  1705. JCountwd = Convert.ToInt32(function.CheckInt(dt.Rows[0][10].ToString()));
  1706. YAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][11].ToString()));
  1707. TotalAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][12].ToString()));
  1708. DAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][13].ToString()));
  1709. JAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][14].ToString()));
  1710. JfAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][15].ToString()));
  1711. JCountyl = Convert.ToInt32(function.CheckInt(dt.Rows[0][16].ToString()));
  1712. YAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][17].ToString()));
  1713. }
  1714. //统计激活数(个人、团队)
  1715. dt = OtherMySqlConn.dtable("SELECT SUM(if(SeoTitle='self',ActiveBuddyMerStatus,0)),SUM(if(SeoTitle='team',ActiveBuddyMerStatus,0)) FROM UserTradeMonthSummary WHERE UserId= " + ParentId + "" + cons);
  1716. if (dt.Rows.Count > 0)
  1717. {
  1718. PACount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1719. TACount = Convert.ToInt32(function.CheckNum(dt.Rows[0][1].ToString()));
  1720. }
  1721. 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);
  1722. if (dts.Rows.Count > 0)
  1723. {
  1724. TotalAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][0].ToString()));
  1725. DAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][1].ToString()));
  1726. JAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][2].ToString()));
  1727. JfAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][3].ToString()));
  1728. JCountfc1 = Convert.ToInt32(function.CheckInt(dts.Rows[0][4].ToString()));
  1729. YAmtfc1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][5].ToString()));
  1730. TotalAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][6].ToString()));
  1731. DAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][7].ToString()));
  1732. JAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][8].ToString()));
  1733. JfAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][9].ToString()));
  1734. JCountwd1 = Convert.ToInt32(function.CheckInt(dts.Rows[0][10].ToString()));
  1735. YAmtwd1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][11].ToString()));
  1736. TotalAmtyl1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][12].ToString()));
  1737. DAmtyl1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][13].ToString()));
  1738. JAmtyl1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][14].ToString()));
  1739. JfAmtyl1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][15].ToString()));
  1740. JCountyl1 = Convert.ToInt32(function.CheckInt(dts.Rows[0][16].ToString()));
  1741. YAmtyl1 = Convert.ToDecimal(function.CheckNum(dts.Rows[0][17].ToString()));
  1742. }
  1743. other.Add("TotalAmtfc", TotalAmtfc);
  1744. other.Add("DAmtfc", DAmtfc);
  1745. other.Add("JAmtfc", JAmtfc);
  1746. other.Add("JfAmtfc", JfAmtfc);
  1747. other.Add("JCountfc", JCountfc);
  1748. other.Add("YAmtfc", YAmtfc);
  1749. other.Add("TotalAmtwd", TotalAmtwd);
  1750. other.Add("DAmtwd", DAmtwd);
  1751. other.Add("JAmtwd", JAmtwd);
  1752. other.Add("JfAmtwd", JfAmtwd);
  1753. other.Add("JCountwd", JCountwd);
  1754. other.Add("YAmtwd", YAmtwd);
  1755. other.Add("TotalAmtyl", TotalAmtyl);
  1756. other.Add("DAmtyl", DAmtyl);
  1757. other.Add("JAmtyl", JAmtyl);
  1758. other.Add("JfAmtyl", JfAmtyl);
  1759. other.Add("JCountyl", JCountyl);
  1760. other.Add("YAmtyl", YAmtyl);
  1761. other.Add("TotalAmtfc1", TotalAmtfc1);
  1762. other.Add("DAmtfc1", DAmtfc1);
  1763. other.Add("JAmtfc1", JAmtfc1);
  1764. other.Add("JfAmtfc1", JfAmtfc1);
  1765. other.Add("JCountfc1", JCountfc1);
  1766. other.Add("YAmtfc1", YAmtfc1);
  1767. other.Add("TotalAmtwd1", TotalAmtwd1);
  1768. other.Add("DAmtwd1", DAmtwd1);
  1769. other.Add("JAmtwd1", JAmtwd1);
  1770. other.Add("JfAmtwd1", JfAmtwd1);
  1771. other.Add("JCountwd1", JCountwd1);
  1772. other.Add("YAmtwd1", YAmtwd1);
  1773. other.Add("TotalAmtyl1", TotalAmtyl1);
  1774. other.Add("DAmtyl1", DAmtyl1);
  1775. other.Add("JAmtyl1", JAmtyl1);
  1776. other.Add("JfAmtyl1", JfAmtyl1);
  1777. other.Add("JCountyl1", JCountyl1);
  1778. other.Add("YAmtyl1", YAmtyl1);
  1779. other.Add("PBCount", PBCount);
  1780. other.Add("PACount", PACount);
  1781. other.Add("TBCount", TBCount);
  1782. other.Add("TACount", TACount);
  1783. db.Dispose();
  1784. obj.Add("other", other);
  1785. return Json(obj);
  1786. }
  1787. public Dictionary<string, object> GetMonthTradeForBrand(int UserId, string sTradeDate, string eTradeDate, int BrandId)
  1788. {
  1789. WebCMSEntities db = new WebCMSEntities();
  1790. string condition = " and Status>-1";
  1791. string cons = " and Status>=-1";
  1792. //产品类型
  1793. if (!string.IsNullOrEmpty(BrandId.ToString()) && BrandId > 0)
  1794. {
  1795. condition += " and BrandId =" + BrandId;
  1796. cons += " and BrandId =" + BrandId;
  1797. }
  1798. //创客Id
  1799. if (!string.IsNullOrEmpty(UserId.ToString()))
  1800. {
  1801. condition += " and UserId =" + UserId;
  1802. }
  1803. //开始时间
  1804. if (!string.IsNullOrEmpty(sTradeDate) && !string.IsNullOrEmpty(eTradeDate))
  1805. {
  1806. condition += " and TradeDate >=" + Convert.ToInt32(sTradeDate) + " and TradeDate <=" + Convert.ToInt32(eTradeDate);
  1807. cons += " and SeoKeyword >=" + Convert.ToInt32(sTradeDate) + " and SeoKeyword <=" + Convert.ToInt32(eTradeDate);
  1808. }
  1809. //结束时间
  1810. else
  1811. {
  1812. var start = DateTime.Now.ToString("yyyyMM") + "01";
  1813. condition += " and TradeDate >=" + Convert.ToInt32(start) + " and TradeDate <=" + Convert.ToInt32(eTradeDate);
  1814. cons += " and SeoKeyword >=" + Convert.ToInt32(start) + " and SeoKeyword <=" + Convert.ToInt32(eTradeDate);
  1815. }
  1816. //扶持期
  1817. decimal TotalAmtfc = 0;
  1818. decimal DAmtfc = 0;
  1819. decimal JAmtfc = 0;
  1820. decimal JfAmtfc = 0;
  1821. int JCountfc = 0;
  1822. decimal YAmtfc = 0;
  1823. //稳定期
  1824. decimal TotalAmtwd = 0;
  1825. decimal DAmtwd = 0;
  1826. decimal JAmtwd = 0;
  1827. decimal JfAmtwd = 0;
  1828. int JCountwd = 0;
  1829. decimal YAmtwd = 0;
  1830. //盈利期
  1831. decimal TotalAmtyl = 0;
  1832. decimal DAmtyl = 0;
  1833. decimal JAmtyl = 0;
  1834. decimal JfAmtyl = 0;
  1835. int JCountyl = 0;
  1836. decimal YAmtyl = 0;
  1837. int BCount = 0;
  1838. int ACount = 0;
  1839. int PBCount = 0;
  1840. int PACount = 0;
  1841. int TBCount = 0;
  1842. int TACount = 0;
  1843. Dictionary<string, object> obj = new Dictionary<string, object>();
  1844. 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);
  1845. if (dt.Rows.Count > 0)
  1846. {
  1847. TotalAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][0].ToString()));
  1848. DAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][1].ToString()));
  1849. JAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][2].ToString()));
  1850. JfAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][3].ToString()));
  1851. JCountfc = Convert.ToInt32(function.CheckInt(dt.Rows[0][4].ToString()));
  1852. YAmtfc = Convert.ToDecimal(function.CheckNum(dt.Rows[0][5].ToString()));
  1853. TotalAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][6].ToString()));
  1854. DAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][7].ToString()));
  1855. JAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][8].ToString()));
  1856. JfAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][9].ToString()));
  1857. JCountwd = Convert.ToInt32(function.CheckInt(dt.Rows[0][10].ToString()));
  1858. YAmtwd = Convert.ToDecimal(function.CheckNum(dt.Rows[0][11].ToString()));
  1859. TotalAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][12].ToString()));
  1860. DAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][13].ToString()));
  1861. JAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][14].ToString()));
  1862. JfAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][15].ToString()));
  1863. JCountyl = Convert.ToInt32(function.CheckInt(dt.Rows[0][16].ToString()));
  1864. YAmtyl = Convert.ToDecimal(function.CheckNum(dt.Rows[0][17].ToString()));
  1865. }
  1866. //统计激活数(个人、团队)
  1867. dt = OtherMySqlConn.dtable("SELECT SUM(if(SeoTitle='team',ActiveBuddyMerStatus,0)) FROM UserTradeMonthSummary WHERE UserId= " + UserId + "" + cons);
  1868. if (dt.Rows.Count > 0)
  1869. {
  1870. TACount = Convert.ToInt32(function.CheckNum(dt.Rows[0][0].ToString()));
  1871. }
  1872. obj.Add("TotalAmtfc", TotalAmtfc);
  1873. obj.Add("DAmtfc", DAmtfc);
  1874. obj.Add("JAmtfc", JAmtfc);
  1875. obj.Add("JfAmtfc", JfAmtfc);
  1876. obj.Add("JCountfc", JCountfc);
  1877. obj.Add("YAmtfc", YAmtfc);
  1878. obj.Add("TotalAmtwd", TotalAmtwd);
  1879. obj.Add("DAmtwd", DAmtwd);
  1880. obj.Add("JAmtwd", JAmtwd);
  1881. obj.Add("JfAmtwd", JfAmtwd);
  1882. obj.Add("JCountwd", JCountwd);
  1883. obj.Add("YAmtwd", YAmtwd);
  1884. obj.Add("TotalAmtyl", TotalAmtyl);
  1885. obj.Add("DAmtyl", DAmtyl);
  1886. obj.Add("JAmtyl", JAmtyl);
  1887. obj.Add("JfAmtyl", JfAmtyl);
  1888. obj.Add("JCountyl", JCountyl);
  1889. obj.Add("YAmtyl", YAmtyl);
  1890. obj.Add("BCount", BCount);
  1891. obj.Add("ACount", ACount);
  1892. obj.Add("PBCount", PBCount);
  1893. obj.Add("PACount", PACount);
  1894. obj.Add("TBCount", TBCount);
  1895. obj.Add("TACount", TACount);
  1896. db.Dispose();
  1897. return obj;
  1898. }
  1899. #endregion
  1900. #region 未实名创客列表
  1901. /// <summary>
  1902. /// 根据条件查询未实名创客列表
  1903. /// </summary>
  1904. /// <returns></returns>
  1905. public IActionResult AuthIndex(Users data, string right)
  1906. {
  1907. ViewBag.RightInfo = RightInfo;
  1908. ViewBag.right = right;
  1909. return View();
  1910. }
  1911. #endregion
  1912. #region 根据条件查询未实名创客列表
  1913. /// <summary>
  1914. /// 未实名创客列表
  1915. /// </summary>
  1916. /// <returns></returns>
  1917. public JsonResult AuthIndexData(Users data, int page = 1, int limit = 30)
  1918. {
  1919. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1920. Fields.Add("MakerCode", "1"); //创客编号
  1921. string condition = " and Status>-1 and AuthFlag=0 and RealName is not null and CertId is not null and SettleBankCardNo is not null and SettleBankName is not null";
  1922. string sort = "Id desc";
  1923. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, sort, "True", page, limit, condition);
  1924. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1925. foreach (Dictionary<string, object> dic in diclist)
  1926. {
  1927. dic["AuthFlagName"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  1928. dic["RiskFlagName"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  1929. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  1930. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  1931. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  1932. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1933. dic["ParentMakerCode"] = puser.MakerCode;
  1934. dic["ParentRealName"] = puser.RealName;
  1935. string ParentNav = dic["ParentNav"].ToString();
  1936. if (!string.IsNullOrEmpty(ParentNav))
  1937. {
  1938. string[] list = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1939. if (list.Length > 1)
  1940. {
  1941. int TopId = int.Parse(function.CheckInt(list[1]));
  1942. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1943. dic["TopMakerCode"] = tuser.MakerCode;
  1944. dic["TopRealName"] = tuser.RealName;
  1945. }
  1946. }
  1947. }
  1948. return Json(obj);
  1949. }
  1950. #endregion
  1951. #region 认证
  1952. /// <summary>
  1953. /// 认证
  1954. /// </summary>
  1955. /// <returns></returns>
  1956. public string Auth(string Id)
  1957. {
  1958. string[] idlist = Id.Split(new char[] { ',' });
  1959. AddSysLog(Id, "Users", "Auth");
  1960. foreach (string subid in idlist)
  1961. {
  1962. int id = int.Parse(subid);
  1963. Dictionary<string, object> Fields = new Dictionary<string, object>();
  1964. Fields.Add("AuthFlag", 1);
  1965. Fields.Add("AuthDate", DateTime.Now);
  1966. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, id);
  1967. }
  1968. db.SaveChanges();
  1969. return "success";
  1970. }
  1971. #endregion
  1972. #region 修改盟主金额
  1973. public IActionResult ChangeLeaderAmount(string right, int Id = 0)
  1974. {
  1975. ViewBag.RightInfo = RightInfo;
  1976. ViewBag.right = right;
  1977. Users editData = db.Users.FirstOrDefault(m => m.Id == Id) ?? new Users();
  1978. ViewBag.data = editData;
  1979. return View();
  1980. }
  1981. #endregion
  1982. #region 修改盟主金额
  1983. [HttpPost]
  1984. public string ChangeLeaderAmount(Users data, string ChangeAmount, int AmountType, string Note, int Kind)
  1985. {
  1986. int UserId = data.Id;
  1987. var Amount = Convert.ToDecimal(ChangeAmount);
  1988. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  1989. if (account == null)
  1990. {
  1991. account = db.UserAccount.Add(new UserAccount()
  1992. {
  1993. Id = UserId,
  1994. UserId = UserId,
  1995. }).Entity;
  1996. db.SaveChanges();
  1997. }
  1998. //盟主储蓄金
  1999. if (AmountType == 1)
  2000. {
  2001. if ((Kind == 1 || Kind == 3) && Amount > account.LeaderReserve)
  2002. {
  2003. return "盟主储蓄金不足";
  2004. }
  2005. decimal BeforeLeaderReserve = account.LeaderReserve; //变更前盟主储蓄金
  2006. decimal BeforeLeaderBalanceAmount = account.LeaderBalanceAmount; //变更前盟主可提现余额
  2007. int ChangeType = 0;
  2008. if (Kind == 1 && Amount <= account.LeaderReserve)
  2009. {
  2010. account.LeaderReserve -= Amount;
  2011. account.TotalProfit += Amount;
  2012. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统冻结(盟主储蓄金)',Time'" + DateTime.Now + "'");
  2013. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  2014. }
  2015. else if (Kind == 1 && Amount > account.LeaderReserve)
  2016. {
  2017. return "冻结金额大于盟主储蓄金";
  2018. }
  2019. else if (Kind == 2 && Amount <= account.TotalProfit)
  2020. {
  2021. account.LeaderReserve += Amount;
  2022. account.TotalProfit -= Amount;
  2023. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统解冻(盟主储蓄金)',Time'" + DateTime.Now + "'");
  2024. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  2025. }
  2026. else if (Kind == 2 && Amount > account.TotalProfit)
  2027. {
  2028. return "解冻金额大于冻结金额";
  2029. }
  2030. else if (Kind == 3 && Amount <= account.LeaderReserve)
  2031. {
  2032. account.LeaderReserve -= Amount;
  2033. ChangeType = 4;
  2034. decimal AfterLeaderReserve = account.LeaderReserve; //变更后盟主储蓄金
  2035. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后盟主可提现余额
  2036. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  2037. {
  2038. CreateDate = DateTime.Now, //创建时间
  2039. UserId = UserId, //创客
  2040. Remark = "系统扣减(盟主储蓄金)",
  2041. ChangeType = ChangeType,
  2042. BeforeAmt = BeforeLeaderReserve,
  2043. AfterAmt = AfterLeaderReserve,
  2044. ChangeAmt = Amount,
  2045. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  2046. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  2047. }).Entity;
  2048. db.SaveChanges();
  2049. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统扣减(盟主储蓄金)',Time'" + DateTime.Now + "'");
  2050. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  2051. }
  2052. else if (Kind == 3 && Amount > account.LeaderReserve)
  2053. {
  2054. return "扣减金额大于盟主储蓄金";
  2055. }
  2056. else if (Kind == 4)
  2057. {
  2058. account.LeaderReserve += Amount;
  2059. ChangeType = 1;
  2060. decimal AfterLeaderReserve = account.LeaderReserve; //变更后总金额
  2061. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后冻结金额
  2062. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  2063. {
  2064. CreateDate = DateTime.Now, //创建时间
  2065. UserId = UserId, //创客
  2066. Remark = "系统增加(盟主储蓄金)",
  2067. ChangeType = ChangeType,
  2068. BeforeAmt = BeforeLeaderReserve,
  2069. AfterAmt = AfterLeaderReserve,
  2070. ChangeAmt = Amount,
  2071. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  2072. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  2073. }).Entity;
  2074. db.SaveChanges();
  2075. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统增加(盟主储蓄金)',Time'" + DateTime.Now + "'");
  2076. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  2077. }
  2078. AddSysLog(data.Id.ToString(), "Users", "ChangeLeaderAmount");
  2079. db.SaveChanges();
  2080. }
  2081. //盟主可提现余额
  2082. if (AmountType == 2)
  2083. {
  2084. if ((Kind == 1 || Kind == 3) && Amount > account.LeaderBalanceAmount)
  2085. {
  2086. return "盟主可提现余额不足";
  2087. }
  2088. decimal BeforeLeaderReserve = account.LeaderReserve; //变更前盟主储蓄金
  2089. decimal BeforeLeaderBalanceAmount = account.LeaderBalanceAmount; //变更前盟主可提现余额
  2090. int ChangeType = 0;
  2091. if (Kind == 1 && Amount <= account.LeaderReserve)
  2092. {
  2093. account.LeaderBalanceAmount -= Amount;
  2094. account.TotalServiceProfit += Amount;
  2095. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统冻结(盟主可提现余额)',Time'" + DateTime.Now + "'");
  2096. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  2097. }
  2098. else if (Kind == 1 && Amount > account.LeaderBalanceAmount)
  2099. {
  2100. return "冻结金额大于盟主可提现余额";
  2101. }
  2102. else if (Kind == 2 && Amount <= account.TotalServiceProfit)
  2103. {
  2104. account.LeaderBalanceAmount += Amount;
  2105. account.TotalServiceProfit -= Amount;
  2106. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统解冻(盟主可提现余额)',Time'" + DateTime.Now + "'");
  2107. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  2108. }
  2109. else if (Kind == 2 && Amount > account.TotalServiceProfit)
  2110. {
  2111. return "解冻金额大于冻结金额";
  2112. }
  2113. else if (Kind == 3 && Amount <= account.LeaderBalanceAmount)
  2114. {
  2115. account.LeaderBalanceAmount -= Amount;
  2116. ChangeType = 6;
  2117. decimal AfterLeaderReserve = account.LeaderReserve; //变更后总金额
  2118. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后冻结金额
  2119. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  2120. {
  2121. CreateDate = DateTime.Now, //创建时间
  2122. UserId = UserId, //创客
  2123. Remark = "系统扣减(盟主可提现余额)",
  2124. ChangeType = ChangeType,
  2125. BeforeAmt = BeforeLeaderBalanceAmount,
  2126. AfterAmt = AfterLeaderBalanceAmount,
  2127. ChangeAmt = Amount,
  2128. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  2129. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  2130. }).Entity;
  2131. db.SaveChanges();
  2132. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统扣减(盟主可提现余额)',Time'" + DateTime.Now + "'");
  2133. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  2134. }
  2135. else if (Kind == 3 && Amount > account.LeaderBalanceAmount)
  2136. {
  2137. return "扣减金额大于盟主可提现余额";
  2138. }
  2139. else if (Kind == 4)
  2140. {
  2141. account.LeaderBalanceAmount += Amount;
  2142. ChangeType = 5;
  2143. decimal AfterLeaderReserve = account.LeaderReserve; //变更后总金额
  2144. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后冻结金额
  2145. var query = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  2146. {
  2147. CreateDate = DateTime.Now, //创建时间
  2148. UserId = UserId, //创客
  2149. Remark = "系统增加(盟主可提现余额)",
  2150. ChangeType = ChangeType,
  2151. BeforeAmt = BeforeLeaderBalanceAmount,
  2152. AfterAmt = AfterLeaderBalanceAmount,
  2153. ChangeAmt = Amount,
  2154. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  2155. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  2156. }).Entity;
  2157. db.SaveChanges();
  2158. string text = string.Format("修改盟主金额,操作人: '" + SysUserName + "_" + SysRealName + "',操作类型: '系统增加(盟主可提现余额)',Time'" + DateTime.Now + "'");
  2159. function.WriteLog(text, "ChangeLeaderAmount");//修改盟主金额
  2160. }
  2161. AddSysLog(data.Id.ToString(), "Users", "ChangeLeaderAmount");
  2162. db.SaveChanges();
  2163. }
  2164. return "success";
  2165. }
  2166. #endregion
  2167. #region 伞下创客列表
  2168. /// <summary>
  2169. /// 根据条件查询伞下创客列表
  2170. /// </summary>
  2171. /// <returns></returns>
  2172. public IActionResult SanIndex(Users data, string right)
  2173. {
  2174. ViewBag.RightInfo = RightInfo;
  2175. ViewBag.right = right;
  2176. List<Users> TopUsers = db.Users.Where(m => m.ParentUserId == 0).ToList();
  2177. ViewBag.TopUsers = TopUsers;
  2178. List<UserLevelSet> Levels = db.UserLevelSet.OrderBy(m => m.Id).ToList();
  2179. ViewBag.Levels = Levels;
  2180. return View();
  2181. }
  2182. #endregion
  2183. #region 根据条件查询伞下创客列表
  2184. /// <summary>
  2185. /// 伞下创客列表
  2186. /// </summary>
  2187. /// <returns></returns>
  2188. 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)
  2189. {
  2190. Dictionary<string, string> Fields = new Dictionary<string, string>();
  2191. if (ShowFlag == 0)
  2192. {
  2193. Dictionary<string, object> objs = new Dictionary<string, object>();
  2194. return Json(objs);
  2195. }
  2196. string condition = " and Status>-1";
  2197. //创客编号
  2198. if (!string.IsNullOrEmpty(MakerCode))
  2199. {
  2200. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  2201. if (userForMakerCode.UserId == 0)
  2202. {
  2203. return Json(new AppResultJson() { Status = "-1", Info = "未找到创客" + MakerCode + "关联数据", Data = "" });
  2204. }
  2205. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  2206. if (user.Id == 0)
  2207. {
  2208. return Json(new AppResultJson() { Status = "-1", Info = "创客" + MakerCode + "不存在", Data = "" });
  2209. }
  2210. condition += " and ParentNav like '%," + user.Id + ",%'";
  2211. }
  2212. if (!string.IsNullOrEmpty(IsLeader))
  2213. {
  2214. condition += " and LeaderLevel=" + IsLeader;
  2215. }
  2216. if (!string.IsNullOrEmpty(UserYsLevel))
  2217. {
  2218. var UserIds = "";
  2219. var Rank = int.Parse(UserYsLevel);
  2220. var list = db.UserRankWhite.Where(m => m.Status > -1 && m.Rank == Rank).ToList();
  2221. foreach (var item in list)
  2222. {
  2223. UserIds += item.UserId + ",";
  2224. }
  2225. UserIds = UserIds.TrimEnd(',');
  2226. condition += " and Id IN(" + UserIds + ")";
  2227. }
  2228. if (!string.IsNullOrEmpty(UserLevel))
  2229. {
  2230. condition += " and UserLevel=" + UserLevel;
  2231. }
  2232. if (!string.IsNullOrEmpty(IsOp))
  2233. {
  2234. var UserIds = "";
  2235. DataTable dt = CustomerSqlConn.dtable("SELECT UserId FROM SysAdmin WHERE Status>-1 and Sort>0 and QueryCount>0 and AdminName!='admin'", OpConn);
  2236. foreach (DataRow item in dt.Rows)
  2237. {
  2238. UserIds += item["UserId"].ToString() + ",";
  2239. }
  2240. UserIds = UserIds.TrimEnd(',');
  2241. if (IsOp == "1")
  2242. {
  2243. condition += " and Id IN(" + UserIds + ")";
  2244. }
  2245. if (IsOp == "2")
  2246. {
  2247. condition += " and Id NOT IN(" + UserIds + ")";
  2248. }
  2249. }
  2250. if (!string.IsNullOrEmpty(CreateDateData))
  2251. {
  2252. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  2253. string start = datelist[0];
  2254. string end = datelist[1];
  2255. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  2256. }
  2257. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Users", Fields, "Id desc", "True", page, limit, condition);
  2258. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  2259. foreach (Dictionary<string, object> dic in diclist)
  2260. {
  2261. dic["AuthFlagName"] = dic["AuthFlag"].ToString() == "1" ? "已实名" : "未实名";
  2262. dic["RiskFlagName"] = dic["RiskFlag"].ToString() == "1" ? "已风控" : "未风控";
  2263. dic["UserLevel"] = RelationClass.GetUserLevelSetInfo(int.Parse(dic["UserLevel"].ToString()));
  2264. int UserId = int.Parse(dic["Id"].ToString());
  2265. int ParentUserId = int.Parse(dic["ParentUserId"].ToString());
  2266. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  2267. dic["ParentMakerCode"] = puser.MakerCode;
  2268. dic["ParentRealName"] = puser.RealName;
  2269. var userRankWhite = db.UserRankWhite.FirstOrDefault(m => m.UserId == UserId) ?? new UserRankWhite();
  2270. dic["UserYsLevel"] = RelationClass.GetUserLevelSetInfo(userRankWhite.Rank);
  2271. int LeaderLevel = int.Parse(dic["LeaderLevel"].ToString());
  2272. if (LeaderLevel == 1)
  2273. {
  2274. dic["IsLeader"] = "小盟主";
  2275. }
  2276. else if (LeaderLevel == 2)
  2277. {
  2278. dic["IsLeader"] = "大盟主";
  2279. }
  2280. else
  2281. {
  2282. dic["IsLeader"] = "";
  2283. }
  2284. var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.Status > -1 && m.Sort > 0 && m.QueryCount > 0 && m.AdminName != "admin" && m.UserId == UserId) ?? new OpModels.SysAdmin();
  2285. if (sysAdmin.Id > 0)
  2286. {
  2287. dic["IsOp"] = sysAdmin.OpCode;
  2288. }
  2289. else
  2290. {
  2291. dic["IsOp"] = "";
  2292. }
  2293. dic["MerchantType"] = RelationClassForConst.GetMerchantTypeInfo(int.Parse(dic["MerchantType"].ToString()));
  2294. }
  2295. return Json(obj);
  2296. }
  2297. #endregion
  2298. #region 重置小分仓额度
  2299. /// <summary>
  2300. /// 重置小分仓额度
  2301. /// </summary>
  2302. /// <returns></returns>
  2303. public string SycnAmountData(int Id = 0)
  2304. {
  2305. if (Id > 0)
  2306. {
  2307. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == Id) ?? new UserAccount();
  2308. RedisDbconn.Instance.AddList("ResetSmallStoreByUserIdQueue", userAccount.Id);
  2309. }
  2310. AddSysLog(Id, "UserAccount", "SycnAmountData");
  2311. db.SaveChanges();
  2312. return "success";
  2313. }
  2314. #endregion
  2315. #region 批量查询创客信息
  2316. public IActionResult BatchSeeUserInfo(string right)
  2317. {
  2318. ViewBag.RightInfo = RightInfo;
  2319. ViewBag.right = right;
  2320. return View();
  2321. }
  2322. #endregion
  2323. #region 批量查询创客信息
  2324. public JsonResult BatchSeeUserInfoDo(string PosSns, string MerNos, int page = 1, int limit = 30)
  2325. {
  2326. var error = "";
  2327. //实际押金
  2328. Dictionary<string, object> errorInfo = new Dictionary<string, object>();
  2329. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  2330. if (string.IsNullOrEmpty(PosSns) && string.IsNullOrEmpty(MerNos))
  2331. {
  2332. Dictionary<string, object> objs = new Dictionary<string, object>();
  2333. return Json(objs);
  2334. }
  2335. else if (!string.IsNullOrEmpty(PosSns) && !string.IsNullOrEmpty(MerNos))
  2336. {
  2337. Dictionary<string, object> objs = new Dictionary<string, object>();
  2338. return Json(objs);
  2339. }
  2340. else
  2341. {
  2342. if (!string.IsNullOrEmpty(PosSns))
  2343. {
  2344. string[] PosSnsList = PosSns.Replace("\r", "").Replace("\n", ",").Replace(" ", ",").Split(',');
  2345. foreach (string PosSn in PosSnsList)
  2346. {
  2347. string SeoKeyword = "0";
  2348. Dictionary<string, object> data = new Dictionary<string, object>();
  2349. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
  2350. if (pos.Id > 0)
  2351. {
  2352. // error += "机具" + PosSn + "不存在" + '\n';
  2353. // }
  2354. // else
  2355. // {
  2356. var TopMakerCode = ""; //顶级创客编号
  2357. var TopRealName = ""; //顶级创客名称
  2358. var SecondMakerCode = ""; //次顶级创客编号
  2359. var SecondRealName = ""; //次顶级创客姓名
  2360. var ThirdMakerCode = ""; //次次顶级创客编号
  2361. var ThirdRealName = ""; //次次顶级创客姓名
  2362. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  2363. var brand = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
  2364. // if (brand.Id > 0 && brand.SingleDepositApi == 0 && !string.IsNullOrEmpty(SeoKeyword))
  2365. if (brand.Id > 0 && brand.NoticeMoneyUnit == 2 && !string.IsNullOrEmpty(pos.SeoKeyword))
  2366. {
  2367. SeoKeyword = (decimal.Parse(pos.SeoKeyword) / 100).ToString();
  2368. }
  2369. else
  2370. {
  2371. SeoKeyword = pos.SeoKeyword;
  2372. }
  2373. var user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2374. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == user.Id) ?? new UserAccount();
  2375. if (!string.IsNullOrEmpty(user.ParentNav))
  2376. {
  2377. string[] ParentNavList = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2378. var topUserInfo = new Users();
  2379. var secondUserInfo = new Users();
  2380. var thirdUserInfo = new Users();
  2381. if (ParentNavList.Length > 1)
  2382. {
  2383. topUserInfo = db.Users.FirstOrDefault(m => m.Id == (int.Parse(ParentNavList[1]))) ?? new Users();
  2384. if (ParentNavList.Length > 2)
  2385. {
  2386. secondUserInfo = db.Users.FirstOrDefault(m => m.Id == (int.Parse(ParentNavList[2]))) ?? new Users();
  2387. if (ParentNavList.Length > 3)
  2388. {
  2389. thirdUserInfo = db.Users.FirstOrDefault(m => m.Id == (int.Parse(ParentNavList[3]))) ?? new Users();
  2390. }
  2391. }
  2392. }
  2393. else
  2394. {
  2395. topUserInfo = db.Users.FirstOrDefault(m => m.Id == (int.Parse(ParentNavList[0]))) ?? new Users();
  2396. }
  2397. TopMakerCode = topUserInfo.MakerCode; //顶级创客编号
  2398. TopRealName = topUserInfo.RealName; //顶级创客名称
  2399. SecondMakerCode = secondUserInfo.MakerCode; //次顶级创客编号
  2400. SecondRealName = secondUserInfo.RealName; //次顶级创客姓名
  2401. ThirdMakerCode = thirdUserInfo.MakerCode; //次次顶级创客编号
  2402. ThirdRealName = thirdUserInfo.RealName; //次次顶级创客姓名
  2403. }
  2404. data["BrandName"] = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId).Name; //机具类型
  2405. data["BindingTime"] = pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss"); //绑定时间
  2406. data["ActivationTime"] = pos.ActivationTime == null ? "" : pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss"); //激活时间
  2407. data["MerchantName"] = mer.MerchantName; //商户姓名
  2408. // data["MerchantName"] = mer.MerchantName + " " + mer.MerRealName; //商户姓名/真实姓名
  2409. data["PosSn"] = pos.PosSn; //机具Sn
  2410. data["MerNo"] = mer.KqMerNo; //商户编号
  2411. data["PosFee"] = SeoKeyword; //服务费
  2412. data["userInfo"] = user.Id > 0 ? user.MakerCode + "_" + user.RealName : ""; //创客信息
  2413. // data["MakerCode"] = user.MakerCode; //创客编号
  2414. // data["RealName"] = user.RealName; //创客姓名
  2415. data["Mobile"] = user.Mobile; //创客手机号
  2416. data["Balance"] = userAccount.BalanceAmount; //创客账户余额
  2417. data["TopMakerCode"] = TopMakerCode; //顶级创客编号
  2418. data["TopRealName"] = TopRealName; //顶级创客名称
  2419. data["SecondMakerCode"] = SecondMakerCode; //次顶级创客编号
  2420. data["SecondRealName"] = SecondRealName; //次顶级创客姓名
  2421. data["ThirdMakerCode"] = ThirdMakerCode; //次次顶级创客编号
  2422. data["ThirdRealName"] = ThirdRealName; //次次顶级创客姓名
  2423. dataList.Add(data);
  2424. }
  2425. }
  2426. }
  2427. if (!string.IsNullOrEmpty(MerNos))
  2428. {
  2429. string[] MerNosList = MerNos.Replace("\r", "").Replace("\n", ",").Replace(" ", ",").Split(',');
  2430. foreach (string MerNo in MerNosList)
  2431. {
  2432. string SeoKeyword = "0";
  2433. Dictionary<string, object> data = new Dictionary<string, object>();
  2434. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  2435. if (mer.Id > 0)
  2436. {
  2437. // error += "商户" + MerNo + "不存在" + '\n';
  2438. // }
  2439. // else
  2440. // {
  2441. var TopMakerCode = ""; //顶级创客编号
  2442. var TopRealName = ""; //顶级创客名称
  2443. var SecondMakerCode = ""; //次顶级创客编号
  2444. var SecondRealName = ""; //次顶级创客姓名
  2445. var ThirdMakerCode = ""; //次次顶级创客编号
  2446. var ThirdRealName = ""; //次次顶级创客姓名
  2447. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == mer.KqSnNo) ?? new PosMachinesTwo();
  2448. var brand = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
  2449. // if (brand.Id > 0 && brand.SingleDepositApi == 0 && !string.IsNullOrEmpty(SeoKeyword))
  2450. if (brand.Id > 0 && brand.NoticeMoneyUnit == 2 && !string.IsNullOrEmpty(pos.SeoKeyword))
  2451. {
  2452. SeoKeyword = (decimal.Parse(pos.SeoKeyword) / 100).ToString();
  2453. }
  2454. else
  2455. {
  2456. SeoKeyword = pos.SeoKeyword;
  2457. }
  2458. var user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2459. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == user.Id) ?? new UserAccount();
  2460. if (!string.IsNullOrEmpty(user.ParentNav))
  2461. {
  2462. string[] ParentNavList = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2463. var topUserInfo = new Users();
  2464. var secondUserInfo = new Users();
  2465. var thirdUserInfo = new Users();
  2466. if (ParentNavList.Length > 1)
  2467. {
  2468. topUserInfo = db.Users.FirstOrDefault(m => m.Id == (int.Parse(ParentNavList[1]))) ?? new Users();
  2469. if (ParentNavList.Length > 2)
  2470. {
  2471. secondUserInfo = db.Users.FirstOrDefault(m => m.Id == (int.Parse(ParentNavList[2]))) ?? new Users();
  2472. if (ParentNavList.Length > 3)
  2473. {
  2474. thirdUserInfo = db.Users.FirstOrDefault(m => m.Id == (int.Parse(ParentNavList[3]))) ?? new Users();
  2475. }
  2476. }
  2477. }
  2478. else
  2479. {
  2480. topUserInfo = db.Users.FirstOrDefault(m => m.Id == (int.Parse(ParentNavList[0]))) ?? new Users();
  2481. }
  2482. TopMakerCode = topUserInfo.MakerCode; //顶级创客编号
  2483. TopRealName = topUserInfo.RealName; //顶级创客名称
  2484. SecondMakerCode = secondUserInfo.MakerCode; //次顶级创客编号
  2485. SecondRealName = secondUserInfo.RealName; //次顶级创客姓名
  2486. ThirdMakerCode = thirdUserInfo.MakerCode; //次次顶级创客编号
  2487. ThirdRealName = thirdUserInfo.RealName; //次次顶级创客姓名
  2488. }
  2489. data["BrandName"] = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId).Name; //机具类型
  2490. data["BindingTime"] = pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss"); //绑定时间
  2491. data["ActivationTime"] = pos.ActivationTime == null ? "" : pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss"); //激活时间
  2492. data["MerchantName"] = mer.MerchantName; //商户姓名
  2493. // data["MerchantName"] = mer.MerchantName + " " + mer.MerRealName; //商户姓名/真实姓名
  2494. data["PosSn"] = pos.PosSn; //机具Sn
  2495. data["MerNo"] = mer.KqMerNo; //商户编号
  2496. data["PosFee"] = SeoKeyword; //服务费
  2497. data["userInfo"] = user.Id > 0 ? user.MakerCode + "_" + user.RealName : ""; //创客信息
  2498. // data["MakerCode"] = user.MakerCode; //创客编号
  2499. // data["RealName"] = user.RealName; //创客姓名
  2500. data["Mobile"] = user.Mobile; //创客手机号
  2501. data["Balance"] = userAccount.BalanceAmount; //创客账户余额
  2502. data["TopMakerCode"] = TopMakerCode; //顶级创客编号
  2503. data["TopRealName"] = TopRealName; //顶级创客名称
  2504. data["SecondMakerCode"] = SecondMakerCode; //次顶级创客编号
  2505. data["SecondRealName"] = SecondRealName; //次顶级创客姓名
  2506. data["ThirdMakerCode"] = ThirdMakerCode; //次次顶级创客编号
  2507. data["ThirdRealName"] = ThirdRealName; //次次顶级创客姓名
  2508. dataList.Add(data);
  2509. }
  2510. }
  2511. }
  2512. }
  2513. Dictionary<string, object> obj = new Dictionary<string, object>();
  2514. obj.Add("code", 0);
  2515. obj.Add("msg", "");
  2516. obj.Add("count", dataList.Count);
  2517. obj.Add("data", dataList);
  2518. return Json(obj);
  2519. }
  2520. #endregion
  2521. #region 批量查询创客信息快捷导出Excel
  2522. public IActionResult ExportBatchSeeUserInfoExcel(string right)
  2523. {
  2524. ViewBag.RightInfo = RightInfo;
  2525. ViewBag.right = right;
  2526. return View();
  2527. }
  2528. [HttpPost]
  2529. public string ExportBatchSeeUserInfoExcelDo(string PosSns, string MerNos)
  2530. {
  2531. var sql = "";
  2532. if (string.IsNullOrEmpty(PosSns) && string.IsNullOrEmpty(MerNos))
  2533. {
  2534. return "请输入查询内容";
  2535. }
  2536. else if (!string.IsNullOrEmpty(PosSns) && !string.IsNullOrEmpty(MerNos))
  2537. {
  2538. return "不能同时输入机具Sn和商户编号";
  2539. }
  2540. else
  2541. {
  2542. if (!string.IsNullOrEmpty(PosSns))
  2543. {
  2544. var posIds = "";
  2545. string[] PosSnsList = PosSns.Replace("\r", "").Replace("\n", ",").Replace(" ", ",").Split(',');
  2546. foreach (string PosSn in PosSnsList)
  2547. {
  2548. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
  2549. posIds += pos.Id + ",";
  2550. }
  2551. posIds = posIds.TrimEnd(',');
  2552. sql = "SELECT i.BrandName '机具类型',i.PosSn '机具SN',j.KqMerNo '商编',j.MerchantName '商户名称',(CASE WHEN i.posfee IS NULL THEN 0 ELSE i.posfee END) '服务费',DATE_FORMAT(i.BindingTime,'%Y-%m-%d %H:%i:%s') '绑定时间',DATE_FORMAT(i.ActivationTime,'%Y-%m-%d %H:%i:%s') '激活时间',i.userInfo '创客信息',i.Mobile '创客手机号',i.BalanceAmount '创客账户余额',i.topMakerCode '顶级创客编号',i.topRealname '顶级姓名',i.secondMakerCode '次顶级创客编号',i.secondRealname '次顶级姓名',i.thirdMakerCode '次次顶级创客编号',i.thirdRealname '次次顶级姓名' FROM(SELECT g.*,h.MakerCode thirdMakerCode,h.Realname thirdRealname FROM (SELECT e.*,f.MakerCode secondMakerCode,f.Realname secondRealname FROM(SELECT c.*,d.MakerCode topMakerCode,d.Realname topRealname FROM(SELECT a.*,c1.NAME BrandName,(CASE WHEN a.BrandId not in(2,7,10,11) THEN ROUND(CAST(a.SeoKeyword AS DECIMAL)/100, 2) ELSE a.SeoKeyword end) posfee,b.Id useId,CONCAT(b.MakerCode,'_',b.RealName) userInfo,b.Mobile,c2.BalanceAmount,b.RealName uRealName, SUBSTRING_INDEX(SUBSTRING_INDEX(b.ParentNav,',',4),',',-1) topId,SUBSTRING_INDEX(SUBSTRING_INDEX(b.ParentNav,',',6),',',-1) secondId,SUBSTRING_INDEX(SUBSTRING_INDEX(b.ParentNav,',',8),',',-1) thirdId FROM PosMachinesTwo a LEFT JOIN Users b ON a.BuyUserId=b.Id LEFT JOIN UserAccount c2 ON a.BuyUserId=c2.Id LEFT JOIN KqProducts c1 ON a.BrandId=c1.Id WHERE a.Id in(" + posIds + "))c LEFT JOIN Users d ON c.topId=d.Id) e LEFT JOIN Users f ON e.secondId=f.Id) g LEFT JOIN Users h ON g.thirdId=h.Id) i LEFT JOIN PosMerchantInfo j ON i.BindMerchantId=j.Id";
  2553. }
  2554. if (!string.IsNullOrEmpty(MerNos))
  2555. {
  2556. var merIds = "";
  2557. string[] MerNosList = MerNos.Replace("\r", "").Replace("\n", ",").Replace(" ", ",").Split(',');
  2558. foreach (string MerNo in MerNosList)
  2559. {
  2560. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  2561. merIds += mer.Id + ",";
  2562. }
  2563. merIds = merIds.TrimEnd(',');
  2564. sql = "SELECT i.BrandName '机具类型',i.KqSnNo '机具SN',i.KqMerNo '商编',i.MerchantName '商户名称',(CASE WHEN i.SeoKeyword IS NULL THEN 0 ELSE i.SeoKeyword END) '服务费',DATE_FORMAT(i.BindingTime,'%Y-%m-%d %H:%i:%s') '绑定时间',DATE_FORMAT(i.ActivationTime,'%Y-%m-%d %H:%i:%s') '激活时间',i.userInfo '创客信息',i.Mobile '创客手机号',i.BalanceAmount '创客账户余额',i.topMakerCode '顶级创客编号',i.topRealname '顶级姓名',i.secondMakerCode '次顶级创客编号',i.secondRealname '次顶级姓名',j.MakerCode '次次顶级创客编号',j.Realname '次次顶级姓名' FROM(SELECT g.*,h.MakerCode secondMakerCode,h.Realname secondRealname FROM(SELECT e.*,f.MakerCode topMakerCode,f.RealName topRealName FROM(SELECT c.*,CONCAT(d.MakerCode,'_',d.RealName) userInfo,d.Mobile,SUBSTRING_INDEX(SUBSTRING_INDEX(d.ParentNav,',',4),',',-1) topId,SUBSTRING_INDEX(SUBSTRING_INDEX(d.ParentNav,',',6),',',-1) secondId,SUBSTRING_INDEX(SUBSTRING_INDEX(d.ParentNav,',',8),',',-1) thirdId FROM(SELECT a.KqMerNo,a.KqSnNo,a.MerchantName,(CASE WHEN b.BrandId not in(2,7,10,11) THEN ROUND(CAST(b.SeoKeyword AS DECIMAL)/100, 2) ELSE b.SeoKeyword end) SeoKeyword,b.BindingTime,b.ActivationTime,b.BuyUserId,c1.Name BrandName,c2.BalanceAmount FROM PosMerchantInfo a LEFT JOIN PosMachinesTwo b ON a.KqSnNo=b.PosSn LEFT JOIN UserAccount c2 ON b.BuyUserId=c2.Id LEFT JOIN KqProducts c1 ON b.BrandId=c1.Id WHERE a.Id in(" + merIds + "))c LEFT JOIN Users d ON c.BuyUserId=d.Id) e LEFT JOIN Users f ON e.topId=f.Id) g LEFT JOIN Users h ON g.secondId=h.Id) i LEFT JOIN Users j ON i.thirdId=j.Id";
  2565. }
  2566. }
  2567. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
  2568. var FileName = "批量查询创客信息" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2569. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  2570. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  2571. return "success";
  2572. }
  2573. #endregion
  2574. #region 注销时间提前
  2575. public string SetLogoutDate(int Id)
  2576. {
  2577. Dictionary<string, object> Fields = new Dictionary<string, object>();
  2578. Fields.Add("LogOutDate", DateTime.Now.AddDays(-31));
  2579. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Users", Fields, Id);
  2580. AddSysLog(Id, "Users", "SetLogoutDate");
  2581. return "success";
  2582. }
  2583. #endregion
  2584. }
  2585. }