增加 新版本登录请求

This commit is contained in:
chfei committed 2026-11-04 18:39:51 +08:00
1 parent afeb7e5d90
commit b28940c02d
10 files changed
+865 -592

No files matched your search

+11 -97
View File
@@ -6,7 +6,7 @@ using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Work.Store.Api;
using System.Threading.Tasks;
using Work.Api.Wx;
@@ -17,35 +17,13 @@ namespace Work.Services
/// </summary>
public class CloudGoodsService
{
private static string ServerUrl = "http://103.90.155.78:9001";
static CloudGoodsService()
{
if (EnvironmentHelper.IsDevelopment)
{
ServerUrl = "http://localhost:14312";
}
}
public static async Task<PageData<CloudGoods>> GetGoods(GoodsSearchRequest request)
{
var html = await GetHtml.PostJsonAsync(ServerUrl + "/api/CloudGoods/SearchGoods", request);
var ret = JsonConvert.DeserializeObject<Result<PageData<CloudGoods>>>(html);
if (ret.Code != 200)
{
throw new Exception(ret.Msg);
}
return ret.Data;
return await StoreApiClient.Instance.CloudGoods.GetGoods(request);
}
public static string GetGoodsDetail(long goodsId)
{
var html = GetHtml.PostJson(ServerUrl + $"/api/CloudGoods/GetGoodsRawData?goodsId={goodsId}", "");
var ret = JsonConvert.DeserializeObject<Result<string>>(html);
if (ret.Code != 200)
{
throw new Exception(ret.Msg);
}
return ret.Data;
return StoreApiClient.Instance.CloudGoods.GetGoodsDetail(goodsId);
}
/// <summary>
@@ -338,17 +316,7 @@ namespace Work.Services
throw new ArgumentException("违规商品列表不能包含空项。", nameof(items));
}
var html = await GetHtml.PostJsonAsync(ServerUrl + "/api/CloudGoods/ReportViolations", items, timeOut: 5);
var ret = JsonConvert.DeserializeObject<Result<List<ReportGoodsViolationResult>>>(html);
if (ret == null)
{
throw new Exception("批量上报违规商品返回为空。");
}
if (ret.Code != 200)
{
throw new Exception(ret.Msg);
}
return ret.Data ?? throw new Exception("批量上报违规商品返回数据为空。");
return await StoreApiClient.Instance.CloudGoods.ReportViolations(items);
}
/// <summary>
@@ -361,17 +329,7 @@ namespace Work.Services
throw new ArgumentNullException(nameof(goodsIds));
}
var html = GetHtml.PostJson(ServerUrl + "/api/CloudGoods/GetViolationStatus", goodsIds, timeOut: 5);
var ret = JsonConvert.DeserializeObject<Result<List<GoodsViolationStatus>>>(html);
if (ret == null)
{
throw new Exception("批量查询商品违规状态返回为空。");
}
if (ret.Code != 200)
{
throw new Exception(ret.Msg);
}
return ret.Data ?? throw new Exception("批量查询商品违规状态返回数据为空。");
return StoreApiClient.Instance.CloudGoods.GetViolationStatus(goodsIds);
}
/// <summary>逐原因记录店铺动作。日志请求失败不能改变剔除决定或中断后续下架。</summary>
@@ -424,23 +382,13 @@ namespace Work.Services
{
if (requests == null || requests.Count == 0 || requests.Any(item => item == null))
throw new ArgumentException("请提供有效的违规日志。", nameof(requests));
var html = await GetHtml.PostJsonAsync(ServerUrl + "/api/CloudGoods/RecordViolationLog", requests, timeOut: 5);
var ret = JsonConvert.DeserializeObject<Result>(html) ?? throw new Exception("记录违规日志返回为空。");
if (ret.Code != 200)
throw new Exception(ret.Msg);
await StoreApiClient.Instance.CloudGoods.RecordViolationLogs(requests);
}
/// <summary>读取日志筛选和显示使用的违规原因字典。</summary>
public static async Task<List<ViolationReason>> GetViolationReasons()
{
using (var web = new System.Net.WebClient { Encoding = Encoding.UTF8 })
{
var html = await web.DownloadStringTaskAsync(ServerUrl + "/api/CloudGoods/GetViolationReasons");
var ret = JsonConvert.DeserializeObject<Result<List<ViolationReason>>>(html);
if (ret?.Code != 200 || ret.Data == null)
throw new Exception(ret?.Msg ?? "查询违规类型返回为空。");
return ret.Data;
}
return await StoreApiClient.Instance.CloudGoods.GetViolationReasons();
}
public class ViolationReason
@@ -457,12 +405,7 @@ namespace Work.Services
if (shopIds == null || shopIds.Length == 0 || shopIds.Any(string.IsNullOrWhiteSpace))
throw new ArgumentException("请提供有效的店铺编号。", nameof(shopIds));
var request = new GetViolationLogsRequest { ShopIds = shopIds, GoodsId = goodsId, BeforeId = beforeId, Size = size };
var html = await GetHtml.PostJsonAsync(ServerUrl + "/api/CloudGoods/GetViolationLogs", request, timeOut: 5);
var ret = JsonConvert.DeserializeObject<Result<List<GoodsViolationLogEntity>>>(html)
?? throw new Exception("查询违规日志返回为空。");
if (ret.Code != 200)
throw new Exception(ret.Msg);
return ret.Data ?? throw new Exception("查询违规日志返回数据为空。");
return await StoreApiClient.Instance.CloudGoods.GetViolationLogs(request);
}
#region user
@@ -475,14 +418,7 @@ namespace Work.Services
public static async Task<PageData<CloudGoods>> SearchFavorites(UserFavoritesGoodsSearchRequest request)
{
request.UserName = GetUserName();
var html = await GetHtml.PostJsonAsync(ServerUrl + "/api/CloudGoods/SearchFavorites", request);
var ret = JsonConvert.DeserializeObject<Result<PageData<CloudGoods>>>(html);
if (ret.Code != 200)
{
throw new Exception(ret.Msg);
}
return ret.Data;
return await StoreApiClient.Instance.CloudGoods.SearchFavorites(request);
}
/// <summary>
@@ -494,18 +430,7 @@ namespace Work.Services
public static async Task<int> Favorite(List<long> goodsIds)
{
var html = await GetHtml.PostJsonAsync(ServerUrl + $"/api/CloudGoods/AddFavorite", new
{
UserName = GetUserName(),
GoodsIds = goodsIds,
});
var ret = JsonConvert.DeserializeObject<Result<int>>(html);
if (ret.Code != 200)
{
throw new Exception(ret.Msg);
}
return ret.Data;
return await StoreApiClient.Instance.CloudGoods.Favorite(GetUserName(), goodsIds);
}
/// <summary>
/// 取消收藏
@@ -516,18 +441,7 @@ namespace Work.Services
public static async Task<int> RemoveFavorites(List<long> goodsIds)
{
var html = await GetHtml.PostJsonAsync(ServerUrl + $"/api/CloudGoods/RemoveFavorites", new
{
UserName = GetUserName(),
GoodsIds = goodsIds,
});
var ret = JsonConvert.DeserializeObject<Result<int>>(html);
if (ret.Code != 200)
{
throw new Exception(ret.Msg);
}
return ret.Data;
return await StoreApiClient.Instance.CloudGoods.RemoveFavorites(GetUserName(), goodsIds);
}
#endregion
+9 -61
View File
@@ -1,14 +1,11 @@
using AllBase;
using AllBase.Helper;
using AllBase.Model.Result;
using AllBase.Model.Result.PDDResult;
using AllBase.Model.Result;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Work.Store.Api;
namespace Work.Services;
@@ -17,17 +14,6 @@ namespace Work.Services;
/// </summary>
public class ImageCacheService
{
private static string ServerUrl = "http://103.90.155.78:9001";
static ImageCacheService()
{
if (EnvironmentHelper.IsDevelopment)
{
ServerUrl = "http://localhost:14312";
}
}
/// <summary>
/// 获取图片缓存
/// </summary>
@@ -37,10 +23,6 @@ public class ImageCacheService
Dictionary<string, ImageCache> wxImgMapDic = new Dictionary<string, ImageCache>(StringComparer.OrdinalIgnoreCase);
try
{
//if (EnvironmentHelper.IsProduction)
//{
// return wxImgMapDic;
//}
List<string> imageUrls = new List<string>();
imageUrls.AddRange(product.detail.galleries.Where(g => g.type == 1).Take(9).Select(a => a.url));
var temp_detailGalleries = product.detail.galleries.Where(g => g.type == 2).ToList();
@@ -58,16 +40,11 @@ public class ImageCacheService
List<string> imageUrlMd5s = imageUrls.Select(a => BaseClass.GetMd5(a)).ToList();
var url = ServerUrl + "/api/ImageCache/GetImageCache";//获取缓存
var html = GetHtml.PostJson(url, new { md5s = imageUrlMd5s });
var ret = JsonConvert.DeserializeObject<Result<List<ImageCache>>>(html);
if (ret.Code == 200)
var caches = StoreApiClient.Instance.ImageCache.GetImageCaches(imageUrlMd5s);
foreach (var item in caches)
{
foreach (var item in ret.Data)
{
item.IsCache = true;
wxImgMapDic[item.Md5] = item;
}
item.IsCache = true;
wxImgMapDic[item.Md5] = item;
}
}
catch(Exception ex)
@@ -86,38 +63,9 @@ public class ImageCacheService
{
try
{
//if (EnvironmentHelper.IsProduction)
//{
// return;
//}
var data = "";
data = JsonHelper.SerializeObject(images.Where(a => a.IsCache == false).Select(a =>
new
{
md5 = a.Md5,
Platform = platform,
PlatformUrl = a.PlatformUrl
}
));
var url = ServerUrl + "/api/ImageCache/AddOrUpdate";
var html = GetHtml.PostJson(url, data);
var ret = JsonConvert.DeserializeObject<Result<JToken>>(html);
List<string> failed = new List<string>();
if (ret.Code == 500)
{
if (ret.Data is JArray jArray)
{
failed = jArray.ToObject<List<string>>() ?? new List<string>();
}
else if (ret.Data is JValue jValue && jValue.Value is string str)
{
failed.Add(str);
}
}
foreach (ImageCache item in images)
var pending = images.Where(image => !image.IsCache).ToList();
var failed = StoreApiClient.Instance.ImageCache.SaveImageCaches((int)platform, pending);
foreach (var item in pending)
{
item.IsCache = !failed.Contains(item.Md5, StringComparer.OrdinalIgnoreCase);
}