OrderRefundService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 OrderRefundService
  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("Reason"); //退款原因
  32. fields.Add("Amount"); //退款金额
  33. fields.Add("Mobile"); //申请人手机号
  34. fields.Add("GoodStatus"); //货物状态
  35. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("OrderRefund", 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("Reason"); //退款原因
  47. fields.Add("Amount"); //退款金额
  48. fields.Add("Mobile"); //申请人手机号
  49. fields.Add("GoodStatus"); //货物状态
  50. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("OrderRefund", 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="Id">主键Id</param>
  58. /// <returns></returns>
  59. public static OrderRefund Query(int Id)
  60. {
  61. WebCMSEntities db = new WebCMSEntities();
  62. OrderRefund editData = db.OrderRefund.FirstOrDefault(m => m.Id == Id) ?? new OrderRefund();
  63. db.Dispose();
  64. return editData;
  65. }
  66. public static OrderRefund Query(string condition, string fields = "*")
  67. {
  68. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail(fields, "OrderRefund", condition);
  69. // if (dt.Rows.Count > 0)
  70. // {
  71. // Dictionary<string, object> row = new Dictionary<string, object>();
  72. // foreach (DataColumn dc in dt.Columns)
  73. // {
  74. // row.Add(dc.ColumnName, dt.Rows[0][dc.ColumnName].ToString());
  75. // }
  76. // return Newtonsoft.Json.JsonConvert.DeserializeObject<OrderRefund>(Newtonsoft.Json.JsonConvert.SerializeObject(row));
  77. // }
  78. // return new OrderRefund();
  79. var orderRefund = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "OrderRefund", condition);
  80. if (orderRefund.Count > 0)
  81. {
  82. return Newtonsoft.Json.JsonConvert.DeserializeObject<OrderRefund>(Newtonsoft.Json.JsonConvert.SerializeObject(orderRefund));
  83. }
  84. return new OrderRefund();
  85. }
  86. public static decimal Sum(string condition, string field)
  87. {
  88. DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("Sum(" + field + ")", "OrderRefund", condition);
  89. decimal amount = 0;
  90. if (dt.Rows.Count > 0)
  91. {
  92. amount = decimal.Parse(dt.Rows[0][0].ToString());
  93. }
  94. return amount;
  95. }
  96. /// <summary>
  97. /// 查询记录数
  98. /// </summary>
  99. /// <param name="Id">主键Id</param>
  100. /// <returns></returns>
  101. public static int Count(string condition = "", string field = "Id")
  102. {
  103. int result = 0;
  104. DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("count(" + field + ")", "OrderRefund", condition);
  105. if (dt.Rows.Count > 0)
  106. {
  107. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  108. }
  109. return result;
  110. }
  111. /// <summary>
  112. /// 查询是否存在
  113. /// </summary>
  114. /// <param name="Id">主键Id</param>
  115. /// <returns></returns>
  116. public static bool Exist(int Id)
  117. {
  118. WebCMSEntities db = new WebCMSEntities();
  119. bool check = db.OrderRefund.Any(m => m.Id == Id);
  120. db.Dispose();
  121. return check;
  122. }
  123. /// <summary>
  124. /// 添加数据
  125. /// </summary>
  126. /// <param name="Fields">要设置的字段</param>
  127. /// <returns></returns>
  128. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  129. {
  130. if (check)
  131. {
  132. if (string.IsNullOrEmpty(fields["Reason"].ToString()))
  133. {
  134. return new AppResultJson() { Status = "-1", Info = "请填写退款原因" };
  135. }
  136. if (string.IsNullOrEmpty(fields["Amount"].ToString()))
  137. {
  138. return new AppResultJson() { Status = "-1", Info = "请填写退款金额" };
  139. }
  140. if (!function.IsNum(fields["Amount"].ToString()))
  141. {
  142. return new AppResultJson() { Status = "-1", Info = "请填写正确的退款金额" };
  143. }
  144. if (string.IsNullOrEmpty(fields["Mobile"].ToString()))
  145. {
  146. return new AppResultJson() { Status = "-1", Info = "请填写申请人手机号" };
  147. }
  148. if (function.CheckMobile(fields["Mobile"].ToString()) == "")
  149. {
  150. return new AppResultJson() { Status = "-1", Info = "请填写正确的申请人手机号" };
  151. }
  152. }
  153. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("OrderRefund", fields, 0);
  154. return new AppResultJson() { Status = "1", Data = Id };
  155. }
  156. /// <summary>
  157. /// 修改数据
  158. /// </summary>
  159. /// <param name="Fields">要设置的字段</param>
  160. /// <param name="Id">主键Id</param>
  161. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  162. {
  163. if (check)
  164. {
  165. if (string.IsNullOrEmpty(fields["Reason"].ToString()))
  166. {
  167. return new AppResultJson() { Status = "-1", Info = "请填写退款原因" };
  168. }
  169. if (string.IsNullOrEmpty(fields["Amount"].ToString()))
  170. {
  171. return new AppResultJson() { Status = "-1", Info = "请填写退款金额" };
  172. }
  173. if (!function.IsNum(fields["Amount"].ToString()))
  174. {
  175. return new AppResultJson() { Status = "-1", Info = "请填写正确的退款金额" };
  176. }
  177. if (string.IsNullOrEmpty(fields["Mobile"].ToString()))
  178. {
  179. return new AppResultJson() { Status = "-1", Info = "请填写申请人手机号" };
  180. }
  181. if (function.CheckMobile(fields["Mobile"].ToString()) == "")
  182. {
  183. return new AppResultJson() { Status = "-1", Info = "请填写正确的申请人手机号" };
  184. }
  185. }
  186. new DbService(AppConfig.Base.dbTables, _conn).Edit("OrderRefund", fields, Id);
  187. return new AppResultJson() { Status = "1", Data = Id };
  188. }
  189. /// <summary>
  190. /// 逻辑删除
  191. /// </summary>
  192. /// <param name="Id">主键Id</param>
  193. public static void Remove(int Id)
  194. {
  195. Dictionary<string, object> fields = new Dictionary<string, object>();
  196. fields.Add("Status", -1);
  197. new DbService(AppConfig.Base.dbTables, _conn).Edit("OrderRefund", fields, Id);
  198. }
  199. /// <summary>
  200. /// 删除数据
  201. /// </summary>
  202. /// <param name="Id">主键Id</param>
  203. public static void Delete(int Id)
  204. {
  205. new DbService(AppConfig.Base.dbTables, _conn).Delete("OrderRefund", Id);
  206. }
  207. /// <summary>
  208. /// 排序
  209. /// </summary>
  210. /// <param name="Id">主键Id</param>
  211. /// <param name="Sort">排序序号</param>
  212. public static void Sort(int Id, int Sort)
  213. {
  214. new DbService(AppConfig.Base.dbTables, _conn).Sort("OrderRefund", Sort, Id);
  215. }
  216. /// <summary>
  217. /// 导入数据
  218. /// </summary>
  219. /// <param name="ExcelData">json数据</param>
  220. public static void Import(string ExcelData)
  221. {
  222. WebCMSEntities db = new WebCMSEntities();
  223. JsonData list = JsonMapper.ToObject(ExcelData);
  224. for (int i = 1; i < list.Count; i++)
  225. {
  226. JsonData dr = list[i];
  227. db.OrderRefund.Add(new OrderRefund()
  228. {
  229. CreateDate = DateTime.Now,
  230. UpdateDate = DateTime.Now,
  231. });
  232. db.SaveChanges();
  233. }
  234. db.Dispose();
  235. }
  236. /// <summary>
  237. /// 导出excel表格
  238. /// </summary>
  239. /// <param name="fields">查询条件(单个字段)</param>
  240. /// <param name="condition">查询条件(sql语句)</param>
  241. /// <returns></returns>
  242. // public static void ExportExcel(List<RelationData> relationData, string condition)
  243. // {
  244. // }
  245. }
  246. }