ProfitReceiveRecordService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 ProfitReceiveRecordService
  14. {
  15. string _conn = "";
  16. public ProfitReceiveRecordService()
  17. {
  18. _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  19. }
  20. /// <summary>
  21. /// 查询列表
  22. /// </summary>
  23. /// <param name="relationData">关联表</param>
  24. /// <param name="condition">查询条件(sql语句)</param>
  25. /// <param name="count">总数(输出)</param>
  26. /// <param name="page">页码</param>
  27. /// <param name="limit">每页条数</param>
  28. /// <returns></returns>
  29. public 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")
  30. {
  31. List<string> fields = new List<string>(); //要显示的列
  32. fields.Add("Id");
  33. fields.Add("CreateDate"); //添加时间
  34. fields.Add("Status"); //状态
  35. fields.Add("MerchantId"); //商户
  36. fields.Add("SubMchid"); //子商户号
  37. fields.Add("AppId"); //应用ID
  38. fields.Add("SubAppId"); //子商户应用ID
  39. fields.Add("Type"); //分账接收方类型
  40. fields.Add("Account"); //分账接收方账号
  41. fields.Add("RelationType"); //与分账方的关系类型
  42. fields.Add("TransactionId"); //微信订单号
  43. fields.Add("OutOrderNo"); //商户分账单号
  44. fields.Add("Amount"); //分账金额
  45. fields.Add("UnfreezeUnsplit"); //是否解冻剩余未分资金
  46. fields.Add("OrderId"); //微信分账单号
  47. fields.Add("State"); //分账单状态
  48. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("ProfitReceiveRecord", relationData, orderBy, page, limit, condition, fields);
  49. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  50. count = int.Parse(obj["count"].ToString());
  51. return diclist;
  52. }
  53. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  54. {
  55. List<string> fields = new List<string>(); //要显示的列
  56. fields.Add("Id");
  57. fields.Add("CreateDate"); //添加时间
  58. fields.Add("Status"); //状态
  59. fields.Add("MerchantId"); //商户
  60. fields.Add("SubMchid"); //子商户号
  61. fields.Add("AppId"); //应用ID
  62. fields.Add("SubAppId"); //子商户应用ID
  63. fields.Add("Type"); //分账接收方类型
  64. fields.Add("Account"); //分账接收方账号
  65. fields.Add("RelationType"); //与分账方的关系类型
  66. fields.Add("TransactionId"); //微信订单号
  67. fields.Add("OutOrderNo"); //商户分账单号
  68. fields.Add("Amount"); //分账金额
  69. fields.Add("UnfreezeUnsplit"); //是否解冻剩余未分资金
  70. fields.Add("OrderId"); //微信分账单号
  71. fields.Add("State"); //分账单状态
  72. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("ProfitReceiveRecord", relationData, orderBy, page, limit, condition, fields);
  73. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  74. return diclist;
  75. }
  76. /// <summary>
  77. /// 查询一条记录
  78. /// </summary>
  79. /// <param name="Id">主键Id</param>
  80. /// <returns></returns>
  81. public ProfitReceiveRecord Query(int Id)
  82. {
  83. WebCMSEntities db = new WebCMSEntities();
  84. ProfitReceiveRecord editData = db.ProfitReceiveRecord.FirstOrDefault(m => m.Id == Id) ?? new ProfitReceiveRecord();
  85. db.Dispose();
  86. return editData;
  87. }
  88. /// <summary>
  89. /// 查询记录数
  90. /// </summary>
  91. /// <param name="Id">主键Id</param>
  92. /// <returns></returns>
  93. public int Count(string condition = "")
  94. {
  95. int result = 0;
  96. DataTable dt = CustomerSqlConn.dtable("select count(Id) from ProfitReceiveRecord where 1=1" + condition, _conn);
  97. if(dt.Rows.Count > 0)
  98. {
  99. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  100. }
  101. return result;
  102. }
  103. /// <summary>
  104. /// 查询是否存在
  105. /// </summary>
  106. /// <param name="Id">主键Id</param>
  107. /// <returns></returns>
  108. public bool Exist(int Id)
  109. {
  110. WebCMSEntities db = new WebCMSEntities();
  111. bool check = db.ProfitReceiveRecord.Any(m => m.Id == Id);
  112. db.Dispose();
  113. return check;
  114. }
  115. /// <summary>
  116. /// 添加数据
  117. /// </summary>
  118. /// <param name="Fields">要设置的字段</param>
  119. /// <returns></returns>
  120. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  121. {
  122. if(check)
  123. {
  124. if (string.IsNullOrEmpty(fields["MerchantId"].ToString()))
  125. {
  126. return new AppResultJson() { Status = "-1", Info = "请填写商户" };
  127. }
  128. if (string.IsNullOrEmpty(fields["SubMchid"].ToString()))
  129. {
  130. return new AppResultJson() { Status = "-1", Info = "请填写子商户号" };
  131. }
  132. if (string.IsNullOrEmpty(fields["AppId"].ToString()))
  133. {
  134. return new AppResultJson() { Status = "-1", Info = "请填写应用ID" };
  135. }
  136. if (string.IsNullOrEmpty(fields["SubAppId"].ToString()))
  137. {
  138. return new AppResultJson() { Status = "-1", Info = "请填写子商户应用ID" };
  139. }
  140. if (string.IsNullOrEmpty(fields["Type"].ToString()))
  141. {
  142. return new AppResultJson() { Status = "-1", Info = "请填写分账接收方类型" };
  143. }
  144. if (string.IsNullOrEmpty(fields["Account"].ToString()))
  145. {
  146. return new AppResultJson() { Status = "-1", Info = "请填写分账接收方账号" };
  147. }
  148. if (string.IsNullOrEmpty(fields["RelationType"].ToString()))
  149. {
  150. return new AppResultJson() { Status = "-1", Info = "请填写与分账方的关系类型" };
  151. }
  152. if (string.IsNullOrEmpty(fields["TransactionId"].ToString()))
  153. {
  154. return new AppResultJson() { Status = "-1", Info = "请填写微信订单号" };
  155. }
  156. if (string.IsNullOrEmpty(fields["OutOrderNo"].ToString()))
  157. {
  158. return new AppResultJson() { Status = "-1", Info = "请填写商户分账单号" };
  159. }
  160. if (string.IsNullOrEmpty(fields["Amount"].ToString()))
  161. {
  162. return new AppResultJson() { Status = "-1", Info = "请填写分账金额" };
  163. }
  164. if (!function.IsNum(fields["Amount"].ToString()))
  165. {
  166. return new AppResultJson() { Status = "-1", Info = "请填写正确的分账金额" };
  167. }
  168. if (string.IsNullOrEmpty(fields["Description"].ToString()))
  169. {
  170. return new AppResultJson() { Status = "-1", Info = "请填写分账描述" };
  171. }
  172. }
  173. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("ProfitReceiveRecord", fields, 0);
  174. return new AppResultJson(){ Status = "1", Data = Id };
  175. }
  176. /// <summary>
  177. /// 修改数据
  178. /// </summary>
  179. /// <param name="Fields">要设置的字段</param>
  180. /// <param name="Id">主键Id</param>
  181. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  182. {
  183. if(check)
  184. {
  185. if (string.IsNullOrEmpty(fields["MerchantId"].ToString()))
  186. {
  187. return new AppResultJson() { Status = "-1", Info = "请填写商户" };
  188. }
  189. if (string.IsNullOrEmpty(fields["SubMchid"].ToString()))
  190. {
  191. return new AppResultJson() { Status = "-1", Info = "请填写子商户号" };
  192. }
  193. if (string.IsNullOrEmpty(fields["AppId"].ToString()))
  194. {
  195. return new AppResultJson() { Status = "-1", Info = "请填写应用ID" };
  196. }
  197. if (string.IsNullOrEmpty(fields["SubAppId"].ToString()))
  198. {
  199. return new AppResultJson() { Status = "-1", Info = "请填写子商户应用ID" };
  200. }
  201. if (string.IsNullOrEmpty(fields["Type"].ToString()))
  202. {
  203. return new AppResultJson() { Status = "-1", Info = "请填写分账接收方类型" };
  204. }
  205. if (string.IsNullOrEmpty(fields["Account"].ToString()))
  206. {
  207. return new AppResultJson() { Status = "-1", Info = "请填写分账接收方账号" };
  208. }
  209. if (string.IsNullOrEmpty(fields["RelationType"].ToString()))
  210. {
  211. return new AppResultJson() { Status = "-1", Info = "请填写与分账方的关系类型" };
  212. }
  213. if (string.IsNullOrEmpty(fields["TransactionId"].ToString()))
  214. {
  215. return new AppResultJson() { Status = "-1", Info = "请填写微信订单号" };
  216. }
  217. if (string.IsNullOrEmpty(fields["OutOrderNo"].ToString()))
  218. {
  219. return new AppResultJson() { Status = "-1", Info = "请填写商户分账单号" };
  220. }
  221. if (string.IsNullOrEmpty(fields["Amount"].ToString()))
  222. {
  223. return new AppResultJson() { Status = "-1", Info = "请填写分账金额" };
  224. }
  225. if (!function.IsNum(fields["Amount"].ToString()))
  226. {
  227. return new AppResultJson() { Status = "-1", Info = "请填写正确的分账金额" };
  228. }
  229. if (string.IsNullOrEmpty(fields["Description"].ToString()))
  230. {
  231. return new AppResultJson() { Status = "-1", Info = "请填写分账描述" };
  232. }
  233. }
  234. new DbService(AppConfig.Base.dbTables, _conn).Edit("ProfitReceiveRecord", fields, Id);
  235. return new AppResultJson(){ Status = "1", Data = Id };
  236. }
  237. /// <summary>
  238. /// 逻辑删除
  239. /// </summary>
  240. /// <param name="Id">主键Id</param>
  241. public void Remove(int Id)
  242. {
  243. Dictionary<string, object> fields = new Dictionary<string, object>();
  244. fields.Add("Status", -1);
  245. new DbService(AppConfig.Base.dbTables, _conn).Edit("ProfitReceiveRecord", fields, Id);
  246. }
  247. /// <summary>
  248. /// 删除数据
  249. /// </summary>
  250. /// <param name="Id">主键Id</param>
  251. public void Delete(int Id)
  252. {
  253. new DbService(AppConfig.Base.dbTables, _conn).Delete("ProfitReceiveRecord", Id);
  254. }
  255. /// <summary>
  256. /// 排序
  257. /// </summary>
  258. /// <param name="Id">主键Id</param>
  259. /// <param name="Sort">排序序号</param>
  260. public void Sort(int Id, int Sort)
  261. {
  262. new DbService(AppConfig.Base.dbTables, _conn).Sort("ProfitReceiveRecord", Sort, Id);
  263. }
  264. /// <summary>
  265. /// 导入数据
  266. /// </summary>
  267. /// <param name="ExcelData">json数据</param>
  268. public void Import(string ExcelData)
  269. {
  270. WebCMSEntities db = new WebCMSEntities();
  271. JsonData list = JsonMapper.ToObject(ExcelData);
  272. for (int i = 1; i < list.Count;i++ )
  273. {
  274. JsonData dr = list[i];
  275. db.ProfitReceiveRecord.Add(new ProfitReceiveRecord()
  276. {
  277. CreateDate = DateTime.Now,
  278. UpdateDate = DateTime.Now,
  279. });
  280. db.SaveChanges();
  281. }
  282. db.Dispose();
  283. }
  284. /// <summary>
  285. /// 导出excel表格
  286. /// </summary>
  287. /// <param name="fields">查询条件(单个字段)</param>
  288. /// <param name="condition">查询条件(sql语句)</param>
  289. /// <returns></returns>
  290. // public void ExportExcel(List<RelationData> relationData, string condition)
  291. // {
  292. // }
  293. }
  294. }