Merge branch 'ww' into test

This commit is contained in:
2024-10-25 11:21:49 +08:00
9 changed files with 85 additions and 46 deletions

View File

@@ -1,46 +0,0 @@
package com.chaozhanggui.system.cashierservice.service;
import com.chaozhanggui.system.cashierservice.entity.TbActivateProduct;
/**
* 活动赠送商品表(TbActivateProduct)表服务接口
*
* @author ww
* @since 2024-08-20 15:15:01
*/
public interface TbActivateProductService {
/**
* 通过ID查询单条数据
*
* @param id 主键
* @return 实例对象
*/
TbActivateProduct queryById(Integer id);
/**
* 新增数据
*
* @param tbActivateProduct 实例对象
* @return 实例对象
*/
TbActivateProduct insert(TbActivateProduct tbActivateProduct);
/**
* 修改数据
*
* @param tbActivateProduct 实例对象
* @return 实例对象
*/
TbActivateProduct update(TbActivateProduct tbActivateProduct);
/**
* 通过主键删除数据
*
* @param id 主键
* @return 是否成功
*/
boolean deleteById(Integer id);
}

View File

@@ -1,9 +1,13 @@
package com.chaozhanggui.system.cashierservice.service;
import com.chaozhanggui.system.cashierservice.entity.TbActivateOutRecord;
import com.chaozhanggui.system.cashierservice.entity.dto.CouponDto;
import com.chaozhanggui.system.cashierservice.entity.dto.CouponUseDto;
import com.chaozhanggui.system.cashierservice.sign.Result;
import org.springframework.context.annotation.Primary;
import java.util.List;
/**
* 优惠券(TbShopCoupon)表服务接口
*
@@ -12,4 +16,8 @@ import org.springframework.context.annotation.Primary;
*/
public interface TbShopCouponService {
Result find(CouponDto param);
boolean use(Integer shopId,Integer orderId,Integer vipUserId,List<TbActivateOutRecord> param);
boolean refund(List<TbActivateOutRecord> param);
}

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.CouponDto;
import com.chaozhanggui.system.cashierservice.entity.dto.CouponUseDto;
import com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo;
import com.chaozhanggui.system.cashierservice.service.TbShopCouponService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
@@ -125,4 +126,48 @@ public class TbShopCouponServiceImpl implements TbShopCouponService {
return new Result(CodeEnum.SUCCESS);
}
/**
* 使用券
* @param shopId
* @param orderId
* @param vipUserId
* @param param giveId 和 useNum 必传
* @return
*/
@Override
public boolean use(Integer shopId,Integer orderId,Integer vipUserId,List<TbActivateOutRecord> param) {
for (TbActivateOutRecord outRecord : param) {
TbActivateInRecord inRecord = inRecordMapper.queryById(outRecord.getGiveId());
inRecord.setOverNum(inRecord.getOverNum() - outRecord.getUseNum());
inRecordMapper.updateOverNum(inRecord.getId(), inRecord.getOverNum());
outRecord.setType(inRecord.getType());
outRecord.setShopId(shopId);
outRecord.setOrderId(orderId.toString());
outRecord.setVipUserId(vipUserId);
outRecord.setStatus("closed");
outRecord.setCreateTime(new Date());
}
outRecordMapper.insertBatch(param);
return true;
}
/**
* 退还券
* @param param giveId和 refNum 必传
* @return
*/
@Override
public boolean refund(List<TbActivateOutRecord> param) {
for (TbActivateOutRecord outRecord : param) {
outRecord.setUpdateTime(new Date());
outRecordMapper.updateRefNum(outRecord.getId(),outRecord.getRefNum());
TbActivateInRecord inRecord = inRecordMapper.queryById(outRecord.getGiveId());
inRecord.setOverNum(inRecord.getOverNum() + outRecord.getRefNum());
inRecordMapper.updateOverNum(inRecord.getId(), inRecord.getOverNum());
}
return true;
}
}