UserCashRecordController.cs 50 KB

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