Files
zszq-trs/YLErpWeb/Controllers/servicerepresentativeconfigController.cs
T
2024-05-09 14:06:26 +08:00

225 lines
7.6 KiB
C#

using YLErp.Commons;
using YLErp.Model.Enum;
using YLErp.Modules.ClientModule;
namespace YLErp.Web.Controllers
{
public class servicerepresentativeconfigController : BaseController
{
/// <summary>
/// 获取所有服务商名称下拉列表
/// </summary>
public static List<SelectListItem> 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<SelectListItem>();
}
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<JsonResult> 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<ActionResult> 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<ReturnInfo<ServiceRepresentativeConfig>> 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<ServiceRepresentativeConfig>("此别名已经存在了");
}
if (req.ServiceId.HasValue && clientDB.servicerepresentativeconfig.Any(s => s.ServiceId == req.ServiceId.Value && s.id != id))
{
return Return.Fail<ServiceRepresentativeConfig>("已经有该供应商的配置了");
}
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<SelectListItem> GetAllSellerRightDeliveryDayType()
{
return new List<SelectListItem> {
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();
}
}
/// <summary>
/// 获取行权规则下拉菜单
/// </summary>
/// <returns></returns>
public static List<SelectListItem> GetAllExerciseRule()
{
return new List<SelectListItem>()
{
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);
}
}
}