/***********************************************************************
* Project: baifenBinfa
* ProjectName: 百分兵法管理系统
* Web: http://chuanyin.com
* Author:
* Email:
* CreateTime: 202403/02
* Description: 暂无
***********************************************************************/
using System;
using System.Threading.Tasks;
using CoreCms.Net.Configuration;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.IServices;
using CoreCms.Net.Loging;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.UI;
using Microsoft.Extensions.DependencyInjection;
namespace CoreCms.Net.Services
{
///
/// 用户订阅提醒状态 接口实现
///
public class CoreCmsUserWeChatMsgSubscriptionSwitchServices : BaseServices, ICoreCmsUserWeChatMsgSubscriptionSwitchServices
{
private readonly ICoreCmsUserWeChatMsgSubscriptionSwitchRepository _dal;
private readonly IServiceProvider _serviceProvider;
private readonly IUnitOfWork _unitOfWork;
public CoreCmsUserWeChatMsgSubscriptionSwitchServices(IUnitOfWork unitOfWork, ICoreCmsUserWeChatMsgSubscriptionSwitchRepository dal, IServiceProvider serviceProvider)
{
this._dal = dal;
_serviceProvider = serviceProvider;
base.BaseDal = dal;
_unitOfWork = unitOfWork;
}
///
/// 获取用户是否订阅
///
///
///
public async Task IsTip(int userId)
{
var jm = new WebApiCallBack { data = true, otherData = false };
using var container = _serviceProvider.CreateScope();
var templateServices = container.ServiceProvider.GetService();
var subscriptionServices = container.ServiceProvider.GetService();
var setting = await templateServices.QueryAsync();
var flag = false;
foreach (var item in setting)
{
if (!string.IsNullOrEmpty(item.templateId))
{
flag = true;
jm.otherData = true;
break;
}
}
if (flag)
{
var res = await _dal.QueryByClauseAsync(p => p.userId == userId);
if (res != null)
{
if (res.isSwitch) jm.data = false;
}
else
{
var count = await subscriptionServices.GetCountAsync(p => p.userId == userId);
if (count == setting.Count) jm.data = false;
}
}
else
{
jm.data = false;
}
jm.status = true;
jm.msg = "获取成功";
return jm;
}
///
/// 获取用户是否关闭订阅
///
///
///
public async Task CloseTip(int userId)
{
var jm = new WebApiCallBack();
var res = await _dal.QueryByClauseAsync(p => p.userId == userId);
if (res != null)
{
await _dal.UpdateAsync(
p => new CoreCmsUserWeChatMsgSubscriptionSwitch() { isSwitch = true },
p => p.userId == userId);
}
else
{
var st = new CoreCmsUserWeChatMsgSubscriptionSwitch();
st.isSwitch = true;
st.userId = userId;
await _dal.InsertAsync(st);
}
jm.status = true;
jm.msg = "关闭成功";
jm.otherData = true; //是否关闭订阅
return jm;
}
}
}