UsersController.cs 104 KB

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