OpenRewardDetailService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 OpenRewardDetailService
  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("Status"); //状态
  31. fields.Add("TradeDate"); //达标日期
  32. fields.Add("UserId"); //创客
  33. fields.Add("BrandId"); //品牌
  34. fields.Add("MerchantId"); //商户
  35. fields.Add("DirectUserId"); //商户直属人
  36. fields.Add("SnNo"); //SN号
  37. fields.Add("MerNo"); //渠道商户号
  38. fields.Add("SnType"); //机具类型
  39. fields.Add("SnApplyUserId"); //机具申请人
  40. fields.Add("StandardDate"); //商户的激活日期
  41. fields.Add("SnStoreId"); //SN仓库
  42. fields.Add("MerBuddyType"); //商户创客类型
  43. fields.Add("RewardType"); //奖励类型
  44. fields.Add("CreditTradeAmt"); //贷记卡交易总金额
  45. fields.Add("DebitTradeAmt"); //借记卡交易总金额
  46. fields.Add("CreditRewardAmount"); //贷记卡交易奖励金额
  47. fields.Add("DebitRewardAmount"); //借记记卡交易奖励金额
  48. fields.Add("OpenRewardNo"); //开机奖励单号
  49. fields.Add("RewardDesc"); //奖励描述
  50. fields.Add("CheckStatus"); //同步状态
  51. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("OpenRewardDetail", relationData, orderBy, page, limit, condition, fields);
  52. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  53. count = int.Parse(obj["count"].ToString());
  54. return diclist;
  55. }
  56. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  57. {
  58. List<string> fields = new List<string>(); //要显示的列
  59. fields.Add("Id");
  60. fields.Add("CreateDate"); //添加时间
  61. fields.Add("Status"); //状态
  62. fields.Add("TradeDate"); //达标日期
  63. fields.Add("UserId"); //创客
  64. fields.Add("BrandId"); //品牌
  65. fields.Add("MerchantId"); //商户
  66. fields.Add("DirectUserId"); //商户直属人
  67. fields.Add("SnNo"); //SN号
  68. fields.Add("MerNo"); //渠道商户号
  69. fields.Add("SnType"); //机具类型
  70. fields.Add("SnApplyUserId"); //机具申请人
  71. fields.Add("StandardDate"); //商户的激活日期
  72. fields.Add("SnStoreId"); //SN仓库
  73. fields.Add("MerBuddyType"); //商户创客类型
  74. fields.Add("RewardType"); //奖励类型
  75. fields.Add("CreditTradeAmt"); //贷记卡交易总金额
  76. fields.Add("DebitTradeAmt"); //借记卡交易总金额
  77. fields.Add("CreditRewardAmount"); //贷记卡交易奖励金额
  78. fields.Add("DebitRewardAmount"); //借记记卡交易奖励金额
  79. fields.Add("OpenRewardNo"); //开机奖励单号
  80. fields.Add("RewardDesc"); //奖励描述
  81. fields.Add("CheckStatus"); //同步状态
  82. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("OpenRewardDetail", relationData, orderBy, page, limit, condition, fields);
  83. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  84. return diclist;
  85. }
  86. /// <summary>
  87. /// 查询一条记录
  88. /// </summary>
  89. /// <param name="Id">主键Id</param>
  90. /// <returns></returns>
  91. public static OpenRewardDetail Query(int Id)
  92. {
  93. WebCMSEntities db = new WebCMSEntities();
  94. OpenRewardDetail editData = db.OpenRewardDetail.FirstOrDefault(m => m.Id == Id) ?? new OpenRewardDetail();
  95. db.Dispose();
  96. return editData;
  97. }
  98. public static OpenRewardDetail Query(string condition, string fields = "*")
  99. {
  100. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail(fields, "OpenRewardDetail", condition);
  101. // if (dt.Rows.Count > 0)
  102. // {
  103. // Dictionary<string, object> row = new Dictionary<string, object>();
  104. // foreach (DataColumn dc in dt.Columns)
  105. // {
  106. // row.Add(dc.ColumnName, dt.Rows[0][dc.ColumnName].ToString());
  107. // }
  108. // return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenRewardDetail>(Newtonsoft.Json.JsonConvert.SerializeObject(row));
  109. // }
  110. var openRewardDetail = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "OrderOpenRewardDetailProduct", condition);
  111. if (openRewardDetail.Count > 0)
  112. {
  113. return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenRewardDetail>(Newtonsoft.Json.JsonConvert.SerializeObject(openRewardDetail));
  114. }
  115. return new OpenRewardDetail();
  116. }
  117. public static decimal Sum(string condition, string field)
  118. {
  119. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("Sum(" + field + ")", "OpenRewardDetail", condition);
  120. // decimal amount = 0;
  121. // if (dt.Rows.Count > 0)
  122. // {
  123. // amount = decimal.Parse(dt.Rows[0][0].ToString());
  124. // }
  125. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field, "OpenRewardDetail", condition);
  126. decimal amount = 0;
  127. if (dt.Count > 0)
  128. {
  129. amount = decimal.Parse(dt[field].ToString());
  130. }
  131. return amount;
  132. }
  133. /// <summary>
  134. /// 查询记录数
  135. /// </summary>
  136. /// <param name="Id">主键Id</param>
  137. /// <returns></returns>
  138. public static int Count(string condition = "", string field = "Id")
  139. {
  140. // int result = 0;
  141. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("count(" + field + ")", "OpenRewardDetail", condition);
  142. // if (dt.Rows.Count > 0)
  143. // {
  144. // result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  145. // }
  146. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "OpenRewardDetail", condition);
  147. int result = 0;
  148. if (dt.Count > 0)
  149. {
  150. result = int.Parse(dt[field].ToString());
  151. }
  152. return result;
  153. }
  154. /// <summary>
  155. /// 查询是否存在
  156. /// </summary>
  157. /// <param name="Id">主键Id</param>
  158. /// <returns></returns>
  159. public static bool Exist(int Id)
  160. {
  161. WebCMSEntities db = new WebCMSEntities();
  162. bool check = db.OpenRewardDetail.Any(m => m.Id == Id);
  163. db.Dispose();
  164. return check;
  165. }
  166. /// <summary>
  167. /// 添加数据
  168. /// </summary>
  169. /// <param name="Fields">要设置的字段</param>
  170. /// <returns></returns>
  171. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  172. {
  173. if (check)
  174. {
  175. }
  176. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("OpenRewardDetail", fields, 0);
  177. return new AppResultJson() { Status = "1", Data = Id };
  178. }
  179. /// <summary>
  180. /// 修改数据
  181. /// </summary>
  182. /// <param name="Fields">要设置的字段</param>
  183. /// <param name="Id">主键Id</param>
  184. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  185. {
  186. if (check)
  187. {
  188. }
  189. new DbService(AppConfig.Base.dbTables, _conn).Edit("OpenRewardDetail", fields, Id);
  190. return new AppResultJson() { Status = "1", Data = Id };
  191. }
  192. /// <summary>
  193. /// 逻辑删除
  194. /// </summary>
  195. /// <param name="Id">主键Id</param>
  196. public static void Remove(int Id)
  197. {
  198. Dictionary<string, object> fields = new Dictionary<string, object>();
  199. fields.Add("Status", -1);
  200. new DbService(AppConfig.Base.dbTables, _conn).Edit("OpenRewardDetail", fields, Id);
  201. }
  202. /// <summary>
  203. /// 删除数据
  204. /// </summary>
  205. /// <param name="Id">主键Id</param>
  206. public static void Delete(int Id)
  207. {
  208. new DbService(AppConfig.Base.dbTables, _conn).Delete("OpenRewardDetail", Id);
  209. }
  210. /// <summary>
  211. /// 排序
  212. /// </summary>
  213. /// <param name="Id">主键Id</param>
  214. /// <param name="Sort">排序序号</param>
  215. public static void Sort(int Id, int Sort)
  216. {
  217. new DbService(AppConfig.Base.dbTables, _conn).Sort("OpenRewardDetail", Sort, Id);
  218. }
  219. /// <summary>
  220. /// 导入数据
  221. /// </summary>
  222. /// <param name="ExcelData">json数据</param>
  223. public static void Import(string ExcelData)
  224. {
  225. WebCMSEntities db = new WebCMSEntities();
  226. JsonData list = JsonMapper.ToObject(ExcelData);
  227. for (int i = 1; i < list.Count; i++)
  228. {
  229. JsonData dr = list[i];
  230. db.OpenRewardDetail.Add(new OpenRewardDetail()
  231. {
  232. CreateDate = DateTime.Now,
  233. UpdateDate = DateTime.Now,
  234. });
  235. db.SaveChanges();
  236. }
  237. db.Dispose();
  238. }
  239. /// <summary>
  240. /// 导出excel表格
  241. /// </summary>
  242. /// <param name="fields">查询条件(单个字段)</param>
  243. /// <param name="condition">查询条件(sql语句)</param>
  244. /// <returns></returns>
  245. // public static void ExportExcel(List<RelationData> relationData, string condition)
  246. // {
  247. // }
  248. }
  249. }