SysWithdrawalApplyRecordService.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*
  2. * 润观米账户提现申请记录
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Main1;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Main1
  12. {
  13. public class SysWithdrawalApplyRecordService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["SqlConnStr1"].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. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.main1Tables, _conn).IndexData("SysWithdrawalApplyRecord", relationData, orderBy, page, limit, condition, fields);
  29. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  30. count = int.Parse(obj["count"].ToString());
  31. return diclist;
  32. }
  33. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  34. {
  35. List<string> fields = new List<string>(); //要显示的列,不设置则返回全部字段
  36. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.main1Tables, _conn).IndexData("SysWithdrawalApplyRecord", relationData, orderBy, page, limit, condition, fields);
  37. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  38. return diclist;
  39. }
  40. /// <summary>
  41. /// 查询列表(单表)
  42. /// </summary>
  43. /// <param name="fieldList">返回的字段</param>
  44. /// <param name="condition">查询条件</param>
  45. /// <param name="page">页码</param>
  46. /// <param name="limit">每页条数</param>
  47. /// <param name="orderBy">排序</param>
  48. /// <returns></returns>
  49. public static List<Dictionary<string, object>> List(string fieldList, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  50. {
  51. List<string> fields = fieldList.Split(',').ToList(); //要显示的列
  52. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.main1Tables, _conn).IndexData("SysWithdrawalApplyRecord", new List<RelationData>(), orderBy, page, limit, condition, fields);
  53. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  54. return diclist;
  55. }
  56. /// <summary>
  57. /// 查询一条记录
  58. /// </summary>
  59. /// <param name="Id">主键Id</param>
  60. /// <returns></returns>
  61. public static SysWithdrawalApplyRecord Query(int Id)
  62. {
  63. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.main1Tables, _conn).Query("*", "SysWithdrawalApplyRecord", Id);
  64. if (obj.Keys.Count > 0)
  65. {
  66. return Newtonsoft.Json.JsonConvert.DeserializeObject<SysWithdrawalApplyRecord>(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
  67. }
  68. return new SysWithdrawalApplyRecord();
  69. }
  70. /// <summary>
  71. /// 查询一条记录
  72. /// </summary>
  73. /// <param name="condition">查询条件(sql语句)</param>
  74. /// <returns></returns>
  75. public static SysWithdrawalApplyRecord Query(string condition)
  76. {
  77. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.main1Tables, _conn).Query("*", "SysWithdrawalApplyRecord", condition);
  78. if (obj.Keys.Count > 0)
  79. {
  80. return Newtonsoft.Json.JsonConvert.DeserializeObject<SysWithdrawalApplyRecord>(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
  81. }
  82. return new SysWithdrawalApplyRecord();
  83. }
  84. /// <summary>
  85. /// 查询一条记录
  86. /// </summary>
  87. /// <param name="condition">查询条件(sql语句)</param>
  88. /// <param name="fields">返回的字段</param>
  89. /// <returns></returns>
  90. public static Dictionary<string, object> Query(string condition, string fields)
  91. {
  92. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.main1Tables, _conn).Query(fields, "SysWithdrawalApplyRecord", condition);
  93. return obj;
  94. }
  95. /// <summary>
  96. /// 单字段统计
  97. /// </summary>
  98. /// <param name="condition"></param>
  99. /// <param name="field"></param>
  100. /// <returns></returns>
  101. public static decimal Sum(string condition, string field)
  102. {
  103. decimal amount = 0;
  104. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.main1Tables, _conn).Query("Sum(" + field + ") " + field + "", "SysWithdrawalApplyRecord", condition);
  105. if (obj.Keys.Count > 0)
  106. {
  107. amount = decimal.Parse(function.CheckNum(obj[field].ToString()));
  108. }
  109. return amount;
  110. }
  111. /// <summary>
  112. /// 多字段统计
  113. /// </summary>
  114. /// <param name="field"></param>
  115. /// <param name="condition"></param>
  116. /// <returns></returns>
  117. public static Dictionary<string, string> Sums(string field, string condition)
  118. {
  119. Dictionary<string, string> result = new Dictionary<string, string>();
  120. string sumString = "";
  121. string[] fieldlist = field.Split(',');
  122. foreach (string f in fieldlist)
  123. {
  124. sumString += "sum(" + f + ") " + f + ",";
  125. }
  126. sumString = sumString.TrimEnd(',');
  127. DataTable dt = CustomerSqlConn.dtable("select " + sumString + " from SysWithdrawalApplyRecord where 1=1" + condition, _conn);
  128. if (dt.Rows.Count > 0)
  129. {
  130. foreach (string f in fieldlist)
  131. {
  132. result.Add(f, function.CheckNum(dt.Rows[0][f].ToString()));
  133. }
  134. }
  135. return result;
  136. }
  137. /// <summary>
  138. /// 查询记录数
  139. /// </summary>
  140. /// <param name="Id">主键Id</param>
  141. /// <returns></returns>
  142. public static int Count(string condition = "", string field = "Id")
  143. {
  144. int result = 0;
  145. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.main1Tables, _conn).Query("count(" + field + ") " + field + "", "SysWithdrawalApplyRecord", condition);
  146. if (obj.Keys.Count > 0)
  147. {
  148. result = int.Parse(function.CheckInt(obj[field].ToString()));
  149. }
  150. return result;
  151. }
  152. /// <summary>
  153. /// 查询是否存在
  154. /// </summary>
  155. /// <param name="Id">主键Id</param>
  156. /// <returns></returns>
  157. public static bool Exist(string condition)
  158. {
  159. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.main1Tables, _conn).Query("1", "SysWithdrawalApplyRecord", condition);
  160. if (obj.Keys.Count > 0)
  161. {
  162. return true;
  163. }
  164. return false;
  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. if (string.IsNullOrEmpty(fields["MerchantId"].ToString()))
  176. {
  177. return new AppResultJson() { Status = "-1", Info = "请填写商户" };
  178. }
  179. if (string.IsNullOrEmpty(fields["ConsumerId"].ToString()))
  180. {
  181. return new AppResultJson() { Status = "-1", Info = "请填写消费者" };
  182. }
  183. if (string.IsNullOrEmpty(fields["PayMode"].ToString()))
  184. {
  185. return new AppResultJson() { Status = "-1", Info = "请填写支付方式" };
  186. }
  187. if (string.IsNullOrEmpty(fields["PayMoney"].ToString()))
  188. {
  189. return new AppResultJson() { Status = "-1", Info = "请填写支付金额" };
  190. }
  191. if (!function.IsNum(fields["PayMoney"].ToString()))
  192. {
  193. return new AppResultJson() { Status = "-1", Info = "请填写正确的支付金额" };
  194. }
  195. if (string.IsNullOrEmpty(fields["ReturnMoney"].ToString()))
  196. {
  197. return new AppResultJson() { Status = "-1", Info = "请填写已返金额" };
  198. }
  199. if (!function.IsNum(fields["ReturnMoney"].ToString()))
  200. {
  201. return new AppResultJson() { Status = "-1", Info = "请填写正确的已返金额" };
  202. }
  203. if (string.IsNullOrEmpty(fields["MaxDivi"].ToString()))
  204. {
  205. return new AppResultJson() { Status = "-1", Info = "请填写最大分红" };
  206. }
  207. if (!function.IsNum(fields["MaxDivi"].ToString()))
  208. {
  209. return new AppResultJson() { Status = "-1", Info = "请填写正确的最大分红" };
  210. }
  211. if (string.IsNullOrEmpty(fields["CurDivi"].ToString()))
  212. {
  213. return new AppResultJson() { Status = "-1", Info = "请填写当前分红" };
  214. }
  215. if (!function.IsNum(fields["CurDivi"].ToString()))
  216. {
  217. return new AppResultJson() { Status = "-1", Info = "请填写正确的当前分红" };
  218. }
  219. if (string.IsNullOrEmpty(fields["IsAct"].ToString()))
  220. {
  221. return new AppResultJson() { Status = "-1", Info = "请填写是否活动" };
  222. }
  223. }
  224. int Id = new DbServiceNew(AppConfig.Base.main1Tables, _conn).Add("SysWithdrawalApplyRecord", fields, 0);
  225. return new AppResultJson() { Status = "1", Data = Id };
  226. }
  227. /// <summary>
  228. /// 修改数据
  229. /// </summary>
  230. /// <param name="Fields">要设置的字段</param>
  231. /// <param name="Id">主键Id</param>
  232. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  233. {
  234. if (check)
  235. {
  236. if (string.IsNullOrEmpty(fields["MerchantId"].ToString()))
  237. {
  238. return new AppResultJson() { Status = "-1", Info = "请填写商户" };
  239. }
  240. if (string.IsNullOrEmpty(fields["ConsumerId"].ToString()))
  241. {
  242. return new AppResultJson() { Status = "-1", Info = "请填写消费者" };
  243. }
  244. if (string.IsNullOrEmpty(fields["PayMode"].ToString()))
  245. {
  246. return new AppResultJson() { Status = "-1", Info = "请填写支付方式" };
  247. }
  248. if (string.IsNullOrEmpty(fields["PayMoney"].ToString()))
  249. {
  250. return new AppResultJson() { Status = "-1", Info = "请填写支付金额" };
  251. }
  252. if (!function.IsNum(fields["PayMoney"].ToString()))
  253. {
  254. return new AppResultJson() { Status = "-1", Info = "请填写正确的支付金额" };
  255. }
  256. if (string.IsNullOrEmpty(fields["ReturnMoney"].ToString()))
  257. {
  258. return new AppResultJson() { Status = "-1", Info = "请填写已返金额" };
  259. }
  260. if (!function.IsNum(fields["ReturnMoney"].ToString()))
  261. {
  262. return new AppResultJson() { Status = "-1", Info = "请填写正确的已返金额" };
  263. }
  264. if (string.IsNullOrEmpty(fields["MaxDivi"].ToString()))
  265. {
  266. return new AppResultJson() { Status = "-1", Info = "请填写最大分红" };
  267. }
  268. if (!function.IsNum(fields["MaxDivi"].ToString()))
  269. {
  270. return new AppResultJson() { Status = "-1", Info = "请填写正确的最大分红" };
  271. }
  272. if (string.IsNullOrEmpty(fields["CurDivi"].ToString()))
  273. {
  274. return new AppResultJson() { Status = "-1", Info = "请填写当前分红" };
  275. }
  276. if (!function.IsNum(fields["CurDivi"].ToString()))
  277. {
  278. return new AppResultJson() { Status = "-1", Info = "请填写正确的当前分红" };
  279. }
  280. if (string.IsNullOrEmpty(fields["IsAct"].ToString()))
  281. {
  282. return new AppResultJson() { Status = "-1", Info = "请填写是否活动" };
  283. }
  284. }
  285. new DbServiceNew(AppConfig.Base.main1Tables, _conn).Edit("SysWithdrawalApplyRecord", fields, Id);
  286. return new AppResultJson() { Status = "1", Data = Id };
  287. }
  288. /// <summary>
  289. /// 逻辑删除
  290. /// </summary>
  291. /// <param name="Id">主键Id</param>
  292. public static void Remove(int Id)
  293. {
  294. Dictionary<string, object> fields = new Dictionary<string, object>();
  295. fields.Add("Status", -1);
  296. new DbServiceNew(AppConfig.Base.main1Tables, _conn).Edit("SysWithdrawalApplyRecord", fields, Id);
  297. }
  298. /// <summary>
  299. /// 删除数据
  300. /// </summary>
  301. /// <param name="Id">主键Id</param>
  302. public static void Delete(int Id)
  303. {
  304. new DbServiceNew(AppConfig.Base.main1Tables, _conn).Delete("SysWithdrawalApplyRecord", Id);
  305. }
  306. /// <summary>
  307. /// 排序
  308. /// </summary>
  309. /// <param name="Id">主键Id</param>
  310. /// <param name="Sort">排序序号</param>
  311. public static void Sort(int Id, int Sort)
  312. {
  313. new DbServiceNew(AppConfig.Base.main1Tables, _conn).Sort("SysWithdrawalApplyRecord", Sort, Id);
  314. }
  315. /// <summary>
  316. /// 导入数据
  317. /// </summary>
  318. /// <param name="ExcelData">json数据</param>
  319. public static void Import(string ExcelData)
  320. {
  321. // WebCMSEntities db = new WebCMSEntities();
  322. // JsonData list = JsonMapper.ToObject(ExcelData);
  323. // for (int i = 1; i < list.Count;i++ )
  324. // {
  325. // JsonData dr = list[i];
  326. // db.SysWithdrawalApplyRecord.Add(new SysWithdrawalApplyRecord()
  327. // {
  328. // CreateDate = DateTime.Now,
  329. // UpdateDate = DateTime.Now,
  330. // });
  331. // db.SaveChanges();
  332. // }
  333. // db.Dispose();
  334. }
  335. /// <summary>
  336. /// 导出excel表格
  337. /// </summary>
  338. /// <param name="fields">查询条件(单个字段)</param>
  339. /// <param name="condition">查询条件(sql语句)</param>
  340. /// <returns></returns>
  341. // public static void ExportExcel(List<RelationData> relationData, string condition)
  342. // {
  343. // }
  344. }
  345. }