优惠券 券使用记录
This commit is contained in:
parent
c29f508b4c
commit
97ae7983f1
|
|
@ -1,11 +1,19 @@
|
|||
package com.czg.controller.admin;
|
||||
|
||||
import com.czg.account.dto.ShopCouponDTO;
|
||||
import com.czg.account.service.ShopCouponService;
|
||||
import com.czg.annotation.SaAdminCheckPermission;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 店铺优惠券
|
||||
*
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
|
|
@ -16,5 +24,37 @@ public class ShopCouponController {
|
|||
@Resource
|
||||
private ShopCouponService couponService;
|
||||
|
||||
/**
|
||||
* 店铺优惠券列表
|
||||
* 权限标识: coupon:list
|
||||
* 状态 0 未使用 1已使用 2已过期
|
||||
*/
|
||||
@SaAdminCheckPermission("coupon:list")
|
||||
@GetMapping
|
||||
public CzgResult<List<ShopCouponDTO>> detail(@RequestParam(required = false) Integer type,
|
||||
@RequestParam(required = false) Integer status) {
|
||||
return CzgResult.success(couponService.getList(StpKit.USER.getShopId(), type, status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺优惠券新增
|
||||
* 权限标识: coupon:add
|
||||
*/
|
||||
@SaAdminCheckPermission("coupon:add")
|
||||
@PostMapping
|
||||
public CzgResult<Boolean> add(@RequestBody @Validated ShopCouponDTO couponDTO) {
|
||||
couponDTO.setShopId(StpKit.USER.getShopId());
|
||||
return CzgResult.success(couponService.add(couponDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺优惠券修改
|
||||
* 权限标识: coupon:edit
|
||||
*/
|
||||
@SaAdminCheckPermission("coupon:edit")
|
||||
@PutMapping
|
||||
public CzgResult<Boolean> edit(@RequestBody @Validated ShopCouponDTO couponDTO) {
|
||||
couponDTO.setShopId(StpKit.USER.getShopId());
|
||||
return CzgResult.success(couponService.edit(couponDTO));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
package com.czg.controller.user;
|
||||
|
||||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
import com.czg.account.service.ShopCouponService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 店铺优惠券
|
||||
*
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/coupon")
|
||||
public class UserShopCouponController {
|
||||
@Resource
|
||||
private ShopCouponService couponService;
|
||||
|
||||
/**
|
||||
* 通过用户Id 查找优惠券
|
||||
*
|
||||
* @param status 0 未使用 1已使用 2已过期
|
||||
*/
|
||||
@GetMapping("/findByUserId")
|
||||
public CzgResult<List<ShopActivateCouponRecord>> findByUserId(
|
||||
@RequestParam Long shopUserId, @RequestParam(required = false) Integer status) {
|
||||
return CzgResult.success(couponService.find(shopUserId, status));
|
||||
}
|
||||
}
|
||||
|
|
@ -37,6 +37,9 @@ public class UserOrderController {
|
|||
return CzgResult.success(orderInfoService.getOrderByPage(queryDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成订单
|
||||
*/
|
||||
@PostMapping("/createOrder")
|
||||
public CzgResult<OrderInfo> createOrder(@RequestBody OrderInfoAddDTO addDto) {
|
||||
addDto.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
package com.czg.account.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
public class ShopActivateCouponDTO {
|
||||
private Long id;
|
||||
private Integer num;
|
||||
private String name;
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
package com.czg.account.dto;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.czg.account.entity.ShopCoupon;
|
||||
import com.czg.validator.group.InsertGroup;
|
||||
import com.czg.validator.group.UpdateGroup;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
|
@ -59,11 +60,7 @@ public class ShopActivateDTO implements Serializable {
|
|||
*/
|
||||
private Integer isGiftCoupon;
|
||||
|
||||
private List<ShopActivateCouponDTO> couponList;
|
||||
|
||||
/**
|
||||
* 优惠卷信息{卷id:数量}
|
||||
*/
|
||||
private List<ShopCoupon> couponList;
|
||||
private String coupons;
|
||||
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ public class ShopActivateCouponRecord implements Serializable {
|
|||
private Long id;
|
||||
|
||||
/**
|
||||
* 会员id
|
||||
* 用户id shopUserId
|
||||
*/
|
||||
private Long vipUserId;
|
||||
private Long shopUserId;
|
||||
|
||||
/**
|
||||
* 卷Id (校验是否可用)
|
||||
|
|
@ -100,13 +100,18 @@ public class ShopActivateCouponRecord implements Serializable {
|
|||
|
||||
private String couponJson;
|
||||
|
||||
/**
|
||||
* invited 邀请
|
||||
* activate 活动
|
||||
*/
|
||||
private String source;
|
||||
|
||||
/**
|
||||
* 已使用 used
|
||||
* 未使用 not_used
|
||||
* 已过期 expired
|
||||
* 未使用 0
|
||||
* 已使用 1
|
||||
* 已过期 2
|
||||
*/
|
||||
private String status;
|
||||
private Integer status;
|
||||
private Long targetId;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.czg.account.service;
|
|||
|
||||
import com.czg.account.dto.ShopActivateDTO;
|
||||
import com.czg.account.entity.ShopActivate;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
|
@ -28,6 +29,6 @@ public interface ShopActivateService extends IService<ShopActivate> {
|
|||
* 充值奖励 的关联id 是tb_shop_user_flow的充值 记录id
|
||||
* 支付/退款 tb_order_payment.id
|
||||
*/
|
||||
void giveActivate(Long shopId, Long vipId, BigDecimal memAmount, Long relationId);
|
||||
void giveActivate(ShopUser shopUser, BigDecimal memAmount, Long relationId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.czg.account.service;
|
||||
|
||||
import com.czg.account.dto.ShopCouponDTO;
|
||||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
import com.czg.account.entity.ShopCoupon;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
|
|
@ -18,21 +19,21 @@ public interface ShopCouponService extends IService<ShopCoupon> {
|
|||
* 优惠券列表
|
||||
*
|
||||
* @param shopId 店铺id
|
||||
* @param type 1-满减 2-商品
|
||||
* @param status 状态 0 未使用 1已使用 -1已过期
|
||||
*/
|
||||
List<ShopCoupon> getList(Long shopId, Integer status);
|
||||
ShopCouponDTO getCouponById(ShopCouponDTO couponDTO);
|
||||
List<ShopCouponDTO> getList(Long shopId, Integer type, Integer status);
|
||||
|
||||
Boolean add(ShopCouponDTO couponDTO);
|
||||
|
||||
Boolean edit(ShopCouponDTO couponDTO);
|
||||
|
||||
Boolean delete(Long id);
|
||||
Boolean find(Long id);
|
||||
Boolean use(Integer shopId, Integer orderId, Integer vipUserId);
|
||||
|
||||
Boolean refund();
|
||||
List<ShopActivateCouponRecord> find(Long shopUserId, Integer status);
|
||||
|
||||
Boolean use(List<Long> ids, Long shopUserId, Long orderId);
|
||||
|
||||
Boolean refund(Long orderId, Long shopUserId);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,17 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.dto.ShopActivateCouponDTO;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import com.czg.account.dto.ShopActivateDTO;
|
||||
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
||||
import com.czg.account.entity.ShopActivate;
|
||||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
import com.czg.account.entity.ShopCoupon;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.ShopActivateCouponRecordService;
|
||||
import com.czg.account.service.ShopActivateService;
|
||||
import com.czg.account.service.ShopCouponService;
|
||||
|
|
@ -57,7 +56,8 @@ public class ShopActivateServiceImpl extends ServiceImpl<ShopActivateMapper, Sho
|
|||
.listAs(ShopActivateDTO.class);
|
||||
for (ShopActivateDTO activateDTO : activateDtoS) {
|
||||
if (StrUtil.isNotBlank(activateDTO.getCoupons())) {
|
||||
activateDTO.setCouponList(JSON.parseArray(activateDTO.getCoupons(), ShopActivateCouponDTO.class));
|
||||
//组装优惠券
|
||||
activateDTO.setCouponList(getCoupons(activateDTO.getCoupons()));
|
||||
}
|
||||
}
|
||||
return activateDtoS;
|
||||
|
|
@ -67,9 +67,6 @@ public class ShopActivateServiceImpl extends ServiceImpl<ShopActivateMapper, Sho
|
|||
public Boolean add(ShopActivateDTO activateDTO) {
|
||||
ShopActivate shopActivate = new ShopActivate();
|
||||
BeanUtil.copyProperties(activateDTO, shopActivate);
|
||||
if (CollUtil.isNotEmpty(activateDTO.getCouponList())) {
|
||||
shopActivate.setCoupons(JSONObject.toJSONString(activateDTO.getCouponList()));
|
||||
}
|
||||
return save(shopActivate);
|
||||
}
|
||||
|
||||
|
|
@ -77,15 +74,12 @@ public class ShopActivateServiceImpl extends ServiceImpl<ShopActivateMapper, Sho
|
|||
public Boolean edit(ShopActivateDTO activateDTO) {
|
||||
ShopActivate shopActivate = new ShopActivate();
|
||||
BeanUtil.copyProperties(activateDTO, shopActivate);
|
||||
if (CollUtil.isNotEmpty(activateDTO.getCouponList())) {
|
||||
shopActivate.setCoupons(JSONObject.toJSONString(activateDTO.getCouponList()));
|
||||
}
|
||||
return updateById(shopActivate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveActivate(Long shopId, Long vipId, BigDecimal memAmount, Long relationId) {
|
||||
ShopActivate activate = queryChain().select().eq(ShopActivate::getShopId, shopId)
|
||||
public void giveActivate(ShopUser shopUser, BigDecimal memAmount, Long relationId) {
|
||||
ShopActivate activate = queryChain().select().eq(ShopActivate::getShopId, shopUser.getShopId())
|
||||
.le(ShopActivate::getAmount, memAmount)
|
||||
.orderBy(ShopActivate::getGiftAmount, false)
|
||||
.one();
|
||||
|
|
@ -94,17 +88,18 @@ public class ShopActivateServiceImpl extends ServiceImpl<ShopActivateMapper, Sho
|
|||
}
|
||||
//赠送优惠券
|
||||
if (activate.getIsGiftCoupon() == 1) {
|
||||
List<ShopActivateCouponDTO> activateCoupons = JSON.parseArray(activate.getCoupons(), ShopActivateCouponDTO.class);
|
||||
Map<Long, Integer> couponUseMap = JSONObject.parseObject(activate.getCoupons(), new TypeReference<>() {
|
||||
});
|
||||
Map<Long, ShopCoupon> couponMap = new HashMap<>();
|
||||
activateCoupons.forEach(coupon -> {
|
||||
ShopCoupon shopCoupon = new ShopCoupon();
|
||||
if (couponMap.containsKey(coupon.getId())) {
|
||||
shopCoupon = couponMap.get(coupon.getId());
|
||||
couponUseMap.forEach((couponId, giftNumber) -> {
|
||||
ShopCoupon shopCoupon;
|
||||
if (couponMap.containsKey(couponId)) {
|
||||
shopCoupon = couponMap.get(couponId);
|
||||
} else {
|
||||
shopCoupon = couponService.queryChain().select().eq(ShopCoupon::getId, coupon.getId()).one();
|
||||
couponMap.put(coupon.getId(), shopCoupon);
|
||||
shopCoupon = couponService.queryChain().select().eq(ShopCoupon::getId, couponId).one();
|
||||
couponMap.put(couponId, shopCoupon);
|
||||
}
|
||||
if (shopCoupon != null && shopCoupon.getStatus().equals(1) && shopCoupon.getLeftNumber() > coupon.getNum()) {
|
||||
if (shopCoupon != null && shopCoupon.getStatus().equals(1) && shopCoupon.getLeftNumber() > giftNumber) {
|
||||
LocalDateTime start = LocalDateTime.now().with(LocalTime.MIN);
|
||||
LocalDateTime end = null;
|
||||
if ("fixed".equals(shopCoupon.getValidityType())) {
|
||||
|
|
@ -117,31 +112,30 @@ public class ShopActivateServiceImpl extends ServiceImpl<ShopActivateMapper, Sho
|
|||
}
|
||||
List<ShopActivateCouponRecord> actGiveRecords = new ArrayList<>();
|
||||
ShopActivateCouponRecord record = new ShopActivateCouponRecord();
|
||||
record.setVipUserId(vipId);
|
||||
record.setShopUserId(shopUser.getId());
|
||||
record.setCouponId(shopCoupon.getId());
|
||||
record.setShopId(shopId);
|
||||
record.setShopId(shopUser.getShopId());
|
||||
record.setSourceActId(activate.getId());
|
||||
record.setSourceFlowId(relationId);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
record.setSource("activate");
|
||||
record.setName(shopCoupon.getTitle());
|
||||
record.setCouponJson(getCouponJson(activate, shopCoupon));
|
||||
if (shopCoupon.getType() == 1) {
|
||||
record.setType(1);
|
||||
record.setName("满" + shopCoupon.getFullAmount() + "减" + shopCoupon.getDiscountAmount());
|
||||
record.setFullAmount(shopCoupon.getFullAmount());
|
||||
record.setDiscountAmount(shopCoupon.getDiscountAmount());
|
||||
} else if (shopCoupon.getType() == 2) {
|
||||
record.setType(2);
|
||||
record.setName("商品券");
|
||||
record.setProId(shopCoupon.getProId());
|
||||
}
|
||||
for (int i = 0; i < coupon.getNum(); i++) {
|
||||
for (int i = 0; i < giftNumber; i++) {
|
||||
actGiveRecords.add(record);
|
||||
}
|
||||
inRecordService.saveBatch(actGiveRecords);
|
||||
couponService.updateChain()
|
||||
.set(ShopCoupon::getLeftNumber, shopCoupon.getLeftNumber() - coupon.getNum())
|
||||
.set(ShopCoupon::getLeftNumber, shopCoupon.getLeftNumber() - giftNumber)
|
||||
.eq(ShopCoupon::getId, shopCoupon.getId())
|
||||
.update();
|
||||
}
|
||||
|
|
@ -150,7 +144,7 @@ public class ShopActivateServiceImpl extends ServiceImpl<ShopActivateMapper, Sho
|
|||
//赠送金额
|
||||
if (activate.getGiftAmount() != null && activate.getGiftAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder()
|
||||
.id(vipId)
|
||||
.id(shopUser.getId())
|
||||
.money(activate.getGiftAmount())
|
||||
.type(1)
|
||||
.remark("充值活动赠送")
|
||||
|
|
@ -158,10 +152,25 @@ public class ShopActivateServiceImpl extends ServiceImpl<ShopActivateMapper, Sho
|
|||
.bizEnum(ShopUserFlowBizEnum.AWARD_IN)
|
||||
.build();
|
||||
//更新会员余额 并生成流水
|
||||
shopUserService.updateMoney(shopId, shopUserMoneyEditDTO);
|
||||
shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取优惠券详细信息 目前仅返回 id 名称 剩余数量 赠送数量
|
||||
*/
|
||||
private List<ShopCoupon> getCoupons(String couponJson) {
|
||||
Map<Long, Integer> couponMap = JSONObject.parseObject(couponJson, new TypeReference<>() {
|
||||
});
|
||||
List<ShopCoupon> list = couponService.queryChain()
|
||||
.select(ShopCoupon::getId, ShopCoupon::getTitle, ShopCoupon::getLeftNumber)
|
||||
.eq(ShopCoupon::getId, couponMap.keySet())
|
||||
.list();
|
||||
list.forEach(coupon -> {
|
||||
coupon.setNumber(couponMap.get(coupon.getId()));
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
private String getCouponJson(ShopActivate activate, ShopCoupon tbShopCoupon) {
|
||||
JSONObject result = new JSONObject();
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.czg.account.dto.ShopCouponDTO;
|
||||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
import com.czg.account.service.ShopActivateCouponRecordService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.ShopCoupon;
|
||||
import com.czg.account.service.ShopActivateCouponRecordService;
|
||||
import com.czg.account.service.ShopCouponService;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.account.mapper.ShopCouponMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -24,81 +24,60 @@ import java.util.List;
|
|||
public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCoupon> implements ShopCouponService {
|
||||
|
||||
@Resource
|
||||
private ShopActivateCouponRecordService inService;
|
||||
private ShopActivateCouponRecordService couponRecordService;
|
||||
|
||||
@Override
|
||||
public List<ShopCoupon> getList(Long shopId, Integer status) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
if (shopId != null) {
|
||||
if (status == 1) {
|
||||
queryWrapper.eq(ShopActivateCouponRecord::getShopId, shopId);
|
||||
}else {
|
||||
queryWrapper.eq(ShopActivateCouponRecord::getShopId, shopId);
|
||||
}
|
||||
}
|
||||
return switch (status) {
|
||||
case -1 -> {
|
||||
queryWrapper.ge(ShopActivateCouponRecord::getUseEndTime, DateUtil.date());
|
||||
yield list(queryWrapper);
|
||||
}
|
||||
case 0 -> {
|
||||
// yield outService.list(queryWrapper);
|
||||
yield null;
|
||||
|
||||
}
|
||||
case 1 -> {
|
||||
yield null;
|
||||
|
||||
}
|
||||
default -> throw new IllegalStateException("Unexpected value: " + status);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopCouponDTO getCouponById(ShopCouponDTO couponDTO) {
|
||||
return null;
|
||||
public List<ShopCouponDTO> getList(Long shopId, Integer type, Integer status) {
|
||||
return queryChain().select().eq(ShopCoupon::getShopId, shopId)
|
||||
.eq(ShopCoupon::getType, type)
|
||||
.eq(ShopCoupon::getStatus, status)
|
||||
.orderBy(ShopCoupon::getCreateTime).desc().listAs(ShopCouponDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean add(ShopCouponDTO couponDTO) {
|
||||
return null;
|
||||
ShopCoupon shopCoupon = new ShopCoupon();
|
||||
BeanUtil.copyProperties(couponDTO, shopCoupon);
|
||||
return save(shopCoupon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean edit(ShopCouponDTO couponDTO) {
|
||||
return null;
|
||||
ShopCoupon shopCoupon = new ShopCoupon();
|
||||
BeanUtil.copyProperties(couponDTO, shopCoupon);
|
||||
return updateById(shopCoupon);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<ShopActivateCouponRecord> find(Long shopUserId, Integer status) {
|
||||
return couponRecordService.queryChain()
|
||||
.eq(ShopActivateCouponRecord::getShopId, StpKit.USER.getShopId())
|
||||
.eq(ShopActivateCouponRecord::getShopUserId, shopUserId)
|
||||
.eq(ShopActivateCouponRecord::getStatus, status)
|
||||
.orderBy(ShopActivateCouponRecord::getStatus).asc()
|
||||
.orderBy(ShopActivateCouponRecord::getCreateTime).desc()
|
||||
.select().list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delete(Long id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean find(Long id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean use(Integer shopId, Integer orderId, Integer vipUserId) {
|
||||
return null;
|
||||
public Boolean use(List<Long> ids, Long shopUserId, Long orderId) {
|
||||
return couponRecordService.updateChain()
|
||||
.set(ShopActivateCouponRecord::getStatus, 1)
|
||||
.set(ShopActivateCouponRecord::getTargetId, orderId)
|
||||
.eq(ShopActivateCouponRecord::getShopUserId, shopUserId)
|
||||
.in(ShopActivateCouponRecord::getId, ids).update();
|
||||
}
|
||||
|
||||
/**
|
||||
* 退还券
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public Boolean refund() {
|
||||
// for (ShopActivateOutRecord outRecord : param) {
|
||||
// outService.updateChain()
|
||||
// .set(ShopActivateOutRecord::getRefNum, outRecord.getRefNum())
|
||||
// .eq(ShopActivateOutRecord::getId, outRecord.getId())
|
||||
// .update();
|
||||
// ShopActivateInRecord inRecord = inService.getById(outRecord.getGiveId());
|
||||
// inRecord.setOverNum(inRecord.getOverNum() + outRecord.getRefNum());
|
||||
// inService.updateOverNum(inRecord.getId(), inRecord.getOverNum());
|
||||
// }
|
||||
return true;
|
||||
public Boolean refund(Long orderId, Long shopUserId) {
|
||||
return couponRecordService.updateChain()
|
||||
.set(ShopActivateCouponRecord::getStatus, 0)
|
||||
.eq(ShopActivateCouponRecord::getShopUserId, shopUserId)
|
||||
.eq(ShopActivateCouponRecord::getTargetId, orderId)
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,8 +81,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
@DubboReference
|
||||
private PointsBasicSettingService pointsBasicService;
|
||||
@DubboReference
|
||||
private ShopCouponService couponService;
|
||||
@DubboReference
|
||||
private ShopActivateCouponRecordService couponRecordService;
|
||||
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
@Resource
|
||||
|
|
@ -152,38 +153,14 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
if (param.getDiscountRatio().compareTo(BigDecimal.ZERO) <= 0 && param.getDiscountRatio().compareTo(BigDecimal.ONE) > 0) {
|
||||
throw new ValidateException("生成订单失败,折扣比例不正确");
|
||||
}
|
||||
//商品券
|
||||
//商品券 <商品id,数量>
|
||||
Map<Long, Integer> prodCouponMap = new HashMap<>();
|
||||
//满减券 满fullCouponAmount 减disCouponAmount
|
||||
BigDecimal fullAmount = BigDecimal.ZERO;
|
||||
BigDecimal discountAmount = BigDecimal.ZERO;
|
||||
if (CollUtil.isNotEmpty(param.getCouponList())) {
|
||||
//校验优惠券
|
||||
List<ShopActivateCouponRecord> records = couponRecordService.list(QueryWrapper.create()
|
||||
.where(ShopActivateCouponRecord::getId).in(param.getCouponList())
|
||||
.and(ShopActivateCouponRecord::getStatus).eq("not_used"));
|
||||
if (CollUtil.isEmpty(records)) {
|
||||
throw new ValidateException("生成订单失败,优惠券信息不存在");
|
||||
} else if (records.size() != param.getCouponList().size()) {
|
||||
throw new ValidateException("生成订单失败,优惠券信息不正确");
|
||||
}
|
||||
boolean isFullMinus = false;
|
||||
for (ShopActivateCouponRecord record : records) {
|
||||
if (record.getType().equals(1)) {
|
||||
if (isFullMinus) {
|
||||
throw new ValidateException("生成订单失败,满减券仅可使用一张");
|
||||
}
|
||||
fullAmount = record.getFullAmount();
|
||||
discountAmount = record.getDiscountAmount();
|
||||
isFullMinus = true;
|
||||
} else if (record.getType().equals(2)) {
|
||||
prodCouponMap.compute(record.getProId(), (key, oldValue) -> oldValue == null ? 1 : oldValue + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (discountAmount.compareTo(param.getFullCouponDiscountAmount()) != 0) {
|
||||
throw new ValidateException("生成订单失败,满减券减免金额不正确");
|
||||
}
|
||||
//校验优惠券
|
||||
checkCoupon(prodCouponMap, fullAmount, discountAmount, param);
|
||||
|
||||
//获取商品信息 计算金额 需要传入优惠券 减去优惠券
|
||||
List<OrderDetail> orderDetails = cartService.getCartByTableCode(table.getTableCode(), param.isVipPrice() ? 1 : 0, param.getPlaceNum());
|
||||
//总打包费
|
||||
|
|
@ -237,6 +214,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
//生成订单 //discount_info 所有折扣 几折 折扣金额 满减金额 优惠券金额 积分抵扣金额 抹零
|
||||
OrderInfo orderInfo = initOrderInfo(param, shopInfo, table);
|
||||
orderDetailService.createOrderDetails(orderInfo.getId(), orderDetails);
|
||||
//券消耗
|
||||
couponService.use(param.getCouponList(), shopUser.getId(), orderInfo.getId());
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
|
|
@ -296,6 +275,39 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
orderDetails = resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验优惠券可用性 回填优惠券信息
|
||||
*/
|
||||
private void checkCoupon(Map<Long, Integer> prodCouponMap, BigDecimal fullAmount, BigDecimal discountAmount, OrderInfoAddDTO param) {
|
||||
if (CollUtil.isNotEmpty(param.getCouponList())) {
|
||||
//校验优惠券
|
||||
List<ShopActivateCouponRecord> records = couponRecordService.list(QueryWrapper.create()
|
||||
.where(ShopActivateCouponRecord::getId).in(param.getCouponList())
|
||||
.and(ShopActivateCouponRecord::getStatus).eq(0));
|
||||
if (CollUtil.isEmpty(records)) {
|
||||
throw new ValidateException("生成订单失败,优惠券信息不存在");
|
||||
} else if (records.size() != param.getCouponList().size()) {
|
||||
throw new ValidateException("生成订单失败,优惠券信息不正确");
|
||||
}
|
||||
boolean isFullMinus = false;
|
||||
for (ShopActivateCouponRecord record : records) {
|
||||
if (record.getType().equals(1)) {
|
||||
if (isFullMinus) {
|
||||
throw new ValidateException("生成订单失败,满减券仅可使用一张");
|
||||
}
|
||||
fullAmount = record.getFullAmount();
|
||||
discountAmount = record.getDiscountAmount();
|
||||
isFullMinus = true;
|
||||
} else if (record.getType().equals(2)) {
|
||||
prodCouponMap.compute(record.getProId(), (key, oldValue) -> oldValue == null ? 1 : oldValue + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (discountAmount.compareTo(param.getFullCouponDiscountAmount()) != 0) {
|
||||
throw new ValidateException("生成订单失败,满减券减免金额不正确");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void payCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson) {
|
||||
|
|
@ -338,7 +350,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
//更新会员余额 并生成流水
|
||||
Long flowId = shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
|
||||
//会员活动
|
||||
activateService.giveActivate(shopUser.getShopId(), shopUser.getId(),
|
||||
activateService.giveActivate(shopUser,
|
||||
new BigDecimal(czgCallBackDto.getAmount() / 100L), flowId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import com.czg.system.enums.SysParamCodeEnum;
|
|||
import com.czg.system.service.SysParamsService;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.MD5Util;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.NonNull;
|
||||
|
|
@ -64,6 +65,8 @@ public class PayServiceImpl implements PayService {
|
|||
private ShopUserFlowService userFlowService;
|
||||
@DubboReference
|
||||
private ShopActivateCouponRecordService inRecordService;
|
||||
@DubboReference
|
||||
private ShopCouponService couponService;
|
||||
@Resource
|
||||
private RabbitPublisher rabbitPublisher;
|
||||
@Resource
|
||||
|
|
@ -243,7 +246,7 @@ public class PayServiceImpl implements PayService {
|
|||
//更新会员余额 并生成流水
|
||||
Long flowId = shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
|
||||
//会员活动
|
||||
shopActivateService.giveActivate(shopUser.getShopId(), shopUser.getId(), payParam.getAmount(), flowId);
|
||||
shopActivateService.giveActivate(shopUser, payParam.getAmount(), flowId);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
|
|
@ -342,7 +345,7 @@ public class PayServiceImpl implements PayService {
|
|||
}
|
||||
Long refPaymentId = null;
|
||||
if (!refPayParam.isCashRefund()) {
|
||||
OrderPayment payment = null;
|
||||
OrderPayment payment;
|
||||
if (inFlow.getRelationId() != null) {
|
||||
payment = paymentService.getById(inFlow.getRelationId());
|
||||
} else {
|
||||
|
|
@ -379,11 +382,11 @@ public class PayServiceImpl implements PayService {
|
|||
.eq(ShopUserFlow::getId, giftFlow.getId())
|
||||
.update();
|
||||
}
|
||||
inRecordService.updateChain()
|
||||
.set(ShopActivateCouponRecord::getStatus, "not_used")
|
||||
//移除优惠券
|
||||
inRecordService.remove(QueryWrapper.create()
|
||||
.eq(ShopActivateCouponRecord::getSourceFlowId, inFlow.getId())
|
||||
.update();
|
||||
|
||||
.eq(ShopActivateCouponRecord::getSource, "activate")
|
||||
.eq(ShopActivateCouponRecord::getStatus, 0));
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue