UserAccountService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * 账户
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Operate;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Operate
  12. {
  13. public class UserAccountService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["OpSqlConnStr"].ToString();
  16. // public UserAccountService()
  17. // {
  18. // _conn = ConfigurationManager.AppSettings["OpSqlConnStr"].ToString();
  19. // }
  20. /// <summary>
  21. /// 查询列表
  22. /// </summary>
  23. /// <param name="relationData">关联表</param>
  24. /// <param name="condition">查询条件(sql语句)</param>
  25. /// <param name="count">总数(输出)</param>
  26. /// <param name="page">页码</param>
  27. /// <param name="limit">每页条数</param>
  28. /// <returns></returns>
  29. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, out int count, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  30. {
  31. List<string> fields = new List<string>(); //要显示的列
  32. fields.Add("Id");
  33. fields.Add("CreateDate"); //添加时间
  34. fields.Add("Status"); //状态
  35. fields.Add("UserId"); //运营中心
  36. fields.Add("TotalAmount"); //总金额
  37. fields.Add("FreezeAmount"); //冻结金额
  38. fields.Add("BalanceAmount"); //余额
  39. fields.Add("AccountStatus"); //账户状态
  40. fields.Add("WithdrawAmount"); //已提现金额
  41. fields.Add("TotalAmt"); //总额度
  42. fields.Add("ValidAmount"); //可用额度
  43. fields.Add("WithdrawingAmount"); //提现中金额
  44. fields.Add("PosCouponApplyAmount"); //机具券申请金额
  45. fields.Add("ValidForGetAmount"); //可提现额度
  46. Dictionary<string, object> obj = new DbService(AppConfig.Base.opTables, _conn).IndexData("UserAccount", relationData, orderBy, page, limit, condition, fields);
  47. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  48. count = int.Parse(obj["count"].ToString());
  49. return diclist;
  50. }
  51. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  52. {
  53. List<string> fields = new List<string>(); //要显示的列
  54. fields.Add("Id");
  55. fields.Add("CreateDate"); //添加时间
  56. fields.Add("Status"); //状态
  57. fields.Add("UserId"); //运营中心
  58. fields.Add("TotalAmount"); //总金额
  59. fields.Add("FreezeAmount"); //冻结金额
  60. fields.Add("BalanceAmount"); //余额
  61. fields.Add("AccountStatus"); //账户状态
  62. fields.Add("WithdrawAmount"); //已提现金额
  63. fields.Add("TotalAmt"); //总额度
  64. fields.Add("ValidAmount"); //可用额度
  65. fields.Add("WithdrawingAmount"); //提现中金额
  66. fields.Add("PosCouponApplyAmount"); //机具券申请金额
  67. fields.Add("ValidForGetAmount"); //可提现额度
  68. Dictionary<string, object> obj = new DbService(AppConfig.Base.opTables, _conn).IndexData("UserAccount", relationData, orderBy, page, limit, condition, fields);
  69. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  70. return diclist;
  71. }
  72. /// <summary>
  73. /// 查询一条记录
  74. /// </summary>
  75. /// <param name="Id">主键Id</param>
  76. /// <returns></returns>
  77. public static UserAccount Query(int Id)
  78. {
  79. WebCMSEntities db = new WebCMSEntities();
  80. UserAccount editData = db.UserAccount.FirstOrDefault(m => m.Id == Id) ?? new UserAccount();
  81. db.Dispose();
  82. return editData;
  83. }
  84. /// <summary>
  85. /// 查询记录数
  86. /// </summary>
  87. /// <param name="Id">主键Id</param>
  88. /// <returns></returns>
  89. public static int Count(string condition = "")
  90. {
  91. int result = 0;
  92. DataTable dt = CustomerSqlConn.dtable("select count(Id) from UserAccount where 1=1" + condition, _conn);
  93. if (dt.Rows.Count > 0)
  94. {
  95. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  96. }
  97. return result;
  98. }
  99. /// <summary>
  100. /// 查询是否存在
  101. /// </summary>
  102. /// <param name="Id">主键Id</param>
  103. /// <returns></returns>
  104. public static bool Exist(int Id)
  105. {
  106. WebCMSEntities db = new WebCMSEntities();
  107. bool check = db.UserAccount.Any(m => m.Id == Id);
  108. db.Dispose();
  109. return check;
  110. }
  111. /// <summary>
  112. /// 添加数据
  113. /// </summary>
  114. /// <param name="Fields">要设置的字段</param>
  115. /// <returns></returns>
  116. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  117. {
  118. if (check)
  119. {
  120. if (string.IsNullOrEmpty(fields["TotalAmount"].ToString()))
  121. {
  122. return new AppResultJson() { Status = "-1", Info = "请填写总金额" };
  123. }
  124. if (!function.IsNum(fields["TotalAmount"].ToString()))
  125. {
  126. return new AppResultJson() { Status = "-1", Info = "请填写正确的总金额" };
  127. }
  128. if (string.IsNullOrEmpty(fields["FreezeAmount"].ToString()))
  129. {
  130. return new AppResultJson() { Status = "-1", Info = "请填写冻结金额" };
  131. }
  132. if (!function.IsNum(fields["FreezeAmount"].ToString()))
  133. {
  134. return new AppResultJson() { Status = "-1", Info = "请填写正确的冻结金额" };
  135. }
  136. if (string.IsNullOrEmpty(fields["BalanceAmount"].ToString()))
  137. {
  138. return new AppResultJson() { Status = "-1", Info = "请填写余额" };
  139. }
  140. if (!function.IsNum(fields["BalanceAmount"].ToString()))
  141. {
  142. return new AppResultJson() { Status = "-1", Info = "请填写正确的余额" };
  143. }
  144. if (string.IsNullOrEmpty(fields["WithdrawAmount"].ToString()))
  145. {
  146. return new AppResultJson() { Status = "-1", Info = "请填写已提现金额" };
  147. }
  148. if (!function.IsNum(fields["WithdrawAmount"].ToString()))
  149. {
  150. return new AppResultJson() { Status = "-1", Info = "请填写正确的已提现金额" };
  151. }
  152. if (string.IsNullOrEmpty(fields["WithdrawingAmount"].ToString()))
  153. {
  154. return new AppResultJson() { Status = "-1", Info = "请填写提现中金额" };
  155. }
  156. if (!function.IsNum(fields["WithdrawingAmount"].ToString()))
  157. {
  158. return new AppResultJson() { Status = "-1", Info = "请填写正确的提现中金额" };
  159. }
  160. if (string.IsNullOrEmpty(fields["PosCouponApplyAmount"].ToString()))
  161. {
  162. return new AppResultJson() { Status = "-1", Info = "请填写机具券申请金额" };
  163. }
  164. if (!function.IsNum(fields["PosCouponApplyAmount"].ToString()))
  165. {
  166. return new AppResultJson() { Status = "-1", Info = "请填写正确的机具券申请金额" };
  167. }
  168. if (string.IsNullOrEmpty(fields["ValidForGetAmount"].ToString()))
  169. {
  170. return new AppResultJson() { Status = "-1", Info = "请填写可提现额度" };
  171. }
  172. if (!function.IsNum(fields["ValidForGetAmount"].ToString()))
  173. {
  174. return new AppResultJson() { Status = "-1", Info = "请填写正确的可提现额度" };
  175. }
  176. }
  177. int Id = new DbService(AppConfig.Base.opTables, _conn).Add("UserAccount", fields, 0);
  178. return new AppResultJson() { Status = "1", Data = Id };
  179. }
  180. /// <summary>
  181. /// 修改数据
  182. /// </summary>
  183. /// <param name="Fields">要设置的字段</param>
  184. /// <param name="Id">主键Id</param>
  185. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  186. {
  187. new DbService(AppConfig.Base.opTables, _conn).Edit("UserAccount", fields, Id);
  188. return new AppResultJson() { Status = "1", Data = Id };
  189. }
  190. /// <summary>
  191. /// 逻辑删除
  192. /// </summary>
  193. /// <param name="Id">主键Id</param>
  194. public static void Remove(int Id)
  195. {
  196. Dictionary<string, object> fields = new Dictionary<string, object>();
  197. fields.Add("Status", -1);
  198. new DbService(AppConfig.Base.opTables, _conn).Edit("UserAccount", fields, Id);
  199. }
  200. /// <summary>
  201. /// 删除数据
  202. /// </summary>
  203. /// <param name="Id">主键Id</param>
  204. public static void Delete(int Id)
  205. {
  206. new DbService(AppConfig.Base.opTables, _conn).Delete("UserAccount", Id);
  207. }
  208. /// <summary>
  209. /// 排序
  210. /// </summary>
  211. /// <param name="Id">主键Id</param>
  212. /// <param name="Sort">排序序号</param>
  213. public static void Sort(int Id, int Sort)
  214. {
  215. new DbService(AppConfig.Base.opTables, _conn).Sort("UserAccount", Sort, Id);
  216. }
  217. /// <summary>
  218. /// 导入数据
  219. /// </summary>
  220. /// <param name="ExcelData">json数据</param>
  221. public static void Import(string ExcelData)
  222. {
  223. WebCMSEntities db = new WebCMSEntities();
  224. JsonData list = JsonMapper.ToObject(ExcelData);
  225. for (int i = 1; i < list.Count; i++)
  226. {
  227. JsonData dr = list[i];
  228. db.UserAccount.Add(new UserAccount()
  229. {
  230. CreateDate = DateTime.Now,
  231. UpdateDate = DateTime.Now,
  232. });
  233. db.SaveChanges();
  234. }
  235. db.Dispose();
  236. }
  237. /// <summary>
  238. /// 导出excel表格
  239. /// </summary>
  240. /// <param name="fields">查询条件(单个字段)</param>
  241. /// <param name="condition">查询条件(sql语句)</param>
  242. /// <returns></returns>
  243. // public void ExportExcel(List<RelationData> relationData, string condition)
  244. // {
  245. // }
  246. }
  247. }