|
|
@@ -14,9 +14,8 @@ import com.dk.common.model.vo.mst.StaffVO;
|
|
|
import com.dk.common.response.ResponseCodeEnum;
|
|
|
import com.dk.common.response.ResponseResultUtil;
|
|
|
import com.dk.common.response.ResponseResultVO;
|
|
|
-import com.dk.common.util.AESUtil;
|
|
|
-import com.dk.common.util.HaipHttpUtils;
|
|
|
-import com.dk.common.util.StringUtils;
|
|
|
+import com.dk.common.util.*;
|
|
|
+import com.dk.oauth.config.WechatPayConfigInfo;
|
|
|
import com.dk.oauth.convert.CompanyConvert;
|
|
|
import com.dk.oauth.entity.*;
|
|
|
import com.dk.oauth.feign.service.OrgFeign;
|
|
|
@@ -37,8 +36,16 @@ import com.dk.oauth.model.response.integral.IntegralTacticResponse;
|
|
|
import com.dk.oauth.query.*;
|
|
|
import com.dk.oauth.response.*;
|
|
|
import com.dk.oauth.service.ICompanyService;
|
|
|
+import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
|
|
|
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
+import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
|
|
|
+import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
|
+import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
+import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
+import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
@@ -51,6 +58,7 @@ import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* 公司实现类
|
|
|
@@ -100,6 +108,9 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> impl
|
|
|
@Autowired
|
|
|
private CouponUseMapper couponUseMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WechatPayConfigInfo wechatPayConfigInfo;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @desc : 通过ID查询
|
|
|
@@ -229,6 +240,118 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> impl
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @desc : web注册商户
|
|
|
+ * @author : 常皓宁
|
|
|
+ * @date : 2024/8/8 10:14
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public ResponseResultVO webRegisterCompany(CompanyVO companyVO) {
|
|
|
+ //校验当前手机号是否注册过
|
|
|
+ UserLogin userLogin = userMapper.getByPhone(companyVO.getCpPhone());
|
|
|
+ //没有微信用户 需要新建微信用户
|
|
|
+ if (userLogin == null) {
|
|
|
+ UserLogin wxUser = new UserLogin();
|
|
|
+ wxUser.setUserName(companyVO.getCpManager());
|
|
|
+ wxUser.setUserPhone(companyVO.getCpPhone());
|
|
|
+ wxUser.setUserPwd(Md5Utils.hash(Constant.StringConstant.LOGIN_INIT_PWD.getName()));
|
|
|
+ userMapper.insert(wxUser);
|
|
|
+ companyVO.setOwner(wxUser.getUserId());
|
|
|
+ companyVO.setWxUserId(wxUser.getUserId());
|
|
|
+ //注册商户
|
|
|
+ this.registerCompany(companyVO);
|
|
|
+ }
|
|
|
+ //有微信用户需要查看company是否存在持有人
|
|
|
+ else {
|
|
|
+ List<Company> owner = companyMapper.selectByCond(new Company().setOwner(userLogin.getUserId()));
|
|
|
+ //说明company存在当前持有人 则需要查看是否支付
|
|
|
+ if (owner != null && owner.size() > 0) {
|
|
|
+ //临时license为null非临时不为null则说明已经支付
|
|
|
+ if (owner.get(0).getLicenseSocial() == null && owner.get(0).getLicense() != null) {
|
|
|
+ return ResponseResultUtil.error(ErrorCodeEnum.PHONE_REGISTER_COMPANY.getCode(),
|
|
|
+ ErrorCodeEnum.PHONE_REGISTER_COMPANY.getMessage());
|
|
|
+ }
|
|
|
+ //未支付则找到对应的交易记录进行支付操作
|
|
|
+ else {
|
|
|
+ // 获取交易记录并返回前台进行支付操作
|
|
|
+ List<TradeResponse> tradeResponses = tradeMapper.selectTrade(new Trade().setCpId(owner.get(0).getCpId()));
|
|
|
+ if (tradeResponses != null && tradeResponses.size() > 0) {
|
|
|
+ companyVO.setTradeNo(tradeResponses.get(0).getTradeNo());
|
|
|
+ companyVO.setTradeAmount(tradeResponses.get(0).getTradeAmount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //company没有对应的持有人数据 则直接新建
|
|
|
+ else {
|
|
|
+ companyVO.setOwner(userLogin.getUserId());
|
|
|
+ companyVO.setWxUserId(userLogin.getUserId());
|
|
|
+ this.registerCompany(companyVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return this.getQRCode(companyVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 获取支付二维码
|
|
|
+ * @author : 常皓宁
|
|
|
+ * @date : 2024/8/8 16:03
|
|
|
+ */
|
|
|
+ public ResponseResultVO getQRCode(CompanyVO companyVO) {
|
|
|
+ try {
|
|
|
+ //todo 支付金额用时需放开
|
|
|
+ //BigDecimal payFee = companyVO.getTradeAmount();
|
|
|
+ String payFee = "0.01";
|
|
|
+ //获取微信二维码
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
+ //商品描述
|
|
|
+ orderRequest.setBody("东科智云-注册商户");
|
|
|
+ //单号
|
|
|
+ orderRequest.setOutTradeNo(companyVO.getTradeNo());
|
|
|
+ //金额
|
|
|
+ orderRequest.setTotalFee(BaseWxPayRequest.yuanToFen(payFee.toString()));//元转成分
|
|
|
+ orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
+ orderRequest.setNotifyUrl(wechatPayConfigInfo.getWechatNotifyUrl() + "/" + wechatPayConfigInfo.getAppId());
|
|
|
+ //交易类型
|
|
|
+ orderRequest.setTradeType("NATIVE");
|
|
|
+ //商品ID 二维码支付时必填(不到什么东西 随机给)
|
|
|
+ orderRequest.setProductId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ WxPayService wxPayService = this.getWxPayService();
|
|
|
+ WxPayUnifiedOrderResult result = null;
|
|
|
+ result = wxPayService.unifiedOrder(orderRequest);
|
|
|
+ if ("SUCCESS".equals(result.getReturnCode())) {//与支付成功
|
|
|
+ return ResponseResultUtil.success(result);
|
|
|
+ } else {
|
|
|
+ return ResponseResultUtil.error(result.getReturnMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseResultUtil.error("生成收款码失败.请稍后重试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public WxPayService getWxPayService() {
|
|
|
+ log.info("getWxPayService----------" + wechatPayConfigInfo.toString());
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
+ payConfig.setAppId(StringUtils.trimToNull(wechatPayConfigInfo.getAppId()));
|
|
|
+ payConfig.setMchId(StringUtils.trimToNull(wechatPayConfigInfo.getMchId()));
|
|
|
+ payConfig.setMchKey(StringUtils.trimToNull(wechatPayConfigInfo.getMchKey()));
|
|
|
+// payConfig.setSubAppId(null);
|
|
|
+// payConfig.setSubMchId(null);
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("apiclient_cert.p12");
|
|
|
+ payConfig.setKeyPath(StringUtils.trimToNull(classPathResource.getPath()));
|
|
|
+ log.info("getWxPayService=>" + classPathResource.toString());
|
|
|
+// payConfig.setKeyPath(StringUtils.trimToNull(wechatPayConfigInfo.getKeyPath()));
|
|
|
+ // 可以指定是否使用沙箱环境
|
|
|
+ payConfig.setUseSandboxEnv(false);
|
|
|
+ WxPayService wxPayService = new WxPayServiceImpl();
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
+ return wxPayService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* @desc : 注册-商户
|
|
|
* @author : 姜永辉
|
|
|
* @date : 2024-02-20 13:55
|
|
|
@@ -619,6 +742,13 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> impl
|
|
|
|
|
|
// 使用员工 // 积分的使用
|
|
|
if (companyVO.getIntegral() != null && companyVO.getIntegral() > 0) {
|
|
|
+ // 公司积分--查询
|
|
|
+ IntegralResponse integralResponse = integralMapper.selectById(companyVO.getCpId());
|
|
|
+ if (integralResponse!=null && integralResponse.getIntegral() < companyVO.getIntegral()){
|
|
|
+ // 积分不足,不允许进行该操作!
|
|
|
+ throw new BaseBusinessException(ErrorCodeEnum.INTEGRAL_MAX.getCode(),
|
|
|
+ ErrorCodeEnum.INTEGRAL_MAX.getMessage());
|
|
|
+ }
|
|
|
// 积分明细
|
|
|
IntegralItem integralItem = new IntegralItem();
|
|
|
integralItem.setIntegralType(Constant.IntegralType.INTEGRAL_TYPE_USE.getName());
|
|
|
@@ -701,6 +831,14 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> impl
|
|
|
|
|
|
// 使用员工 // 积分的使用
|
|
|
if (companyVO.getIntegral() != null && companyVO.getIntegral() > 0) {
|
|
|
+ // 公司积分--查询
|
|
|
+ IntegralResponse integralResponse = integralMapper.selectById(companyVO.getCpId());
|
|
|
+ if (integralResponse!=null && integralResponse.getIntegral() < companyVO.getIntegral()){
|
|
|
+ // 积分不足,不允许进行该操作!
|
|
|
+ throw new BaseBusinessException(ErrorCodeEnum.INTEGRAL_MAX.getCode(),
|
|
|
+ ErrorCodeEnum.INTEGRAL_MAX.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
// 积分明细
|
|
|
IntegralItem integralItem = new IntegralItem();
|
|
|
integralItem.setIntegralType(Constant.IntegralType.INTEGRAL_TYPE_USE.getName());
|