username@email.com
2024-10-29 a5851a4e906725b868bcfdaa8c59249523137586
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/***********************************************************************
 *            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
{
    /// <summary>
    /// 用户订阅提醒状态 接口实现
    /// </summary>
    public class CoreCmsUserWeChatMsgSubscriptionSwitchServices : BaseServices<CoreCmsUserWeChatMsgSubscriptionSwitch>, 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;
        }
 
 
 
        /// <summary>
        /// 获取用户是否订阅
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task<WebApiCallBack> IsTip(int userId)
        {
            var jm = new WebApiCallBack { data = true, otherData = false };
 
            using var container = _serviceProvider.CreateScope();
 
            var templateServices = container.ServiceProvider.GetService<ICoreCmsUserWeChatMsgTemplateServices>();
            var subscriptionServices = container.ServiceProvider.GetService<ICoreCmsUserWeChatMsgSubscriptionServices>();
 
            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;
        }
 
 
 
 
        /// <summary>
        /// 获取用户是否关闭订阅
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task<WebApiCallBack> 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;
        }
    }
}