UsersController.cs 133 KB

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