UserCashRecordForBusinessController.cs 15 KB

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