UserCashRecordController.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  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 UserCashRecordController : BaseController
  24. {
  25. public UserCashRecordController(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(UserCashRecord data, string right)
  35. {
  36. ViewBag.RightInfo = RightInfo;
  37. ViewBag.right = right;
  38. string Condition = "";
  39. Condition += "CashOrderNo:\"" + data.CashOrderNo + "\",";
  40. Condition += "TradeType:\"" + data.TradeType + "\",";
  41. if (!string.IsNullOrEmpty(Condition))
  42. {
  43. Condition = Condition.TrimEnd(',');
  44. Condition = ", where: {" + Condition + "}";
  45. }
  46. ViewBag.Condition = Condition;
  47. return View();
  48. }
  49. #endregion
  50. #region 根据条件查询提现记录列表
  51. /// <summary>
  52. /// 提现记录列表
  53. /// </summary>
  54. /// <returns></returns>
  55. public JsonResult IndexData(UserCashRecord data, string MakerCode, string RealName, string StatusSelect, string QueryCountSelect, string CreateDateData, int page = 1, int limit = 30)
  56. {
  57. Dictionary<string, string> Fields = new Dictionary<string, string>();
  58. Fields.Add("CashOrderNo", "1"); //提现单号
  59. Fields.Add("TradeType", "0"); //交易类型
  60. string condition = " and Status>-1 and TradeType<3";
  61. //创客编号
  62. if (!string.IsNullOrEmpty(MakerCode))
  63. {
  64. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  65. }
  66. //创客名称
  67. if (!string.IsNullOrEmpty(RealName))
  68. {
  69. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  70. // condition += " and UserId in (select Id from Users where RealName='" + RealName + "')";
  71. }
  72. //提现状态
  73. if (!string.IsNullOrEmpty(StatusSelect))
  74. {
  75. condition += " and Status=" + StatusSelect;
  76. }
  77. if (!string.IsNullOrEmpty(data.CashOrderNo))
  78. {
  79. condition += " and CashOrderNo='" + data.CashOrderNo + "'";
  80. }
  81. if (data.TradeType > 0)
  82. {
  83. condition += " and TradeType=" + data.TradeType;
  84. }
  85. //提交到代付状态
  86. if (!string.IsNullOrEmpty(QueryCountSelect))
  87. {
  88. condition += " and QueryCount=" + QueryCountSelect;
  89. }
  90. if (!string.IsNullOrEmpty(CreateDateData))
  91. {
  92. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  93. string start = datelist[0];
  94. string end = datelist[1];
  95. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  96. }
  97. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("UserCashRecord", Fields, "Id desc", "0", page, limit, condition);
  98. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  99. foreach (Dictionary<string, object> dic in diclist)
  100. {
  101. int UserId = int.Parse(dic["UserId"].ToString());
  102. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  103. dic["MakerCode"] = user.MakerCode;
  104. dic["RealName"] = user.RealName;
  105. dic["TradeType"] = RelationClassForConst.GetTradeTypeInfo(int.Parse(dic["TradeType"].ToString()));
  106. int Status = int.Parse(dic["Status"].ToString());
  107. if (Status == 0) dic["StatusName"] = "处理中";
  108. if (Status == 1) dic["StatusName"] = "成功";
  109. if (Status == 2) dic["StatusName"] = "失败";
  110. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  111. if (QueryCount == 0) dic["LockName"] = "待提交";
  112. if (QueryCount == 1) dic["LockName"] = "已提交";
  113. }
  114. Dictionary<string, object> other = new Dictionary<string, object>();
  115. string WaitAmount = "0.00";//待处理总金额
  116. string SuccessAmount = "0.00";//提现成功总金额
  117. string FailAmount = "0.00";//提现失败总金额
  118. DataTable dt = OtherMySqlConn.dtable("select sum(TradeAmount) from UserCashRecord where Status=0" + condition);
  119. if (dt.Rows.Count > 0)
  120. {
  121. WaitAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  122. }
  123. dt = OtherMySqlConn.dtable("select sum(TradeAmount) from UserCashRecord where Status=1" + condition);
  124. if (dt.Rows.Count > 0)
  125. {
  126. SuccessAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  127. }
  128. dt = OtherMySqlConn.dtable("select sum(TradeAmount) from UserCashRecord where Status=2" + condition);
  129. if (dt.Rows.Count > 0)
  130. {
  131. FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  132. }
  133. other.Add("WaitAmount", WaitAmount);
  134. other.Add("SuccessAmount", SuccessAmount);
  135. other.Add("FailAmount", FailAmount);
  136. obj.Add("other", other);
  137. return Json(obj);
  138. }
  139. #endregion
  140. #region 增加提现记录
  141. /// <summary>
  142. /// 增加或修改提现记录信息
  143. /// </summary>
  144. /// <returns></returns>
  145. public IActionResult Add(string right)
  146. {
  147. ViewBag.RightInfo = RightInfo;
  148. ViewBag.right = right;
  149. return View();
  150. }
  151. #endregion
  152. #region 增加提现记录
  153. /// <summary>
  154. /// 增加或修改提现记录信息
  155. /// </summary>
  156. /// <returns></returns>
  157. [HttpPost]
  158. public string Add(UserCashRecord data)
  159. {
  160. Dictionary<string, object> Fields = new Dictionary<string, object>();
  161. Fields.Add("Remark", data.Remark); //备注
  162. Fields.Add("SeoTitle", data.SeoTitle);
  163. Fields.Add("SeoKeyword", data.SeoKeyword);
  164. Fields.Add("SeoDescription", data.SeoDescription);
  165. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("UserCashRecord", Fields, 0);
  166. AddSysLog(data.Id.ToString(), "UserCashRecord", "add");
  167. db.SaveChanges();
  168. return "success";
  169. }
  170. #endregion
  171. #region 修改提现记录
  172. /// <summary>
  173. /// 增加或修改提现记录信息
  174. /// </summary>
  175. /// <returns></returns>
  176. public IActionResult Edit(string right, int Id = 0)
  177. {
  178. ViewBag.RightInfo = RightInfo;
  179. ViewBag.right = right;
  180. UserCashRecord editData = db.UserCashRecord.FirstOrDefault(m => m.Id == Id) ?? new UserCashRecord();
  181. ViewBag.data = editData;
  182. return View();
  183. }
  184. #endregion
  185. #region 修改提现记录
  186. /// <summary>
  187. /// 增加或修改提现记录信息
  188. /// </summary>
  189. /// <returns></returns>
  190. [HttpPost]
  191. public string Edit(UserCashRecord data)
  192. {
  193. Dictionary<string, object> Fields = new Dictionary<string, object>();
  194. Fields.Add("Remark", data.Remark); //备注
  195. Fields.Add("SeoTitle", data.SeoTitle);
  196. Fields.Add("SeoKeyword", data.SeoKeyword);
  197. Fields.Add("SeoDescription", data.SeoDescription);
  198. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserCashRecord", Fields, data.Id);
  199. AddSysLog(data.Id.ToString(), "UserCashRecord", "update");
  200. db.SaveChanges();
  201. return "success";
  202. }
  203. #endregion
  204. #region 删除提现记录信息
  205. /// <summary>
  206. /// 删除提现记录信息
  207. /// </summary>
  208. /// <returns></returns>
  209. public string Delete(string Id)
  210. {
  211. string[] idlist = Id.Split(new char[] { ',' });
  212. AddSysLog(Id, "UserCashRecord", "del");
  213. foreach (string subid in idlist)
  214. {
  215. int id = int.Parse(subid);
  216. Dictionary<string, object> Fields = new Dictionary<string, object>();
  217. Fields.Add("Status", -1);
  218. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserCashRecord", Fields, id);
  219. }
  220. db.SaveChanges();
  221. return "success";
  222. }
  223. #endregion
  224. #region 开启
  225. /// <summary>
  226. /// 开启
  227. /// </summary>
  228. /// <returns></returns>
  229. public string Open(string Id)
  230. {
  231. string[] idlist = Id.Split(new char[] { ',' });
  232. AddSysLog(Id, "UserCashRecord", "open");
  233. foreach (string subid in idlist)
  234. {
  235. int id = int.Parse(subid);
  236. Dictionary<string, object> Fields = new Dictionary<string, object>();
  237. Fields.Add("Status", 1);
  238. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserCashRecord", Fields, id);
  239. }
  240. db.SaveChanges();
  241. return "success";
  242. }
  243. #endregion
  244. #region 关闭
  245. /// <summary>
  246. /// 关闭
  247. /// </summary>
  248. /// <returns></returns>
  249. public string Close(string Id)
  250. {
  251. string[] idlist = Id.Split(new char[] { ',' });
  252. AddSysLog(Id, "UserCashRecord", "close");
  253. foreach (string subid in idlist)
  254. {
  255. int id = int.Parse(subid);
  256. Dictionary<string, object> Fields = new Dictionary<string, object>();
  257. Fields.Add("Status", 0);
  258. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserCashRecord", Fields, id);
  259. }
  260. db.SaveChanges();
  261. return "success";
  262. }
  263. #endregion
  264. #region 排序
  265. /// <summary>
  266. /// 排序
  267. /// </summary>
  268. /// <param name="Id"></param>
  269. public string Sort(int Id, int Sort)
  270. {
  271. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("UserCashRecord", Sort, Id);
  272. AddSysLog(Id.ToString(), "UserCashRecord", "sort");
  273. return "success";
  274. }
  275. #endregion
  276. #region 导入数据
  277. public IActionResult Import(string right)
  278. {
  279. ViewBag.RightInfo = RightInfo;
  280. ViewBag.right = right;
  281. return View();
  282. }
  283. /// <summary>
  284. /// 导入数据
  285. /// </summary>
  286. /// <param name="ExcelData"></param>
  287. [HttpPost]
  288. public string ImportPost(string ExcelPath)
  289. {
  290. string key = function.MD5_16(Guid.NewGuid().ToString());
  291. RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#UserCashRecord#cut#" + key + "#cut#" + SysUserName);
  292. return "success|" + key;
  293. }
  294. public string CheckImport(string key)
  295. {
  296. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  297. if (!string.IsNullOrEmpty(result))
  298. {
  299. string[] datalist = result.Split('|');
  300. if (datalist[0] == "success")
  301. {
  302. return result;
  303. }
  304. return datalist[0];
  305. }
  306. return "0";
  307. }
  308. #endregion
  309. #region 导出Excel
  310. /// <summary>
  311. /// 导出Excel
  312. /// </summary>
  313. /// <returns></returns>
  314. public JsonResult ExportExcel(UserCashRecord data, string MakerCode, string RealName, string StatusSelect, string PayStatus)
  315. {
  316. Dictionary<string, string> Fields = new Dictionary<string, string>();
  317. Fields.Add("CashOrderNo", "1"); //提现单号
  318. Fields.Add("CreateDate", "3"); //创建时间
  319. Fields.Add("TradeType", "0"); //交易类型
  320. string condition = " and Status>-1 and TradeType<3";
  321. //创客编号
  322. if (!string.IsNullOrEmpty(MakerCode))
  323. {
  324. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  325. }
  326. //创客名称
  327. if (!string.IsNullOrEmpty(RealName))
  328. {
  329. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  330. }
  331. //提现状态
  332. if (!string.IsNullOrEmpty(StatusSelect))
  333. {
  334. condition += " and Status=" + StatusSelect;
  335. }
  336. //提交到代付状态
  337. if (!string.IsNullOrEmpty(PayStatus))
  338. {
  339. int QueryCount = int.Parse(function.CheckInt(PayStatus));
  340. if (QueryCount == 2)
  341. {
  342. QueryCount = 0;
  343. }
  344. condition += " and QueryCount=" + QueryCount;
  345. }
  346. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("UserCashRecord", Fields, "Id desc", "0", 1, 20000, condition, "CashOrderNo,UserId,IdCardNo,ActualTradeAmount,Remark,Status,QueryCount,CreateDate", false);
  347. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  348. foreach (Dictionary<string, object> dic in diclist)
  349. {
  350. int UserId = int.Parse(dic["UserId"].ToString());
  351. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  352. dic["MakerCode"] = user.MakerCode;
  353. dic["RealName"] = user.RealName;
  354. dic["Mobile"] = user.Mobile;
  355. dic["SettleBankName"] = user.SettleBankName;
  356. dic["SettleBankCardNo"] = user.SettleBankCardNo;
  357. dic.Remove("UserId");
  358. // dic["TradeType"] = RelationClassForConst.GetTradeTypeInfo(int.Parse(dic["TradeType"].ToString()));
  359. int Status = int.Parse(dic["Status"].ToString());
  360. if (Status == 0) dic["StatusName"] = "处理中";
  361. if (Status == 1) dic["StatusName"] = "成功";
  362. if (Status == 2) dic["StatusName"] = "失败";
  363. dic.Remove("Status");
  364. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  365. if (QueryCount == 0) dic["LockName"] = "待提交";
  366. if (QueryCount == 1) dic["LockName"] = "已提交";
  367. dic.Remove("QueryCount");
  368. }
  369. Dictionary<string, object> result = new Dictionary<string, object>();
  370. result.Add("Status", "1");
  371. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  372. result.Add("Obj", diclist);
  373. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  374. ReturnFields.Add("CashOrderNo", "提现单号");
  375. ReturnFields.Add("MakerCode", "创客编号");
  376. ReturnFields.Add("RealName", "灵工姓名");
  377. ReturnFields.Add("Mobile", "手机号");
  378. ReturnFields.Add("IdCardNo", "身份证号");
  379. ReturnFields.Add("SettleBankName", "开户行名称");
  380. ReturnFields.Add("SettleBankCardNo", "开户行卡号");
  381. ReturnFields.Add("ActualTradeAmount", "发佣金额(单位:元)");
  382. ReturnFields.Add("LockName", "代付标记");
  383. ReturnFields.Add("StatusName", "状态");
  384. ReturnFields.Add("Remark", "备注");
  385. ReturnFields.Add("CreateDate", "创建时间");
  386. // ReturnFields.Add("CashOrderNo", "提现单号");
  387. // ReturnFields.Add("MakerCode", "创客编码");
  388. // ReturnFields.Add("RealName", "创客名称");
  389. // ReturnFields.Add("IdCardNo", "身份证号");
  390. // ReturnFields.Add("SettleBankCardNo", "提现卡号");
  391. // ReturnFields.Add("SettleBankName", "银行名称");
  392. // ReturnFields.Add("TradeType", "交易类型");
  393. // ReturnFields.Add("TradeAmount", "交易金额(元)");
  394. // ReturnFields.Add("Status", "订单状态");
  395. // ReturnFields.Add("ReturnCode", "提现服务返回编码");
  396. // ReturnFields.Add("ReturnMsg", "提现服务返回信息");
  397. result.Add("Fields", ReturnFields);
  398. AddSysLog("0", "UserCashRecord", "ExportExcel");
  399. return Json(result);
  400. }
  401. #endregion
  402. #region 盟主提现记录列表
  403. /// <summary>
  404. /// 根据条件查询盟主提现记录列表
  405. /// </summary>
  406. /// <returns></returns>
  407. public IActionResult LeaderIndex(UserCashRecord data, string right)
  408. {
  409. ViewBag.RightInfo = RightInfo;
  410. ViewBag.right = right;
  411. string Condition = "";
  412. Condition += "CashOrderNo:\"" + data.CashOrderNo + "\",";
  413. Condition += "TradeType:\"" + data.TradeType + "\",";
  414. if (!string.IsNullOrEmpty(Condition))
  415. {
  416. Condition = Condition.TrimEnd(',');
  417. Condition = ", where: {" + Condition + "}";
  418. }
  419. ViewBag.Condition = Condition;
  420. return View();
  421. }
  422. #endregion
  423. #region 根据条件查询盟主提现记录列表
  424. /// <summary>
  425. /// 盟主提现记录列表
  426. /// </summary>
  427. /// <returns></returns>
  428. public JsonResult LeaderIndexData(UserCashRecord data, string MakerCode, string RealName, string StatusSelect, string QueryCountSelect, string CreateDateData, int page = 1, int limit = 30)
  429. {
  430. Dictionary<string, string> Fields = new Dictionary<string, string>();
  431. Fields.Add("CashOrderNo", "1"); //提现单号
  432. string condition = " and Status>-1 and TradeType=3";
  433. //创客编号
  434. if (!string.IsNullOrEmpty(MakerCode))
  435. {
  436. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  437. }
  438. //创客名称
  439. if (!string.IsNullOrEmpty(RealName))
  440. {
  441. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  442. // condition += " and UserId in (select Id from Users where RealName='" + RealName + "')";
  443. }
  444. //提现状态
  445. if (!string.IsNullOrEmpty(StatusSelect))
  446. {
  447. condition += " and Status=" + StatusSelect;
  448. }
  449. if (!string.IsNullOrEmpty(data.CashOrderNo))
  450. {
  451. condition += " and CashOrderNo='" + data.CashOrderNo + "'";
  452. }
  453. if (data.TradeType > 0)
  454. {
  455. condition += " and TradeType=" + data.TradeType;
  456. }
  457. //提交到代付状态
  458. if (!string.IsNullOrEmpty(QueryCountSelect))
  459. {
  460. condition += " and QueryCount=" + QueryCountSelect;
  461. }
  462. if (!string.IsNullOrEmpty(CreateDateData))
  463. {
  464. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  465. string start = datelist[0];
  466. string end = datelist[1];
  467. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  468. }
  469. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("UserCashRecord", Fields, "Id desc", "0", page, limit, condition);
  470. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  471. foreach (Dictionary<string, object> dic in diclist)
  472. {
  473. int UserId = int.Parse(dic["UserId"].ToString());
  474. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  475. dic["MakerCode"] = user.MakerCode;
  476. dic["RealName"] = user.RealName;
  477. dic["TradeType"] = RelationClassForConst.GetTradeTypeInfo(int.Parse(dic["TradeType"].ToString()));
  478. int Status = int.Parse(dic["Status"].ToString());
  479. if (Status == 0) dic["StatusName"] = "处理中";
  480. if (Status == 1) dic["StatusName"] = "成功";
  481. if (Status == 2) dic["StatusName"] = "失败";
  482. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  483. if (QueryCount == 0) dic["LockName"] = "待提交";
  484. if (QueryCount == 1) dic["LockName"] = "已提交";
  485. }
  486. Dictionary<string, object> other = new Dictionary<string, object>();
  487. string WaitAmount = "0.00";//待处理总金额
  488. string SuccessAmount = "0.00";//提现成功总金额
  489. string FailAmount = "0.00";//提现失败总金额
  490. DataTable dt = OtherMySqlConn.dtable("select sum(TradeAmount) from UserCashRecord where Status=0" + condition);
  491. if (dt.Rows.Count > 0)
  492. {
  493. WaitAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  494. }
  495. dt = OtherMySqlConn.dtable("select sum(TradeAmount) from UserCashRecord where Status=1" + condition);
  496. if (dt.Rows.Count > 0)
  497. {
  498. SuccessAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  499. }
  500. dt = OtherMySqlConn.dtable("select sum(TradeAmount) from UserCashRecord where Status=2" + condition);
  501. if (dt.Rows.Count > 0)
  502. {
  503. FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  504. }
  505. other.Add("WaitAmount", WaitAmount);
  506. other.Add("SuccessAmount", SuccessAmount);
  507. other.Add("FailAmount", FailAmount);
  508. obj.Add("other", other);
  509. return Json(obj);
  510. }
  511. #endregion
  512. #region 导出盟主Excel
  513. /// <summary>
  514. /// 导出Excel
  515. /// </summary>
  516. /// <returns></returns>
  517. public JsonResult LeaderExportExcel(UserCashRecord data, string MakerCode, string RealName, string StatusSelect, string PayStatus)
  518. {
  519. Dictionary<string, string> Fields = new Dictionary<string, string>();
  520. Fields.Add("CashOrderNo", "1"); //提现单号
  521. Fields.Add("CreateDate", "3"); //创建时间
  522. string condition = " and Status>-1 and TradeType=3";
  523. //创客编号
  524. if (!string.IsNullOrEmpty(MakerCode))
  525. {
  526. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  527. }
  528. //创客名称
  529. if (!string.IsNullOrEmpty(RealName))
  530. {
  531. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  532. }
  533. //提现状态
  534. if (!string.IsNullOrEmpty(StatusSelect))
  535. {
  536. condition += " and Status=" + StatusSelect;
  537. }
  538. //提交到代付状态
  539. if (!string.IsNullOrEmpty(PayStatus))
  540. {
  541. int QueryCount = int.Parse(function.CheckInt(PayStatus));
  542. if (QueryCount == 2)
  543. {
  544. QueryCount = 0;
  545. }
  546. condition += " and QueryCount=" + QueryCount;
  547. }
  548. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("UserCashRecord", Fields, "Id desc", "0", 1, 20000, condition, "CashOrderNo,UserId,IdCardNo,ActualTradeAmount,Remark,Status,QueryCount,CreateDate", false);
  549. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  550. foreach (Dictionary<string, object> dic in diclist)
  551. {
  552. int UserId = int.Parse(dic["UserId"].ToString());
  553. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  554. dic["MakerCode"] = user.MakerCode;
  555. dic["RealName"] = user.RealName;
  556. dic["Mobile"] = user.Mobile;
  557. dic["SettleBankName"] = user.SettleBankName;
  558. dic["SettleBankCardNo"] = user.SettleBankCardNo;
  559. dic.Remove("UserId");
  560. // dic["TradeType"] = RelationClassForConst.GetTradeTypeInfo(int.Parse(dic["TradeType"].ToString()));
  561. int Status = int.Parse(dic["Status"].ToString());
  562. if (Status == 0) dic["StatusName"] = "处理中";
  563. if (Status == 1) dic["StatusName"] = "成功";
  564. if (Status == 2) dic["StatusName"] = "失败";
  565. dic.Remove("Status");
  566. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  567. if (QueryCount == 0) dic["LockName"] = "待提交";
  568. if (QueryCount == 1) dic["LockName"] = "已提交";
  569. dic.Remove("QueryCount");
  570. }
  571. Dictionary<string, object> result = new Dictionary<string, object>();
  572. result.Add("Status", "1");
  573. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  574. result.Add("Obj", diclist);
  575. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  576. ReturnFields.Add("CashOrderNo", "提现单号");
  577. ReturnFields.Add("MakerCode", "创客编号");
  578. ReturnFields.Add("RealName", "灵工姓名");
  579. ReturnFields.Add("Mobile", "手机号");
  580. ReturnFields.Add("IdCardNo", "身份证号");
  581. ReturnFields.Add("SettleBankName", "开户行名称");
  582. ReturnFields.Add("SettleBankCardNo", "开户行卡号");
  583. ReturnFields.Add("ActualTradeAmount", "发佣金额(单位:元)");
  584. ReturnFields.Add("LockName", "代付标记");
  585. ReturnFields.Add("StatusName", "状态");
  586. ReturnFields.Add("Remark", "备注");
  587. ReturnFields.Add("CreateDate", "创建时间");
  588. result.Add("Fields", ReturnFields);
  589. AddSysLog("0", "UserCashRecord", "ExportExcel");
  590. return Json(result);
  591. }
  592. #endregion
  593. #region 助利宝提现记录列表
  594. /// <summary>
  595. /// 根据条件查询助利宝提现记录列表
  596. /// </summary>
  597. /// <returns></returns>
  598. public IActionResult HelpProfitIndex(UserCashRecord data, string right)
  599. {
  600. ViewBag.RightInfo = RightInfo;
  601. ViewBag.right = right;
  602. string Condition = "";
  603. Condition += "CashOrderNo:\"" + data.CashOrderNo + "\",";
  604. Condition += "TradeType:\"" + data.TradeType + "\",";
  605. if (!string.IsNullOrEmpty(Condition))
  606. {
  607. Condition = Condition.TrimEnd(',');
  608. Condition = ", where: {" + Condition + "}";
  609. }
  610. ViewBag.Condition = Condition;
  611. return View();
  612. }
  613. #endregion
  614. #region
  615. /// <summary>
  616. /// 助利宝提现记录列表
  617. /// </summary>
  618. /// <returns></returns>
  619. public JsonResult HelpProfitIndexData(UserCashRecord data, string MakerCode, string RealName, string StatusSelect, string QueryCountSelect, string CreateDateData, int page = 1, int limit = 30)
  620. {
  621. Dictionary<string, string> Fields = new Dictionary<string, string>();
  622. Fields.Add("CashOrderNo", "1"); //提现单号
  623. string condition = " and Status>-1 and TradeType=4";
  624. //创客编号
  625. if (!string.IsNullOrEmpty(MakerCode))
  626. {
  627. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  628. }
  629. //创客名称
  630. if (!string.IsNullOrEmpty(RealName))
  631. {
  632. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  633. // condition += " and UserId in (select Id from Users where RealName='" + RealName + "')";
  634. }
  635. //提现状态
  636. if (!string.IsNullOrEmpty(StatusSelect))
  637. {
  638. condition += " and Status=" + StatusSelect;
  639. }
  640. if (!string.IsNullOrEmpty(data.CashOrderNo))
  641. {
  642. condition += " and CashOrderNo='" + data.CashOrderNo + "'";
  643. }
  644. if (data.TradeType > 0)
  645. {
  646. condition += " and TradeType=" + data.TradeType;
  647. }
  648. //提交到代付状态
  649. if (!string.IsNullOrEmpty(QueryCountSelect))
  650. {
  651. condition += " and QueryCount=" + QueryCountSelect;
  652. }
  653. if (!string.IsNullOrEmpty(CreateDateData))
  654. {
  655. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  656. string start = datelist[0];
  657. string end = datelist[1];
  658. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  659. }
  660. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("UserCashRecord", Fields, "Id desc", "0", page, limit, condition);
  661. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  662. foreach (Dictionary<string, object> dic in diclist)
  663. {
  664. int UserId = int.Parse(dic["UserId"].ToString());
  665. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  666. dic["MakerCode"] = user.MakerCode;
  667. dic["RealName"] = user.RealName;
  668. dic["TradeType"] = RelationClassForConst.GetTradeTypeInfo(int.Parse(dic["TradeType"].ToString()));
  669. int Status = int.Parse(dic["Status"].ToString());
  670. if (Status == 0) dic["StatusName"] = "处理中";
  671. if (Status == 1) dic["StatusName"] = "成功";
  672. if (Status == 2) dic["StatusName"] = "失败";
  673. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  674. if (QueryCount == 0) dic["LockName"] = "待提交";
  675. if (QueryCount == 1) dic["LockName"] = "已提交";
  676. }
  677. Dictionary<string, object> other = new Dictionary<string, object>();
  678. string WaitAmount = "0.00";//待处理总金额
  679. string SuccessAmount = "0.00";//提现成功总金额
  680. string FailAmount = "0.00";//提现失败总金额
  681. DataTable dt = OtherMySqlConn.dtable("select sum(TradeAmount) from UserCashRecord where Status=0" + condition);
  682. if (dt.Rows.Count > 0)
  683. {
  684. WaitAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  685. }
  686. dt = OtherMySqlConn.dtable("select sum(TradeAmount) from UserCashRecord where Status=1" + condition);
  687. if (dt.Rows.Count > 0)
  688. {
  689. SuccessAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  690. }
  691. dt = OtherMySqlConn.dtable("select sum(TradeAmount) from UserCashRecord where Status=2" + condition);
  692. if (dt.Rows.Count > 0)
  693. {
  694. FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  695. }
  696. other.Add("WaitAmount", WaitAmount);
  697. other.Add("SuccessAmount", SuccessAmount);
  698. other.Add("FailAmount", FailAmount);
  699. obj.Add("other", other);
  700. return Json(obj);
  701. }
  702. #endregion
  703. #region 导出助利宝Excel
  704. /// <summary>
  705. /// 导出Excel
  706. /// </summary>
  707. /// <returns></returns>
  708. public JsonResult HelpProfitExportExcel(UserCashRecord data, string MakerCode, string RealName, string StatusSelect, string PayStatus)
  709. {
  710. Dictionary<string, string> Fields = new Dictionary<string, string>();
  711. Fields.Add("CashOrderNo", "1"); //提现单号
  712. Fields.Add("CreateDate", "3"); //创建时间
  713. string condition = " and Status>-1 and TradeType=4";
  714. //创客编号
  715. if (!string.IsNullOrEmpty(MakerCode))
  716. {
  717. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  718. }
  719. //创客名称
  720. if (!string.IsNullOrEmpty(RealName))
  721. {
  722. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  723. }
  724. //提现状态
  725. if (!string.IsNullOrEmpty(StatusSelect))
  726. {
  727. condition += " and Status=" + StatusSelect;
  728. }
  729. //提交到代付状态
  730. if (!string.IsNullOrEmpty(PayStatus))
  731. {
  732. int QueryCount = int.Parse(function.CheckInt(PayStatus));
  733. if (QueryCount == 2)
  734. {
  735. QueryCount = 0;
  736. }
  737. condition += " and QueryCount=" + QueryCount;
  738. }
  739. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("UserCashRecord", Fields, "Id desc", "0", 1, 20000, condition, "CashOrderNo,UserId,IdCardNo,ActualTradeAmount,Remark,Status,QueryCount,CreateDate", false);
  740. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  741. foreach (Dictionary<string, object> dic in diclist)
  742. {
  743. int UserId = int.Parse(dic["UserId"].ToString());
  744. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  745. dic["MakerCode"] = user.MakerCode;
  746. dic["RealName"] = user.RealName;
  747. dic["Mobile"] = user.Mobile;
  748. dic["SettleBankName"] = user.SettleBankName;
  749. dic["SettleBankCardNo"] = user.SettleBankCardNo;
  750. dic.Remove("UserId");
  751. // dic["TradeType"] = RelationClassForConst.GetTradeTypeInfo(int.Parse(dic["TradeType"].ToString()));
  752. int Status = int.Parse(dic["Status"].ToString());
  753. if (Status == 0) dic["StatusName"] = "处理中";
  754. if (Status == 1) dic["StatusName"] = "成功";
  755. if (Status == 2) dic["StatusName"] = "失败";
  756. dic.Remove("Status");
  757. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  758. if (QueryCount == 0) dic["LockName"] = "待提交";
  759. if (QueryCount == 1) dic["LockName"] = "已提交";
  760. dic.Remove("QueryCount");
  761. }
  762. Dictionary<string, object> result = new Dictionary<string, object>();
  763. result.Add("Status", "1");
  764. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  765. result.Add("Obj", diclist);
  766. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  767. ReturnFields.Add("CashOrderNo", "提现单号");
  768. ReturnFields.Add("MakerCode", "创客编号");
  769. ReturnFields.Add("RealName", "灵工姓名");
  770. ReturnFields.Add("Mobile", "手机号");
  771. ReturnFields.Add("IdCardNo", "身份证号");
  772. ReturnFields.Add("SettleBankName", "开户行名称");
  773. ReturnFields.Add("SettleBankCardNo", "开户行卡号");
  774. ReturnFields.Add("ActualTradeAmount", "发佣金额(单位:元)");
  775. ReturnFields.Add("LockName", "代付标记");
  776. ReturnFields.Add("StatusName", "状态");
  777. ReturnFields.Add("Remark", "备注");
  778. ReturnFields.Add("CreateDate", "创建时间");
  779. result.Add("Fields", ReturnFields);
  780. AddSysLog("0", "UserCashRecord", "ExportExcel");
  781. return Json(result);
  782. }
  783. #endregion
  784. #region 提交代付平台
  785. /// <summary>
  786. /// 提交代付平台
  787. /// </summary>
  788. /// <returns></returns>
  789. public string Cash(string Id)
  790. {
  791. string[] idlist = Id.Split(new char[] { ',' });
  792. AddSysLog(Id, "UserCashRecord", "cash");
  793. db.SaveChanges();
  794. foreach (string subid in idlist)
  795. {
  796. int id = int.Parse(subid);
  797. UserCashRecord edit = db.UserCashRecord.FirstOrDefault(m => m.Id == id && m.QueryCount == 0);
  798. if (edit != null)
  799. {
  800. edit.QueryCount = 1;
  801. edit.UpdateDate = DateTime.Now;
  802. db.SaveChanges();
  803. RedisDbconn.Instance.AddList("CashPayApplyQueue", Newtonsoft.Json.JsonConvert.SerializeObject(edit));
  804. }
  805. }
  806. return "success";
  807. }
  808. #endregion
  809. #region 拒绝
  810. /// <summary>
  811. /// 拒绝
  812. /// </summary>
  813. /// <returns></returns>
  814. public IActionResult Reduce(string right, int Id = 0)
  815. {
  816. ViewBag.RightInfo = RightInfo;
  817. ViewBag.right = right;
  818. UserCashRecord editData = db.UserCashRecord.FirstOrDefault(m => m.Id == Id) ?? new UserCashRecord();
  819. ViewBag.data = editData;
  820. return View();
  821. }
  822. #endregion
  823. #region 拒绝
  824. /// <summary>
  825. /// 拒绝
  826. /// </summary>
  827. /// <returns></returns>
  828. public string ReduceDo(int Id, string Remark)
  829. {
  830. AddSysLog(Id, "UserCashRecord", "Reduce");
  831. UserCashRecord edit = db.UserCashRecord.FirstOrDefault(m => m.Id == Id);
  832. if (edit != null)
  833. {
  834. if (edit.TradeType == 3)
  835. {
  836. edit.Status = 2;
  837. edit.Remark = Remark;
  838. edit.UpdateMan = SysUserName;
  839. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == edit.UserId);
  840. if (account != null)
  841. {
  842. decimal TradeAmount = edit.TradeAmount;
  843. account.LeaderBalanceAmount += TradeAmount;
  844. db.LeaderAccountRecord.Add(new LeaderAccountRecord()
  845. {
  846. CreateDate = DateTime.Now,
  847. UserId = edit.UserId, //创客
  848. ChangeType = 6, //变动类型
  849. ProductType = 99, //产品类型
  850. ChangeAmount = TradeAmount, //变更金额
  851. BeforeBalanceAmount = account.LeaderBalanceAmount - TradeAmount, //变更前余额
  852. AfterBalanceAmount = account.LeaderBalanceAmount, //变更后余额
  853. });
  854. db.SaveChanges();
  855. RedisDbconn.Instance.Set("UserAccount:" + edit.UserId, account);
  856. }
  857. }
  858. else if (edit.TradeType == 4)
  859. {
  860. edit.Status = 2;
  861. edit.Remark = Remark;
  862. edit.UpdateMan = SysUserName;
  863. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == edit.UserId);
  864. if (account != null)
  865. {
  866. decimal TradeAmount = edit.TradeAmount;
  867. account.HelpProfitBalanceAmount += TradeAmount;
  868. db.HelpProfitAccountRecord.Add(new HelpProfitAccountRecord()
  869. {
  870. CreateDate = DateTime.Now,
  871. UserId = edit.UserId, //创客
  872. ChangeType = 6, //变动类型
  873. ProductType = 99, //产品类型
  874. ChangeAmount = TradeAmount, //变更金额
  875. BeforeBalanceAmount = account.HelpProfitBalanceAmount - TradeAmount, //变更前余额
  876. AfterBalanceAmount = account.HelpProfitBalanceAmount, //变更后余额
  877. });
  878. db.SaveChanges();
  879. RedisDbconn.Instance.Set("UserAccount:" + edit.UserId, account);
  880. }
  881. }
  882. else
  883. {
  884. edit.Status = 2;
  885. edit.Remark = Remark;
  886. edit.UpdateMan = SysUserName;
  887. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == edit.UserId);
  888. if (account != null)
  889. {
  890. decimal TradeAmount = edit.TradeAmount;
  891. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  892. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  893. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  894. account.BalanceAmount += TradeAmount;
  895. if (account.FreezeAmount >= TradeAmount)
  896. {
  897. account.FreezeAmount -= TradeAmount;
  898. }
  899. else
  900. {
  901. return "冻结金额不足";
  902. }
  903. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  904. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  905. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  906. db.UserAccountRecord.Add(new UserAccountRecord()
  907. {
  908. CreateDate = DateTime.Now,
  909. UpdateDate = DateTime.Now,
  910. UserId = edit.UserId, //创客
  911. ChangeType = 6, //变动类型
  912. ProductType = 99, //产品类型
  913. ChangeAmount = TradeAmount, //变更金额
  914. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  915. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  916. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  917. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  918. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  919. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  920. });
  921. db.SaveChanges();
  922. RedisDbconn.Instance.Set("UserAccount:" + edit.UserId, account);
  923. }
  924. }
  925. db.SaveChanges();
  926. }
  927. return "success";
  928. }
  929. #endregion
  930. #region 解除
  931. /// <summary>
  932. /// 解除
  933. /// </summary>
  934. /// <returns></returns>
  935. public string Cancel(string Id)
  936. {
  937. string[] idlist = Id.Split(new char[] { ',' });
  938. AddSysLog(Id, "WithdrawRecord", "Cancel");
  939. foreach (string subid in idlist)
  940. {
  941. int id = int.Parse(subid);
  942. UserCashRecord edit = db.UserCashRecord.FirstOrDefault(m => m.Id == id);
  943. if (edit != null)
  944. {
  945. edit.QueryCount = 0;
  946. db.SaveChanges();
  947. }
  948. }
  949. return "success";
  950. }
  951. #endregion
  952. }
  953. }