BusinessUtil.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. using MySystem.Models.Main;
  2. using Library;
  3. using MySystem.Service.Main;
  4. using System.Collections.Generic;
  5. using System;
  6. using System.Linq;
  7. using System.Data;
  8. namespace MySystem
  9. {
  10. /// <summary>
  11. /// 经营数据工具类
  12. /// </summary>
  13. public class BusinessUtil
  14. {
  15. #region 经营数据记录(月)
  16. /// <summary>
  17. /// 经营数据记录(月)
  18. /// </summary>
  19. /// <param name="MerchantId">商户Id</param>
  20. /// <param name="TradeMonth">月份</param>
  21. /// <param name="pageSize">条数</param>
  22. /// <param name="pageNum">页数</param>
  23. /// <returns></returns>
  24. public static List<Dictionary<string, object>> BussinessRecordForMonth(int MerchantId, string TradeMonth, int pageSize, int pageNum)
  25. {
  26. List<RelationData> relationData = new List<RelationData>();
  27. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  28. // if (!new MerchantTradeSummaryService().CheckTableExist(TradeMonth))
  29. // {
  30. // return dataList;
  31. // }
  32. // List<Dictionary<string, object>> source = MerchantTradeSummaryService.List2(relationData, " and MerchantId=" + MerchantId, TradeMonth, pageNum, pageSize,"TradeDate desc");
  33. // foreach (Dictionary<string, object> subdata in source)
  34. // {
  35. // Dictionary<string, object> curData = new Dictionary<string, object>();
  36. // curData.Add("TradeDate", subdata["TradeDate"].ToString()); //日期
  37. // curData.Add("TotalAmount", decimal.Parse(subdata["TradeAmount"].ToString()).ToString("f2")); //营业总金额
  38. // curData.Add("InFactAmount", decimal.Parse(subdata["InFactAmount"].ToString()).ToString("f2")); //实收总金额
  39. // curData.Add("ActAmount", decimal.Parse(subdata["ActAmount"].ToString()).ToString("f2")); //活动总金额
  40. // curData.Add("NonActAmount", decimal.Parse(subdata["NonActAmount"].ToString()).ToString("f2")); //非活动总金额
  41. // curData.Add("WeChatInFactAmount", decimal.Parse(subdata["WeChatInfactAmount"].ToString()).ToString("f2")); //微信实收
  42. // curData.Add("AliPayInFactAmount", decimal.Parse(subdata["AliPayInFactAmount"].ToString()).ToString("f2")); //支付宝实收
  43. // curData.Add("OrderCount", subdata["OderCount"].ToString()); //订单数
  44. // curData.Add("Kind", 2); //通道(1 直连 2 银联)
  45. // dataList.Add(curData);
  46. // }
  47. string limit = " limit " + pageSize;
  48. if (pageNum > 1)
  49. {
  50. int skip = (pageNum - 1) * pageSize;
  51. limit = " limit " + skip + "," + pageSize;
  52. }
  53. DataTable dt = CustomerSqlConn.dtable("select TradeDate,sum(TradeAmount) TotalAmount,sum(TotalActual) InFactAmount,sum(if(IsAct=1,TradeAmount,0)) ActAmount,sum(if(IsAct=0,TradeAmount,0)) NonActAmount,sum(if(PayMode=2,TotalActual,0)) WeChatInFactAmount,sum(if(PayMode=1,TotalActual,0)) AliPayInFactAmount,sum(TradeCount) OrderCount from MerchantAmountSummay where MerchantId=" + MerchantId + " and TradeMonth='" + TradeMonth + "' group by TradeDate order by TradeDate desc" + limit, AppConfig.Base.SqlConnStr);
  54. if (dt.Rows.Count < 1)
  55. {
  56. return dataList;
  57. }
  58. foreach (DataRow subdata in dt.Rows)
  59. {
  60. Dictionary<string, object> curData = new Dictionary<string, object>();
  61. curData.Add("TradeDate", subdata["TradeDate"].ToString()); //日期
  62. curData.Add("TotalAmount", decimal.Parse(subdata["TotalAmount"].ToString()).ToString("f2")); //营业总金额
  63. curData.Add("InFactAmount", decimal.Parse(subdata["InFactAmount"].ToString()).ToString("f2")); //实收总金额
  64. curData.Add("ActAmount", decimal.Parse(subdata["ActAmount"].ToString()).ToString("f2")); //活动总金额
  65. curData.Add("NonActAmount", decimal.Parse(subdata["NonActAmount"].ToString()).ToString("f2")); //非活动总金额
  66. curData.Add("WeChatInFactAmount", decimal.Parse(subdata["WeChatInfactAmount"].ToString()).ToString("f2")); //微信实收
  67. curData.Add("AliPayInFactAmount", decimal.Parse(subdata["AliPayInFactAmount"].ToString()).ToString("f2")); //支付宝实收
  68. curData.Add("OrderCount", subdata["OrderCount"].ToString()); //订单数
  69. curData.Add("Kind", 2); //通道(1 直连 2 银联)
  70. dataList.Add(curData);
  71. }
  72. return dataList;
  73. }
  74. #endregion
  75. #region 经营数据记录(半年)
  76. /// <summary>
  77. /// 经营数据记录(半年)
  78. /// </summary>
  79. /// <param name="MerchantId">商户Id</param>
  80. /// <param name="pageSize">条数</param>
  81. /// <param name="pageNum">页数</param>
  82. /// <returns></returns>
  83. public static List<Dictionary<string, object>> BussinessRecordForHalfYear(int MerchantId, int pageSize, int pageNum)
  84. {
  85. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  86. // List<Dictionary<string, object>> source = UserTradeDbconn.Instance.GetMonthTradeList(MerchantId, "TradeAmount,InFactAmount,ActAmount,NonActAmount,WeChatInfactAmount,AliPayInFactAmount,OderCount");
  87. // foreach (Dictionary<string, object> subdata in source)
  88. // {
  89. // Dictionary<string, object> curData = new Dictionary<string, object>();
  90. // curData.Add("TradeDate", subdata["TradeDate"].ToString()); //日期
  91. // curData.Add("TotalAmount", decimal.Parse(subdata["TradeAmount"].ToString()).ToString("f2")); //营业总金额
  92. // curData.Add("InFactAmount", decimal.Parse(subdata["InFactAmount"].ToString()).ToString("f2")); //实收总金额
  93. // curData.Add("ActAmount", decimal.Parse(subdata["ActAmount"].ToString()).ToString("f2")); //活动总金额
  94. // curData.Add("NonActAmount", decimal.Parse(subdata["NonActAmount"].ToString()).ToString("f2")); //非活动总金额
  95. // curData.Add("WeChatInFactAmount", decimal.Parse(subdata["WeChatInfactAmount"].ToString()).ToString("f2")); //微信实收
  96. // curData.Add("AliPayInFactAmount", decimal.Parse(subdata["AliPayInFactAmount"].ToString()).ToString("f2")); //支付宝实收
  97. // curData.Add("OrderCount", subdata["OderCount"].ToString()); //订单数
  98. // dataList.Add(curData);
  99. // }
  100. var end = DateTime.Now.ToString("yyyyMM");
  101. var start = DateTime.Now.AddMonths(-5).ToString("yyyyMM");
  102. DataTable dt = CustomerSqlConn.dtable("SELECT TradeMonth 日期,SUM(TradeAmount) 营业总金额,SUM(TotalActual) 实收总金额,SUM(IF(IsAct=1,TotalActual,0)) 活动总金额,SUM(IF(IsAct=0,TotalActual,0)) 非活动总金额,SUM(IF(PayMode=1,TotalActual,0)) 微信实收,SUM(IF(PayMode=2,TotalActual,0)) 支付宝实收,SUM(TradeCount) 订单数 FROM MerchantAmountSummay WHERE MerchantId=" + MerchantId + " AND TradeMonth>='" + start + "' AND TradeMonth<='" + end + "' GROUP BY TradeMonth ORDER BY TradeMonth DESC", AppConfig.Base.SqlConnStr);
  103. if (dt.Rows.Count < 1)
  104. {
  105. return dataList;
  106. }
  107. else
  108. {
  109. foreach (DataRow item in dt.Rows)
  110. {
  111. Dictionary<string, object> curData = new Dictionary<string, object>();
  112. var TradeDate = item["日期"].ToString();
  113. curData.Add("TradeDate", TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(TradeDate.Length - 2, 2)); //日期
  114. curData.Add("TotalAmount", decimal.Parse(item["营业总金额"].ToString()).ToString("f2")); //营业总金额
  115. curData.Add("InFactAmount", decimal.Parse(item["实收总金额"].ToString()).ToString("f2")); //实收总金额
  116. curData.Add("ActAmount", decimal.Parse(item["活动总金额"].ToString()).ToString("f2")); //活动总金额
  117. curData.Add("NonActAmount", decimal.Parse(item["非活动总金额"].ToString()).ToString("f2")); //非活动总金额
  118. curData.Add("WeChatInFactAmount", decimal.Parse(item["微信实收"].ToString()).ToString("f2")); //微信实收
  119. curData.Add("AliPayInFactAmount", decimal.Parse(item["支付宝实收"].ToString()).ToString("f2")); //支付宝实收
  120. curData.Add("OrderCount", item["订单数"].ToString()); //订单数
  121. dataList.Add(curData);
  122. }
  123. }
  124. return dataList;
  125. }
  126. #endregion
  127. #region 经营详情列表
  128. /// <summary>
  129. /// 经营详情列表
  130. /// </summary>
  131. /// <param name="condition">查询条件</param>
  132. /// <param name="pageSize">条数</param>
  133. /// <param name="pageNum">页数</param>
  134. /// <returns></returns>
  135. public static List<Dictionary<string, object>> DayDetailList(string condition, int pageSize, int pageNum)
  136. {
  137. List<RelationData> relationData = new List<RelationData>();
  138. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  139. List<Dictionary<string, object>> source = ConsumerOrdersService.List(relationData, condition, pageNum, pageSize);
  140. foreach (Dictionary<string, object> subdata in source)
  141. {
  142. Dictionary<string, object> curData = new Dictionary<string, object>();
  143. curData.Add("Id", subdata["Id"].ToString()); //订单Id
  144. curData.Add("TradeDate", DateTime.Parse(subdata["CreateDate"].ToString()).ToString("HH:mm:ss")); //日期
  145. curData.Add("PayMode", subdata["PayMode"].ToString()); //支付方式(1 支付宝 2 微信)
  146. curData.Add("IsAct", subdata["IsAct"].ToString()); //是否活动(1 是 0 否)
  147. curData.Add("PayMoney", decimal.Parse(subdata["PayMoney"].ToString()).ToString("f2")); //订单金额
  148. curData.Add("Kind", 2); //通道(1 直连 2 银联)
  149. dataList.Add(curData);
  150. }
  151. return dataList;
  152. }
  153. #endregion
  154. #region 交易详情
  155. /// <summary>
  156. /// 交易详情
  157. /// </summary>
  158. /// <param name="condition">查询条件</param>
  159. /// <returns></returns>
  160. public static Dictionary<string, object> OrderDetail(string condition)
  161. {
  162. List<RelationData> relationData = new List<RelationData>();
  163. Dictionary<string, object> obj = new Dictionary<string, object>();
  164. List<Dictionary<string, object>> source = ConsumerOrdersService.List(relationData, condition, 1, 999);
  165. foreach (Dictionary<string, object> subdata in source)
  166. {
  167. var leaveAmount = decimal.Parse(subdata["MaxDivi"].ToString()) - decimal.Parse(subdata["CurDivi"].ToString());
  168. obj.Add("TradeDate", DateTime.Parse(subdata["CreateDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss")); //日期
  169. obj.Add("PayMode", subdata["PayMode"].ToString()); //支付方式(1 微信 2 支付宝)
  170. obj.Add("PayMoney", decimal.Parse(subdata["PayMoney"].ToString()).ToString("f2")); //支付金额
  171. obj.Add("IsAct", subdata["IsAct"].ToString()); //是否活动(1 是 0 否)
  172. obj.Add("OrderNo", subdata["OrderNo"].ToString()); //订单号
  173. obj.Add("ReturnFlag", int.Parse(subdata["ReturnFlag"].ToString())); //返现标记(0 否 1 是)
  174. obj.Add("Kind", 2); //通道(1 直连 2 银联)
  175. obj.Add("LeaveAmount", leaveAmount); //剩余返现金额
  176. obj.Add("MerchantName", MerchantInfoService.Query(int.Parse(subdata["MerchantId"].ToString())).Name); //交易门店
  177. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  178. List<Dictionary<string, object>> dics = ConsumerProfitService.List(relationData, " and OrderId=" + int.Parse(subdata["Id"].ToString()) + "", 1, 999);
  179. foreach (Dictionary<string, object> dic in dics)
  180. {
  181. Dictionary<string, object> cdata = new Dictionary<string, object>();
  182. var CreateDate = DateTime.Parse(dic["CreateDate"].ToString());
  183. var TradeDate = CreateDate.Month + "月" + CreateDate.Day + "日" + " " + CreateDate.ToString("HH:mm");
  184. cdata.Add("ProfitDate", TradeDate); //分红时间
  185. cdata.Add("ProfitAmount", decimal.Parse(dic["GetMoney"].ToString()).ToString("f2")); //分红金额
  186. dataList.Add(cdata);
  187. }
  188. obj.Add("ProfitTotalAmount", ConsumerProfitService.Sum(" OrderId=" + int.Parse(subdata["Id"].ToString()) + "", "GetMoney").ToString("f2")); //分红总金额
  189. obj.Add("ProfitList", dataList); //订单分红记录列表
  190. }
  191. return obj;
  192. }
  193. #endregion
  194. }
  195. }