liangpeile před 1 rokem
rodič
revize
91d9a79f38

+ 39 - 5
crmeb-admin/src/main/java/com/zbkj/admin/controller/merchant/NewMerchantApi.java

@@ -4,7 +4,6 @@ package com.zbkj.admin.controller.merchant;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
@@ -18,10 +17,7 @@ import com.zbkj.common.annotation.LogControllerAnnotation;
 import com.zbkj.common.enums.MethodType;
 import com.zbkj.common.model.admin.SystemAdmin;
 import com.zbkj.common.model.bill.MerchantDailyXYED;
-import com.zbkj.common.model.merchant.MerchantSms;
-import com.zbkj.common.model.merchant.MerchantSmsPay;
-import com.zbkj.common.model.merchant.MerchantSmsTemplate;
-import com.zbkj.common.model.merchant.MerchantSmsTiming;
+import com.zbkj.common.model.merchant.*;
 import com.zbkj.common.model.order.Order;
 import com.zbkj.common.model.product.Product;
 import com.zbkj.common.model.product.ProductAttrValue;
@@ -37,12 +33,15 @@ import com.zbkj.common.response.AdminProductListResponse;
 import com.zbkj.common.response.MerchantOrder2PageResponse;
 import com.zbkj.common.response.ProductInfoResponse;
 import com.zbkj.common.result.CommonResult;
+
+import com.zbkj.common.utils.EmailUtil;
 import com.zbkj.common.utils.SecurityUtil;
 import com.zbkj.service.dao.MerchantSmsTimingDao;
 import com.zbkj.service.service.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
@@ -111,6 +110,8 @@ public class NewMerchantApi {
     private DynamicScheduledTask dynamicScheduledTask;
     @Autowired
     private TaskMessageService taskMessageService;
+    @Autowired
+    private EmailUtil emailUtil;
 
 
     //    @PreAuthorize("hasAuthority('merchant:productAttrValueIntegral:edit')")
@@ -572,4 +573,37 @@ public class NewMerchantApi {
 
         return CommonResult.success(merchantSmsTiming);
     }
+
+
+    @ApiOperation(value = "邮件发送")
+    @RequestMapping(value = "/emailMessage", method = RequestMethod.POST)
+    public CommonResult<?> emailMessage() {
+
+        //创建订单完成后发送邮件
+        HashMap<String, String> map = systemConfigService.info(59);
+        String isCerateTemp = map.get("isCerateTemp");
+        String email="1015018539@qq.com";
+        String toemail="18866983575@163.com";
+//        Integer merId = order.getMerId();
+//        Merchant merchant = merchantService.getById(merId);
+        if (StringUtils.isNotBlank(isCerateTemp)) {
+            if ("1".equals(isCerateTemp)) {
+                String fromEmail = map.get("fromEmail");
+                String emailPassword = map.get("emailPassword");
+                String cerateTemp = map.get("cerateTemp");
+                String cerateTempTitle = map.get("cerateTempTitle");
+                String afterEmail = StringUtils.substringAfter(email, "@");
+                if ("163.com".equals(afterEmail)) {
+                    emailUtil.sendMessage(fromEmail, emailPassword, "smtp.163.com", toemail, cerateTempTitle, cerateTemp);
+                } else if ("qq.com".equals(afterEmail)) {
+                    emailUtil.sendMessage(fromEmail, emailPassword, "smtp.qq.com", toemail, cerateTempTitle, cerateTemp);
+
+                }
+
+            }
+        }
+
+
+        return CommonResult.success();
+    }
 }

+ 10 - 0
crmeb-common/pom.xml

@@ -48,6 +48,16 @@
             <groupId>org.apache.tomcat</groupId>
             <artifactId>tomcat-jsp-api</artifactId>
         </dependency>
+        <!--邮件发送依赖-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-mail</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.mail</groupId>
+            <artifactId>javax.mail</artifactId>
+            <version>1.6.2</version>
+        </dependency>
 
         <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
         <dependency>

+ 3 - 0
crmeb-common/src/main/java/com/zbkj/common/vo/MerchantConfigInfoVo.java

