优惠券使用 以及 退券
This commit is contained in:
parent
b1e7095357
commit
84a2007b26
|
|
@ -17,6 +17,7 @@ import java.util.List;
|
||||||
public interface TbActivateInRecordMapper extends BaseMapper<TbActivateInRecord> {
|
public interface TbActivateInRecordMapper extends BaseMapper<TbActivateInRecord> {
|
||||||
|
|
||||||
@Select("SELECT" +
|
@Select("SELECT" +
|
||||||
|
" inRecord.coupon_id as id," +
|
||||||
" inRecord.coupon_id as couponId," +
|
" inRecord.coupon_id as couponId," +
|
||||||
" pro.id as proId," +
|
" pro.id as proId," +
|
||||||
" CASE" +
|
" CASE" +
|
||||||
|
|
@ -37,5 +38,10 @@ public interface TbActivateInRecordMapper extends BaseMapper<TbActivateInRecord>
|
||||||
" and inRecord.use_end_time > now()" +
|
" and inRecord.use_end_time > now()" +
|
||||||
" order by inRecord.use_end_time asc")
|
" order by inRecord.use_end_time asc")
|
||||||
List<TbUserCouponVo> queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId);
|
List<TbUserCouponVo> queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId);
|
||||||
|
|
||||||
|
@Select("update tb_activate_in_record" +
|
||||||
|
" set over_num = #{overNum}" +
|
||||||
|
" where id = #{id}")
|
||||||
|
int updateOverNum(@Param("id") Integer id, @Param("overNum") Integer overNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package cn.ysk.cashier.mybatis.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord;
|
import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 活动赠送商品使用记录表(TbActivateOutRecord)表数据库访问层
|
* 活动赠送商品使用记录表(TbActivateOutRecord)表数据库访问层
|
||||||
|
|
@ -11,5 +13,9 @@ import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord;
|
||||||
*/
|
*/
|
||||||
public interface TbActivateOutRecordMapper extends BaseMapper<TbActivateOutRecord> {
|
public interface TbActivateOutRecordMapper extends BaseMapper<TbActivateOutRecord> {
|
||||||
|
|
||||||
|
@Select("update tb_activate_out_record" +
|
||||||
|
" set ref_num = ref_num + #{refNum}" +
|
||||||
|
" where id = #{id}")
|
||||||
|
int updateRefNum(@Param("id") Integer id, @Param("refNum") Integer refNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package cn.ysk.cashier.mybatis.service;
|
package cn.ysk.cashier.mybatis.service;
|
||||||
|
|
||||||
import cn.ysk.cashier.dto.CouponDto;
|
import cn.ysk.cashier.dto.CouponDto;
|
||||||
|
import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord;
|
||||||
import cn.ysk.cashier.mybatis.entity.TbCouponProduct;
|
import cn.ysk.cashier.mybatis.entity.TbCouponProduct;
|
||||||
import cn.ysk.cashier.mybatis.vo.TbShopCouponVo;
|
import cn.ysk.cashier.mybatis.vo.TbShopCouponVo;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
@ -24,11 +25,15 @@ public interface TbShopCouponService extends IService<TbShopCoupon> {
|
||||||
|
|
||||||
TbShopCoupon findById (Integer id);
|
TbShopCoupon findById (Integer id);
|
||||||
|
|
||||||
ResponseEntity<Object> find(CouponDto param);
|
|
||||||
|
|
||||||
boolean update(TbShopCouponVo param);
|
boolean update(TbShopCouponVo param);
|
||||||
boolean delete(Integer id);
|
boolean delete(Integer id);
|
||||||
|
|
||||||
|
ResponseEntity<Object> find(CouponDto param);
|
||||||
|
|
||||||
|
boolean use(Integer shopId,Integer orderId,Integer vipUserId,List<TbActivateOutRecord> param);
|
||||||
|
|
||||||
|
boolean refund(List<TbActivateOutRecord> param);
|
||||||
|
|
||||||
List<TbCouponProduct> findActivatePros(Integer couponId);
|
List<TbCouponProduct> findActivatePros(Integer couponId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,12 @@ import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.ysk.cashier.dto.CouponDto;
|
import cn.ysk.cashier.dto.CouponDto;
|
||||||
import cn.ysk.cashier.dto.TbShopCouponQueryCriteria;
|
import cn.ysk.cashier.dto.TbShopCouponQueryCriteria;
|
||||||
|
import cn.ysk.cashier.mybatis.entity.TbActivateInRecord;
|
||||||
|
import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord;
|
||||||
import cn.ysk.cashier.mybatis.entity.TbCouponProduct;
|
import cn.ysk.cashier.mybatis.entity.TbCouponProduct;
|
||||||
import cn.ysk.cashier.mybatis.entity.TbShopCoupon;
|
import cn.ysk.cashier.mybatis.entity.TbShopCoupon;
|
||||||
import cn.ysk.cashier.mybatis.mapper.TbActivateInRecordMapper;
|
import cn.ysk.cashier.mybatis.mapper.TbActivateInRecordMapper;
|
||||||
|
import cn.ysk.cashier.mybatis.mapper.TbActivateOutRecordMapper;
|
||||||
import cn.ysk.cashier.mybatis.mapper.TbShopCouponMapper;
|
import cn.ysk.cashier.mybatis.mapper.TbShopCouponMapper;
|
||||||
import cn.ysk.cashier.mybatis.service.TbActivateInRecordService;
|
import cn.ysk.cashier.mybatis.service.TbActivateInRecordService;
|
||||||
import cn.ysk.cashier.mybatis.service.TbCouponProductService;
|
import cn.ysk.cashier.mybatis.service.TbCouponProductService;
|
||||||
|
|
@ -66,6 +69,8 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
||||||
private TbOrderDetailRepository orderDetailRepository;
|
private TbOrderDetailRepository orderDetailRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
private TbActivateInRecordMapper inRecordMapper;
|
private TbActivateInRecordMapper inRecordMapper;
|
||||||
|
@Autowired
|
||||||
|
private TbActivateOutRecordMapper outRecordMapper;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -97,6 +102,43 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
||||||
return tbShopCouponVo;
|
return tbShopCouponVo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean update(TbShopCouponVo param) {
|
||||||
|
if (param.getId() == null) {
|
||||||
|
tbShopCouponmapper.insert(param);
|
||||||
|
} else {
|
||||||
|
tbShopCouponmapper.updateById(param);
|
||||||
|
}
|
||||||
|
if (CollectionUtil.isNotEmpty(param.getProducts())) {
|
||||||
|
List<Integer> collect = new ArrayList<>();
|
||||||
|
for (TbCouponProduct product : param.getProducts()) {
|
||||||
|
product.setCouponId(param.getId());
|
||||||
|
if (product.getId() != null) collect.add(product.getId());
|
||||||
|
}
|
||||||
|
QueryWrapper<TbCouponProduct> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("coupon_id", param.getId());
|
||||||
|
List<TbCouponProduct> actProducts = couProductService.list(queryWrapper);
|
||||||
|
for (TbCouponProduct actProduct : actProducts) {
|
||||||
|
if (!collect.contains(actProduct.getId())) {
|
||||||
|
couProductService.removeById(actProduct.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
couProductService.saveOrUpdateBatch(param.getProducts());
|
||||||
|
} else {
|
||||||
|
LambdaQueryWrapper<TbCouponProduct> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(TbCouponProduct::getCouponId, param.getId());
|
||||||
|
couProductService.remove(queryWrapper);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean delete(Integer id) {
|
||||||
|
tbShopCouponmapper.deleteById(id);
|
||||||
|
couProductService.remove(new LambdaQueryWrapper<TbCouponProduct>().eq(TbCouponProduct::getCouponId, id));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Object> find(CouponDto param) {
|
public ResponseEntity<Object> find(CouponDto param) {
|
||||||
TbShopUser tbShopUser = shopUserRepository.selectByUserIdAndShopId(param.getUserId().toString(), param.getShopId().toString());
|
TbShopUser tbShopUser = shopUserRepository.selectByUserIdAndShopId(param.getUserId().toString(), param.getShopId().toString());
|
||||||
|
|
@ -170,45 +212,51 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用券
|
||||||
|
* @param shopId
|
||||||
|
* @param orderId
|
||||||
|
* @param vipUserId
|
||||||
|
* @param param giveId 和 useNum 必传
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean update(TbShopCouponVo param) {
|
public boolean use(Integer shopId,Integer orderId,Integer vipUserId,List<TbActivateOutRecord> param) {
|
||||||
if (param.getId() == null) {
|
for (TbActivateOutRecord outRecord : param) {
|
||||||
tbShopCouponmapper.insert(param);
|
TbActivateInRecord inRecord = inRecordMapper.selectById(outRecord.getGiveId());
|
||||||
} else {
|
inRecord.setOverNum(inRecord.getOverNum() - outRecord.getUseNum());
|
||||||
tbShopCouponmapper.updateById(param);
|
inRecordMapper.updateOverNum(inRecord.getId(), inRecord.getOverNum());
|
||||||
}
|
|
||||||
if (CollectionUtil.isNotEmpty(param.getProducts())) {
|
outRecord.setType(inRecord.getType());
|
||||||
List<Integer> collect = new ArrayList<>();
|
outRecord.setShopId(shopId);
|
||||||
for (TbCouponProduct product : param.getProducts()) {
|
outRecord.setOrderId(orderId.toString());
|
||||||
product.setCouponId(param.getId());
|
outRecord.setVipUserId(vipUserId);
|
||||||
if (product.getId() != null) collect.add(product.getId());
|
outRecord.setStatus("closed");
|
||||||
}
|
outRecord.setCreateTime(new Date());
|
||||||
QueryWrapper<TbCouponProduct> queryWrapper = new QueryWrapper<>();
|
outRecordMapper.insert(outRecord);
|
||||||
queryWrapper.eq("coupon_id", param.getId());
|
|
||||||
List<TbCouponProduct> actProducts = couProductService.list(queryWrapper);
|
|
||||||
for (TbCouponProduct actProduct : actProducts) {
|
|
||||||
if (!collect.contains(actProduct.getId())) {
|
|
||||||
couProductService.removeById(actProduct.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
couProductService.saveOrUpdateBatch(param.getProducts());
|
|
||||||
} else {
|
|
||||||
LambdaQueryWrapper<TbCouponProduct> queryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
queryWrapper.eq(TbCouponProduct::getCouponId, param.getId());
|
|
||||||
couProductService.remove(queryWrapper);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退还券
|
||||||
|
* @param param giveId和 refNum 必传
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(Integer id) {
|
public boolean refund(List<TbActivateOutRecord> param) {
|
||||||
tbShopCouponmapper.deleteById(id);
|
for (TbActivateOutRecord outRecord : param) {
|
||||||
couProductService.remove(new LambdaQueryWrapper<TbCouponProduct>().eq(TbCouponProduct::getCouponId, id));
|
outRecord.setUpdateTime(new Date());
|
||||||
|
outRecordMapper.updateRefNum(outRecord.getId(),outRecord.getRefNum());
|
||||||
|
TbActivateInRecord inRecord = inRecordMapper.selectById(outRecord.getGiveId());
|
||||||
|
inRecord.setOverNum(inRecord.getOverNum() + outRecord.getRefNum());
|
||||||
|
inRecordMapper.updateOverNum(inRecord.getId(), inRecord.getOverNum());
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<TbCouponProduct> findActivatePros(Integer couponId) {
|
public List<TbCouponProduct> findActivatePros(Integer couponId) {
|
||||||
QueryWrapper<TbCouponProduct> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<TbCouponProduct> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("coupon_id", couponId);
|
queryWrapper.eq("coupon_id", couponId);
|
||||||
|
|
|
||||||
|
|
@ -400,22 +400,6 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void upOrderStatus(TbOrderInfo tbOrderInfo) {
|
public void upOrderStatus(TbOrderInfo tbOrderInfo) {
|
||||||
tbOrderInfo.setStatus("cancelled");
|
tbOrderInfo.setStatus("cancelled");
|
||||||
//订单取消 赠送商品数量返回
|
|
||||||
QueryWrapper<TbActivateOutRecord> queryWrapper = new QueryWrapper<>();
|
|
||||||
queryWrapper.eq("order_id", tbOrderInfo.getId());
|
|
||||||
queryWrapper.eq("status", "create");
|
|
||||||
List<TbActivateOutRecord> outRecords = outRecordService.list(queryWrapper);
|
|
||||||
for (TbActivateOutRecord outRecord : outRecords) {
|
|
||||||
TbActivateInRecord inRecord = inRecordService.getById(outRecord.getGiveId());
|
|
||||||
inRecord.setOverNum(inRecord.getOverNum() + outRecord.getUseNum());
|
|
||||||
inRecordService.updateById(inRecord);
|
|
||||||
}
|
|
||||||
LambdaUpdateWrapper<TbActivateOutRecord> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
||||||
lambdaUpdateWrapper.eq(TbActivateOutRecord::getOrderId, tbOrderInfo.getId())
|
|
||||||
.eq(TbActivateOutRecord::getStatus, "create")
|
|
||||||
.set(TbActivateOutRecord::getStatus, "cancel");
|
|
||||||
outRecordService.update(lambdaUpdateWrapper);
|
|
||||||
|
|
||||||
List<TbOrderDetail> details = tbOrderDetailRepository.searchDetailByOrderId(tbOrderInfo.getId());
|
List<TbOrderDetail> details = tbOrderDetailRepository.searchDetailByOrderId(tbOrderInfo.getId());
|
||||||
for (TbOrderDetail detail : details) {
|
for (TbOrderDetail detail : details) {
|
||||||
detail.setStatus("cancelled");
|
detail.setStatus("cancelled");
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import java.util.Date;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class TbUserCouponVo {
|
public class TbUserCouponVo {
|
||||||
|
private Integer id;
|
||||||
private Integer couponId;
|
private Integer couponId;
|
||||||
private Integer proId;
|
private Integer proId;
|
||||||
//优惠券名称
|
//优惠券名称
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue