152 lines
4.5 KiB
C#
152 lines
4.5 KiB
C#
using YLErp.Modules.ClientModule;
|
|
|
|
namespace YLErp.Web.Controllers
|
|
{
|
|
public class credit_ratingController : BaseController
|
|
{
|
|
public static List<SelectListItem> GetValidcredit_rating()
|
|
{
|
|
using (var db = DbContextFactory.GetClientDbContext(null))
|
|
{
|
|
return db.credit_rating.Where(x => x.ValidState == "Valid").Select(m => new SelectListItem
|
|
{
|
|
Text = m.CreditName,
|
|
Value = m.id + ""
|
|
}).ToList();
|
|
}
|
|
}
|
|
|
|
[MyAuthorize("客户管理-资信等级")]
|
|
public ActionResult credit_ratingList()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult credit_ratingQuery(CreditRatingReq req)
|
|
{
|
|
var sList = new CreditRatingService(CurUser).SearchList(req);
|
|
return Json(sList);
|
|
}
|
|
|
|
public ActionResult credit_ratingView(string enid)
|
|
{
|
|
var intid = DataProtectHelper.DecryptInt(enid);
|
|
var r = clientDB.credit_rating.Find(intid);
|
|
return View(r);
|
|
}
|
|
|
|
public ActionResult credit_ratingEdit(string enid)
|
|
{
|
|
var r = new CreditRating();
|
|
var isAdd = string.IsNullOrEmpty(enid) || enid == "0";
|
|
if (isAdd)
|
|
{
|
|
return View(r);
|
|
}
|
|
|
|
var intid = DataProtectHelper.DecryptInt(enid);
|
|
r = clientDB.credit_rating.Find(intid);
|
|
|
|
return View(r);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<JsonResult> credit_ratingEditJson(CreditRatingReq req)
|
|
{
|
|
var id = 0;
|
|
|
|
if (!string.IsNullOrEmpty(req.EncryptId))
|
|
{
|
|
id = DataProtectHelper.DecryptInt(req.EncryptId);
|
|
}
|
|
|
|
if (req.ValidState == "InValid")
|
|
{
|
|
var systemDate = valuedateBLL.SystemDate;
|
|
//系统交易日
|
|
var valueDate = systemDate.ValueDate;
|
|
|
|
if (clientDB.Client_Rating.Any(x => !x.IsDeleted && x.ProcessStatus != "已拒绝" && x.CreditRatingId == id && x.RatingStartDate <= valueDate && x.RatingDeadLine >= valueDate))
|
|
{
|
|
return JsonError("该客户等级正在被使用中,不能设置为无效");
|
|
}
|
|
}
|
|
|
|
var r = await savecredit_rating(id, req);
|
|
|
|
if (r == null)
|
|
{
|
|
return JsonError("资信等级不能重复");
|
|
}
|
|
|
|
return JsonSuccess("更新成功", r);
|
|
}
|
|
|
|
private async Task<CreditRating> savecredit_rating(int? id, CreditRatingReq req = null)
|
|
{
|
|
CreditRating r;
|
|
|
|
//判断资信评级名称是否重复,重复的话返回null,前台将会根据null给出消息提示
|
|
var CreditName = clientDB.credit_rating.FirstOrDefault(x => x.id != id && x.CreditName == req.CreditName);
|
|
if (CreditName != null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var isAddNew = id == null || id == 0;
|
|
if (isAddNew)
|
|
{
|
|
r = new CreditRating
|
|
{
|
|
OptId = CurUser.UserId,
|
|
OptName = CurUser.UserName,
|
|
OptDate = DateTime.Now
|
|
};
|
|
|
|
clientDB.credit_rating.Add(r);
|
|
}
|
|
else
|
|
{
|
|
r = clientDB.credit_rating.Find(id);
|
|
r.OptId = CurUser.UserId;
|
|
r.OptName = CurUser.UserName;
|
|
r.OptDate = DateTime.Now;
|
|
}
|
|
r.OptDate = DateTime.Now;
|
|
r.Remark = req.Remark;
|
|
await TryUpdateModelAsync(r);
|
|
if (!req.IsUnLimited.HasValue)
|
|
{
|
|
r.IsUnLimited = 0;
|
|
}
|
|
|
|
if (double.TryParse(req.CreditLine, out var creditLine))
|
|
{
|
|
r.CreditLine = creditLine;
|
|
}
|
|
else
|
|
{
|
|
r.CreditLine = 0;
|
|
}
|
|
|
|
clientDB.SaveChanges();
|
|
|
|
return r;
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult Deletecredit_rating(string id)
|
|
{
|
|
var intid = DataProtectHelper.DecryptInt(id);
|
|
var r = clientDB.credit_rating.Find(intid);
|
|
if (r == null)
|
|
{
|
|
return JsonError("找不到资信等级");
|
|
}
|
|
clientDB.credit_rating.Remove(r);
|
|
clientDB.SaveChanges();
|
|
return JsonSuccess("删除成功");
|
|
}
|
|
}
|
|
} |