MerchantDepositOrderService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 MerchantDepositOrderService
  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("MerchantId"); //商户Id
  32. fields.Add("UserId"); //创客Id
  33. fields.Add("ActPayPrice"); //激活支付金额
  34. fields.Add("OrderNo"); //订单号
  35. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantDepositOrder", relationData, orderBy, page, limit, condition, fields);
  36. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  37. count = int.Parse(obj["count"].ToString());
  38. return diclist;
  39. }
  40. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  41. {
  42. List<string> fields = new List<string>(); //要显示的列
  43. fields.Add("Id");
  44. fields.Add("CreateDate"); //添加时间
  45. fields.Add("Status"); //状态
  46. fields.Add("MerchantId"); //商户Id
  47. fields.Add("UserId"); //创客Id
  48. fields.Add("ActPayPrice"); //激活支付金额
  49. fields.Add("OrderNo"); //订单号
  50. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantDepositOrder", relationData, orderBy, page, limit, condition, fields);
  51. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  52. return diclist;
  53. }
  54. /// <summary>
  55. /// 查询列表(单表)
  56. /// </summary>
  57. /// <param name="fieldList">返回的字段</param>
  58. /// <param name="condition">查询条件</param>
  59. /// <param name="page">页码</param>
  60. /// <param name="limit">每页条数</param>
  61. /// <param name="orderBy">排序</param>
  62. /// <returns></returns>
  63. public static List<Dictionary<string, object>> List(string fieldList, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  64. {
  65. List<string> fields = fieldList.Split(',').ToList(); //要显示的列
  66. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantDepositOrder", new List<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 static MerchantDepositOrder Query(int Id)
  76. {
  77. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).Query("*", "MerchantDepositOrder", Id);
  78. if (obj.Keys.Count > 0)
  79. {
  80. return Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantDepositOrder>(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
  81. }
  82. return new MerchantDepositOrder();
  83. }
  84. /// <summary>
  85. /// 查询一条记录
  86. /// </summary>
  87. /// <param name="condition">查询条件(sql语句)</param>
  88. /// <returns></returns>
  89. public static MerchantDepositOrder Query(string condition)
  90. {
  91. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).Query("*", "MerchantDepositOrder", condition);
  92. if (obj.Keys.Count > 0)
  93. {
  94. return Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantDepositOrder>(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
  95. }
  96. return new MerchantDepositOrder();
  97. }
  98. /// <summary>
  99. /// 查询一条记录
  100. /// </summary>
  101. /// <param name="condition">查询条件(sql语句)</param>
  102. /// <param name="fields">返回的字段</param>
  103. /// <returns></returns>
  104. public static Dictionary<string, object> Query(string condition, string fields)
  105. {
  106. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "MerchantDepositOrder", condition);
  107. return obj;
  108. }
  109. public static decimal Sum(string condition, string field)
  110. {
  111. decimal amount = 0;
  112. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field + "", "MerchantDepositOrder", condition);
  113. if (obj.Keys.Count > 0)
  114. {
  115. amount = decimal.Parse(obj[field].ToString());
  116. }
  117. return amount;
  118. }
  119. /// <summary>
  120. /// 查询记录数
  121. /// </summary>
  122. /// <param name="Id">主键Id</param>
  123. /// <returns></returns>
  124. public static int Count(string condition = "", string field = "Id")
  125. {
  126. int result = 0;
  127. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).Query("count(" + field + ") " + field + "", "MerchantDepositOrder", condition);
  128. if (obj.Keys.Count > 0)
  129. {
  130. result = int.Parse(function.CheckInt(obj[field].ToString()));
  131. }
  132. return result;
  133. }
  134. /// <summary>
  135. /// 查询是否存在
  136. /// </summary>
  137. /// <param name="Id">主键Id</param>
  138. /// <returns></returns>
  139. public static bool Exist(string condition)
  140. {
  141. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).Query("1", "MerchantDepositOrder", condition);
  142. if (obj.Keys.Count > 0)
  143. {
  144. return true;
  145. }
  146. return false;
  147. }
  148. /// <summary>
  149. /// 添加数据
  150. /// </summary>
  151. /// <param name="Fields">要设置的字段</param>
  152. /// <returns></returns>
  153. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  154. {
  155. if (check)
  156. {
  157. if (string.IsNullOrEmpty(fields["MerchantId"].ToString()))
  158. {
  159. return new AppResultJson() { Status = "-1", Info = "请填写商户Id" };
  160. }
  161. if (!function.IsInt(fields["MerchantId"].ToString()))
  162. {
  163. return new AppResultJson() { Status = "-1", Info = "请填写正确的商户Id" };
  164. }
  165. if (string.IsNullOrEmpty(fields["UserId"].ToString()))
  166. {
  167. return new AppResultJson() { Status = "-1", Info = "请填写创客Id" };
  168. }
  169. if (!function.IsInt(fields["UserId"].ToString()))
  170. {
  171. return new AppResultJson() { Status = "-1", Info = "请填写正确的创客Id" };
  172. }
  173. }
  174. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantDepositOrder", fields, 0);
  175. return new AppResultJson() { Status = "1", Data = Id };
  176. }
  177. /// <summary>
  178. /// 修改数据
  179. /// </summary>
  180. /// <param name="Fields">要设置的字段</param>
  181. /// <param name="Id">主键Id</param>
  182. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  183. {
  184. if (check)
  185. {
  186. if (string.IsNullOrEmpty(fields["MerchantId"].ToString()))
  187. {
  188. return new AppResultJson() { Status = "-1", Info = "请填写商户Id" };
  189. }
  190. if (!function.IsInt(fields["MerchantId"].ToString()))
  191. {
  192. return new AppResultJson() { Status = "-1", Info = "请填写正确的商户Id" };
  193. }
  194. if (string.IsNullOrEmpty(fields["UserId"].ToString()))
  195. {
  196. return new AppResultJson() { Status = "-1", Info = "请填写创客Id" };
  197. }
  198. if (!function.IsInt(fields["UserId"].ToString()))
  199. {
  200. return new AppResultJson() { Status = "-1", Info = "请填写正确的创客Id" };
  201. }
  202. }
  203. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantDepositOrder", fields, Id);
  204. return new AppResultJson() { Status = "1", Data = Id };
  205. }
  206. /// <summary>
  207. /// 逻辑删除
  208. /// </summary>
  209. /// <param name="Id">主键Id</param>
  210. public static void Remove(int Id)
  211. {
  212. Dictionary<string, object> fields = new Dictionary<string, object>();
  213. fields.Add("Status", -1);
  214. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantDepositOrder", fields, Id);
  215. }
  216. /// <summary>
  217. /// 删除数据
  218. /// </summary>
  219. /// <param name="Id">主键Id</param>
  220. public static void Delete(int Id)
  221. {
  222. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantDepositOrder", Id);
  223. }
  224. /// <summary>
  225. /// 排序
  226. /// </summary>
  227. /// <param name="Id">主键Id</param>
  228. /// <param name="Sort">排序序号</param>
  229. public static void Sort(int Id, int Sort)
  230. {
  231. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantDepositOrder", Sort, Id);
  232. }
  233. /// <summary>
  234. /// 导入数据
  235. /// </summary>
  236. /// <param name="ExcelData">json数据</param>
  237. public static void Import(string ExcelData)
  238. {
  239. // WebCMSEntities db = new WebCMSEntities();
  240. // JsonData list = JsonMapper.ToObject(ExcelData);
  241. // for (int i = 1; i < list.Count;i++ )
  242. // {
  243. // JsonData dr = list[i];
  244. // db.MerchantDepositOrder.Add(new MerchantDepositOrder()
  245. // {
  246. // CreateDate = DateTime.Now,
  247. // UpdateDate = DateTime.Now,
  248. // });
  249. // db.SaveChanges();
  250. // }
  251. // db.Dispose();
  252. }
  253. /// <summary>
  254. /// 导出excel表格
  255. /// </summary>
  256. /// <param name="fields">查询条件(单个字段)</param>
  257. /// <param name="condition">查询条件(sql语句)</param>
  258. /// <returns></returns>
  259. // public static void ExportExcel(List<RelationData> relationData, string condition)
  260. // {
  261. // }
  262. }
  263. }