Skip to content

Commit

Permalink
Merge pull request #853 from LittleFish-233/master
Browse files Browse the repository at this point in the history
Isthereanydeal迁移到新的api上,添加Vginsights数据源,销量和拥有人数取平均
  • Loading branch information
LittleFish-233 authored Jan 1, 2025
2 parents fad578e + 6f12968 commit 8030f00
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,15 @@ public async Task UpdateSteamInfo(StoreInfo storeInfo)
Name = storeInfo.Name,
Link = storeInfo.Link,
};
var officalApiTask = UpdateSteamInfoFromOfficialAPI(data);
var officalHtmlTask = UpdateSteamInfoFromOfficialHtml(data);
var isthereanydealTask = UpdateSteamInfoFromIsthereanydeal(data);
var xiaoHeiHeTask = UpdateSteamInfoFromXiaoHeiHe(data);
var gamalyticTask = UpdateSteamInfoFromGamalytic(data);

await Task.WhenAll(officalApiTask, officalHtmlTask, isthereanydealTask, xiaoHeiHeTask, gamalyticTask);

await UpdateSteamInfoFromOfficialAPI(data);
await UpdateSteamInfoFromOfficialHtml(data);
await UpdateSteamInfoFromIsthereanydeal(data);
await UpdateSteamInfoFromXiaoHeiHe(data);
await UpdateSteamInfoFromGamalytic(data);
await UpdateSteamInfoFromVginsights(data);


