UserCashRecordController.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  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 QueryCountSelect, 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("TradeType", "0"); //交易类型
  60. string condition = " and Status>-1 and TradeType<3";
  61. //创客编号
  62. if (!string.IsNullOrEmpty(MakerCode))
  63. {
  64. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  65. }
  66. //创客名称
  67. if (!string.IsNullOrEmpty(RealName))
  68. {
  69. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  70. }
  71. //提现状态
  72. if (!string.IsNullOrEmpty(StatusSelect))
  73. {
  74. condition += " and Status=" + StatusSelect;
  75. }
  76. if (!string.IsNullOrEmpty(data.CashOrderNo))
  77. {
  78. condition += " and CashOrderNo='" + data.CashOrderNo + "'";
  79. }
  80. if (data.TradeType > 0)
  81. {
  82. condition += " and TradeType=" + data.TradeType;
  83. }
  84. //提交到代付状态
  85. if (!string.IsNullOrEmpty(QueryCountSelect))
  86. {
  87. if(QueryCountSelect == "0")
  88. {
  89. condition += " and QueryCount=" + QueryCountSelect;
  90. }
  91. else
  92. {
  93. condition += " and QueryCount>0";
  94. }
  95. }
  96. if (!string.IsNullOrEmpty(CreateDateData))
  97. {
  98. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  99. var start = Convert.ToDateTime(Convert.ToDateTime(datelist[0]).ToString("yyyy-MM-dd"));
  100. var end = Convert.ToDateTime(Convert.ToDateTime(datelist[1]).ToString("yyyy-MM-dd") + " 23:59:59");
  101. var check = db.UserCashRecord.Any(m => m.CreateDate >= start && m.TradeType < 3);
  102. var checks = db.UserCashRecord.Any(m => m.CreateDate <= end && m.TradeType < 3);
  103. if (check)
  104. {
  105. var sId = db.UserCashRecord.Where(m => m.CreateDate >= start && m.TradeType < 3).Min(m => m.Id);
  106. condition += " and Id >=" + sId;
  107. }
  108. if (checks)
  109. {
  110. var eId = db.UserCashRecord.Where(m => m.CreateDate <= end && m.TradeType < 3).Max(m => m.Id);
  111. condition += " and Id <=" + eId;
  112. }
  113. }
  114. else
  115. {
  116. var start = Convert.ToDateTime(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01");
  117. var check = db.UserCashRecord.Any(m => m.CreateDate >= start && m.TradeType < 3);
  118. if (check)
  119. {
  120. var minId = db.UserCashRecord.Where(m => m.CreateDate >= start && m.TradeType < 3).Min(m => m.Id);
  121. var Info = function.ReadInstance("/WritePage/UserCashRecord/UserCashRecord.txt");
  122. if (string.IsNullOrEmpty(Info.ToString()))
  123. {
  124. function.WritePage("/WritePage/UserCashRecord/", "UserCashRecord.txt", minId.ToString());
  125. condition += " and Id >=" + minId;
  126. }
  127. else
  128. {
  129. condition += " and Id >=" + Convert.ToInt32(Info);
  130. }
  131. }
  132. else
  133. {
  134. condition += " and Id =0";
  135. }
  136. }
  137. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("UserCashRecord", Fields, "Id desc", "0", page, limit, condition);
  138. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  139. foreach (Dictionary<string, object> dic in diclist)
  140. {
  141. int UserId = int.Parse(dic["UserId"].ToString());
  142. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  143. dic["MakerCode"] = user.MakerCode;
  144. dic["RealName"] = user.RealName;
  145. dic["TradeType"] = RelationClassForConst.GetTradeTypeInfo(int.Parse(dic["TradeType"].ToString()));
  146. int Status = int.Parse(dic["Status"].ToString());
  147. if (Status == 0) dic["StatusName"] = "处理中";
  148. if (Status == 1) dic["StatusName"] = "成功";
  149. if (Status == 2) dic["StatusName"] = "失败";
  150. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  151. if (QueryCount == 0) dic["LockName"] = "待提交";
  152. if (QueryCount > 0) dic["LockName"] = "已提交";
  153. }
  154. Dictionary<string, object> other = new Dictionary<string, object>();
  155. string WaitAmount = "0.00";//待处理总金额
  156. string SuccessAmount = "0.00";//提现成功总金额
  157. string FailAmount = "0.00";//提现失败总金额
  158. string WaitTaxAmount = "0.00";//待处理总金额(税后)
  159. string SuccessTaxAmount = "0.00";//提现成功总金额(税后)
  160. string FailTaxAmount = "0.00";//提现失败总金额(税后)
  161. DataTable dt = OtherMySqlConn.dtable("SELECT SUM(if(Status=0,TradeAmount,0)),SUM(if(Status=1,TradeAmount,0)),SUM(if(Status=2,TradeAmount,0)),SUM(if(Status=0,ActualTradeAmount,0)),SUM(if(Status=1,ActualTradeAmount,0)),SUM(if(Status=2,ActualTradeAmount,0)) FROM UserCashRecord where 1=1 " + condition);
  162. if (dt.Rows.Count > 0)
  163. {
  164. WaitAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  165. SuccessAmount = decimal.Parse(function.CheckNum(dt.Rows[0][1].ToString())).ToString("f2");
  166. FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][2].ToString())).ToString("f2");
  167. WaitTaxAmount = decimal.Parse(function.CheckNum(dt.Rows[0][3].ToString())).ToString("f2");
  168. SuccessTaxAmount = decimal.Parse(function.CheckNum(dt.Rows[0][4].ToString())).ToString("f2");
  169. FailTaxAmount = decimal.Parse(function.CheckNum(dt.Rows[0][5].ToString())).ToString("f2");
  170. }
  171. other.Add("WaitAmount", WaitAmount);
  172. other.Add("SuccessAmount", SuccessAmount);
  173. other.Add("FailAmount", FailAmount);
  174. other.Add("WaitTaxAmount", WaitTaxAmount);
  175. other.Add("SuccessTaxAmount", SuccessTaxAmount);
  176. other.Add("FailTaxAmount", FailTaxAmount);
  177. obj.Add("other", other);
  178. return Json(obj);
  179. }
  180. #endregion
  181. #region 增加提现记录
  182. /// <summary>
  183. /// 增加或修改提现记录信息
  184. /// </summary>
  185. /// <returns></returns>
  186. public IActionResult Add(string right)
  187. {
  188. ViewBag.RightInfo = RightInfo;
  189. ViewBag.right = right;
  190. return View();
  191. }
  192. #endregion
  193. #region 增加提现记录
  194. /// <summary>
  195. /// 增加或修改提现记录信息
  196. /// </summary>
  197. /// <returns></returns>
  198. [HttpPost]
  199. public string Add(UserCashRecord data)
  200. {
  201. Dictionary<string, object> Fields = new Dictionary<string, object>();
  202. Fields.Add("Remark", data.Remark); //备注
  203. Fields.Add("SeoTitle", data.SeoTitle);
  204. Fields.Add("SeoKeyword", data.SeoKeyword);
  205. Fields.Add("SeoDescription", data.SeoDescription);
  206. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("UserCashRecord", Fields, 0);
  207. AddSysLog(data.Id.ToString(), "UserCashRecord", "add");
  208. db.SaveChanges();
  209. return "success";
  210. }
  211. #endregion
  212. #region 修改提现记录
  213. /// <summary>
  214. /// 增加或修改提现记录信息
  215. /// </summary>
  216. /// <returns></returns>
  217. public IActionResult Edit(string right, int Id = 0)
  218. {
  219. ViewBag.RightInfo = RightInfo;
  220. ViewBag.right = right;
  221. UserCashRecord editData = db.UserCashRecord.FirstOrDefault(m => m.Id == Id) ?? new UserCashRecord();
  222. ViewBag.data = editData;
  223. return View();
  224. }
  225. #endregion
  226. #region 修改提现记录
  227. /// <summary>
  228. /// 增加或修改提现记录信息
  229. /// </summary>
  230. /// <returns></returns>
  231. [HttpPost]
  232. public string Edit(UserCashRecord data)
  233. {
  234. Dictionary<string, object> Fields = new Dictionary<string, object>();
  235. Fields.Add("Remark", data.Remark); //备注
  236. Fields.Add("SeoTitle", data.SeoTitle);
  237. Fields.Add("SeoKeyword", data.SeoKeyword);
  238. Fields.Add("SeoDescription", data.SeoDescription);
  239. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserCashRecord", Fields, data.Id);
  240. AddSysLog(data.Id.ToString(), "UserCashRecord", "update");
  241. db.SaveChanges();
  242. return "success";
  243. }
  244. #endregion
  245. #region 删除提现记录信息
  246. /// <summary>
  247. /// 删除提现记录信息
  248. /// </summary>
  249. /// <returns></returns>
  250. public string Delete(string Id)
  251. {
  252. string[] idlist = Id.Split(new char[] { ',' });
  253. AddSysLog(Id, "UserCashRecord", "del");
  254. foreach (string subid in idlist)
  255. {
  256. int id = int.Parse(subid);
  257. Dictionary<string, object> Fields = new Dictionary<string, object>();
  258. Fields.Add("Status", -1);
  259. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserCashRecord", Fields, id);
  260. }
  261. db.SaveChanges();
  262. return "success";
  263. }
  264. #endregion
  265. #region 开启
  266. /// <summary>
  267. /// 开启
  268. /// </summary>
  269. /// <returns></returns>
  270. public string Open(string Id)
  271. {
  272. string[] idlist = Id.Split(new char[] { ',' });
  273. AddSysLog(Id, "UserCashRecord", "open");
  274. foreach (string subid in idlist)
  275. {
  276. int id = int.Parse(subid);
  277. Dictionary<string, object> Fields = new Dictionary<string, object>();
  278. Fields.Add("Status", 1);
  279. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserCashRecord", Fields, id);
  280. }
  281. db.SaveChanges();
  282. return "success";
  283. }
  284. #endregion
  285. #region 关闭
  286. /// <summary>
  287. /// 关闭
  288. /// </summary>
  289. /// <returns></returns>
  290. public string Close(string Id)
  291. {
  292. string[] idlist = Id.Split(new char[] { ',' });
  293. AddSysLog(Id, "UserCashRecord", "close");
  294. foreach (string subid in idlist)
  295. {
  296. int id = int.Parse(subid);
  297. Dictionary<string, object> Fields = new Dictionary<string, object>();
  298. Fields.Add("Status", 0);
  299. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserCashRecord", Fields, id);
  300. }
  301. db.SaveChanges();
  302. return "success";
  303. }
  304. #endregion
  305. #region 批量设置成功
  306. /// <summary>
  307. /// 批量设置成功
  308. /// </summary>
  309. /// <returns></returns>
  310. public string BatchSetting(string Id)
  311. {
  312. string[] idlist = Id.Split(new char[] { ',' });
  313. AddSysLog(Id, "UserCashRecord", "BatchSetting");
  314. foreach (string subid in idlist)
  315. {
  316. int id = int.Parse(subid);
  317. Dictionary<string, object> Fields = new Dictionary<string, object>();
  318. Fields.Add("Status", 1);//设置提现记录为成功
  319. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserCashRecord", Fields, id);
  320. var userCashRecord = db.UserCashRecord.FirstOrDefault(m => m.Id == id) ?? new UserCashRecord();
  321. if (userCashRecord.Id > 0)
  322. {
  323. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == Convert.ToInt32(userCashRecord.UserId));
  324. if (account != null)
  325. {
  326. account.QueryCount = 1;
  327. decimal TradeAmount = userCashRecord.TradeAmount;
  328. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  329. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  330. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  331. account.WithdrawAmount += userCashRecord.TradeAmount;
  332. account.FreezeAmount -= userCashRecord.TradeAmount;
  333. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  334. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  335. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  336. db.UserAccountRecord.Add(new UserAccountRecord()
  337. {
  338. CreateDate = DateTime.Now,
  339. UpdateDate = DateTime.Now,
  340. UserId = userCashRecord.UserId, //创客
  341. ChangeType = 3, //变动类型
  342. ProductType = 99, //产品类型
  343. ChangeAmount = userCashRecord.ActualTradeAmount, //变更金额
  344. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  345. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  346. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  347. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  348. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  349. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  350. });
  351. db.UserAccountRecord.Add(new UserAccountRecord()
  352. {
  353. CreateDate = DateTime.Now,
  354. UpdateDate = DateTime.Now,
  355. UserId = userCashRecord.UserId, //创客
  356. ChangeType = 4, //变动类型
  357. ProductType = 99, //产品类型
  358. ChangeAmount = userCashRecord.TradeFee, //变更金额
  359. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  360. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  361. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  362. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  363. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  364. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  365. });
  366. db.UserAccountRecord.Add(new UserAccountRecord()
  367. {
  368. CreateDate = DateTime.Now,
  369. UpdateDate = DateTime.Now,
  370. UserId = userCashRecord.UserId, //创客
  371. ChangeType = 5, //变动类型
  372. ProductType = 99, //产品类型
  373. ChangeAmount = userCashRecord.ManageFee, //变更金额
  374. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  375. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  376. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  377. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  378. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  379. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  380. });
  381. db.SaveChanges();
  382. RedisDbconn.Instance.Set("UserAccount:" + userCashRecord.UserId, account);
  383. }
  384. }
  385. }
  386. db.SaveChanges();
  387. return "success";
  388. }
  389. #endregion
  390. #region 排序
  391. /// <summary>
  392. /// 排序
  393. /// </summary>
  394. /// <param name="Id"></param>
  395. public string Sort(int Id, int Sort)
  396. {
  397. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("UserCashRecord", Sort, Id);
  398. AddSysLog(Id.ToString(), "UserCashRecord", "sort");
  399. return "success";
  400. }
  401. #endregion
  402. #region 导入数据
  403. public IActionResult Import(string right)
  404. {
  405. ViewBag.RightInfo = RightInfo;
  406. ViewBag.right = right;
  407. return View();
  408. }
  409. /// <summary>
  410. /// 导入数据
  411. /// </summary>
  412. /// <param name="ExcelData"></param>
  413. [HttpPost]
  414. public string ImportPost(string ExcelPath)
  415. {
  416. string key = function.MD5_16(Guid.NewGuid().ToString());
  417. RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#UserCashRecord#cut#" + key + "#cut#" + SysUserName);
  418. return "success|" + key;
  419. }
  420. public string CheckImport(string key)
  421. {
  422. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  423. if (!string.IsNullOrEmpty(result))
  424. {
  425. string[] datalist = result.Split('|');
  426. if (datalist[0] == "success")
  427. {
  428. return result;
  429. }
  430. return datalist[0];
  431. }
  432. return "0";
  433. }
  434. #endregion
  435. #region 导出Excel
  436. /// <summary>
  437. /// 导出Excel
  438. /// </summary>
  439. /// <returns></returns>
  440. public JsonResult ExportExcel(UserCashRecord data, string MakerCode, string RealName, string StatusSelect, string QueryCountSelect, string CreateDateData)
  441. {
  442. Dictionary<string, string> Fields = new Dictionary<string, string>();
  443. Fields.Add("CashOrderNo", "1"); //提现单号
  444. Fields.Add("TradeType", "0"); //交易类型
  445. string condition = " and Status>-1 and TradeType<3";
  446. //创客编号
  447. if (!string.IsNullOrEmpty(MakerCode))
  448. {
  449. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  450. }
  451. //创客名称
  452. if (!string.IsNullOrEmpty(RealName))
  453. {
  454. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  455. }
  456. //提现状态
  457. if (!string.IsNullOrEmpty(StatusSelect))
  458. {
  459. condition += " and Status=" + StatusSelect;
  460. }
  461. if (!string.IsNullOrEmpty(data.CashOrderNo))
  462. {
  463. condition += " and CashOrderNo='" + data.CashOrderNo + "'";
  464. }
  465. if (data.TradeType > 0)
  466. {
  467. condition += " and TradeType=" + data.TradeType;
  468. }
  469. //提交到代付状态
  470. if (!string.IsNullOrEmpty(QueryCountSelect))
  471. {
  472. if(QueryCountSelect == "0")
  473. {
  474. condition += " and QueryCount=" + QueryCountSelect;
  475. }
  476. else
  477. {
  478. condition += " and QueryCount>0";
  479. }
  480. }
  481. if (!string.IsNullOrEmpty(CreateDateData))
  482. {
  483. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  484. var start = Convert.ToDateTime(Convert.ToDateTime(datelist[0]).ToString("yyyy-MM-dd"));
  485. var end = Convert.ToDateTime(Convert.ToDateTime(datelist[1]).ToString("yyyy-MM-dd") + " 23:59:59");
  486. var check = db.UserCashRecord.Any(m => m.CreateDate >= start && m.TradeType < 3);
  487. var checks = db.UserCashRecord.Any(m => m.CreateDate <= end && m.TradeType < 3);
  488. if (check)
  489. {
  490. var sId = db.UserCashRecord.Where(m => m.CreateDate >= start && m.TradeType < 3).Min(m => m.Id);
  491. condition += " and Id >=" + sId;
  492. }
  493. if (checks)
  494. {
  495. var eId = db.UserCashRecord.Where(m => m.CreateDate <= end && m.TradeType < 3).Max(m => m.Id);
  496. condition += " and Id <=" + eId;
  497. }
  498. }
  499. else
  500. {
  501. var start = Convert.ToDateTime(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01");
  502. var check = db.UserCashRecord.Any(m => m.CreateDate >= start && m.TradeType < 3);
  503. if (check)
  504. {
  505. var minId = db.UserCashRecord.Where(m => m.CreateDate >= start && m.TradeType < 3).Min(m => m.Id);
  506. var Info = function.ReadInstance("/WritePage/UserCashRecord/UserCashRecord.txt");
  507. if (string.IsNullOrEmpty(Info.ToString()))
  508. {
  509. function.WritePage("/WritePage/UserCashRecord/", "UserCashRecord.txt", minId.ToString());
  510. condition += " and Id >=" + minId;
  511. }
  512. else
  513. {
  514. condition += " and Id >=" + Convert.ToInt32(Info);
  515. }
  516. }
  517. else
  518. {
  519. condition += " and Id =0";
  520. }
  521. }
  522. 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,CreateDate", false);
  523. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  524. foreach (Dictionary<string, object> dic in diclist)
  525. {
  526. int UserId = int.Parse(dic["UserId"].ToString());
  527. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  528. dic["MakerCode"] = user.MakerCode;
  529. dic["RealName"] = user.RealName;
  530. dic["TradeType"] = RelationClassForConst.GetTradeTypeInfo(int.Parse(dic["TradeType"].ToString()));
  531. dic.Remove("UserId");
  532. int Status = int.Parse(dic["Status"].ToString());
  533. if (Status == 0) dic["StatusName"] = "处理中";
  534. if (Status == 1) dic["StatusName"] = "成功";
  535. if (Status == 2) dic["StatusName"] = "失败";
  536. dic.Remove("Status");
  537. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  538. if (QueryCount == 0) dic["LockName"] = "待提交";
  539. if (QueryCount > 0) dic["LockName"] = "已提交";
  540. dic.Remove("QueryCount");
  541. }
  542. Dictionary<string, object> result = new Dictionary<string, object>();
  543. result.Add("Status", "1");
  544. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  545. result.Add("Obj", diclist);
  546. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  547. ReturnFields.Add("CashOrderNo", "提现单号");
  548. ReturnFields.Add("MakerCode", "创客编号");
  549. ReturnFields.Add("RealName", "灵工姓名");
  550. ReturnFields.Add("Mobile", "手机号");
  551. ReturnFields.Add("IdCardNo", "身份证号");
  552. ReturnFields.Add("SettleBankName", "开户行名称");
  553. ReturnFields.Add("SettleBankCardNo", "开户行卡号");
  554. ReturnFields.Add("ActualTradeAmount", "发佣金额(单位:元)");
  555. ReturnFields.Add("LockName", "代付标记");
  556. ReturnFields.Add("StatusName", "状态");
  557. ReturnFields.Add("Remark", "备注");
  558. ReturnFields.Add("CreateDate", "创建时间");
  559. result.Add("Fields", ReturnFields);
  560. AddSysLog("0", "UserCashRecord", "ExportExcel");
  561. return Json(result);
  562. }
  563. #endregion
  564. #region 盟主提现记录列表
  565. /// <summary>
  566. /// 根据条件查询盟主提现记录列表
  567. /// </summary>
  568. /// <returns></returns>
  569. public IActionResult LeaderIndex(UserCashRecord data, string right)
  570. {
  571. ViewBag.RightInfo = RightInfo;
  572. ViewBag.right = right;
  573. string Condition = "";
  574. Condition += "CashOrderNo:\"" + data.CashOrderNo + "\",";
  575. Condition += "TradeType:\"" + data.TradeType + "\",";
  576. if (!string.IsNullOrEmpty(Condition))
  577. {
  578. Condition = Condition.TrimEnd(',');
  579. Condition = ", where: {" + Condition + "}";
  580. }
  581. ViewBag.Condition = Condition;
  582. return View();
  583. }
  584. #endregion
  585. #region 根据条件查询盟主提现记录列表
  586. /// <summary>
  587. /// 盟主提现记录列表
  588. /// </summary>
  589. /// <returns></returns>
  590. public JsonResult LeaderIndexData(UserCashRecord data, string MakerCode, string RealName, string StatusSelect, string QueryCountSelect, string CreateDateData, int page = 1, int limit = 30)
  591. {
  592. Dictionary<string, string> Fields = new Dictionary<string, string>();
  593. Fields.Add("CashOrderNo", "1"); //提现单号
  594. string condition = " and Status>-1 and TradeType=3";
  595. //创客编号
  596. if (!string.IsNullOrEmpty(MakerCode))
  597. {
  598. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  599. }
  600. //创客名称
  601. if (!string.IsNullOrEmpty(RealName))
  602. {
  603. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  604. }
  605. //提现状态
  606. if (!string.IsNullOrEmpty(StatusSelect))
  607. {
  608. condition += " and Status=" + StatusSelect;
  609. }
  610. if (!string.IsNullOrEmpty(data.CashOrderNo))
  611. {
  612. condition += " and CashOrderNo='" + data.CashOrderNo + "'";
  613. }
  614. if (data.TradeType > 0)
  615. {
  616. condition += " and TradeType=" + data.TradeType;
  617. }
  618. //提交到代付状态
  619. if (!string.IsNullOrEmpty(QueryCountSelect))
  620. {
  621. condition += " and QueryCount=" + QueryCountSelect;
  622. }
  623. if (!string.IsNullOrEmpty(CreateDateData))
  624. {
  625. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  626. var start = Convert.ToDateTime(Convert.ToDateTime(datelist[0]).ToString("yyyy-MM-dd"));
  627. var end = Convert.ToDateTime(Convert.ToDateTime(datelist[1]).ToString("yyyy-MM-dd") + " 23:59:59");
  628. var check = db.UserCashRecord.Any(m => m.CreateDate >= start && m.TradeType == 3);
  629. var checks = db.UserCashRecord.Any(m => m.CreateDate <= end && m.TradeType == 3);
  630. if (check)
  631. {
  632. var sId = db.UserCashRecord.Where(m => m.CreateDate >= start && m.TradeType == 3).Min(m => m.Id);
  633. condition += " and Id >=" + sId;
  634. }
  635. if (checks)
  636. {
  637. var eId = db.UserCashRecord.Where(m => m.CreateDate <= end && m.TradeType == 3).Max(m => m.Id);
  638. condition += " and Id <=" + eId;
  639. }
  640. }
  641. else
  642. {
  643. var start = Convert.ToDateTime(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01");
  644. var check = db.UserCashRecord.Any(m => m.CreateDate >= start && m.TradeType == 3);
  645. if (check)
  646. {
  647. var minId = db.UserCashRecord.Where(m => m.CreateDate >= start && m.TradeType == 3).Min(m => m.Id);
  648. var Info = function.ReadInstance("/WritePage/UserCashRecord/LeaderUserCashRecord.txt");
  649. if (string.IsNullOrEmpty(Info.ToString()))
  650. {
  651. function.WritePage("/WritePage/UserCashRecord/", "LeaderUserCashRecord.txt", minId.ToString());
  652. condition += " and Id >=" + minId;
  653. }
  654. else
  655. {
  656. condition += " and Id >=" + Convert.ToInt32(Info);
  657. }
  658. }
  659. else
  660. {
  661. condition += " and Id =0";
  662. }
  663. }
  664. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("UserCashRecord", Fields, "Id desc", "0", page, limit, condition);
  665. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  666. foreach (Dictionary<string, object> dic in diclist)
  667. {
  668. int UserId = int.Parse(dic["UserId"].ToString());
  669. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  670. dic["MakerCode"] = user.MakerCode;
  671. dic["RealName"] = user.RealName;
  672. dic["TradeType"] = RelationClassForConst.GetTradeTypeInfo(int.Parse(dic["TradeType"].ToString()));
  673. int Status = int.Parse(dic["Status"].ToString());
  674. if (Status == 0) dic["StatusName"] = "处理中";
  675. if (Status == 1) dic["StatusName"] = "成功";
  676. if (Status == 2) dic["StatusName"] = "失败";
  677. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  678. if (QueryCount == 0) dic["LockName"] = "待提交";
  679. if (QueryCount == 1) dic["LockName"] = "已提交";
  680. }
  681. Dictionary<string, object> other = new Dictionary<string, object>();
  682. string WaitAmount = "0.00";//待处理总金额
  683. string SuccessAmount = "0.00";//提现成功总金额
  684. string FailAmount = "0.00";//提现失败总金额
  685. DataTable dt = OtherMySqlConn.dtable("SELECT SUM(if(Status=0,TradeAmount,0)),SUM(if(Status=1,TradeAmount,0)),SUM(if(Status=2,TradeAmount,0)) FROM UserCashRecord where 1=1 " + condition);
  686. if (dt.Rows.Count > 0)
  687. {
  688. WaitAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  689. SuccessAmount = decimal.Parse(function.CheckNum(dt.Rows[0][1].ToString())).ToString("f2");
  690. FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][2].ToString())).ToString("f2");
  691. }
  692. other.Add("WaitAmount", WaitAmount);
  693. other.Add("SuccessAmount", SuccessAmount);
  694. other.Add("FailAmount", FailAmount);
  695. obj.Add("other", other);
  696. return Json(obj);
  697. }
  698. #endregion
  699. #region 导出盟主Excel
  700. /// <summary>
  701. /// 导出Excel
  702. /// </summary>
  703. /// <returns></returns>
  704. public JsonResult LeaderExportExcel(UserCashRecord data, string MakerCode, string RealName, string StatusSelect, string PayStatus)
  705. {
  706. Dictionary<string, string> Fields = new Dictionary<string, string>();
  707. Fields.Add("CashOrderNo", "1"); //提现单号
  708. Fields.Add("CreateDate", "3"); //创建时间
  709. string condition = " and Status>-1 and TradeType=3";
  710. //创客编号
  711. if (!string.IsNullOrEmpty(MakerCode))
  712. {
  713. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  714. }
  715. //创客名称
  716. if (!string.IsNullOrEmpty(RealName))
  717. {
  718. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  719. }
  720. //提现状态
  721. if (!string.IsNullOrEmpty(StatusSelect))
  722. {
  723. condition += " and Status=" + StatusSelect;
  724. }
  725. //提交到代付状态
  726. if (!string.IsNullOrEmpty(PayStatus))
  727. {
  728. int QueryCount = int.Parse(function.CheckInt(PayStatus));
  729. if (QueryCount == 2)
  730. {
  731. QueryCount = 0;
  732. }
  733. condition += " and QueryCount=" + QueryCount;
  734. }
  735. 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,CreateDate", false);
  736. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  737. foreach (Dictionary<string, object> dic in diclist)
  738. {
  739. int UserId = int.Parse(dic["UserId"].ToString());
  740. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  741. dic["MakerCode"] = user.MakerCode;
  742. dic["RealName"] = user.RealName;
  743. dic["Mobile"] = user.Mobile;
  744. dic["SettleBankName"] = user.SettleBankName;
  745. dic["SettleBankCardNo"] = user.SettleBankCardNo;
  746. dic.Remove("UserId");
  747. int Status = int.Parse(dic["Status"].ToString());
  748. if (Status == 0) dic["StatusName"] = "处理中";
  749. if (Status == 1) dic["StatusName"] = "成功";
  750. if (Status == 2) dic["StatusName"] = "失败";
  751. dic.Remove("Status");
  752. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  753. if (QueryCount == 0) dic["LockName"] = "待提交";
  754. if (QueryCount == 1) dic["LockName"] = "已提交";
  755. dic.Remove("QueryCount");
  756. }
  757. Dictionary<string, object> result = new Dictionary<string, object>();
  758. result.Add("Status", "1");
  759. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  760. result.Add("Obj", diclist);
  761. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  762. ReturnFields.Add("CashOrderNo", "提现单号");
  763. ReturnFields.Add("MakerCode", "创客编号");
  764. ReturnFields.Add("RealName", "灵工姓名");
  765. ReturnFields.Add("Mobile", "手机号");
  766. ReturnFields.Add("IdCardNo", "身份证号");
  767. ReturnFields.Add("SettleBankName", "开户行名称");
  768. ReturnFields.Add("SettleBankCardNo", "开户行卡号");
  769. ReturnFields.Add("ActualTradeAmount", "发佣金额(单位:元)");
  770. ReturnFields.Add("LockName", "代付标记");
  771. ReturnFields.Add("StatusName", "状态");
  772. ReturnFields.Add("Remark", "备注");
  773. ReturnFields.Add("CreateDate", "创建时间");
  774. result.Add("Fields", ReturnFields);
  775. AddSysLog("0", "UserCashRecord", "ExportExcel");
  776. return Json(result);
  777. }
  778. #endregion
  779. #region 助利宝提现记录列表
  780. /// <summary>
  781. /// 根据条件查询助利宝提现记录列表
  782. /// </summary>
  783. /// <returns></returns>
  784. public IActionResult HelpProfitIndex(UserCashRecord data, string right)
  785. {
  786. ViewBag.RightInfo = RightInfo;
  787. ViewBag.right = right;
  788. string Condition = "";
  789. Condition += "CashOrderNo:\"" + data.CashOrderNo + "\",";
  790. Condition += "TradeType:\"" + data.TradeType + "\",";
  791. if (!string.IsNullOrEmpty(Condition))
  792. {
  793. Condition = Condition.TrimEnd(',');
  794. Condition = ", where: {" + Condition + "}";
  795. }
  796. ViewBag.Condition = Condition;
  797. return View();
  798. }
  799. #endregion
  800. #region
  801. /// <summary>
  802. /// 助利宝提现记录列表
  803. /// </summary>
  804. /// <returns></returns>
  805. public JsonResult HelpProfitIndexData(UserCashRecord data, string MakerCode, string RealName, string StatusSelect, string QueryCountSelect, string CreateDateData, int page = 1, int limit = 30)
  806. {
  807. Dictionary<string, string> Fields = new Dictionary<string, string>();
  808. Fields.Add("CashOrderNo", "1"); //提现单号
  809. string condition = " and Status>-1 and TradeType=4";
  810. //创客编号
  811. if (!string.IsNullOrEmpty(MakerCode))
  812. {
  813. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  814. }
  815. //创客名称
  816. if (!string.IsNullOrEmpty(RealName))
  817. {
  818. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  819. }
  820. //提现状态
  821. if (!string.IsNullOrEmpty(StatusSelect))
  822. {
  823. condition += " and Status=" + StatusSelect;
  824. }
  825. if (!string.IsNullOrEmpty(data.CashOrderNo))
  826. {
  827. condition += " and CashOrderNo='" + data.CashOrderNo + "'";
  828. }
  829. if (data.TradeType > 0)
  830. {
  831. condition += " and TradeType=" + data.TradeType;
  832. }
  833. //提交到代付状态
  834. if (!string.IsNullOrEmpty(QueryCountSelect))
  835. {
  836. condition += " and QueryCount=" + QueryCountSelect;
  837. }
  838. if (!string.IsNullOrEmpty(CreateDateData))
  839. {
  840. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  841. string start = datelist[0];
  842. string end = datelist[1];
  843. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  844. }
  845. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("UserCashRecord", Fields, "Id desc", "0", page, limit, condition);
  846. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  847. foreach (Dictionary<string, object> dic in diclist)
  848. {
  849. int UserId = int.Parse(dic["UserId"].ToString());
  850. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  851. dic["MakerCode"] = user.MakerCode;
  852. dic["RealName"] = user.RealName;
  853. dic["TradeType"] = RelationClassForConst.GetTradeTypeInfo(int.Parse(dic["TradeType"].ToString()));
  854. int Status = int.Parse(dic["Status"].ToString());
  855. if (Status == 0) dic["StatusName"] = "处理中";
  856. if (Status == 1) dic["StatusName"] = "成功";
  857. if (Status == 2) dic["StatusName"] = "失败";
  858. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  859. if (QueryCount == 0) dic["LockName"] = "待提交";
  860. if (QueryCount == 1) dic["LockName"] = "已提交";
  861. }
  862. Dictionary<string, object> other = new Dictionary<string, object>();
  863. string WaitAmount = "0.00";//待处理总金额
  864. string SuccessAmount = "0.00";//提现成功总金额
  865. string FailAmount = "0.00";//提现失败总金额
  866. DataTable dt = OtherMySqlConn.dtable("SELECT SUM(if(Status=0,TradeAmount,0)),SUM(if(Status=1,TradeAmount,0)),SUM(if(Status=2,TradeAmount,0)) FROM UserCashRecord where 1=1 " + condition);
  867. if (dt.Rows.Count > 0)
  868. {
  869. WaitAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  870. SuccessAmount = decimal.Parse(function.CheckNum(dt.Rows[0][1].ToString())).ToString("f2");
  871. FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][2].ToString())).ToString("f2");
  872. }
  873. other.Add("WaitAmount", WaitAmount);
  874. other.Add("SuccessAmount", SuccessAmount);
  875. other.Add("FailAmount", FailAmount);
  876. obj.Add("other", other);
  877. return Json(obj);
  878. }
  879. #endregion
  880. #region 导出助利宝Excel
  881. /// <summary>
  882. /// 导出Excel
  883. /// </summary>
  884. /// <returns></returns>
  885. public JsonResult HelpProfitExportExcel(UserCashRecord data, string MakerCode, string RealName, string StatusSelect, string PayStatus)
  886. {
  887. Dictionary<string, string> Fields = new Dictionary<string, string>();
  888. Fields.Add("CashOrderNo", "1"); //提现单号
  889. Fields.Add("CreateDate", "3"); //创建时间
  890. string condition = " and Status>-1 and TradeType=4";
  891. //创客编号
  892. if (!string.IsNullOrEmpty(MakerCode))
  893. {
  894. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  895. }
  896. //创客名称
  897. if (!string.IsNullOrEmpty(RealName))
  898. {
  899. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  900. }
  901. //提现状态
  902. if (!string.IsNullOrEmpty(StatusSelect))
  903. {
  904. condition += " and Status=" + StatusSelect;
  905. }
  906. //提交到代付状态
  907. if (!string.IsNullOrEmpty(PayStatus))
  908. {
  909. int QueryCount = int.Parse(function.CheckInt(PayStatus));
  910. if (QueryCount == 2)
  911. {
  912. QueryCount = 0;
  913. }
  914. condition += " and QueryCount=" + QueryCount;
  915. }
  916. 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,CreateDate", false);
  917. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  918. foreach (Dictionary<string, object> dic in diclist)
  919. {
  920. int UserId = int.Parse(dic["UserId"].ToString());
  921. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  922. dic["MakerCode"] = user.MakerCode;
  923. dic["RealName"] = user.RealName;
  924. dic["Mobile"] = user.Mobile;
  925. dic["SettleBankName"] = user.SettleBankName;
  926. dic["SettleBankCardNo"] = user.SettleBankCardNo;
  927. dic.Remove("UserId");
  928. int Status = int.Parse(dic["Status"].ToString());
  929. if (Status == 0) dic["StatusName"] = "处理中";
  930. if (Status == 1) dic["StatusName"] = "成功";
  931. if (Status == 2) dic["StatusName"] = "失败";
  932. dic.Remove("Status");
  933. int QueryCount = int.Parse(dic["QueryCount"].ToString());
  934. if (QueryCount == 0) dic["LockName"] = "待提交";
  935. if (QueryCount == 1) dic["LockName"] = "已提交";
  936. dic.Remove("QueryCount");
  937. }
  938. Dictionary<string, object> result = new Dictionary<string, object>();
  939. result.Add("Status", "1");
  940. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  941. result.Add("Obj", diclist);
  942. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  943. ReturnFields.Add("CashOrderNo", "提现单号");
  944. ReturnFields.Add("MakerCode", "创客编号");
  945. ReturnFields.Add("RealName", "灵工姓名");
  946. ReturnFields.Add("Mobile", "手机号");
  947. ReturnFields.Add("IdCardNo", "身份证号");
  948. ReturnFields.Add("SettleBankName", "开户行名称");
  949. ReturnFields.Add("SettleBankCardNo", "开户行卡号");
  950. ReturnFields.Add("ActualTradeAmount", "发佣金额(单位:元)");
  951. ReturnFields.Add("LockName", "代付标记");
  952. ReturnFields.Add("StatusName", "状态");
  953. ReturnFields.Add("Remark", "备注");
  954. ReturnFields.Add("CreateDate", "创建时间");
  955. result.Add("Fields", ReturnFields);
  956. AddSysLog("0", "UserCashRecord", "ExportExcel");
  957. return Json(result);
  958. }
  959. #endregion
  960. #region 提交代付平台
  961. public IActionResult Cash(string right)
  962. {
  963. ViewBag.RightInfo = RightInfo;
  964. ViewBag.right = right;
  965. return View();
  966. }
  967. /// <summary>
  968. /// 提交代付平台
  969. /// </summary>
  970. /// <returns></returns>
  971. [HttpPost]
  972. public string Cash(string Id, int Channel = 1)
  973. {
  974. string[] idlist = Id.Split(new char[] { ',' });
  975. AddSysLog(Id, "UserCashRecord", "cash");
  976. db.SaveChanges();
  977. CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == "CashWithoutUser") ?? new CustomTagSet();
  978. string MakerCodeString = "," + set.Contents + ",";
  979. foreach (string subid in idlist)
  980. {
  981. int id = int.Parse(subid);
  982. UserCashRecord edit = db.UserCashRecord.FirstOrDefault(m => m.Id == id && m.QueryCount == 0);
  983. if (edit != null)
  984. {
  985. Users user = db.Users.FirstOrDefault(m => m.Id == edit.UserId) ?? new Users();
  986. if (!MakerCodeString.Contains("," + user.MakerCode + ","))
  987. {
  988. edit.QueryCount = Channel;
  989. edit.UpdateDate = DateTime.Now;
  990. db.SaveChanges();
  991. if(Channel == 1)
  992. {
  993. RedisDbconn.Instance.AddList("CashPayApplyQueue", Newtonsoft.Json.JsonConvert.SerializeObject(edit));
  994. }
  995. else if(Channel == 2)
  996. {
  997. RedisDbconn.Instance.AddList("JkCashPayApplyQueue", Newtonsoft.Json.JsonConvert.SerializeObject(edit));
  998. }
  999. }
  1000. }
  1001. }
  1002. return "success";
  1003. }
  1004. #endregion
  1005. #region 拒绝
  1006. /// <summary>
  1007. /// 拒绝
  1008. /// </summary>
  1009. /// <returns></returns>
  1010. public IActionResult Reduce(string right, int Id = 0)
  1011. {
  1012. ViewBag.RightInfo = RightInfo;
  1013. ViewBag.right = right;
  1014. UserCashRecord editData = db.UserCashRecord.FirstOrDefault(m => m.Id == Id) ?? new UserCashRecord();
  1015. ViewBag.data = editData;
  1016. return View();
  1017. }
  1018. #endregion
  1019. #region 拒绝
  1020. /// <summary>
  1021. /// 拒绝
  1022. /// </summary>
  1023. /// <returns></returns>
  1024. public string ReduceDo(int Id, string Remark)
  1025. {
  1026. AddSysLog(Id, "UserCashRecord", "Reduce");
  1027. UserCashRecord edit = db.UserCashRecord.FirstOrDefault(m => m.Id == Id);
  1028. if (edit != null)
  1029. {
  1030. if (edit.TradeType == 3)
  1031. {
  1032. edit.Status = 2;
  1033. edit.Remark = Remark;
  1034. edit.UpdateMan = SysUserName;
  1035. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == edit.UserId);
  1036. if (account != null)
  1037. {
  1038. decimal TradeAmount = edit.TradeAmount;
  1039. account.LeaderBalanceAmount += TradeAmount;
  1040. db.LeaderAccountRecord.Add(new LeaderAccountRecord()
  1041. {
  1042. CreateDate = DateTime.Now,
  1043. UserId = edit.UserId, //创客
  1044. ChangeType = 6, //变动类型
  1045. ProductType = 99, //产品类型
  1046. ChangeAmount = TradeAmount, //变更金额
  1047. BeforeBalanceAmount = account.LeaderBalanceAmount - TradeAmount, //变更前余额
  1048. AfterBalanceAmount = account.LeaderBalanceAmount, //变更后余额
  1049. });
  1050. db.SaveChanges();
  1051. RedisDbconn.Instance.Set("UserAccount:" + edit.UserId, account);
  1052. }
  1053. }
  1054. else if (edit.TradeType == 4)
  1055. {
  1056. edit.Status = 2;
  1057. edit.Remark = Remark;
  1058. edit.UpdateMan = SysUserName;
  1059. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == edit.UserId);
  1060. if (account != null)
  1061. {
  1062. decimal TradeAmount = edit.TradeAmount;
  1063. account.HelpProfitBalanceAmount += TradeAmount;
  1064. db.HelpProfitAccountRecord.Add(new HelpProfitAccountRecord()
  1065. {
  1066. CreateDate = DateTime.Now,
  1067. UserId = edit.UserId, //创客
  1068. ChangeType = 6, //变动类型
  1069. ProductType = 99, //产品类型
  1070. ChangeAmount = TradeAmount, //变更金额
  1071. BeforeBalanceAmount = account.HelpProfitBalanceAmount - TradeAmount, //变更前余额
  1072. AfterBalanceAmount = account.HelpProfitBalanceAmount, //变更后余额
  1073. });
  1074. db.SaveChanges();
  1075. RedisDbconn.Instance.Set("UserAccount:" + edit.UserId, account);
  1076. }
  1077. }
  1078. else
  1079. {
  1080. edit.Status = 2;
  1081. edit.Remark = Remark;
  1082. edit.UpdateMan = SysUserName;
  1083. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == edit.UserId);
  1084. if (account != null)
  1085. {
  1086. decimal TradeAmount = edit.TradeAmount;
  1087. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  1088. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  1089. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  1090. account.BalanceAmount += TradeAmount;
  1091. if (account.FreezeAmount >= TradeAmount)
  1092. {
  1093. account.FreezeAmount -= TradeAmount;
  1094. }
  1095. else
  1096. {
  1097. return "冻结金额不足";
  1098. }
  1099. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  1100. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  1101. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  1102. db.UserAccountRecord.Add(new UserAccountRecord()
  1103. {
  1104. CreateDate = DateTime.Now,
  1105. UpdateDate = DateTime.Now,
  1106. UserId = edit.UserId, //创客
  1107. ChangeType = 6, //变动类型
  1108. ProductType = 99, //产品类型
  1109. ChangeAmount = TradeAmount, //变更金额
  1110. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  1111. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  1112. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  1113. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  1114. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  1115. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  1116. });
  1117. db.SaveChanges();
  1118. RedisDbconn.Instance.Set("UserAccount:" + edit.UserId, account);
  1119. }
  1120. }
  1121. db.SaveChanges();
  1122. }
  1123. return "success";
  1124. }
  1125. #endregion
  1126. #region 解除
  1127. /// <summary>
  1128. /// 解除
  1129. /// </summary>
  1130. /// <returns></returns>
  1131. public string Cancel(string Id)
  1132. {
  1133. string[] idlist = Id.Split(new char[] { ',' });
  1134. AddSysLog(Id, "WithdrawRecord", "Cancel");
  1135. foreach (string subid in idlist)
  1136. {
  1137. int id = int.Parse(subid);
  1138. UserCashRecord edit = db.UserCashRecord.FirstOrDefault(m => m.Id == id);
  1139. if (edit != null)
  1140. {
  1141. edit.QueryCount = 0;
  1142. db.SaveChanges();
  1143. }
  1144. }
  1145. return "success";
  1146. }
  1147. #endregion
  1148. #region 退汇
  1149. /// <summary>
  1150. /// 退汇
  1151. /// </summary>
  1152. /// <returns></returns>
  1153. public string Refund(string Id)
  1154. {
  1155. string[] idlist = Id.Split(new char[] { ',' });
  1156. AddSysLog(Id, "退汇", "Refund");
  1157. foreach (string subid in idlist)
  1158. {
  1159. int id = int.Parse(subid);
  1160. var userCashRecord = db.UserCashRecord.FirstOrDefault(m => m.Id == id) ?? new UserCashRecord();
  1161. DataTable dt = OtherMySqlConn.dtable("DELETE FROM UserAccountRecord WHERE Version=" + userCashRecord.Id + "");
  1162. userCashRecord.Status = 0;
  1163. userCashRecord.QueryCount = 0;
  1164. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == userCashRecord.UserId) ?? new UserAccount();
  1165. userAccount.WithdrawAmount -= userCashRecord.TradeAmount;
  1166. userAccount.FreezeAmount += userCashRecord.TradeAmount;
  1167. db.SaveChanges();
  1168. }
  1169. return "success";
  1170. }
  1171. #endregion
  1172. }
  1173. }