UserCashRecordController.cs 23 KB

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