using AllBase;
using AllBase.Model.Result;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Work.Services
{
///
/// 云商品数据服务
///
public class CloudGoodsService
{
private const string ServerUrl = "http://119.45.4.202:14312";
public static async Task> GetGoods(GoodsSearchRequest request)
{
string data = JsonHelper.SerializeObject(request);
var html = await GetHtml.PostUtf8Async(ServerUrl + "/Goods/SearchGoods", data, "application/json");
var ret = JsonConvert.DeserializeObject>>(html);
if (ret.Code != 200)
{
throw new Exception(ret.Msg);
}
return ret.Data;
}
public static string GetGoodsDetail(long goodsId)
{
var html = GetHtml.GetUtf8(ServerUrl + $"/Goods/GetGoodsRawData?goodsId={goodsId}", "application/json");
var ret = JsonConvert.DeserializeObject>(html);
if (ret.Code != 200)
{
throw new Exception(ret.Msg);
}
return ret.Data;
}
}
///
/// 商品搜索请求
///
public class GoodsSearchRequest
{
///
/// 标题(模糊搜索)
///
public string Title { get; set; } = string.Empty;
///
/// 最低价格(元)
///
public long? MinPrice { get; set; }
///
/// 最高价格(元)
///
public long? MaxPrice { get; set; }
///
/// 一级类目ID
///
public int? CatId1 { get; set; }
///
/// 二级类目ID
///
public int? CatId2 { get; set; }
///
/// 三级类目ID
///
public int? CatId3 { get; set; }
///
/// 四级类目ID
///
public int? CatId4 { get; set; }
///
/// 最低销量
///
public int? MinSoldQuantity { get; set; }
///
/// 最高销量
///
public int? MaxSoldQuantity { get; set; }
///
/// 平台类型
///
public PlatformType Platform { get; set; }
///
/// 页码(默认1)
///
public int PageIndex { get; set; } = 1;
///
/// 每页数量(默认20)
///
public int PageSize { get; set; } = 20;
}
///
/// 商品搜索返回结果
///
public class GoodsSearchResponse
{
///
/// 商品列表
///
[JsonProperty("list")]
public List List { get; set; } = new List();
///
/// 总记录数
///
[JsonProperty("total")]
public int Total { get; set; }
///
/// 当前页码
///
[JsonProperty("pageIndex")]
public int PageIndex { get; set; }
///
/// 每页数量
///
[JsonProperty("pageSize")]
public int PageSize { get; set; }
///
/// 总页数
///
[JsonProperty("totalPages")]
public int TotalPages { get; set; }
}
public class CloudGoods : BindableBase
{
public bool IsSelected
{
get => GetValue();
set => SetValue(value);
}
///
/// 自增ID
///
public long Id { get; set; }
///
/// 平台类型
///
public byte Platform { get; set; }
///
/// 商品编号
///
public long GoodsId { get; set; }
///
/// 标题
///
public string Title { get; set; } = string.Empty;
///
/// 描述
///
public string? Description { get; set; }
///
/// 缩略图
///
public string? ThumbUrl { get; set; }
///
/// 一级类目ID
///
public int? CatId1 { get; set; }
///
/// 二级类目ID
///
public int? CatId2 { get; set; }
///
/// 三级类目ID
///
public int? CatId3 { get; set; }
///
/// 四级类目ID
///
public int? CatId4 { get; set; }
///
/// 最低价快照(元),导入时计算
///
public decimal MinPrice { get; set; }
///
/// 最高价快照(元),导入时计算
///
public decimal MaxPrice { get; set; }
public string Price => $"{MinPrice / 100m:N2}";
///
/// 销量
///
public int SoldQuantity { get; set; }
///
/// 状态:0正常 1已删除
///
public byte Status { get; set; }
///
/// 创建时间
///
public DateTime CreatedTime { get; set; }
///
/// 更新时间(自动更新)
///
public DateTime UpdatedTime { get; set; }
///
/// 索引同步状态:0未同步 1已同步
///
public byte IndexStatus { get; set; }
}
}