username@email.com
2024-09-09 e8fd9aa8a76c638991e60544ccab53e2e5bd5b6a
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
/***********************************************************************
 *            Project: baifenBinfa
 *        ProjectName: 百分兵法管理系统                               
 *                Web: http://chuanyin.com                     
 *             Author:                                        
 *              Email:                               
 *         CreateTime: 202403/02   
 *        Description: 暂无
 ***********************************************************************/
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CoreCms.Net.Auth.HttpContextUser;
using CoreCms.Net.Configuration;
using CoreCms.Net.IServices;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.FromBody;
using CoreCms.Net.Model.ViewModels.UI;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
 
namespace CoreCms.Net.Web.WebApi.Controllers
{
    /// <summary>
    /// 广告api控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AdvertController : ControllerBase
    {
 
        private IHttpContextUser _user;
        private readonly ICoreCmsArticleServices _articleServices;
        private readonly ICoreCmsAdvertPositionServices _advertPositionServices;
        private readonly ICoreCmsAdvertisementServices _advertisementServices;
 
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="user"></param>
        /// <param name="articleServices"></param>
        /// <param name="advertPositionServices"></param>
        /// <param name="advertisementServices"></param>
        public AdvertController(IHttpContextUser user
            , ICoreCmsArticleServices articleServices
            , ICoreCmsAdvertPositionServices advertPositionServices
            , ICoreCmsAdvertisementServices advertisementServices
            )
        {
            _user = user;
            _articleServices = articleServices;
            _advertPositionServices = advertPositionServices;
            _advertisementServices = advertisementServices;
        }
 
        #region 获取广告列表=============================================================================
        /// <summary>
        /// 获取广告列表
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> GetAdvertList([FromBody] FMPageByIntId entity)
        {
            var jm = new WebApiCallBack();
 
            var list = await _advertisementServices.QueryPageAsync(p => p.code == entity.where, p => p.createTime, OrderByType.Desc,
                entity.page, entity.limit);
            jm.status = true;
            jm.data = list;
 
            return jm;
 
        }
        #endregion
 
        #region 获取广告位置信息=============================================================================
        /// <summary>
        /// 获取广告位置信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> GetPositionList([FromBody] WxAdvert entity)
        {
            var jm = new WebApiCallBack();
 
            var position = await _advertPositionServices.QueryByClauseAsync(p => p.isEnable && p.code == entity.code && p.platform == entity.platform);
            if (position == null)
            {
                jm.msg = "未获取到广告位置信息";
                return jm;
            }
 
            jm.status = true;
            jm.data = new
            {
                position,
                childs = await _advertisementServices.QueryListByClauseAsync(p => p.positionId == position.id, p => p.sort, OrderByType.Desc, true)
            };
 
            return jm;
        }
        #endregion
 
    }
}