using Learun.Util;
using System.Data;
using Learun.Application.TwoDevelopment.PersonnelManagement;
using System.Web.Mvc;
using System.Collections.Generic;
using Quanjiang.DigitalScholl.SendSms;
using System;
using Learun.Cache.Redis;
namespace Learun.Application.Web.Areas.PersonnelManagement.Controllers
{
///
/// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
/// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
/// 创 建:超级管理员
/// 日 期:2021-05-17 10:11
/// 描 述:访客管理
///
public class VisitorInfoController : MvcControllerBase
{
private VisitorInfoIBLL visitorInfoIBLL = new VisitorInfoBLL();
CacheByRedis _redis = new CacheByRedis();
#region 视图功能
///
/// 主页面
///
///
[HttpGet]
public ActionResult Index()
{
return View();
}
///
/// 表单页
///
///
[HttpGet]
public ActionResult Form()
{
return View();
}
///
/// 表单页
///
///
[HttpGet]
public ActionResult FormAdd()
{
return View();
}
///
///
///
///
[HttpGet]
public ActionResult ExamineForm()
{
return View();
}
#endregion
#region 获取数据
///
/// 生成验证码
///
///
[HttpGet]
public ActionResult VerifyCode()
{
return File(new VerifyCode().GetVerifyCode(), @"image/Gif");
}
///
/// 获取页面显示列表数据
///
/// 分页参数
/// 查询参数
///
[HttpGet]
[AjaxOnly]
public ActionResult GetPageList(string pagination, string queryJson)
{
Pagination paginationobj = pagination.ToObject();
var data = visitorInfoIBLL.GetPageList(paginationobj, queryJson);
var jsonData = new
{
rows = data,
total = paginationobj.total,
page = paginationobj.page,
records = paginationobj.records
};
return Success(jsonData);
}
///
/// 获取表单数据
///
/// 主键
///
[HttpGet]
[AjaxOnly]
public ActionResult GetFormData(string keyValue)
{
var VisitorInfoData = visitorInfoIBLL.GetVisitorInfoEntity(keyValue);
var jsonData = new
{
VisitorInfo = VisitorInfoData,
};
return Success(jsonData);
}
#endregion
#region 提交数据
///
/// 删除实体数据
///
/// 主键
///
[HttpPost]
[AjaxOnly]
public ActionResult DeleteForm(string keyValue)
{
visitorInfoIBLL.DeleteEntity(keyValue);
return Success("删除成功!");
}
///
/// 保存实体数据(新增、修改)
///
/// 主键
/// 实体
/// 图片验证码
/// 手机验证码
///
[HttpPost]
[ValidateAntiForgeryToken]
[AjaxOnly]
public ActionResult SaveForm(string keyValue, string strEntity, string verifycode, string phonecode)
{
VisitorInfoEntity entity = strEntity.ToObject();
var VisitorInfoData = visitorInfoIBLL.GetEntityByPhone(entity.VPhone);
if (string.IsNullOrEmpty(keyValue) && VisitorInfoData != null)
return Fail("手机号已存在!");
else if (!string.IsNullOrEmpty(keyValue) && VisitorInfoData.VID != keyValue)
return Fail("手机号已存在!");
//验证图片验证码
verifycode = Md5Helper.Encrypt(verifycode.ToLower(), 16);
if (Session["session_verifycode"].IsEmpty() || verifycode != Session["session_verifycode"].ToString())
{
return Fail("图片验证码错误");
}
//验证手机验证码
var type = (SmsType)Enum.Parse(typeof(SmsType), "0");
var smscode = _redis.Read($"checkcode_{type}_{entity.VPhone}");
if (!string.IsNullOrEmpty(smscode))
{
if (smscode != phonecode)
{
return Fail("手机验证码不正确,请核对!");
}
}
entity.VState = 0;
entity.VApplyTime = DateTime.Now;
visitorInfoIBLL.SaveEntity(keyValue, entity);
if (string.IsNullOrEmpty(keyValue))
{
}
return Success("保存成功!");
}
///
/// 审核
/// 主键
///
///
[HttpPost]
[AjaxOnly]
public ActionResult Check(string keyValue,string strEntity)
{
//var keyValueArr = keyValue.Split(',');
//var keyValues = "'" + string.Join("','", keyValueArr) + "'";
VisitorInfoEntity entity = strEntity.ToObject();
visitorInfoIBLL.Check(keyValue, entity.VExamineRemarks);
return Success("审核成功!");
}
///
/// 取消审核
/// 主键
///
///
[HttpPost]
[AjaxOnly]
public ActionResult UnCheck(string keyValue)
{
var keyValueArr = keyValue.Split(',');
var keyValues = "'" + string.Join("','", keyValueArr) + "'";
visitorInfoIBLL.UnCheck(keyValues);
return Success("取消审核成功!");
}
///
/// 全部审核
/// 主键
///
///
[HttpPost]
[AjaxOnly]
public ActionResult CheckAll()
{
visitorInfoIBLL.CheckAll();
return Success("全部审核成功!");
}
///
/// 生成帐号
///
///
[HttpPost]
[AjaxOnly]
public ActionResult Generate()
{
visitorInfoIBLL.GenerateAccout();
return Success("生成成功!");
}
#endregion
}
}