BusinessUtil.cs 13 KB

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