UserCashRecordController.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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 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("CreateDate", "3"); //创建时间
  60. Fields.Add("TradeType", "0"); //交易类型
  61. string condition = " and Status>-1";
  62. //创客编号
  63. if (!string.IsNullOrEmpty(MakerCode))
  64. {
  65. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  66. }
  67. //创客名称
  68. if (!string.IsNullOrEmpty(RealName))
  69. {
  70. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  71. }
  72. //提现状态
  73. if (!string.IsNullOrEmpty(StatusSelect))
  74. {
  75. condition += " and Status=" + StatusSelect;
  76. }
  77. if (data.QueryCount > 0)
  78. {
  79. int QueryCount = data.QueryCount;
  80. if (QueryCount == 2)
  81. {
  82. QueryCount = 0;
  83. }
  84. condition += " and QueryCount=" + QueryCount;
  85. }
  86. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("UserCashRecord", Fields, "Id desc", "0", page, limit, condition);
  87. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  88. foreach (Dictionary<string, object> dic in diclist)
  89. {
  90. int UserId = int.Parse(dic["UserId"].ToString());
  91. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  92. dic["MakerCode"] = user.MakerCode;
  93. dic["RealName"] = user.RealName;
  94. dic["TradeType"] = RelationClassForConst.GetTradeTypeInfo(int.Parse(dic["TradeType"].ToString()));
  95. int Status = int.Parse(dic["Status"].ToString());
  96. if (Status == 0) dic["StatusName"] = "处理中";
  97. if (Status == 1) dic["StatusName"] = "成功";
  98. if (Status == 2) dic["StatusName"] = "失败";
  99. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  100. if (QueryCount == 0) dic["LockName"] = "待提交";
  101. if (QueryCount == 1) dic["LockName"] = "已提交";
  102. }
  103. Dictionary<string, object> other = new Dictionary<string, object>();
  104. if (!string.IsNullOrEmpty(data.CashOrderNo))
  105. {
  106. condition += " and CashOrderNo='" + data.CashOrderNo + "'";
  107. }
  108. if (data.TradeType > 0)
  109. {
  110. condition += " and TradeType=" + data.TradeType;
  111. }
  112. if (!string.IsNullOrEmpty(CreateDateData))
  113. {
  114. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  115. string start = datelist[0];
  116. string end = datelist[1];
  117. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate>='" + end + " 23:59:59'";
  118. }
  119. string SuccessAmount = "0.00";
  120. string FailAmount = "0.00";
  121. string WaitAmount = "0.00";
  122. DataTable dt = OtherMySqlConn.dtable("select sum(TradeAmount) from UserCashRecord where Status=1" + condition);
  123. if (dt.Rows.Count > 0)
  124. {
  125. SuccessAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  126. }
  127. dt = OtherMySqlConn.dtable("select sum(TradeAmount) from UserCashRecord where Status=2" + condition);
  128. if (dt.Rows.Count > 0)
  129. {
  130. FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  131. }
  132. dt = OtherMySqlConn.dtable("select sum(TradeAmount) from UserCashRecord where Status=0" + condition);
  133. if (dt.Rows.Count > 0)
  134. {
  135. WaitAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  136. }
  137. other.Add("SuccessAmount", SuccessAmount);
  138. other.Add("FailAmount", FailAmount);
  139. other.Add("WaitAmount", WaitAmount);
  140. obj.Add("other", other);
  141. return Json(obj);
  142. }
  143. #endregion
  144. #region 增加提现记录
  145. /// <summary>
  146. /// 增加或修改提现记录信息
  147. /// </summary>
  148. /// <returns></returns>
  149. public IActionResult Add(string right)
  150. {
  151. ViewBag.RightInfo = RightInfo;
  152. ViewBag.right = right;
  153. return View();
  154. }
  155. #endregion
  156. #region 增加提现记录
  157. /// <summary>
  158. /// 增加或修改提现记录信息
  159. /// </summary>
  160. /// <returns></returns>
  161. [HttpPost]
  162. public string Add(UserCashRecord data)
  163. {
  164. Dictionary<string, object> Fields = new Dictionary<string, object>();
  165. Fields.Add("Remark", data.Remark); //备注
  166. Fields.Add("SeoTitle", data.SeoTitle);
  167. Fields.Add("SeoKeyword", data.SeoKeyword);
  168. Fields.Add("SeoDescription", data.SeoDescription);
  169. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("UserCashRecord", Fields, 0);
  170. AddSysLog(data.Id.ToString(), "UserCashRecord", "add");
  171. db.SaveChanges();
  172. return "success";
  173. }
  174. #endregion
  175. #region 修改提现记录
  176. /// <summary>
  177. /// 增加或修改提现记录信息
  178. /// </summary>
  179. /// <returns></returns>
  180. public IActionResult Edit(string right, int Id = 0)
  181. {
  182. ViewBag.RightInfo = RightInfo;
  183. ViewBag.right = right;
  184. UserCashRecord editData = db.UserCashRecord.FirstOrDefault(m => m.Id == Id) ?? new UserCashRecord();
  185. ViewBag.data = editData;
  186. return View();
  187. }
  188. #endregion
  189. #region 修改提现记录
  190. /// <summary>
  191. /// 增加或修改提现记录信息
  192. /// </summary>
  193. /// <returns></returns>
  194. [HttpPost]
  195. public string Edit(UserCashRecord data)
  196. {
  197. Dictionary<string, object> Fields = new Dictionary<string, object>();
  198. Fields.Add("Remark", data.Remark); //备注
  199. Fields.Add("SeoTitle", data.SeoTitle);
  200. Fields.Add("SeoKeyword", data.SeoKeyword);
  201. Fields.Add("SeoDescription", data.SeoDescription);
  202. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserCashRecord", Fields, data.Id);
  203. AddSysLog(data.Id.ToString(), "UserCashRecord", "update");
  204. db.SaveChanges();
  205. return "success";
  206. }
  207. #endregion
  208. #region 删除提现记录信息
  209. /// <summary>
  210. /// 删除提现记录信息
  211. /// </summary>
  212. /// <returns></returns>
  213. public string Delete(string Id)
  214. {
  215. string[] idlist = Id.Split(new char[] { ',' });
  216. AddSysLog(Id, "UserCashRecord", "del");
  217. foreach (string subid in idlist)
  218. {
  219. int id = int.Parse(subid);
  220. Dictionary<string, object> Fields = new Dictionary<string, object>();
  221. Fields.Add("Status", -1);
  222. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserCashRecord", Fields, id);
  223. }
  224. db.SaveChanges();
  225. return "success";
  226. }
  227. #endregion
  228. #region 开启
  229. /// <summary>
  230. /// 开启
  231. /// </summary>
  232. /// <returns></returns>
  233. public string Open(string Id)
  234. {
  235. string[] idlist = Id.Split(new char[] { ',' });
  236. AddSysLog(Id, "UserCashRecord", "open");
  237. foreach (string subid in idlist)
  238. {
  239. int id = int.Parse(subid);
  240. Dictionary<string, object> Fields = new Dictionary<string, object>();
  241. Fields.Add("Status", 1);
  242. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserCashRecord", Fields, id);
  243. }
  244. db.SaveChanges();
  245. return "success";
  246. }
  247. #endregion
  248. #region 关闭
  249. /// <summary>
  250. /// 关闭
  251. /// </summary>
  252. /// <returns></returns>
  253. public string Close(string Id)
  254. {
  255. string[] idlist = Id.Split(new char[] { ',' });
  256. AddSysLog(Id, "UserCashRecord", "close");
  257. foreach (string subid in idlist)
  258. {
  259. int id = int.Parse(subid);
  260. Dictionary<string, object> Fields = new Dictionary<string, object>();
  261. Fields.Add("Status", 0);
  262. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserCashRecord", Fields, id);
  263. }
  264. db.SaveChanges();
  265. return "success";
  266. }
  267. #endregion
  268. #region 排序
  269. /// <summary>
  270. /// 排序
  271. /// </summary>
  272. /// <param name="Id"></param>
  273. public string Sort(int Id, int Sort)
  274. {
  275. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("UserCashRecord", Sort, Id);
  276. AddSysLog(Id.ToString(), "UserCashRecord", "sort");
  277. return "success";
  278. }
  279. #endregion
  280. #region 导入数据
  281. public IActionResult Import(string right)
  282. {
  283. ViewBag.RightInfo = RightInfo;
  284. ViewBag.right = right;
  285. return View();
  286. }
  287. /// <summary>
  288. /// 导入数据
  289. /// </summary>
  290. /// <param name="ExcelData"></param>
  291. [HttpPost]
  292. public string ImportPost(string ExcelPath)
  293. {
  294. string key = function.MD5_16(Guid.NewGuid().ToString());
  295. RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#UserCashRecord#cut#" + key + "#cut#" + SysUserName);
  296. return "success|" + key;
  297. }
  298. public string CheckImport(string key)
  299. {
  300. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  301. if (!string.IsNullOrEmpty(result))
  302. {
  303. string[] datalist = result.Split('|');
  304. if (datalist[0] == "success")
  305. {
  306. return result;
  307. }
  308. return datalist[0];
  309. }
  310. return "0";
  311. }
  312. #endregion
  313. #region 导出Excel
  314. /// <summary>
  315. /// 导出Excel
  316. /// </summary>
  317. /// <returns></returns>
  318. public JsonResult ExportExcel(UserCashRecord data, string MakerCode, string RealName, string StatusSelect)
  319. {
  320. Dictionary<string, string> Fields = new Dictionary<string, string>();
  321. Fields.Add("CashOrderNo", "1"); //提现单号
  322. Fields.Add("CreateDate", "3"); //创建时间
  323. Fields.Add("TradeType", "0"); //交易类型
  324. string condition = " and Status>-1";
  325. //创客编号
  326. if (!string.IsNullOrEmpty(MakerCode))
  327. {
  328. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  329. }
  330. //创客名称
  331. if (!string.IsNullOrEmpty(RealName))
  332. {
  333. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  334. }
  335. //提现状态
  336. if (!string.IsNullOrEmpty(StatusSelect))
  337. {
  338. condition += " and Status=" + StatusSelect;
  339. }
  340. 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", false);
  341. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  342. foreach (Dictionary<string, object> dic in diclist)
  343. {
  344. int UserId = int.Parse(dic["UserId"].ToString());
  345. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  346. dic["MakerCode"] = user.MakerCode;
  347. dic["RealName"] = user.RealName;
  348. dic["Mobile"] = user.Mobile;
  349. dic["SettleBankName"] = user.SettleBankName;
  350. dic["SettleBankCardNo"] = user.SettleBankCardNo;
  351. dic.Remove("UserId");
  352. // dic["TradeType"] = RelationClassForConst.GetTradeTypeInfo(int.Parse(dic["TradeType"].ToString()));
  353. int Status = int.Parse(dic["Status"].ToString());
  354. if (Status == 0) dic["StatusName"] = "处理中";
  355. if (Status == 1) dic["StatusName"] = "成功";
  356. if (Status == 2) dic["StatusName"] = "失败";
  357. dic.Remove("Status");
  358. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  359. if (QueryCount == 0) dic["LockName"] = "待提交";
  360. if (QueryCount == 1) dic["LockName"] = "已提交";
  361. dic.Remove("QueryCount");
  362. }
  363. Dictionary<string, object> result = new Dictionary<string, object>();
  364. result.Add("Status", "1");
  365. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  366. result.Add("Obj", diclist);
  367. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  368. ReturnFields.Add("CashOrderNo", "提现单号");
  369. ReturnFields.Add("MakerCode", "创客编号");
  370. ReturnFields.Add("RealName", "灵工姓名");
  371. ReturnFields.Add("Mobile", "手机号");
  372. ReturnFields.Add("IdCardNo", "身份证号");
  373. ReturnFields.Add("SettleBankName", "开户行名称");
  374. ReturnFields.Add("SettleBankCardNo", "开户行卡号");
  375. ReturnFields.Add("ActualTradeAmount", "发佣金额(单位:元)");
  376. ReturnFields.Add("LockName", "代付标记");
  377. ReturnFields.Add("StatusName", "状态");
  378. ReturnFields.Add("Remark", "备注");
  379. // ReturnFields.Add("CashOrderNo", "提现单号");
  380. // ReturnFields.Add("MakerCode", "创客编码");
  381. // ReturnFields.Add("RealName", "创客名称");
  382. // ReturnFields.Add("IdCardNo", "身份证号");
  383. // ReturnFields.Add("SettleBankCardNo", "提现卡号");
  384. // ReturnFields.Add("SettleBankName", "银行名称");
  385. // ReturnFields.Add("TradeType", "交易类型");
  386. // ReturnFields.Add("TradeAmount", "交易金额(元)");
  387. // ReturnFields.Add("Status", "订单状态");
  388. // ReturnFields.Add("ReturnCode", "提现服务返回编码");
  389. // ReturnFields.Add("ReturnMsg", "提现服务返回信息");
  390. // ReturnFields.Add("CreateDate", "创建时间");
  391. result.Add("Fields", ReturnFields);
  392. AddSysLog("0", "UserCashRecord", "ExportExcel");
  393. return Json(result);
  394. }
  395. #endregion
  396. #region 提交代付平台
  397. /// <summary>
  398. /// 提交代付平台
  399. /// </summary>
  400. /// <returns></returns>
  401. public string Cash(string Id)
  402. {
  403. string[] idlist = Id.Split(new char[] { ',' });
  404. AddSysLog(Id, "UserCashRecord", "cash");
  405. db.SaveChanges();
  406. foreach (string subid in idlist)
  407. {
  408. int id = int.Parse(subid);
  409. UserCashRecord edit = db.UserCashRecord.FirstOrDefault(m => m.Id == id && m.QueryCount == 0);
  410. if (edit != null)
  411. {
  412. edit.QueryCount = 1;
  413. db.SaveChanges();
  414. RedisDbconn.Instance.AddList("CashPayApplyQueue", Newtonsoft.Json.JsonConvert.SerializeObject(edit));
  415. }
  416. }
  417. return "success";
  418. }
  419. #endregion
  420. #region 拒绝
  421. /// <summary>
  422. /// 拒绝
  423. /// </summary>
  424. /// <returns></returns>
  425. public IActionResult Reduce(string right)
  426. {
  427. ViewBag.RightInfo = RightInfo;
  428. ViewBag.right = right;
  429. return View();
  430. }
  431. #endregion
  432. #region 拒绝
  433. /// <summary>
  434. /// 拒绝
  435. /// </summary>
  436. /// <returns></returns>
  437. public string ReduceDo(int Id, string Remark)
  438. {
  439. AddSysLog(Id, "UserCashRecord", "Reduce");
  440. UserCashRecord edit = db.UserCashRecord.FirstOrDefault(m => m.Id == Id);
  441. if (edit != null)
  442. {
  443. edit.Status = 2;
  444. edit.Remark = Remark;
  445. edit.UpdateMan = SysUserName;
  446. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == edit.UserId);
  447. if (account != null)
  448. {
  449. decimal TradeAmount = edit.TradeAmount;
  450. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  451. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  452. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  453. account.BalanceAmount += TradeAmount;
  454. account.FreezeAmount -= TradeAmount;
  455. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  456. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  457. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  458. db.UserAccountRecord.Add(new UserAccountRecord()
  459. {
  460. CreateDate = DateTime.Now,
  461. UpdateDate = DateTime.Now,
  462. UserId = edit.UserId, //创客
  463. ChangeType = 6, //变动类型
  464. ProductType = 99, //产品类型
  465. ChangeAmount = TradeAmount, //变更金额
  466. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  467. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  468. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  469. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  470. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  471. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  472. });
  473. db.SaveChanges();
  474. RedisDbconn.Instance.Set("UserAccount:" + edit.UserId, account);
  475. }
  476. db.SaveChanges();
  477. }
  478. return "success";
  479. }
  480. #endregion
  481. #region 解除
  482. /// <summary>
  483. /// 解除
  484. /// </summary>
  485. /// <returns></returns>
  486. public string Cancel(string Id)
  487. {
  488. string[] idlist = Id.Split(new char[] { ',' });
  489. AddSysLog(Id, "WithdrawRecord", "Cancel");
  490. foreach (string subid in idlist)
  491. {
  492. int id = int.Parse(subid);
  493. UserCashRecord edit = db.UserCashRecord.FirstOrDefault(m => m.Id == id);
  494. if (edit != null)
  495. {
  496. edit.QueryCount = 0;
  497. db.SaveChanges();
  498. }
  499. }
  500. return "success";
  501. }
  502. #endregion
  503. }
  504. }