|
|
@@ -3,17 +3,22 @@ package com.fdkankan.ucenter.service.impl;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.fdkankan.common.constant.AppConstant;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.constant.ServerCode;
|
|
|
import com.fdkankan.common.constant.TbStatus;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.ucenter.common.OssPath;
|
|
|
import com.fdkankan.ucenter.common.PageInfo;
|
|
|
+import com.fdkankan.ucenter.common.RandomCodeUtil;
|
|
|
+import com.fdkankan.ucenter.common.constants.NacosProperty;
|
|
|
import com.fdkankan.ucenter.entity.*;
|
|
|
import com.fdkankan.ucenter.mapper.IInvoiceMapper;
|
|
|
import com.fdkankan.ucenter.service.*;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.ucenter.util.MyExcelUtil;
|
|
|
import com.fdkankan.ucenter.vo.request.InvoiceParam;
|
|
|
import com.fdkankan.ucenter.vo.request.PlaceOrderParam;
|
|
|
import com.fdkankan.ucenter.vo.response.OrderVo;
|
|
|
@@ -25,6 +30,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
@@ -52,6 +59,8 @@ public class InvoiceServiceImpl extends ServiceImpl<IInvoiceMapper, Invoice> imp
|
|
|
IExpansionOrderService expansionOrderService;
|
|
|
@Autowired
|
|
|
IDownloadOrderService downloadOrderService;
|
|
|
+ @Autowired
|
|
|
+ IMailTemplateService mailTemplateService;
|
|
|
|
|
|
@Override
|
|
|
public Invoice getByOrderId(Long orderId) {
|
|
|
@@ -142,57 +151,87 @@ public class InvoiceServiceImpl extends ServiceImpl<IInvoiceMapper, Invoice> imp
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public BigDecimal getMoney(Long orderId, Integer consumeType) {
|
|
|
- LambdaQueryWrapper<Invoice> wrapper = new LambdaQueryWrapper<>();
|
|
|
- BigDecimal money = BigDecimal.ZERO;
|
|
|
+ public void getMoney(Long orderId, Integer consumeType,Invoice dbEntity) {
|
|
|
+ dbEntity.setMoney(BigDecimal.ZERO);
|
|
|
switch (consumeType){
|
|
|
case 0 :
|
|
|
Order order = orderService.getById(orderId);
|
|
|
if(order.getPaymentStatus().equals("paid")){
|
|
|
- money = order.getTotalAmount();
|
|
|
+ dbEntity.setMoney(order.getTotalAmount());
|
|
|
+ dbEntity.setOrderSn(order.getOrderSn());
|
|
|
+ dbEntity.setProductCount(order.getGoodsTotalCount());
|
|
|
+ dbEntity.setProductName(order.getTradeNum());
|
|
|
+ dbEntity.setPayType(order.getOrderSn());
|
|
|
}
|
|
|
break;
|
|
|
case 1 :
|
|
|
VirtualOrder virtualOrder = virtualOrderService.getById(orderId);
|
|
|
if(virtualOrder.getPayStatus() == 1){
|
|
|
- money = virtualOrder.getAmount();
|
|
|
+ dbEntity.setMoney(virtualOrder.getAmount());
|
|
|
+ dbEntity.setOrderSn(virtualOrder.getOrderSn());
|
|
|
+ dbEntity.setProductCount(virtualOrder.getPoints());
|
|
|
+ dbEntity.setProductName(virtualOrder.getNumber());
|
|
|
+ dbEntity.setPayType(virtualOrder.getOrderSn());
|
|
|
}
|
|
|
break;
|
|
|
case 2 :
|
|
|
IncrementOrder incrementOrder = incrementOrderService.getById(orderId);
|
|
|
if(incrementOrder.getPayStatus() == 1){
|
|
|
- money = incrementOrder.getAmount();
|
|
|
+ dbEntity.setMoney(incrementOrder.getAmount());
|
|
|
+ dbEntity.setOrderSn(incrementOrder.getOrderSn());
|
|
|
+ dbEntity.setProductCount(incrementOrder.getCount());
|
|
|
+
|
|
|
+ if("SE".equals(incrementOrder.getMemberLevels())){
|
|
|
+ dbEntity.setProductName("Senior (Monthly) *" +incrementOrder.getMonthQy());
|
|
|
+ }else {
|
|
|
+ dbEntity.setProductName("Premium (Yearly) *" +incrementOrder.getMonthQy());
|
|
|
+ }
|
|
|
+ if(incrementOrder.getPayType() ==2 ){
|
|
|
+ dbEntity.setPayType("paypal");
|
|
|
+ }
|
|
|
+ if(incrementOrder.getPayType() ==6 ){
|
|
|
+ dbEntity.setPayType("stripe");
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case 3 :
|
|
|
DownloadOrder downloadOrder = downloadOrderService.getById(orderId);
|
|
|
if(downloadOrder.getPayStatus() == 1){
|
|
|
- money = downloadOrder.getAmount();
|
|
|
+ dbEntity.setMoney(downloadOrder.getAmount());
|
|
|
+ dbEntity.setOrderSn(downloadOrder.getOrderSn());
|
|
|
+ dbEntity.setProductCount(downloadOrder.getCount());
|
|
|
+ dbEntity.setProductName("Scene Download");
|
|
|
+ if(downloadOrder.getPayType() ==2 ){
|
|
|
+ dbEntity.setPayType("paypal");
|
|
|
+ }
|
|
|
+ if(downloadOrder.getPayType() ==6 ){
|
|
|
+ dbEntity.setPayType("stripe");
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
- return money;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Invoice openInvoice(InvoiceParam param, String token) {
|
|
|
+ public Invoice openInvoice(InvoiceParam param, String token) {
|
|
|
User user = userService.getByToken(token);
|
|
|
//验证是否已经开票
|
|
|
this.checkInvoice(param.getOrderId(),param.getConsumeType());
|
|
|
//获取开票金额
|
|
|
- BigDecimal money = this.getMoney(param.getOrderId(),param.getConsumeType());
|
|
|
|
|
|
Invoice dbEntity = new Invoice();
|
|
|
|
|
|
+ this.getMoney(param.getOrderId(),param.getConsumeType(),dbEntity);
|
|
|
+
|
|
|
+
|
|
|
BeanUtils.copyProperties(param, dbEntity);
|
|
|
|
|
|
dbEntity.setOrderId(null);
|
|
|
switch (param.getConsumeType()){
|
|
|
case 0: dbEntity.setOrderId(param.getOrderId()); break;
|
|
|
case 1: dbEntity.setVirtualOrderId(param.getOrderId()); break;
|
|
|
- case 2: dbEntity.setIncrementOrderId(param.getOrderId()); break;
|
|
|
+ case 2: dbEntity.setIncrementOrderId(param.getOrderId());break;
|
|
|
case 3: dbEntity.setDownloadOrderId(param.getOrderId()); break;
|
|
|
}
|
|
|
|
|
|
@@ -200,12 +239,44 @@ public class InvoiceServiceImpl extends ServiceImpl<IInvoiceMapper, Invoice> imp
|
|
|
dbEntity.setCameraId(param.getCameraId());
|
|
|
}
|
|
|
dbEntity.setUserId(user.getId());
|
|
|
- dbEntity.setMoney(money);
|
|
|
this.save(dbEntity);
|
|
|
-
|
|
|
+ String invoiceNumber = this.updateInvoiceNumber(dbEntity.getId());
|
|
|
+ dbEntity.setInvoiceNumber(invoiceNumber);
|
|
|
+ sendEmail(dbEntity);
|
|
|
return dbEntity;
|
|
|
}
|
|
|
|
|
|
+ private void sendEmail(Invoice dbEntity) {
|
|
|
+ //国际服直接发送邮件
|
|
|
+ if("aws".equals(NacosProperty.uploadType) && dbEntity.getEmailAddress() != null){
|
|
|
+ MailTemplate mailTemplate = mailTemplateService.getTemplate(14, "en");
|
|
|
+ MyExcelUtil.excelTemplteToPdf(OssPath.localPath,"invoiceTemplate",dbEntity);
|
|
|
+ mailTemplateService.sendMail(dbEntity.getEmailAddress(),mailTemplate,"");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String updateInvoiceNumber(Long id) {
|
|
|
+ String format1 = new SimpleDateFormat("yyMMdd").format(new Date());
|
|
|
+ String invoiceNumber = "W-"+format1 + id;
|
|
|
+ LambdaUpdateWrapper<Invoice> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(Invoice::getId,id);
|
|
|
+ wrapper.set(Invoice::getInvoiceNumber,invoiceNumber);
|
|
|
+ this.update(wrapper);
|
|
|
+ return invoiceNumber;
|
|
|
+ }
|
|
|
+
|
|
|
+ private synchronized String genInVoiceNumber() {
|
|
|
+ String invoiceNumber = RandomCodeUtil.generateCode("W-", 8);
|
|
|
+ LambdaQueryWrapper<Invoice> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(Invoice::getInvoiceNumber,invoiceNumber);
|
|
|
+ List<Invoice> list = this.list(wrapper);
|
|
|
+ if(list == null || list.isEmpty()){
|
|
|
+ return invoiceNumber;
|
|
|
+ }else {
|
|
|
+ return genInVoiceNumber();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public JSONObject getMaxInvoice(InvoiceParam param) {
|
|
|
JSONObject object = new JSONObject();
|