|
@@ -22,7 +22,6 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -86,18 +85,56 @@ public class SysCouponIssueRecordServiceImpl extends ServiceImpl<SysCouponIssueR
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 手动领取优惠券
|
|
|
+ *
|
|
|
+ * @param userId 用户id
|
|
|
+ * @param couponId 优惠券id
|
|
|
+ */
|
|
|
@Override
|
|
|
- public int revokeCoupon(Integer id) {
|
|
|
- List<SysCouponIssueRecord> issueRecords = this.list(new WrapperUtil<SysCouponIssueRecord>()
|
|
|
- .hasEq("id_", id)
|
|
|
- .hasEq("ops", 0)
|
|
|
- .queryWrapper());
|
|
|
- if (CollectionUtils.isEmpty(issueRecords)) {
|
|
|
- throw new BizException("未查询到该优惠券的发放记录!");
|
|
|
- }
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void manualIssueCoupon(Integer userId, Integer couponId) {
|
|
|
+ sysCouponCodeService.exchangeCoupon(userId, couponId,
|
|
|
+ null, 1, 1, null);
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 撤回优惠券
|
|
|
+ *
|
|
|
+ * @param issueId 发放记录
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void revokeCoupon(Integer issueId) {
|
|
|
+ SysCouponIssueRecord issueRecord = Optional.ofNullable(issueId)
|
|
|
+ .map(this::getById)
|
|
|
+ .orElseThrow(() -> new BizException("未查询到该发放记录!"));
|
|
|
+
|
|
|
+ //修改未使用的优惠券为撤回状态
|
|
|
+ baseMapper.revoke(issueId);
|
|
|
+ //查询券的信息
|
|
|
+ SysCoupon sysCoupon = Optional.ofNullable(issueRecord.getCouponId())
|
|
|
+ .map(sysCouponService::get)
|
|
|
+ .orElseThrow(() -> new BizException("未查询到该优惠券!"));
|
|
|
+
|
|
|
+ //查询未使用的优惠券有多少
|
|
|
+ int useCount = baseMapper.queryCouponCode(issueId, 0);
|
|
|
+ if (useCount >= 0) {
|
|
|
+ //返还库存
|
|
|
+ baseMapper.opsConsume(sysCoupon.getId(), useCount);
|
|
|
+ }
|
|
|
+ //发放记录修改为撤回状态
|
|
|
+ issueRecord.setOps(1);
|
|
|
+ issueRecord.setUpdatedBy(getUserId());
|
|
|
+ issueRecord.setUpdatedTime(new Date());
|
|
|
+ this.updateById(issueRecord);
|
|
|
+ }
|
|
|
|
|
|
- return 0;
|
|
|
+ /**
|
|
|
+ * 检查已使用的优惠券数量
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int checkRevoke(Integer issueId) {
|
|
|
+ return baseMapper.queryCouponCode(issueId, 1);//0 未使用 1已使用
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -106,7 +143,7 @@ public class SysCouponIssueRecordServiceImpl extends ServiceImpl<SysCouponIssueR
|
|
|
@Override
|
|
|
public PageInfo<CouponIssueRecordVo> queryIssueRecord(Map<String, Object> param) {
|
|
|
Page<CouponIssueRecordVo> pageInfo = PageUtil.getPageInfo(param);
|
|
|
- pageInfo.setAsc("a.create_time_");
|
|
|
+ pageInfo.setAsc("a.created_time_");
|
|
|
return PageUtil.pageInfo(baseMapper.queryIssueRecord(pageInfo, param));
|
|
|
}
|
|
|
|