174 lines
5.8 KiB
C#
174 lines
5.8 KiB
C#
using Models;
|
||
using Models.ModelItems;
|
||
using Models.View;
|
||
using Services.Cache;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using Newtonsoft.Json;
|
||
using static Services.Cache.CacheHelp;
|
||
using SqlSugar;
|
||
|
||
namespace Services.Manager
|
||
{
|
||
public class HotelServer
|
||
{
|
||
//键值对存储酒店的最高就酒店组 如果存在就不需要查找
|
||
public static Dictionary<int, int> keyValues = new Dictionary<int, int>();
|
||
#region 检测组名
|
||
public static bool CheckGroupName(string Name, int ParentId)
|
||
{
|
||
|
||
var au = CacheHelp.cacheHoteldGroups.FirstOrDefault(x => x.ParentId == ParentId && x.Name == Name);
|
||
if (au == null)
|
||
return true;
|
||
else
|
||
return false;
|
||
}
|
||
#endregion
|
||
#region 添加组名
|
||
public static int? AddGroupName(string Name, int ParentId, string Desc)
|
||
{
|
||
var au = CacheHelp.cacheHoteldGroups.FirstOrDefault(x => x.ParentId == ParentId && x.Name == Name);
|
||
if (au != null)
|
||
return null;
|
||
|
||
HotelGroups groups = new HotelGroups() { Name = Name, ParentId = ParentId, Desc = Desc };
|
||
SqlSugarBase.Db.Insertable(groups).ExecuteCommand();
|
||
CacheHelp.Removesys(syskey.sysHoteldGroupsListKey);
|
||
return groups.Id;
|
||
|
||
}
|
||
#endregion
|
||
#region 检测酒店名
|
||
public static bool CheckHotelName(string Name, int ParentId)
|
||
{
|
||
|
||
var au = CacheHelp.cacheHotels.FirstOrDefault(x => x.GroupId == ParentId && x.Name == Name);
|
||
if (au == null)
|
||
return true;
|
||
else
|
||
return false;
|
||
}
|
||
#endregion
|
||
#region 添加酒店名
|
||
public static int? AddHotel(string Name, int ParentId, string Desc)
|
||
{
|
||
var au = CacheHelp.cacheHotels.FirstOrDefault(x => x.GroupId == ParentId && x.Name == Name);
|
||
if (au != null)
|
||
return null;
|
||
Hotels hotels = new Hotels() { Name = Name, GroupId = ParentId, Desc = Desc };
|
||
SqlSugarBase.Db.Insertable(hotels).ExecuteCommand();
|
||
CacheHelp.Removesys(syskey.sysHotelsListKey);
|
||
return hotels.Id;
|
||
}
|
||
#endregion
|
||
//返回酒店下面的人员信息 权限数量
|
||
#region 找查酒店用户信息
|
||
public static dynamic FindUserinfo()
|
||
{
|
||
dynamic resdata;
|
||
var res = new List<dynamic>();
|
||
var data = UserInfoServer.GetUserInfo(null);
|
||
foreach (var item in data)
|
||
{
|
||
foreach (var tump in item.HotelInfo)
|
||
{
|
||
res.Add(new
|
||
{
|
||
hotelId = tump.id,
|
||
Id = item.Id,
|
||
Uid = item.Uid,
|
||
sum = tump.sum
|
||
});
|
||
}
|
||
}
|
||
resdata = res.GroupBy(x => x.hotelId).ToList();
|
||
return resdata;
|
||
}
|
||
#endregion
|
||
#region 找查 用户最高所属酒店组 或者 公司信息
|
||
public static dynamic FindUserinfoGs(View_UserInfo u)
|
||
{
|
||
try
|
||
{
|
||
if (u.Company != null)
|
||
{
|
||
return new
|
||
{
|
||
//0 宝来威 1 住好 2 卓豪
|
||
Id = u.Company,
|
||
name = u.Company == 0?"宝来威":(u.Company == 1? "住好" : "卓豪")
|
||
};
|
||
}
|
||
//if(u.Company)
|
||
var S = 2;
|
||
if (u.IsImport > 0)
|
||
{
|
||
if (u.HotelGroupID > 0)
|
||
S = FindRoot(u.HotelGroupID);
|
||
else
|
||
{
|
||
if (u.HotelID > 1)
|
||
S = FindRoot_(u.HotelID);
|
||
}
|
||
}
|
||
S -= 2;
|
||
if (S < 0)
|
||
{
|
||
throw new Exception("用户没有找到对应的公司"+u.Id.ToString());
|
||
}
|
||
// S 2 "宝来威" 3 住好
|
||
|
||
UserInfo info = new UserInfo();
|
||
info.Id = u.Id;
|
||
info.Company = S;
|
||
var result = SqlSugarBase.Db.Updateable(info).UpdateColumns(it => new { it.Company }).ExecuteCommand();
|
||
Task.Run(() =>{
|
||
Cache.CacheHelp.Removesys(syskey.sysUserInfoListKey);
|
||
});
|
||
return new
|
||
{
|
||
Id = S,
|
||
name = S == 0 ? "宝来威" : (u.Company == 1 ? "住好" : "卓豪")
|
||
};
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Logs.WriteTimingUDPLog("参入参数:"+JsonConvert.SerializeObject( u));
|
||
LogHelp.WriteExceptionLog(ex);
|
||
return new
|
||
{
|
||
Id = 0,
|
||
name = "宝来威"
|
||
};
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
static dynamic FindRoot(int? group)
|
||
{
|
||
if (group == null)
|
||
return 0;
|
||
var groupinfo = cacheHoteldGroups.FirstOrDefault(x => x.Id == group);
|
||
if (groupinfo == null)
|
||
throw new Exception("group未找到!");
|
||
if (groupinfo.ParentId <= 1)
|
||
return groupinfo.Id;
|
||
return FindRoot(groupinfo.ParentId);
|
||
}
|
||
static dynamic FindRoot_(int? id)
|
||
{
|
||
if (id == null)
|
||
return 0;
|
||
var groupinfo = cacheHotels.First(x => x.Id == id);
|
||
return FindRoot(groupinfo.GroupId);
|
||
}
|
||
}
|
||
}
|