移动系统liao
2024-05-29 71e821ab5e6b3014fac9b691d6957bcc09704b70
CoreCms.Net.Services/Cart/CoreCmsCartServices.cs
@@ -12,10 +12,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CoreCms.Net.Auth.HttpContextUser;
using CoreCms.Net.Configuration;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.IServices;
using CoreCms.Net.IServices.baifenbingfa;
using CoreCms.Net.Loging;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.Entities.Expression;
@@ -57,6 +59,8 @@
        private readonly ICoreCmsSolitaireServices _solitaireServices;
        private readonly ICoreCmsUserShipServices _userShipServices;
        private readonly ICoreCmsStoreServices _storeServices;
        private readonly IBfbfComAPIService  _bfbfComAPIService;
        private readonly IHttpContextUser _user;
        public CoreCmsCartServices(
            ICoreCmsCartRepository dal
@@ -69,7 +73,17 @@
            , ICoreCmsUserServices userServices
            , ICoreCmsSettingServices settingServices
            , ICoreCmsProductsServices productsServices
            , ICoreCmsPinTuanGoodsServices pinTuanGoodsServices, ICoreCmsPromotionConditionServices promotionConditionServices, ICoreCmsGoodsServices goodsServices, ICoreCmsGoodsCategoryServices goodsCategoryServices, ICoreCmsPromotionResultServices promotionResultServices, ICoreCmsPinTuanRecordServices pinTuanRecordServices, ICoreCmsSolitaireServices solitaireServices, ICoreCmsUserShipServices userShipServices, ICoreCmsStoreServices storeServices)
            , ICoreCmsPinTuanGoodsServices pinTuanGoodsServices
            , IBfbfComAPIService bfbfComAPIService
            ,ICoreCmsPromotionConditionServices promotionConditionServices
            , ICoreCmsGoodsServices goodsServices
            , ICoreCmsGoodsCategoryServices goodsCategoryServices
            , ICoreCmsPromotionResultServices promotionResultServices
            , ICoreCmsPinTuanRecordServices pinTuanRecordServices
            , ICoreCmsSolitaireServices solitaireServices
            , ICoreCmsUserShipServices userShipServices
            , ICoreCmsStoreServices storeServices
            ,IHttpContextUser user)
        {
            this._dal = dal;
            base.BaseDal = dal;
@@ -92,6 +106,8 @@
            _solitaireServices = solitaireServices;
            _userShipServices = userShipServices;
            _storeServices = storeServices;
            _bfbfComAPIService = bfbfComAPIService;
            _user   = user;
        }
        #region 设置购物车商品数量====================================================
@@ -104,6 +120,7 @@
        /// <param name="userId"></param>
        /// <param name="numType"></param>
        /// <param name="type"></param>
        ///  <param name="isCustomizable"></param>
        /// <returns></returns>
        public async Task<WebApiCallBack> SetCartNum(int id, int nums, int userId, int numType, int type = 1)
        {
@@ -129,7 +146,7 @@
                jm.msg = "获取购物车数据失败";
                return jm;
            }
            var outData = await Add(userId, cartModel.productId, nums, numType, type);
            var outData = await Add(userId, cartModel.productId, nums, numType, type,isCustomizable:cartModel.isCustomizable);
            jm.status = outData.status;
            jm.msg = jm.status ? GlobalConstVars.SetDataSuccess : GlobalConstVars.SetDataFailure;
            jm.otherData = outData;
@@ -179,8 +196,9 @@
        /// <param name="numType">数量类型/1是直接增加/2是赋值</param>
        /// <param name="cartTypes">1普通购物还是2团购秒杀3团购模式4秒杀模式6砍价模式7赠品</param>
        /// <param name="objectId">关联对象类型</param>
        /// <param name="isCustomizable">关联对象类型</param>
        /// <returns></returns>
        public async Task<WebApiCallBack> Add(int userId, int productId, int nums, int numType, int cartTypes = 1, int objectId = 0)
        public async Task<WebApiCallBack> Add(int userId, int productId, int nums, int numType, int cartTypes = 1, int objectId = 0,bool isCustomizable = false)
        {
            var jm = new WebApiCallBack();
@@ -206,6 +224,11 @@
            if (products == null)
            {
                jm.msg = "获取货品信息失败";
                return jm;
            }
            if(isCustomizable==true&&products.isCustomizable!=true)
            {
                jm.msg = "该货物不支持定制";
                return jm;
            }
            //判断是否下架
@@ -298,7 +321,9 @@
                    productId = productId,
                    nums = nums,
                    type = cartTypes,
                    objectId = objectId
                    objectId = objectId,
                    //支持定制
                    isCustomizable= isCustomizable,
                };
                var outId = await _dal.InsertAsync(catInfo);
                jm.status = outId > 0;
@@ -338,6 +363,7 @@
        /// <param name="userId">用户序列</param>
        /// <param name="nums">加入购物车数量</param>
        /// <param name="ruleId">规则序列</param>
        ///  <param name="ruleId">货品是否定制</param>
        public async Task<WebApiCallBack> AddCartHavePinTuan(int productId, int userId = 0, int nums = 1, int ruleId = 0)
        {
            var jm = new WebApiCallBack();
@@ -496,6 +522,7 @@
                cartProducts.type = item.type;
                cartProducts.weight = goodsWeight;
                cartProducts.products = productInfo;
                cartProducts.isCustomizable = item.isCustomizable;
                //如果传过来了购物车数据,就算指定的购物车的数据,否则,就算全部购物车的数据
                if (ids != null && ids.Any() && ids.Contains(item.id))
                {
@@ -515,6 +542,16 @@
            {
                case (int)GlobalEnumVars.OrderType.Common:
                    //标准模式不需要修改订单数据和商品数据
                    {
                        if(await _bfbfComAPIService.IsDictionary(_user.ID))
                        {
                            foreach (var item in cartDto.list)
                            {
                                item.products.price=item.products.distributionPrice;
                            }
                        }
                    }
                    break;
                case (int)GlobalEnumVars.OrderType.PinTuan:
                    //拼团模式走拼团价,去修改商品价格
@@ -605,6 +642,13 @@
                }
                //单条商品总价
                item.products.amount = Math.Round(item.nums * (decimal)item.products.price, 2);
                //定制商品添加定制价格
                if (item.isCustomizable)
                //是定制商品
                {
                    item.products.amount += _bfbfComAPIService.CommandCustomizable(item.nums);
                    item.CustomizableMoney = _bfbfComAPIService.CommandCustomizable(item.nums);
                }
                if (item.isSelect)
                {