|
@@ -3,25 +3,31 @@ package com.example.xiaoshiweixinback.service;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.example.xiaoshiweixinback.business.exception.BusinessException;
|
|
|
|
+import com.example.xiaoshiweixinback.business.exception.ExceptionEnum;
|
|
import com.example.xiaoshiweixinback.business.utils.BatchNoUtil;
|
|
import com.example.xiaoshiweixinback.business.utils.BatchNoUtil;
|
|
-import com.example.xiaoshiweixinback.domain.AssoPersonProduct;
|
|
|
|
|
|
+import com.example.xiaoshiweixinback.domain.*;
|
|
|
|
|
|
-import com.example.xiaoshiweixinback.domain.Order;
|
|
|
|
-import com.example.xiaoshiweixinback.domain.Ticket;
|
|
|
|
-import com.example.xiaoshiweixinback.domain.Vip;
|
|
|
|
import com.example.xiaoshiweixinback.entity.dto.ticket.TicketProcessUpDTO;
|
|
import com.example.xiaoshiweixinback.entity.dto.ticket.TicketProcessUpDTO;
|
|
import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
|
|
import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
|
|
import com.example.xiaoshiweixinback.entity.vo.person.PersonVO;
|
|
import com.example.xiaoshiweixinback.entity.vo.person.PersonVO;
|
|
import com.example.xiaoshiweixinback.entity.weixinPay.GetPayTicketVO;
|
|
import com.example.xiaoshiweixinback.entity.weixinPay.GetPayTicketVO;
|
|
|
|
+import com.example.xiaoshiweixinback.entity.weixinPay.GoodVO;
|
|
import com.example.xiaoshiweixinback.entity.weixinPay.JsApiDTO;
|
|
import com.example.xiaoshiweixinback.entity.weixinPay.JsApiDTO;
|
|
import com.example.xiaoshiweixinback.entity.weixinPay.WeiXinPayDTO;
|
|
import com.example.xiaoshiweixinback.entity.weixinPay.WeiXinPayDTO;
|
|
|
|
+import com.example.xiaoshiweixinback.factorys.goodFactory.GoodFactory;
|
|
|
|
+import com.example.xiaoshiweixinback.factorys.goodFactory.GoodImp;
|
|
import com.example.xiaoshiweixinback.mapper.AssoPersonProductMapper;
|
|
import com.example.xiaoshiweixinback.mapper.AssoPersonProductMapper;
|
|
import com.example.xiaoshiweixinback.mapper.OrderMapper;
|
|
import com.example.xiaoshiweixinback.mapper.OrderMapper;
|
|
|
|
+import com.example.xiaoshiweixinback.service.weixinpay.AssoPayOrderGoodService;
|
|
|
|
+import com.example.xiaoshiweixinback.service.weixinpay.AssoPayOrderVoucherService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @author admin
|
|
* @author admin
|
|
* @description
|
|
* @description
|
|
@@ -36,38 +42,36 @@ public class OrderService extends ServiceImpl<OrderMapper, Order> {
|
|
@Autowired
|
|
@Autowired
|
|
private TicketService ticketService;
|
|
private TicketService ticketService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private AssoPayOrderGoodService assoPayOrderGoodService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private AssoPayOrderVoucherService assoPayOrderVoucherService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private GoodFactory goodFactory;
|
|
|
|
+ @Autowired
|
|
|
|
+ private AssoPersonVoucherService assoPersonVoucherService;
|
|
|
|
+
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
- public Order addOrder(WeiXinPayDTO weiXinPayDTO, GetPayTicketVO getPayTicketVO, String tradeNo, PersonnelVO personVO) {
|
|
|
|
|
|
+ public Order addOrder(WeiXinPayDTO weiXinPayDTO, String tradeNo, PersonnelVO personVO) {
|
|
|
|
+ this.verifyPrice(weiXinPayDTO,personVO);
|
|
Integer type = weiXinPayDTO.getGoodType();
|
|
Integer type = weiXinPayDTO.getGoodType();
|
|
- String uuid = weiXinPayDTO.getGoodUuid();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ Double price = weiXinPayDTO.getPrice();
|
|
|
|
+ Double finalPrice = weiXinPayDTO.getFinalPrice();
|
|
|
|
+ Double discount = weiXinPayDTO.getDiscount();
|
|
|
|
+ List<GoodVO> goodVOS = weiXinPayDTO.getGoods();
|
|
|
|
+ List<Integer> assoVoucherIds = weiXinPayDTO.getPersonVoucherIds();
|
|
Order order = new Order();
|
|
Order order = new Order();
|
|
order.setOrderState(0);
|
|
order.setOrderState(0);
|
|
order.setTradeNo(tradeNo);
|
|
order.setTradeNo(tradeNo);
|
|
-
|
|
|
|
- String json = JSONObject.toJSONString(getPayTicketVO);
|
|
|
|
-
|
|
|
|
- switch (type) {
|
|
|
|
- case 1:
|
|
|
|
- Vip vip = vipService.getVipByUuId(uuid);
|
|
|
|
- order.setOrgPrice(vip.getPrice());
|
|
|
|
- order.setTruePrice(vip.getPrice());
|
|
|
|
- order.setGoodsType(type);
|
|
|
|
- order.setGoodUuid(uuid);
|
|
|
|
- order.setOrderParameter(json);
|
|
|
|
- order.setPersonUuid(personVO.getUuid());
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- Ticket ticket =ticketService.getTicketByUUid(uuid);
|
|
|
|
- order.setOrgPrice(ticket.getPrice());
|
|
|
|
- order.setTruePrice(ticket.getPrice());
|
|
|
|
- order.setGoodsType(type);
|
|
|
|
- order.setGoodUuid(uuid);
|
|
|
|
- order.setOrderParameter(json);
|
|
|
|
- order.setPersonUuid(personVO.getUuid());
|
|
|
|
- }
|
|
|
|
|
|
+ order.setPersonUuid(personVO.getUuid());
|
|
|
|
+ order.setOrgPrice(price);
|
|
|
|
+ order.setTruePrice(finalPrice);
|
|
|
|
+ order.setPersonUuid(personVO.getUuid());
|
|
|
|
+ order.setDiscount(discount);
|
|
order.insert();
|
|
order.insert();
|
|
|
|
+ assoPayOrderGoodService.addAssoPayOrderGood(order.getId(), type, goodVOS);
|
|
|
|
+ assoPayOrderVoucherService.addAssoPayOrderVoucher(order.getId(), assoVoucherIds);
|
|
|
|
+ assoPersonVoucherService.useVoucher(assoVoucherIds, 2);
|
|
return order;
|
|
return order;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -78,23 +82,52 @@ public class OrderService extends ServiceImpl<OrderMapper, Order> {
|
|
return order;
|
|
return order;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
public void payBack(String tradeNo) {
|
|
public void payBack(String tradeNo) {
|
|
Order order = this.getOrderByTradeNo(tradeNo);
|
|
Order order = this.getOrderByTradeNo(tradeNo);
|
|
- if(order.getOrderState()!=0){
|
|
|
|
|
|
+
|
|
|
|
+ if (order.getOrderState() != 0) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
order.setOrderState(1);
|
|
order.setOrderState(1);
|
|
order.updateById();
|
|
order.updateById();
|
|
- Integer orderType = order.getGoodsType();
|
|
|
|
- String orderuuid = order.getGoodUuid();
|
|
|
|
- switch (orderType) {
|
|
|
|
- case 1:
|
|
|
|
- vipService.activateVIP(order);
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- ticketService.updateProcess(orderuuid,3);
|
|
|
|
- break;
|
|
|
|
|
|
+ List<AssoPayOrderGood> assoPayOrderGoods = assoPayOrderGoodService.getPayOrderGoodByOrderId(order.getId());
|
|
|
|
+ Integer orderType =assoPayOrderGoods.get(0).getGoodType();
|
|
|
|
+ GoodImp goodImp = goodFactory.getClass(orderType);
|
|
|
|
+ goodImp.activeGood(order, assoPayOrderGoods);
|
|
|
|
+ List<Integer> assoPersonVoucherIds = assoPayOrderVoucherService.getAssoVoucherIdsByOrder(order.getId());
|
|
|
|
+ assoPersonVoucherService.useVoucher(assoPersonVoucherIds, 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 校验订单价格
|
|
|
|
+ */
|
|
|
|
+ private void verifyPrice(WeiXinPayDTO weiXinPayDTO, PersonnelVO personVO) {
|
|
|
|
+ String personUuid = personVO.getUuid();
|
|
|
|
+ Integer type = weiXinPayDTO.getGoodType();
|
|
|
|
+ List<GoodVO> goodVOS = weiXinPayDTO.getGoods();
|
|
|
|
+ List<Integer> assoVoucherIds = weiXinPayDTO.getPersonVoucherIds();
|
|
|
|
+ Double price = weiXinPayDTO.getFinalPrice();
|
|
|
|
+ Double discount = weiXinPayDTO.getDiscount();
|
|
|
|
+ if(discount==null){
|
|
|
|
+ discount=1d;
|
|
}
|
|
}
|
|
|
|
+ //校验优惠卷是否能使用
|
|
|
|
+ Double voucherMon = assoPersonVoucherService.verifyVouchers(assoVoucherIds, personVO);
|
|
|
|
|
|
|
|
+ //计算商品价格
|
|
|
|
+ GoodImp goodImp = goodFactory.getClass(type);
|
|
|
|
+ Double allPrice = goodImp.computePrice(goodVOS);
|
|
|
|
+ Double withVocherPrice =allPrice-voucherMon;
|
|
|
|
+ if(withVocherPrice<=0){
|
|
|
|
+ withVocherPrice=0d;
|
|
|
|
+ }
|
|
|
|
+ //查看是否有折扣
|
|
|
|
+ // 计算价格 (商品总价格-优惠券) *折扣
|
|
|
|
+ Double truePrice =withVocherPrice*discount;
|
|
|
|
+ if(!truePrice.equals(price)){
|
|
|
|
+ throw new BusinessException(ExceptionEnum.BUSINESS_ERROR,"价格错误");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|