From 6f5e0af7b4e3c4e6d2bcd33bafb6649727e98b37 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期五, 06 六月 2025 18:33:44 +0800
Subject: [PATCH] 开发商户端相关接口
---
ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java | 192 +++++++++++++++++++++++++++++++++++++-----------
1 files changed, 148 insertions(+), 44 deletions(-)
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
index 2d4ade6..1ef2d06 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
@@ -17,7 +17,6 @@
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.ruoyi.common.core.constant.CacheConstants;
-import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.enums.UserStatus;
import com.ruoyi.common.core.exception.ServiceException;
@@ -29,6 +28,8 @@
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.utils.CodeFactoryUtil;
import com.ruoyi.common.security.utils.SecurityUtils;
+import com.ruoyi.goods.api.domain.LotteryEvent;
+import com.ruoyi.goods.api.service.LotteryEventClient;
import com.ruoyi.order.config.WxPayConfiguration;
import com.ruoyi.order.domain.dto.*;
import com.ruoyi.order.domain.pojo.account.OrderPayment;
@@ -72,7 +73,6 @@
import lombok.extern.log4j.Log4j2;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -80,7 +80,6 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
-import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@@ -154,18 +153,20 @@
@Resource
private OrderPaymentService orderPaymentService;
-
+
@Resource
private ProfitSharingService profitSharingService;
-
+
@Resource
private OrderRefundService orderRefundService;
-
+
@Value("${wx.pay.callbackPath}")
private String callbackPath;
-
-
+ @Resource
+ private LotteryEventClient lotteryEventClient;
+
+
/**
* @description: buyGoods
* @param: appSureOrderDto
@@ -1544,6 +1545,13 @@
appPlaceOrderVo.setPaySign(payArr[5]);
appPlaceOrderVo.setPrepayId(orderPayment.getPrepayId());
// 返回AppPlaceOrderVo对象
+ List<LotteryEvent> data = lotteryEventClient.getLotteryEventList(2).getData();
+ if (data.size() > 0) {
+ long count = data.stream().filter(s -> s.getPayMoney().compareTo(order.getPayMoney()) >= 0).count();
+ appPlaceOrderVo.setLotteryDraw(count > 0);
+ } else {
+ appPlaceOrderVo.setLotteryDraw(false);
+ }
return appPlaceOrderVo;
}
@@ -2405,20 +2413,20 @@
Long shopId = shopRelUserVo.getShopId();
Shop shop = remoteShopService.getShop(shopId).getData();
//平台奖品判断
- if (memberGiftRecord.getGiftFrom() == 1) {
+ if (memberGiftRecord.getGiftFrom() == 1 && memberGiftRecord.getPrizeFrom() == 1) {
BirthdayCard birthdayCard = remoteMemberService.getBirthdayCard().getData();
//判断生日活动状态
- if(birthdayCard!=null&&birthdayCard.getCardStatus()==1){
+ if (birthdayCard != null && birthdayCard.getCardStatus() == 1) {
shop = remoteShopService.getShop(shopId).getData();
//判断指定区域全部店铺
- if(birthdayCard.getAreaFlag()==2&&birthdayCard.getShopFlag()==1&&!StringUtils.checkString(birthdayCard.getDesignatedArea(),shop.getShopCityCode())){
+ if (birthdayCard.getAreaFlag() == 2 && birthdayCard.getShopFlag() == 1 && !StringUtils.checkString(birthdayCard.getDesignatedArea(), shop.getShopCityCode())) {
throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR);
}
//判断指定店铺
- if(birthdayCard.getShopFlag()==2&&!StringUtils.checkString(birthdayCard.getApplicableShop(),shopId.toString())){
+ if (birthdayCard.getShopFlag() == 2 && !StringUtils.checkString(birthdayCard.getApplicableShop(), shopId.toString())) {
throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR);
}
- }else{
+ } else {
throw new ServiceException(AppErrorConstant.BIRTHDAY_CARD_ERROR);
}
}
@@ -2427,29 +2435,35 @@
throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR);
}
Member member = remoteMemberService.getMember(memberGiftRecord.getUserId()).getData();
-
+
merVerifyAwardVo.setUserName(member.getRealName());
merVerifyAwardVo.setUserMobile(member.getMobile());
- if (memberGiftRecord.getGiftFrom() == 1) {
- merVerifyAwardVo.setGiftFrom("平台生日卡");
+ if (memberGiftRecord.getPrizeFrom() == 1) {
+ if (memberGiftRecord.getGiftFrom() == 1) {
+ merVerifyAwardVo.setGiftFrom("平台生日卡");
+ } else {
+ merVerifyAwardVo.setGiftFrom("商户生日卡");
+ }
} else {
- merVerifyAwardVo.setGiftFrom("商户生日卡");
+ merVerifyAwardVo.setGiftFrom("抽奖");
}
merVerifyAwardVo.setGiftType(memberGiftRecord.getGiftType());
List<BirthdayGiftSendDto> giftSendDtoList = new ArrayList<>();
BirthdayGiftSendDto birthdayGiftSendDto = new BirthdayGiftSendDto();
switch (memberGiftRecord.getGiftType()) {
case 1:
- merVerifyAwardVo.setGiftName(memberGiftRecord.getCouponName());
- merVerifyAwardVo.setGiftNumber(Double.valueOf(memberGiftRecord.getCouponNumber()));
- birthdayGiftSendDto.setUserId(memberGiftRecord.getUserId());
- birthdayGiftSendDto.setGiftType(memberGiftRecord.getGiftType());
- birthdayGiftSendDto.setGiftFrom(memberGiftRecord.getGiftFrom());
- birthdayGiftSendDto.setShopId(memberGiftRecord.getShopId());
- birthdayGiftSendDto.setCouponId(memberGiftRecord.getCouponId());
- birthdayGiftSendDto.setCouponNumber(memberGiftRecord.getCouponNumber());
- giftSendDtoList.add(birthdayGiftSendDto);
- remoteCouponService.sendCouponGift(giftSendDtoList);
+ if (memberGiftRecord.getPrizeFrom() == 1) {
+ merVerifyAwardVo.setGiftName(memberGiftRecord.getCouponName());
+ merVerifyAwardVo.setGiftNumber(Double.valueOf(memberGiftRecord.getCouponNumber()));
+ birthdayGiftSendDto.setUserId(memberGiftRecord.getUserId());
+ birthdayGiftSendDto.setGiftType(memberGiftRecord.getGiftType());
+ birthdayGiftSendDto.setGiftFrom(memberGiftRecord.getGiftFrom());
+ birthdayGiftSendDto.setShopId(memberGiftRecord.getShopId());
+ birthdayGiftSendDto.setCouponId(memberGiftRecord.getCouponId());
+ birthdayGiftSendDto.setCouponNumber(memberGiftRecord.getCouponNumber());
+ giftSendDtoList.add(birthdayGiftSendDto);
+ remoteCouponService.sendCouponGift(giftSendDtoList);
+ }
break;
case 2:
Goods goods = remoteGoodsService.getGoods(memberGiftRecord.getGoodsId()).getData();
@@ -2472,10 +2486,16 @@
birthdayGiftSendDto.setGoodsNumber(memberGiftRecord.getGoodsNumber());
giftSendDtoList.add(birthdayGiftSendDto);
consumerGoodsService.sendGoodsGift(giftSendDtoList);
+ //抽奖奖品中的平台商品需要生成订单数据
+ if (memberGiftRecord.getPrizeFrom() == 2) {
+ addOrder(memberGiftRecord.getShopId(), memberGiftRecord.getUserId(), goods, memberGiftRecord.getGoodsNumber(), memberGiftRecord.getGiftId());
+ }
break;
case 3:
- merVerifyAwardVo.setGiftName("现金");
- merVerifyAwardVo.setGiftNumber(memberGiftRecord.getMoney().doubleValue());
+ if (memberGiftRecord.getPrizeFrom() == 1) {
+ merVerifyAwardVo.setGiftName("现金");
+ merVerifyAwardVo.setGiftNumber(memberGiftRecord.getMoney().doubleValue());
+ }
break;
case 4:
merVerifyAwardVo.setGiftName(memberGiftRecord.getGiftName());
@@ -2503,8 +2523,65 @@
merVerifyAwardVo.setVerifyStatus(2);
return merVerifyAwardVo;
}
-
-
+
+
+ /**
+ * 核销抽奖的平台商品生成订单
+ *
+ * @param shopId
+ * @param userId
+ * @param goods
+ * @param goodsNum
+ */
+ public void addOrder(Long shopId, Long userId, Goods goods, Integer goodsNum, String giftId) {
+ Order order = new Order();
+ order.setOrderId(IdUtils.simpleUUID());
+ order.setDelFlag(0);
+ order.setOrderStatus(3);
+ order.setOrderNo(CodeFactoryUtil.getShopOrderNo());
+ order.setOrderFrom(4);
+ order.setShopId(shopId);
+ order.setUserId(userId);
+ order.setOrderMoney(BigDecimal.ZERO);
+ order.setCouponMoney(BigDecimal.ZERO);
+ order.setDiscountMoney(BigDecimal.ZERO);
+ order.setReceivableMoney(BigDecimal.ZERO);
+ order.setPayType(1);
+ order.setPayMoney(BigDecimal.ZERO);
+ order.setOrderRemark("抽奖订单");
+ order.setCreateTime(new Date());
+ order.setPayTime(new Date());
+ order.setUseTime(new Date());
+ order.setUseUserId(userId);
+ order.setGoodsNum(goodsNum);
+ order.setReceivableDeposit(BigDecimal.ZERO);
+ order.setCloseFlag(1);
+ order.setActivityId(giftId);
+ this.save(order);
+ OrderGoods orderGoods = new OrderGoods();
+ orderGoods.setOrderGoodsId(IdUtils.simpleUUID());
+ orderGoods.setDelFlag(0);
+ orderGoods.setOrderId(order.getOrderId());
+ orderGoods.setGoodsId(goods.getGoodsId());
+ orderGoods.setBuyNum(goodsNum);
+ orderGoods.setGoodsPrice(goods.getSalesPrice());
+ orderGoods.setGoodsDeposit(goods.getSubscription());
+ orderGoods.setGoodsTotalMoney(goods.getSalesPrice().multiply(new BigDecimal(goodsNum)));
+ orderGoods.setGoodsReceivableMoney(BigDecimal.ZERO);
+ orderGoods.setCycleNumFlag(goods.getCycleNumFlag());
+ orderGoods.setServiceNum(goods.getServiceNum());
+ orderGoods.setGoodsType(goods.getGoodsType());
+ orderGoods.setGoodsName(goods.getGoodsName());
+ GoodsFile goodsFile = remoteGoodsService.getGoodsFile(goods.getGoodsId()).getData();
+ if (null != goodsFile) {
+ orderGoods.setGoodsPicture(goodsFile.getFileUrl());
+ }
+ orderGoods.setGoodsIntroduction(goods.getGoodsIntroduction());
+ orderGoods.setGoodsTag(goods.getGoodsTags());
+ orderGoodsService.save(orderGoods);
+ }
+
+
/**
* 收银未结清订单列表
*
@@ -2521,14 +2598,14 @@
if (merMemberNoClearOrderVo.getUnPaidMoney() == null) {
merMemberNoClearOrderVo.setUnPaidMoney(zeroBig);
}
- if(merMemberNoClearOrderVo.getUnPaidMoney().compareTo(zeroBig)<0){
+ if (merMemberNoClearOrderVo.getUnPaidMoney().compareTo(zeroBig) < 0) {
merMemberNoClearOrderVo.setUnPaidMoney(zeroBig);
}
}
}
return merMemberNoClearOrderVoList;
}
-
+
/**
* 结清订单
*
@@ -2670,8 +2747,12 @@
goodsRealPrice = goodsTotalPrice;
//优惠券计算
if (memberCouponId != null) {
- appMemberCouponVo = appMemberCouponVoMap.get(memberCouponId);
+ log.info("使用优惠券:{}", memberCouponId);
+ appMemberCouponVo = appMemberCouponVoMap.get(memberCouponId.toString());
+ log.info("匹配的优惠券:{}", JSON.toJSONString(appMemberCouponVo));
if (null != appMemberCouponVo && (StringUtils.isBlank(appMemberCouponVo.getRelGoodsIds()) || appMemberCouponVo.getRelGoodsIds().contains(goodsId))) {
+ log.info("可以使用优惠券:{}", JSON.toJSONString(appMemberCouponVo));
+ couponType = appMemberCouponVo.getCouponType();
couponType = appMemberCouponVo.getCouponType();
if (couponType == 1 && appMemberCouponVo.getMoneyThreshold() != null && appMemberCouponVo.getDiscountMoney() != null) {
moneyThreshold = appMemberCouponVo.getMoneyThreshold();
@@ -2841,6 +2922,7 @@
consumerGoodsService.saveBatchConsumerGoods(consumerGoodsList);
//减去优惠券
if (StringUtils.isNotBlank(memberCouponSJ.toString())) {
+ log.info("修改优惠券使用状态:{}", JSON.toJSONString(memberCouponSJ));
remoteCouponService.useMemberCoupon(memberCouponSJ.toString());
}
//更新会员消费记录
@@ -2950,9 +3032,27 @@
if (merMemberNoClearOrderVo.getUnPaidMoney() == null) {
merMemberNoClearOrderVo.setUnPaidMoney(zeroBig);
}
- if(merMemberNoClearOrderVo.getUnPaidMoney().compareTo(zeroBig)<0){
+ if (merMemberNoClearOrderVo.getUnPaidMoney().compareTo(zeroBig) < 0) {
merMemberNoClearOrderVo.setUnPaidMoney(zeroBig);
}
+ List<MerCouponGoodsListVo> goodsList = new ArrayList<>();
+ orderGoodsService.listByOrderId(merMemberNoClearOrderVo.getOrderId()).forEach(orderGoodsVo -> {
+ MerCouponGoodsListVo merCouponGoodsListVo = new MerCouponGoodsListVo();
+ merCouponGoodsListVo.setGoodsId(orderGoodsVo.getGoodsId());
+ merCouponGoodsListVo.setGoodsName(orderGoodsVo.getGoodsName());
+ merCouponGoodsListVo.setGoodsNum(orderGoodsVo.getBuyNum());
+ if (orderGoodsVo.getGoodsType() == 1) {
+ merCouponGoodsListVo.setGoodsType("周期");
+ } else if (orderGoodsVo.getGoodsType() == 2) {
+ merCouponGoodsListVo.setGoodsType("服务");
+ } else if (orderGoodsVo.getGoodsType() == 3) {
+ merCouponGoodsListVo.setGoodsType("体验");
+ } else if (orderGoodsVo.getGoodsType() == 4) {
+ merCouponGoodsListVo.setGoodsType("单品");
+ }
+ goodsList.add(merCouponGoodsListVo);
+ });
+ merMemberNoClearOrderVo.setGoodsList(goodsList);
}
}
return merMemberNoClearOrderVoList;
@@ -4719,17 +4819,17 @@
if (memberGiftRecord.getGiftFrom() == 1) {
BirthdayCard birthdayCard = remoteMemberService.getBirthdayCard().getData();
//判断生日活动状态
- if(birthdayCard!=null&&birthdayCard.getCardStatus()==1){
+ if (birthdayCard != null && birthdayCard.getCardStatus() == 1) {
shop = remoteShopService.getShop(shopId).getData();
//判断指定区域全部店铺
- if(birthdayCard.getAreaFlag()==2&&birthdayCard.getShopFlag()==1&&!StringUtils.checkString(birthdayCard.getDesignatedArea(),shop.getShopCityCode())){
+ if (birthdayCard.getAreaFlag() == 2 && birthdayCard.getShopFlag() == 1 && !StringUtils.checkString(birthdayCard.getDesignatedArea(), shop.getShopCityCode())) {
throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR);
}
//判断指定店铺
- if(birthdayCard.getShopFlag()==2&&!StringUtils.checkString(birthdayCard.getApplicableShop(),shopId.toString())){
+ if (birthdayCard.getShopFlag() == 2 && !StringUtils.checkString(birthdayCard.getApplicableShop(), shopId.toString())) {
throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR);
}
- }else{
+ } else {
throw new ServiceException(AppErrorConstant.BIRTHDAY_CARD_ERROR);
}
}
@@ -4737,16 +4837,20 @@
if (memberGiftRecord.getGiftFrom() == 2 && !memberGiftRecord.getShopId().equals(shopId)) {
throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR);
}
-
+
merVerifyAwardVo.setUserName(member.getRealName());
merVerifyAwardVo.setUserMobile(member.getMobile());
- if (memberGiftRecord.getGiftFrom() == 1) {
- merVerifyAwardVo.setGiftFrom("平台生日卡");
+ if (1 == memberGiftRecord.getPrizeFrom()) {
+ if (memberGiftRecord.getGiftFrom() == 1) {
+ merVerifyAwardVo.setGiftFrom("平台生日卡");
+ } else {
+ merVerifyAwardVo.setGiftFrom("商户生日卡");
+ }
} else {
- merVerifyAwardVo.setGiftFrom("商户生日卡");
+ merVerifyAwardVo.setGiftFrom("平台抽奖");
}
merVerifyAwardVo.setGiftType(memberGiftRecord.getGiftType());
- //礼物类型1优惠券2商品3现金4实物
+ //礼物类型1优惠券2商品3现金4实物5积分
switch (memberGiftRecord.getGiftType()) {
case 1:
merVerifyAwardVo.setGiftName(memberGiftRecord.getCouponName());
--
Gitblit v1.7.1