PreAmountRecordController.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.Models;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  18. namespace MySystem.Areas.Admin.Controllers
  19. {
  20. [Area("Admin")]
  21. [Route("Admin/[controller]/[action]")]
  22. public class PreAmountRecordController : BaseController
  23. {
  24. public PreAmountRecordController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  27. }
  28. #region 根据条件查询小分仓临时额度记录列表
  29. /// <summary>
  30. /// 根据条件查询小分仓临时额度记录列表
  31. /// </summary>
  32. /// <returns></returns>
  33. public IActionResult Index(PreAmountRecord data, string right)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. return View();
  38. }
  39. #endregion
  40. #region 根据条件查询小分仓临时额度记录列表
  41. /// <summary>
  42. /// 根据条件查询小分仓临时额度记录列表
  43. /// </summary>
  44. /// <returns></returns>
  45. public JsonResult IndexData(PreAmountRecord data, string UserIdRealName, string UserIdMakerCode, string CreateDateData, string OperateTypeSelect, string PayModeSelect, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. string condition = " and Status>=-1";
  49. //创客真实姓名
  50. if (!string.IsNullOrEmpty(UserIdRealName))
  51. {
  52. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  53. }
  54. //创客编号
  55. if (!string.IsNullOrEmpty(UserIdMakerCode))
  56. {
  57. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  58. }
  59. if (!string.IsNullOrEmpty(CreateDateData))
  60. {
  61. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  62. string start = datelist[0];
  63. string end = datelist[1];
  64. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  65. }
  66. //操作类别
  67. if (!string.IsNullOrEmpty(OperateTypeSelect))
  68. {
  69. condition += " and OperateType=" + OperateTypeSelect;
  70. }
  71. //额度类别
  72. if (!string.IsNullOrEmpty(PayModeSelect))
  73. {
  74. condition += " and PayMode=" + PayModeSelect;
  75. }
  76. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PreAmountRecord", Fields, "Id desc", "0", page, limit, condition);
  77. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  78. foreach (Dictionary<string, object> dic in diclist)
  79. {
  80. //创客
  81. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  82. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  83. dic["UserIdRealName"] = userid_Users.RealName;
  84. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  85. dic.Remove("UserId");
  86. //变动类别
  87. int ChangeType = int.Parse(dic["Sort"].ToString());
  88. if (ChangeType == 1) dic["ChangeType"] = "购买临额";
  89. if (ChangeType == 3) dic["ChangeType"] = "调低临额";
  90. //操作类别
  91. int OperateType = int.Parse(dic["OperateType"].ToString());
  92. if (OperateType == 0) dic["OperateType"] = "减少";
  93. if (OperateType == 1) dic["OperateType"] = "增加";
  94. //额度类别
  95. int PayMode = int.Parse(dic["PayMode"].ToString());
  96. if (PayMode == 1) dic["PayMode"] = "支付宝";
  97. if (PayMode == 3) dic["PayMode"] = "余额";
  98. if (PayMode == 0) dic["PayMode"] = "";
  99. }
  100. return Json(obj);
  101. }
  102. #endregion
  103. #region 小分仓银行卡临额提现记录列表
  104. /// <summary>
  105. /// 根据条件查询小分仓银行卡临额提现记录列表
  106. /// </summary>
  107. /// <returns></returns>
  108. public IActionResult Indexs(PreAmountRecord data, string right)
  109. {
  110. ViewBag.RightInfo = RightInfo;
  111. ViewBag.right = right;
  112. return View();
  113. }
  114. #endregion
  115. #region 小分仓银行卡临额提现记录列表
  116. /// <summary>
  117. /// 根据条件查询小分仓银行卡临额提现记录列表
  118. /// </summary>
  119. /// <returns></returns>
  120. public JsonResult IndexsData(PreAmountRecord data, string UserIdRealName, string UserIdMakerCode, string CreateDateData, string OperateTypeSelect, string PayModeSelect, string StatusSelect = "0", int page = 1, int limit = 30)
  121. {
  122. Dictionary<string, string> Fields = new Dictionary<string, string>();
  123. string condition = " and Status>=-1 and PayMode=1 and Sort=3";
  124. //创客真实姓名
  125. if (!string.IsNullOrEmpty(UserIdRealName))
  126. {
  127. condition += " and UserId in (select UserId from Users where RealName='" + UserIdRealName + "')";
  128. }
  129. //创客编号
  130. if (!string.IsNullOrEmpty(UserIdMakerCode))
  131. {
  132. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  133. }
  134. if (!string.IsNullOrEmpty(CreateDateData))
  135. {
  136. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  137. string start = datelist[0];
  138. string end = datelist[1];
  139. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  140. }
  141. //操作类别
  142. if (!string.IsNullOrEmpty(OperateTypeSelect))
  143. {
  144. condition += " and OperateType=" + OperateTypeSelect;
  145. }
  146. //额度类别
  147. if (!string.IsNullOrEmpty(PayModeSelect))
  148. {
  149. condition += " and PayMode=" + PayModeSelect;
  150. }
  151. //状态
  152. if (!string.IsNullOrEmpty(StatusSelect))
  153. {
  154. condition += " and Status=" + StatusSelect;
  155. }
  156. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PreAmountRecord", Fields, "Id desc", "0", page, limit, condition);
  157. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  158. foreach (Dictionary<string, object> dic in diclist)
  159. {
  160. //创客
  161. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  162. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  163. dic["UserIdRealName"] = userid_Users.RealName;
  164. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  165. dic["CertId"] = userid_Users.CertId;
  166. dic["SettleBankCardNo"] = userid_Users.SettleBankCardNo;
  167. dic["SettleBankName"] = userid_Users.SettleBankName;
  168. dic["Mobile"] = userid_Users.Mobile;
  169. dic["Type"] = "临额提现";
  170. dic.Remove("UserId");
  171. //操作类别
  172. int OperateType = int.Parse(dic["OperateType"].ToString());
  173. if (OperateType == 0) dic["OperateType"] = "减少";
  174. if (OperateType == 1) dic["OperateType"] = "增加";
  175. //额度类别
  176. int PayMode = int.Parse(dic["PayMode"].ToString());
  177. if (PayMode == 1) dic["PayMode"] = "支付宝";
  178. if (PayMode == 3) dic["PayMode"] = "余额";
  179. if (PayMode == 0) dic["PayMode"] = "";
  180. //状态
  181. int Status = int.Parse(dic["Status"].ToString());
  182. if (Status == 0) dic["Status"] = "待处理";
  183. if (Status == 2) dic["Status"] = "处理中";
  184. if (Status == 1) dic["Status"] = "成功";
  185. if (Status == -1) dic["Status"] = "失败";
  186. }
  187. return Json(obj);
  188. }
  189. #endregion
  190. #region 小分仓银行卡临额提现记录导出Excel
  191. /// <summary>
  192. /// 导出Excel
  193. /// </summary>
  194. /// <returns></returns>
  195. public JsonResult ExportsExcel(PreAmountRecord data, string UserIdRealName, string UserIdMakerCode, string CreateDateData, string StatusSelect)
  196. {
  197. Dictionary<string, string> Fields = new Dictionary<string, string>();
  198. string condition = " and PayMode=1 and Sort=3";
  199. //创客真实姓名
  200. if (!string.IsNullOrEmpty(UserIdRealName))
  201. {
  202. condition += " and UserId in (select UserId from Users where RealName='" + UserIdRealName + "')";
  203. }
  204. //创客编号
  205. if (!string.IsNullOrEmpty(UserIdMakerCode))
  206. {
  207. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  208. }
  209. if (!string.IsNullOrEmpty(CreateDateData))
  210. {
  211. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  212. string start = datelist[0];
  213. string end = datelist[1];
  214. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  215. }
  216. //状态
  217. if (!string.IsNullOrEmpty(StatusSelect))
  218. {
  219. condition += " and Status=" + StatusSelect;
  220. }
  221. var Ids = "";
  222. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PreAmountRecord", Fields, "Id desc", "0", 1, 20000, condition, "Id,CreateDate,UserId,UseAmount", false);
  223. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  224. foreach (Dictionary<string, object> dic in diclist)
  225. {
  226. //创客
  227. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  228. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  229. dic["UserIdRealName"] = userid_Users.RealName;
  230. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  231. dic["CertId"] = userid_Users.CertId;
  232. dic["SettleBankCardNo"] = userid_Users.SettleBankCardNo;
  233. dic["SettleBankName"] = userid_Users.SettleBankName;
  234. dic["Mobile"] = userid_Users.Mobile;
  235. dic["Type"] = "临额提现";
  236. dic["IsOk"] = "";
  237. dic.Remove("UserId");
  238. //记录Id
  239. int Id = int.Parse(function.CheckInt(dic["Id"].ToString()));
  240. var preAmountRecord = db.PreAmountRecord.FirstOrDefault(m => m.Id == Id) ?? new PreAmountRecord();
  241. if (preAmountRecord.Status == 0) dic["Status"] = "待处理";
  242. if (preAmountRecord.Status == 2) dic["Status"] = "处理中";
  243. if (preAmountRecord.Status == 1) dic["Status"] = "成功";
  244. if (preAmountRecord.Status == -1) dic["Status"] = "失败";
  245. dic["Id"] = Id;
  246. Ids += Id + ",";
  247. }
  248. Ids = Ids.TrimEnd(',');
  249. Dictionary<string, object> result = new Dictionary<string, object>();
  250. result.Add("Status", "1");
  251. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  252. result.Add("Obj", diclist);
  253. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  254. ReturnFields.Add("Id", "记录ID");
  255. ReturnFields.Add("CreateDate", "提现申请时间");
  256. ReturnFields.Add("Status", "提现结果");
  257. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  258. ReturnFields.Add("UserIdMakerCode", "创客编号");
  259. ReturnFields.Add("UseAmount", "申请提现临额");
  260. ReturnFields.Add("CertId", "身份证号");
  261. ReturnFields.Add("SettleBankCardNo", "银行卡号");
  262. ReturnFields.Add("SettleBankName", "银行名称");
  263. ReturnFields.Add("Mobile", "手机号");
  264. ReturnFields.Add("Type", "交易类型");
  265. ReturnFields.Add("IsOk", "是否成功(是、否)");
  266. result.Add("Fields", ReturnFields);
  267. OtherMySqlConn.op("UPDATE PreAmountRecord SET `Status`=2 WHERE Id IN(" + Ids + ") AND `Status`=0");
  268. AddSysLog("0", "PreAmountRecord", "ExportExcel");
  269. return Json(result);
  270. }
  271. #endregion
  272. #region 快捷导出Excel
  273. public IActionResult QuickExportExcel(string right)
  274. {
  275. ViewBag.RightInfo = RightInfo;
  276. ViewBag.right = right;
  277. return View();
  278. }
  279. [HttpPost]
  280. public string QuickExportExcelDo(string UserIdRealName, string UserIdMakerCode, string CreateDateData, string StatusSelect)
  281. {
  282. Dictionary<string, string> Fields = new Dictionary<string, string>();
  283. string condition = " where 1=1 and a.PayMode=1 and a.Sort=3";
  284. string conditions = " and PayMode=1 and Sort=3";
  285. //创客真实姓名
  286. if (!string.IsNullOrEmpty(UserIdRealName))
  287. {
  288. condition += " and a.UserId in (select UserId from Users where RealName='" + UserIdRealName + "')";
  289. conditions += " and UserId in (select UserId from Users where RealName='" + UserIdRealName + "')";
  290. }
  291. //创客编号
  292. if (!string.IsNullOrEmpty(UserIdMakerCode))
  293. {
  294. condition += " and a.UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  295. conditions += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  296. }
  297. if (!string.IsNullOrEmpty(CreateDateData))
  298. {
  299. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  300. string start = datelist[0];
  301. string end = datelist[1];
  302. condition += " and a.CreateDate>='" + start + " 00:00:00' and a.CreateDate<='" + end + " 23:59:59'";
  303. conditions += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  304. }
  305. //状态
  306. if (!string.IsNullOrEmpty(StatusSelect))
  307. {
  308. if (StatusSelect == "0")
  309. {
  310. condition += " and a.Status=2";
  311. }
  312. else
  313. {
  314. condition += " and a.Status=" + StatusSelect;
  315. }
  316. conditions += " and Status=" + StatusSelect;
  317. }
  318. var Ids = "";
  319. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PreAmountRecord", Fields, "Id desc", "0", 1, 20000000, conditions, "Id", false);
  320. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  321. foreach (Dictionary<string, object> dic in diclist)
  322. {
  323. //记录Id
  324. int Id = int.Parse(function.CheckInt(dic["Id"].ToString()));
  325. Ids += Id + ",";
  326. }
  327. Ids = Ids.TrimEnd(',');
  328. OtherMySqlConn.op("UPDATE PreAmountRecord SET `Status`=2 WHERE Id IN(" + Ids + ") AND `Status`=0");
  329. var Sql = "SELECT a.Id '记录ID',DATE_FORMAT(a.CreateDate,'%Y-%m-%d %H:%i:%s') '提现申请时间',(CASE WHEN a.Status=0 THEN '待处理' WHEN a.Status=2 THEN '处理中' WHEN a.Status=1 THEN '成功' WHEN a.Status=-1 THEN '失败' ELSE '' end) '提现结果',b.RealName '创客真实姓名',b.MakerCode '创客编号',a.UseAmount '申请提现临额',b.CertId '身份证号',b.SettleBankCardNo '银行卡号',b.SettleBankName '银行名称',b.Mobile '手机号',(CASE WHEN a.AmountType=1 THEN '临额提现' ELSE '' end) '交易类型',null '是否成功(是、否)' FROM PreAmountRecord a LEFT JOIN Users b ON a.UserId=b.Id" + condition + "";
  330. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
  331. var FileName = "小分仓临额提现提现记录" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  332. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  333. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  334. AddSysLog(Ids, "PreAmountRecord", "QuickExportExcelDo");
  335. return "success";
  336. }
  337. #endregion
  338. #region 小分仓银行卡临额提现记录结果导入Excel
  339. /// <summary>
  340. /// 小分仓银行卡临额提现记录结果导入Excel
  341. /// </summary>
  342. /// <param name="ExcelData"></param>
  343. public string Imports(string ExcelData)
  344. {
  345. ExcelData = HttpUtility.UrlDecode(ExcelData);
  346. JsonData list = JsonMapper.ToObject(ExcelData);
  347. string error = "";
  348. List<int> IdList = new List<int>();
  349. List<int> IdLists = new List<int>();
  350. for (int i = 1; i < list.Count; i++)
  351. {
  352. JsonData dr = list[i];
  353. string itemJson = dr.ToJson();
  354. string Id = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  355. string IsOk = itemJson.Contains("\"L\"") ? dr["L"].ToString() : "";
  356. if (IdList.Contains(Convert.ToInt32(Id)))
  357. {
  358. error += "以下操作失败" + Id + ',' + "该记录重复" + '\n';
  359. }
  360. else if (IsOk == "否")
  361. {
  362. IdLists.Add(Convert.ToInt32(Id));
  363. }
  364. else
  365. {
  366. IdList.Add(Convert.ToInt32(Id));
  367. }
  368. }
  369. if (!string.IsNullOrEmpty(error))
  370. {
  371. return "Warning|" + error;
  372. }
  373. else
  374. {
  375. var Info = db.PreAmountRecord.Where(m => IdList.Contains(m.Id) && m.Status == 2).ToList();//成功
  376. var Infos = db.PreAmountRecord.Where(m => IdLists.Contains(m.Id) && m.Status == 2).ToList();//失败
  377. foreach (var item in Info)
  378. {
  379. item.Status = 1;//设置为成功
  380. db.SaveChanges();
  381. }
  382. foreach (var items in Infos)
  383. {
  384. items.Status = -1;//设置为失败
  385. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == items.UserId) ?? new UserAccount();
  386. if (userAccount.Id > 0)
  387. {
  388. userAccount.PreTempAmount += items.UseAmount;//退还卡充值临额
  389. userAccount.ValidPreAmount += items.UseAmount;//退还可用额度
  390. }
  391. db.SaveChanges();
  392. }
  393. }
  394. AddSysLog("0", "PreCardAmountRecord", "Import");
  395. return "success";
  396. }
  397. #endregion
  398. }
  399. }