ProfitRecordService.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 ProfitRecordService
  14. {
  15. string _conn = "";
  16. public ProfitRecordService()
  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 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("MerchantId"); //商户
  37. fields.Add("MerNo"); //渠道商户编号
  38. fields.Add("MerHelpFlag"); //是否属于扶持周期内商户
  39. fields.Add("MerBuddyType"); //商户创客类型
  40. fields.Add("SnNo"); //SN号
  41. fields.Add("TradeDate"); //交易日期
  42. fields.Add("ProfitAmount"); //分润金额
  43. fields.Add("QrPayFlag"); //云闪付标识
  44. fields.Add("CapFlag"); //借记卡封顶交易标志
  45. fields.Add("BrandId"); //品牌
  46. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("ProfitRecord", 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 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("MerchantId"); //商户
  59. fields.Add("MerNo"); //渠道商户编号
  60. fields.Add("MerHelpFlag"); //是否属于扶持周期内商户
  61. fields.Add("MerBuddyType"); //商户创客类型
  62. fields.Add("SnNo"); //SN号
  63. fields.Add("TradeDate"); //交易日期
  64. fields.Add("ProfitAmount"); //分润金额
  65. fields.Add("QrPayFlag"); //云闪付标识
  66. fields.Add("CapFlag"); //借记卡封顶交易标志
  67. fields.Add("BrandId"); //品牌
  68. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("ProfitRecord", 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 ProfitRecord Query(int Id)
  78. {
  79. WebCMSEntities db = new WebCMSEntities();
  80. ProfitRecord editData = db.ProfitRecord.FirstOrDefault(m => m.Id == Id) ?? new ProfitRecord();
  81. db.Dispose();
  82. return editData;
  83. }
  84. /// <summary>
  85. /// 查询记录数
  86. /// </summary>
  87. /// <param name="Id">主键Id</param>
  88. /// <returns></returns>
  89. public int Count(string condition = "")
  90. {
  91. int result = 0;
  92. DataTable dt = CustomerSqlConn.dtable("select count(Id) from ProfitRecord 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 bool Exist(int Id)
  105. {
  106. WebCMSEntities db = new WebCMSEntities();
  107. bool check = db.ProfitRecord.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 AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  117. {
  118. if(check)
  119. {
  120. }
  121. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("ProfitRecord", fields, 0);
  122. return new AppResultJson(){ Status = "1", Data = Id };
  123. }
  124. /// <summary>
  125. /// 修改数据
  126. /// </summary>
  127. /// <param name="Fields">要设置的字段</param>
  128. /// <param name="Id">主键Id</param>
  129. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  130. {
  131. if(check)
  132. {
  133. }
  134. new DbService(AppConfig.Base.dbTables, _conn).Edit("ProfitRecord", fields, Id);
  135. return new AppResultJson(){ Status = "1", Data = Id };
  136. }
  137. /// <summary>
  138. /// 逻辑删除
  139. /// </summary>
  140. /// <param name="Id">主键Id</param>
  141. public void Remove(int Id)
  142. {
  143. Dictionary<string, object> fields = new Dictionary<string, object>();
  144. fields.Add("Status", -1);
  145. new DbService(AppConfig.Base.dbTables, _conn).Edit("ProfitRecord", fields, Id);
  146. }
  147. /// <summary>
  148. /// 删除数据
  149. /// </summary>
  150. /// <param name="Id">主键Id</param>
  151. public void Delete(int Id)
  152. {
  153. new DbService(AppConfig.Base.dbTables, _conn).Delete("ProfitRecord", Id);
  154. }
  155. /// <summary>
  156. /// 排序
  157. /// </summary>
  158. /// <param name="Id">主键Id</param>
  159. /// <param name="Sort">排序序号</param>
  160. public void Sort(int Id, int Sort)
  161. {
  162. new DbService(AppConfig.Base.dbTables, _conn).Sort("ProfitRecord", Sort, Id);
  163. }
  164. /// <summary>
  165. /// 导入数据
  166. /// </summary>
  167. /// <param name="ExcelData">json数据</param>
  168. public void Import(string ExcelData)
  169. {
  170. WebCMSEntities db = new WebCMSEntities();
  171. JsonData list = JsonMapper.ToObject(ExcelData);
  172. for (int i = 1; i < list.Count;i++ )
  173. {
  174. JsonData dr = list[i];
  175. db.ProfitRecord.Add(new ProfitRecord()
  176. {
  177. CreateDate = DateTime.Now,
  178. UpdateDate = DateTime.Now,
  179. });
  180. db.SaveChanges();
  181. }
  182. db.Dispose();
  183. }
  184. /// <summary>
  185. /// 导出excel表格
  186. /// </summary>
  187. /// <param name="fields">查询条件(单个字段)</param>
  188. /// <param name="condition">查询条件(sql语句)</param>
  189. /// <returns></returns>
  190. // public void ExportExcel(List<RelationData> relationData, string condition)
  191. // {
  192. // }
  193. }
  194. }