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
{
///
/// 全部数据
///
///
///
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(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()
};
}
///
/// 折线图
///
///
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(sql).ToList();
List