From 6d959c0e2c777f3cb1f4f9d692eb8997eb736ba5 Mon Sep 17 00:00:00 2001
From: Hentua <wangdoubleone@gmail.com>
Date: Thu, 25 Jan 2024 00:14:54 +0800
Subject: [PATCH] fix
---
src/main/java/cc/mrbird/febs/vip/controller/ApiMallVipConfigController.java | 1
src/main/java/cc/mrbird/febs/vip/service/IMallVipBenefitsService.java | 2
src/main/java/cc/mrbird/febs/vip/service/impl/MallVipBenefitsServiceImpl.java | 121 +++++++++++++++++++++++++++++++++++++++-
3 files changed, 121 insertions(+), 3 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/vip/controller/ApiMallVipConfigController.java b/src/main/java/cc/mrbird/febs/vip/controller/ApiMallVipConfigController.java
index b8af531..60a38ac 100644
--- a/src/main/java/cc/mrbird/febs/vip/controller/ApiMallVipConfigController.java
+++ b/src/main/java/cc/mrbird/febs/vip/controller/ApiMallVipConfigController.java
@@ -51,6 +51,7 @@
@ApiOperation(value = "领取权益")
@PostMapping(value = "/getBenefitsData/{id}")
public FebsResponse getBenefitsData(@PathVariable("id") Long id) {
+ mallVipBenefitsService.getBenefits(id);
return new FebsResponse().success().message("领取成功");
}
}
diff --git a/src/main/java/cc/mrbird/febs/vip/service/IMallVipBenefitsService.java b/src/main/java/cc/mrbird/febs/vip/service/IMallVipBenefitsService.java
index 5187343..df60c35 100644
--- a/src/main/java/cc/mrbird/febs/vip/service/IMallVipBenefitsService.java
+++ b/src/main/java/cc/mrbird/febs/vip/service/IMallVipBenefitsService.java
@@ -16,4 +16,6 @@
void delVipBenefits(Long id);
void editVipBenefits(MallVipBenefits mallVipBenefits);
+
+ void getBenefits(Long id);
}
diff --git a/src/main/java/cc/mrbird/febs/vip/service/impl/MallVipBenefitsServiceImpl.java b/src/main/java/cc/mrbird/febs/vip/service/impl/MallVipBenefitsServiceImpl.java
index 07d20cb..636c8c4 100644
--- a/src/main/java/cc/mrbird/febs/vip/service/impl/MallVipBenefitsServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/vip/service/impl/MallVipBenefitsServiceImpl.java
@@ -1,8 +1,13 @@
package cc.mrbird.febs.vip.service.impl;
import cc.mrbird.febs.common.entity.QueryRequest;
+import cc.mrbird.febs.common.enumerates.OrderStatusEnum;
import cc.mrbird.febs.common.exception.FebsException;
-import cc.mrbird.febs.mall.entity.MallNewsInfo;
+import cc.mrbird.febs.common.utils.LoginUserUtil;
+import cc.mrbird.febs.common.utils.MallUtils;
+import cc.mrbird.febs.mall.entity.*;
+import cc.mrbird.febs.mall.mapper.*;
+import cc.mrbird.febs.mall.vo.AdminMailGoodsDetailVo;
import cc.mrbird.febs.mall.vo.AdminMallNewsInfoVo;
import cc.mrbird.febs.vip.entity.MallVipBenefits;
import cc.mrbird.febs.vip.entity.MallVipBenefitsDetails;
@@ -11,8 +16,12 @@
import cc.mrbird.febs.vip.service.IMallVipBenefitsDetailsService;
import cc.mrbird.febs.vip.service.IMallVipBenefitsService;
import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
@@ -20,12 +29,21 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import java.math.BigDecimal;
+import java.util.Date;
+
@Slf4j
@Service
@RequiredArgsConstructor
public class MallVipBenefitsServiceImpl extends ServiceImpl<MallVipBenefitsMapper, MallVipBenefits> implements IMallVipBenefitsService {
private final IMallVipBenefitsDetailsService mallVipBenefitsDetailsService;
+ private final MallMemberCouponMapper mallMemberCouponMapper;
+ private final MallGoodsCouponMapper mallGoodsCouponMapper;
+ private final MallGoodsMapper mallGoodsMapper;
+ private final MallAddressInfoMapper mallAddressInfoMapper;
+ private final MallOrderInfoMapper mallOrderInfoMapper;
+ private final MallOrderItemMapper mallOrderItemMapper;
@Override
public IPage<MallVipBenefits> vipBenefitsListInPage(QueryRequest request) {
@@ -58,7 +76,7 @@
}
@Override
- @Transactional
+ @Transactional(rollbackFor = Exception.class)
public void delVipBenefits(Long id) {
this.baseMapper.deleteById(id);
@@ -68,7 +86,7 @@
}
@Override
- @Transactional
+ @Transactional(rollbackFor = Exception.class)
public void editVipBenefits(MallVipBenefits mallVipBenefits) {
if (mallVipBenefits.getId() == null) {
throw new FebsException("缺少重要参数");
@@ -88,4 +106,101 @@
}
+ @Override
+ public void getBenefits(Long id) {
+ MallMember member = LoginUserUtil.getLoginUser();
+
+ MallVipBenefitsDetails benefits = mallVipBenefitsDetailsService.getById(id);
+ if (benefits == null) {
+ throw new FebsException("权益不存在");
+ }
+
+ Integer linkType = benefits.getLinkType();
+
+ // 商品
+ if (linkType == 2) {
+ MallGoods goods = mallGoodsMapper.selectGoodsDetailById(Long.parseLong(benefits.getContent()));
+ if (goods == null) {
+ throw new FebsException("商品不存在");
+ }
+
+ LambdaQueryWrapper<MallAddressInfo> query = new LambdaQueryWrapper<>();
+ query.eq(MallAddressInfo::getMemberId, member.getId())
+ .eq(MallAddressInfo::getIsDefault, 1)
+ .last("limit 1");
+ MallAddressInfo address = mallAddressInfoMapper.selectOne(query);
+ if (address == null) {
+ throw new FebsException("请设置默认地址");
+ }
+
+ String orderNo = MallUtils.getOrderNum();
+ MallOrderInfo orderInfo = new MallOrderInfo();
+ orderInfo.setOrderNo(orderNo);
+ orderInfo.setOrderTime(new Date());
+ orderInfo.setMemberId(member.getId());
+ orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue());
+ orderInfo.setOrderType(goods.getGoodsType());
+ orderInfo.setDeliveryType(2);
+ orderInfo.setCarriage(BigDecimal.ZERO);
+ orderInfo.setAmount(BigDecimal.ZERO);
+ orderInfo.setAddressId(address.getId());
+ orderInfo.setName(address.getName());
+ orderInfo.setPhone(address.getPhone());
+ orderInfo.setIsHome(2);
+ orderInfo.setAddress(address.getProvince()+address.getCity()+address.getArea() + address.getAddress());
+ orderInfo.setLatitude(address.getLatitude());
+ orderInfo.setLongitude(address.getLongitude());
+
+ MallOrderItem orderItem = new MallOrderItem();
+ if (goods.getGoodsType() == 2) {
+ orderItem.setAmount(BigDecimal.ZERO);
+ orderItem.setCnt(1);
+ orderItem.setOrderId(orderInfo.getId());
+ orderItem.setPrice(goods.getScore());
+ orderItem.setGoodsId(goods.getId());
+ orderItem.setGoodsName(goods.getGoodsName());
+ orderItem.setStyleName(goods.getGoodsName());
+ orderItem.setSkuName(goods.getGoodsName());
+ orderItem.setSkuImage(goods.getThumb());
+ orderItem.setState(1);
+ } else {
+ MallGoodsSku sku = goods.getStyles().get(0).getSkus().get(0);
+
+ orderItem.setAmount(BigDecimal.ZERO);
+ orderItem.setCnt(1);
+ orderItem.setOrderId(orderInfo.getId());
+ orderItem.setPrice(sku.getPresentPrice());
+ orderItem.setGoodsId(sku.getGoodsId());
+ orderItem.setGoodsName(sku.getGoodsName());
+ orderItem.setSkuId(sku.getId());
+ orderItem.setState(1);
+ orderItem.setStyleName(sku.getStyleName());
+ orderItem.setSkuName(sku.getSkuName());
+ orderItem.setSkuImage(sku.getSkuImage());
+ orderItem.setIsNormal(goods.getIsNormal());
+ orderItem.setCostPrice(sku.getCostPrice());
+ }
+
+ mallOrderInfoMapper.insert(orderInfo);
+ mallOrderItemMapper.insert(orderItem);
+ }
+
+ // 优惠券
+ if (linkType == 3) {
+ MallGoodsCoupon coupon = mallGoodsCouponMapper.selectById(Long.parseLong(benefits.getContent()));
+ if (coupon == null) {
+ throw new FebsException("优惠券");
+ }
+ MallMemberCoupon memberCoupon = new MallMemberCoupon();
+ memberCoupon.setCouponId(coupon.getId());
+ memberCoupon.setCouponName(coupon.getName());
+ memberCoupon.setInviteId(member.getInviteId());
+ memberCoupon.setCouponUuid(IdUtil.simpleUUID());
+ memberCoupon.setState(1);
+ memberCoupon.setExpireTime(DateUtil.offsetDay(DateUtil.date(), coupon.getExpireDay()));
+ memberCoupon.setMemberId(member.getId());
+ mallMemberCouponMapper.insert(memberCoupon);
+ }
+ }
+
}
--
Gitblit v1.9.1