会员购买完善
This commit is contained in:
@@ -3,14 +3,13 @@ package com.czg.service.market.service.impl;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.dto.shopuser.ShopUserAddDTO;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.market.dto.MemberConfigDTO;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.czg.account.entity.UserInfo;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.market.service.TbMemberConfigService;
|
||||
import com.czg.account.service.UserInfoService;
|
||||
import com.czg.market.vo.MemberConfigVO;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.market.dto.MemberOrderDTO;
|
||||
@@ -45,6 +44,8 @@ public class MemberOrderServiceImpl extends ServiceImpl<MemberOrderMapper, Membe
|
||||
@DubboReference
|
||||
private UserInfoService userInfoService;
|
||||
@DubboReference
|
||||
private UShopUserService uShopUserService;
|
||||
@DubboReference
|
||||
private ShopUserService shopUserService;
|
||||
@DubboReference
|
||||
private TbMemberConfigService memberConfigService;
|
||||
@@ -58,30 +59,53 @@ public class MemberOrderServiceImpl extends ServiceImpl<MemberOrderMapper, Membe
|
||||
ShopInfo shopInfo = shopInfoService.getById(orderDTO.getShopId());
|
||||
AssertUtil.isNull(shopInfo, "生成订单失败,店铺信息不存在");
|
||||
|
||||
if (orderDTO.getUserId() != null) {
|
||||
UserInfo userInfo = userInfoService.getById(orderDTO.getUserId());
|
||||
AssertUtil.isNull(userInfo, "生成订单失败,用户信息不存在");
|
||||
}
|
||||
|
||||
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getSourceShopId, orderDTO.getShopId()).eq(ShopUser::getUserId, orderDTO.getUserId()));
|
||||
AssertUtil.isNull(shopUser, "生成订单失败,用户信息不存在");
|
||||
UserInfo userInfo = userInfoService.getById(orderDTO.getUserId());
|
||||
AssertUtil.isNull(userInfo, "生成订单失败,用户信息不存在");
|
||||
|
||||
|
||||
MemberConfigVO memberConfigVO = memberConfigService.detail(shopInfo.getId());
|
||||
if(memberConfigVO.getConfigList() == null || memberConfigVO.getConfigList().isEmpty()) {
|
||||
throw new CzgException("会员开通方案未配置,请联系店铺");
|
||||
|
||||
if (memberConfigVO.getIsSubmitInfo() == 1) {
|
||||
AssertUtil.isBlank(orderDTO.getBirthDay(), "生日不能为空");
|
||||
AssertUtil.isBlank(orderDTO.getNickName(), "名称不能为空");
|
||||
AssertUtil.isNull(orderDTO.getSex(), "性别不能为空");
|
||||
|
||||
userInfo.setSex(orderDTO.getSex());
|
||||
userInfo.setNickName(orderDTO.getNickName());
|
||||
userInfo.setBirthDay(orderDTO.getBirthDay());
|
||||
}
|
||||
|
||||
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getUserId, orderDTO.getUserId()).eq(ShopUser::getSourceShopId, orderDTO.getShopId()));
|
||||
if (shopUser == null) {
|
||||
uShopUserService.join(orderDTO.getShopId(), orderDTO.getUserId(), new ShopUserAddDTO()
|
||||
.setPhone(userInfo.getPhone())
|
||||
.setSex(userInfo.getSex())
|
||||
.setHeadImg(userInfo.getHeadImg())
|
||||
.setAmount(BigDecimal.ZERO)
|
||||
.setBirthDay(userInfo.getBirthDay())
|
||||
.setIsVip(0)
|
||||
.setAccountPoints(0)
|
||||
.setNickName(userInfo.getNickName())
|
||||
);
|
||||
}
|
||||
|
||||
MemberConfigDTO.ConfigList configItem = memberConfigVO.getConfigList().stream()
|
||||
.filter(item -> item.getName().equals(orderDTO.getName()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new CzgException("会员开通方案未配置,请联系店铺"));
|
||||
|
||||
if ("PAY".equals(memberConfigVO.getOpenType())){
|
||||
if(memberConfigVO.getConfigList() == null || memberConfigVO.getConfigList().isEmpty()) {
|
||||
throw new CzgException("会员开通方案未配置,请联系店铺");
|
||||
}
|
||||
AssertUtil.isBlank(orderDTO.getName(), "方案名称不能为空");
|
||||
AssertUtil.isNull(orderDTO.getNum(), "开通周期数不为空");
|
||||
|
||||
MemberConfigDTO.ConfigList configItem = memberConfigVO.getConfigList().stream()
|
||||
.filter(item -> item.getName().equals(orderDTO.getName()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new CzgException("会员开通方案未配置,请联系店铺"));
|
||||
|
||||
//生成订单
|
||||
MemberOrder orderInfo = new MemberOrder();
|
||||
|
||||
orderInfo.setOrderNo(orderDTO.getPlatformType() + IdUtil.getSnowflakeNextId());
|
||||
orderInfo.setOrderNo(orderDTO.getPlatformType() + "ME" + IdUtil.getSnowflakeNextId());
|
||||
orderInfo.setShopId(orderDTO.getShopId());
|
||||
orderInfo.setPayAmount(BigDecimal.ZERO);
|
||||
orderInfo.setStatus(OrderStatusEnums.UNPAID.getCode());
|
||||
|
||||
@@ -317,10 +317,6 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
|
||||
|
||||
// 条件开通
|
||||
if (memberOrderId == null) {
|
||||
if (memberConfigVO.getConfigList() == null || memberConfigVO.getConfigList().isEmpty()) {
|
||||
throw new CzgException("会员开通方案未配置,请联系店铺");
|
||||
}
|
||||
|
||||
AssertUtil.isTrue(!"CONDITION".equals(memberConfigVO.getOpenType()), "开通方式未开启");
|
||||
|
||||
for (MemberConfigDTO.condition item : memberConfigVO.getConditionList()) {
|
||||
@@ -328,15 +324,15 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
|
||||
case "BIND_PHONE" -> StrUtil.isNotBlank(shopUser.getPhone());
|
||||
case "ORDER" ->
|
||||
orderInfoService.count(new QueryWrapper().eq(OrderInfo::getShopId, shopUser.getSourceShopId()).eq(OrderInfo::getUserId, shopUser.getUserId())
|
||||
.notIn(OrderInfo::getStatus, OrderStatusEnums.UNPAID.getCode(), OrderStatusEnums.CANCELLED.getCode())) > Integer.parseInt(item.getValue());
|
||||
.notIn(OrderInfo::getStatus, OrderStatusEnums.UNPAID.getCode(), OrderStatusEnums.CANCELLED.getCode())) >= Integer.parseInt(item.getValue());
|
||||
case "COST_AMOUNT" ->
|
||||
orderInfoService.list(new QueryWrapper().eq(OrderInfo::getShopId, shopUser.getSourceShopId()).eq(OrderInfo::getUserId, shopUser.getUserId())
|
||||
.notIn(OrderInfo::getStatus, OrderStatusEnums.UNPAID.getCode(), OrderStatusEnums.CANCELLED.getCode()))
|
||||
.stream().map(OrderInfo::getPayAmount).reduce(BigDecimal.ZERO, BigDecimal::add).compareTo(new BigDecimal(item.getValue())) > 0;
|
||||
.stream().map(OrderInfo::getPayAmount).reduce(BigDecimal.ZERO, BigDecimal::add).compareTo(new BigDecimal(item.getValue())) >= 0;
|
||||
case "RECHARGE_AMOUNT" ->
|
||||
paymentService.list(new QueryWrapper().eq(OrderPayment::getShopId, shopUser.getSourceShopId())
|
||||
.eq(OrderPayment::getSourceId, shopUser.getId()).isNotNull(OrderPayment::getTradeNumber))
|
||||
.stream().map(OrderPayment::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add).compareTo(new BigDecimal(item.getValue())) > 0;
|
||||
.stream().map(OrderPayment::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add).compareTo(new BigDecimal(item.getValue())) >= 0;
|
||||
default -> throw new CzgException("会员开通条件类型错误");
|
||||
};
|
||||
if (!canOpen) {
|
||||
@@ -344,15 +340,18 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
|
||||
}
|
||||
}
|
||||
|
||||
if (DateUtil.isIn(DateUtil.date(), DateUtil.date(shopUser.getStartTime()), DateUtil.date(shopUser.getEndTime()))) {
|
||||
if (shopUser.getStartTime() != null && shopUser.getEndTime() != null && DateUtil.isIn(DateUtil.date(), DateUtil.date(shopUser.getStartTime()), DateUtil.date(shopUser.getEndTime()))) {
|
||||
throw new ApiNotPrintException("您已经是会员");
|
||||
}
|
||||
shopUser.setMemberLevelId(levelConfig.getId());
|
||||
shopUser.setStartTime(DateUtil.date().toLocalDateTime());
|
||||
|
||||
// shopUser.setEndTime(shopUser.getStartTime().plusDays(30));
|
||||
shopUser.setEndTime(shopUser.getStartTime().plusDays(20000));
|
||||
// 购买开通
|
||||
} else {
|
||||
if (memberConfigVO.getConfigList() == null || memberConfigVO.getConfigList().isEmpty()) {
|
||||
throw new CzgException("会员开通方案未配置,请联系店铺");
|
||||
}
|
||||
|
||||
if (shopUser.getStartTime() == null || shopUser.getEndTime().isBefore(DateUtil.date().toLocalDateTime())) {
|
||||
shopUser.setStartTime(DateUtil.date().toLocalDateTime());
|
||||
|
||||
Reference in New Issue
Block a user