MerchantDepositOrderService.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * 商户服务费缴纳记录
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.MainModels;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Main
  12. {
  13. public class MerchantDepositOrderService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  16. /// <summary>
  17. /// 查询列表
  18. /// </summary>
  19. /// <param name="fields">查询条件(单个字段)</param>
  20. /// <param name="condition">查询条件(sql语句)</param>
  21. /// <param name="page">页码</param>
  22. /// <param name="limit">每页条数</param>
  23. /// <returns></returns>
  24. public List<Dictionary<string, object>> List(List<FieldItem> fields, string condition, int page = 1, int limit = 30, string orderby = "Id desc")
  25. {
  26. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantDepositOrder", fields, orderby, "0", page, limit, condition);
  27. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  28. return diclist;
  29. }
  30. /// <summary>
  31. /// 通过商户Id查询一条记录
  32. /// </summary>
  33. /// <param name="MerchantId">商户Id</param>
  34. /// <returns></returns>
  35. public MerchantDepositOrder QueryByMerchantId(int MerchantId)
  36. {
  37. WebCMSEntities db = new WebCMSEntities();
  38. MerchantDepositOrder editData = db.MerchantDepositOrder.FirstOrDefault(m => m.Status > 0 && m.MerchantId == MerchantId) ?? new MerchantDepositOrder();
  39. db.Dispose();
  40. return editData;
  41. }
  42. /// <summary>
  43. /// 通过Id查询一条记录
  44. /// </summary>
  45. /// <param name="Id">主键Id</param>
  46. /// <returns></returns>
  47. public MerchantDepositOrder QueryById(int Id)
  48. {
  49. WebCMSEntities db = new WebCMSEntities();
  50. MerchantDepositOrder editData = db.MerchantDepositOrder.FirstOrDefault(m => m.Id == Id) ?? new MerchantDepositOrder();
  51. db.Dispose();
  52. return editData;
  53. }
  54. public Dictionary<string, string> Sum(string field, string condition)
  55. {
  56. Dictionary<string, string> result = new Dictionary<string, string>();
  57. string sumString = "";
  58. string[] fieldlist = field.Split(',');
  59. foreach(string f in fieldlist)
  60. {
  61. sumString += "sum(" + f + ") " + f + ",";
  62. }
  63. sumString = sumString.TrimEnd(',');
  64. DataTable dt = CustomerSqlConn.dtable("select " + sumString + " from MerchantDepositOrder where 1=1" + condition, _conn);
  65. if(dt.Rows.Count > 0)
  66. {
  67. foreach(string f in fieldlist)
  68. {
  69. result.Add(f, function.CheckNum(dt.Rows[0][f].ToString()));
  70. }
  71. }
  72. return result;
  73. }
  74. // /// <summary>
  75. // /// 查询记录数
  76. // /// </summary>
  77. // /// <param name="Id">主键Id</param>
  78. // /// <returns></returns>
  79. // public static int Count(string condition = "", string field = "Id")
  80. // {
  81. // int result = 0;
  82. // Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).Query("count(" + field + ") " + field + "", "MerchantDepositOrder", condition);
  83. // if (obj.Keys.Count > 0)
  84. // {
  85. // result = int.Parse(function.CheckInt(obj[field].ToString()));
  86. // }
  87. // return result;
  88. // }
  89. // /// <summary>
  90. // /// 查询是否存在
  91. // /// </summary>
  92. // /// <param name="Id">主键Id</param>
  93. // /// <returns></returns>
  94. // public static bool Exist(string condition)
  95. // {
  96. // Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).Query("1", "MerchantDepositOrder", condition);
  97. // if (obj.Keys.Count > 0)
  98. // {
  99. // return true;
  100. // }
  101. // return false;
  102. // }
  103. /// <summary>
  104. /// 添加数据
  105. /// </summary>
  106. /// <param name="Fields">要设置的字段</param>
  107. /// <returns></returns>
  108. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  109. {
  110. if (check)
  111. {
  112. if (string.IsNullOrEmpty(fields["MerchantId"].ToString()))
  113. {
  114. return new AppResultJson() { Status = "-1", Info = "请填写商户Id" };
  115. }
  116. if (!function.IsInt(fields["MerchantId"].ToString()))
  117. {
  118. return new AppResultJson() { Status = "-1", Info = "请填写正确的商户Id" };
  119. }
  120. if (string.IsNullOrEmpty(fields["UserId"].ToString()))
  121. {
  122. return new AppResultJson() { Status = "-1", Info = "请填写创客Id" };
  123. }
  124. if (!function.IsInt(fields["UserId"].ToString()))
  125. {
  126. return new AppResultJson() { Status = "-1", Info = "请填写正确的创客Id" };
  127. }
  128. }
  129. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantDepositOrder", fields, 0);
  130. return new AppResultJson() { Status = "1", Data = Id };
  131. }
  132. /// <summary>
  133. /// 修改数据
  134. /// </summary>
  135. /// <param name="Fields">要设置的字段</param>
  136. /// <param name="Id">主键Id</param>
  137. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  138. {
  139. if (check)
  140. {
  141. if (string.IsNullOrEmpty(fields["MerchantId"].ToString()))
  142. {
  143. return new AppResultJson() { Status = "-1", Info = "请填写商户Id" };
  144. }
  145. if (!function.IsInt(fields["MerchantId"].ToString()))
  146. {
  147. return new AppResultJson() { Status = "-1", Info = "请填写正确的商户Id" };
  148. }
  149. if (string.IsNullOrEmpty(fields["UserId"].ToString()))
  150. {
  151. return new AppResultJson() { Status = "-1", Info = "请填写创客Id" };
  152. }
  153. if (!function.IsInt(fields["UserId"].ToString()))
  154. {
  155. return new AppResultJson() { Status = "-1", Info = "请填写正确的创客Id" };
  156. }
  157. }
  158. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantDepositOrder", fields, Id);
  159. return new AppResultJson() { Status = "1", Data = Id };
  160. }
  161. /// <summary>
  162. /// 逻辑删除
  163. /// </summary>
  164. /// <param name="Id">主键Id</param>
  165. public static void Remove(int Id)
  166. {
  167. Dictionary<string, object> fields = new Dictionary<string, object>();
  168. fields.Add("Status", -1);
  169. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantDepositOrder", fields, Id);
  170. }
  171. /// <summary>
  172. /// 删除数据
  173. /// </summary>
  174. /// <param name="Id">主键Id</param>
  175. public static void Delete(int Id)
  176. {
  177. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantDepositOrder", Id);
  178. }
  179. /// <summary>
  180. /// 排序
  181. /// </summary>
  182. /// <param name="Id">主键Id</param>
  183. /// <param name="Sort">排序序号</param>
  184. public static void Sort(int Id, int Sort)
  185. {
  186. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantDepositOrder", Sort, Id);
  187. }
  188. /// <summary>
  189. /// 导入数据
  190. /// </summary>
  191. /// <param name="ExcelData">json数据</param>
  192. public static void Import(string ExcelData)
  193. {
  194. // WebCMSEntities db = new WebCMSEntities();
  195. // JsonData list = JsonMapper.ToObject(ExcelData);
  196. // for (int i = 1; i < list.Count;i++ )
  197. // {
  198. // JsonData dr = list[i];
  199. // db.MerchantDepositOrder.Add(new MerchantDepositOrder()
  200. // {
  201. // CreateDate = DateTime.Now,
  202. // UpdateDate = DateTime.Now,
  203. // });
  204. // db.SaveChanges();
  205. // }
  206. // db.Dispose();
  207. }
  208. /// <summary>
  209. /// 导出excel表格
  210. /// </summary>
  211. /// <param name="fields">查询条件(单个字段)</param>
  212. /// <param name="condition">查询条件(sql语句)</param>
  213. /// <returns></returns>
  214. // public static void ExportExcel(List<RelationData> relationData, string condition)
  215. // {
  216. // }
  217. }
  218. }