UserCashRecordService.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 UserCashRecordService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  16. /// <summary>
  17. /// 查询列表
  18. /// </summary>
  19. /// <param name="relationData">关联表</param>
  20. /// <param name="condition">查询条件(sql语句)</param>
  21. /// <param name="count">总数(输出)</param>
  22. /// <param name="page">页码</param>
  23. /// <param name="limit">每页条数</param>
  24. /// <returns></returns>
  25. 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")
  26. {
  27. List<string> fields = new List<string>(); //要显示的列
  28. fields.Add("Id");
  29. fields.Add("CreateDate"); //添加时间
  30. fields.Add("QueryCount"); //提现标记
  31. fields.Add("Status"); //状态
  32. fields.Add("CashOrderNo"); //申请提现单号
  33. fields.Add("UserId"); //创客
  34. fields.Add("IdCardNo"); //身份证号
  35. fields.Add("SettleBankCardNo"); //提现卡号
  36. fields.Add("SettleBankName"); //银行名称
  37. fields.Add("TradeType"); //交易类型
  38. fields.Add("TradeAmount"); //提现金额(元)
  39. fields.Add("ActualTradeAmount"); //发佣金额(元)
  40. fields.Add("ManageFee"); //交易扣税(元)
  41. fields.Add("TradeFee"); //交易手续费(元)
  42. fields.Add("ReturnCode"); //返回编码
  43. fields.Add("ReturnMsg"); //返回信息
  44. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("UserCashRecord", relationData, orderBy, page, limit, condition, fields);
  45. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  46. count = int.Parse(obj["count"].ToString());
  47. return diclist;
  48. }
  49. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  50. {
  51. List<string> fields = new List<string>(); //要显示的列
  52. fields.Add("Id");
  53. fields.Add("CreateDate"); //添加时间
  54. fields.Add("QueryCount"); //提现标记
  55. fields.Add("Status"); //状态
  56. fields.Add("CashOrderNo"); //申请提现单号
  57. fields.Add("UserId"); //创客
  58. fields.Add("IdCardNo"); //身份证号
  59. fields.Add("SettleBankCardNo"); //提现卡号
  60. fields.Add("SettleBankName"); //银行名称
  61. fields.Add("TradeType"); //交易类型
  62. fields.Add("TradeAmount"); //提现金额(元)
  63. fields.Add("ActualTradeAmount"); //发佣金额(元)
  64. fields.Add("ManageFee"); //交易扣税(元)
  65. fields.Add("TradeFee"); //交易手续费(元)
  66. fields.Add("TradeAmount"); //交易金额
  67. fields.Add("ReturnCode"); //返回编码
  68. fields.Add("ReturnMsg"); //返回信息
  69. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("UserCashRecord", relationData, orderBy, page, limit, condition, fields);
  70. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  71. return diclist;
  72. }
  73. /// <summary>
  74. /// 查询一条记录
  75. /// </summary>
  76. /// <param name="Id">主键Id</param>
  77. /// <returns></returns>
  78. public static UserCashRecord Query(int Id)
  79. {
  80. WebCMSEntities db = new WebCMSEntities();
  81. UserCashRecord editData = db.UserCashRecord.FirstOrDefault(m => m.Id == Id) ?? new UserCashRecord();
  82. db.Dispose();
  83. return editData;
  84. }
  85. public static UserCashRecord Query(string condition, string fields = "*")
  86. {
  87. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail(fields, "UserCashRecord", condition);
  88. // if (dt.Rows.Count > 0)
  89. // {
  90. // Dictionary<string, object> row = new Dictionary<string, object>();
  91. // foreach (DataColumn dc in dt.Columns)
  92. // {
  93. // row.Add(dc.ColumnName, dt.Rows[0][dc.ColumnName].ToString());
  94. // }
  95. // return Newtonsoft.Json.JsonConvert.DeserializeObject<UserCashRecord>(Newtonsoft.Json.JsonConvert.SerializeObject(row));
  96. // }
  97. var userCashRecord = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "UserCashRecord", condition);
  98. if (userCashRecord.Count > 0)
  99. {
  100. return Newtonsoft.Json.JsonConvert.DeserializeObject<UserCashRecord>(Newtonsoft.Json.JsonConvert.SerializeObject(userCashRecord));
  101. }
  102. return new UserCashRecord();
  103. }
  104. public static decimal Sum(string condition, string field)
  105. {
  106. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("Sum(" + field + ")", "UserCashRecord", condition);
  107. // decimal amount = 0;
  108. // if (dt.Rows.Count > 0)
  109. // {
  110. // amount = decimal.Parse(dt.Rows[0][0].ToString());
  111. // }
  112. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field, "UserCashRecord", condition);
  113. decimal amount = 0;
  114. if (dt.Count > 0)
  115. {
  116. amount = decimal.Parse(dt[field].ToString());
  117. }
  118. return amount;
  119. }
  120. /// <summary>
  121. /// 查询记录数
  122. /// </summary>
  123. /// <param name="Id">主键Id</param>
  124. /// <returns></returns>
  125. public static int Count(string condition = "", string field = "Id")
  126. {
  127. // int result = 0;
  128. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("count(" + field + ")", "UserCashRecord", condition);
  129. // if (dt.Rows.Count > 0)
  130. // {
  131. // result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  132. // }
  133. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "UserCashRecord", condition);
  134. int result = 0;
  135. if (dt.Count > 0)
  136. {
  137. result = int.Parse(dt[field].ToString());
  138. }
  139. return result;
  140. }
  141. /// <summary>
  142. /// 查询是否存在
  143. /// </summary>
  144. /// <param name="Id">主键Id</param>
  145. /// <returns></returns>
  146. public static bool Exist(int Id)
  147. {
  148. WebCMSEntities db = new WebCMSEntities();
  149. bool check = db.UserCashRecord.Any(m => m.Id == Id);
  150. db.Dispose();
  151. return check;
  152. }
  153. /// <summary>
  154. /// 添加数据
  155. /// </summary>
  156. /// <param name="Fields">要设置的字段</param>
  157. /// <returns></returns>
  158. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  159. {
  160. if (check)
  161. {
  162. }
  163. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("UserCashRecord", fields, 0);
  164. return new AppResultJson() { Status = "1", Data = Id };
  165. }
  166. /// <summary>
  167. /// 修改数据
  168. /// </summary>
  169. /// <param name="Fields">要设置的字段</param>
  170. /// <param name="Id">主键Id</param>
  171. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  172. {
  173. if (check)
  174. {
  175. }
  176. new DbService(AppConfig.Base.mainTables, _conn).Edit("UserCashRecord", fields, Id);
  177. return new AppResultJson() { Status = "1", Data = Id };
  178. }
  179. /// <summary>
  180. /// 逻辑删除
  181. /// </summary>
  182. /// <param name="Id">主键Id</param>
  183. public static void Remove(int Id)
  184. {
  185. Dictionary<string, object> fields = new Dictionary<string, object>();
  186. fields.Add("Status", -1);
  187. new DbService(AppConfig.Base.mainTables, _conn).Edit("UserCashRecord", fields, Id);
  188. }
  189. /// <summary>
  190. /// 删除数据
  191. /// </summary>
  192. /// <param name="Id">主键Id</param>
  193. public static void Delete(int Id)
  194. {
  195. new DbService(AppConfig.Base.mainTables, _conn).Delete("UserCashRecord", Id);
  196. }
  197. /// <summary>
  198. /// 排序
  199. /// </summary>
  200. /// <param name="Id">主键Id</param>
  201. /// <param name="Sort">排序序号</param>
  202. public static void Sort(int Id, int Sort)
  203. {
  204. new DbService(AppConfig.Base.mainTables, _conn).Sort("UserCashRecord", Sort, Id);
  205. }
  206. /// <summary>
  207. /// 导入数据
  208. /// </summary>
  209. /// <param name="ExcelData">json数据</param>
  210. public static void Import(string ExcelData)
  211. {
  212. WebCMSEntities db = new WebCMSEntities();
  213. JsonData list = JsonMapper.ToObject(ExcelData);
  214. for (int i = 1; i < list.Count; i++)
  215. {
  216. JsonData dr = list[i];
  217. db.UserCashRecord.Add(new UserCashRecord()
  218. {
  219. CreateDate = DateTime.Now,
  220. UpdateDate = DateTime.Now,
  221. });
  222. db.SaveChanges();
  223. }
  224. db.Dispose();
  225. }
  226. /// <summary>
  227. /// 导出excel表格
  228. /// </summary>
  229. /// <param name="fields">查询条件(单个字段)</param>
  230. /// <param name="condition">查询条件(sql语句)</param>
  231. /// <returns></returns>
  232. // public static void ExportExcel(List<RelationData> relationData, string condition)
  233. // {
  234. // }
  235. }
  236. }