279 lines
10 KiB
C#
279 lines
10 KiB
C#
using YLErp.Modules.ClientModule;
|
|
using YLErp.Modules.SubAppModule.ClientApp;
|
|
using YLErp.Modules.TradeDalModule;
|
|
|
|
namespace YLWebAPI.ApiModule.ClientApi
|
|
{
|
|
/// <summary>
|
|
/// 专用于客户端的API列表(路径样式:api/v1/client/*)
|
|
/// </summary>
|
|
[ClientAuth]
|
|
public class ClientApiController : BaseApiController
|
|
{
|
|
[HttpPost, Route("api/v1/client/test")]
|
|
public ApiResponseModel Test([FromBody] ClientChangePasswordRequest reqModel)
|
|
{
|
|
throw new System.Exception("测试报错");
|
|
}
|
|
|
|
[HttpPost, Route("api/v1/client/changeClientPassword")]
|
|
public ApiResponseModel ChangeClientPassword([FromBody] ClientChangePasswordRequest reqModel)
|
|
{
|
|
new ClientUserPasswordService(CurUser).ChangePassword(reqModel);
|
|
return JsonSuccess("成功", "成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 结算报告:获取客户财务状况
|
|
/// </summary>
|
|
[HttpPost, Route("api/v1/client/clientLatestBalance")]
|
|
public IActionResult ClientLatestBalance([FromBody] ClientLatestBalanceRequestModel reqModel)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(reqModel.ClientName))
|
|
{
|
|
var ids = new ClientDataService(CurUser).GetClientIdByName(reqModel.ClientName);
|
|
if (ids.Length == 0)
|
|
{
|
|
return Ok(JsonError($"根据客户名称'{reqModel.ClientName}'没有找到客户信息"));
|
|
}
|
|
if (ids.Length > 1)
|
|
{
|
|
return Ok(JsonError($"根据客户名称'{reqModel.ClientName}'找到多个客户信息,不支持此种请求"));
|
|
}
|
|
reqModel.ClientId = ids[0];
|
|
}
|
|
|
|
ClientSettleBalance data = null;
|
|
if (reqModel.ClientId > 0)
|
|
{
|
|
data = ClientAssetDataService.GetClientLatestBalance(
|
|
reqModel.ValueDateFrom,
|
|
reqModel.ValueDateTo,
|
|
reqModel.ClientId);
|
|
}
|
|
return Ok(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 结算报告:获取客户持仓信息
|
|
/// </summary>
|
|
[HttpPost, Route("api/v1/client/clientTradePosition")]
|
|
public IActionResult ClientTradePosition([FromBody] ClientTradePositionRequestModel reqModel)
|
|
{
|
|
SearchListResult<eod_position> data = null;
|
|
|
|
if (reqModel.ClientId > 0)
|
|
{
|
|
data = new ClientPositionQueryService(CurUser).GetClientPositionAPI(
|
|
reqModel.ValueDate,
|
|
reqModel.ClientId,
|
|
reqModel.Page,
|
|
reqModel.PageRowCount);
|
|
}
|
|
|
|
return Ok(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 结算报告:历史交易
|
|
/// </summary>
|
|
[HttpPost, Route("api/v1/client/clientTradeHistory")]
|
|
public IActionResult ClientTradeHistory([FromBody] ClientLatestBalancePagedRequestModel reqModel)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(reqModel.ClientName))
|
|
{
|
|
var ids = new ClientDataService(CurUser).GetClientIdByName(reqModel.ClientName);
|
|
if (ids.Length == 0)
|
|
{
|
|
return Ok(JsonError($"根据客户名称'{reqModel.ClientName}'没有找到客户信息"));
|
|
}
|
|
if (ids.Length > 1)
|
|
{
|
|
return Ok(JsonError($"根据客户名称'{reqModel.ClientName}'找到多个客户信息,不支持此种请求"));
|
|
}
|
|
reqModel.ClientId = ids[0];
|
|
}
|
|
|
|
SearchListResult<trade_contract_group_simple> data = null;
|
|
if (reqModel.ClientId > 0)
|
|
{
|
|
data = ClientAssetDataService.GetClientTradeHistory(
|
|
reqModel.ValueDateFrom,
|
|
reqModel.ValueDateTo,
|
|
reqModel.ClientId,
|
|
reqModel.Page ?? 0,
|
|
reqModel.PageRowCount ?? 0);
|
|
}
|
|
return Ok(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 结算报告:查看交易详情
|
|
/// </summary>
|
|
[HttpPost, Route("api/v1/client/tradeDetails")]
|
|
public IActionResult TradeDetails([FromBody] ClientTradeDetailRequestModel reqModel)
|
|
{
|
|
TradeWithSettlement data = null;
|
|
if (!string.IsNullOrWhiteSpace(reqModel.EncryptedId))
|
|
{
|
|
var tradeId = DataProtectHelper.DecryptInt(reqModel.EncryptedId);
|
|
var trade = YLErp.Modules.DbContextFactory.GetYLDbContext().trade.Find(tradeId);
|
|
|
|
//客户角度看交易,买卖方向反过来
|
|
if (trade != null)
|
|
{
|
|
data = new TradeDalService(CurUser).GetTradeWithSettlementTradeCash(trade);
|
|
|
|
if (trade.BuySell == "买入")
|
|
{
|
|
data.Trade.BuySell = "卖出";
|
|
}
|
|
else if (trade.BuySell == "卖出")
|
|
{
|
|
data.Trade.BuySell = "买入";
|
|
}
|
|
|
|
if (data.MaturityTradeCash != null)
|
|
{
|
|
data.MaturityTradeCash.SingleWinPrice = -data.MaturityTradeCash.SingleWinPrice;
|
|
data.MaturityTradeCash.WinLoss = MinusNumberString(data.MaturityTradeCash.WinLoss);
|
|
}
|
|
|
|
if (data.UnwindTradeCashList != null)
|
|
{
|
|
data.UnwindTradeCashList.ForEach(tradeCash =>
|
|
{
|
|
tradeCash.WinLoss = MinusNumberString(tradeCash.WinLoss);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
return Ok(data);
|
|
}
|
|
|
|
private static string MinusNumberString(string numberStr)
|
|
{
|
|
double number;
|
|
if (double.TryParse(numberStr, out number))
|
|
{
|
|
return (-number).ToString();
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 结算报告:资金记录
|
|
/// </summary>
|
|
[HttpPost, Route("api/v1/client/clientCashRecords")]
|
|
public IActionResult ClientCashRecords([FromBody] ClientLatestBalancePagedRequestModel reqModel)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(reqModel.ClientName))
|
|
{
|
|
var ids = new ClientDataService(CurUser).GetClientIdByName(reqModel.ClientName);
|
|
if (ids.Length == 0)
|
|
{
|
|
return Ok(JsonError($"根据客户名称'{reqModel.ClientName}'没有找到客户信息"));
|
|
}
|
|
if (ids.Length > 1)
|
|
{
|
|
return Ok(JsonError($"根据客户名称'{reqModel.ClientName}'找到多个客户信息,不支持此种请求"));
|
|
}
|
|
reqModel.ClientId = ids[0];
|
|
}
|
|
|
|
SearchListResult<ClientCashInCashOutExtend> data = null;
|
|
if (reqModel.ClientId > 0)
|
|
{
|
|
data = ClientAssetDataService.GetClientCashRecords(
|
|
reqModel.ValueDateFrom,
|
|
reqModel.ValueDateTo,
|
|
reqModel.ClientId,
|
|
reqModel.Page ?? 0,
|
|
reqModel.PageRowCount ?? 0);
|
|
}
|
|
return Ok(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 结算报告:客户是否有过质押记录
|
|
/// </summary>
|
|
[HttpPost, Route("api/v1/client/clientHasCollateral")]
|
|
public ApiResponseModel ClientHasCollateral([FromBody] ClientLatestBalanceRequestModel reqModel)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(reqModel.ClientName))
|
|
{
|
|
var ids = new ClientDataService(CurUser).GetClientIdByName(reqModel.ClientName);
|
|
if (ids.Length == 0)
|
|
{
|
|
return JsonError($"根据客户名称'{reqModel.ClientName}'没有找到客户信息");
|
|
}
|
|
if (ids.Length > 1)
|
|
{
|
|
return JsonError($"根据客户名称'{reqModel.ClientName}'找到多个客户信息,不支持此种请求");
|
|
}
|
|
reqModel.ClientId = ids[0];
|
|
}
|
|
|
|
var hasCollateral = false;
|
|
if (reqModel.ClientId > 0)
|
|
{
|
|
using (var db = YLErp.Modules.DbContextFactory.GetYLDbContext())
|
|
{
|
|
hasCollateral = db.clientcashincashout_product.Count(x => x.ClientId == reqModel.ClientId) > 0;
|
|
}
|
|
}
|
|
//必须包一层
|
|
return JsonSuccess(hasCollateral);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 结算报告:质押记录
|
|
/// </summary>
|
|
[HttpPost, Route("api/v1/client/clientCollateral")]
|
|
public IActionResult ClientCollateral([FromBody] ClientLatestBalanceRequestModel reqModel)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(reqModel.ClientName))
|
|
{
|
|
var ids = new ClientDataService(CurUser).GetClientIdByName(reqModel.ClientName);
|
|
if (ids.Length == 0)
|
|
{
|
|
return Ok(JsonError($"根据客户名称'{reqModel.ClientName}'没有找到客户信息"));
|
|
}
|
|
if (ids.Length > 1)
|
|
{
|
|
return Ok(JsonError($"根据客户名称'{reqModel.ClientName}'找到多个客户信息,不支持此种请求"));
|
|
}
|
|
reqModel.ClientId = ids[0];
|
|
}
|
|
|
|
SearchListResult<clientcashincashout_productLinq> data = null;
|
|
if (reqModel.ClientId > 0)
|
|
{
|
|
var req = new clientcashincashout_productReq()
|
|
{
|
|
ValueDate = reqModel.ValueDateTo,
|
|
ClientId = reqModel.ClientId
|
|
};
|
|
data = new clientcashincashout_productBLL().SearchListForMarketReport(req);
|
|
}
|
|
return Ok(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回客户端声明
|
|
/// </summary>
|
|
[HttpGet, Route("api/v1/client/clientDesc")]
|
|
public ApiResponseModel ClientDesc()
|
|
{
|
|
using (var db = YLErp.Modules.DbContextFactory.GetYLDbContext())
|
|
{
|
|
var description = db.valuedate.FirstOrDefault(v => v.State == valuedate.当前使用).ClientDesc;
|
|
return JsonSuccess(description);//必须包一层
|
|
}
|
|
}
|
|
}
|
|
}
|