|
- using DataVApi.Order.Dto;
- using DataVApi.Order.RequestModel;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- using XExten.Advance.HttpFramework.MultiFactory;
-
- namespace DataVApi.Order
- {
- public class OrderProvider : SugarDb
- {
- /// <summary>
- /// 全部数据
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public object GetAllOrderDataState(FullScreenInput input)
- {
- var db = DbContext();
-
- StringBuilder sb = new StringBuilder();
- sb.Append(@"SELECT
- a.Id,
- b.CreatedAt as Time,
- b.OrderRealMoney as Money
- FROM
- BPA_Organize AS a
- JOIN BPA_Order AS b ON a.Id= b.OrgId
- WHERE
- ( b.PayMode= 1 OR b.PayMode= 4 )
- AND ( b.TransactionId IS NOT NULL OR b.TransactionId != '' )
- AND ( b.TradeNo IS NOT NULL OR b.TradeNo != '' )");
- if (input.OrgId.HasValue)
- {
- sb.Append(@$" AND a.AutoKey = {input.OrgId.Value} ");
- if (input.DeviceId.HasValue)
- sb.Append($@" AND b.Id IN(SELECT c.OrderId FROM BPA_SubOrder as c JOIN BPA_DeviceInfo as d ON c.StoreId = d.Id WHERE d.AutoKey={input.DeviceId.Value} AND d.OrgId=a.Id)");
- }
- if (input.Star.HasValue)
- sb.Append(@$" AND b.CreatedAt>='{input.Star.Value}'");
- if (input.End.HasValue)
- sb.Append(@$" AND b.CreatedAt<'{input.End.Value}'");
-
- var sql = sb.ToString();
-
- var data = db.SqlQueryable<OrderDataStateDto>(sql).ToList();
-
- return new
- {
- Total = data.Sum(t => t.Money).ToString(),
- OrderCount = data.Count().ToString(),
- MoneyM = data.Where(t => t.Time.Month == DateTime.Now.Month).Sum(t => t.Money).ToString(),
- MoneyD = data.Where(t => t.Time >= DateTime.Parse(DateTime.Now.ToShortDateString()) && t.Time < DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(1)).Sum(t => t.Money).ToString(),
- StoreCount = data.GroupBy(t => t.Id).Count()
- };
- }
- /// <summary>
- /// 折线图
- /// </summary>
- /// <returns></returns>
- public object OrderLine(FullScreenBasic input)
- {
- var db = DbContext();
-
- StringBuilder sb = new StringBuilder();
- sb.Append(@"SELECT
- b.OrderStatus,
- b.CreatedAt,
- b.AfterStatus,
- b.PayMode
- FROM
- BPA_Organize AS a
- JOIN BPA_Order AS b ON a.Id= b.OrgId
- WHERE
- ( b.TransactionId IS NOT NULL OR b.TransactionId != '' )
- AND ( b.TradeNo IS NOT NULL OR b.TradeNo != '' )");
-
- if (input.OrgId.HasValue)
- {
- sb.Append(@$" AND a.AutoKey = {input.OrgId.Value} ");
- if (input.DeviceId.HasValue)
- sb.Append($@" AND b.Id IN(SELECT c.OrderId FROM BPA_SubOrder as c JOIN BPA_DeviceInfo as d ON c.StoreId = d.Id WHERE d.AutoKey={input.DeviceId.Value} AND d.OrgId=a.Id)");
- }
-
- var sql = sb.ToString();
- var data = db.SqlQueryable<OrderLineDto>(sql).ToList();
-
- List<object> res = new List<object>();
- int indexcount = input.Count.HasValue ? input.Count.Value : 10;
- for (int index = indexcount; index >= 0; index--)
- {
- var temp = DateTime.Now.AddDays(-index);
- var end = DateTime.Parse(temp.ToString("yyyy-MM-dd 23:59:59"));
- var start = DateTime.Parse(temp.ToString("yyyy-MM-dd 00:00:00"));
- var NO = data.Where(t => t.CreatedAt < end && t.CreatedAt >= start).Where(t => t.AfterStatus != 0 && (t.OrderStatus == 1 || t.PayMode == 4)).Count();
- var OK = data.Where(t => t.CreatedAt < end && t.CreatedAt >= start).Where(t => t.AfterStatus == 0 && (t.OrderStatus == 1 || t.PayMode == 4)).Count();
- var Date = temp.ToString("MM/dd");
- res.Add(new
- {
- NO,
- OK,
- Date
- });
- }
-
- return new { data= res };
- }
- /// <summary>
- /// 区域销售
- /// </summary>
- /// <returns></returns>
- public object GetLocSale()
- {
- var db = DbContext();
-
- var baiduMap = "http://api.map.baidu.com/geocoder/v2/?ak=3ce7ddfda60046708248ea55e10b1435&callback=renderReverse&location={0}&output=xml";
- List<LocSaleDto> loc = new List<LocSaleDto>();
- var data = db.SqlQueryable<dynamic>(@"SELECT
- a.Store_Loc AS Loc,
- (SELECT Count(b.Id) FROM BPA_Order as b WHERE b.OrgId=a.Id) as Count
- FROM
- BPA_Organize AS a
- WHERE
- a.IsDeleted = 0
- AND a.Store_Loc LIKE '%,%';
-
- ").ToList();
- IHttpMultiClient http = null;
-
- data.ForEach(item =>
- {
- if (http == null)
- http = IHttpMultiClient.HttpMulti.AddNode(opt =>
- {
- opt.NodePath = string.Format(baiduMap, item.Loc);
- });
- else
- http = http.AddNode(opt =>
- {
- opt.NodePath = string.Format(baiduMap, item.Loc);
- });
- });
- XmlDocument doc = new XmlDocument();
-
- var Temps = http.Build().RunString();
-
- for (int i = 0; i < Temps.Count; i++)
- {
- doc.LoadXml(Temps[i]);
- loc.Add(new LocSaleDto
- {
- Count = data[i].Count,
- City = doc.SelectSingleNode("//province")?.InnerText + doc.SelectSingleNode("//city")?.InnerText
- });
- }
-
- return new
- {
- data = loc.GroupBy(t => t.City).Select(t => new LocSaleDto
- {
- City = string.IsNullOrEmpty(t.Key)?"未知": t.Key,
- Count = t.Sum(t => t.Count)
- })
- };
- }
- /// <summary>
- /// 下单数量
- /// </summary>
- /// <returns></returns>
- public object OrderNumber(FullScreenBasic input)
- {
- var db = DbContext();
-
- StringBuilder sb = new StringBuilder();
- sb.Append(@"SELECT
- b.CreatedAt
- FROM
- BPA_Organize AS a
- JOIN BPA_Order AS b ON a.Id= b.OrgId
- WHERE
- ( b.PayMode= 1 OR b.PayMode= 4 )
- AND ( b.TransactionId IS NOT NULL OR b.TransactionId != '' )
- AND ( b.TradeNo IS NOT NULL OR b.TradeNo != '' )");
-
- if (input.OrgId.HasValue)
- {
- sb.Append(@$" AND a.AutoKey = {input.OrgId.Value} ");
- if (input.DeviceId.HasValue)
- sb.Append($@" AND b.Id IN(SELECT c.OrderId FROM BPA_SubOrder as c JOIN BPA_DeviceInfo as d ON c.StoreId = d.Id WHERE d.AutoKey={input.DeviceId.Value} AND d.OrgId=a.Id)");
- }
-
- var sql = sb.ToString();
- var data = db.SqlQueryable<OrderNumberDto>(sql).ToList();
- int Year = data.Where(t => t.CreatedAt.Year == DateTime.Now.Year).Count();
- int Month = data.Where(t => t.CreatedAt.Month == DateTime.Now.Month).Count();
- int Day = data.Where(t => t.CreatedAt.Day == DateTime.Now.Day).Count();
- int L_Year = data.Where(t => t.CreatedAt.Year == DateTime.Now.AddYears(-1).Year).Count();
- int L_Month = data.Where(t => t.CreatedAt.Month == DateTime.Now.AddMonths(-1).Month).Count();
- int L_Day = data.Where(t => t.CreatedAt.Day == DateTime.Now.AddDays(-1).Day).Count();
-
- return new
- {
- Year = Year, Month = Month, Day = Day,
- L_Year = L_Year, L_Month = L_Month, L_Day = L_Day,
- B_Year = ((Year + L_Year) == 0) ? 0 : (((Year - L_Year) * 100) / (Year + L_Year)),
- B_Month = ((Month + L_Month) == 0) ? 0 : (((Month - L_Month) * 100) / (Month + L_Month)),
- B_Day = ((Day + L_Day) == 0) ? 0 : (((Day - L_Day) * 100) / (Day + L_Day))
- };
- }
- }
- }
|