diff --git a/BBWY.Server.Business/EarlyWarning/StoreHouseWarningBusiness.cs b/BBWY.Server.Business/EarlyWarning/StoreHouseWarningBusiness.cs new file mode 100644 index 00000000..6ebd8a29 --- /dev/null +++ b/BBWY.Server.Business/EarlyWarning/StoreHouseWarningBusiness.cs @@ -0,0 +1,62 @@ +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 validStorageTypeList; + + public StoreHouseWarningBusiness(RestApiService restApiService, IOptions 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.本地自发 + }; + } + + 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() + .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() + .Where(s => s.Date >= queryStartDate && s.Date <= yesterDayDate) + .Where(s => yesterDaySkuIds.Contains(s.Sku)) + .ToList(); + + + } + } +} diff --git a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs index e8e07ef7..57699da6 100644 --- a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs +++ b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs @@ -622,5 +622,22 @@ namespace BBWY.Server.Business return (JArray)res.Json["jingdong_store_findPartitionWhByIdAndStatus_responce"]["find_Partition_Warehouse_Result"]["result"]; } + + public override JArray GetStockNumBySku(SearchProductSkuRequest request) + { + var jdClient = GetJdClient(request.AppKey, request.AppSecret); + var req = new StockReadFindSkuStockRequest(); + + + req.skuId = long.Parse(request.Sku); // 10036238533172; //京仓sku + var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime()); + + if (res.IsError) + throw new BusinessException($"获取sku库存出错 {(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); + if (res.Json == null) + res.Json = JsonConvert.DeserializeObject(res.Body); + + return (JArray)res.Json["jingdong_stock_read_findSkuStock_responce"]["skuStocks"]; + } } } diff --git a/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs b/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs index b658f4fd..5d4c94e1 100644 --- a/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs +++ b/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs @@ -109,7 +109,7 @@ namespace BBWY.Server.Business } public virtual JArray GetJDShopSopularizeRecordList(SyncShopPopularizeRequest syncShopPopularizeRequest) - { + { throw new NotImplementedException(); } @@ -142,5 +142,10 @@ namespace BBWY.Server.Business { throw new NotImplementedException(); } + + public virtual JArray GetStockNumBySku(SearchProductSkuRequest request) + { + throw new NotImplementedException(); + } } } diff --git a/BBWY.Server.Business/Vender/VenderBusiness.cs b/BBWY.Server.Business/Vender/VenderBusiness.cs index 1e888f4b..c4e81847 100644 --- a/BBWY.Server.Business/Vender/VenderBusiness.cs +++ b/BBWY.Server.Business/Vender/VenderBusiness.cs @@ -22,7 +22,7 @@ namespace BBWY.Server.Business public VenderBusiness(FreeSqlMultiDBManager freeSqlMultiDBManager, RestApiService restApiService, IOptions options, - IIdGenerator idGenerator,YunDingBusiness yunDingBusiness) : base(restApiService, options, yunDingBusiness) + IIdGenerator idGenerator, YunDingBusiness yunDingBusiness) : base(restApiService, options, yunDingBusiness) { this.freeSqlMultiDBManager = freeSqlMultiDBManager; this.idGenerator = idGenerator; @@ -222,11 +222,13 @@ namespace BBWY.Server.Business return departmentList; } - public IList GetShopList(long? shopId = null, Enums.Platform? platform = null) + public IList GetShopList(long? shopId = null, Enums.Platform? platform = null, bool filterTurnoverDays = false) { return freeSqlMultiDBManager.MDSfsql.Select().Where(s => !string.IsNullOrEmpty(s.ShopId)) .WhereIf(shopId != null, s => s.ShopId == shopId.ToString()) - .WhereIf(platform != null, s => s.PlatformId == (int)platform).ToList(); + .WhereIf(platform != null, s => s.PlatformId == (int)platform) + .WhereIf(filterTurnoverDays, s => s.SkuSafeTurnoverDays != 0) + .ToList(); } public ShopResponse GetShopByShopId(string shopId) diff --git a/BBWY.Server.Model/Db/Mds/Shops.cs b/BBWY.Server.Model/Db/Mds/Shops.cs index baf54d65..3f1b1b15 100644 --- a/BBWY.Server.Model/Db/Mds/Shops.cs +++ b/BBWY.Server.Model/Db/Mds/Shops.cs @@ -106,6 +106,22 @@ namespace BBWY.Server.Model.Db.Mds [Column(DbType = "decimal(11,2)")] public decimal? PlatformCommissionRatio { get; set; } + /// + /// SKU库存安全周转天数 + /// + public int SkuSafeTurnoverDays { get; set; } + + /// + /// 钉钉WebHook地址 + /// + [Column(StringLength = 255)] + public string DingDingWebHook { get; set; } + + /// + /// 钉钉密钥 + /// + [Column(StringLength = 100)] + public string DingDingKey { get; set; } } } diff --git a/BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs b/BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs index f1dbc7ae..bcb3e16e 100644 --- a/BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs +++ b/BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs @@ -35,6 +35,21 @@ namespace BBWY.Server.Model.Dto public decimal? PlatformCommissionRatio { get; set; } public IList PurchaseList { get; set; } + + /// + /// SKU库存安全周转天数 + /// + public int SkuSafeTurnoverDays { get; set; } + + /// + /// 钉钉WebHook地址 + /// + public string DingDingWebHook { get; set; } + + /// + /// 钉钉密钥 + /// + public string DingDingKey { get; set; } } public class PurchaseAccountResponse diff --git a/JD.API/Controllers/PlatformSDKController.cs b/JD.API/Controllers/PlatformSDKController.cs index 36360fd6..f0e97e35 100644 --- a/JD.API/Controllers/PlatformSDKController.cs +++ b/JD.API/Controllers/PlatformSDKController.cs @@ -265,5 +265,16 @@ namespace JD.API.API.Controllers { return platformSDKBusinessList.FirstOrDefault(p => p.Platform == request.Platform).GetStoreHouseList(request); } + + /// + /// 查询单个sku库存 + /// + /// + /// + [HttpPost] + public JArray GetStockNumBySku([FromBody] SearchProductSkuRequest request) + { + return platformSDKBusinessList.FirstOrDefault(p => p.Platform == request.Platform).GetStockNumBySku(request); + } } }