Przeglądaj źródła

调整统计数据

lcl 1 rok temu
rodzic
commit
6c778ae683

+ 2 - 2
AppStart/Redis/Mysql/MerchantAmountSummary.cs

@@ -97,7 +97,7 @@ namespace MySystem
             {
                 skipNum = PageSize * (PageNum - 1);
             }
-            DataTable dt = CustomerSqlConn.dtable("select TradeDate,sum(if(PayMode=1, TotalActual, 0)),sum(if(PayMode=2, TotalActual, 0)),sum(TotalActual),sum(TradeCount) from MerchantAmountSummay where MerchantId=" + MerchantId + " and TradeMonth='" + TradeMonth + "' group by TradeDate order by TradeDate desc limit " + skipNum + "," + PageSize, AppConfig.Base.SqlConnStr);
+            DataTable dt = CustomerSqlConn.dtable("select TradeDate,sum(if(PayMode=1, TotalActual, 0)),sum(if(PayMode=2, TotalActual, 0)),sum(TotalActual),sum(TradeCount),sum(TradeAmount) from MerchantAmountSummay where MerchantId=" + MerchantId + " and TradeMonth='" + TradeMonth + "' group by TradeDate order by TradeDate desc limit " + skipNum + "," + PageSize, AppConfig.Base.SqlConnStr);
             return dt;
         }
 
@@ -108,7 +108,7 @@ namespace MySystem
             {
                 skipNum = PageSize * (PageNum - 1);
             }
-            DataTable dt = CustomerSqlConn.dtable("select TradeMonth,sum(if(PayMode=1, TotalActual, 0)),sum(if(PayMode=2, TotalActual, 0)),sum(TotalActual),sum(TradeCount) from MerchantAmountSummay where MerchantId=" + MerchantId + " group by TradeMonth order by TradeMonth desc limit " + skipNum + "," + PageSize, AppConfig.Base.SqlConnStr);
+            DataTable dt = CustomerSqlConn.dtable("select TradeMonth,sum(if(PayMode=1, TotalActual, 0)),sum(if(PayMode=2, TotalActual, 0)),sum(TotalActual),sum(TradeCount),sum(TradeAmount) from MerchantAmountSummay where MerchantId=" + MerchantId + " group by TradeMonth order by TradeMonth desc limit " + skipNum + "," + PageSize, AppConfig.Base.SqlConnStr);
             return dt;
         }
     }

+ 4 - 2
Areas/Api/Controllers/v1/MainServer/ConsumerOrdersController.cs

@@ -48,7 +48,8 @@ namespace MySystem.Areas.Api.Controllers.v1
                 string TradeDate = dr["TradeDate"].ToString();
                 Dictionary<string, object> curData = new Dictionary<string, object>();
                 curData.Add("Date", TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2)); //日期
-                curData.Add("Amount", dr[3].ToString()); //实收金额
+                curData.Add("TotalAmount", dr[5].ToString()); //营收金额
+                curData.Add("TotalActual", dr[3].ToString()); //实收金额
                 curData.Add("WeChatAmount", dr[2].ToString()); //微信实收
                 curData.Add("AlipayAmount", dr[1].ToString()); //支付宝实收
                 curData.Add("OrderCount", dr[4].ToString()); //订单数
@@ -83,7 +84,8 @@ namespace MySystem.Areas.Api.Controllers.v1
                 string TradeDate = dr["TradeMonth"].ToString();
                 Dictionary<string, object> curData = new Dictionary<string, object>();
                 curData.Add("Date", TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2)); //日期
-                curData.Add("Amount", dr[3].ToString()); //实收金额
+                curData.Add("TotalAmount", dr[5].ToString()); //营收金额
+                curData.Add("TotalActual", dr[3].ToString()); //实收金额
                 curData.Add("WeChatAmount", dr[2].ToString()); //微信实收
                 curData.Add("AlipayAmount", dr[1].ToString()); //支付宝实收
                 curData.Add("OrderCount", dr[4].ToString()); //订单数

+ 22 - 21
Areas/Api/Controllers/v1/MainServer/MerchantInfoController.cs

