using YLErp.Commons; using YLErp.Model.Enum; using YLErp.Modules.ClientModule; namespace YLErp.Web.Controllers { public class servicerepresentativeconfigController : BaseController { /// /// 获取所有服务商名称下拉列表 /// public static List GetAllServiceNames() { using (var db = DbContextFactory.GetClientDbContext(null)) { var serviceIds = db.servicerepresentativeconfig.Select(n => n.ServiceId).ToArray(); if (serviceIds.Any()) { return ClientDataQueryService.GetClientsFromDB(n => serviceIds.Contains(n.id)) .Select(n => new SelectListItem { Text = n.Name, Value = n.id + "" }).ToList(); } } return new List(); } public ActionResult servicerepresentativeconfigList() { return View(); } [HttpPost] public JsonResult servicerepresentativeconfigQuery(ServiceRepresentativeConfigReq req) { var sList = new ServicerePresentativeConfigService(CurUser).SearchList(req); foreach (var x in sList.rows) { x.DefaultPremiumRate *= 100; x.PremiumRateVariation = Convert.ToDouble(Convert.ToDecimal(x.PremiumRateVariation) * 10000); } return Json(sList); } public ActionResult servicerepresentativeconfigView(string enid) { var intid = DataProtectHelper.DecryptInt(enid); var r = clientDB.servicerepresentativeconfig.Find(intid); var serviceModel = ClientDataQueryService.GetClient(r.ServiceId); if (serviceModel != null) { r.ServiceName = serviceModel.Name; } return View(r); } public ActionResult servicerepresentativeconfigEdit(string enid) { var r = new ServiceRepresentativeConfig(); var isAdd = string.IsNullOrEmpty(enid) || enid == "0"; if (isAdd) { return View(r); } var intid = DataProtectHelper.DecryptInt(enid); r = clientDB.servicerepresentativeconfig.Find(intid); return View(r); } [HttpPost] public async Task servicerepresentativeconfigEditJson(ServiceRepresentativeConfigReq req) { var id = 0; if (!string.IsNullOrEmpty(req.EncryptId)) { id = DataProtectHelper.DecryptInt(req.EncryptId); } var r = await saveservicerepresentativeconfig(id, req); if (!r.Success) { return JsonError(r.Msg); } return JsonSuccess("更新成功", r.Content); } [HttpPost] public async Task servicerepresentativeconfigEdit(ServiceRepresentativeConfigReq req) { var id = DataProtectHelper.DecryptInt(req.EncryptId); var r = await saveservicerepresentativeconfig(id, req); if (!r.Success) { return JsonError(r.Msg); } return Redirect("~/servicerepresentativeconfig/servicerepresentativeconfigView/?id=" + r.Content.EncryptId); } private async Task> saveservicerepresentativeconfig(int? id,ServiceRepresentativeConfigReq req = null) { if (!string.IsNullOrWhiteSpace(req.Alias) && clientDB.servicerepresentativeconfig.Any(s => s.Alias == req.Alias && s.id != id)) { return Return.Fail("此别名已经存在了"); } if (req.ServiceId.HasValue && clientDB.servicerepresentativeconfig.Any(s => s.ServiceId == req.ServiceId.Value && s.id != id)) { return Return.Fail("已经有该供应商的配置了"); } ServiceRepresentativeConfig r; var isAddNew = id == null || id == 0; if (isAddNew) { r = new ServiceRepresentativeConfig(); clientDB.servicerepresentativeconfig.Add(r); } else { r = clientDB.servicerepresentativeconfig.Find(id); if (!req.SellerRightDeliveryDayType.HasValue) { req.SellerRightDeliveryDayType = r.SellerRightDeliveryDayType; } } await TryUpdateModelAsync(r); r.SellerRightDeliveryDayType = req.SellerRightDeliveryDayType; r.DefaultPremiumRate /= 100; r.PremiumRateVariation /= 10000; if (CurUser != null) { r.OptDate = DateTime.Now; r.OptId = CurUser.UserId; r.OptName = CurUser.UserName; } clientDB.SaveChanges(); return Return.Success(r); } [HttpPost] public JsonResult Deleteservicerepresentativeconfig(string id) { var intid = DataProtectHelper.DecryptInt(id); var r = clientDB.servicerepresentativeconfig.Find(intid); if (r == null) { return JsonError("找不到服务商配置"); } clientDB.servicerepresentativeconfig.Remove(r); clientDB.SaveChanges(); return JsonSuccess("删除成功"); } public static List GetAllSellerRightDeliveryDayType() { return new List { new SelectListItem() { Text =SellerRightDeliveryDayTypeEnum.行权日.ToString(), Value=((int)SellerRightDeliveryDayTypeEnum.行权日).ToString() }, new SelectListItem() { Text =SellerRightDeliveryDayTypeEnum.交易开始日.ToString(), Value=((int)SellerRightDeliveryDayTypeEnum.交易开始日).ToString() } }; } public static string GetSellerRightDeliveryDayTypeByID(int? SellerRightDeliveryDayType) { if (SellerRightDeliveryDayType == (int)SellerRightDeliveryDayTypeEnum.交易开始日) { return SellerRightDeliveryDayTypeEnum.交易开始日.ToString(); } else { return SellerRightDeliveryDayTypeEnum.行权日.ToString(); } } /// /// 获取行权规则下拉菜单 /// /// public static List GetAllExerciseRule() { return new List() { new SelectListItem() { Text = "T + 0", Value = "0" }, new SelectListItem() { Text = "T + 1", Value = "1" }, new SelectListItem() { Text = "T + 2", Value = "2" } }; } public static string GetExerciseRuleName(int? exerciseRule) { return "T + " + (exerciseRule == null ? 0 : exerciseRule.Value); } } }