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 { /// /// 黑名单服务 /// 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; } } /// /// 删除用户黑名单 /// /// /// /// /// public string RemoveUserBlack(string username, UserType userType, bool isCloud) { if (isCloud) { var res = YZCloudApiHelper.RemoveBlacklist(new List() { new RemoveBlacklistInput() { Username = username, Type = GetUserType( userType), UserToken = "" } }); //if (!res.Ok) //{ // return PutData("云端黑名单删除失败!" + res.Message); //} } var item = Db.Queryable().Where(w => w.Username == username && w.UserType == userType).First(); if (item != null) { item.IsDel = true; Db.Updateable(item).ExecuteCommand(); return null; } return null; } /// /// 新增用户黑名单 /// /// /// /// /// /// /// /// 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() { 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().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; } /// /// 新增商品黑名单 /// /// /// /// /// /// /// public string AddGoodsBlack(string goodsId, LianmengType platform, string storeName, string remark, bool isCloud) { //上传到云 void AddCloud() { if (!isCloud) { return; } YZCloudApiHelper.AddGoodsBlacklist(new List() { new SetGoodsBlacklistInput() { AddDateTime = DateTime.Now, GoodsId = goodsId, Platform = LianmengTypeHelper.GetPlatform(platform), Remark = remark, StoreName = storeName, UserToken = "" } }); } var item = Db.Queryable().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; } /// /// 删除商品黑名单 /// /// /// /// /// public string RemoveGoodsBlack(string goodsId, LianmengType platform, bool isCloud) { if (isCloud) { var res = YZCloudApiHelper.RemoveGoodsBlacklist(new List() { new RemoveGoodsBlacklistInput() { GoodsId = goodsId, Platform = LianmengTypeHelper.GetPlatform(platform), UserToken = "" } }); //if (res.Ok) //{ // return PutData("云端黑名单删除失败!" + res.Message); //} } var item = Db.Queryable().Where(w => w.GoodsId == goodsId && w.Platform == platform).First(); if (item != null) { item.IsDel = true; Db.Updateable(item).ExecuteCommand(); return null; } return "删除失败"; } /// /// 新增商店黑名单 /// /// /// /// /// /// public string AddStoreBlack(LianmengType platform, string storeId, string storeName, string remark, bool isCloud) { //上传到云 void AddCloud() { if (!isCloud) { return; } YZCloudApiHelper.AddStoreBlacklist(new List() { new SetStoerBlacklistInput() { AddDateTime = DateTime.Now, Platform = LianmengTypeHelper.GetPlatform(platform), Remark = remark, StoreName = storeName, StoreId = storeId, UserToken = "" } }); } var item = Db.Queryable().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; } /// /// 删除商店黑名单 /// /// /// /// /// public string RemoveStoreBlack(string storeId, LianmengType platform, bool isCloud) { if (isCloud) { var res = YZCloudApiHelper.RemoveStoreBlacklist(new List() { new RemoveStoreBlacklistInput() { StoreId = storeId, Platform = LianmengTypeHelper.GetPlatform(platform), UserToken = "" } }); //if (res.Ok) //{ // return PutData("云端黑名单删除失败!" + res.Message); //} } var item = Db.Queryable().Where(w => w.StoreName == storeId && w.Platform == platform).First(); if (item != null) { item.IsDel = true; Db.Updateable(item).ExecuteCommand(); return null; } return "删除失败"; } } }