商铺统计增加外部接口 订单详情
This commit is contained in:
1 parent
3b85f00d88
commit
9c8103893a
3 files changed
+101
-52
No files matched your search
@@ -50,57 +50,7 @@ namespace KJD_Web.Controllers.WX
|
||||
{
|
||||
return GetShopStats(request, request.GroupType);
|
||||
}
|
||||
/// <summary>
|
||||
/// 外部调用
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public IHttpActionResult GetShopStatsExternal(ShopStatsRequest request)
|
||||
{
|
||||
Dictionary<string, List<ShopStatsResponse>> ret; try
|
||||
{
|
||||
if (request == null) throw new ArgumentNullException(nameof(request));
|
||||
if (request.StartDate == null) throw new ArgumentNullException(nameof(request.StartDate));
|
||||
if (request.EndDate == null) throw new ArgumentNullException(nameof(request.EndDate));
|
||||
if (request.ShopIds == null || request.ShopIds.Count == 0) throw new ArgumentNullException(nameof(request.ShopIds));
|
||||
Dictionary<string, string> dict = _freeSql.Select<WXShopEntity>()
|
||||
.Where(a => request.ShopIds.Contains(a.AppKey))
|
||||
.ToList(a => new { a.Id, a.AppKey })
|
||||
.ToDictionary(a => a.Id.ToString(), a => a.AppKey);
|
||||
var shopIds = dict.Keys.ToList();
|
||||
ret = _statsService.GetShopStats(request.StartDate, request.EndDate, "", shopIds, request.GroupType);
|
||||
var newRet = new Dictionary<string, List<ShopStatsResponse>>();
|
||||
|
||||
foreach (var item in ret)
|
||||
{
|
||||
|
||||
if (dict.TryGetValue(item.Key, out var appKey))
|
||||
{
|
||||
item.Value.ForEach(a => a.ShopId = appKey);
|
||||
newRet[appKey] = item.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
newRet[item.Key] = item.Value;
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(ApiResult.Success(newRet));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
return Ok(ApiResult.Fail(ex.Message, ResultCode.Fail));
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
return Ok(ApiResult.Fail(ex.Message, ResultCode.Fail));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Ok(ApiResult.Fail("查询失败:", ResultCode.ServerError));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 商铺销售趋势:按天返回所有商铺合计的销售额和订单数(无数据的天补 0)
|
||||
@@ -160,5 +110,104 @@ namespace KJD_Web.Controllers.WX
|
||||
return Ok(ApiResult.Fail("查询失败", ResultCode.ServerError));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region 外部接口
|
||||
|
||||
/// <summary>
|
||||
/// 外部调用
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public IHttpActionResult GetShopStatsExternal(ShopStatsRequest request)
|
||||
{
|
||||
Dictionary<string, List<ShopStatsResponse>> ret;
|
||||
try
|
||||
{
|
||||
if (request == null) throw new ArgumentNullException(nameof(request));
|
||||
if (request.StartDate == null) throw new ArgumentNullException(nameof(request.StartDate));
|
||||
if (request.EndDate == null) throw new ArgumentNullException(nameof(request.EndDate));
|
||||
if (request.ShopIds == null || request.ShopIds.Count == 0) throw new ArgumentNullException(nameof(request.ShopIds));
|
||||
Dictionary<string, string> dict = _freeSql.Select<WXShopEntity>()
|
||||
.Where(a => request.ShopIds.Contains(a.AppKey))
|
||||
.ToList(a => new { a.Id, a.AppKey })
|
||||
.ToDictionary(a => a.Id.ToString(), a => a.AppKey);
|
||||
var shopIds = dict.Keys.ToList();
|
||||
ret = _statsService.GetShopStats(request.StartDate, request.EndDate, "", shopIds, request.GroupType);
|
||||
var newRet = new Dictionary<string, List<ShopStatsResponse>>();
|
||||
|
||||
foreach (var item in ret)
|
||||
{
|
||||
|
||||
if (dict.TryGetValue(item.Key, out var appKey))
|
||||
{
|
||||
item.Value.ForEach(a => a.ShopId = appKey);
|
||||
newRet[appKey] = item.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
newRet[item.Key] = item.Value;
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(ApiResult.Success(newRet));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
return Ok(ApiResult.Fail(ex.Message, ResultCode.Fail));
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
return Ok(ApiResult.Fail(ex.Message, ResultCode.Fail));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Ok(ApiResult.Fail("查询失败:", ResultCode.ServerError));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 订单明细统一入口:有效订单 / 退款订单 / 买手未退回金额的订单,三种列表返回同一结构
|
||||
/// 请求参数 OrderType:All(默认全部) / Valid(有效订单) / Refund(退款订单) / BuyerUnrefunded(买手未退回金额)
|
||||
/// 时间范围为订单创建时间,商铺ID为空时按用户名的商铺查询
|
||||
/// </summary>
|
||||
public IHttpActionResult GetShopOrderDetailsExternal(ShopStatsRequest request)
|
||||
{
|
||||
List<ShopOrderDetailResponse> ret;
|
||||
try
|
||||
{
|
||||
if (request == null) throw new ArgumentNullException(nameof(request));
|
||||
if (request.StartDate == null) throw new ArgumentNullException(nameof(request.StartDate));
|
||||
if (request.EndDate == null) throw new ArgumentNullException(nameof(request.EndDate));
|
||||
if (request.ShopIds == null || request.ShopIds.Count == 0) throw new ArgumentNullException(nameof(request.ShopIds));
|
||||
Dictionary<string, string> dict = _freeSql.Select<WXShopEntity>()
|
||||
.Where(a => request.ShopIds.Contains(a.AppKey))
|
||||
.ToList(a => new { a.Id, a.AppKey })
|
||||
.ToDictionary(a => a.Id.ToString(), a => a.AppKey);
|
||||
var shopIds = dict.Keys.ToList();
|
||||
|
||||
|
||||
ret = _statsService.GetShopOrderDetails(request.StartDate, request.EndDate, request.OrderType, "", shopIds);
|
||||
//return Ok(ApiResult.Success(ret));
|
||||
|
||||
|
||||
|
||||
foreach (var item in ret)
|
||||
{
|
||||
item.ShopId= dict[item.ShopId];
|
||||
}
|
||||
|
||||
return Ok(ApiResult.Success(ret));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Ok(ApiResult.Fail("查询失败", ResultCode.ServerError));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public class ShopOrderDetailResponse
|
||||
/// <summary>
|
||||
/// 店铺ID
|
||||
/// </summary>
|
||||
public long ShopId { get; set; }
|
||||
public string ShopId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 店铺名称
|
||||
|
||||
@@ -231,7 +231,7 @@ public class ShopRevenueStatisticsService : ITransientDependency
|
||||
|
||||
result.Add(new ShopOrderDetailResponse
|
||||
{
|
||||
ShopId = order.ShopId,
|
||||
ShopId = order.ShopId.ToString(),
|
||||
ShopName = order.ShopName,
|
||||
OrderId = order.OrderId,
|
||||
CreateTime = order.CreateTime,
|
||||
|
||||
Reference in new issue
Block a user