PublicFunction.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.MainModels;
  5. using Library;
  6. namespace MySystem
  7. {
  8. public class PublicFunction
  9. {
  10. #region 根据ParentNav获取顶级创客Id
  11. public static int GetTopUserId(string ParentNav)
  12. {
  13. int TopUserId = 0;
  14. if (!string.IsNullOrEmpty(ParentNav))
  15. {
  16. TopUserId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  17. }
  18. return TopUserId;
  19. }
  20. #endregion
  21. #region 隐藏身份证号
  22. public static string HideCertId(string str)
  23. {
  24. return str.Substring(0, 3) + "***********" + str.Substring(14);
  25. }
  26. #endregion
  27. #region 隐藏姓名
  28. public static string HideRealName(string str)
  29. {
  30. string result = "";
  31. for (int i = 0; i < str.Length; i++)
  32. {
  33. if (i == 0)
  34. {
  35. result += str.Substring(i, 1);
  36. }
  37. else
  38. {
  39. result += "*";
  40. }
  41. }
  42. return result;
  43. }
  44. #endregion
  45. #region 姓名脱敏
  46. /// <summary>
  47. /// 姓名敏感处理
  48. /// </summary>
  49. /// <param name="fullName">姓名</param>
  50. /// <returns>脱敏后的姓名</returns>
  51. public static string SetSensitiveName(string fullName)
  52. {
  53. if (string.IsNullOrEmpty(fullName)) return string.Empty;
  54. string familyName = fullName.Substring(0, 1);
  55. string end = fullName.Substring(fullName.Length - 1, 1);
  56. string name = string.Empty;
  57. //长度为2
  58. if (fullName.Length <= 2) name = familyName + "*";
  59. //长度⼤于2
  60. else if (fullName.Length >= 3)
  61. {
  62. name = familyName.PadRight(fullName.Length - 1, '*') + end;
  63. }
  64. return name;
  65. }
  66. #endregion
  67. #region 统计机具绑定数据
  68. public static void StatUserMachineData(int UserId, int BrandId, int Count)
  69. {
  70. using (WebCMSEntities db = new WebCMSEntities())
  71. {
  72. string IdBrand = UserId + "_" + BrandId;
  73. UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  74. if (MachineData == null)
  75. {
  76. MachineData = db.UserMachineData.Add(new UserMachineData()
  77. {
  78. IdBrand = IdBrand,
  79. }).Entity;
  80. db.SaveChanges();
  81. }
  82. if(Count < 0)
  83. {
  84. MachineData.TotalMachineCount -= Math.Abs(Count);
  85. MachineData.UnBindCount -= Math.Abs(Count);
  86. }
  87. else
  88. {
  89. MachineData.TotalMachineCount += Count;
  90. MachineData.UnBindCount += Count;
  91. }
  92. db.SaveChanges();
  93. }
  94. }
  95. #endregion
  96. #region 设置押金添加记录公共方法
  97. public static void MerchantDepositSet(int BrandId, int UserId, int SnId, string SnNo, int BeforeDeposit, decimal DepositAmount, string ReturnNote)
  98. {
  99. try
  100. {
  101. WebCMSEntities maindb = new WebCMSEntities();
  102. MerchantDepositSet query = maindb.MerchantDepositSet.Add(new MerchantDepositSet()
  103. {
  104. CreateDate = DateTime.Now, //创建时间
  105. Sort = BrandId,//品牌
  106. SeoTitle = BeforeDeposit.ToString(),//变更前押金
  107. DepositAmount = DepositAmount,//押金
  108. ReturnNote = ReturnNote,//返回信息
  109. SnNo = SnNo,//机具Sn
  110. UserId = UserId,//创客Id
  111. }).Entity;
  112. maindb.SaveChanges();
  113. }
  114. catch (Exception ex)
  115. {
  116. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":" + ex.ToString(), "设置押金队列异常");
  117. }
  118. }
  119. #endregion
  120. //收支明细类别结合
  121. public static List<int> IncomeTypes()
  122. {
  123. List<int> list = new List<int>();
  124. list.Add(0);
  125. list.Add(1);
  126. list.Add(12);
  127. list.Add(31);
  128. list.Add(50);
  129. list.Add(60);
  130. list.Add(64);
  131. list.Add(66);
  132. list.Add(111);
  133. list.Add(112);
  134. list.Add(113);
  135. list.Add(114);
  136. list.Add(115);
  137. list.Add(116);
  138. list.Add(117);
  139. list.Add(118);
  140. list.Add(119);
  141. list.Add(120);
  142. list.Add(121);
  143. list.Add(122);
  144. list.Add(123);
  145. list.Add(126);
  146. return list;
  147. }
  148. public static List<int> ExpendTypes()
  149. {
  150. List<int> list = new List<int>();
  151. list.Add(3);
  152. list.Add(4);
  153. list.Add(5);
  154. list.Add(20);
  155. list.Add(63);
  156. list.Add(65);
  157. list.Add(124);
  158. list.Add(125);
  159. return list;
  160. }
  161. }
  162. }