@@ -197,8 +197,8 @@ namespace MySystem.Areas.Api.Controllers.v1
                 curData.Add("MerchantName", item.Name); //商户姓名
                 curData.Add("KqRegTime", item.CreateDate == null ? "" : item.CreateDate.Value.ToString("yyyy-MM-dd")); //渠道注册时间
                 curData.Add("Id", item.Id); //Id
-                curData.Add("TotalAmount", item.TotalAmount); //交易额
-                curData.Add("TodayTrade", MerchantTradeStat.Instance.Amount(item.Id, DateTime.Now.ToString("yyyyMMdd"))); //今日交易额
+                curData.Add("TotalAmount", item.TotalAmount.ToString("f2")); //交易额
+                curData.Add("TodayTrade", MerchantTradeStat.Instance.Amount(item.Id, DateTime.Now.ToString("yyyyMMdd")).ToString("f2")); //今日交易额
                 curData.Add("TradeCount", item.TotalConsumeCount); //交易笔数
                 curData.Add("TodayTradeCount", MerchantTradeStat.Instance.Count(item.Id, DateTime.Now.ToString("yyyyMMdd"))); //今日交易笔数
                 dataList.Add(curData);
@@ -235,7 +235,7 @@ namespace MySystem.Areas.Api.Controllers.v1
             Obj.Add("SubjectType", addinfo.SubjectType); //主体类型
             Obj.Add("CreateDate", merchant.CreateDate == null ? "" : merchant.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //注册时间
             Obj.Add("ActivationDate", merchant.ActivationDate == null ? "" : merchant.ActivationDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //达标时间
-            Obj.Add("TotalAmount", merchant.TotalAmount); //总交易额
+            Obj.Add("TotalAmount", merchant.TotalAmount.ToString("f2")); //总交易额
             Obj.Add("ActivationStatus", merchant.ActivationStatus); //达标状态
             return Obj;
         }
@@ -289,14 +289,14 @@ namespace MySystem.Areas.Api.Controllers.v1
                 int TradeCount = 0;
                 if(total.Rows.Count > 0)
                 {
-                    TradeAmt = decimal.Parse(total.Rows[0][0].ToString()); //交易金额
-                    ActTradeAmt = decimal.Parse(total.Rows[0][2].ToString()); //活动交易金额
-                    UnActTradeAmt = decimal.Parse(total.Rows[0][3].ToString()); //非活动交易金额
-                    TradeCount = int.Parse(total.Rows[0][1].ToString()); //交易笔数
+                    TradeAmt = decimal.Parse(function.CheckNum(total.Rows[0][0].ToString())); //交易金额
+                    ActTradeAmt = decimal.Parse(function.CheckNum(total.Rows[0][2].ToString())); //活动交易金额
+                    UnActTradeAmt = decimal.Parse(function.CheckNum(total.Rows[0][3].ToString())); //非活动交易金额
+                    TradeCount = int.Parse(function.CheckNum(total.Rows[0][1].ToString())); //交易笔数
                 }
-                other.Add("TradeAmt", TradeAmt); //交易金额
-                other.Add("ActTradeAmt", ActTradeAmt); //活动交易金额
-                other.Add("UnActTradeAmt", UnActTradeAmt); //非活动交易金额
+                other.Add("TradeAmt", TradeAmt.ToString("f2")); //交易金额
+                other.Add("ActTradeAmt", ActTradeAmt.ToString("f2")); //活动交易金额
+                other.Add("UnActTradeAmt", UnActTradeAmt.ToString("f2")); //非活动交易金额
                 other.Add("TradeCount", TradeCount); //交易笔数
             }
             return dataList;
@@ -337,7 +337,7 @@ namespace MySystem.Areas.Api.Controllers.v1
             {
                 Dictionary<string, object> curData = new Dictionary<string, object>();
                 curData.Add("SnNo", item.SnNo); //sn
-                curData.Add("TradeAmount", QrCodeTradeStat.Instance.Amount(item.SnNo));
+                curData.Add("TradeAmount", QrCodeTradeStat.Instance.Amount(item.SnNo).ToString("f2"));
                 dataList.Add(curData);
             }
             return dataList;
