264 lines
9.0 KiB
C#
264 lines
9.0 KiB
C#
using YLErp.BLL.EodSettlement;
|
|
using YLErp.Commons;
|
|
using YLErp.Model.Enum;
|
|
using YLErp.Modules.ClientModule;
|
|
|
|
namespace YLErp.Web.Controllers
|
|
{
|
|
public class clientcashincashout_productController : BaseController
|
|
{
|
|
readonly YLContext db = new YLContext();
|
|
|
|
public ActionResult clientcashincashout_productList()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult clientcashincashout_productInnerListQuery(clientcashincashout_productReq req)
|
|
{
|
|
var bll = new clientcashincashout_productBLL();
|
|
var sList = bll.SearchList(req, out _);
|
|
return Json(sList);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 抵押品
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public JsonResult clientcashincashout_productQuery(clientcashincashout_productReq req)
|
|
{
|
|
var bll = new clientcashincashout_productBLL();
|
|
var sList = bll.SearchList(req, out _);
|
|
return Json(sList);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 抵押品
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public JsonResult clientcashincashout_productQueryForMarketReport(clientcashincashout_productReq req)
|
|
{
|
|
CurUser.CheckClientPowerByClientId(req.ClientId ?? 0);
|
|
var bll = new clientcashincashout_productBLL();
|
|
var sList = bll.SearchListForMarketReport(req);
|
|
return Json(sList);
|
|
}
|
|
|
|
public ActionResult clientcashincashout_productView(string enid)
|
|
{
|
|
var intid = DecryptInt(enid);
|
|
var r = db.clientcashincashout_product.Find(intid);
|
|
|
|
var underlying = DataCacheProvider.GetUnderlyingDataSource().GetData(r.UnderlyingId ?? 0);
|
|
if (underlying != null)
|
|
{
|
|
r.UnderlyingCode = underlying.UnderlyingCode;
|
|
r.SpotPrice = underlying.Price;
|
|
r.ProductTotalPrice = r.SpotPrice * r.ProductAmount * r.Rate;
|
|
}
|
|
|
|
var variety = db.variety.Find(r.VarietyId);
|
|
r.VarietyShortName = variety == null ? "" : variety.ShortName;
|
|
|
|
return View(r);
|
|
}
|
|
|
|
public ActionResult clientcashincashout_productEdit(string enid)
|
|
{
|
|
clientcashincashout_product r;
|
|
var isAdd = string.IsNullOrEmpty(enid) || enid == "0";
|
|
if (isAdd)
|
|
{
|
|
r = new clientcashincashout_product { HappenDate = valuedateBLL.ValueDate.Add(DateTime.Now.TimeOfDay) };
|
|
return View(r);
|
|
}
|
|
|
|
var intid = DecryptInt(enid);
|
|
r = db.clientcashincashout_product.Find(intid);
|
|
|
|
return View(r);
|
|
}
|
|
|
|
public ActionResult clientcashincashout_productBackOperation(string enid)
|
|
{
|
|
var r = new clientcashincashout_product();
|
|
var isAdd = string.IsNullOrEmpty(enid) || enid == "0";
|
|
if (isAdd)
|
|
{
|
|
return View(r);
|
|
}
|
|
|
|
var intid = DecryptInt(enid);
|
|
r = db.clientcashincashout_product.Find(intid);
|
|
|
|
return View(r);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<JsonResult> clientcashincashout_productEditJson(clientcashincashout_productReq req)
|
|
{
|
|
var id = 0;
|
|
if (!string.IsNullOrEmpty(req.EncryptId))
|
|
{
|
|
id = DecryptInt(req.EncryptId);
|
|
}
|
|
|
|
if (req.HappenDate > DateTime.Now)
|
|
{
|
|
return JsonError("抵押时间不能大于当前时间");
|
|
}
|
|
|
|
var r = await saveclientcashincashout_product(id);
|
|
|
|
if (string.IsNullOrWhiteSpace(r.ErrorMsg))
|
|
{
|
|
return JsonSuccess("更新成功", r);
|
|
}
|
|
else
|
|
{
|
|
return JsonError(r.ErrorMsg, r);
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<ActionResult> clientcashincashout_productEdit(clientcashincashout_productReq req)
|
|
{
|
|
var id = DecryptInt(req.EncryptId);
|
|
var r = await saveclientcashincashout_product(id);
|
|
return Redirect("~/clientcashincashout_product/clientcashincashout_productView/?id=" + r.EncryptId);
|
|
}
|
|
|
|
private async Task<clientcashincashout_product> saveclientcashincashout_product(int? id)
|
|
{
|
|
clientcashincashout_product r;
|
|
var isAddNew = id == null || id == 0;
|
|
if (isAddNew)
|
|
{
|
|
r = new clientcashincashout_product
|
|
{
|
|
CreatorId = CurUser.UserId,
|
|
CreatorName = CurUser.UserName,
|
|
CreateDate = DateTime.Now,
|
|
|
|
OptId = CurUser.UserId,
|
|
OptName = CurUser.UserName,
|
|
OptDate = DateTime.Now,
|
|
|
|
Status = Clientcashincashout_productStatusEnum.抵押.ToString()
|
|
};
|
|
db.clientcashincashout_product.Add(r);
|
|
}
|
|
else
|
|
{
|
|
r = db.clientcashincashout_product.Find(id);
|
|
}
|
|
|
|
await TryUpdateModelAsync(r);
|
|
|
|
//设置关联数据
|
|
var client = ClientDataQueryService.GetClient(r.ClientId, true);
|
|
if (client != null)
|
|
{
|
|
r.ClientName = client.Name;
|
|
r.ClientNumber = client.Number;
|
|
}
|
|
if (isAddNew)
|
|
{
|
|
//新增编号
|
|
r.Number = UniqueTimeId.GetStr();
|
|
}
|
|
r.Rate /= 100;
|
|
r.OptStatus = "未确认";
|
|
|
|
db.SaveChanges();
|
|
|
|
return r;
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult Deleteclientcashincashout_product(string id)
|
|
{
|
|
var intid = DecryptInt(id);
|
|
var r = db.clientcashincashout_product.Find(intid);
|
|
if (r == null)
|
|
{
|
|
return JsonError("找不到数据");
|
|
}
|
|
db.clientcashincashout_product.Remove(r);
|
|
db.SaveChanges();
|
|
return JsonSuccess("删除成功");
|
|
}
|
|
|
|
public JsonResult excute(IEnumerable<int> ids)
|
|
{
|
|
new ClientCashInCashOutDataService(CurUser).ExcuteClientCashInCashOutProduc(ids);
|
|
return JsonSuccess("执行成功");
|
|
}
|
|
public JsonResult reject(string ids)
|
|
{
|
|
var entryids = ids.Split(","[0]).Select(s => Convert.ToInt32(s)).ToList();
|
|
var entrys = db.clientcashincashout_product.Where(e => entryids.Contains(e.id)).ToList();
|
|
entrys.ForEach(e =>
|
|
{
|
|
e.OptStatus = "拒绝";
|
|
e.OptId = CurUser.UserId;
|
|
e.OptName = CurUser.UserName;
|
|
e.OptDate = DateTime.Now;
|
|
});
|
|
db.SaveChanges();
|
|
|
|
return JsonSuccess("拒绝成功");
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult setBackStatus(clientcashincashout_productReq req)
|
|
{
|
|
var intid = DecryptInt(req.EncryptId);
|
|
var r = db.clientcashincashout_product.Find(intid);
|
|
|
|
if (r == null)
|
|
{
|
|
return JsonError("该抵押品记录不存在");
|
|
}
|
|
|
|
if (req.BackDate < r.HappenDate)
|
|
{
|
|
return JsonError("赎回时间不能小于抵押时间");
|
|
}
|
|
|
|
if (req.BackDate > DateTime.Now)
|
|
{
|
|
return JsonError("赎回时间不能大于当前时间");
|
|
}
|
|
|
|
r.Status = Clientcashincashout_productStatusEnum.赎回.ToString();
|
|
r.OptStatus = "未确认";
|
|
r.BackDate = req.BackDate;
|
|
r.OptId = CurUser.UserId;
|
|
r.OptName = CurUser.UserName;
|
|
r.OptDate = DateTime.Now;
|
|
|
|
var spotPrice = DataCacheProvider.GetUnderlyingDataSource().GetData(r.UnderlyingId ?? 0)?.Price;
|
|
//查看当前客户可用资金是否符合出金条件
|
|
var clientbalance = ClientBalanceUtility.GetClientBanlances(new List<int> { r.ClientId }, DateTime.MinValue, DateTime.Now.Date).FirstOrDefault();
|
|
//当日可用资金(除去抵押品部分的价值,默认客户先消费现金,再消费抵押品,所以出金时可用资金要除去抵押品的价值)
|
|
var availableFund = (clientbalance == null ? 0 : clientbalance.AvailableAmount);
|
|
//如果出金大于可用资金(修改操作时需要算差价)则抛出错误
|
|
if ((spotPrice * r.ProductAmount * r.Rate ?? 0.0) > availableFund)
|
|
{
|
|
var variety = db.variety.Find(r.VarietyId);
|
|
return JsonError("部分执行错误,客户:" + r.ClientName + " 赎回抵押品:" + (variety == null ? "" : variety.ShortName) + "失败,实际可用资金:" + availableFund.ToString("0.00") + ",小于抵押品抵押价值;");
|
|
}
|
|
|
|
db.SaveChanges();
|
|
|
|
return JsonSuccess("赎回成功");
|
|
}
|
|
}
|
|
}
|