| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.order.mapper.ShoppingCartMapper; |
| | | import com.ruoyi.order.service.ShoppingCartService; |
| | | import com.ruoyi.order.vo.MyShoppingCartVo; |
| | | import com.ruoyi.other.api.domain.Goods; |
| | | import com.ruoyi.other.api.domain.GoodsArea; |
| | | import com.ruoyi.other.api.domain.GoodsShop; |
| | | import com.ruoyi.other.api.domain.GoodsVip; |
| | | import com.ruoyi.other.api.feignClient.GoodsAreaClient; |
| | | import com.ruoyi.other.api.feignClient.GoodsClient; |
| | | import com.ruoyi.other.api.feignClient.GoodsShopClient; |
| | | import com.ruoyi.other.api.feignClient.GoodsVipClient; |
| | | import com.ruoyi.order.vo.SetGoodsNumber; |
| | | import com.ruoyi.other.api.domain.*; |
| | | import com.ruoyi.other.api.feignClient.*; |
| | | import com.ruoyi.other.api.vo.GetGoodsBargainPrice; |
| | | import com.ruoyi.other.api.vo.GetSeckillActivityInfo; |
| | | import lombok.Data; |
| | | import model.ShoppingCart; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | |
| | | @Resource |
| | | private GoodsVipClient goodsVipClient; |
| | | |
| | | @Resource |
| | | private SeckillActivityInfoClient seckillActivityInfoClient; |
| | | |
| | | @Resource |
| | | private GoodsBargainPriceClient goodsBargainPriceClient; |
| | | |
| | | |
| | | |
| | |
| | | vo.setHomePicture(goods.getHomePagePicture()); |
| | | vo.setName(goods.getName()); |
| | | |
| | | GoodsArea area = new GoodsArea(); |
| | | area.setDistrictsCode(appUser.getDistrictCode()); |
| | | area.setCityCode(appUser.getCityCode()); |
| | | area.setProvinceCode(appUser.getProvinceCode()); |
| | | area.setVip(appUser.getVipId()); |
| | | GoodsArea goodsArea = goodsAreaClient.getGoodsArea(area).getData(); |
| | | if(null == goodsArea){ |
| | | GoodsVip goodsVip = goodsVipClient.getGoodsVip(appUser.getVipId()).getData(); |
| | | //获取支付价格 |
| | | Price price = getPrice(appUser, shoppingCart.getGoodsId(), shopId); |
| | | if(null == price){ |
| | | //使用商品的基础价格 |
| | | price.setCash(1 == goods.getCashPayment() ? goods.getSellingPrice() : null); |
| | | price.setPoint(1 == goods.getPointPayment() ? goods.getIntegral() : null); |
| | | } |
| | | |
| | | |
| | | vo.setSellingPrice(goods); |
| | | //构建价格展示内容 |
| | | String sellingPrice = ""; |
| | | if(null != price.getCash() && null != price.getPoint()){ |
| | | sellingPrice = price.getCash() + "或" + price.getPoint() + "积分"; |
| | | } |
| | | if(null != price.getCash() && null == price.getPoint()){ |
| | | sellingPrice = price.getCash() + ""; |
| | | } |
| | | if(null == price.getCash() && null != price.getPoint()){ |
| | | sellingPrice = price.getPoint() + "积分"; |
| | | } |
| | | vo.setSellingPrice(sellingPrice); |
| | | vo.setEndTime(price.getEndTime()); |
| | | vo.setOriginalPrice(goods.getOriginalPrice().toString()); |
| | | vo.setNumber(shoppingCart.getNumber()); |
| | | vo.setEndTime(); |
| | | GoodsShop goodsShop = new GoodsShop(); |
| | | goodsShop.setGoodsId(shoppingCart.getGoodsId()); |
| | | goodsShop.setShopId(shopId); |
| | |
| | | } |
| | | return page; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取支付价格 |
| | | * @param appUser |
| | | * @param goodsId |
| | | * @param shopId |
| | | * @return |
| | | */ |
| | | public Price getPrice(AppUser appUser, Integer goodsId, Integer shopId){ |
| | | //获取支付价格 |
| | | //秒杀活动>门店特价>地区价格>会员价格 |
| | | //判断是否有秒杀活动 |
| | | Price price = new Price(); |
| | | GetSeckillActivityInfo info = new GetSeckillActivityInfo(); |
| | | info.setGoodsId(goodsId); |
| | | info.setVip(appUser.getVipId()); |
| | | GoodsSeckill goodsSeckill = seckillActivityInfoClient.getSeckillActivityInfo(info).getData(); |
| | | if(null == goodsSeckill){ |
| | | //没有秒杀价,则判断门店特价 |
| | | GetGoodsBargainPrice goodsBargainPrice = new GetGoodsBargainPrice(); |
| | | goodsBargainPrice.setGoodsId(goodsId); |
| | | goodsBargainPrice.setVip(appUser.getVipId()); |
| | | goodsBargainPrice.setShopId(shopId); |
| | | GoodsBargainPriceDetail bargainPriceDetail = goodsBargainPriceClient.getGoodsBargainPrice(goodsBargainPrice).getData(); |
| | | if(null == bargainPriceDetail){ |
| | | //没有门店特价,判断地区价格配置 |
| | | GoodsArea area = new GoodsArea(); |
| | | area.setDistrictsCode(appUser.getDistrictCode()); |
| | | area.setCityCode(appUser.getCityCode()); |
| | | area.setProvinceCode(appUser.getProvinceCode()); |
| | | area.setVip(appUser.getVipId()); |
| | | GoodsArea goodsArea = goodsAreaClient.getGoodsArea(area).getData(); |
| | | if(null == goodsArea){ |
| | | //没有地区价格,则使用会员价格 |
| | | GoodsVip goodsVip = goodsVipClient.getGoodsVip(appUser.getVipId()).getData(); |
| | | if(null == goodsVip){ |
| | | //没有配置价格,直接使用原始基础价格 |
| | | return null; |
| | | }else{ |
| | | price.setCash(goodsVip.getSellingPrice()); |
| | | price.setPoint(goodsVip.getIntegral()); |
| | | } |
| | | }else{ |
| | | price.setCash(goodsArea.getSellingPrice()); |
| | | price.setPoint(goodsArea.getIntegral()); |
| | | } |
| | | }else{ |
| | | price.setCash(bargainPriceDetail.getSellingPrice()); |
| | | price.setPoint(bargainPriceDetail.getIntegral()); |
| | | } |
| | | }else{ |
| | | //构建价格数据 |
| | | if(goodsSeckill.getCashPayment() == 1 && goodsSeckill.getPointPayment() == 1){ |
| | | price.setCash(goodsSeckill.getSellingPrice()); |
| | | price.setPoint(goodsSeckill.getIntegral()); |
| | | } |
| | | if(goodsSeckill.getCashPayment() == 1 && goodsSeckill.getPointPayment() == 0){ |
| | | price.setCash(goodsSeckill.getSellingPrice()); |
| | | } |
| | | if(goodsSeckill.getCashPayment() == 0 && goodsSeckill.getPointPayment() == 1){ |
| | | price.setPoint(goodsSeckill.getIntegral()); |
| | | } |
| | | price.setEndTime(goodsSeckill.getEndTime()); |
| | | } |
| | | return price; |
| | | } |
| | | |
| | | |
| | | @Data |
| | | class Price { |
| | | /** |
| | | * 现金 |
| | | */ |
| | | private BigDecimal cash; |
| | | /** |
| | | * 积分 |
| | | */ |
| | | private Integer point; |
| | | /** |
| | | * 获取结束时间 |
| | | */ |
| | | private Long endTime; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void addGoods(ShoppingCart shoppingCart) { |
| | |
| | | shoppingCart.setAppUserId(userid); |
| | | this.save(shoppingCart); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改购物车数量 |
| | | * @param setGoodsNumber |
| | | * @return |
| | | */ |
| | | @Override |
| | | public AjaxResult setGoodsNumber(SetGoodsNumber setGoodsNumber) { |
| | | if(0 >= setGoodsNumber.getNumber()){ |
| | | return AjaxResult.error("修改数量不能小于等于0"); |
| | | } |
| | | ShoppingCart shoppingCart = this.getById(setGoodsNumber.getId()); |
| | | if(null != shoppingCart){ |
| | | shoppingCart.setNumber(setGoodsNumber.getNumber()); |
| | | this.updateById(shoppingCart); |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | } |