步步为盈
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.9 KiB

3 years ago
using BBWY.Common.Http;
using BBWY.Common.Models;
using BBWY.Server.Model;
using BBWY.Server.Model.Db;
using BBWY.Server.Model.Dto;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using Yitter.IdGenerator;
namespace BBWY.Server.Business
{
public class StoreHouseWarningBusiness : BaseSyncBusiness, IDenpendency
{
private IList<Enums.StorageType> validStorageTypeList;
public StoreHouseWarningBusiness(RestApiService restApiService, IOptions<GlobalConfig> options, NLogManager nLogManager, IFreeSql fsql, IIdGenerator idGenerator, TaskSchedulerManager taskSchedulerManager, VenderBusiness venderBusiness, YunDingBusiness yunDingBusiness) : base(restApiService, options, nLogManager, fsql, idGenerator, taskSchedulerManager, venderBusiness, yunDingBusiness)
{
validStorageTypeList = new List<Enums.StorageType>() {
Enums.StorageType.,
Enums.StorageType.,
Enums.StorageType.
};
}
public void StartCheckStockNum()
{
var shopList = venderBusiness.GetShopList(filterTurnoverDays: true);
foreach (var shop in shopList)
{
CheckStockNum(shop);
}
}
private void CheckStockNum(ShopResponse shop)
{
long shopId = long.Parse(shop.ShopId);
var yesterDayDate = DateTime.Now.Date.AddDays(-1);
var ysterDayTime = DateTime.Now.Date.AddSeconds(-1);
var yesterDaySkuIds = fsql.Select<SkuDailySalesDetail, OrderSku, Order>()
.InnerJoin((s, osku, o) => s.Sku == osku.SkuId)
.InnerJoin((s, osku, o) => osku.OrderId == o.Id)
.Where((s, osku, o) => s.ShopId == shopId &&
s.Date == yesterDayDate &&
s.IsGift == false &&
s.ItemTotal > s.CancelItemTotal &&
o.StartTime >= yesterDayDate &&
o.StartTime <= ysterDayTime &&
validStorageTypeList.Contains(o.StorageType.Value))
.Distinct()
.ToList((s, osku, o) => s.Sku);
var queryStartDate = DateTime.Now.Date.AddDays(-9);
var skuSaleDailyList = fsql.Select<SkuDailySalesDetail>()
.Where(s => s.Date >= queryStartDate && s.Date <= yesterDayDate)
.Where(s => yesterDaySkuIds.Contains(s.Sku))
.ToList();
}
}
}