From 2c44da15d2ed01cefdc0d9e12497ebbd0ef2c8f9 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期二, 14 一月 2025 11:22:33 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java | 1207 ++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 898 insertions(+), 309 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
index dbb718c..307c92a 100644
--- 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
@@ -6,10 +6,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.account.api.feignClient.*;
-import com.ruoyi.account.api.model.AppUser;
-import com.ruoyi.account.api.model.BalanceChangeRecord;
-import com.ruoyi.account.api.model.UserAddress;
-import com.ruoyi.account.api.model.UserPoint;
+import com.ruoyi.account.api.model.*;
import com.ruoyi.account.api.vo.CouponInfoVo;
import com.ruoyi.account.api.vo.PaymentUserCoupon;
import com.ruoyi.account.api.vo.PaymentUserCouponVo;
@@ -18,18 +15,22 @@
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.mapper.ShoppingCartMapper;
import com.ruoyi.order.model.Order;
+import com.ruoyi.order.model.OrderBalancePayment;
import com.ruoyi.order.model.OrderGood;
import com.ruoyi.order.model.ShoppingCart;
-import com.ruoyi.order.service.OrderGoodService;
-import com.ruoyi.order.service.OrderService;
-import com.ruoyi.order.service.ShoppingCartService;
+import com.ruoyi.order.service.*;
+import com.ruoyi.order.util.payment.PaymentUtil;
+import com.ruoyi.order.util.payment.model.CloseOrderResult;
+import com.ruoyi.order.util.payment.model.UniPayCallbackResult;
+import com.ruoyi.order.util.payment.model.UniPayResult;
import com.ruoyi.order.vo.*;
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.GetGoodsShopByGoodsIds;
import com.ruoyi.other.api.vo.GetSeckillActivityInfo;
-import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -37,66 +38,87 @@
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
+import java.time.ZoneOffset;
import java.util.*;
import java.util.stream.Collectors;
+@Slf4j
@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;
-
+
@Resource
private OrderService orderService;
-
+
@Resource
private OrderGoodService orderGoodService;
-
+
@Resource
private ShopClient shopClient;
-
+
@Resource
private OrderActivityInfoClient orderActivityInfoClient;
-
+
@Resource
private BaseSettingClient baseSettingClient;
-
+
@Resource
private UserAddressClient userAddressClient;
-
+
@Resource
private UserCouponClient userCouponClient;
-
+
@Resource
private SystemConfigClient systemConfigClient;
-
+
@Resource
private UserPointClient userPointClient;
-
+
@Resource
private BalanceChangeRecordClient balanceChangeRecordClient;
+
+ @Resource
+ private CommissionService commissionService;
+
+ @Resource
+ private VipSettingClient vipSettingClient;
+
+ @Resource
+ private UserChangeLogClient userChangeLogClient;
+
+ @Resource
+ private PointSettingClient pointSettingClient;
+
+ @Resource
+ private OrderBalancePaymentService orderBalancePaymentService;
+
+ @Resource
+ private RedisTemplate redisTemplate;
+
+
@@ -120,13 +142,37 @@
}
List<Integer> 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<ShoppingCart> list = this.list(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid)
+ .in(ShoppingCart::getGoodsId, goodsIds).eq(ShoppingCart::getStatus, 1));
+ //删除过期的秒杀活动商品
+ List<ShoppingCart> list1 = new ArrayList<>();
+ for (ShoppingCart shoppingCart : list) {
+ if(shoppingCart.getType() == 2){
+ GetSeckillActivityInfo info = new GetSeckillActivityInfo();
+ info.setGoodsId(shoppingCart.getGoodsId());
+ info.setVip(appUser.getVipId());
+ GoodsSeckill data1 = seckillActivityInfoClient.getSeckillActivityInfo(info).getData();
+ if(null != data1){
+ SeckillActivityInfo seckillActivityInfo = seckillActivityInfoClient.getSeckillActivityInfoById(data1.getSeckillActivityInfoId()).getData();
+ if(null != seckillActivityInfo && (seckillActivityInfo.getIsShelves() == 1 &&
+ seckillActivityInfo.getStartTime().isBefore(LocalDateTime.now()) && seckillActivityInfo.getEndTime().isAfter(LocalDateTime.now()))){
+
+ list1.add(shoppingCart);
+ continue;
+ }
+ }
+ this.removeById(shoppingCart.getId());
+ }else{
+ list1.add(shoppingCart);
+ }
+ }
+
//构建返回数据
- List<MyShoppingCartVo> page = buildDetail(appUser, shopId, list, null);
+ List<MyShoppingCartVo> page = buildDetail(appUser, shopId, list1, null);
return page;
}
-
-
+
+
/**
* 获取支付价格
* @param appUser
@@ -134,7 +180,7 @@
* @param shopId
* @return
*/
- public Price getPrice(AppUser appUser, Integer goodsId, Integer shopId){
+ public Price getPrice(AppUser appUser, Integer goodsId, Integer type, Integer shopId){
//获取支付价格
//秒杀活动>门店特价>地区价格>会员价格
//判断是否有秒杀活动
@@ -143,13 +189,17 @@
info.setGoodsId(goodsId);
info.setVip(appUser.getVipId());
GoodsSeckill goodsSeckill = seckillActivityInfoClient.getSeckillActivityInfo(info).getData();
- if(null == goodsSeckill){
+ //没有秒杀活动或者添加的普通商品则不使用秒杀活动价格
+ if(null == goodsSeckill || type == 1){
//没有秒杀价,则判断门店特价
GetGoodsBargainPrice goodsBargainPrice = new GetGoodsBargainPrice();
goodsBargainPrice.setGoodsId(goodsId);
goodsBargainPrice.setVip(appUser.getVipId());
- goodsBargainPrice.setShopId(shopId);
- GoodsBargainPriceDetail bargainPriceDetail = goodsBargainPriceClient.getGoodsBargainPrice(goodsBargainPrice).getData();
+ GoodsBargainPriceDetail bargainPriceDetail = null;
+ if (shopId != null){
+ goodsBargainPrice.setShopId(shopId);
+ bargainPriceDetail = goodsBargainPriceClient.getGoodsBargainPrice(goodsBargainPrice).getData();
+ }
if(null == bargainPriceDetail){
//没有门店特价,判断地区价格配置
GoodsArea area = new GoodsArea();
@@ -157,22 +207,24 @@
area.setCityCode(appUser.getCityCode());
area.setProvinceCode(appUser.getProvinceCode());
area.setVip(appUser.getVipId());
+ area.setGoodsId(goodsId);
GoodsArea goodsArea = goodsAreaClient.getGoodsArea(area).getData();
if(null == goodsArea){
//没有地区价格,则使用会员价格
- GoodsVip goodsVip = goodsVipClient.getGoodsVip(appUser.getVipId()).getData();
+ GoodsVip goodsVip = goodsVipClient.getGoodsVip(goodsId, appUser.getVipId()).getData();
if(null == goodsVip){
//没有配置价格,直接使用原始基础价格
return null;
}else{
price.setCash(goodsVip.getSellingPrice());
price.setPoint(goodsVip.getIntegral());
- price.setCashPayment(goodsVip.getCashPayment() == 1 ? true : false);
- price.setPointPayment(goodsVip.getPointPayment() == 1 ? true : false);
+ price.setCashPayment(goodsVip.getCashPayment() == 1);
+ price.setPointPayment(goodsVip.getPointPayment() == 1);
price.setEarnSpendingPoints(goodsVip.getEarnSpendingPoints());
price.setSuperiorSubcommission(goodsVip.getSuperiorSubcommission());
price.setSuperiorRebatePoints(goodsVip.getSuperiorRebatePoints());
price.setSuperiorType(goodsVip.getSuperiorType());
+ price.setSuperiorPriceType(goodsVip.getSuperiorPriceType());
price.setServuceShopCharges(goodsVip.getServuceShopCharges());
price.setServuceShopPoints(goodsVip.getServuceShopPoints());
price.setTechnicianPoints(goodsVip.getTechnicianPoints());
@@ -184,12 +236,13 @@
}else{
price.setCash(goodsArea.getSellingPrice());
price.setPoint(goodsArea.getIntegral());
- price.setCashPayment(goodsArea.getCashPayment() == 1 ? true : false);
- price.setPointPayment(goodsArea.getPointPayment() == 1 ? true : false);
+ price.setCashPayment(goodsArea.getCashPayment() == 1);
+ price.setPointPayment(goodsArea.getPointPayment() == 1);
price.setEarnSpendingPoints(goodsArea.getEarnSpendingPoints());
price.setSuperiorSubcommission(goodsArea.getSuperiorSubcommission());
price.setSuperiorRebatePoints(goodsArea.getSuperiorRebatePoints());
price.setSuperiorType(goodsArea.getSuperiorType());
+ price.setSuperiorPriceType(goodsArea.getSuperiorPriceType());
price.setServuceShopCharges(goodsArea.getServuceShopCharges());
price.setServuceShopPoints(goodsArea.getServuceShopPoints());
price.setTechnicianPoints(goodsArea.getTechnicianPoints());
@@ -201,8 +254,8 @@
}else{
price.setCash(bargainPriceDetail.getSellingPrice());
price.setPoint(bargainPriceDetail.getIntegral());
- price.setCashPayment(bargainPriceDetail.getSellingPrice() != null ? true : false);
- price.setPointPayment(bargainPriceDetail.getIntegral() != null ? true : false);
+ price.setCashPayment(bargainPriceDetail.getSellingPrice() != null);
+ price.setPointPayment(bargainPriceDetail.getIntegral() != null);
//门店特价,消费积分使用会员等级的消费积分
GoodsArea area = new GoodsArea();
area.setDistrictsCode(appUser.getDistrictCode());
@@ -210,17 +263,34 @@
area.setProvinceCode(appUser.getProvinceCode());
area.setVip(appUser.getVipId());
GoodsArea goodsArea = goodsAreaClient.getGoodsArea(area).getData();
- price.setEarnSpendingPoints(goodsArea.getEarnSpendingPoints());
- price.setSuperiorSubcommission(goodsArea.getSuperiorSubcommission());
- price.setSuperiorRebatePoints(goodsArea.getSuperiorRebatePoints());
- price.setSuperiorType(goodsArea.getSuperiorType());
- price.setServuceShopCharges(goodsArea.getServuceShopCharges());
- price.setServuceShopPoints(goodsArea.getServuceShopPoints());
- price.setTechnicianPoints(goodsArea.getTechnicianPoints());
- price.setBoundShopCharges(goodsArea.getBoundShopCharges());
- price.setBoundShopPoints(goodsArea.getBoundShopPoints());
- price.setBoundShopSuperiorsCharges(goodsArea.getBoundShopSuperiorsCharges());
- price.setBoundShopSuperiorsPoints(goodsArea.getBoundShopSuperiorsPoints());
+ if(null != goodsArea){
+ price.setEarnSpendingPoints(goodsArea.getEarnSpendingPoints());
+ price.setSuperiorSubcommission(goodsArea.getSuperiorSubcommission());
+ price.setSuperiorRebatePoints(goodsArea.getSuperiorRebatePoints());
+ price.setSuperiorType(goodsArea.getSuperiorType());
+ price.setSuperiorPriceType(goodsArea.getSuperiorPriceType());
+ price.setServuceShopCharges(goodsArea.getServuceShopCharges());
+ price.setServuceShopPoints(goodsArea.getServuceShopPoints());
+ price.setTechnicianPoints(goodsArea.getTechnicianPoints());
+ price.setBoundShopCharges(goodsArea.getBoundShopCharges());
+ price.setBoundShopPoints(goodsArea.getBoundShopPoints());
+ price.setBoundShopSuperiorsCharges(goodsArea.getBoundShopSuperiorsCharges());
+ price.setBoundShopSuperiorsPoints(goodsArea.getBoundShopSuperiorsPoints());
+ }else{
+ GoodsVip goodsVip = goodsVipClient.getGoodsVip(goodsId, appUser.getVipId()).getData();
+ price.setEarnSpendingPoints(goodsVip.getEarnSpendingPoints());
+ price.setSuperiorSubcommission(goodsVip.getSuperiorSubcommission());
+ price.setSuperiorRebatePoints(goodsVip.getSuperiorRebatePoints());
+ price.setSuperiorType(goodsVip.getSuperiorType());
+ price.setSuperiorPriceType(goodsVip.getSuperiorPriceType());
+ price.setServuceShopCharges(goodsVip.getServuceShopCharges());
+ price.setServuceShopPoints(goodsVip.getServuceShopPoints());
+ price.setTechnicianPoints(goodsVip.getTechnicianPoints());
+ price.setBoundShopCharges(goodsVip.getBoundShopCharges());
+ price.setBoundShopPoints(goodsVip.getBoundShopPoints());
+ price.setBoundShopSuperiorsCharges(goodsVip.getBoundShopSuperiorsCharges());
+ price.setBoundShopSuperiorsPoints(goodsVip.getBoundShopSuperiorsPoints());
+ }
}
}else{
//构建价格数据
@@ -234,13 +304,14 @@
if(goodsSeckill.getCashPayment() == 0 && goodsSeckill.getPointPayment() == 1){
price.setPoint(goodsSeckill.getIntegral());
}
- price.setCashPayment(goodsSeckill.getCashPayment() == 1 ? true : false);
- price.setPointPayment(goodsSeckill.getPointPayment() == 1 ? true : false);
+ price.setCashPayment(goodsSeckill.getCashPayment() == 1);
+ price.setPointPayment(goodsSeckill.getPointPayment() == 1);
price.setEndTime(goodsSeckill.getEndTime());
price.setEarnSpendingPoints(goodsSeckill.getEarnSpendingPoints());
price.setSuperiorSubcommission(goodsSeckill.getSuperiorSubcommission());
price.setSuperiorRebatePoints(goodsSeckill.getSuperiorRebatePoints());
price.setSuperiorType(goodsSeckill.getSuperiorType());
+ price.setSuperiorPriceType(goodsSeckill.getSuperiorPriceType());
price.setServuceShopCharges(goodsSeckill.getServuceShopCharges());
price.setServuceShopPoints(goodsSeckill.getServuceShopPoints());
price.setTechnicianPoints(goodsSeckill.getTechnicianPoints());
@@ -251,85 +322,28 @@
}
return price;
}
-
-
- @Data
- class Price {
- /**
- * 现金
- */
- private BigDecimal cash;
- /**
- * 积分
- */
- private Integer point;
- /**
- * 获取结束时间
- */
- private Long endTime;
- /**
- * 现金支付
- */
- private Boolean cashPayment;
- /**
- * 积分支付
- */
- private Boolean pointPayment;
- /**
- * 可获得消费积分
- */
- private Integer earnSpendingPoints;
- /**
- * 上级获得分佣金额
- */
- private BigDecimal superiorSubcommission;
- /**
- * 上级获得返佣积分
- */
- private Integer superiorRebatePoints;
- /**
- * 获取返佣积分上级类型(1=直推上级,2=直帮上级)
- */
- private Integer superiorType;
- /**
- * 核销门店可获得服务费
- */
- private BigDecimal servuceShopCharges;
- /**
- * 核销门店可获得服务积分
- */
- private Integer servuceShopPoints;
- /**
- * 技师可获得服务积分
- */
- private Integer technicianPoints;
- /**
- * 绑定门店可获得分佣金额
- */
- private BigDecimal boundShopCharges;
- /**
- * 绑定门店可获得返佣积分
- */
- private Integer boundShopPoints;
- /**
- * 绑定门店上级门店可获得分佣金额
- */
- private BigDecimal boundShopSuperiorsCharges;
- /**
- * 绑定门店上级门店可获得返佣积分
- */
- private Integer boundShopSuperiorsPoints;
- }
-
+
+
+
@Override
- public void addGoods(ShoppingCart shoppingCart) {
+ public Long addGoods(ShoppingCart shoppingCart) {
Long userid = tokenService.getLoginUserApplet().getUserid();
- shoppingCart.setAppUserId(userid);
- this.save(shoppingCart);
+ ShoppingCart one = this.getOne(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid)
+ .eq(ShoppingCart::getGoodsId, shoppingCart.getGoodsId()).eq(ShoppingCart::getType, shoppingCart.getType()).eq(ShoppingCart::getStatus, 1));
+ if(null != one){
+ one.setNumber(one.getNumber() + shoppingCart.getNumber());
+ this.updateById(one);
+ return one.getId();
+ }else{
+ shoppingCart.setAppUserId(userid);
+ shoppingCart.setStatus(1);
+ this.save(shoppingCart);
+ return shoppingCart.getId();
+ }
}
-
-
+
+
/**
* 修改购物车数量
* @param setGoodsNumber
@@ -341,18 +355,21 @@
return R.fail("修改数量不能小于等于0");
}
ShoppingCart shoppingCart = this.getById(setGoodsNumber.getId());
- Goods goods = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData();
- if(null != goods.getPurchaseLimit() && -1 != goods.getPurchaseLimit() && goods.getPurchaseLimit() < setGoodsNumber.getNumber()){
- return R.fail("修改数量不能大于限购数量");
- }
+
if(null != shoppingCart){
+
+ Goods goods = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData();
+ if(null != goods.getPurchaseLimit() && -1 != goods.getPurchaseLimit() && goods.getPurchaseLimit() < setGoodsNumber.getNumber()){
+ return R.fail("修改数量不能大于限购数量");
+ }
+
shoppingCart.setNumber(setGoodsNumber.getNumber());
this.updateById(shoppingCart);
}
return R.ok();
}
-
-
+
+
/**
* 确认购物车订单
* @param confirmOrder
@@ -360,7 +377,25 @@
*/
@Override
public ConfirmOrderVo confirmOrder(ConfirmOrder confirmOrder) {
+ Integer position = confirmOrder.getPosition();
Long userid = tokenService.getLoginUserApplet().getUserid();
+ //直接购买商品
+ if(2 == position){
+ //先加入购物车
+ String goodsJson = confirmOrder.getGoodsJson();
+ JSONArray objects = JSON.parseArray(goodsJson);
+ Long id = objects.getJSONObject(0).getLong("id");
+ Integer num1 = objects.getJSONObject(0).getInteger("num");
+ Integer type = objects.getJSONObject(0).getInteger("type");
+ ShoppingCart shoppingCart = new ShoppingCart();
+ shoppingCart.setAppUserId(userid);
+ shoppingCart.setGoodsId(id.intValue());
+ shoppingCart.setNumber(num1);
+ shoppingCart.setType(type);
+ shoppingCart.setStatus(0);
+ this.save(shoppingCart);
+ confirmOrder.setGoodsJson("[{\"id\": " + shoppingCart.getId() + ", \"num\": " + num1 + ",\"type\":" + type + "}]");
+ }
AppUser appUser = appUserClient.getAppUserById(userid);
Integer shopId = confirmOrder.getShopId();
Shop shop = shopClient.getShopById(shopId).getData();
@@ -380,32 +415,137 @@
confirmOrderVo.setShopName(shop.getName());
//现金支付
if(confirmOrder.getPaymentType() == 1){
- BigDecimal bigDecimal = goodsList.stream().map(MyShoppingCartVo::getCash).reduce(BigDecimal::add).get();
+ BigDecimal bigDecimal = BigDecimal.ZERO;
+ for (MyShoppingCartVo myShoppingCartVo : goodsList) {
+ bigDecimal = bigDecimal.add(myShoppingCartVo.getCash().multiply(new BigDecimal(myShoppingCartVo.getNumber())));
+ }
confirmOrderVo.setOrderMoney(bigDecimal);
}else{
- int sum = goodsList.stream().mapToInt(MyShoppingCartVo::getPoint).sum();
+ int sum = 0;
+ for (MyShoppingCartVo myShoppingCartVo : goodsList) {
+ sum += (myShoppingCartVo.getPoint() * myShoppingCartVo.getNumber());
+ }
confirmOrderVo.setOrderPoint(sum);
}
- //查询当前是否有订单活动
- OrderActivityInfo orderActivityInfo = orderActivityInfoClient.getNowOrderActivityInfo(appUser.getVipId()).getData();
+
BigDecimal orderMoney = confirmOrderVo.getOrderMoney();
BigDecimal paymentMoney = orderMoney;
- //满XX才打折,只有现金才能优惠
- if(null != orderActivityInfo && confirmOrder.getPaymentType() == 1 && orderActivityInfo.getConditionAmount().compareTo(orderMoney) <= 0){
- confirmOrderVo.setActivityName(orderActivityInfo.getActivityName());
- paymentMoney = orderActivityInfo.getDiscount().divide(new BigDecimal(10)).multiply(orderMoney);
- confirmOrderVo.setDiscountAmount(orderMoney.subtract(paymentMoney).setScale(2, RoundingMode.HALF_EVEN));
- }
+ //总优惠金额
+ BigDecimal activityAmount = BigDecimal.ZERO;
+
+
BaseSetting baseSetting = baseSettingClient.getBaseSetting(4).getData();
- confirmOrderVo.setUseSimultaneously(baseSetting.getContent().equals("1") ? true : false);
+ confirmOrderVo.setUseSimultaneously(JSON.parseObject(baseSetting.getContent()).getInteger("status") == 1);
+ //减去优惠券优惠金额
+ CouponInfoVo couponInfoVo = null;
+ if(null != confirmOrder.getCouponId() && 2 != confirmOrder.getPaymentType()){
+ couponInfoVo = userCouponClient.getCouponInfo(confirmOrder.getCouponId()).getData();
+ String forGoodIds = couponInfoVo.getForGoodIds();
+ String[] split = forGoodIds.split(",");
+ List<String> parseArray = Arrays.asList(split);
+ //全部商品
+ if("-1".equals(forGoodIds)){
+ //满减
+ if(1 == couponInfoVo.getCouponType() && couponInfoVo.getConditionAmount().compareTo(paymentMoney) <= 0){
+ paymentMoney = paymentMoney.subtract(couponInfoVo.getDiscountAmount());
+ activityAmount = activityAmount.add(couponInfoVo.getDiscountAmount());
+ }
+ //代金券
+ if(2 == couponInfoVo.getCouponType()){
+ paymentMoney = paymentMoney.subtract(couponInfoVo.getMoneyAmount());
+ activityAmount = activityAmount.add(couponInfoVo.getMoneyAmount());
+ if(paymentMoney.compareTo(BigDecimal.ZERO) < 0){
+ paymentMoney = BigDecimal.ZERO;
+ }
+ }
+ //折扣券
+ if(3 == couponInfoVo.getCouponType()){
+ BigDecimal paymentMoney1 = couponInfoVo.getDiscount().divide(new BigDecimal(10)).multiply(paymentMoney);
+ BigDecimal bigDecimal = paymentMoney.subtract(paymentMoney1).setScale(2, RoundingMode.HALF_EVEN);
+ paymentMoney = paymentMoney1;
+ activityAmount = activityAmount.add(bigDecimal);
+ }
+ }else{
+ //部分商品,需要计算参与优惠商品的支付金额,然后再对商品进行优惠券处理
+ paymentMoney = BigDecimal.ZERO;
+ BigDecimal goodsMoney = BigDecimal.ZERO;
+ for (MyShoppingCartVo myShoppingCartVo : goodsList) {
+ String goodsId = myShoppingCartVo.getGoodsId().toString();
+ BigDecimal cash = myShoppingCartVo.getCash();
+ if(parseArray.contains(goodsId)){
+ goodsMoney = goodsMoney.add(cash);
+ }else{
+ paymentMoney = paymentMoney.add(cash);
+ }
+ }
+
+ //满减
+ if(1 == couponInfoVo.getCouponType() && couponInfoVo.getConditionAmount().compareTo(goodsMoney) <= 0){
+ goodsMoney = goodsMoney.subtract(couponInfoVo.getDiscountAmount());
+ activityAmount = activityAmount.add(couponInfoVo.getDiscountAmount());
+ }
+ //代金券
+ if(2 == couponInfoVo.getCouponType()){
+ goodsMoney = goodsMoney.subtract(couponInfoVo.getMoneyAmount());
+ activityAmount = activityAmount.add(couponInfoVo.getMoneyAmount());
+ if(goodsMoney.compareTo(BigDecimal.ZERO) < 0){
+ goodsMoney = BigDecimal.ZERO;
+ }
+ }
+ //折扣券
+ if(3 == couponInfoVo.getCouponType()){
+ BigDecimal paymentMoney1 = couponInfoVo.getDiscount().divide(new BigDecimal(10)).multiply(goodsMoney);
+ BigDecimal bigDecimal = goodsMoney.subtract(paymentMoney1).setScale(2, RoundingMode.HALF_EVEN);
+ goodsMoney = paymentMoney1;
+ activityAmount = activityAmount.add(bigDecimal);
+ }
+ paymentMoney = paymentMoney.add(goodsMoney);
+ }
+ }
+
+ //查询当前是否有订单活动
+ List<OrderActivityInfo> orderActivityInfo = orderActivityInfoClient.getNowOrderActivityInfo(appUser.getVipId()).getData();
+ //满XX才打折,只有现金才能优惠
+ if((confirmOrderVo.getUseSimultaneously() || (!confirmOrderVo.getUseSimultaneously() && activityAmount.equals(BigDecimal.ZERO)))
+ && null != orderActivityInfo && confirmOrder.getPaymentType() == 1){
+ BigDecimal zyh = BigDecimal.ZERO;
+ OrderActivityInfo activityInfo1 = null;
+ for (OrderActivityInfo activityInfo : orderActivityInfo) {
+ if(activityInfo.getConditionAmount().compareTo(paymentMoney) <= 0){
+ //优惠后的支付金额
+ BigDecimal multiply = activityInfo.getDiscount().divide(new BigDecimal(10)).multiply(paymentMoney);
+ //优惠金额
+ BigDecimal bigDecimal = paymentMoney.subtract(multiply).setScale(2, RoundingMode.HALF_EVEN);
+ if(bigDecimal.compareTo(zyh) > 0){
+ zyh = bigDecimal;
+ activityInfo1 = activityInfo;
+ }
+ }
+ }
+
+ if(null != activityInfo1){
+ confirmOrderVo.setActivityName(activityInfo1.getActivityName());
+ paymentMoney = paymentMoney.subtract(zyh);
+ activityAmount = activityAmount.add(zyh);
+ }
+ }
+ confirmOrderVo.setDiscountAmount(activityAmount);
int earnPoint = goodsList.stream().mapToInt(MyShoppingCartVo::getEarnSpendingPoints).sum();
confirmOrderVo.setEarnPoint(earnPoint);
+ if(null != paymentMoney && BigDecimal.ZERO.compareTo(paymentMoney) > 0){
+ paymentMoney = BigDecimal.ZERO;
+ }
+
//支付金额,订单金额-订单优惠
confirmOrderVo.setPayMoney(paymentMoney);
- confirmOrderVo.setResidualPoint(appUser.getLavePoint().intValue());
+ confirmOrderVo.setResidualPoint(appUser.getAvailablePoint().intValue());
//获取默认收货地址
UserAddress userAddress = userAddressClient.getDefaultUserAddress(userid).getData();
- confirmOrderVo.setUserAddress(userAddress);
+ if(null != userAddress){
+ userAddress.setIdStr(userAddress.getId().toString());
+ userAddress.setRecieveAddress(userAddress.getProvince() + userAddress.getCity() + userAddress.getDistrict() + userAddress.getRecieveAddress());
+ confirmOrderVo.setUserAddress(userAddress);
+ }
confirmOrderVo.setPaymentType(confirmOrder.getPaymentType());
//获取用户优惠券,用户全部优惠券,不能使用的需要标识出来置灰展示
PaymentUserCoupon paymentUserCoupon = new PaymentUserCoupon();
@@ -414,35 +554,37 @@
paymentUserCoupon.setType(confirmOrder.getType());
if(confirmOrder.getPaymentType() == 1){
List<PaymentUserCouponVo> data = userCouponClient.getPaymentUserCoupon(paymentUserCoupon).getData();
- for (PaymentUserCouponVo couponInfo : data) {
- List<Integer> forGoodIds = couponInfo.getForGoodIds();
- //全部商品适用
- if(null == forGoodIds){
- //满减券
- if(1 == couponInfo.getCouponType() && orderMoney.compareTo(couponInfo.getConditionAmount()) >= 0){
- couponInfo.setAvailable(true);
- }
- //代金券和折扣券
- if(2 == couponInfo.getCouponType() || 3 == couponInfo.getCouponType()){
- couponInfo.setAvailable(true);
- }
- }else{
- //部分商品适用
- BigDecimal goodsMoney = BigDecimal.ZERO;
- for (MyShoppingCartVo myShoppingCartVo : goodsList) {
- Integer goodsId = myShoppingCartVo.getGoodsId();
- BigDecimal cash = myShoppingCartVo.getCash();
- if(forGoodIds.contains(goodsId)){
- goodsMoney = goodsMoney.add(cash);
+ if(null != data){
+ for (PaymentUserCouponVo couponInfo : data) {
+ List<String> forGoodIds = couponInfo.getForGoodIds();
+ //全部商品适用
+ if(null == forGoodIds){
+ //满减券
+ if(1 == couponInfo.getCouponType() && orderMoney.compareTo(couponInfo.getConditionAmount()) >= 0){
+ couponInfo.setAvailable(true);
}
- }
- //满减
- if(1 == couponInfo.getCouponType() && couponInfo.getConditionAmount().compareTo(goodsMoney) <= 0){
- couponInfo.setAvailable(true);
- }
- //代金券
- if(2 == couponInfo.getCouponType() || 3 == couponInfo.getCouponType()){
- couponInfo.setAvailable(true);
+ //代金券和折扣券
+ if(2 == couponInfo.getCouponType() || 3 == couponInfo.getCouponType()){
+ couponInfo.setAvailable(true);
+ }
+ }else{
+ //部分商品适用
+ BigDecimal goodsMoney = BigDecimal.ZERO;
+ for (MyShoppingCartVo myShoppingCartVo : goodsList) {
+ Integer goodsId = myShoppingCartVo.getGoodsId();
+ BigDecimal cash = myShoppingCartVo.getCash();
+ if(forGoodIds.contains(goodsId)){
+ goodsMoney = goodsMoney.add(cash);
+ }
+ }
+ //满减
+ if(1 == couponInfo.getCouponType() && couponInfo.getConditionAmount().compareTo(goodsMoney) <= 0){
+ couponInfo.setAvailable(true);
+ }
+ //代金券
+ if(2 == couponInfo.getCouponType() || 3 == couponInfo.getCouponType()){
+ couponInfo.setAvailable(true);
+ }
}
}
}
@@ -451,19 +593,19 @@
//获取快递策略
SystemConfig systemConfig = systemConfigClient.getSystemConfig(3).getData();
JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
- confirmOrderVo.setExpressFee(jsonObject.getBigDecimal("expressFee"));
- List<Integer> vip = jsonObject.getJSONArray("vip").toList(Integer.class);
+ confirmOrderVo.setExpressFee(jsonObject.getBigDecimal("freight"));
+ List<String> vip = Arrays.asList(jsonObject.getString("freeVip").split(","));
//包邮条件(所有会员或者满足条件的会员)
- if(vip.get(0) == -1 || vip.contains(appUser.getVipId())){
+ if(vip.get(0).equals("0") || vip.contains(appUser.getVipId().toString())){
if(confirmOrder.getPaymentType() == 1){
//现金支付,支付金额满足包邮条件
- BigDecimal cash = jsonObject.getBigDecimal("cash");
+ BigDecimal cash = jsonObject.getBigDecimal("freeFreight");
if(confirmOrderVo.getPayMoney().compareTo(cash) >= 0){
confirmOrderVo.setExpressFee(BigDecimal.ZERO);
}
}else{
//积分支付,支付积分是否满足包邮条件
- Integer point = jsonObject.getInteger("point");
+ Integer point = jsonObject.getInteger("freeIntegral");
if(confirmOrderVo.getOrderPoint().compareTo(point) >= 0){
confirmOrderVo.setExpressFee(BigDecimal.ZERO);
}
@@ -471,8 +613,8 @@
}
return confirmOrderVo;
}
-
-
+
+
/**
* 构建购物车商品列表
* @param appUser
@@ -486,7 +628,8 @@
for (ShoppingCart shoppingCart : list) {
Goods goods = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData();
MyShoppingCartVo vo = new MyShoppingCartVo();
- vo.setId(shoppingCart.getId());
+ vo.setId(shoppingCart.getId().toString());
+ vo.setType(shoppingCart.getType());
vo.setGoodsId(goods.getId());
vo.setHomePicture(goods.getHomePagePicture());
vo.setName(goods.getName());
@@ -501,13 +644,14 @@
}
}
//获取支付价格
- Price price = getPrice(appUser, shoppingCart.getGoodsId(), shopId);
+ Price price = getPrice(appUser, shoppingCart.getGoodsId(), shoppingCart.getType(), shopId);
if(null == price){
+ price = new Price();
//使用商品的基础价格
price.setCash(1 == goods.getCashPayment() ? goods.getSellingPrice() : null);
price.setPoint(1 == goods.getPointPayment() ? goods.getIntegral() : null);
- price.setCashPayment(goods.getCashPayment() == 1 ? true : false);
- price.setPointPayment(goods.getPointPayment() == 1 ? true : false);
+ price.setCashPayment(goods.getCashPayment() == 1);
+ price.setPointPayment(goods.getPointPayment() == 1);
}
vo.setCash(price.getCash());
vo.setPoint(price.getPoint());
@@ -520,26 +664,29 @@
goodsShop.setGoodsId(shoppingCart.getGoodsId());
goodsShop.setShopId(shopId);
GoodsShop goodsShop1 = goodsShopClient.getGoodsShop(goodsShop).getData();
- vo.setVerifiable(null == goodsShop1 ? false : true);
+ vo.setVerifiable(goods.getAppointStore() != 1 || null != goodsShop1);
//判断当前数量是否已经超出限购数量(需要计算已经购买的数量)
if(null == goods.getPurchaseLimit() || -1 == goods.getPurchaseLimit()){
vo.setPurchaseLimit(false);
+ vo.setPurchaseLimitNum(-1);
}else{
List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getAppUserId, appUser.getId()).eq(Order::getDelFlag, 0).in(Order::getOrderStatus, Arrays.asList(4, 8)));
List<Long> orderIds = orders.stream().map(Order::getId).collect(Collectors.toList());
int sum = 0;
- if(orderIds.size() > 0){
+ if(!orderIds.isEmpty()){
List<OrderGood> orderGoodList = orderGoodService.list(new LambdaQueryWrapper<OrderGood>().in(OrderGood::getOrderId, orderIds)
.eq(OrderGood::getGoodsId, shoppingCart.getGoodsId()).eq(OrderGood::getDelFlag, 0));
sum = orderGoodList.stream().mapToInt(OrderGood::getNum).sum();
}
- vo.setPurchaseLimit((num + sum) > goods.getPurchaseLimit() ? true : false);
+ vo.setPurchaseLimit((num + sum) > goods.getPurchaseLimit());
+ vo.setPurchaseLimitNum(goods.getPurchaseLimit() - sum);
}
vo.setDistributionMode(goods.getDistributionMode());
vo.setEarnSpendingPoints(price.getEarnSpendingPoints());
vo.setSuperiorSubcommission(price.getSuperiorSubcommission());
vo.setSuperiorRebatePoints(price.getSuperiorRebatePoints());
vo.setSuperiorType(price.getSuperiorType());
+ vo.setSuperiorPriceType(price.getSuperiorPriceType());
vo.setServuceShopCharges(price.getServuceShopCharges());
vo.setServuceShopPoints(price.getServuceShopPoints());
vo.setTechnicianPoints(price.getTechnicianPoints());
@@ -551,8 +698,8 @@
}
return page;
}
-
-
+
+
/**
* 购物车支付操作
* @param shoppingCartPayment
@@ -570,26 +717,39 @@
for (int i = 0; i < objects.size(); i++) {
Long id = objects.getJSONObject(i).getLong("id");
Integer num1 = objects.getJSONObject(i).getInteger("num");
+ Integer type = objects.getJSONObject(i).getInteger("type");
num += num1;
ShoppingCart shoppingCart = this.getById(id);
//判断当前数量是否已经超出限购数量(需要计算已经购买的数量)
+ Integer goodsSaleNum = orderService.getGoodsSaleNum(shoppingCart.getGoodsId(), type);
Goods goods = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData();
- if(null != goods.getPurchaseLimit() && -1 != goods.getPurchaseLimit()){
- List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getAppUserId, appUser.getId()).eq(Order::getDelFlag, 0).in(Order::getOrderStatus, Arrays.asList(4, 8)));
- List<Long> orderIds = orders.stream().map(Order::getId).collect(Collectors.toList());
- int sum = 0;
- if(orderIds.size() > 0){
- List<OrderGood> orderGoodList = orderGoodService.list(new LambdaQueryWrapper<OrderGood>().in(OrderGood::getOrderId, orderIds)
- .eq(OrderGood::getGoodsId, shoppingCart.getGoodsId()).eq(OrderGood::getDelFlag, 0));
- sum = orderGoodList.stream().mapToInt(OrderGood::getNum).sum();
- }
- if((num1 + sum) > goods.getPurchaseLimit()){
+ if(1 == type){
+ if(null != goods.getPurchaseLimit() && -1 != goods.getPurchaseLimit() && (goodsSaleNum + num1) > goods.getPurchaseLimit()){
return R.fail(goods.getName() + "已超出购买上限");
}
+ }else{
+ GetSeckillActivityInfo info = new GetSeckillActivityInfo();
+ info.setGoodsId(shoppingCart.getGoodsId());
+ info.setVip(appUser.getVipId());
+ GoodsSeckill goodsSeckill = seckillActivityInfoClient.getSeckillActivityInfo(info).getData();
+ if(null != goodsSeckill ){
+ SeckillActivityInfo activityInfo = seckillActivityInfoClient.getSeckillActivityInfoById(goodsSeckill.getSeckillActivityInfoId()).getData();
+ if(null != activityInfo.getMaxNum() && -1 != activityInfo.getMaxNum() && (goodsSaleNum + num1) > activityInfo.getMaxNum()){
+ return R.fail(goods.getName() + "已超出秒杀活动购买上限");
+ }
+ }
}
+
+ if(goods.getStatus() == 1){
+ throw new RuntimeException(goods.getName() + "商品已被下架");
+ }
+ if(!goods.getCommodityAuthority().contains("-1") && !goods.getCommodityAuthority().contains(appUser.getVipId().toString())){
+ throw new RuntimeException("无权限购买" + goods.getName());
+ }
+
ids.add(id);
}
-
+
List<ShoppingCart> list = this.listByIds(ids);
//构建商品明细列表
List<MyShoppingCartVo> goodsList = buildDetail(appUser, shopId, list, objects);
@@ -619,12 +779,15 @@
if(data.size() != goodsList.size()){
String goodsName = "";
for (Integer goodsId : goodsIds) {
- if(!collect.contains(goodsId)){
- goodsName = goodsClient.getGoodsById(goodsId).getData().getName();
+ Goods goods = goodsClient.getGoodsById(goodsId).getData();
+ if(goods.getType() == 1 && 1 == goods.getAppointStore() && !collect.contains(goodsId)){
+ goodsName = goods.getName();
break;
}
}
- return R.fail(goodsName + "不能在该门店核销");
+ if(StringUtils.isNotEmpty(goodsName)){
+ return R.fail(goodsName + "不能在该门店核销");
+ }
}
//开始构建支付信息
//现金支付的订单金额
@@ -634,11 +797,12 @@
//积分支付的订单积分
Integer orderPoint = 0;
if(3 != shoppingCartPayment.getPaymentType()){
- orderMoney = goodsList.stream().map(MyShoppingCartVo::getCash).reduce(BigDecimal::add).get();
+ for (MyShoppingCartVo myShoppingCartVo : goodsList) {
+ orderMoney = orderMoney.add(myShoppingCartVo.getCash().multiply(new BigDecimal(myShoppingCartVo.getNumber())));
+ }
}else{
- orderPoint = goodsList.stream().mapToInt(MyShoppingCartVo::getPoint).sum();
- if(appUser.getLavePoint().intValue() < orderPoint){
- return R.fail("账户剩余积分不足");
+ for (MyShoppingCartVo myShoppingCartVo : goodsList) {
+ orderPoint += (myShoppingCartVo.getPoint() * myShoppingCartVo.getNumber());
}
}
//现金的支付金额
@@ -651,15 +815,16 @@
BigDecimal discountAmount = BigDecimal.ZERO;
//活动优惠金额
BigDecimal activityAmount = BigDecimal.ZERO;
-
+
//减去优惠券优惠金额
CouponInfoVo couponInfoVo = null;
if(null != shoppingCartPayment.getUserCouponId() && 3 != shoppingCartPayment.getPaymentType()){
couponInfoVo = userCouponClient.getCouponInfo(shoppingCartPayment.getUserCouponId()).getData();
String forGoodIds = couponInfoVo.getForGoodIds();
- List<Integer> parseArray = JSON.parseArray(forGoodIds, Integer.class);
+ String[] split = forGoodIds.split(",");
+ List<String> parseArray = Arrays.asList(split);
//全部商品
- if(parseArray.contains(-1)){
+ if("-1".equals(forGoodIds)){
//满减
if(1 == couponInfoVo.getCouponType() && couponInfoVo.getConditionAmount().compareTo(paymentMoney) <= 0){
paymentMoney = paymentMoney.subtract(couponInfoVo.getDiscountAmount());
@@ -686,7 +851,7 @@
paymentMoney = BigDecimal.ZERO;
BigDecimal goodsMoney = BigDecimal.ZERO;
for (MyShoppingCartVo myShoppingCartVo : goodsList) {
- Integer goodsId = myShoppingCartVo.getGoodsId();
+ String goodsId = myShoppingCartVo.getGoodsId().toString();
BigDecimal cash = myShoppingCartVo.getCash();
if(parseArray.contains(goodsId)){
goodsMoney = goodsMoney.add(cash);
@@ -694,7 +859,7 @@
paymentMoney = paymentMoney.add(cash);
}
}
-
+
//满减
if(1 == couponInfoVo.getCouponType() && couponInfoVo.getConditionAmount().compareTo(goodsMoney) <= 0){
goodsMoney = goodsMoney.subtract(couponInfoVo.getDiscountAmount());
@@ -719,55 +884,70 @@
paymentMoney = paymentMoney.add(goodsMoney);
}
}
-
+
//查询当前是否有订单活动
- OrderActivityInfo orderActivityInfo = orderActivityInfoClient.getNowOrderActivityInfo(appUser.getVipId()).getData();
+ List<OrderActivityInfo> orderActivityInfo = orderActivityInfoClient.getNowOrderActivityInfo(appUser.getVipId()).getData();
BaseSetting baseSetting = baseSettingClient.getBaseSetting(4).getData();
//系统活动设置(优惠券和活动能否同时使用)
- boolean useSimultaneously = baseSetting.getContent().equals("1") ? true : false;
+ Integer status = JSON.parseObject(baseSetting.getContent()).getInteger("status");
//满XX才打折,只有现金才能优惠
//如果使用优惠券,则需要判断是否可以和同时使用,且活动满足使用条件。
//没有使用优惠券,只需要判断是都满足使用条件
- if(((useSimultaneously && null != shoppingCartPayment.getUserCouponId()) || null == shoppingCartPayment.getUserCouponId()) &&
- null != orderActivityInfo && shoppingCartPayment.getPaymentType() != 3 && orderActivityInfo.getConditionAmount().compareTo(paymentMoney) <= 0){
- BigDecimal paymentMoney1 = orderActivityInfo.getDiscount().divide(new BigDecimal(10)).multiply(paymentMoney);
- BigDecimal bigDecimal = paymentMoney.subtract(paymentMoney1).setScale(2, RoundingMode.HALF_EVEN);
- discount = orderActivityInfo.getDiscount();
- paymentMoney = paymentMoney1;
- activityAmount = activityAmount.add(bigDecimal);
+ OrderActivityInfo orderActivityInfo1 = null;
+ if((1 == status || null == shoppingCartPayment.getUserCouponId()) &&
+ null != orderActivityInfo && shoppingCartPayment.getPaymentType() != 3){
+ //找出最优会的金额
+ BigDecimal zyh = BigDecimal.ZERO;
+ for (OrderActivityInfo activityInfo : orderActivityInfo) {
+ if(activityInfo.getConditionAmount().compareTo(paymentMoney) <= 0){
+ BigDecimal paymentMoney1 = activityInfo.getDiscount().divide(new BigDecimal(10)).multiply(paymentMoney);
+ BigDecimal bigDecimal = paymentMoney.subtract(paymentMoney1).setScale(2, RoundingMode.HALF_EVEN);
+ if(bigDecimal.compareTo(zyh) > 0){
+ zyh = bigDecimal;
+ orderActivityInfo1 = activityInfo;
+ }
+ }
+ }
+
+ paymentMoney = paymentMoney.subtract(zyh);
+ activityAmount = activityAmount.add(zyh);
}
-
+
//可获得的消费积分
- int earnPoint = goodsList.stream().mapToInt(MyShoppingCartVo::getEarnSpendingPoints).sum();
- if(null != shoppingCartPayment.getUserAddressId()){
- userAddressClient.getUserAddressById(shoppingCartPayment.getUserAddressId()).getData();
+ int earnPoint = 0;
+ for (MyShoppingCartVo myShoppingCartVo : goodsList) {
+ earnPoint += (myShoppingCartVo.getEarnSpendingPoints() * myShoppingCartVo.getNumber());
}
-
+
//获取快递策略,计算快递费
BigDecimal expressFee = BigDecimal.ZERO;
if(null != shoppingCartPayment.getUserAddressId()){
SystemConfig systemConfig = systemConfigClient.getSystemConfig(3).getData();
JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
//快递费
- expressFee = jsonObject.getBigDecimal("expressFee");
- List<Integer> vip = jsonObject.getJSONArray("vip").toList(Integer.class);
+ expressFee = jsonObject.getBigDecimal("freight");
+ List<String> vip = Arrays.asList(jsonObject.getString("freeVip").split(","));
//包邮条件(所有会员或者满足条件的会员)
- if(vip.get(0) == -1 || vip.contains(appUser.getVipId())){
+ if(vip.get(0).equals("0") || vip.contains(appUser.getVipId().toString())){
if(shoppingCartPayment.getPaymentType() != 3){
//现金支付,支付金额满足包邮条件
- BigDecimal cash = jsonObject.getBigDecimal("cash");
+ BigDecimal cash = jsonObject.getBigDecimal("freeFreight");
if(paymentMoney.compareTo(cash) >= 0){
expressFee = BigDecimal.ZERO;
}
}else{
//积分支付,支付积分是否满足包邮条件
- Integer point = jsonObject.getInteger("point");
+ Integer point = jsonObject.getInteger("freeIntegral");
if(orderPoint.compareTo(point) >= 0){
expressFee = BigDecimal.ZERO;
}
}
}
}
+ if(BigDecimal.ZERO.compareTo(paymentMoney) > 0){
+ paymentMoney = BigDecimal.ZERO;
+ }
+
//构建订单明细
Order order = new Order();
order.setAppUserId(userid);
@@ -782,7 +962,7 @@
order.setGoodName(goodName.substring(0, goodName.length() - 1));
Goods goods = goodsClient.getGoodsById(goodsList.get(0).getGoodsId()).getData();
order.setOrderType(goods.getType());
- order.setOrderStatus(1);
+ order.setOrderStatus(goods.getType() == 1 ? 3 : (shoppingCartPayment.getDistributionMode() == 2 ? 1 : 2));
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
order.setOrderNumber("QJS" + getNumber(3) + sdf.format(new Date()));
order.setTotalAmount(orderMoney.setScale(2, RoundingMode.HALF_EVEN));
@@ -799,11 +979,12 @@
}
if(3 != shoppingCartPayment.getPaymentType() && (fullReductionAmount.compareTo(BigDecimal.ZERO) > 0 ||moneyAmount.compareTo(BigDecimal.ZERO) > 0 || discountAmount.compareTo(BigDecimal.ZERO) > 0)){
order.setCouponJson(JSON.toJSONString(couponInfoVo));
+ order.setUserCouponId(shoppingCartPayment.getUserCouponId());
}
- if(activityAmount.compareTo(BigDecimal.ZERO) > 0){
- order.setActivityJson(JSON.toJSONString(orderActivityInfo));
+ if(null != orderActivityInfo1){
+ order.setActivityJson(JSON.toJSONString(orderActivityInfo1));
}
- if(null != shoppingCartPayment.getUserAddressId()){
+ if(2 == shoppingCartPayment.getDistributionMode()){
UserAddress address = userAddressClient.getUserAddressById(shoppingCartPayment.getUserAddressId()).getData();
order.setExpressAmount(expressFee);
order.setAddressJson(JSON.toJSONString(address));
@@ -813,40 +994,53 @@
order.setShopId(shoppingCartPayment.getShopId());
order.setDelFlag(0);
order.setCreateTime(LocalDateTime.now());
-
+ order.setExpressPayMethod(shoppingCartPayment.getFreightPaymentType());
+ order.setDistributionMode(shoppingCartPayment.getDistributionMode());
+
if(2 == shoppingCartPayment.getPaymentType()){
BigDecimal balance = appUser.getBalance();
if(balance.compareTo(paymentMoney) < 0){
return R.fail("账户余额不足");
}
}
+ if(3 == shoppingCartPayment.getPaymentType()){
+ Integer availablePoint = appUser.getAvailablePoint();
+ if(availablePoint < orderPoint){
+ return R.fail("账户可用积分不足");
+ }
+ }
//判断运费支付是否足够
- if(2 == shoppingCartPayment.getFreightPaymentType() && expressFee.compareTo(BigDecimal.ZERO) > 0){
+ if(null != shoppingCartPayment.getFreightPaymentType() && 2 == shoppingCartPayment.getFreightPaymentType() && expressFee.compareTo(BigDecimal.ZERO) > 0){
BigDecimal balance = appUser.getBalance();
if(balance.compareTo(expressFee) < 0){
return R.fail("账户余额不足");
}
}
-
+
orderService.save(order);
//构建订单明细数据
for (MyShoppingCartVo myShoppingCartVo : goodsList) {
OrderGood orderGood = new OrderGood();
orderGood.setGoodsId(myShoppingCartVo.getGoodsId());
orderGood.setOrderId(order.getId());
- GetSeckillActivityInfo info = new GetSeckillActivityInfo();
- info.setGoodsId(myShoppingCartVo.getGoodsId());
- info.setVip(appUser.getVipId());
- GoodsSeckill goodsSeckill = seckillActivityInfoClient.getSeckillActivityInfo(info).getData();
- if(null != goodsSeckill){
- orderGood.setSeckillJson(JSON.toJSONString(goodsSeckill));
- }
for (int i = 0; i < objects.size(); i++) {
Long id = objects.getJSONObject(i).getLong("id");
- if(myShoppingCartVo.getId().equals(id)){
+ if(myShoppingCartVo.getId().equals(id.toString())){
+ ShoppingCart shoppingCart = this.getById(id);
Integer num1 = objects.getJSONObject(i).getInteger("num");
+ Integer type = objects.getJSONObject(i).getInteger("type");
orderGood.setNum(num1);
- Goods goods1 = goodsClient.getGoodsById(myShoppingCartVo.getGoodsId()).getData();
+ orderGood.setType(type);
+ if(2 == type){
+ GetSeckillActivityInfo info = new GetSeckillActivityInfo();
+ info.setGoodsId(myShoppingCartVo.getGoodsId());
+ info.setVip(appUser.getVipId());
+ GoodsSeckill goodsSeckill = seckillActivityInfoClient.getSeckillActivityInfo(info).getData();
+ if(null != goodsSeckill){
+ orderGood.setSeckillJson(JSON.toJSONString(goodsSeckill));
+ }
+ }
+ Goods goods1 = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData();
orderGood.setGoodJson(JSON.toJSONString(goods1));
break;
}
@@ -857,6 +1051,7 @@
orderGood.setSuperiorSubcommission(myShoppingCartVo.getSuperiorSubcommission());
orderGood.setSuperiorRebatePoints(myShoppingCartVo.getSuperiorRebatePoints());
orderGood.setSuperiorType(myShoppingCartVo.getSuperiorType());
+ orderGood.setSuperiorPriceType(myShoppingCartVo.getSuperiorPriceType());
orderGood.setServuceShopCharges(myShoppingCartVo.getServuceShopCharges());
orderGood.setServuceShopPoints(myShoppingCartVo.getServuceShopPoints());
orderGood.setTechnicianPoints(myShoppingCartVo.getTechnicianPoints());
@@ -864,65 +1059,188 @@
orderGood.setBoundShopPoints(myShoppingCartVo.getBoundShopPoints());
orderGood.setBoundShopSuperiorsCharges(myShoppingCartVo.getBoundShopSuperiorsCharges());
orderGood.setBoundShopSuperiorsPoints(myShoppingCartVo.getBoundShopSuperiorsPoints());
+ orderGood.setCashPayment(myShoppingCartVo.getCashPayment() ? 1 : 0);
+ orderGood.setPointPayment(myShoppingCartVo.getPointPayment() ? 1 : 0);
+ orderGood.setSellingPrice(myShoppingCartVo.getCash());
+ orderGood.setIntegral(myShoppingCartVo.getPoint());
orderGoodService.save(orderGood);
}
-
+
//开始构建支付数据
//现金支付
paymentMoney = paymentMoney.add(expressFee).setScale(2, RoundingMode.HALF_EVEN);
+ if(BigDecimal.ZERO.compareTo(paymentMoney) > 0){
+ paymentMoney = BigDecimal.ZERO;
+ }
if(1 == shoppingCartPayment.getPaymentType()){
- //调起微信支付 TODO 待完善
-
-
-
+ if(BigDecimal.ZERO.compareTo(paymentMoney) < 0){
+ //调起微信支付
+ String goodsNames = goodsList.stream().map(MyShoppingCartVo::getName).collect(Collectors.joining("\n"));
+ UniPayResult uniPayResult = PaymentUtil.uniPay(order.getOrderNumber(), paymentMoney.doubleValue(), order.getOrderType() == 1 ? "购买服务商品" : "购买单品商品",
+ goodsNames, "", "/order/shopping-cart/shoppingCartPaymentCallback", appUser.getWxOpenid(), null);
+ if(null == uniPayResult || !"100".equals(uniPayResult.getRa_Code())){
+ return R.fail(null == uniPayResult ? "支付失败" : uniPayResult.getRb_CodeMsg());
+ }
+ String rc_result = uniPayResult.getRc_Result();
+ JSONObject jsonObject = JSON.parseObject(rc_result);
+ jsonObject.put("orderId", order.getId().toString());
+ //将支付数据添加到redis队列中,便于定时任务去校验是否完成支付,没有完成支付支付,15分钟后关闭订单。
+ long second = LocalDateTime.now().plusMinutes(15).toEpochSecond(ZoneOffset.UTC);
+ redisTemplate.opsForZSet().add("OrderPayment", order.getOrderNumber(), second);
+ return R.ok(jsonObject.toJSONString());
+ }else{
+
+ earnPoint = order.getGetPoint();
+ appUser = appUserClient.getAppUserById(order.getAppUserId());
+ Integer lavePoint = appUser.getLavePoint();
+ paymentMoney = order.getPaymentAmount();
+ //构建积分流水记录
+ if(earnPoint > 0){
+ PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData();
+ int earnPoint1 = 0;
+ if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){
+ earnPoint1 = new BigDecimal(earnPoint).multiply(pointSetting.getBuyPoint().divide(new BigDecimal(100))).intValue();
+ }
+ appUser.setShopPoint(appUser.getShopPoint() + earnPoint);
+ appUser.setLavePoint(appUser.getLavePoint() + earnPoint);
+ appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint);
+ appUser.setAvailablePoint(appUser.getAvailablePoint() + earnPoint1);
+ appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() + earnPoint1);
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("shopPoint", earnPoint);
+ jsonObject.put("availablePoint", earnPoint1);
+ if(null != pointSetting && 1 == pointSetting.getBuyPointGift()){
+ appUser.setTransferablePoint(appUser.getTransferablePoint() + earnPoint1);
+ jsonObject.put("transferablePoint", earnPoint1);
+ }
+
+ UserPoint userPoint = new UserPoint();
+ userPoint.setType(1);
+ userPoint.setHistoricalPoint(lavePoint);
+ userPoint.setVariablePoint(earnPoint);
+ userPoint.setBalance(appUser.getLavePoint());
+ userPoint.setCreateTime(LocalDateTime.now());
+ userPoint.setAppUserId(appUser.getId());
+ userPoint.setObjectId(order.getId());
+ userPoint.setExtention(jsonObject.toJSONString());
+ userPointClient.saveUserPoint(userPoint);
+ }
+ appUser.setShopAmount(appUser.getShopAmount().add(paymentMoney).setScale(2, RoundingMode.HALF_EVEN));
+ appUser.setLastShopTime(LocalDateTime.now());
+ appUserClient.editAppUserById(appUser);
+ //变更等级
+ appUserClient.vipUpgrade(appUser.getId());
+ //修改订支付状态
+ order.setPayStatus(2);
+ //自提
+ if(order.getOrderType() == 1 && StringUtils.isEmpty(order.getAddressJson())){
+ order.setOrderStatus(2);
+ }
+ orderService.updateById(order);
+
+ //处理优惠券
+ if(null != order.getUserCouponId()){
+ UserCoupon userCoupon = userCouponClient.getUserCoupon(order.getUserCouponId()).getData();
+ if(null != userCoupon && null == userCoupon.getUseTime()){
+ userCoupon.setStatus(2);
+ userCoupon.setUseTime(LocalDateTime.now());
+ userCouponClient.editUserCoupon(userCoupon);
+ }
+ }
+ //添加查询快递信息队列
+ if(StringUtils.isNotEmpty(order.getExpressJson())){
+ //一小时后定时查询快递信息
+ redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(1).toEpochSecond(ZoneOffset.UTC));
+ }
+
+ //删除购物车数据
+ userid = tokenService.getLoginUserApplet().getUserid();
+ List<OrderGood> list1 = orderGoodService.list(new LambdaQueryWrapper<OrderGood>().eq(OrderGood::getOrderId, order.getId()));
+ List<Integer> goodsIds1 = list1.stream().map(OrderGood::getGoodsId).collect(Collectors.toList());
+ this.remove(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid).in(ShoppingCart::getGoodsId, goodsIds1));
+
+ }
}
//账户余额
+ BigDecimal redPacketAmount = BigDecimal.ZERO;
+ BigDecimal distributionAmount = BigDecimal.ZERO;
if(2 == shoppingCartPayment.getPaymentType()){
BigDecimal totalRedPacketAmount = appUser.getTotalRedPacketAmount();
BigDecimal totalDistributionAmount = appUser.getTotalDistributionAmount();
BigDecimal balance = appUser.getBalance();
- if(paymentMoney.compareTo(totalRedPacketAmount) <= 0){
- totalRedPacketAmount = totalRedPacketAmount.subtract(paymentMoney);
- balance = balance.subtract(paymentMoney);
+ //红包金额满足支付
+ BigDecimal paymentMoney1 = paymentMoney;
+ if(paymentMoney1.compareTo(totalRedPacketAmount) <= 0){
+ totalRedPacketAmount = totalRedPacketAmount.subtract(paymentMoney1);
+ balance = balance.subtract(paymentMoney1);
appUser.setTotalRedPacketAmount(totalRedPacketAmount);
appUser.setBalance(balance);
+ redPacketAmount = paymentMoney1;
}else{
- paymentMoney = paymentMoney.subtract(totalRedPacketAmount);
+ paymentMoney1 = paymentMoney1.subtract(totalRedPacketAmount);
+ redPacketAmount = totalRedPacketAmount;
totalRedPacketAmount = BigDecimal.ZERO;
- if(paymentMoney.compareTo(totalDistributionAmount) <= 0){
- totalDistributionAmount = totalDistributionAmount.subtract(paymentMoney);
- balance = balance.subtract(paymentMoney);
+ if(paymentMoney1.compareTo(totalDistributionAmount) <= 0){
+ totalDistributionAmount = totalDistributionAmount.subtract(paymentMoney1);
+ balance = balance.subtract(paymentMoney1);
appUser.setTotalRedPacketAmount(totalRedPacketAmount);
appUser.setTotalDistributionAmount(totalDistributionAmount);
appUser.setBalance(balance);
+ distributionAmount = paymentMoney1;
}else{
- paymentMoney = paymentMoney.subtract(totalDistributionAmount);
+ paymentMoney1 = paymentMoney1.subtract(totalDistributionAmount);
totalDistributionAmount = BigDecimal.ZERO;
- balance = balance.subtract(paymentMoney);
+ balance = balance.subtract(paymentMoney1);
appUser.setTotalRedPacketAmount(totalRedPacketAmount);
appUser.setTotalDistributionAmount(totalDistributionAmount);
appUser.setBalance(balance);
+ distributionAmount = totalDistributionAmount;
}
}
//构建积分流水记录
if(earnPoint > 0){
+ PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData();
+ int earnPoint1 = 0;
+ if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){
+ earnPoint1 = new BigDecimal(earnPoint).multiply(pointSetting.getBuyPoint().divide(new BigDecimal(100))).intValue();
+ }
appUser.setShopPoint(appUser.getShopPoint() + earnPoint);
appUser.setLavePoint(appUser.getLavePoint() + earnPoint);
-
- UserPoint userPoint = new UserPoint();
- userPoint.setType(1);
- userPoint.setHistoricalPoint(appUser.getLavePoint() - earnPoint);
- userPoint.setVariablePoint(earnPoint);
- userPoint.setBalance(appUser.getLavePoint());
- userPoint.setCreateTime(LocalDateTime.now());
- userPoint.setAppUserId(appUser.getId());
- userPoint.setObjectId(order.getId());
- userPointClient.saveUserPoint(userPoint);
+ appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint);
+ appUser.setAvailablePoint(appUser.getAvailablePoint() + earnPoint1);
+ appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() + earnPoint1);
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("shopPoint", earnPoint);
+ jsonObject.put("availablePoint", earnPoint1);
+ if(null != pointSetting && 1 == pointSetting.getBuyPointGift()){
+ appUser.setTransferablePoint(appUser.getTransferablePoint() + earnPoint1);
+ jsonObject.put("transferablePoint", earnPoint1);
+ }
+
+ if(earnPoint > 0){
+ UserPoint userPoint = new UserPoint();
+ userPoint.setType(1);
+ userPoint.setHistoricalPoint(appUser.getLavePoint() - earnPoint);
+ userPoint.setVariablePoint(earnPoint);
+ userPoint.setBalance(appUser.getLavePoint());
+ userPoint.setCreateTime(LocalDateTime.now());
+ userPoint.setAppUserId(appUser.getId());
+ userPoint.setObjectId(order.getId());
+ userPoint.setExtention(jsonObject.toJSONString());
+ userPointClient.saveUserPoint(userPoint);
+ }
}
+ appUser.setShopAmount(appUser.getShopAmount().add(paymentMoney).setScale(2, RoundingMode.HALF_EVEN));
+ appUser.setLastShopTime(LocalDateTime.now());
appUserClient.editAppUserById(appUser);
+ //变更等级
+ appUserClient.vipUpgrade(appUser.getId());
//构建余额明细变动记录
BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord();
balanceChangeRecord.setAppUserId(appUser.getId());
+ balanceChangeRecord.setVipId(appUser.getVipId());
balanceChangeRecord.setOrderId(order.getId());
balanceChangeRecord.setChangeType(5);
balanceChangeRecord.setBeforeAmount(balance.add(paymentMoney));
@@ -933,85 +1251,133 @@
balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord);
//修改订支付状态
order.setPayStatus(2);
+ if(goods.getType() == 2 && null == shoppingCartPayment.getUserAddressId()){
+ order.setOrderStatus(2);
+ }
orderService.updateById(order);
//删除购物车数据
this.removeBatchByIds(ids);
+ //处理优惠券
+ if(null != order.getUserCouponId()){
+ UserCoupon userCoupon = userCouponClient.getUserCoupon(order.getUserCouponId()).getData();
+ if(null != userCoupon && null == userCoupon.getUseTime()){
+ userCoupon.setUseTime(LocalDateTime.now());
+ userCouponClient.editUserCoupon(userCoupon);
+ }
+ }
+ //添加查询快递信息队列
+ if(StringUtils.isNotEmpty(order.getExpressJson())){
+ //一小时后定时查询快递信息
+ redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(1).toEpochSecond(ZoneOffset.UTC));
+ }
}
//积分支付
if(3 == shoppingCartPayment.getPaymentType()){
+ //先完成快递费支付后再处理后续的逻辑
+ if(expressFee.compareTo(BigDecimal.ZERO) > 0){
+ if(shoppingCartPayment.getFreightPaymentType() == 1){
+ //调起微信支付
+ UniPayResult uniPayResult = PaymentUtil.uniPay("K" + order.getOrderNumber(), expressFee.doubleValue(), order.getOrderType() == 1 ? "购买服务商品快递费" : "购买单品商品快递费",
+ "快递费", "", "/order/shopping-cart/shoppingCartMaterialFlowPaymentCallback", appUser.getWxOpenid(), null);
+ if(null == uniPayResult || !"100".equals(uniPayResult.getRa_Code())){
+ return R.fail(null == uniPayResult ? "支付失败" : uniPayResult.getRb_CodeMsg());
+ }
+ String rc_result = uniPayResult.getRc_Result();
+ JSONObject jsonObject = JSON.parseObject(rc_result);
+ jsonObject.put("orderId", order.getId().toString());
+ //将支付数据添加到redis队列中,便于定时任务去校验是否完成支付,没有完成支付支付,15分钟后关闭订单。
+ long second = LocalDateTime.now().plusMinutes(15).toEpochSecond(ZoneOffset.UTC);
+ redisTemplate.opsForZSet().add("MaterialFlowPayment", "K" + order.getOrderNumber(), second);
+ return R.ok(jsonObject.toJSONString());
+ }
+ }
+
Integer lavePoint = appUser.getLavePoint();
- appUser.setLavePoint(lavePoint - orderPoint);
- appUser.setShopPoint(appUser.getShopPoint() + earnPoint);
- appUser.setLavePoint(appUser.getLavePoint() + earnPoint);
- appUserClient.editAppUserById(appUser);
+ //扣减订单支付积分
+ appUser.setLavePoint(appUser.getLavePoint() - orderPoint);
+ appUser.setAvailablePoint(appUser.getAvailablePoint() - orderPoint);
+ //可转增积分
+ Integer transferablePoint = appUser.getTransferablePoint();
+ Integer tra = 0;
+ if(transferablePoint > 0){
+ tra = transferablePoint - orderPoint;
+ appUser.setTransferablePoint(tra >= 0 ? tra : 0);
+ }else{
+ appUser.setTransferablePoint(appUser.getTransferablePoint() - orderPoint);
+ }
+
//构建积分流水记录
UserPoint userPoint = new UserPoint();
- userPoint.setType(4);
+ userPoint.setType(11);
userPoint.setHistoricalPoint(lavePoint);
userPoint.setVariablePoint(orderPoint);
userPoint.setBalance(appUser.getLavePoint());
userPoint.setCreateTime(LocalDateTime.now());
userPoint.setAppUserId(appUser.getId());
userPoint.setObjectId(order.getId());
+ userPoint.setExtention((tra >= 0 ? orderPoint : transferablePoint) + "");
userPointClient.saveUserPoint(userPoint);
- if(earnPoint > 0){
- userPoint = new UserPoint();
- userPoint.setType(1);
- userPoint.setHistoricalPoint(appUser.getLavePoint() - earnPoint);
- userPoint.setVariablePoint(earnPoint);
- userPoint.setBalance(appUser.getLavePoint());
- userPoint.setCreateTime(LocalDateTime.now());
- userPoint.setAppUserId(appUser.getId());
- userPoint.setObjectId(order.getId());
- userPointClient.saveUserPoint(userPoint);
- }
+
+ appUser.setLastShopTime(LocalDateTime.now());
+ appUserClient.editAppUserById(appUser);
+ //变更等级
+ appUserClient.vipUpgrade(appUser.getId());
+
+ //积分支付不返佣
+
//如果有运费,需要先扣除账户积分,再进行支付。支付成功后修改订单状态,未支付成功则回退积分,删除的订单
if(expressFee.compareTo(BigDecimal.ZERO) > 0){
- if(shoppingCartPayment.getFreightPaymentType() == 1){
- //调起微信支付
- }
if(shoppingCartPayment.getFreightPaymentType() == 2){
BigDecimal totalRedPacketAmount = appUser.getTotalRedPacketAmount();
BigDecimal totalDistributionAmount = appUser.getTotalDistributionAmount();
BigDecimal balance = appUser.getBalance();
- if(expressFee.compareTo(totalRedPacketAmount) <= 0){
- totalRedPacketAmount = totalRedPacketAmount.subtract(expressFee);
- balance = balance.subtract(expressFee);
+ BigDecimal expressFee1 = expressFee;
+ if(expressFee1.compareTo(totalRedPacketAmount) <= 0){
+ totalRedPacketAmount = totalRedPacketAmount.subtract(expressFee1);
+ balance = balance.subtract(expressFee1);
appUser.setTotalRedPacketAmount(totalRedPacketAmount);
appUser.setBalance(balance);
+ redPacketAmount = expressFee1;
}else{
- expressFee = expressFee.subtract(totalRedPacketAmount);
+ expressFee1 = expressFee1.subtract(totalRedPacketAmount);
+ redPacketAmount = totalRedPacketAmount;
totalRedPacketAmount = BigDecimal.ZERO;
- if(expressFee.compareTo(totalDistributionAmount) <= 0){
- totalDistributionAmount = totalDistributionAmount.subtract(expressFee);
- balance = balance.subtract(expressFee);
+ if(expressFee1.compareTo(totalDistributionAmount) <= 0){
+ totalDistributionAmount = totalDistributionAmount.subtract(expressFee1);
+ balance = balance.subtract(expressFee1);
appUser.setTotalRedPacketAmount(totalRedPacketAmount);
appUser.setTotalDistributionAmount(totalDistributionAmount);
appUser.setBalance(balance);
+ distributionAmount = expressFee1;
}else{
- expressFee = expressFee.subtract(totalDistributionAmount);
+ expressFee1 = expressFee1.subtract(totalDistributionAmount);
totalDistributionAmount = BigDecimal.ZERO;
- balance = balance.subtract(expressFee);
+ balance = balance.subtract(expressFee1);
appUser.setTotalRedPacketAmount(totalRedPacketAmount);
appUser.setTotalDistributionAmount(totalDistributionAmount);
appUser.setBalance(balance);
+ distributionAmount = totalDistributionAmount;
}
}
-
+
appUserClient.editAppUserById(appUser);
//构建余额明细变动记录
BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord();
balanceChangeRecord.setAppUserId(appUser.getId());
+ balanceChangeRecord.setVipId(appUser.getVipId());
balanceChangeRecord.setOrderId(order.getId());
balanceChangeRecord.setChangeType(5);
- balanceChangeRecord.setBeforeAmount(balance.add(paymentMoney));
- balanceChangeRecord.setChangeAmount(paymentMoney);
+ balanceChangeRecord.setBeforeAmount(balance.add(expressFee));
+ balanceChangeRecord.setChangeAmount(expressFee);
balanceChangeRecord.setAfterAmount(balance);
balanceChangeRecord.setDelFlag(0);
balanceChangeRecord.setCreateTime(LocalDateTime.now());
balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord);
//修改订支付状态
order.setPayStatus(2);
+ if(goods.getType() == 2 && null == shoppingCartPayment.getUserAddressId()){
+ order.setOrderStatus(2);
+ }
orderService.updateById(order);
//删除购物车数据
this.removeBatchByIds(ids);
@@ -1019,14 +1385,34 @@
}else{
//修改订支付状态
order.setPayStatus(2);
+ if(goods.getType() == 2 && null == shoppingCartPayment.getUserAddressId()){
+ order.setOrderStatus(2);
+ }
orderService.updateById(order);
//删除购物车数据
this.removeBatchByIds(ids);
}
+ //添加查询快递信息队列
+ if(StringUtils.isNotEmpty(order.getExpressJson())){
+ //一小时后定时查询快递信息
+ SystemConfig systemConfig = systemConfigClient.getSystemConfig(3).getData();
+ JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
+ Integer waitTime = jsonObject.getInteger("waitTime");
+ redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(waitTime).toEpochSecond(ZoneOffset.UTC));
+ }
}
- return R.ok();
+
+ //添加账户余额支付明细
+ if(redPacketAmount.compareTo(BigDecimal.ZERO) > 0 || distributionAmount.compareTo(BigDecimal.ZERO) > 0){
+ OrderBalancePayment orderBalancePayment = new OrderBalancePayment();
+ orderBalancePayment.setOrderId(order.getId());
+ orderBalancePayment.setRedPacketAmount(redPacketAmount);
+ orderBalancePayment.setDistributionAmount(distributionAmount);
+ orderBalancePaymentService.save(orderBalancePayment);
+ }
+ return R.ok(order.getId().toString());
}
-
+
public String getNumber(Integer size){
String str = "";
@@ -1035,4 +1421,207 @@
}
return str;
}
+
+
+ /**
+ * 线上支付回调逻辑处理
+ * @param uniPayCallbackResult
+ * @return
+ */
+ @Override
+ public R shoppingCartPaymentCallback(UniPayCallbackResult uniPayCallbackResult) {
+ Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, uniPayCallbackResult.getR2_OrderNo()));
+ if(null == order || order.getPayStatus() == 2){
+ return R.ok();
+ }
+ Integer earnPoint = order.getGetPoint();
+ AppUser appUser = appUserClient.getAppUserById(order.getAppUserId());
+ Integer lavePoint = appUser.getLavePoint();
+ BigDecimal paymentMoney = order.getPaymentAmount();
+ //构建积分流水记录
+ if(earnPoint > 0){
+ PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData();
+ int earnPoint1 = 0;
+ if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){
+ earnPoint1 = new BigDecimal(earnPoint).multiply(pointSetting.getBuyPoint().divide(new BigDecimal(100))).intValue();
+ }
+ appUser.setShopPoint(appUser.getShopPoint() + earnPoint);
+ appUser.setLavePoint(appUser.getLavePoint() + earnPoint);
+ appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint);
+ appUser.setAvailablePoint(appUser.getAvailablePoint() + earnPoint1);
+ appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() + earnPoint1);
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("shopPoint", earnPoint);
+ jsonObject.put("availablePoint", earnPoint1);
+ if(null != pointSetting && 1 == pointSetting.getBuyPointGift()){
+ appUser.setTransferablePoint(appUser.getTransferablePoint() + earnPoint1);
+ jsonObject.put("transferablePoint", earnPoint1);
+ }
+
+ UserPoint userPoint = new UserPoint();
+ userPoint.setType(1);
+ userPoint.setHistoricalPoint(lavePoint);
+ userPoint.setVariablePoint(earnPoint);
+ userPoint.setBalance(appUser.getLavePoint());
+ userPoint.setCreateTime(LocalDateTime.now());
+ userPoint.setAppUserId(appUser.getId());
+ userPoint.setObjectId(order.getId());
+ userPoint.setExtention(jsonObject.toJSONString());
+ userPointClient.saveUserPoint(userPoint);
+ }
+ appUser.setShopAmount(appUser.getShopAmount().add(paymentMoney).setScale(2, RoundingMode.HALF_EVEN));
+ appUser.setLastShopTime(LocalDateTime.now());
+ appUserClient.editAppUserById(appUser);
+ //变更等级
+ appUserClient.vipUpgrade(appUser.getId());
+ //修改订支付状态
+ order.setPayStatus(2);
+ //自提
+ if(order.getOrderType() == 1 && StringUtils.isEmpty(order.getAddressJson())){
+ order.setOrderStatus(2);
+ }
+ orderService.updateById(order);
+
+ //处理优惠券
+ if(null != order.getUserCouponId()){
+ UserCoupon userCoupon = userCouponClient.getUserCoupon(order.getUserCouponId()).getData();
+ if(null != userCoupon && null == userCoupon.getUseTime()){
+ userCoupon.setStatus(2);
+ userCoupon.setUseTime(LocalDateTime.now());
+ userCouponClient.editUserCoupon(userCoupon);
+ }
+ }
+ //添加查询快递信息队列
+ if(StringUtils.isNotEmpty(order.getExpressJson())){
+ //一小时后定时查询快递信息
+ redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(1).toEpochSecond(ZoneOffset.UTC));
+ }
+
+ //删除购物车数据
+ Long userid = order.getAppUserId();
+ List<OrderGood> list = orderGoodService.list(new LambdaQueryWrapper<OrderGood>().eq(OrderGood::getOrderId, order.getId()));
+ List<Integer> goodsIds = list.stream().map(OrderGood::getGoodsId).collect(Collectors.toList());
+ this.remove(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid).in(ShoppingCart::getGoodsId, goodsIds));
+
+ //商品销量增加
+ for (Integer goodsId : goodsIds) {
+ goodsClient.editGoodsNum(goodsId, 1);
+ }
+ return R.ok();
+ }
+
+
+ /**
+ * 订单物流支付回调处理逻辑
+ * @param uniPayCallbackResult
+ * @return
+ */
+ @Override
+ public R shoppingCartMaterialFlowPaymentCallback(UniPayCallbackResult uniPayCallbackResult) {
+ String r2_orderNo = uniPayCallbackResult.getR2_OrderNo();
+ r2_orderNo = r2_orderNo.substring(1);
+ Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, r2_orderNo));
+ if(null == order || order.getPayStatus() == 2){
+ return R.ok();
+ }
+ Integer orderPoint = order.getPoint();
+ AppUser appUser = appUserClient.getAppUserById(order.getAppUserId());
+
+ Integer lavePoint = appUser.getLavePoint();
+ //扣减订单支付积分
+ appUser.setLavePoint(appUser.getLavePoint() - orderPoint);
+ appUser.setAvailablePoint(appUser.getAvailablePoint() - orderPoint);
+ //可转增积分
+ Integer transferablePoint = appUser.getTransferablePoint();
+ Integer tra = 0;
+ if(transferablePoint > 0){
+ tra = transferablePoint - orderPoint;
+ appUser.setTransferablePoint(tra >= 0 ? tra : 0);
+ }else{
+ appUser.setTransferablePoint(appUser.getTransferablePoint() - orderPoint);
+ }
+
+ //构建积分流水记录
+ UserPoint userPoint = new UserPoint();
+ userPoint.setType(11);
+ userPoint.setHistoricalPoint(lavePoint);
+ userPoint.setVariablePoint(orderPoint);
+ userPoint.setBalance(appUser.getLavePoint());
+ userPoint.setCreateTime(LocalDateTime.now());
+ userPoint.setAppUserId(appUser.getId());
+ userPoint.setObjectId(order.getId());
+ userPoint.setExtention((tra >= 0 ? orderPoint : transferablePoint) + "");
+ userPointClient.saveUserPoint(userPoint);
+
+ //积分支付不反积分
+
+ appUser.setLastShopTime(LocalDateTime.now());
+ appUserClient.editAppUserById(appUser);
+ //变更等级
+ appUserClient.vipUpgrade(appUser.getId());
+
+ //修改订支付状态
+ order.setPayStatus(2);
+ //自提
+ if(order.getOrderType() == 1 && StringUtils.isEmpty(order.getAddressJson())){
+ order.setOrderStatus(2);
+ }
+ orderService.updateById(order);
+ //删除购物车数据
+ Long userid = tokenService.getLoginUserApplet().getUserid();
+ List<OrderGood> list = orderGoodService.list(new LambdaQueryWrapper<OrderGood>().eq(OrderGood::getOrderId, order.getId()));
+ List<Integer> goodsIds = list.stream().map(OrderGood::getGoodsId).collect(Collectors.toList());
+ this.remove(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid).in(ShoppingCart::getGoodsId, goodsIds));
+ return R.ok();
+ }
+
+
+ /**
+ * 定时任务关闭订单
+ */
+ @Override
+ public void closeOrder() {
+ //订单支付数据
+ long second = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
+ Set<String> orderPayment = redisTemplate.opsForZSet().rangeByScore("OrderPayment", 0, second);
+ if(orderPayment.size() > 0){
+ List<Order> list = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getOrderNumber, orderPayment));
+ for (Order order : list) {
+ if(null == order || order.getPayStatus() != 1){
+ redisTemplate.opsForZSet().remove("OrderPayment", order.getOrderNumber());
+ continue;
+ }
+ //开始执行关闭订单操作
+ CloseOrderResult closeOrderResult = PaymentUtil.closeOrder(order.getOrderNumber());
+ if((null == closeOrderResult || !closeOrderResult.getRa_Status().equals("100")) &&
+ Arrays.asList("0", "4", "101", "10080000", "10080002", "10083004", "10083005").contains(closeOrderResult.getRb_Code())){
+ redisTemplate.opsForZSet().add("OrderPayment", order.getOrderNumber(), 0);
+ log.error("关闭订单失败:{}---->{}", order.getOrderNumber(), JSON.toJSONString(closeOrderResult));
+ }
+ redisTemplate.opsForZSet().remove("OrderPayment", order.getOrderNumber());
+ }
+ }
+
+ //快递支付
+ Set<String> materialFlowPayment = redisTemplate.opsForZSet().rangeByScore("MaterialFlowPayment", 0, second);
+ if(materialFlowPayment.size() > 0){
+ materialFlowPayment.forEach(s->s.substring(1));
+ List<Order> list = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getOrderNumber, materialFlowPayment));
+ for (Order order : list) {
+ if(null == order || order.getPayStatus() != 1){
+ redisTemplate.opsForZSet().remove("MaterialFlowPayment", order.getOrderNumber());
+ continue;
+ }
+ //开始执行关闭订单操作
+ CloseOrderResult closeOrderResult = PaymentUtil.closeOrder("K" + order.getOrderNumber());
+ if((null == closeOrderResult || !closeOrderResult.getRa_Status().equals("100")) &&
+ Arrays.asList("0", "4", "101", "10080000", "10080002", "10083004", "10083005").contains(closeOrderResult.getRb_Code())){
+ redisTemplate.opsForZSet().add("MaterialFlowPayment", order.getOrderNumber(), 0);
+ log.error("关闭订单失败:{}---->{}", order.getOrderNumber(), JSON.toJSONString(closeOrderResult));
+ }
+ redisTemplate.opsForZSet().remove("MaterialFlowPayment", order.getOrderNumber());
+ }
+ }
+ }
}
--
Gitblit v1.7.1