storeInfo.State = data.State;
storeInfo.PriceLowest = data.PriceLowest;
Expand Down Expand Up @@ -241,8 +243,6 @@ public async Task UpdateSteamInfoFromOfficialHtml(StoreInfo storeInfo)
{
storeInfo.RecommendationRate ??= recommendationRate;
}


}
catch (Exception ex)
{
Expand All @@ -259,29 +259,41 @@ public async Task UpdateSteamInfoFromIsthereanydeal(StoreInfo storeInfo)
{
try
{
var json = await (await _httpService.GetClientAsync()).GetStringAsync("https://api.isthereanydeal.com/v01/game/overview/?key=" + _configuration["IsthereanydealAPIToken"] + "&region=cn&country=CN&shop=steam&ids=app%2F" + storeInfo.Link + "&allowed=steam");
var re = JObject.Parse(json);
var data = re["data"][$"app/{storeInfo.Link}"].ToObject<IsthereanydealDataModel>();
if (data.Price != null)
var id = await _httpService.GetAsync<IsthereanydealGetIdModel>($"https://api.isthereanydeal.com/games/lookup/v1?key={_configuration["IsthereanydealAPIToken"]}&appid={storeInfo.Link}");

if (id.found == false)
{
return;
}

var data = await _httpService.PostAsync<List<string>, IsthereanydealDataModel>($"https://api.isthereanydeal.com/games/overview/v2?key={_configuration["IsthereanydealAPIToken"]}&shops=61&country=CN", [id.game.id]);

if (data.prices == null || data.prices.Count == 0)
{
return;
}
var price = data.prices[0];

if (price.current != null)
{
//原价
storeInfo.OriginalPrice ??= data.Price.Cut == 100 ? 0 : data.Price.Price / (100 - data.Price.Cut) * 100;
storeInfo.OriginalPrice ??= price.current.regular.amount;
//现价
storeInfo.PriceNow ??= data.Price.Price;
storeInfo.PriceNow ??= price.current.price.amount;
//折扣
storeInfo.CutNow ??= data.Price.Cut;
storeInfo.CutNow ??= price.current.cut;
}
if (data.Lowest != null)
if (price.lowest != null)
{
//历史最低
storeInfo.PriceLowest ??= data.Lowest.Price;
storeInfo.PriceLowest ??= price.lowest.price.amount;
//历史最高折扣
storeInfo.CutLowest ??= data.Lowest.Cut;
storeInfo.CutLowest ??= price.lowest.cut;
}
//状态
if (storeInfo.State == StoreState.None)
{
if (data.Price != null && data.Lowest != null)
if (price.current != null && price.lowest != null)
{
storeInfo.State = StoreState.OnSale;
}
Expand Down Expand Up @@ -335,7 +347,7 @@ public async Task UpdateSteamInfoFromXiaoHeiHe(StoreInfo storeInfo)
//折扣
storeInfo.CutNow ??= data.Result.Price.Discount;
//历史最低
storeInfo.PriceLowest ??=data.Result.Price.Lowest_price_raw;
storeInfo.PriceLowest ??= data.Result.Price.Lowest_price_raw;
//历史最高折扣
storeInfo.CutLowest ??= data.Result.Price.Lowest_discount;
//状态
Expand Down Expand Up @@ -372,12 +384,23 @@ public async Task UpdateSteamInfoFromGamalytic(StoreInfo storeInfo)
storeInfo.RecommendationRate ??= data.ReviewScore;
//平均游玩时长
storeInfo.PlayTime ??= (int)(data.AvgPlaytime * 60);
//估计拥有人数上限
storeInfo.EstimationOwnersMax ??= (int)(data.Owners);
//估计拥有人数下限
storeInfo.EstimationOwnersMin ??= (int)(data.Owners);
//销售额
storeInfo.Revenue ??= (int)(data.Revenue * 7);
//估计拥有人数上限 - 取平均
if (storeInfo.EstimationOwnersMax.HasValue)
storeInfo.EstimationOwnersMax = (storeInfo.EstimationOwnersMax.Value + (int)data.Owners) / 2;
else
storeInfo.EstimationOwnersMax = (int)data.Owners;

//估计拥有人数下限 - 取平均
if (storeInfo.EstimationOwnersMin.HasValue)
storeInfo.EstimationOwnersMin = (storeInfo.EstimationOwnersMin.Value + (int)data.Owners) / 2;
else
storeInfo.EstimationOwnersMin = (int)data.Owners;

//销售额 - 取平均
if (storeInfo.Revenue.HasValue)
storeInfo.Revenue = (storeInfo.Revenue.Value + (int)(data.Revenue * 7)) / 2;
else
storeInfo.Revenue = (int)(data.Revenue * 7);

//状态
if (storeInfo.State == StoreState.None && data.Unreleased)
Expand All @@ -391,6 +414,56 @@ public async Task UpdateSteamInfoFromGamalytic(StoreInfo storeInfo)
}
}


/// <summary>
/// 使用 Vginsights API获取信息
/// </summary>
/// <param name="storeInfo"></param>
/// <returns></returns>
public async Task UpdateSteamInfoFromVginsights(StoreInfo storeInfo)
{
try
{
var data = await _httpService.GetAsync<VginsightsDataModel>("https://vginsights.com/api/v1/game/" + storeInfo.Link);

//评测数
storeInfo.EvaluationCount ??= data.reviews;
//好评率
storeInfo.RecommendationRate ??= data.rating;
//估计拥有人数上限 - 取平均
if (storeInfo.EstimationOwnersMax.HasValue)
storeInfo.EstimationOwnersMax = (storeInfo.EstimationOwnersMax.Value + (int)data.units_sold_vgi) / 2;
else
storeInfo.EstimationOwnersMax = (int)data.units_sold_vgi;

//估计拥有人数下限 - 取平均
if (storeInfo.EstimationOwnersMin.HasValue)
storeInfo.EstimationOwnersMin = (storeInfo.EstimationOwnersMin.Value + (int)data.units_sold_vgi) / 2;
else
storeInfo.EstimationOwnersMin = (int)data.units_sold_vgi;

if (int.TryParse(data.revenue_vgi, out var result))
{
//销售额 - 取平均
if (storeInfo.Revenue.HasValue)
storeInfo.Revenue = (storeInfo.Revenue.Value + (int)(result * 7)) / 2;
else
storeInfo.Revenue = (int)(result * 7);
}


//状态
if (storeInfo.State == StoreState.None)
{
storeInfo.State = data.isReleased ? StoreState.OnSale : StoreState.NotPublished;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "获取 {name} - {id} Vginsights 数据失败", storeInfo.Name, storeInfo.Link);
}
}

#endregion

#region TapTap
Expand Down Expand Up @@ -499,7 +572,7 @@ public async Task UpdateTapTapInfoFromOfficialAPI(StoreInfo storeInfo)
}

// 评测
if(storeInfo.RecommendationRate==null&&string.IsNullOrWhiteSpace(data.Data.Stat?.Rating?.Score)==false)
if (storeInfo.RecommendationRate == null && string.IsNullOrWhiteSpace(data.Data.Stat?.Rating?.Score) == false)
{
if (double.TryParse(data.Data.Stat?.Rating?.Score, out double score))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public async Task<ActionResult<Result>> TempFunction()
{
try
{
await _fileService.TransferMainImagesToPublic(10);
await _storeInfoService.BatchUpdate(10);

return new Result { Successful = true };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,47 @@

namespace CnGalWebSite.DataModel.ViewModel.Stores
{
public class IsthereanydealGetIdModel
{
public bool found { get; set; }
public IsthereanydealGameInfo game { get; set; }
}

public class IsthereanydealGameInfo
{
public string id { get; set; }
}


public class IsthereanydealDataModel
{
public IsthereanydealDataModelPrice Price { get; set; }
public IsthereanydealDataModelPriceLowest Lowest { get; set; }
public List<IsthereanydealPriceInfo> prices { get; set; }
}

public class IsthereanydealPriceInfo
{
public IsthereanydealCurrentPrice current { get; set; }
public IsthereanydealLowestPrice lowest { get; set; }
}

public class IsthereanydealCurrentPrice
{
public IsthereanydealPrice price { get; set; }
public IsthereanydealPrice regular { get; set; }
public int cut { get; set; }
}

public class IsthereanydealDataModelPrice
public class IsthereanydealLowestPrice
{
public double Price { get; set; }
public int Cut { get; set; }
public string Price_formatted { get; set; }
public IsthereanydealPrice price { get; set; }
public IsthereanydealPrice regular { get; set; }
public int cut { get; set; }
}

public class IsthereanydealDataModelPriceLowest
public class IsthereanydealPrice
{
public double Price { get; set; }
public int Cut { get; set; }
public string Price_formatted { get; set; }
public long Recorded { get; set; }
public double amount { get; set; }
public int amountInt { get; set; }
public string currency { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CnGalWebSite.DataModel.ViewModel.Stores
{
public class VginsightsDataModel
{
public double price { get; set; }
public double price_final { get; set; }
public double rating { get; set; }
public int reviews { get; set; }
public int reviews_positive { get; set; }
public int reviews_negative { get; set; }
public int units_sold_vgi { get; set; }
public string revenue_vgi { get; set; }
public bool isReleased { get; set; }
}
}

0 comments on commit 8030f00

Please sign in to comment.