using CommonUtil;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Operater.DAL;
using Operater.DbModel;
using Operater.DTO;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
namespace Api.Operater.Controllers
{
[Route(TopConstants.API_ROUTE)]
public class DataStaticController : BaseController
{
///
/// 获取当天数据
///
///
[HttpPost]
public IActionResult GetTodayData()
{
GetTodayDataResponse response = new GetTodayDataResponse
{
YzPayAmount = 0,
YzTradeCount = 0,
YcTradeAmount = 0,
ProfitPay = 0
};
string tradeStr = $"select count(1) as count,sum(payment) as payment,sum(real_pay) as realpay from yz_tradeinfo where create_time>='{DateTime.Now.ToString("yyyy-MM-dd 00:00:00")}'";
DataTable tradeDt = new YzOrderinfoDAL().SearchBySqlDataTable("", tradeStr);
if (!tradeDt.IsNull() && tradeDt.Rows.Count > 0)
{
response.YzTradeCount = tradeDt.Rows[0]["count"].ToString().IsNullOrEmpty() ? 0 : int.Parse(tradeDt.Rows[0]["count"].ToString());
response.YcTradeAmount = tradeDt.Rows[0]["payment"].ToString().IsNullOrEmpty() ? 0 : decimal.Parse(tradeDt.Rows[0]["payment"].ToString());
response.YzPayAmount = tradeDt.Rows[0]["realpay"].ToString().IsNullOrEmpty() ? 0 : decimal.Parse(tradeDt.Rows[0]["realpay"].ToString());
}
//利润
string relaStr = $"SELECT ali_tid as tid FROM yz_orderinfo where create_time>='{DateTime.Now.ToString("yyyy-MM-dd 00:00:00")}' and ali_trade_status='1'";
string staticCount = $"select sum(sum_product_payment+shipping_fee) as payment from ali_tradeinfo where tid in({relaStr})";
DataTable aliFeeDt = new YzOrderinfoDAL().SearchBySqlDataTable("", staticCount);
if (!aliFeeDt.IsNull())
{
decimal aliFee = aliFeeDt.Rows[0]["payment"].ToString().IsNullOrEmpty() ? 0 : decimal.Parse(aliFeeDt.Rows[0]["payment"].ToString());
response.ProfitPay = response.YzPayAmount - aliFee;
}
return Success(response);
}
///
/// 获取时间范围内的统计数据
///
///
///
[HttpPost]
public IActionResult GetStaticData([FromBody] GetStaticDataRequest request)
{
var expression = Expressionable.Create().AndIF(!request.StartTime.IsNull(),t =>t.StaticTime>=request.StartTime)
.AndIF(!request.EndTime.IsNull(), t => t.StaticTime <= request.EndTime)
.ToExpression();
var taskList = new DataStaticDAL().ListGet(expression, t => t.StaticTime, DbEnum.OrderType.Desc);
return Success(taskList);
}
}
}