@@ -632,17 +632,17 @@ namespace MySystem.Areas.Api.Controllers.v1
             }
             while(Start <= DateTime.Now)
             {
-                MerchantAmountSummay query = new MerchantAmountSummayService().Query(Id, Start.ToString("yyyyMMdd"));
-                TotalAmount += query.TradeAmount;
-                TotalOrder += query.TradeCount;
+                Dictionary<string, string> dic = new MerchantAmountSummayService().Sum("TradeAmount,TradeCount,TotalActual", " and MerchantId=" + Id + " and TradeDate='" + Start.ToString("yyyyMMdd") + "'");
+                TotalAmount += decimal.Parse(dic["TradeAmount"]);
+                TotalOrder += decimal.Parse(dic["TradeCount"]);
                 // TotalUser += query.TotalUser;
-                // TotalActual += query.TotalActual;
+                TotalActual += decimal.Parse(dic["TotalActual"]);
                 Start = Start.AddDays(1);
             }
-            Obj.Add("TotalAmount", TotalActual); //平台总收益
+            Obj.Add("TotalAmount", TotalAmount); //营总收益
             Obj.Add("TotalOrder", TotalOrder); //累计订单
             Obj.Add("TotalUser", TotalUser); //会员数
-            Obj.Add("TotalActual", TotalAmount); //营收总额
+            Obj.Add("TotalActual", TotalActual); //实收总额
             return Obj;
         }
         #endregion
@@ -694,8 +694,9 @@ namespace MySystem.Areas.Api.Controllers.v1
             int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
             MerchantInfo query = MerchantInfoDbconn.Instance.Get(Id) ?? new MerchantInfo();
             Obj.Add("Name", query.Name); //名称
-            Obj.Add("TotalActual", query.TotalActual); //实收总金额
-            Obj.Add("TotalOrder", query.TotalOrder); //累计订单
+            Obj.Add("TotalAmount", query.TotalAmount.ToString("f2")); //营收总金额
+            Obj.Add("TotalActual", query.TotalActual.ToString("f2")); //实收总金额
+            Obj.Add("TotalOrder", query.TotalConsumeCount); //累计订单
             Obj.Add("TotalCustomer", query.TotalCustomer); //累计客户
             Obj.Add("Logo", DefaultPic(query.Logo)); //Logo图片
             int ConsumeCount = 0;
@@ -709,8 +710,8 @@ namespace MySystem.Areas.Api.Controllers.v1
                 AlipayTotal += MerchantAmountSummary.Instance.GetActualTradeByMode(Id, 1, Date);
             }
             Obj.Add("SevenDayConsumer", ConsumeCount); //近7日新增会员
-            Obj.Add("WeChatTotal", WeChatTotal); //微信实收
-            Obj.Add("AlipayTotal", AlipayTotal); //支付宝实收
+            Obj.Add("WeChatTotal", WeChatTotal.ToString("f2")); //微信实收
+            Obj.Add("AlipayTotal", AlipayTotal.ToString("f2")); //支付宝实收
             Obj.Add("CreateDate", query.CreateDate == null ? "" : query.CreateDate.Value.ToString("yyyy-MM-dd"));
             return Obj;
         }

+ 21 - 0
Services/MerchantAmountSummayService.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using MySystem.MainModels;
 using Library;
 using LitJson;
+using System.Data;
 
 namespace MySystem
 {
@@ -42,6 +43,26 @@ namespace MySystem
             db.Dispose();
             return editData;
         }
+        public Dictionary<string, string> Sum(string field, string condition)
+        {
+            Dictionary<string, string> result = new Dictionary<string, string>();
+            string sumString = "";
+            string[] fieldlist = field.Split(',');
+            foreach(string f in fieldlist)
+            {
+                sumString += "sum(" + f + ") " + f + ",";
+            }
+            sumString = sumString.TrimEnd(',');
+            DataTable dt = CustomerSqlConn.dtable("select " + sumString + " from MerchantAmountSummay where 1=1" + condition, _conn);
+            if(dt.Rows.Count > 0)
+            {
+                foreach(string f in fieldlist)
+                {
+                    result.Add(f, function.CheckNum(dt.Rows[0][f].ToString()));
+                }
+            }
+            return result;
+        }
 
         /// <summary>
         /// 添加数据