UsersController.cs 79 KB

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