| | |
| | | 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; |
| | |
| | | private readonly ICoreCmsSolitaireServices _solitaireServices; |
| | | private readonly ICoreCmsUserShipServices _userShipServices; |
| | | private readonly ICoreCmsStoreServices _storeServices; |
| | | private readonly IBfbfComAPIService _bfbfComAPIService; |
| | | private readonly IHttpContextUser _user; |
| | | |
| | | public CoreCmsCartServices( |
| | | ICoreCmsCartRepository dal |
| | |
| | | , 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; |
| | |
| | | _solitaireServices = solitaireServices; |
| | | _userShipServices = userShipServices; |
| | | _storeServices = storeServices; |
| | | _bfbfComAPIService = bfbfComAPIService; |
| | | _user = user; |
| | | } |
| | | |
| | | #region 设置购物车商品数量==================================================== |
| | |
| | | /// <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) |
| | | { |
| | |
| | | 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; |
| | |
| | | /// <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(); |
| | | |
| | |
| | | if (products == null) |
| | | { |
| | | jm.msg = "获取货品信息失败"; |
| | | return jm; |
| | | } |
| | | if(isCustomizable==true&&products.isCustomizable!=true) |
| | | { |
| | | jm.msg = "该货物不支持定制"; |
| | | return jm; |
| | | } |
| | | //判断是否下架 |
| | |
| | | productId = productId, |
| | | nums = nums, |
| | | type = cartTypes, |
| | | objectId = objectId |
| | | objectId = objectId, |
| | | //支持定制 |
| | | isCustomizable= isCustomizable, |
| | | }; |
| | | var outId = await _dal.InsertAsync(catInfo); |
| | | jm.status = outId > 0; |
| | |
| | | /// <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(); |
| | |
| | | /// <param name="ids">已选择货号</param> |
| | | /// <param name="type">购物车类型/同订单类型</param> |
| | | /// <param name="objectId">关联非订单类型数据序列</param> |
| | | /// <param name="goodsId">goodsId</param> |
| | | /// <returns></returns> |
| | | public async Task<WebApiCallBack> GetCartDtoData(int userId, int[] ids = null, int type = 1, int objectId = 0) |
| | | public async Task<WebApiCallBack> GetCartDtoData(int userId, int[] ids = null, int type = 1, int objectId = 0, int goodsId = 0) |
| | | { |
| | | var jm = new WebApiCallBack() { methodDescription = "获取购物车原始列表(未核算)" }; |
| | | |
| | |
| | | { |
| | | carts = await _dal.QueryListByClauseAsync(p => p.userId == userId && p.type == type, p => p.id, OrderByType.Asc); |
| | | } |
| | | |
| | | if (goodsId>0) |
| | | { |
| | | var products = await _productsServices.GetProducts(goodsId); |
| | | int[] ss = products.Select(x => x.id).ToArray(); |
| | | |
| | | carts = carts.Where(p => ss.Contains(p.productId)).ToList(); |
| | | |
| | | } |
| | | |
| | | |
| | | var cartDto = new CartDto { userId = userId, type = type }; |
| | | |
| | | foreach (var item in carts) |
| | |
| | | cartProducts.type = item.type; |
| | | cartProducts.weight = goodsWeight; |
| | | cartProducts.products = productInfo; |
| | | cartProducts.isCustomizable = item.isCustomizable; |
| | | //如果传过来了购物车数据,就算指定的购物车的数据,否则,就算全部购物车的数据 |
| | | if (ids != null && ids.Any() && ids.Contains(item.id)) |
| | | { |
| | |
| | | { |
| | | 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: |
| | | //拼团模式走拼团价,去修改商品价格 |
| | |
| | | /// <param name="userShipId">用户收货地址</param> |
| | | /// <param name="objectId">关联非普通订单营销类型序列</param> |
| | | /// <returns></returns> |
| | | public async Task<WebApiCallBack> GetCartInfos(int userId, int[] ids, int orderType, int areaId, int point, string couponCode, int deliveryType = (int)GlobalEnumVars.OrderReceiptType.Logistics, int userShipId = 0, int objectId = 0) |
| | | public async Task<WebApiCallBack> GetCartInfos(int userId, int[] ids, int orderType, int areaId, int point, string couponCode, int deliveryType = (int)GlobalEnumVars.OrderReceiptType.Logistics, int userShipId = 0, int objectId = 0, int goodsId = 0) |
| | | { |
| | | var jm = new WebApiCallBack() { methodDescription = "获取处理后的购物车信息" }; |
| | | var cartDto = new CartDto(); //必须初始化 |
| | | var cartDtoData = await GetCartDtoData(userId, ids, orderType, objectId); |
| | | var cartDtoData = await GetCartDtoData(userId, ids, orderType, objectId, goodsId); |
| | | if (!cartDtoData.status) |
| | | { |
| | | jm.msg = "1"; |
| | |
| | | } |
| | | //单条商品总价 |
| | | 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) |
| | | { |