移动系统liao
2024-11-12 1cb49b04ae6709e6054c328f5ed12bff9ca014c8
CoreCms.Net.Web.WebApi/Controllers/GoodController.cs
@@ -1,10 +1,9 @@
/***********************************************************************
 *            Project: CoreCms
 *        ProjectName: 核心内容管理系统
 *                Web: https://www.corecms.net
 *             Author: 大灰灰
 *              Email: jianweie@163.com
 *         CreateTime: 2021/1/31 21:45:10
/***********************************************************************
 *        ProjectName: 百分兵法管理系统
 *                Web: http://chuanyin.com
 *             Author:
 *              Email:
 *         CreateTime: 202403/02
 *        Description: 暂无
 ***********************************************************************/
@@ -20,11 +19,13 @@
using CoreCms.Net.Configuration;
using CoreCms.Net.DTO.ComponentsDTO;
using CoreCms.Net.IServices;
using CoreCms.Net.IServices.baifenbingfa;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.Entities.Expression;
using CoreCms.Net.Model.FromBody;
using CoreCms.Net.Model.ViewModels.DTO;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Services.Basic;
using CoreCms.Net.Utility.Extensions;
using CoreCms.Net.Utility.Helper;
using Microsoft.AspNetCore.Authorization;
@@ -33,6 +34,8 @@
using Newtonsoft.Json;
using NPOI.SS.Formula.Functions;
using SqlSugar;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.ChannelsECMerchantAddFreightTemplateRequest.Types.FreightTemplate.Types;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.ComponentTCBBatchCreateContainerServiceVersionRequest.Types;
namespace CoreCms.Net.Web.WebApi.Controllers
{
@@ -60,6 +63,8 @@
        private ICoreCmsAgentProductsServices _agentProductsServices;
        private ICoreCmsAgentGradeServices _agentGradeServices;
        private ICoreCmsGoodsCategoryExtendServices _goodsCategoryExtendServices;
        private readonly ICoreCmsAreaServices _coreCmsAreaServices;
        private readonly IBfbfComAPIService _bfbfComAPIService;
        /// <summary>
        /// 构造函数
@@ -76,7 +81,14 @@
            , ICoreCmsGoodsParamsServices goodsParamsServices
            , ICoreCmsGoodsCollectionServices goodsCollectionServices
            , ICoreCmsUserServices userServices
            , ICoreCmsAgentServices agentServices, ICoreCmsAgentProductsServices agentProductsServices, ICoreCmsAgentGradeServices agentGradeServices, ICoreCmsGoodsCategoryExtendServices goodsCategoryExtendServices)
            , ICoreCmsAgentServices agentServices,
            ICoreCmsAgentProductsServices agentProductsServices,
            ICoreCmsAgentGradeServices agentGradeServices,
            ICoreCmsGoodsCategoryExtendServices goodsCategoryExtendServices,
            ICoreCmsAreaServices areaServices,
            IBfbfComAPIService bfbfComAPIService
            )
        {
            _mapper = mapper;
            _user = user;
@@ -94,6 +106,8 @@
            _agentProductsServices = agentProductsServices;
            _agentGradeServices = agentGradeServices;
            _goodsCategoryExtendServices = goodsCategoryExtendServices;
            _coreCmsAreaServices = areaServices;
            _bfbfComAPIService = bfbfComAPIService;
        }
        //公共接口====================================================================================================
@@ -133,7 +147,7 @@
                parentTree.imageUrl = !string.IsNullOrEmpty(item.imageUrl) ? item.imageUrl : "/static/images/common/empty.png";
                parentTree.name = item.name;
                parentTree.sort = item.sort;
               parentTree.key=item.key;
                childTree.Add(parentTree);
                parentTree.child = GetCategories(oldCategories, item.id);
@@ -155,6 +169,13 @@
            var jm = new WebApiCallBack();
            var where = PredicateBuilder.True<GoodListDTO>();
            //是否是经销商
            bool isDic = false;
            if (_user.ID > 0)
            {
                isDic = await _bfbfComAPIService.IsDictionary(_user.ID);
            };
            var className = string.Empty;
            if (!string.IsNullOrWhiteSpace(entity.where))
@@ -167,6 +188,8 @@
                    brandId = "",
                    labelId = "",
                    searchName = "",
                    areaCode=""
                });
                if (!string.IsNullOrWhiteSpace(obj.priceFrom))
@@ -241,13 +264,35 @@
                {
                    where = where.And(p => p.name.Contains(obj.searchName));
                }
                if (!string.IsNullOrWhiteSpace(obj.areaCode))
                {
                    where = where.And(p => p.areaCode.Contains(obj.areaCode));
                }
            }
            //获取数据
            var list = await _goodsServices.QueryPageByDTOAsync(where, entity.page, entity.limit, true);
            //获取品牌
            var brands = await _brandServices.QueryListByClauseAsync(p => p.isShow == true, p => p.sort, OrderByType.Desc, true, true);
            foreach (var item in list)
            {
                var codelist = item.areaCode?.Split(",");
                item.area = "";
                if(codelist!=null)
                foreach (var code in codelist)
                {
                    item.area+= (await _coreCmsAreaServices.GetAreaString(code)+"");
                }
                //调整经销商价格 百分兵法
                if(isDic)
                {
                    item.price = item.distributionPrice;
                }
            }
            //返回数据
            jm.status = true;
            jm.data = new
@@ -278,13 +323,19 @@
        {
            var jm = new WebApiCallBack();
            var model = await _goodsServices.GetGoodsDetail(entity.id, 0, false, "goods", 0, entity.data.ObjectToBool());
            CoreCmsGoods model = await _goodsServices.GetGoodsDetail(entity.id, 0, false, "goods", 0, entity.data.ObjectToBool());
            if (model == null)
            {
                jm.msg = "商品获取失败";
                return jm;
            }
            var codelist= model.areaCode.Split(",");
            model.area = "";
            foreach (var item in codelist)
            {
                model.area += (await _coreCmsAreaServices.GetAreaString(item) + "");
            }
            jm.status = true;
            jm.msg = "获取商品详情成功";
            jm.data = model;
@@ -574,13 +625,25 @@
            }
            var model = await _goodsServices.GetGoodsDetail(entity.id, userId, false, "goods", 0, entity.data.ObjectToBool());
            if (model == null)
            {
                jm.msg = "商品获取失败";
                return jm;
            }
            if (await _bfbfComAPIService.IsDictionary(user.id))
            {
                //百分兵法经销商
                model.product.price = model.product.distributionPrice;
            }
            var codelist = model.areaCode?.Split(",");
            model.area = "";
            if(codelist!=null)
            foreach (var item in codelist)
            {
                model.area += (await _coreCmsAreaServices.GetAreaString(item) + "");
            }
            var userAgent = await _agentServices.QueryByClauseAsync(p => p.userId == user.id);
            var agentProducts = new List<CoreCmsAgentProducts>();
            var userAgentGrade = new CoreCmsAgentGrade();