OpenRewardService.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 OpenRewardService
  14. {
  15. string _conn = "";
  16. public OpenRewardService()
  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("TradeDate"); //达标日期
  36. fields.Add("UserId"); //创客
  37. fields.Add("BrandId"); //品牌
  38. fields.Add("RewardType"); //奖励类型
  39. fields.Add("CreditTradeAmt"); //贷记卡交易总金额
  40. fields.Add("DebitTradeAmt"); //借记卡交易总金额
  41. fields.Add("CreditRewardAmount"); //贷记卡交易奖励金额
  42. fields.Add("DebitRewardAmount"); //借记记卡交易奖励金额
  43. fields.Add("RewardMerCount"); //达标商户数
  44. fields.Add("CheckStatus"); //验证和同步账户状态
  45. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("OpenReward", relationData, orderBy, page, limit, condition, fields);
  46. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  47. count = int.Parse(obj["count"].ToString());
  48. return diclist;
  49. }
  50. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  51. {
  52. List<string> fields = new List<string>(); //要显示的列
  53. fields.Add("Id");
  54. fields.Add("CreateDate"); //添加时间
  55. fields.Add("Status"); //状态
  56. fields.Add("TradeDate"); //达标日期
  57. fields.Add("UserId"); //创客
  58. fields.Add("BrandId"); //品牌
  59. fields.Add("RewardType"); //奖励类型
  60. fields.Add("CreditTradeAmt"); //贷记卡交易总金额
  61. fields.Add("DebitTradeAmt"); //借记卡交易总金额
  62. fields.Add("CreditRewardAmount"); //贷记卡交易奖励金额
  63. fields.Add("DebitRewardAmount"); //借记记卡交易奖励金额
  64. fields.Add("RewardMerCount"); //达标商户数
  65. fields.Add("CheckStatus"); //验证和同步账户状态
  66. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("OpenReward", relationData, orderBy, page, limit, condition, fields);
  67. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  68. return diclist;
  69. }
  70. /// <summary>
  71. /// 查询一条记录
  72. /// </summary>
  73. /// <param name="Id">主键Id</param>
  74. /// <returns></returns>
  75. public OpenReward Query(int Id)
  76. {
  77. WebCMSEntities db = new WebCMSEntities();
  78. OpenReward editData = db.OpenReward.FirstOrDefault(m => m.Id == Id) ?? new OpenReward();
  79. db.Dispose();
  80. return editData;
  81. }
  82. /// <summary>
  83. /// 查询记录数
  84. /// </summary>
  85. /// <param name="Id">主键Id</param>
  86. /// <returns></returns>
  87. public int Count(string condition = "")
  88. {
  89. int result = 0;
  90. DataTable dt = CustomerSqlConn.dtable("select count(Id) from OpenReward where 1=1" + condition, _conn);
  91. if(dt.Rows.Count > 0)
  92. {
  93. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  94. }
  95. return result;
  96. }
  97. /// <summary>
  98. /// 查询是否存在
  99. /// </summary>
  100. /// <param name="Id">主键Id</param>
  101. /// <returns></returns>
  102. public bool Exist(int Id)
  103. {
  104. WebCMSEntities db = new WebCMSEntities();
  105. bool check = db.OpenReward.Any(m => m.Id == Id);
  106. db.Dispose();
  107. return check;
  108. }
  109. /// <summary>
  110. /// 添加数据
  111. /// </summary>
  112. /// <param name="Fields">要设置的字段</param>
  113. /// <returns></returns>
  114. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  115. {
  116. if(check)
  117. {
  118. }
  119. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("OpenReward", fields, 0);
  120. return new AppResultJson(){ Status = "1", Data = Id };
  121. }
  122. /// <summary>
  123. /// 修改数据
  124. /// </summary>
  125. /// <param name="Fields">要设置的字段</param>
  126. /// <param name="Id">主键Id</param>
  127. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  128. {
  129. if(check)
  130. {
  131. }
  132. new DbService(AppConfig.Base.dbTables, _conn).Edit("OpenReward", fields, Id);
  133. return new AppResultJson(){ Status = "1", Data = Id };
  134. }
  135. /// <summary>
  136. /// 逻辑删除
  137. /// </summary>
  138. /// <param name="Id">主键Id</param>
  139. public void Remove(int Id)
  140. {
  141. Dictionary<string, object> fields = new Dictionary<string, object>();
  142. fields.Add("Status", -1);
  143. new DbService(AppConfig.Base.dbTables, _conn).Edit("OpenReward", fields, Id);
  144. }
  145. /// <summary>
  146. /// 删除数据
  147. /// </summary>
  148. /// <param name="Id">主键Id</param>
  149. public void Delete(int Id)
  150. {
  151. new DbService(AppConfig.Base.dbTables, _conn).Delete("OpenReward", Id);
  152. }
  153. /// <summary>
  154. /// 排序
  155. /// </summary>
  156. /// <param name="Id">主键Id</param>
  157. /// <param name="Sort">排序序号</param>
  158. public void Sort(int Id, int Sort)
  159. {
  160. new DbService(AppConfig.Base.dbTables, _conn).Sort("OpenReward", Sort, Id);
  161. }
  162. /// <summary>
  163. /// 导入数据
  164. /// </summary>
  165. /// <param name="ExcelData">json数据</param>
  166. public void Import(string ExcelData)
  167. {
  168. WebCMSEntities db = new WebCMSEntities();
  169. JsonData list = JsonMapper.ToObject(ExcelData);
  170. for (int i = 1; i < list.Count;i++ )
  171. {
  172. JsonData dr = list[i];
  173. db.OpenReward.Add(new OpenReward()
  174. {
  175. CreateDate = DateTime.Now,
  176. UpdateDate = DateTime.Now,
  177. });
  178. db.SaveChanges();
  179. }
  180. db.Dispose();
  181. }
  182. /// <summary>
  183. /// 导出excel表格
  184. /// </summary>
  185. /// <param name="fields">查询条件(单个字段)</param>
  186. /// <param name="condition">查询条件(sql语句)</param>
  187. /// <returns></returns>
  188. // public void ExportExcel(List<RelationData> relationData, string condition)
  189. // {
  190. // }
  191. }
  192. }