UserAccountService.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * 创客账户
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Main;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Main
  12. {
  13. public class UserAccountService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  16. // public UserAccountService()
  17. // {
  18. // _conn = ConfigurationManager.AppSettings["SqlConnStr"].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("SeoDescription"); //备注
  41. fields.Add("UpdateDate"); //冻结/解冻时间
  42. // fields.Add("WithdrawAmount"); //已提现金额
  43. // fields.Add("TotalProfit"); //总收益
  44. // fields.Add("TotalServiceProfit"); //总服务分润
  45. // fields.Add("TeamTotalOverProfit"); //团队总流水分润
  46. // fields.Add("TeamTotalProfit"); //团队总收益
  47. // fields.Add("TeamTotalServiceProfit"); //团队总服务分润
  48. // fields.Add("TotalOverProfit"); //总流水分润
  49. // fields.Add("FixedAmount"); //固定额度
  50. // fields.Add("TempAmount"); //临时额度
  51. // fields.Add("LeaderReserve"); //盟主储备金
  52. // fields.Add("ValidAmount"); //可用额度
  53. // fields.Add("LeaderBalanceAmount"); //盟主余额
  54. // fields.Add("HelpProfitBalanceAmount"); //助利宝余额
  55. // fields.Add("TempAmountForBalance"); //余额临时额度
  56. // fields.Add("ThisMonthPreAmount"); //本月预发额度
  57. // fields.Add("ValidPreAmount"); //可用预发额度
  58. // fields.Add("SmallStoreDeposit"); //小分仓押金
  59. // fields.Add("StoreDeposit"); //分仓押金金额
  60. // fields.Add("PreTempAmount"); //预发临时额度
  61. // fields.Add("PreTempAmountForBalance"); //余额临时额度
  62. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("UserAccount", relationData, orderBy, page, limit, condition, fields);
  63. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  64. count = int.Parse(obj["count"].ToString());
  65. return diclist;
  66. }
  67. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  68. {
  69. List<string> fields = new List<string>(); //要显示的列
  70. fields.Add("Id");
  71. fields.Add("CreateDate"); //添加时间
  72. fields.Add("Status"); //状态
  73. fields.Add("UserId"); //创客
  74. fields.Add("TotalAmount"); //总金额
  75. fields.Add("FreezeAmount"); //冻结金额
  76. fields.Add("BalanceAmount"); //余额
  77. fields.Add("AccountStatus"); //账户状态
  78. fields.Add("WithdrawAmount"); //已提现金额
  79. fields.Add("TotalProfit"); //总收益
  80. fields.Add("TotalServiceProfit"); //总服务分润
  81. fields.Add("TeamTotalOverProfit"); //团队总流水分润
  82. fields.Add("TeamTotalProfit"); //团队总收益
  83. fields.Add("TeamTotalServiceProfit"); //团队总服务分润
  84. fields.Add("TotalOverProfit"); //总流水分润
  85. fields.Add("FixedAmount"); //固定额度
  86. fields.Add("TempAmount"); //临时额度
  87. fields.Add("LeaderReserve"); //盟主储备金
  88. fields.Add("ValidAmount"); //可用额度
  89. fields.Add("LeaderBalanceAmount"); //盟主余额
  90. fields.Add("HelpProfitBalanceAmount"); //助利宝余额
  91. fields.Add("TempAmountForBalance"); //余额临时额度
  92. fields.Add("ThisMonthPreAmount"); //本月预发额度
  93. fields.Add("ValidPreAmount"); //可用预发额度
  94. fields.Add("SmallStoreDeposit"); //小分仓押金
  95. fields.Add("StoreDeposit"); //分仓押金金额
  96. fields.Add("PreTempAmount"); //预发临时额度
  97. fields.Add("PreTempAmountForBalance"); //余额临时额度
  98. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("UserAccount", relationData, orderBy, page, limit, condition, fields);
  99. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  100. return diclist;
  101. }
  102. /// <summary>
  103. /// 查询一条记录
  104. /// </summary>
  105. /// <param name="Id">主键Id</param>
  106. /// <returns></returns>
  107. public static UserAccount Query(int Id)
  108. {
  109. WebCMSEntities db = new WebCMSEntities();
  110. UserAccount editData = db.UserAccount.FirstOrDefault(m => m.Id == Id) ?? new UserAccount();
  111. db.Dispose();
  112. return editData;
  113. }
  114. public static Dictionary<string, object> QueryForDic(int Id)
  115. {
  116. WebCMSEntities db = new WebCMSEntities();
  117. UserAccount editData = db.UserAccount.FirstOrDefault(m => m.Id == Id) ?? new UserAccount();
  118. db.Dispose();
  119. return Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(Newtonsoft.Json.JsonConvert.SerializeObject(editData));
  120. }
  121. /// <summary>
  122. /// 查询记录数
  123. /// </summary>
  124. /// <param name="Id">主键Id</param>
  125. /// <returns></returns>
  126. public static int Count(string condition = "")
  127. {
  128. int result = 0;
  129. DataTable dt = CustomerSqlConn.dtable("select count(Id) from UserAccount where 1=1" + condition, _conn);
  130. if (dt.Rows.Count > 0)
  131. {
  132. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  133. }
  134. return result;
  135. }
  136. /// <summary>
  137. /// 指定数据字段求和
  138. /// </summary>
  139. /// <param name="condition">条件</param>
  140. /// <param name="field">求和字段</param>
  141. /// <returns></returns>
  142. public static decimal Sum(string condition, string field)
  143. {
  144. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "UserAccount", condition);
  145. decimal amount = 0;
  146. if (dt.Count > 0)
  147. {
  148. amount = decimal.Parse(dt[field].ToString());
  149. }
  150. return amount;
  151. }
  152. /// <summary>
  153. /// 查询记录数
  154. /// </summary>
  155. /// <param name="Id">主键Id</param>
  156. /// <returns></returns>
  157. public static int Count(string condition = "", string field = "Id")
  158. {
  159. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ")", "UserAccount", condition);
  160. int result = 0;
  161. if (dt.Count > 0)
  162. {
  163. result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(Newtonsoft.Json.JsonConvert.SerializeObject(dt));
  164. }
  165. return result;
  166. }
  167. /// <summary>
  168. /// 查询是否存在
  169. /// </summary>
  170. /// <param name="Id">主键Id</param>
  171. /// <returns></returns>
  172. public static bool Exist(int Id)
  173. {
  174. WebCMSEntities db = new WebCMSEntities();
  175. bool check = db.UserAccount.Any(m => m.Id == Id);
  176. db.Dispose();
  177. return check;
  178. }
  179. /// <summary>
  180. /// 添加数据
  181. /// </summary>
  182. /// <param name="Fields">要设置的字段</param>
  183. /// <returns></returns>
  184. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  185. {
  186. if (check)
  187. {
  188. if (string.IsNullOrEmpty(fields["TotalAmount"].ToString()))
  189. {
  190. return new AppResultJson() { Status = "-1", Info = "请填写总金额" };
  191. }
  192. if (!function.IsNum(fields["TotalAmount"].ToString()))
  193. {
  194. return new AppResultJson() { Status = "-1", Info = "请填写正确的总金额" };
  195. }
  196. if (string.IsNullOrEmpty(fields["FreezeAmount"].ToString()))
  197. {
  198. return new AppResultJson() { Status = "-1", Info = "请填写冻结金额" };
  199. }
  200. if (!function.IsNum(fields["FreezeAmount"].ToString()))
  201. {
  202. return new AppResultJson() { Status = "-1", Info = "请填写正确的冻结金额" };
  203. }
  204. if (string.IsNullOrEmpty(fields["BalanceAmount"].ToString()))
  205. {
  206. return new AppResultJson() { Status = "-1", Info = "请填写余额" };
  207. }
  208. if (!function.IsNum(fields["BalanceAmount"].ToString()))
  209. {
  210. return new AppResultJson() { Status = "-1", Info = "请填写正确的余额" };
  211. }
  212. if (string.IsNullOrEmpty(fields["WithdrawAmount"].ToString()))
  213. {
  214. return new AppResultJson() { Status = "-1", Info = "请填写已提现金额" };
  215. }
  216. if (!function.IsNum(fields["WithdrawAmount"].ToString()))
  217. {
  218. return new AppResultJson() { Status = "-1", Info = "请填写正确的已提现金额" };
  219. }
  220. if (string.IsNullOrEmpty(fields["LeaderBalanceAmount"].ToString()))
  221. {
  222. return new AppResultJson() { Status = "-1", Info = "请填写盟主余额" };
  223. }
  224. if (!function.IsNum(fields["LeaderBalanceAmount"].ToString()))
  225. {
  226. return new AppResultJson() { Status = "-1", Info = "请填写正确的盟主余额" };
  227. }
  228. if (string.IsNullOrEmpty(fields["StoreDeposit"].ToString()))
  229. {
  230. return new AppResultJson() { Status = "-1", Info = "请填写分仓押金金额" };
  231. }
  232. if (!function.IsNum(fields["StoreDeposit"].ToString()))
  233. {
  234. return new AppResultJson() { Status = "-1", Info = "请填写正确的分仓押金金额" };
  235. }
  236. }
  237. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("UserAccount", fields, 0);
  238. return new AppResultJson() { Status = "1", Data = Id };
  239. }
  240. /// <summary>
  241. /// 修改数据
  242. /// </summary>
  243. /// <param name="Fields">要设置的字段</param>
  244. /// <param name="Id">主键Id</param>
  245. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  246. {
  247. new DbService(AppConfig.Base.mainTables, _conn).Edit("UserAccount", fields, Id);
  248. return new AppResultJson() { Status = "1", Data = Id };
  249. }
  250. /// <summary>
  251. /// 逻辑删除
  252. /// </summary>
  253. /// <param name="Id">主键Id</param>
  254. public static void Remove(int Id)
  255. {
  256. Dictionary<string, object> fields = new Dictionary<string, object>();
  257. fields.Add("Status", -1);
  258. new DbService(AppConfig.Base.mainTables, _conn).Edit("UserAccount", fields, Id);
  259. }
  260. /// <summary>
  261. /// 删除数据
  262. /// </summary>
  263. /// <param name="Id">主键Id</param>
  264. public static void Delete(int Id)
  265. {
  266. new DbService(AppConfig.Base.mainTables, _conn).Delete("UserAccount", Id);
  267. }
  268. /// <summary>
  269. /// 排序
  270. /// </summary>
  271. /// <param name="Id">主键Id</param>
  272. /// <param name="Sort">排序序号</param>
  273. public static void Sort(int Id, int Sort)
  274. {
  275. new DbService(AppConfig.Base.mainTables, _conn).Sort("UserAccount", Sort, Id);
  276. }
  277. /// <summary>
  278. /// 导入数据
  279. /// </summary>
  280. /// <param name="ExcelData">json数据</param>
  281. public static void Import(string ExcelData)
  282. {
  283. WebCMSEntities db = new WebCMSEntities();
  284. JsonData list = JsonMapper.ToObject(ExcelData);
  285. for (int i = 1; i < list.Count; i++)
  286. {
  287. JsonData dr = list[i];
  288. db.UserAccount.Add(new UserAccount()
  289. {
  290. CreateDate = DateTime.Now,
  291. UpdateDate = DateTime.Now,
  292. });
  293. db.SaveChanges();
  294. }
  295. db.Dispose();
  296. }
  297. /// <summary>
  298. /// 导出excel表格
  299. /// </summary>
  300. /// <param name="fields">查询条件(单个字段)</param>
  301. /// <param name="condition">查询条件(sql语句)</param>
  302. /// <returns></returns>
  303. // public void ExportExcel(List<RelationData> relationData, string condition)
  304. // {
  305. // }
  306. }
  307. }