Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.account.mapper;
|
||||
|
||||
import com.czg.account.entity.ShopCouponProduct;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
|
||||
/**
|
||||
* 活动赠送商品表 映射层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-18
|
||||
*/
|
||||
public interface ShopCouponProductMapper extends BaseMapper<ShopCouponProduct> {
|
||||
|
||||
}
|
||||
@@ -1,15 +1,29 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.dto.ShopActivateDTO;
|
||||
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
||||
import com.czg.account.entity.ShopActivate;
|
||||
import com.czg.account.service.ShopActivateService;
|
||||
import com.czg.account.entity.ShopActivateInRecord;
|
||||
import com.czg.account.entity.ShopCoupon;
|
||||
import com.czg.account.entity.ShopCouponProduct;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.account.vo.CouponProductVo;
|
||||
import com.czg.enums.ShopUserFlowBizEnum;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.account.mapper.ShopActivateMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -21,6 +35,15 @@ import java.util.List;
|
||||
@DubboService
|
||||
public class ShopActivateServiceImpl extends ServiceImpl<ShopActivateMapper, ShopActivate> implements ShopActivateService {
|
||||
|
||||
@Resource
|
||||
private ShopCouponService couponService;
|
||||
@Resource
|
||||
private ShopActivateInRecordService inRecordService;
|
||||
@Resource
|
||||
private ShopCouponProductService couProductService;
|
||||
@Resource
|
||||
private ShopUserService shopUserService;
|
||||
|
||||
@Override
|
||||
public List<ShopActivateDTO> getList() {
|
||||
return queryChain().select()
|
||||
@@ -42,4 +65,106 @@ public class ShopActivateServiceImpl extends ServiceImpl<ShopActivateMapper, Sho
|
||||
BeanUtil.copyProperties(activateDTO, shopActivate);
|
||||
return updateById(shopActivate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveActivate(Long shopId, Long vipId, BigDecimal memAmount, Long relationId) {
|
||||
ShopActivate activate = queryChain().select().eq(ShopActivate::getShopId, shopId)
|
||||
.le(ShopActivate::getAmount, memAmount)
|
||||
.orderBy(ShopActivate::getGiftAmount, false)
|
||||
.one();
|
||||
if (ObjectUtil.isNull(activate)) {
|
||||
return;
|
||||
}
|
||||
//赠送优惠券
|
||||
if (activate.getIsGiftCoupon() == 1) {
|
||||
ShopCoupon shopCoupon = couponService.getById(activate.getCouponId());
|
||||
if (shopCoupon != null && shopCoupon.getStatus().equals(1) && shopCoupon.getLeftNumber() > activate.getNum()) {
|
||||
LocalDateTime start = LocalDateTime.now().with(LocalTime.MIN);
|
||||
LocalDateTime end = null;
|
||||
if ("fixed".equals(shopCoupon.getValidityType())) {
|
||||
//固定时间
|
||||
end = LocalDateTimeUtil.offset(start, shopCoupon.getValidDays(), ChronoUnit.DAYS).with(LocalTime.MAX);
|
||||
} else if ("custom".equals(shopCoupon.getValidityType())) {
|
||||
//自定义时间
|
||||
start = shopCoupon.getValidStartTime();
|
||||
end = shopCoupon.getValidEndTime();
|
||||
}
|
||||
List<ShopActivateInRecord> actGiveRecords = new ArrayList<>();
|
||||
if (shopCoupon.getType() == 1) {
|
||||
//满减
|
||||
ShopActivateInRecord record = new ShopActivateInRecord();
|
||||
record.setVipUserId(vipId);
|
||||
record.setCouponId(shopCoupon.getId());
|
||||
record.setName("满" + shopCoupon.getFullAmount() + "减" + shopCoupon.getDiscountAmount());
|
||||
record.setFullAmount(shopCoupon.getFullAmount());
|
||||
record.setDiscountAmount(shopCoupon.getDiscountAmount());
|
||||
record.setType(1);
|
||||
record.setNum(activate.getNum());
|
||||
record.setOverNum(activate.getNum());
|
||||
record.setShopId(shopId);
|
||||
record.setSourceActId(activate.getId());
|
||||
record.setSourceFlowId(relationId);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
record.setSource("activate");
|
||||
record.setCouponJson(getCouponJson(activate, shopCoupon, null));
|
||||
actGiveRecords.add(record);
|
||||
} else if (shopCoupon.getType() == 2) {
|
||||
List<CouponProductVo> couponProducts = couProductService.queryChain()
|
||||
.select(ShopCouponProduct::getProductId, ShopCouponProduct::getNum)
|
||||
.eq(ShopCouponProduct::getCouponId, shopCoupon.getId())
|
||||
.listAs(CouponProductVo.class);
|
||||
//商品券
|
||||
for (CouponProductVo actPro : couponProducts) {
|
||||
ShopActivateInRecord record = new ShopActivateInRecord();
|
||||
record.setVipUserId(vipId);
|
||||
record.setCouponId(shopCoupon.getId());
|
||||
record.setName("商品券");
|
||||
record.setType(2);
|
||||
record.setProId(actPro.getProductId());
|
||||
record.setNum(actPro.getNum() * activate.getNum());
|
||||
record.setOverNum(actPro.getNum() * activate.getNum());
|
||||
record.setShopId(shopId);
|
||||
record.setSourceActId(activate.getId());
|
||||
record.setSourceFlowId(relationId);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
record.setSource("activate");
|
||||
record.setCouponJson(getCouponJson(activate, shopCoupon, actPro));
|
||||
actGiveRecords.add(record);
|
||||
}
|
||||
}
|
||||
inRecordService.saveBatch(actGiveRecords);
|
||||
shopCoupon.setLeftNumber(shopCoupon.getLeftNumber() - activate.getNum());
|
||||
couponService.updateChain()
|
||||
.set(ShopCoupon::getLeftNumber, shopCoupon.getLeftNumber() - activate.getNum())
|
||||
.eq(ShopCoupon::getId, shopCoupon.getId())
|
||||
.update();
|
||||
}
|
||||
}
|
||||
//赠送金额
|
||||
if (activate.getGiftAmount() != null && activate.getGiftAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder()
|
||||
.id(vipId)
|
||||
.money(activate.getGiftAmount())
|
||||
.type(1)
|
||||
.remark("充值活动赠送")
|
||||
.relationId(relationId)
|
||||
.bizEnum(ShopUserFlowBizEnum.AWARD_IN)
|
||||
.build();
|
||||
//更新会员余额 并生成流水
|
||||
shopUserService.updateMoney(shopId, shopUserMoneyEditDTO);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getCouponJson(ShopActivate activate, ShopCoupon tbShopCoupon, CouponProductVo couProduct) {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("activate", JSONObject.toJSONString(activate));
|
||||
result.put("coupon", JSONObject.toJSONString(tbShopCoupon));
|
||||
if (couProduct != null) {
|
||||
result.put("couProduct", JSONObject.toJSONString(couProduct));
|
||||
}
|
||||
return result.toJSONString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.czg.account.entity.ShopCouponProduct;
|
||||
import com.czg.account.service.ShopCouponProductService;
|
||||
import com.czg.service.account.mapper.ShopCouponProductMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 活动赠送商品表 服务层实现。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-18
|
||||
*/
|
||||
@Service
|
||||
public class ShopCouponProductServiceImpl extends ServiceImpl<ShopCouponProductMapper, ShopCouponProduct> implements ShopCouponProductService {
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.dto.shopuser.*;
|
||||
@@ -13,7 +12,6 @@ import com.czg.account.service.ShopUserFlowService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.account.service.UserInfoService;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.enums.ShopUserFlowBizEnum;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.RedisService;
|
||||
@@ -21,12 +19,10 @@ import com.czg.service.account.mapper.ShopUserMapper;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryCondition;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
|
||||
@@ -77,12 +73,12 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateMoney(Long shopId, ShopUserMoneyEditDTO shopUserEditDTO) {
|
||||
public Long updateMoney(Long shopId, ShopUserMoneyEditDTO shopUserEditDTO) {
|
||||
shopUserEditDTO.setMoney(shopUserEditDTO.getMoney().setScale(2, RoundingMode.DOWN));
|
||||
ShopUser userInfo = getUserInfo(shopId, shopUserEditDTO.getId());
|
||||
|
||||
ShopUserFlow userFlow = new ShopUserFlow();
|
||||
int flag = 0;
|
||||
int flag;
|
||||
if (shopUserEditDTO.getType() == 0) {
|
||||
flag = mapper.decrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney());
|
||||
} else {
|
||||
@@ -100,7 +96,8 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
|
||||
userFlow.setType(shopUserEditDTO.getType() == 0 ? "-" : "+");
|
||||
userFlow.setRemark(shopUserEditDTO.getRemark());
|
||||
userFlow.setRelationId(shopUserEditDTO.getRelationId());
|
||||
return shopUserFlowService.save(userFlow);
|
||||
shopUserFlowService.save(userFlow);
|
||||
return userFlow.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.account.mapper.ShopCouponProductMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user