移动系统liao
2024-11-12 1cb49b04ae6709e6054c328f5ed12bff9ca014c8
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/***********************************************************************
 *            Project: baifenBinfa
 *        ProjectName: 百分兵法管理系统                               
 *                Web: http://chuanyin.com                     
 *             Author:                                        
 *              Email:                               
 *         CreateTime: 202403/02   
 *        Description: 暂无
 ***********************************************************************/
 
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.Configuration;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.Entities.Expression;
using CoreCms.Net.Model.FromBody;
using CoreCms.Net.Filter;
using CoreCms.Net.Loging;
using CoreCms.Net.IServices;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Utility.Helper;
using CoreCms.Net.Utility.Extensions;
using CoreCms.Net.Web.Admin.Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using NPOI.HSSF.UserModel;
using SqlSugar;
using CoreCms.Net.Services;
 
namespace CoreCms.Net.Web.Admin.Controllers
{
    /// <summary>
    /// 货品表
    ///</summary>
    [Description("货品表")]
    [Route("api/[controller]/[action]")]
    [ApiController]
    [RequiredErrorForAdmin]
    [Authorize(Permissions.Name)]
    public class CoreCmsProductsController : ControllerBase
    {
        private readonly IWebHostEnvironment _webHostEnvironment;
        private readonly ICoreCmsProductsServices _coreCmsProductsServices;
        private readonly ICoreCmsGoodsCategoryServices _coreCmsGoodsCategoryServices;
 
        /// <summary>
        /// 构造函数
        ///</summary>
        public CoreCmsProductsController(IWebHostEnvironment webHostEnvironment
            , ICoreCmsProductsServices coreCmsProductsServices
            , ICoreCmsGoodsCategoryServices coreCmsGoodsCategoryServices
            )
        {
            _webHostEnvironment = webHostEnvironment;
            _coreCmsProductsServices = coreCmsProductsServices;
            _coreCmsGoodsCategoryServices = coreCmsGoodsCategoryServices;
        }
 
        #region 获取列表============================================================
        // POST: Api/CoreCmsProducts/GetPageList
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("获取列表")]
        public async Task<AdminUiCallBack> GetPageList()
        {
            var jm = new AdminUiCallBack();
            var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
            var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
            var where = PredicateBuilder.True<CoreCmsProducts>();
            where = where.And(p => p.isDel == false);
 
 
            //获取排序字段
            var orderField = Request.Form["orderField"].FirstOrDefault();
 
            Expression<Func<CoreCmsProducts, object>> orderEx = orderField switch
            {
                "id" => p => p.id,
                "goodsId" => p => p.goodsId,
                "barcode" => p => p.barcode,
                "sn" => p => p.sn,
                "price" => p => p.price,
                "costprice" => p => p.costprice,
                "mktprice" => p => p.mktprice,
                "marketable" => p => p.marketable,
                "weight" => p => p.weight,
                "stock" => p => p.stock,
                "freezeStock" => p => p.freezeStock,
                "spesDesc" => p => p.spesDesc,
                "isDefalut" => p => p.isDefalut,
                "images" => p => p.images,
                "isDel" => p => p.isDel,
                _ => p => p.id
            };
 
            //设置排序方式
            var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
            var orderBy = orderDirection switch
            {
                "asc" => OrderByType.Asc,
                "desc" => OrderByType.Desc,
                _ => OrderByType.Desc
            };
            //查询筛选
 
 
            //货品条码 nvarchar
            var barcode = Request.Form["barcode"].FirstOrDefault();
            if (!string.IsNullOrEmpty(barcode))
            {
                where = where.And(p => p.barcode.Contains(barcode));
            }
            //商品编码 nvarchar
            var sn = Request.Form["sn"].FirstOrDefault();
            if (!string.IsNullOrEmpty(sn))
            {
                where = where.And(p => p.sn.Contains(sn));
            }
            //规格值 nvarchar
            var spesDesc = Request.Form["spesDesc"].FirstOrDefault();
            if (!string.IsNullOrEmpty(spesDesc))
            {
                where = where.And(p => p.spesDesc.Contains(spesDesc));
            }
            //规格值 nvarchar
            var name = Request.Form["name"].FirstOrDefault();
            if (!string.IsNullOrEmpty(name))
            {
                where = where.And(p => p.name.Contains(name));
            }
            //商品分类 decimal
            var Category = Request.Form["categoryId"].FirstOrDefault().ToInt32OrDefault();
            if (Category > 0)
            {
                where = where.And(p => p.CategoryID == Category);
            }
            //获取数据
            var list = await _coreCmsProductsServices.QueryDetailPageAsync(where, orderEx, orderBy, pageCurrent, pageSize, true);
            //返回数据
            jm.data = list;
            jm.code = 0;
            jm.count = list.TotalCount;
            jm.msg = "数据调用成功!";
            return jm;
        }
        #endregion
 
        #region 首页数据============================================================
        // POST: Api/CoreCmsProducts/GetIndex
        /// <summary>
        /// 首页数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("首页数据")]
        public async Task<AdminUiCallBack> GetIndexAsync()
        {
            //返回数据
            var jm = new AdminUiCallBack { code = 0 };
            var categories = await _coreCmsGoodsCategoryServices.QueryListByClauseAsync(p => p.isShow, p => p.sort, OrderByType.Asc, true, true);
            var categoriesTree = GoodsHelper.GetTree(categories, false);
            jm.data= categoriesTree;
            return jm;
        }
        #endregion
 
 
        #region 预览数据============================================================
        // POST: Api/CoreCmsProducts/GetDetails/10
        /// <summary>
        /// 预览数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("预览数据")]
        public async Task<AdminUiCallBack> GetDetails([FromBody] FMIntId entity)
        {
            var jm = new AdminUiCallBack();
 
            var model = await _coreCmsProductsServices.QueryByClauseAsync(p => p.id == entity.id);
            if (model == null)
            {
                jm.msg = "不存在此信息";
                return jm;
            }
            jm.code = 0;
            jm.data = model;
 
            return jm;
        }
        #endregion
 
        #region 设置库存============================================================
        // POST: Api/CoreCmsProducts/DoSetStock/10
        /// <summary>
        /// 设置库存
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("设置库存")]
        public async Task<AdminUiCallBack> DoSetStock([FromBody] FMUpdateIntegerDataByIntId entity)
        {
            var jm = await _coreCmsProductsServices.EditStock(entity.id, entity.data);
 
            return jm;
        }
        #endregion
 
 
    }
}