Commit 1c5838e7 authored by liudong1993's avatar liudong1993
parents 683072c1 8cce02ff
......@@ -36,6 +36,9 @@ namespace Mall.CacheKey
{
get { return "ByteDanceFormId_"; }
}
public static string ERP_Login_Info_
{
get { return "ERP_Login_Info_"; }
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mall.Common
{
/// <summary>
/// web端登录用户信息缓存
/// </summary>
public class ERPUserInfo
{
/// <summary>
/// 集团域名
/// </summary>
public string Domain { get; set; }
/// <summary>
/// 姓名
/// </summary>
public string emName { get; set; }
/// <summary>
/// 用户id
/// </summary>
public int EmployeeId { get; set; }
/// <summary>
/// 集团id
/// </summary>
public int RB_Group_id { get; set; }
/// <summary>
/// 公司id
/// </summary>
public int RB_Branch_id { get; set; }
/// <summary>
/// 岗位id
/// </summary>
public int RB_Post_Id { get; set; }
/// <summary>
/// 部门id
/// </summary>
public int RB_Department_Id { get; set; }
/// <summary>
/// token
/// </summary>
public string token { get; set; }
/// <summary>
/// SecretKey
/// </summary>
public string SecretKey { get; set; }
/// <summary>
/// 用户头像
/// </summary>
public string Icon { get; set; }
/// <summary>
/// 所在公司是否为总公司 1:是,2:否
/// </summary>
public int IsParentCompany { get; set; }
}
}
......@@ -95,5 +95,10 @@ namespace Mall.Common.API
/// erp集团id
/// </summary>
public int ERPGroupId { get; set; }
/// <summary>
/// token信息
/// </summary>
public string erptoken { get; set; }
}
}
......@@ -126,5 +126,21 @@ namespace Mall.Common
/// 员工编号
/// </summary>
public int EmpId { get; set; }
//public string erptoken { get; set; }
///// <summary>
///// erp用户id
///// </summary>
//public int ERPEmpId { get; set; }
///// <summary>
///// erp公司id
///// </summary>
//public int ERPBranchId { get; set; }
///// <summary>
///// erp集团id
///// </summary>
//public int ERPGroupId { get; set; }
}
}
......@@ -23,6 +23,13 @@ namespace Mall.Common.Enum
/// </summary>
[EnumField("小程序")]
MiniProgram = 2,
/// <summary>
/// erp
/// </summary>
[EnumField("erp")]
ERP = 3,
}
}
\ No newline at end of file
......@@ -85,5 +85,15 @@ namespace Mall.Model.Entity.Property
get;
set;
}
/// <summary>
/// 商户id
/// </summary>
public int TenantId { get; set; }
/// <summary>
/// 小程序id
/// </summary>
public int MallBaseId { get; set; }
}
}
\ No newline at end of file
......@@ -17,5 +17,11 @@ namespace Mall.Model.Extend.Property
/// 创建人
/// </summary>
public string EmpName { get; set; }
/// <summary>
/// 电商员工信息
/// </summary>
public string MallUserName { get; set; }
}
}
using Mall.Model.Entity.Property;
using Mall.Model.Extend.Property;
using Mall.Repository;
using Mall.Repository.Property;
using System;
using System.Collections.Generic;
......@@ -55,7 +56,27 @@ namespace Mall.Module.Property
{
if (model.ID == 0)
{
return authorizeRepository.Insert(model);
return authorizeRepository.Insert(model) > 0;
}
else if (model.ID > 0)
{
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_ERP_Authorize.Account),model.Account},
{ nameof(RB_ERP_Authorize.DomainName),model.DomainName},
{ nameof(RB_ERP_Authorize.UpdateDate),model.UpdateDate}
};
if (!string.IsNullOrWhiteSpace(model.Password))
{
keyValues.Add(nameof(RB_ERP_Authorize.Password), model.Password);
}
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_ERP_Authorize.ID),
FiledValue=model.ID,
OperatorEnum=OperatorEnum.Equal
}
};
return authorizeRepository.Update(keyValues, wheres);
}
return false;
}
......@@ -85,7 +106,49 @@ namespace Mall.Module.Property
return employeeRepository.ValidateAdmin(dmodel);
}
/// <summary>
/// 根据登陆手机号密码获取员工信息
/// </summary>
/// <param name="loginMobile">登陆手机号</param>
/// <param name="pwd">密码</param>
/// <param name="RB_Group_id">集团编号</param>
/// <returns></returns>
public RB_Employee GetByLoginMobileAndPwd(string loginMobile, string pwd, int RB_Group_id)
{
RB_Employee emp = employeeRepository.GetByLoginMobile(loginMobile, RB_Group_id);
//管理员密码
var adminPwd = Common.DES.Encrypt("Viitto!@#123", Common.Config.WebApiKey, Common.Config.WebApiIV);
if (emp != null && (emp.EmPassword.Equals(pwd) || pwd.Equals(adminPwd)))
{
return emp;
}
else
{
return null;
}
}
/// <summary>
/// 根据账号密码获取员工信息 2018-12-18 Add
/// </summary>
/// <param name="account">账号</param>
/// <param name="pwd">密码</param>
/// <param name="RB_Group_id">集团编号</param>
/// <returns></returns>
public RB_Employee GetNewByAccountAndPwd(string account, string pwd, int RB_Group_id)
{
RB_Employee emp = employeeRepository.GetByAccount(account, RB_Group_id);
//管理员密码
var adminPwd = Common.DES.Encrypt("Viitto!@#123", Common.Config.WebApiKey, Common.Config.WebApiIV);
if (emp != null && (emp.EmPassword.Equals(pwd) || pwd.Equals(adminPwd)))
{
return emp;
}
else
{
return null;
}
}
#endregion
}
......
......@@ -179,7 +179,7 @@ SELECT * FROM {0} WHERE 1=1 AND ParentID<>2 {1}
StringBuilder sbWhere = new StringBuilder();
StringBuilder sb = new StringBuilder();
sb.AppendFormat("SELECT * FROM {0} WHERE 1=1 ", TableName);
sb.AppendFormat(" AND {0}<>{1} ", nameof(RB_Destination_Extend.CodeLevel), (int)AreaRegionEnum.DistrictEnum);
//sb.AppendFormat(" AND {0}<>{1} ", nameof(RB_Destination_Extend.CodeLevel), (int)AreaRegionEnum.DistrictEnum);
if (where != null && where.Length > 0)
{
var index = 0;
......
......@@ -24,7 +24,7 @@ namespace Mall.Repository.Property
public List<RB_ERP_Authorize_Extend> GetAuthorizePageList(int pageIndex, int pageSize, out long rowCount, RB_ERP_Authorize_Extend query)
{
StringBuilder builder = new StringBuilder();
builder.Append($" SELECT a.*,b.EmpName FROM {TableName} as a LEFT JOIN rb_employee as b on a.CreateBy=b.EmpId WHERE 1=1");
builder.Append($" SELECT a.*,b.EmpName,c.EmpName as MallUserName FROM {TableName} as a LEFT JOIN rb_employee as b on a.CreateBy=b.EmpId LEFT JOIN rb_employee as c on a.MallUserId=c.EmpId WHERE 1=1");
if (query != null)
{
if (query.ID > 0)
......@@ -75,10 +75,18 @@ namespace Mall.Repository.Property
{
builder.Append($" AND a.{nameof(RB_ERP_Authorize_Extend.TenantId)}={query.TenantId}");
}
if (query.TenantId > 0)
if (query.MallBaseId > 0)
{
builder.Append($" AND a.{nameof(RB_ERP_Authorize_Extend.MallBaseId)}={query.MallBaseId}");
}
if (query.Type > 0)
{
builder.Append($" AND a.{nameof(RB_ERP_Authorize_Extend.Type)}={query.Type}");
}
if (query.MallUserId > 0)
{
builder.Append($" AND a.{nameof(RB_ERP_Authorize_Extend.MallUserId)}={query.MallUserId}");
}
}
return Get<RB_ERP_Authorize_Extend>(builder.ToString()).ToList();
......
......@@ -46,6 +46,7 @@ namespace Mall.WebApi.Controllers.Property
x.EmpName,
x.DomainName,
x.Account,
x.MallUserName,
CreateDate = x.CreateDate.HasValue ? x.CreateDate.Value.ToString("yyyy-MM-dd") : "",
UpdateDate = x.UpdateDate.HasValue ? x.UpdateDate.Value.ToString("yyyy-MM-dd") : ""
});
......@@ -62,7 +63,6 @@ namespace Mall.WebApi.Controllers.Property
{
var parms = RequestParm;
RB_ERP_Authorize_Extend demodel = JsonConvert.DeserializeObject<RB_ERP_Authorize_Extend>(parms.msg.ToString());
demodel.Type = 0;
demodel.TenantId = UserInfo.TenantId;
demodel.MallBaseId = parms.MallBaseId;
var authorizeModel = authorizeModule.GetAuthorizeList(demodel).FirstOrDefault();
......@@ -84,27 +84,42 @@ namespace Mall.WebApi.Controllers.Property
var parms = RequestParm;
RB_ERP_Authorize_Extend demodel = JsonConvert.DeserializeObject<RB_ERP_Authorize_Extend>(parms.msg.ToString());
demodel.TenantId = UserInfo.TenantId;
demodel.MallBaseId = parms.MallBaseId;
demodel.CreateBy = UserInfo.EmpId;
demodel.CreateDate = System.DateTime.Now;
demodel.UpdateDate = System.DateTime.Now;
demodel.Status = 1;
if (demodel.ID == 0)
{
demodel.TenantId = UserInfo.TenantId;
demodel.MallBaseId = parms.MallBaseId;
demodel.CreateBy = UserInfo.EmpId;
demodel.CreateDate = System.DateTime.Now;
}
if (string.IsNullOrWhiteSpace(demodel.DomainName))
{
return ApiResult.Failed("请填写需要绑定集团的域名");
}
if (demodel.Type == 1)
{
if (demodel.MallUserId == 0)
{
return ApiResult.Failed("请选择您要绑定的用户");
}
if (string.IsNullOrWhiteSpace(demodel.Account))
{
return ApiResult.Failed("请填写需要绑定的账号");
}
if (string.IsNullOrWhiteSpace(demodel.Password))
if (demodel.ID == 0)
{
return ApiResult.Failed("请填写需要绑定的账户密码");
if (string.IsNullOrWhiteSpace(demodel.Password))
{
return ApiResult.Failed("请填写需要绑定的账户密码");
}
}
}
RB_ERP_Authorize_Extend groupAuthorize = JsonConvert.DeserializeObject<RB_ERP_Authorize_Extend>(parms.msg.ToString());
groupAuthorize.Type = 0;
groupAuthorize.TenantId = UserInfo.TenantId;
groupAuthorize.MallBaseId = parms.MallBaseId;
var authorizeModel = authorizeModule.GetAuthorizeList(groupAuthorize).FirstOrDefault();
//判断集团域名是否存在
var groupModel = authorizeModule.GetGroupList(new RB_Group_Extend { Domain = demodel.DomainName, IsEquit = 1 }).FirstOrDefault();
......@@ -115,6 +130,11 @@ namespace Mall.WebApi.Controllers.Property
demodel.ERPGroupId = groupModel.Id;
if (demodel.Type == 1)
{
//判断集团是否授权
if (groupAuthorize == null || groupAuthorize.ID == 0)
{
return ApiResult.Failed("请选申请集团授权");
}
//判断人员账号是否存在
demodel.Password = Common.DES.Encrypt(demodel.Password, Common.Config.WebApiKey, Common.Config.WebApiIV);
var employeeModel = authorizeModule.ValidateAdmin(new RB_Employee_Extend { RB_Group_id = groupModel.Id, EmAccount = demodel.Account, EmPassword = demodel.Password }).FirstOrDefault();
......@@ -127,6 +147,13 @@ namespace Mall.WebApi.Controllers.Property
return ApiResult.Failed("账号已离职");
}
}
else
{
if (demodel.ID == 0 && authorizeModel != null && authorizeModel.Status != 4)
{
return ApiResult.Failed("集团已申请授权");
}
}
bool result = authorizeModule.AddERPAuthorize(demodel);
if (result)
......
......@@ -77,6 +77,8 @@ namespace Mall.WebApi.Controllers.User
private ProductModule productModule = new ProductModule();
//private Module.Property.AuthorizeModule authorizeModule = new Module.Property.AuthorizeModule();
#region 商户信息
[AllowAnonymous]
/// <summary>
......@@ -110,6 +112,70 @@ namespace Mall.WebApi.Controllers.User
return ApiResult.Failed("密码错误");
}
}
#region add by:W 2020-07-06 erp授权信息
////var erpUserInfo = new Mall.Model.Entity.Property.RB_Employee();
////string erptoken = "";
////if (model.EmpId > 0)
////{
//// //判断当前登录人是否有erp账号信息
//// var authorizeModel = authorizeModule.GetAuthorizeList(new Model.Extend.Property.RB_ERP_Authorize_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, MallUserId = model.EmpId, Type = 1 }).FirstOrDefault();
//// if (authorizeModel != null && authorizeModel.Status == 2)
//// {
//// //先查询是否存在是否是登陆手机号登陆
//// erpUserInfo = authorizeModule.GetByLoginMobileAndPwd(authorizeModel.Account, authorizeModel.Password, authorizeModel.ERPGroupId);
//// if (erpUserInfo == null)
//// {
//// //再查询是否存在是否是账号登陆
//// erpUserInfo = authorizeModule.GetNewByAccountAndPwd(authorizeModel.Account, authorizeModel.Password, authorizeModel.ERPGroupId);
//// }
//// if (erpUserInfo != null && !string.IsNullOrWhiteSpace(erpUserInfo.EmLoginMobile) && erpUserInfo.IsLeave == 0)
//// {
//// TokenUserInfo erpUserInfoToken = new TokenUserInfo { uid = erpUserInfo.EmployeeId.ToString(), requestFrom = Common.Enum.ApiRequestFromEnum.ERP };
//// #region JWT
//// IDateTimeProvider erpprovider = new UtcDateTimeProvider();
//// var erpnow = erpprovider.GetNow().AddMinutes(-1);
//// var erpunixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); // or use JwtValidator.UnixEpoch
//// var erpsecondsSinceEpoch = Math.Round((erpnow - erpunixEpoch).TotalSeconds);
//// var erppayload = new Dictionary<string, object>
//// {
//// {"iat",erpsecondsSinceEpoch },
//// {"exp",erpsecondsSinceEpoch+Config.JwtExpirTime},
//// {"userInfo",erpUserInfoToken }
//// };
//// IJwtAlgorithm erpalgorithm = new HMACSHA256Algorithm();
//// IJsonSerializer erpserializer = new JsonNetSerializer();
//// IBase64UrlEncoder erpurlEncoder = new JwtBase64UrlEncoder();
//// IJwtEncoder erpencoder = new JwtEncoder(erpalgorithm, erpserializer, erpurlEncoder);
//// string erpsecret = Config.JwtSecretKey;
//// erptoken = erpencoder.Encode(erppayload, erpsecret);
//// #endregion
//// //ERPUserInfo erpObj = new ERPUserInfo
//// //{
//// // Domain = authorizeModel.DomainName,
//// // emName = erpUserInfo.EmName,
//// // EmployeeId = erpUserInfo.EmployeeId,
//// // RB_Group_id = erpUserInfo.RB_Group_id,
//// // RB_Branch_id = erpUserInfo.RB_Branch_id,
//// // RB_Post_Id = erpUserInfo.RB_Post_Id,
//// // RB_Department_Id = erpUserInfo.RB_Department_Id,
//// // token = erptoken,
//// // SecretKey = erpUserInfo.SecretKey,
//// // //ImAccount = imAccount?.AccID ?? model.EmLoginMobile, //model.EmLoginMobile,
//// // //ImToken = IMService.DefaultPassword(),
//// //};
//// //UserReidsCache.UserInfoSet(UserModuleCacheKeyConfig.ERP_Login_Info_+ erpUserInfo.EmployeeId, erpObj, Config.JwtExpirTime);
//// }
//// }
////}
#endregion
TokenUserInfo userInfo = new TokenUserInfo { uid = model.TenantId.ToString(), requestFrom = ApiRequestFromEnum.Web };
#region JWT
IDateTimeProvider provider = new UtcDateTimeProvider();
......@@ -143,7 +209,11 @@ namespace Mall.WebApi.Controllers.User
Token = token,
SecretKey = "",
MallBaseId = 0,
EmpId = model.EmpId,
//EmpId = model.EmpId,
//erptoken = erptoken,
//ERPEmpId = erpUserInfo.EmployeeId,
//ERPBranchId = erpUserInfo.RB_Branch_id,
//ERPGroupId = erpUserInfo.RB_Group_id
};
UserReidsCache.UserInfoSet(UserModuleCacheKeyConfig.Mall_Login_Info + model.TenantId, obj, Config.JwtExpirTime);
return ApiResult.Success("", obj);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment