yz_server/Server/Services/BlacklistService.cs

337 lines
12 KiB
C#
Raw Normal View History

2022-04-16 07:48:12 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common.DbExtends.Extends;
using Common.Models.Enums;
using Common.Models.UnqTables;
using Server.Controllers.Help;
using Server.Utils;
using SqlSugar;
namespace Server.Services
{
/// <summary>
/// 黑名单服务
/// </summary>
public class BlacklistService
{
private SqlSugarClient Db { get; set; }
public BlacklistService()
{
Db = Client.SingleClient.Db;
}
private int GetUserType(UserType userType)
{
switch (userType)
{
case UserType.:
return 0;
case UserType.:
return 2;
case UserType.QQ用户:
return 1;
default:
return 0;
}
}
/// <summary>
/// 删除用户黑名单
/// </summary>
/// <param name="username"></param>
/// <param name="userType"></param>
/// <param name="isCloud"></param>
/// <returns></returns>
public string RemoveUserBlack(string username, UserType userType, bool isCloud)
{
if (isCloud)
{
var res = YZCloudApiHelper.RemoveBlacklist(new List<RemoveBlacklistInput>()
{
new RemoveBlacklistInput()
{
Username = username,
Type = GetUserType( userType),
UserToken = ""
}
});
//if (!res.Ok)
//{
// return PutData("云端黑名单删除失败!" + res.Message);
//}
}
var item = Db.Queryable<UserBlack>().Where(w => w.Username == username && w.UserType == userType).First();
if (item != null)
{
item.IsDel = true;
Db.Updateable(item).ExecuteCommand();
return null;
}
return null;
}
/// <summary>
/// 新增用户黑名单
/// </summary>
/// <param name="type"></param>
/// <param name="userName"></param>
/// <param name="nickName"></param>
/// <param name="blackType"></param>
/// <param name="avatar"></param>
/// <param name="remark"></param>
/// <param name="isCloud"></param>
public string AddUserBlack(UserType type, string userName, string nickName, BlackType blackType,string avatar, string remark, bool isCloud)
{
BlacklistGroupType GetBlackType()
{
switch (blackType)
{
case BlackType.:
return BlacklistGroupType.;
case BlackType.:
return BlacklistGroupType.;
case BlackType.:
return BlacklistGroupType.;
case BlackType.:
return BlacklistGroupType.;
}
return BlacklistGroupType.;
}
//是否上传到云端
if (isCloud)
{
var res = YZCloudApiHelper.AddUserBlacklist(new List<SetBlacklistInput>()
{
new SetBlacklistInput()
{
AddDateTime = DateTime.Now,
Avatar = avatar,
GroupType=GetBlackType(),
Remark = remark,
Type = GetUserType( type),
UserToken = "",
UserName = userName,
UserNick = nickName
}
});
if (!res.Ok)
{
return "云端新增失败" + res.Message;
}
}
var item = Db.Queryable<UserBlack>().Where(w => w.Username == userName && w.UserType == type).First();
if (item != null)
{
item.NickName = nickName;
item.BlackType = blackType;
item.Remark = remark;
item.IsDel = false;//标记没有被删除
Db.Updateable(item).ExecuteCommand();
}
else
{
item = new UserBlack();
item.UserType = type;
item.Username = userName;
item.NickName = nickName;
item.BlackType = blackType;
item.Remark = remark;
item.IsDel = false;
item.IsCloud = isCloud;
item.UpdateTime = DateTime.Now;
Db.Insertable(item).ExecuteCommand();
}
return null;
}
/// <summary>
/// 新增商品黑名单
/// </summary>
/// <param name="goodsId"></param>
/// <param name="platform"></param>
/// <param name="storeName"></param>
/// <param name="remark"></param>
/// <param name="isCloud"></param>
/// <returns></returns>
public string AddGoodsBlack(string goodsId, LianmengType platform, string storeName, string remark,
bool isCloud)
{
//上传到云
void AddCloud()
{
if (!isCloud)
{
return;
}
YZCloudApiHelper.AddGoodsBlacklist(new List<SetGoodsBlacklistInput>()
{
new SetGoodsBlacklistInput()
{
AddDateTime = DateTime.Now,
GoodsId = goodsId,
Platform = LianmengTypeHelper.GetPlatform(platform),
Remark = remark,
StoreName = storeName,
UserToken = ""
}
});
}
var item = Db.Queryable<GoodsBlacklist>().Where(w => w.GoodsId == goodsId && w.Platform == platform).First();
if (item != null)
{
if (item.IsDel)
{
item.IsDel = false;//取消删除标记
item.UpdateTime = DateTime.Now;
this.Db.Updateable(item).ExecuteCommand();
AddCloud();
return null;
}
return "已经存在";
}
else
{
item = new GoodsBlacklist();
item.GoodsId = goodsId;
item.Platform = platform;
item.StoreName = storeName;
item.Remark = storeName;
item.Remark = remark;
item.IsDel = false;
item.UpdateTime = DateTime.Now;
Db.Insertable(item).ExecuteCommand();
AddCloud();
}
return null;
}
/// <summary>
/// 删除商品黑名单
/// </summary>
/// <param name="goodsId"></param>
/// <param name="platform"></param>
/// <param name="isCloud"></param>
/// <returns></returns>
public string RemoveGoodsBlack(string goodsId, LianmengType platform, bool isCloud)
{
if (isCloud)
{
var res = YZCloudApiHelper.RemoveGoodsBlacklist(new List<RemoveGoodsBlacklistInput>()
{
new RemoveGoodsBlacklistInput()
{
GoodsId = goodsId,
Platform = LianmengTypeHelper.GetPlatform(platform),
UserToken = ""
}
});
//if (res.Ok)
//{
// return PutData("云端黑名单删除失败!" + res.Message);
//}
}
var item = Db.Queryable<GoodsBlacklist>().Where(w => w.GoodsId == goodsId && w.Platform == platform).First();
if (item != null)
{
item.IsDel = true;
Db.Updateable(item).ExecuteCommand();
return null;
}
return "删除失败";
}
/// <summary>
/// 新增商店黑名单
/// </summary>
/// <param name="platform"></param>
/// <param name="storeName"></param>
/// <param name="remark"></param>
/// <param name="isCloud"></param>
/// <returns></returns>
public string AddStoreBlack(LianmengType platform, string storeId, string storeName, string remark, bool isCloud)
{
//上传到云
void AddCloud()
{
if (!isCloud)
{
return;
}
YZCloudApiHelper.AddStoreBlacklist(new List<SetStoerBlacklistInput>()
{
new SetStoerBlacklistInput()
{
AddDateTime = DateTime.Now,
Platform = LianmengTypeHelper.GetPlatform(platform),
Remark = remark,
StoreName = storeName,
StoreId = storeId,
UserToken = ""
}
});
}
var item = Db.Queryable<StoreBlacklist>().Where(w => w.StoreId == storeId && w.Platform == platform).First();
if (item != null)
{
if (item.IsDel)
{
item.StoreName = storeName;
item.IsDel = false;//取消删除标记
item.UpdateTime = DateTime.Now;
this.Db.Updateable(item).ExecuteCommand();
AddCloud();
return null;
}
return "已经存在了";
}
else
{
item = new StoreBlacklist();
item.Platform = platform;
item.StoreName = storeName;
item.StoreId = storeId;
item.Remark = storeName;
item.Remark = remark;
item.IsDel = false;
item.UpdateTime = DateTime.Now;
Db.Insertable(item).ExecuteCommand();
AddCloud();
}
return null;
}
/// <summary>
/// 删除商店黑名单
/// </summary>
/// <param name="storeId"></param>
/// <param name="platform"></param>
/// <param name="isCloud"></param>
/// <returns></returns>
public string RemoveStoreBlack(string storeId, LianmengType platform, bool isCloud)
{
if (isCloud)
{
var res = YZCloudApiHelper.RemoveStoreBlacklist(new List<RemoveStoreBlacklistInput>()
{
new RemoveStoreBlacklistInput()
{
StoreId = storeId,
Platform = LianmengTypeHelper.GetPlatform(platform),
UserToken = ""
}
});
//if (res.Ok)
//{
// return PutData("云端黑名单删除失败!" + res.Message);
//}
}
var item = Db.Queryable<StoreBlacklist>().Where(w => w.StoreName == storeId && w.Platform == platform).First();
if (item != null)
{
item.IsDel = true;
Db.Updateable(item).ExecuteCommand();
return null;
}
return "删除失败";
}
}
}