You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/SysMng/Controllers/USERINFOController.cs

380 lines
12 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using DSWeb.Areas.SysMng.DAL.USERINFO;
using DSWeb.Areas.SysMng.Models.USERINFO;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.TruckMng.Helper;
using DSWeb.TruckMng.Helper.Repository;
using HcUtility.Comm;
using HcUtility.Core;
using DSWeb.Areas.Mobile.Helper;
using DSWeb.Areas.Dispatch.Models;
using System.Runtime.Caching;
using DSWeb.Areas.Dispatch.Helper;
using Newtonsoft.Json.Linq;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.Areas.CommMng.DAL;
using Newtonsoft.Json;
namespace DSWeb.Areas.SysMng.Controllers
{
[JsonRequestBehavior]
public class USERINFOController : Controller
{
//
// GET: /TruckMng/Enum/
public ActionResult Index()
{
return View();
}
//
// GET: /TruckMng/Enum/Edit
public ActionResult Edit()
{
return View();
}
//
// GET/TruckMng/Enum/GetDataList
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = USERINFODAL.GetDataList(condition);
var list = dataList.Skip(start).Take(limit);
var json =DSWeb.TruckMng.Helper. JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
//
// GET/TruckMng/Enum/GetData/
public ContentResult GetData()
{
USERmb headData = null;
var _USERID = Session["USERID"].ToString();
var condition = " GID='" + _USERID + "'";
var list = USERINFODAL.GetDataList(condition);
if (list.Count > 0)
headData = list[0];
if (headData == null)
{
headData = new USERmb();
}
var json = DSWeb.TruckMng.Helper.JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = headData });
return new ContentResult() { Content = json };
}
//
// GET/TruckMng/Enum/Save
public ContentResult Save ( string opstatus, string data, string body, string Delbody )
{
var headData = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<USERmb>(data);
var bodyList = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<List<USERINFOmb>>(body);
var DelbodyList = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<List<USERINFOmb>>(Delbody);
var result = new DBResult();
var _USERID = Session["USERID"].ToString();
var condition = " GID='" + _USERID + "'";
string username = headData.USERNAME;
if (!string.IsNullOrEmpty(headData.PASSWORD))
{
var _USER = USERINFODAL.GetData(condition);
if (_USER.PASSWORD != headData.OLDPASSWORD)
{
var jsonRespose2 = new JsonResponse
{
Success = false,
Message = "旧密码填写错误",
Data = ""
};
return new ContentResult() { Content = DSWeb.TruckMng.Helper. JsonConvert.Serialize(jsonRespose2) };
}
else
{
}
}
else {
headData = USERINFODAL.GetData(condition);
headData.USERNAME = username;
}
//if (opstatus == "add")
//{
// headData.DbOperationType = DbOperationType.DbotIns;
// headData.ModelUIStatus = "I";
//}
//else
//{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
//}
var modb = new ModelObjectRepository();
result = modb.Save(headData,
ModelObjectConvert<USERINFOmb>.ToModelObjectList(bodyList),
ModelObjectConvert<USERINFOmb>.ToModelObjectList(DelbodyList)
);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = ""
};
return new ContentResult() { Content = DSWeb.TruckMng.Helper.JsonConvert.Serialize(jsonRespose) };
}
//
// GET/TruckMng/Enum/Delete
public ContentResult GetUSERINFOBodyList()
{
var _USERID = Session["USERID"].ToString();
var condition = " USERID='" + _USERID + "'";
List<USERINFOmb> list = USERINFODAL.GetUSERINFOList(condition);
var json = DSWeb.TruckMng.Helper.JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetUSERINFOData()
{
USERINFOmb headData = null;
var _USERID = Session["USERID"].ToString();
var condition = " USERID='" + _USERID + "'";
var list = USERINFODAL.GetUSERINFOList(condition);
if (list.Count > 0)
headData = list[0];
if (headData == null)
{
headData = new USERINFOmb();
}
var json = DSWeb.TruckMng.Helper.JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = headData });
return new ContentResult() { Content = json };
}
#region 参照部分
#endregion
public ActionResult GetMobileCode()
{
var user = USERINFODAL. GetUserInfo(Convert.ToString(Session["USERID"]));
var mobile = user.MOBILE;
RespCommon resp = new RespCommon();
string key1 = $"REM_{mobile}";
string key2 = $"MC_{mobile}";
var DJYCOMPANYID = MsSysParamSetDAL.GetData("PARAMNAME='DJYCOMPANYID'");
if (string.IsNullOrEmpty(DJYCOMPANYID.PARAMVALUE))
{
resp.Success = false;
resp.Message = "请先配置参数设置【大简云公司代码】";
return Json(resp);
}
if (MemoryCache.Default.Contains(key1))
{
resp.Success = false;
resp.Message = "获取验证码过于频繁";
}
else
{
Random rnd = new Random();
string code = rnd.Next(1000, 10000).ToString();
MemoryCache.Default.Add(new CacheItem(key1, true), new CacheItemPolicy() { AbsoluteExpiration = DateTime.Now.AddSeconds(120) });
MemoryCache.Default.Remove(key2);
MemoryCache.Default.Add(new CacheItem(key2, code), new CacheItemPolicy() { AbsoluteExpiration = DateTime.Now.AddMinutes(5) });
AliMessageTools.SendSignCodeMsg(mobile, code);
resp.Success = true;
resp.Message = "验证码已发送";//LangCommon.MsgMobileCodeSent;
}
return Json(resp);
}
[HttpPost]
public ActionResult DJYReg(string mobilecode)
{
//测试地址 http://123.234.225.158:35000/user/UserUploadDS
var = "http://123.234.225.158:35000/user/UserUploadDS";
RespCommon resp = new RespCommon();
DJYRegInfo dJYRegInfo = new DJYRegInfo();
dJYRegInfo.SetValue(Convert.ToString(Session["USERID"]));
var errormsg = dJYRegInfo.CanSend();
if (errormsg != "") {
resp.Success = false;
resp.Message = errormsg;
return Json(resp);
}
JObject reqObj = dJYRegInfo.keyValuePairs();
string rtn = WebRequestHelper.DoPost(, reqObj.ToString(Formatting.None));
var obj = new { Success = false, Message = "", UserData = "", ShortName = "", LoginName = "" };
var jsonObj = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(rtn, obj);
if (jsonObj.Success)
{
//Session["UserData"] = jsonObj.UserData;
//Session["UserShortName"] = jsonObj.ShortName;
//Session["UserLoginName"] = jsonObj.LoginName;
//if (!string.IsNullOrWhiteSpace(returnUrl))
//{
// return Redirect(returnUrl);
//}
//else
//{
// return RedirectToAction("Index");
//}
return View();
}
else
{
ModelState.AddModelError("Validate", jsonObj.Message);
return View();
}
}
}
public class DJYRegInfo {
public string USERID { get; set; }
public string USERNAME { get; set; }
public string CODENAME { get; set; }
public string PASSWORD { get; set; }
public string SHOWNAME { get; set; }
public string CORPID { get; set; }
public string OFFICEPHONE { get; set; }
public string HOMEPHONE { get; set; }
public string MOBILE { get; set; }
public string FAX { get; set; }
public string EMAIL1 { get; set; }
public string EMAIL2 { get; set; }
public string HOMEADDRESS { get; set; }
public string ERPTYPE { get; set; } = "ERP";
public string UPLOADTIME { get; set; }
public string SIGN { get; set; }
public void SetValue(string USERID) {
var headData = USERINFODAL.GetUser(USERID);
var headInfoData = USERINFODAL.GetUserInfo(USERID);
USERID = headData.GID;
USERNAME = headData.USERNAME;
CODENAME = headData.DJY_CODENAME;
PASSWORD = headData.DJY_PASSWORD;
SHOWNAME = headData.USERNAME;
var DJYCOMPANYID = MsSysParamSetDAL.GetData("PARAMNAME='DJYCOMPANYID'");
CORPID = DJYCOMPANYID.PARAMVALUE;
OFFICEPHONE = headInfoData.OFFICEPHONE;
MOBILE = headInfoData.MOBILE;
FAX = headInfoData.FAX;
EMAIL1 = headInfoData.EMAIL1;
EMAIL2 = headInfoData.EMAIL2;
HOMEADDRESS = headInfoData.HOMEADDRESS;
ERPTYPE = "ERP";
UPLOADTIME = DateTime.Now.ToString("yyyyMMddHHmmss");
getSign();
}
private void getSign() {
var _str = CODENAME + "&" + CORPID + "&" + ERPTYPE + "&" + MOBILE + "&" + SHOWNAME + "&" + UPLOADTIME + "&" + USERID;
var md5 = BasicDataRefDAL.GetMd5Hash(_str).ToLower();
SIGN = md5;
}
public JObject keyValuePairs() {
JObject reqObj = new JObject();
reqObj.Add("USERID", USERID);
reqObj.Add("USERNAME", USERNAME);
reqObj.Add("CODENAME", CODENAME);
reqObj.Add("PASSWORD", PASSWORD);
reqObj.Add("SHOWNAME", SHOWNAME);
reqObj.Add("CORPID", CORPID);
reqObj.Add("OFFICEPHONE", OFFICEPHONE);
reqObj.Add("MOBILE", MOBILE);
reqObj.Add("FAX", FAX);
reqObj.Add("EMAIL1", EMAIL1);
reqObj.Add("EMAIL2", EMAIL2);
reqObj.Add("HOMEADDRESS", HOMEADDRESS);
reqObj.Add("ERPTYPE", ERPTYPE);
reqObj.Add("UPLOADTIME", UPLOADTIME);
reqObj.Add("SIGN", SIGN);
return reqObj;
}
public string CanSend() {
var result = "";
void addmsg(string msg) {
if (result != "") result += ";";
result += msg;
}
if (string.IsNullOrWhiteSpace(PASSWORD) || PASSWORD.Length<6) {
addmsg("大简云密码过短");
}
var DJYCOMPANYID = MsSysParamSetDAL.GetData("PARAMNAME='DJYCOMPANYID'");
if (string.IsNullOrEmpty(DJYCOMPANYID.PARAMVALUE))
{
addmsg("请先配置参数设置【大简云公司代码】");
}
return result;
}
}
}