指定2023预售书只有妇幼生殖vip送积分,其他vip送优惠券
This commit is contained in:
@@ -304,6 +304,19 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
||||
|
||||
@Override
|
||||
public void refundZSCouponHistoryByOrder(BuyOrder order){
|
||||
MyUserEntity userEntity = userDao.selectById(order.getUserId());
|
||||
BigDecimal refundAllJF = BigDecimal.ZERO;
|
||||
List<JfTransactionDetails> grantJfList = jfTransactionDetailsDao.selectList(new LambdaQueryWrapper<JfTransactionDetails>()
|
||||
.eq(JfTransactionDetails::getRelationId, order.getOrderId())
|
||||
.eq(JfTransactionDetails::getUserId, order.getUserId())
|
||||
.eq(JfTransactionDetails::getActType, 0)
|
||||
.gt(JfTransactionDetails::getChangeAmount, BigDecimal.ZERO)
|
||||
.like(JfTransactionDetails::getRemark, "优惠券换积分"));
|
||||
for (JfTransactionDetails grantJf : grantJfList) {
|
||||
refundAllJF = refundAllJF.add(grantJf.getChangeAmount());
|
||||
}
|
||||
boolean orderGrantedJf = refundAllJF.compareTo(BigDecimal.ZERO) > 0;
|
||||
|
||||
MPJLambdaWrapper<CouponToProduct> wrapper = new MPJLambdaWrapper();
|
||||
wrapper.leftJoin(BuyOrderProduct.class,BuyOrderProduct::getProductId,CouponToProduct::getProductId);
|
||||
wrapper.leftJoin(CouponEntity.class,CouponEntity::getId,CouponToProduct::getCouponId);
|
||||
@@ -314,54 +327,42 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
||||
wrapper.select(BuyOrderProduct::getQuantity);
|
||||
List<Map<String,Object>> buyOrderProducts = couponToProductDao.selectJoinMaps(wrapper);
|
||||
|
||||
MyUserEntity userEntity = userDao.selectById(order.getUserId());
|
||||
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
|
||||
.eq(UserVip::getUserId, userEntity.getId())
|
||||
.eq(UserVip::getState,0)
|
||||
.lt(UserVip::getStartTime,order.getPaymentDate()));
|
||||
boolean isVip = false;
|
||||
if (userVipList.size() > 0) {
|
||||
isVip = true;
|
||||
}
|
||||
System.out.println("isVip:"+isVip);
|
||||
boolean isFyszVip = userVipList.stream().anyMatch(userVip -> Integer.valueOf(10).equals(userVip.getType()));
|
||||
BigDecimal refundAllJF = BigDecimal.ZERO;
|
||||
Boolean isRefundCoupon = false;
|
||||
for (Map<String,Object> map : buyOrderProducts) {
|
||||
ShopProduct shopProduct = shopProductDao.selectById(map.get("product_id").toString());
|
||||
System.out.println("goodsType:"+shopProduct.getGoodsType());
|
||||
if ("03".equals(shopProduct.getGoodsType())){
|
||||
int productId = Integer.parseInt(map.get("product_id").toString());
|
||||
int couponId = Integer.parseInt(map.get("coupon_id").toString());
|
||||
CouponEntity couponEntity = couponDao.selectById(couponId);
|
||||
boolean shouldRefundJf = couponEntity.getCouponType()==0 && ((productId == 2023 && isFyszVip) || (productId != 2023 && isVip));
|
||||
//现金券
|
||||
if (shouldRefundJf){
|
||||
BigDecimal quantity = new BigDecimal(map.get("quantity").toString());
|
||||
BigDecimal sumRefundJF = couponEntity.getCouponAmount().multiply(quantity);
|
||||
refundAllJF = refundAllJF.add(sumRefundJF);
|
||||
|
||||
QueryWrapper<CouponHistory> couponHistoryRemoveWrapper = new QueryWrapper<>();
|
||||
couponHistoryRemoveWrapper.eq("order_id",order.getOrderId());
|
||||
couponHistoryRemoveWrapper.eq("status",1);
|
||||
couponHistoryService.remove(couponHistoryRemoveWrapper);
|
||||
}else{
|
||||
if ("03".equals(shopProduct.getGoodsType())) {
|
||||
if (!orderGrantedJf) {
|
||||
isRefundCoupon = true;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
isRefundCoupon = true;
|
||||
}
|
||||
}
|
||||
if(refundAllJF.compareTo(BigDecimal.ZERO)>0 && userEntity.getJf().compareTo(refundAllJF)>=0){
|
||||
BigDecimal userJF = userEntity.getJf().subtract(refundAllJF);
|
||||
userEntity.setJf(userJF.compareTo(BigDecimal.ZERO)>=0?userJF:BigDecimal.ZERO);
|
||||
userDao.updateById(userEntity);
|
||||
jfTransactionDetailsService.recordZsJfTransaction(order,userEntity, refundAllJF);
|
||||
|
||||
if (orderGrantedJf) {
|
||||
BigDecimal userJf = userEntity.getJf() == null ? BigDecimal.ZERO : userEntity.getJf();
|
||||
BigDecimal actualDeduct;
|
||||
if (userJf.compareTo(refundAllJF) >= 0) {
|
||||
actualDeduct = refundAllJF;
|
||||
} else if (userJf.compareTo(BigDecimal.ZERO) > 0) {
|
||||
actualDeduct = userJf;
|
||||
} else {
|
||||
actualDeduct = BigDecimal.ZERO;
|
||||
}
|
||||
if (actualDeduct.compareTo(BigDecimal.ZERO) > 0) {
|
||||
userEntity.setJf(userJf.subtract(actualDeduct));
|
||||
userDao.updateById(userEntity);
|
||||
jfTransactionDetailsService.recordZsJfTransaction(order, userEntity, actualDeduct);
|
||||
QueryWrapper<CouponHistory> couponHistoryRemoveWrapper = new QueryWrapper<>();
|
||||
couponHistoryRemoveWrapper.eq("order_id", order.getOrderId());
|
||||
couponHistoryRemoveWrapper.eq("status", 1);
|
||||
couponHistoryService.remove(couponHistoryRemoveWrapper);
|
||||
}
|
||||
}
|
||||
if(isRefundCoupon){
|
||||
if (isRefundCoupon) {
|
||||
QueryWrapper<CouponHistory> couponHistoryRemoveWrapper = new QueryWrapper<>();
|
||||
couponHistoryRemoveWrapper.eq("order_id",order.getOrderId());
|
||||
couponHistoryRemoveWrapper.eq("status",0);
|
||||
couponHistoryRemoveWrapper.eq("order_id", order.getOrderId());
|
||||
couponHistoryRemoveWrapper.eq("status", 0);
|
||||
couponHistoryService.remove(couponHistoryRemoveWrapper);
|
||||
}
|
||||
|
||||
@@ -379,9 +380,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
||||
List<Map<String,Object>> buyOrderProducts = couponToProductDao.selectJoinMaps(wrapper);
|
||||
for (Map<String,Object> map : buyOrderProducts) {
|
||||
ShopProduct shopProduct = shopProductDao.selectById(map.get("product_id").toString());
|
||||
//预售书赠送规则:
|
||||
//1) 指定预售书(2023):仅妇幼生殖vip(type=10)且现金券时,改为送积分
|
||||
//2) 其他预售书:保持原规则(任意vip且现金券时,改为送积分)
|
||||
//预售书+赠送现金券:VIP用户将券额转为积分;仅产品id=2023时需为妇幼生殖vip(type=10)
|
||||
if ("03".equals(shopProduct.getGoodsType())){
|
||||
MyUserEntity userEntity = userDao.selectById(order.getUserId());
|
||||
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
|
||||
@@ -391,7 +390,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
||||
int couponId = Integer.parseInt(map.get("coupon_id").toString());
|
||||
CouponEntity couponEntity = couponDao.selectById(couponId);
|
||||
boolean isFyszVip = userVipList.stream().anyMatch(userVip -> Integer.valueOf(10).equals(userVip.getType()));
|
||||
boolean couponToJf = couponEntity.getCouponType() == 0 && ((productId == 2023 && isFyszVip) || (productId != 2023 && userVipList.size() > 0));
|
||||
boolean couponToJf = couponEntity.getCouponType() == 0 && (productId == 2023 ? isFyszVip : userVipList.size() > 0);
|
||||
if (couponToJf){
|
||||
BigDecimal jf = BigDecimal.ZERO;
|
||||
for (int i=0;i<Integer.parseInt(map.get("quantity").toString());i++){
|
||||
|
||||
Reference in New Issue
Block a user