UserAccountController.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.MainModels;
  11. using LitJson;
  12. using Library;
  13. namespace MySystem.Areas.Api.Controllers.v1
  14. {
  15. [Area("Api")]
  16. [Route("Api/v1/[controller]/[action]")]
  17. public class UserAccountController : BaseController
  18. {
  19. public UserAccountController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 创客-我的-账户信息
  23. [Authorize]
  24. public JsonResult MyAccount(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. Dictionary<string, object> Obj = MyAccountDo(value);
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  30. }
  31. public Dictionary<string, object> MyAccountDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  35. Dictionary<string, object> Obj = new Dictionary<string, object>();
  36. UserAccount query = UserAccountDbconn.Instance.Get(UserId) ?? new UserAccount();
  37. Obj.Add("TotalAmount", query.TotalAmount); //总金额
  38. Obj.Add("BalanceAmount", query.BalanceAmount); //余额
  39. Obj.Add("ToChargeAmount", query.ToChargeAmount); //预扣款额度
  40. Obj.Add("WithdrawAmount", query.WithdrawAmount); //已提现金额
  41. Obj.Add("LeaderReserve", query.LeaderReserve); //盟主储蓄金
  42. Obj.Add("WithdrawFlag", query.QueryCount); //提现标记,1-已提现,0-未提现
  43. Obj.Add("SmallStoreDeposit", query.SmallStoreDeposit); //小分仓押金
  44. return Obj;
  45. }
  46. #endregion
  47. #region 创客-首页-统计数据
  48. [Authorize]
  49. public JsonResult MyStatData(string value)
  50. {
  51. value = DesDecrypt(value);
  52. JsonData data = JsonMapper.ToObject(value);
  53. Dictionary<string, object> Obj = MyStatDataDo(value);
  54. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  55. }
  56. public Dictionary<string, object> MyStatDataDo(string value)
  57. {
  58. JsonData data = JsonMapper.ToObject(value);
  59. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  60. Dictionary<string, object> Obj = new Dictionary<string, object>();
  61. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  62. string TradeMonth = DateTime.Now.ToString("yyyyMM"); //交易月
  63. // Obj.Add("TotalProfit", UserTradeDaySummaryDbconn.Instance.GetMonthTrade(UserId, TradeMonth, "team")); //总收益
  64. // Obj.Add("TeamTradeAmount", UserTradeDaySummaryDbconn.Instance.GetMonthTrade(UserId, TradeMonth, "team")); //团队交易额
  65. // Obj.Add("MerchantCount", UsersDbconn.Instance.GetTeamNewUserCount(UserId, TradeMonth)); //新增创客
  66. // Obj.Add("TeamMemberCount", UserDataDbconn.Instance.GetPosActCount(UserId, TradeMonth)); //累计激活POS机商户
  67. return Obj;
  68. }
  69. #endregion
  70. #region 创客-首页-仓库管理-申请机具-我的额度
  71. [Authorize]
  72. public JsonResult MyAmount(string value)
  73. {
  74. value = DesDecrypt(value);
  75. JsonData data = JsonMapper.ToObject(value);
  76. Dictionary<string, object> Obj = MyAmountDo(value);
  77. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  78. }
  79. public Dictionary<string, object> MyAmountDo(string value)
  80. {
  81. JsonData data = JsonMapper.ToObject(value);
  82. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
  83. Dictionary<string, object> Obj = new Dictionary<string, object>();
  84. List<Dictionary<string, object>> listStoreHouse = new List<Dictionary<string, object>>();
  85. UserAccount query = maindb.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount();
  86. var check = maindb.StoreHouseAmountPromiss.Any(m => m.ToUserId == UserId);
  87. decimal amount = 0;
  88. if (check)
  89. {
  90. amount = maindb.StoreHouseAmountPromiss.Where(m => m.Status == 1 && m.ToUserId == UserId).Sum(m => m.PromissAmount);
  91. }
  92. Obj.Add("Amount", query.ValidAmount); //可用总额度
  93. Obj.Add("TotalAmount", query.FixedAmount + query.TempAmount + query.TempAmountForBalance); //总额度
  94. Obj.Add("FixedAmount", query.FixedAmount); //固定额度
  95. Obj.Add("TempAmount", query.TempAmount + query.TempAmountForBalance); //临时额度
  96. Obj.Add("LeaderBalanceAmount", amount); //保证金额度
  97. var a = query.ValidAmount - amount;
  98. if (query.ValidAmount - amount >= query.TempAmount + query.TempAmountForBalance)
  99. {
  100. Obj.Add("OkTempAmount", query.TempAmount + query.TempAmountForBalance); //可用临时额度(可调低总临时额度金额)
  101. Obj.Add("cardLeast", query.TempAmount); //可用真实充值临时额度
  102. Obj.Add("balanceLeast", query.TempAmountForBalance); //可用余额充值临时额度
  103. }
  104. else if (query.ValidAmount - amount <= 0)
  105. {
  106. Obj.Add("OkTempAmount", 0); //可用临时额度(可调总低临时额度金额)
  107. Obj.Add("cardLeast", 0); //可用真实充值临时额度
  108. Obj.Add("balanceLeast", 0); //可用余额充值临时额度
  109. }
  110. else if (0 < query.ValidAmount - amount && query.ValidAmount - amount < query.TempAmount + query.TempAmountForBalance)
  111. {
  112. Obj.Add("OkTempAmount", query.ValidAmount - amount); //可用临时额度(可调低总临时额度金额)
  113. if (query.ValidAmount - amount <= query.TempAmount)
  114. {
  115. Obj.Add("cardLeast", query.ValidAmount - amount); //可用真实充值临时额度
  116. }
  117. if (query.ValidAmount - amount > query.TempAmount)
  118. {
  119. Obj.Add("cardLeast", query.TempAmount); //可用真实充值临时额度
  120. }
  121. if ( query.ValidAmount - amount <= query.TempAmountForBalance)
  122. {
  123. Obj.Add("balanceLeast", query.ValidAmount - amount); //可用余额充值临时额度
  124. }
  125. if ( query.ValidAmount - amount > query.TempAmountForBalance)
  126. {
  127. Obj.Add("balanceLeast", query.TempAmountForBalance); //可用余额充值临时额度
  128. }
  129. }
  130. return Obj;
  131. }
  132. #endregion
  133. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  134. /// <summary>
  135. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  136. /// </summary>
  137. /// <param name="value">请求的参数(json字符串)</param>
  138. /// <param name="signField">要签名的字段</param>
  139. /// <returns></returns>
  140. private string CheckSign(string value, string[] signField)
  141. {
  142. JsonData json = JsonMapper.ToObject(value);
  143. Dictionary<string, string> dic = new Dictionary<string, string>();
  144. for (int i = 0; i < signField.Length; i++)
  145. {
  146. dic.Add(signField[i], json[signField[i]].ToString());
  147. }
  148. string sign = json["sign"].ToString(); //客户端签名字符串
  149. return new Sign().sign(dic, sign);
  150. }
  151. #endregion
  152. }
  153. }