@@ -88,6 +88,9 @@ public class MerchantConfigInfoVo implements Serializable {
     @ApiModelProperty(value = "pc背景图")
     private String pcBackImage;
 
+    @ApiModelProperty(value = "商户邮箱")
+    private String email;
+
     @ApiModelProperty(value = "自提开关:0-关闭,1-开启")
     @NotNull(message = "请选择是否开启自提")
     private Boolean isTakeTheir;

+ 52 - 0
crmeb-front/src/main/java/com/zbkj/front/service/impl/FrontOrderServiceImpl.java

@@ -30,12 +30,14 @@ import com.zbkj.common.request.*;
 import com.zbkj.common.response.*;
 import com.zbkj.common.utils.CrmebDateUtil;
 import com.zbkj.common.utils.CrmebUtil;
+import com.zbkj.common.utils.EmailUtil;
 import com.zbkj.common.utils.RedisUtil;
 import com.zbkj.common.vo.*;
 import com.zbkj.front.service.FrontOrderService;
 import com.zbkj.front.service.SeckillService;
 import com.zbkj.service.dao.UserDao;
 import com.zbkj.service.service.*;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
@@ -122,6 +124,8 @@ public class FrontOrderServiceImpl implements FrontOrderService {
     private AsyncService asyncService;
     @Autowired
     private FrontOrderService frontOrderService;
+    @Autowired
+    private EmailUtil emailUtil;
 
     /**
      * 订单预下单
@@ -1516,6 +1520,30 @@ public class FrontOrderServiceImpl implements FrontOrderService {
     public Boolean takeDelivery(String orderNo) {
         Integer userId = userService.getUserIdException();
         Order order = orderService.getByOrderNo(orderNo);
+        //确认收货订单完成后发送邮件
+        HashMap<String, String> map = systemConfigService.info(59);
+
+        Integer merId = order.getMerId();
+        if (0 != merId){
+            String isCompleteTemp = map.get("isCompleteTemp");
+            Merchant merchant = merchantService.getById(merId);
+            if (StringUtils.isNotBlank(isCompleteTemp)) {
+                if ("1".equals(isCompleteTemp)) {
+                    String fromEmail = map.get("fromEmail");
+                    String emailPassword = map.get("emailPassword");
+                    String completeTemp = map.get("completeTemp");
+                    String completeTempTitle = map.get("completeTempTitle");
+                    String afterEmail = StringUtils.substringAfter(fromEmail, "@");
+                    if ("163.com".equals(afterEmail)) {
+                        emailUtil.sendMessage(fromEmail, emailPassword, "smtp.163.com", merchant.getEmail(), completeTempTitle, completeTemp);
+                    } else if ("qq.com".equals(afterEmail)) {
+                        emailUtil.sendMessage(fromEmail, emailPassword, "smtp.qq.com", merchant.getEmail(), completeTempTitle, completeTemp);
+
+                    }
+
+                }
+            }
+        }
         if (!order.getUid().equals(userId)) {
             throw new CrmebException("订单不存在");
         }
@@ -1698,6 +1726,30 @@ public class FrontOrderServiceImpl implements FrontOrderService {
             return Boolean.TRUE;
         });
         if (!execute) throw new CrmebException("申请退款失败");
+        //售后完成后发送邮件
+        HashMap<String, String> map = systemConfigService.info(59);
+        String isAfterTemp = map.get("isAfterTemp");
+        Integer merId = order.getMerId();
+        if (0 != merId){
+            Merchant merchant = merchantService.getById(merId);
+            if (StringUtils.isNotBlank(isAfterTemp)) {
+                if ("1".equals(isAfterTemp)) {
+                    String fromEmail = map.get("fromEmail");
+                    String emailPassword = map.get("emailPassword");
+                    String afterTemp = map.get("afterTemp");
+                    String afterTempTitle = map.get("afterTempTitle");
+                    String afterEmail = StringUtils.substringAfter(fromEmail, "@");
+                    if ("163.com".equals(afterEmail)) {
+                        emailUtil.sendMessage(fromEmail, emailPassword, "smtp.163.com", merchant.getEmail(), afterTempTitle, afterTemp);
+                    } else if ("qq.com".equals(afterEmail)) {
+                        emailUtil.sendMessage(fromEmail, emailPassword, "smtp.qq.com", merchant.getEmail(), afterTempTitle, afterTemp);
+
+                    }
+
+                }
+            }
+        }
+
         return execute;
     }
 

+ 273 - 65
crmeb-service/src/main/java/com/zbkj/service/service/impl/PayServiceImpl.java

@@ -18,7 +18,6 @@ import com.alipay.api.request.AlipayTradeWapPayRequest;
 import com.alipay.api.response.AlipayTradeAppPayResponse;
 import com.alipay.api.response.AlipayTradeQueryResponse;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.zbkj.common.constants.*;
 import com.zbkj.common.exception.CrmebException;
 import com.zbkj.common.model.bill.Bill;
@@ -44,6 +43,7 @@ import com.zbkj.common.vo.*;
 import com.zbkj.common.vo.wxvedioshop.ShopOrderAddResultVo;
 import com.zbkj.common.vo.wxvedioshop.order.*;
 import com.zbkj.service.service.*;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
@@ -59,7 +59,6 @@ import java.util.stream.Collectors;
 
 /**
  * PayServiceImpl 接口实现
-
  */
 @Service
 public class PayServiceImpl implements PayService {
@@ -136,6 +135,8 @@ public class PayServiceImpl implements PayService {
     private UserBypassAccountService userBypassAccountService;
     @Autowired
     private UserEnterpriseRecordService userEnterpriseRecordService;
+    @Autowired
+    private EmailUtil emailUtil;
 
     /**
      * 获取支付配置
@@ -177,6 +178,8 @@ public class PayServiceImpl implements PayService {
             throw new CrmebException("订单状态异常");
         }
         User user = userService.getInfo();
+
+
         // 根据支付类型进行校验,更换支付类型
         order.setPayType(orderPayRequest.getPayType());
         order.setPayChannel(orderPayRequest.getPayChannel());
@@ -188,22 +191,22 @@ public class PayServiceImpl implements PayService {
         }
         //加企业信息id,为以后 如果人员跳槽还能查到另个公司购买信息做准备
         LambdaQueryWrapper<UserEnterprise> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq( UserEnterprise::getUserId, order.getUid() );
-        queryWrapper.eq( UserEnterprise::getIsDelete, 0 );
-        UserEnterprise one = userEnterpriseService.getOne( queryWrapper, false );
+        queryWrapper.eq(UserEnterprise::getUserId, order.getUid());
+        queryWrapper.eq(UserEnterprise::getIsDelete, 0);
+        UserEnterprise one = userEnterpriseService.getOne(queryWrapper, false);
         if (one == null) {
             LambdaQueryWrapper<UserBypassAccount> queryWrapper2 = new LambdaQueryWrapper<>();
-            queryWrapper2.eq( UserBypassAccount::getUserId, order.getUid() );
-            queryWrapper2.eq( UserBypassAccount::getIsDelete, 0 );
-            UserBypassAccount one1 = userBypassAccountService.getOne( queryWrapper2, false );
+            queryWrapper2.eq(UserBypassAccount::getUserId, order.getUid());
+            queryWrapper2.eq(UserBypassAccount::getIsDelete, 0);
+            UserBypassAccount one1 = userBypassAccountService.getOne(queryWrapper2, false);
             if (one1 == null) {
 
             } else {
-                one = userEnterpriseService.getById( one1.getEnterpriseId() );
+                one = userEnterpriseService.getById(one1.getEnterpriseId());
             }
         }
-        if (one!=null){
-            order.setQyId( one.getId() );
+        if (one != null) {
+            order.setQyId(one.getId());
         }
 
         OrderPayResultResponse response = new OrderPayResultResponse();
@@ -222,6 +225,34 @@ public class PayServiceImpl implements PayService {
             Boolean yueBoolean = yuePay(order, user);
             response.setStatus(yueBoolean);
             logger.info("余额支付 response : {}", JSON.toJSONString(response));
+            //创建订单完成后发送邮件
+            HashMap<String, String> map = systemConfigService.info(59);
+            String isCerateTemp = map.get("isCerateTemp");
+            String orderNo = order.getOrderNo();
+            List<OrderDetail> byOrderNo = orderDetailService.getByOrderNo(orderNo);
+            for (OrderDetail orderDetail : byOrderNo) {
+                Integer merId = orderDetail.getMerId();
+                Merchant merchant = merchantService.getById(merId);
+                if (StringUtils.isNotBlank(isCerateTemp)) {
+                    if ("1".equals(isCerateTemp)) {
+                        String fromEmail = map.get("fromEmail");
+                        String emailPassword = map.get("emailPassword");
+                        String cerateTemp = map.get("cerateTemp");
+                        String cerateTempTitle = map.get("cerateTempTitle");
+                        String afterEmail = StringUtils.substringAfter(fromEmail, "@");
+                        if ("163.com".equals(afterEmail)) {
+                            emailUtil.sendMessage(fromEmail, emailPassword, "smtp.163.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+                        } else if ("qq.com".equals(afterEmail)) {
+                            emailUtil.sendMessage(fromEmail, emailPassword, "smtp.qq.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+
+                        }
+
+                    }
+
+                }
+            }
+
+
             return response;
         }
         // 微信支付,调用微信预下单,返回拉起微信支付需要的信息
@@ -232,10 +263,11 @@ public class PayServiceImpl implements PayService {
             response.setStatus(true);
             response.setJsConfig(vo);
             logger.info("订单支付 微信下单 response :{}", JSON.toJSONString(response));
+
         }
 
         // 微信视频号下单 需要额外调用支付参数
-        if(order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_MINI_VIDEO)){
+        if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_MINI_VIDEO)) {
             WxPayJsResultVo vo = new WxPayJsResultVo();
             UserToken tokenByUser = userTokenService.getTokenByUserId(user.getId(), UserConstants.USER_TOKEN_TYPE_ROUTINE);
             List<OrderDetail> orderDetailList = orderDetailService.getByOrderNo(order.getOrderNo());
@@ -287,11 +319,11 @@ public class PayServiceImpl implements PayService {
             shopOrderAddVo.setMerId(order.getMerId());
 
             // 订单路由地址
-            shopOrderAddVo.setPath("/pages/users/order_details/index?orderNo="+orderPayRequest.getOrderNo());
+            shopOrderAddVo.setPath("/pages/users/order_details/index?orderNo=" + orderPayRequest.getOrderNo());
 
             // 组装订单信息 视频号都是单品 最多是多量
             List<MerchantOrder> merchantOrderList = merchantOrderService.getByOrderNo(orderPayRequest.getOrderNo());
-            if(ObjectUtil.isNull(merchantOrderList) || merchantOrderList.size() == 0) {
+            if (ObjectUtil.isNull(merchantOrderList) || merchantOrderList.size() == 0) {
                 throw new CrmebException("未找到视频号商品订单");
             }
             MerchantOrder CurrentMerchantOrder = merchantOrderList.get(0);
@@ -316,13 +348,41 @@ public class PayServiceImpl implements PayService {
             ShopOrderGetPaymentParamsRersponseVo shopOrderGetPaymentParamsRersponseVo = wechatVideoOrderService.shopOrderGetPaymentParams(videoPaymentRequestVo);
             logger.info("视频号下单时 获取的支付参数 {}", JSON.toJSONString(shopOrderGetPaymentParamsRersponseVo));
             response.setStatus(true);
-            vo.setTimeStamp(WxPayUtil.getCurrentTimestamp()+"");
+            vo.setTimeStamp(WxPayUtil.getCurrentTimestamp() + "");
             vo.setNonceStr(shopOrderGetPaymentParamsRersponseVo.getNonceStr());
             vo.setPackages(shopOrderGetPaymentParamsRersponseVo.get_package());
             vo.setPaySign(shopOrderGetPaymentParamsRersponseVo.getPaySign());
             vo.setSignType(shopOrderGetPaymentParamsRersponseVo.getSignType());
             response.setJsConfig(vo);
             logger.info("订单支付 视频号下单 response:{}", JSON.toJSONString(response));
+            //创建订单完成后发送邮件
+            HashMap<String, String> map = systemConfigService.info(59);
+            String isCerateTemp = map.get("isCerateTemp");
+            String orderNo = order.getOrderNo();
+            List<OrderDetail> byOrderNo = orderDetailService.getByOrderNo(orderNo);
+            for (OrderDetail orderDetail : byOrderNo) {
+                Integer merId = orderDetail.getMerId();
+
+                Merchant merchant = merchantService.getById(merId);
+                if (StringUtils.isNotBlank(isCerateTemp)) {
+                    if ("1".equals(isCerateTemp)) {
+                        String fromEmail = map.get("fromEmail");
+                        String emailPassword = map.get("emailPassword");
+                        String cerateTemp = map.get("cerateTemp");
+                        String cerateTempTitle = map.get("cerateTempTitle");
+                        String afterEmail = StringUtils.substringAfter(fromEmail, "@");
+                        if ("163.com".equals(afterEmail)) {
+                            emailUtil.sendMessage(fromEmail, emailPassword, "smtp.163.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+                        } else if ("qq.com".equals(afterEmail)) {
+                            emailUtil.sendMessage(fromEmail, emailPassword, "smtp.qq.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+
+                        }
+
+                    }
+
+                }
+            }
+
             return response;
         }
         // 微信支付,调用微信预下单,返回拉起微信支付需要的信息
@@ -333,6 +393,33 @@ public class PayServiceImpl implements PayService {
             response.setStatus(true);
             response.setJsConfig(vo);
             logger.info("订单支付 微信下单 response :{}", JSON.toJSONString(response));
+            //创建订单完成后发送邮件
+            HashMap<String, String> map = systemConfigService.info(59);
+            String isCerateTemp = map.get("isCerateTemp");
+            String orderNo = order.getOrderNo();
+            List<OrderDetail> byOrderNo = orderDetailService.getByOrderNo(orderNo);
+            for (OrderDetail orderDetail : byOrderNo) {
+                Integer merId = orderDetail.getMerId();
+
+                Merchant merchant = merchantService.getById(merId);
+                if (StringUtils.isNotBlank(isCerateTemp)) {
+                    if ("1".equals(isCerateTemp)) {
+                        String fromEmail = map.get("fromEmail");
+                        String emailPassword = map.get("emailPassword");
+                        String cerateTemp = map.get("cerateTemp");
+                        String cerateTempTitle = map.get("cerateTempTitle");
+                        String afterEmail = StringUtils.substringAfter(fromEmail, "@");
+                        if ("163.com".equals(afterEmail)) {
+                            emailUtil.sendMessage(fromEmail, emailPassword, "smtp.163.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+                        } else if ("qq.com".equals(afterEmail)) {
+                            emailUtil.sendMessage(fromEmail, emailPassword, "smtp.qq.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+
+                        }
+
+                    }
+
+                }
+            }
             return response;
         }
 
@@ -342,10 +429,66 @@ public class PayServiceImpl implements PayService {
             response.setStatus(true);
             response.setAlipayRequest(result);
             logger.info("订单支付 支付宝 response :{}", JSON.toJSONString(response));
+            //创建订单完成后发送邮件
+            HashMap<String, String> map = systemConfigService.info(59);
+            String isCerateTemp = map.get("isCerateTemp");
+            String orderNo = order.getOrderNo();
+            List<OrderDetail> byOrderNo = orderDetailService.getByOrderNo(orderNo);
+            for (OrderDetail orderDetail : byOrderNo) {
+                Integer merId = orderDetail.getMerId();
+
+                Merchant merchant = merchantService.getById(merId);
+                if (StringUtils.isNotBlank(isCerateTemp)) {
+                    if ("1".equals(isCerateTemp)) {
+                        String fromEmail = map.get("fromEmail");
+                        String emailPassword = map.get("emailPassword");
+                        String cerateTemp = map.get("cerateTemp");
+                        String cerateTempTitle = map.get("cerateTempTitle");
+                        String afterEmail = StringUtils.substringAfter(fromEmail, "@");
+                        if ("163.com".equals(afterEmail)) {
+                            emailUtil.sendMessage(fromEmail, emailPassword, "smtp.163.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+                        } else if ("qq.com".equals(afterEmail)) {
+                            emailUtil.sendMessage(fromEmail, emailPassword, "smtp.qq.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+
+                        }
+
+                    }
+
+                }
+            }
             return response;
         }
         response.setStatus(false);
         logger.info("订单支付 END response:{}", JSON.toJSONString(response));
+
+
+        //创建订单完成后发送邮件
+        HashMap<String, String> map = systemConfigService.info(59);
+        String isCerateTemp = map.get("isCerateTemp");
+        String orderNo = order.getOrderNo();
+        List<OrderDetail> byOrderNo = orderDetailService.getByOrderNo(orderNo);
+        for (OrderDetail orderDetail : byOrderNo) {
+            Integer merId = orderDetail.getMerId();
+
+            Merchant merchant = merchantService.getById(merId);
+            if (StringUtils.isNotBlank(isCerateTemp)) {
+                if ("1".equals(isCerateTemp)) {
+                    String fromEmail = map.get("fromEmail");
+                    String emailPassword = map.get("emailPassword");
+                    String cerateTemp = map.get("cerateTemp");
+                    String cerateTempTitle = map.get("cerateTempTitle");
+                    String afterEmail = StringUtils.substringAfter(fromEmail, "@");
+                    if ("163.com".equals(afterEmail)) {
+                        emailUtil.sendMessage(fromEmail, emailPassword, "smtp.163.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+                    } else if ("qq.com".equals(afterEmail)) {
+                        emailUtil.sendMessage(fromEmail, emailPassword, "smtp.qq.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+
+                    }
+
+                }
+
+            }
+        }
         return response;
     }
 
@@ -370,58 +513,58 @@ public class PayServiceImpl implements PayService {
         order.setIsLineOfCredit(1);
         order.setPayChannel(orderPayRequest.getPayChannel());
         // 信用额度支付
-        if (!orderPayRequest.getPayType().equals("信用额度") ){
+        if (!orderPayRequest.getPayType().equals("信用额度")) {
             throw new CrmebException("该支付是信用额度支付,传错参数");
         }
-        UserEnterprise one =null;
-        List<OrderDetail> byOrderNo = orderDetailService.getByOrderNo( order.getOrderNo() );
+        UserEnterprise one = null;
+        List<OrderDetail> byOrderNo = orderDetailService.getByOrderNo(order.getOrderNo());
         boolean isSameName = byOrderNo.stream()
                 .map(OrderDetail::getMerId)
                 .distinct()
                 .limit(2)
                 .count() <= 1;
-        if (!isSameName){
+        if (!isSameName) {
             throw new CrmebException("信用额度支付 不允许多家商户商品购买");
         }
         //查询信用额度够不够
-        if (orderPayRequest.getUsertype().equals("企业用户") ){
+        if (orderPayRequest.getUsertype().equals("企业用户")) {
             LambdaQueryWrapper<UserEnterprise> queryWrapper = new LambdaQueryWrapper<>();
-            queryWrapper.eq( UserEnterprise::getUserId, user.getId() );
-            queryWrapper.eq( UserEnterprise::getIsDelete, 0 );
-             one = userEnterpriseService.getOne( queryWrapper );
-            if (one==null){
+            queryWrapper.eq(UserEnterprise::getUserId, user.getId());
+            queryWrapper.eq(UserEnterprise::getIsDelete, 0);
+            one = userEnterpriseService.getOne(queryWrapper);
+            if (one == null) {
                 throw new CrmebException("企业用户查询失败,信用额度查询失败");
             }
-            if (one.getMerchantId()!=byOrderNo.get( 0 ).getMerId()){
+            if (one.getMerchantId() != byOrderNo.get(0).getMerId()) {
                 throw new CrmebException("你购买的商品不是绑定信用商户的商品,所以不能使用信用额度支付");
             }
             if (one.getAvailableLineOfCredit().compareTo(order.getPayPrice()) < 0) {
                 throw new CrmebException("企业信用额度不足");
             }
-            order.setAccount( one.getAccount() );
-            order.setQyName( one.getEnterpriseName() );
+            order.setAccount(one.getAccount());
+            order.setQyName(one.getEnterpriseName());
             //加企业信息id,为以后 如果人员跳槽还能查到另个公司购买信息做准备
-            order.setQyId( one.getId() );
+            order.setQyId(one.getId());
         }
-        if (orderPayRequest.getUsertype().equals("企业子用户") ){
+        if (orderPayRequest.getUsertype().equals("企业子用户")) {
             LambdaQueryWrapper<UserBypassAccount> queryWrapper2 = new LambdaQueryWrapper<>();
-            queryWrapper2.eq( UserBypassAccount::getUserId, user.getId() );
-            queryWrapper2.eq( UserBypassAccount::getIsDelete, 0 );
-            UserBypassAccount one1 = userBypassAccountService.getOne( queryWrapper2 );
-            if (one1==null){
+            queryWrapper2.eq(UserBypassAccount::getUserId, user.getId());
+            queryWrapper2.eq(UserBypassAccount::getIsDelete, 0);
+            UserBypassAccount one1 = userBypassAccountService.getOne(queryWrapper2);
+            if (one1 == null) {
                 throw new CrmebException("企业用户查询失败,信用额度查询失败");
             }
-            one = userEnterpriseService.getById( one1.getEnterpriseId() );
-            if (one.getMerchantId()!=byOrderNo.get( 0 ).getMerId()){
+            one = userEnterpriseService.getById(one1.getEnterpriseId());
+            if (one.getMerchantId() != byOrderNo.get(0).getMerId()) {
                 throw new CrmebException("你购买的商品不是绑定信用商户的商品,所以不能使用信用额度支付");
             }
             if (one.getAvailableLineOfCredit().compareTo(order.getPayPrice()) < 0) {
                 throw new CrmebException("企业信用额度不足");
             }
-            order.setAccount( one1.getAccount() );
-            order.setQyName( one.getEnterpriseName() );
+            order.setAccount(one1.getAccount());
+            order.setQyName(one.getEnterpriseName());
             //加企业信息id,为以后 如果人员跳槽还能查到另个公司购买信息做准备
-            order.setQyId( one.getId() );
+            order.setQyId(one.getId());
         }
 
         OrderPayResultResponse response = new OrderPayResultResponse();
@@ -431,16 +574,71 @@ public class PayServiceImpl implements PayService {
 
         // 信用额度支付
         if (order.getPayType().equals("信用额度")) {
-            Boolean yueBoolean = XYEDPay(order, user,one);
+            Boolean yueBoolean = XYEDPay(order, user, one);
             response.setStatus(yueBoolean);
             logger.info("信用额度支付 response : {}", JSON.toJSONString(response));
+            //创建订单完成后发送邮件
+            HashMap<String, String> map = systemConfigService.info(59);
+            String isCerateTemp = map.get("isCerateTemp");
+            String orderNo = order.getOrderNo();
+            List<OrderDetail> byOrderNo1 = orderDetailService.getByOrderNo(orderNo);
+            for (OrderDetail orderDetail : byOrderNo1) {
+                Integer merId = orderDetail.getMerId();
+
+                Merchant merchant = merchantService.getById(merId);
+                if (StringUtils.isNotBlank(isCerateTemp)) {
+                    if ("1".equals(isCerateTemp)) {
+                        String fromEmail = map.get("fromEmail");
+                        String emailPassword = map.get("emailPassword");
+                        String cerateTemp = map.get("cerateTemp");
+                        String cerateTempTitle = map.get("cerateTempTitle");
+                        String afterEmail = StringUtils.substringAfter(fromEmail, "@");
+                        if ("163.com".equals(afterEmail)) {
+                            emailUtil.sendMessage(fromEmail, emailPassword, "smtp.163.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+                        } else if ("qq.com".equals(afterEmail)) {
+                            emailUtil.sendMessage(fromEmail, emailPassword, "smtp.qq.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+
+                        }
+
+                    }
+
+                }
+            }
             return response;
         }
 
         response.setStatus(false);
         logger.info("订单支付 END response:{}", JSON.toJSONString(response));
+        //支付完成完成后发送邮件
+        HashMap<String, String> map = systemConfigService.info(59);
+        String isCerateTemp = map.get("isCerateTemp");
+        String orderNo = order.getOrderNo();
+        List<OrderDetail> byOrderNo1 = orderDetailService.getByOrderNo(orderNo);
+        for (OrderDetail orderDetail : byOrderNo1) {
+            Integer merId = orderDetail.getMerId();
+
+            Merchant merchant = merchantService.getById(merId);
+            if (StringUtils.isNotBlank(isCerateTemp)) {
+                if ("1".equals(isCerateTemp)) {
+                    String fromEmail = map.get("fromEmail");
+                    String emailPassword = map.get("emailPassword");
+                    String cerateTemp = map.get("cerateTemp");
+                    String cerateTempTitle = map.get("cerateTempTitle");
+                    String afterEmail = StringUtils.substringAfter(fromEmail, "@");
+                    if ("163.com".equals(afterEmail)) {
+                        emailUtil.sendMessage(fromEmail, emailPassword, "smtp.163.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+                    } else if ("qq.com".equals(afterEmail)) {
+                        emailUtil.sendMessage(fromEmail, emailPassword, "smtp.qq.com", merchant.getEmail(), cerateTempTitle, cerateTemp);
+
+                    }
+
+                }
+
+            }
+        }
         return response;
     }
+
     /**
      * 查询支付结果
      *
@@ -555,6 +753,7 @@ public class PayServiceImpl implements PayService {
     /**
      * 支付成功后置处理
      * 经验逻辑确定后,可在处理中加入经验处理
+     *
      * @param orderNo 订单编号
      */
     @Override
@@ -608,6 +807,7 @@ public class PayServiceImpl implements PayService {
 
     /**
      * 支付成功后置处理(临时)
+     *
      * @param orderNo 订单编号
      */
     @Override
@@ -721,9 +921,10 @@ public class PayServiceImpl implements PayService {
 
     /**
      * 单商户订单处理
-     * @param order 主订单
+     *
+     * @param order         主订单
      * @param merchantOrder 商户订单
-     * @param user 用户
+     * @param user          用户
      */
     private Boolean oneMerchantOrderProcessing(Order order, MerchantOrder merchantOrder, User user) {
         List<UserIntegralRecord> integralList = CollUtil.newArrayList();
@@ -811,9 +1012,10 @@ public class PayServiceImpl implements PayService {
 
     /**
      * 多商户订单处理
-     * @param order 主订单
+     *
+     * @param order             主订单
      * @param merchantOrderList 商户订单列表
-     * @param user 用户
+     * @param user              用户
      */
     private Boolean manyMerchantOrderProcessing(Order order, List<MerchantOrder> merchantOrderList, User user) {
         List<UserIntegralRecord> integralList = CollUtil.newArrayList();
@@ -949,7 +1151,7 @@ public class PayServiceImpl implements PayService {
         if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_PUBLIC) && payNotification.getIsWechat().equals(1) && user.getIsWechatPublic()) {
             userToken = userTokenService.getTokenByUserId(user.getId(), UserConstants.USER_TOKEN_TYPE_WECHAT);
             if (ObjectUtil.isNull(userToken)) {
-                return ;
+                return;
             }
             // 发送微信模板消息
             /**
@@ -969,13 +1171,13 @@ public class PayServiceImpl implements PayService {
             temMap.put("keyword5", order.getPayTime().toString());
             temMap.put(Constants.WE_CHAT_TEMP_KEY_END, "欢迎下次再来!");
             templateMessageService.pushTemplateMessage(payNotification.getWechatId(), temMap, userToken.getToken());
-            return ;
+            return;
         }
         if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_MINI) && payNotification.getIsRoutine().equals(1)) {
             // 小程序发送订阅消息
             userToken = userTokenService.getTokenByUserId(user.getId(), UserConstants.USER_TOKEN_TYPE_ROUTINE);
             if (ObjectUtil.isNull(userToken)) {
-                return ;
+                return;
             }
             // 组装数据
 //            temMap.put("character_string1", storeOrder.getOrderId());
@@ -991,7 +1193,8 @@ public class PayServiceImpl implements PayService {
 
     /**
      * 佣金处理
-     * @param merchantOrder 商户订单部分
+     *
+     * @param merchantOrder   商户订单部分
      * @param orderDetailList 订单详情列表
      * @return 佣金记录列表
      */
@@ -1002,7 +1205,7 @@ public class PayServiceImpl implements PayService {
         }
         // 检测商城是否开启分销功能
         String isOpen = systemConfigService.getValueByKey(SysConfigConstants.RETAIL_STORE_SWITCH);
-        if(StrUtil.isBlank(isOpen) || isOpen.equals("0")){
+        if (StrUtil.isBlank(isOpen) || isOpen.equals("0")) {
             return CollUtil.newArrayList();
         }
         long count = orderDetailList.stream().filter(e -> e.getSubBrokerageType() > 0).count();
@@ -1012,7 +1215,7 @@ public class PayServiceImpl implements PayService {
         // 查找订单所属人信息
         User user = userService.getById(merchantOrder.getUid());
         // 当前用户不存在 没有上级 或者 当用用户上级时自己  直接返回
-        if(ObjectUtil.isNull(user.getSpreadUid()) || user.getSpreadUid() < 1 || user.getSpreadUid().equals(merchantOrder.getUid())){
+        if (ObjectUtil.isNull(user.getSpreadUid()) || user.getSpreadUid() < 1 || user.getSpreadUid().equals(merchantOrder.getUid())) {
             return CollUtil.newArrayList();
         }
         // 获取参与分佣的人(两级)
@@ -1089,15 +1292,16 @@ public class PayServiceImpl implements PayService {
 
     /**
      * 佣金处理
-     * @param order 订单
+     *
+     * @param order             订单
      * @param merchantOrderList 商户订单部分
-     * @param orderDetailList 订单详情列表
+     * @param orderDetailList   订单详情列表
      * @return 佣金记录列表
      */
     private List<UserBrokerageRecord> assignCommission(Order order, List<MerchantOrder> merchantOrderList, List<OrderDetail> orderDetailList) {
         // 检测商城是否开启分销功能
         String isOpen = systemConfigService.getValueByKey(SysConfigConstants.RETAIL_STORE_SWITCH);
-        if(StrUtil.isBlank(isOpen) || isOpen.equals("0")){
+        if (StrUtil.isBlank(isOpen) || isOpen.equals("0")) {
             return CollUtil.newArrayList();
         }
         // 营销产品不参与
@@ -1111,7 +1315,7 @@ public class PayServiceImpl implements PayService {
         // 查找订单所属人信息
         User user = userService.getById(order.getUid());
         // 当前用户不存在 没有上级 或者 当用用户上级时自己  直接返回
-        if(ObjectUtil.isNull(user.getSpreadUid()) || user.getSpreadUid() < 1 || user.getSpreadUid().equals(order.getUid())){
+        if (ObjectUtil.isNull(user.getSpreadUid()) || user.getSpreadUid() < 1 || user.getSpreadUid().equals(order.getUid())) {
             return CollUtil.newArrayList();
         }
         // 获取参与分佣的人(两级)
@@ -1192,6 +1396,7 @@ public class PayServiceImpl implements PayService {
 
     /**
      * 获取参与分佣人员(两级)
+     *
      * @param spreadUid 一级分佣人Uid
      * @return List<MyRecord>
      */
@@ -1291,6 +1496,7 @@ public class PayServiceImpl implements PayService {
 
     /**
      * 初始化订单分帐表
+     *
      * @param merchantOrder 商户部分订单
      * @return 分账记录
      */
@@ -1316,8 +1522,9 @@ public class PayServiceImpl implements PayService {
 
     /**
      * 初始化订单支付商户账单表
+     *
      * @param merchantOrder 商户订单部分
-     * @param merchantFee 商户分账金额
+     * @param merchantFee   商户分账金额
      */
     private MerchantBill initPayMerchantBill(MerchantOrder merchantOrder, BigDecimal merchantFee) {
         MerchantBill merchantBill = new MerchantBill();
@@ -1333,8 +1540,9 @@ public class PayServiceImpl implements PayService {
 
     /**
      * 初始化订单支付平台账单表
-     * @param order 订单
-     * @param merchantOrder 商户订单部分
+     *
+     * @param order              订单
+     * @param merchantOrder      商户订单部分
      * @param orderProfitSharing 分账数据
      * @return List
      */
@@ -1659,7 +1867,7 @@ public class PayServiceImpl implements PayService {
     /**
      * 信用额度支付
      */
-    private Boolean XYEDPay(Order order, User user,UserEnterprise userEnterprise) {
+    private Boolean XYEDPay(Order order, User user, UserEnterprise userEnterprise) {
         // 信用额度扣除
         Boolean execute = transactionTemplate.execute(e -> {
             Boolean update = Boolean.TRUE;
@@ -1671,15 +1879,15 @@ public class PayServiceImpl implements PayService {
             // 这里只扣除金额,账单记录在task中处理
             if (order.getPayPrice().compareTo(BigDecimal.ZERO) > 0) {
 //                update = userService.updateNowMoney(order.getUid(), order.getPayPrice(), Constants.OPERATION_TYPE_SUBTRACT);
-                BigDecimal subtract = userEnterprise.getAvailableLineOfCredit().subtract( order.getPayPrice() ); //可用额度 减去 订单金额等于现在的可用额度
+                BigDecimal subtract = userEnterprise.getAvailableLineOfCredit().subtract(order.getPayPrice()); //可用额度 减去 订单金额等于现在的可用额度
 
-                BigDecimal subtract2 = userEnterprise.getUsedLineOfCredit().add( order.getPayPrice() );//已用额度 加上 订单金额等于现在的 已用信用额度
+                BigDecimal subtract2 = userEnterprise.getUsedLineOfCredit().add(order.getPayPrice());//已用额度 加上 订单金额等于现在的 已用信用额度
 
-                UserEnterprise userEnterprise1 =new UserEnterprise();
-                userEnterprise1.setId( userEnterprise.getId() );
-                userEnterprise1.setAvailableLineOfCredit( subtract );
-                userEnterprise1.setUsedLineOfCredit( subtract2 );
-                update = userEnterpriseService.updateById( userEnterprise1 );
+                UserEnterprise userEnterprise1 = new UserEnterprise();
+                userEnterprise1.setId(userEnterprise.getId());
+                userEnterprise1.setAvailableLineOfCredit(subtract);
+                userEnterprise1.setUsedLineOfCredit(subtract2);
+                update = userEnterpriseService.updateById(userEnterprise1);
                 if (!update) {
                     logger.error("信用额度支付,扣除信用额度支付失败,orderNo = {}", order.getOrderNo());
                     e.setRollbackOnly();
@@ -1852,7 +2060,7 @@ public class PayServiceImpl implements PayService {
         List<Integer> proIdList = orderDetailList.stream().map(OrderDetail::getProductId).distinct().collect(Collectors.toList());
         for (Integer proId : proIdList) {
             List<ProductCoupon> couponsForGiveUser = productCouponService.getListByProductId(proId);
-            for (int i = 0; i < couponsForGiveUser.size();) {
+            for (int i = 0; i < couponsForGiveUser.size(); ) {
                 ProductCoupon productCoupon = couponsForGiveUser.get(i);
                 MyRecord record = couponUserService.paySuccessGiveAway(productCoupon.getCouponId(), order.getUid());
                 if (record.getStr("status").equals("fail")) {