UserCashRecordForBusinessController.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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 UserCashRecordForBusinessController : BaseController
  24. {
  25. public UserCashRecordForBusinessController(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(UserCashRecordForBusiness 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(UserCashRecordForBusiness data, string MakerCode, string RealName, string CreateDateData, int page = 1, int limit = 30)
  56. {
  57. Dictionary<string, string> Fields = new Dictionary<string, string>();
  58. string condition = " and Status>-1";
  59. //创客编号
  60. if (!string.IsNullOrEmpty(MakerCode))
  61. {
  62. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  63. }
  64. //创客名称
  65. if (!string.IsNullOrEmpty(RealName))
  66. {
  67. condition += " and UserId in (select Id from Users where RealName='" + RealName + "')";
  68. }
  69. if (!string.IsNullOrEmpty(data.CashOrderNo))
  70. {
  71. condition += " and CashOrderNo='" + data.CashOrderNo + "'";
  72. }
  73. if (!string.IsNullOrEmpty(CreateDateData))
  74. {
  75. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  76. var start = datelist[0];
  77. var end = datelist[1];
  78. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  79. // var start = Convert.ToDateTime(Convert.ToDateTime(datelist[0]).ToString("yyyy-MM-dd"));
  80. // var end = Convert.ToDateTime(Convert.ToDateTime(datelist[1]).ToString("yyyy-MM-dd") + " 23:59:59");
  81. // var check = db.UserCashRecordForBusiness.Any(m => m.CreateDate >= start);
  82. // var checks = db.UserCashRecordForBusiness.Any(m => m.CreateDate <= end);
  83. // if (check)
  84. // {
  85. // var sId = db.UserCashRecordForBusiness.Where(m => m.CreateDate >= start).Min(m => m.Id);
  86. // condition += " and Id >=" + sId;
  87. // }
  88. // if (checks)
  89. // {
  90. // var eId = db.UserCashRecordForBusiness.Where(m => m.CreateDate <= end).Max(m => m.Id);
  91. // condition += " and Id <=" + eId;
  92. // }
  93. }
  94. // else
  95. // {
  96. // var start = Convert.ToDateTime(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01");
  97. // var check = db.UserCashRecordForBusiness.Any(m => m.CreateDate >= start);
  98. // if (check)
  99. // {
  100. // var minId = db.UserCashRecordForBusiness.Where(m => m.CreateDate >= start).Min(m => m.Id);
  101. // var Info = function.ReadInstance("/WritePage/UserCashRecord/UserCashRecordForBusiness.txt");
  102. // if (string.IsNullOrEmpty(Info.ToString()))
  103. // {
  104. // function.WritePage("/WritePage/UserCashRecord/", "UserCashRecordForBusiness.txt", minId.ToString());
  105. // condition += " and Id >=" + minId;
  106. // }
  107. // else if (minId != int.Parse(Info))
  108. // {
  109. // function.WritePage("/WritePage/UserCashRecord/", "UserCashRecordForBusiness.txt", minId.ToString());
  110. // condition += " and Id >=" + minId;
  111. // }
  112. // else
  113. // {
  114. // condition += " and Id >=" + Convert.ToInt32(Info);
  115. // }
  116. // }
  117. // else
  118. // {
  119. // condition += " and Id =0";
  120. // }
  121. // }
  122. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("UserCashRecordForBusiness", Fields, "Id desc", "0", page, limit, condition);
  123. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  124. foreach (Dictionary<string, object> dic in diclist)
  125. {
  126. int UserId = int.Parse(dic["UserId"].ToString());
  127. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  128. dic["MakerCode"] = user.MakerCode;
  129. dic["RealName"] = user.RealName;
  130. }
  131. return Json(obj);
  132. }
  133. #endregion
  134. #region 增加直营团队提现记录
  135. /// <summary>
  136. /// 增加或修改直营团队提现记录信息
  137. /// </summary>
  138. /// <returns></returns>
  139. public IActionResult Add(string right)
  140. {
  141. ViewBag.RightInfo = RightInfo;
  142. ViewBag.right = right;
  143. return View();
  144. }
  145. #endregion
  146. #region 增加直营团队提现记录
  147. /// <summary>
  148. /// 增加或修改直营团队提现记录信息
  149. /// </summary>
  150. /// <returns></returns>
  151. [HttpPost]
  152. public string Add(UserCashRecordForBusiness data, string MakerCode, string RealName, string Amount)
  153. {
  154. Dictionary<string, object> Fields = new Dictionary<string, object>();
  155. var userInfo = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode && m.RealName == RealName && m.BusinessFlag == 1) ?? new Users();
  156. if (userInfo.Id > 0 && !string.IsNullOrEmpty(Amount))
  157. {
  158. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == userInfo.Id) ?? new UserAccount();
  159. // GetReserve(MakerCode, RealName, Amount);
  160. if (account.BalanceAmount - account.ToChargeAmount - decimal.Parse(Amount) >= 0)
  161. {
  162. string CashOrderNo = "T1" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  163. Fields.Add("UserId", userInfo.Id); //创客Id
  164. Fields.Add("CreateMan", SysUserName + "_" + SysRealName); //操作人
  165. Fields.Add("TradeAmount", Amount); //提现金额
  166. Fields.Add("CashOrderNo", CashOrderNo); //提现单号
  167. Fields.Add("SeoKeyword", data.SeoKeyword); //备注
  168. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("UserCashRecordForBusiness", Fields, 0);
  169. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  170. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  171. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  172. account.BalanceAmount -= decimal.Parse(Amount);
  173. account.FreezeAmount += decimal.Parse(Amount);
  174. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  175. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  176. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  177. db.UserAccountRecord.Add(new UserAccountRecord()
  178. {
  179. CreateDate = DateTime.Now,
  180. UserId = userInfo.Id, //创客
  181. ChangeType = 132, //变动类型
  182. Kind = 2,
  183. ChangeAmount = decimal.Parse(Amount), //变更金额
  184. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  185. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  186. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  187. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  188. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  189. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  190. });
  191. AddSysLog(data.Id.ToString(), "UserCashRecordForBusiness", "add");
  192. db.SaveChanges();
  193. return "success";
  194. }
  195. else
  196. {
  197. return "创客可提现余额不足";
  198. }
  199. }
  200. else
  201. {
  202. return "输入的创客信息不存在或者创客编号和姓名不匹配";
  203. }
  204. }
  205. #endregion
  206. #region 获取创客账户信息
  207. public string GetReserve(string MakerCode, string RealName, string Amount)
  208. {
  209. var userInfo = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode && m.RealName == RealName) ?? new Users();
  210. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == userInfo.Id) ?? new UserAccount();
  211. return "当前余额为:" + account.BalanceAmount + "元 可提现余额为:" + (account.BalanceAmount - account.ToChargeAmount) + "元 提现后余额为:" + (account.BalanceAmount - decimal.Parse(Amount)) + "元";
  212. }
  213. #endregion
  214. #region 快捷导出Excel
  215. public IActionResult QuickExportExcel(string right)
  216. {
  217. ViewBag.RightInfo = RightInfo;
  218. ViewBag.right = right;
  219. return View();
  220. }
  221. [HttpPost]
  222. public string QuickExportExcelDo(string CashOrderNo, string MakerCode, string RealName, string CreateDateData)
  223. {
  224. Dictionary<string, string> Fields = new Dictionary<string, string>();
  225. string condition = " where 1=1 and a.Status>-1";
  226. //创客编号
  227. if (!string.IsNullOrEmpty(MakerCode))
  228. {
  229. condition += " and a.UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  230. }
  231. //创客名称
  232. if (!string.IsNullOrEmpty(RealName))
  233. {
  234. condition += " and a.UserId in (select Id from Users where RealName='" + RealName + "')";
  235. }
  236. if (!string.IsNullOrEmpty(CashOrderNo))
  237. {
  238. condition += " and a.CashOrderNo='" + CashOrderNo + "'";
  239. }
  240. if (!string.IsNullOrEmpty(CreateDateData))
  241. {
  242. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  243. var start = Convert.ToDateTime(Convert.ToDateTime(datelist[0]).ToString("yyyy-MM-dd"));
  244. var end = Convert.ToDateTime(Convert.ToDateTime(datelist[1]).ToString("yyyy-MM-dd") + " 23:59:59");
  245. var check = db.UserCashRecordForBusiness.Any(m => m.CreateDate >= start);
  246. var checks = db.UserCashRecordForBusiness.Any(m => m.CreateDate <= end);
  247. if (check)
  248. {
  249. var sId = db.UserCashRecordForBusiness.Where(m => m.CreateDate >= start).Min(m => m.Id);
  250. condition += " and a.Id >=" + sId;
  251. }
  252. if (checks)
  253. {
  254. var eId = db.UserCashRecordForBusiness.Where(m => m.CreateDate <= end).Max(m => m.Id);
  255. condition += " and a.Id <=" + eId;
  256. }
  257. }
  258. else
  259. {
  260. var start = Convert.ToDateTime(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01");
  261. var check = db.UserCashRecordForBusiness.Any(m => m.CreateDate >= start);
  262. if (check)
  263. {
  264. var minId = db.UserCashRecordForBusiness.Where(m => m.CreateDate >= start).Min(m => m.Id);
  265. var Info = function.ReadInstance("/WritePage/UserCashRecord/UserCashRecordForBusiness.txt");
  266. if (string.IsNullOrEmpty(Info.ToString()))
  267. {
  268. function.WritePage("/WritePage/UserCashRecord/", "UserCashRecordForBusiness.txt", minId.ToString());
  269. condition += " and a.Id >=" + minId;
  270. }
  271. else if (minId != int.Parse(Info))
  272. {
  273. function.WritePage("/WritePage/UserCashRecord/", "UserCashRecordForBusiness.txt", minId.ToString());
  274. condition += " and a.Id >=" + minId;
  275. }
  276. else
  277. {
  278. condition += " and a.Id >=" + Convert.ToInt32(Info);
  279. }
  280. }
  281. else
  282. {
  283. condition += " and a.Id =0";
  284. }
  285. }
  286. var Sql = "SELECT b.MakerCode '创客编号',b.RealName '创客姓名',a.CashOrderNo '提现单号',a.TradeAmount '提现金额',DATE_FORMAT(a.CreateDate,'%Y-%m-%d %H:%i:%s') '提现时间',a.SeoKeyword '备注',a.CreateMan '操作人' FROM UserCashRecordForBusiness a LEFT JOIN Users b ON a.UserId=b.Id" + condition;
  287. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
  288. var FileName = "直营团队提现记录" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  289. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  290. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  291. return "success";
  292. }
  293. #endregion
  294. }
  295. }