From 06f455915bb9d11caa8829942f9007809ee9ae3d Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期四, 28 十一月 2024 16:37:45 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java |  229 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 229 insertions(+), 0 deletions(-)

diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java
new file mode 100644
index 0000000..1f254ea
--- /dev/null
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java
@@ -0,0 +1,229 @@
+package com.ruoyi.order.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+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.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
+public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements ShoppingCartService {
+	
+	@Resource
+	private TokenService tokenService;
+	
+	@Resource
+	private GoodsClient goodsClient;
+	
+	@Resource
+	private GoodsShopClient goodsShopClient;
+	
+	@Resource
+	private AppUserClient appUserClient;
+	
+	@Resource
+	private GoodsAreaClient goodsAreaClient;
+	
+	@Resource
+	private GoodsVipClient goodsVipClient;
+	
+	@Resource
+	private SeckillActivityInfoClient seckillActivityInfoClient;
+	
+	@Resource
+	private GoodsBargainPriceClient goodsBargainPriceClient;
+	
+	
+	
+	
+	
+	
+	/**
+	 * 获取购物车列表
+	 * @param type
+	 * @param shopId
+	 * @return
+	 */
+	@Override
+	public List<MyShoppingCartVo> getMyShoppingCart(Integer type, Integer shopId) {
+		Long userid = tokenService.getLoginUserApplet().getUserid();
+		AppUser appUser = appUserClient.getAppUserById(userid);
+		//获取对应类型的商品数据
+		List<Goods> data = goodsClient.getGoodsByType(type).getData();
+		if(null == data){
+			throw new RuntimeException("根据类型(1=服务商品,2=单品商品)获取商品数据失败");
+		}
+		List<Long> goodsIds = data.stream().map(Goods::getId).collect(Collectors.toList());
+		//查询符合商品类型的商品数据
+		List<ShoppingCart> list = this.list(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid).in(ShoppingCart::getGoodsId, goodsIds));
+		List<MyShoppingCartVo> page = new ArrayList<>();
+		//构建返回数据
+		for (ShoppingCart shoppingCart : list) {
+			Goods goods = data.stream().filter(s -> s.getId().equals(shoppingCart.getGoodsId())).findFirst().get();
+			MyShoppingCartVo vo = new MyShoppingCartVo();
+			vo.setId(shoppingCart.getId());
+			vo.setHomePicture(goods.getHomePagePicture());
+			vo.setName(goods.getName());
+			
+			//获取支付价格
+			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);
+			}
+			//构建价格展示内容
+			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());
+			GoodsShop goodsShop = new GoodsShop();
+			goodsShop.setGoodsId(shoppingCart.getGoodsId());
+			goodsShop.setShopId(shopId);
+			GoodsShop goodsShop1 = goodsShopClient.getGoodsShop(goodsShop).getData();
+			vo.setVerifiable(null == goodsShop1 ? false : true);
+			page.add(vo);
+		}
+		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) {
+		Long userid = tokenService.getLoginUserApplet().getUserid();
+		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();
+	}
+}

--
Gitblit v1.7.1