|
@@ -7,8 +7,11 @@ import com.wechat.pay.java.service.payments.jsapi.model.Payer;
|
|
|
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
|
|
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
|
|
|
import com.wechat.pay.java.service.payments.model.Transaction;
|
|
import com.wechat.pay.java.service.payments.model.Transaction;
|
|
|
import com.zhongshu.card.client.model.feign.ProjectWxPayParam;
|
|
import com.zhongshu.card.client.model.feign.ProjectWxPayParam;
|
|
|
|
|
+import com.zhongshu.card.client.model.org.OrgUserDetailParam;
|
|
|
|
|
+import com.zhongshu.card.client.model.org.OrganizationUserModel;
|
|
|
import com.zhongshu.card.client.model.payment.paySetting.WxPayConfigModel;
|
|
import com.zhongshu.card.client.model.payment.paySetting.WxPayConfigModel;
|
|
|
import com.zhongshu.card.client.model.wechat.MiniAppUserInfoVo;
|
|
import com.zhongshu.card.client.model.wechat.MiniAppUserInfoVo;
|
|
|
|
|
+import com.zhongshu.card.client.service.OrganizationFeignService;
|
|
|
import com.zhongshu.card.client.service.ProjectPaySettingFeignService;
|
|
import com.zhongshu.card.client.service.ProjectPaySettingFeignService;
|
|
|
import com.zhongshu.payment.client.model.PrePayModel;
|
|
import com.zhongshu.payment.client.model.PrePayModel;
|
|
|
import com.zhongshu.payment.client.model.RechargeRecordModel;
|
|
import com.zhongshu.payment.client.model.RechargeRecordModel;
|
|
@@ -16,23 +19,24 @@ import com.zhongshu.payment.client.model.param.OrderParam;
|
|
|
import com.zhongshu.payment.client.model.param.RechargeParam;
|
|
import com.zhongshu.payment.client.model.param.RechargeParam;
|
|
|
import com.zhongshu.payment.client.ret.ResultContent;
|
|
import com.zhongshu.payment.client.ret.ResultContent;
|
|
|
import com.zhongshu.payment.client.types.RechargeState;
|
|
import com.zhongshu.payment.client.types.RechargeState;
|
|
|
|
|
+import com.zhongshu.payment.client.types.TradeType;
|
|
|
import com.zhongshu.payment.server.core.dao.RechargeRecordDao;
|
|
import com.zhongshu.payment.server.core.dao.RechargeRecordDao;
|
|
|
import com.zhongshu.payment.server.core.dao.WalletDao;
|
|
import com.zhongshu.payment.server.core.dao.WalletDao;
|
|
|
import com.zhongshu.payment.server.core.dao.WxPayConfigDao;
|
|
import com.zhongshu.payment.server.core.dao.WxPayConfigDao;
|
|
|
import com.zhongshu.payment.server.core.dataConfig.WxV3PayConfig;
|
|
import com.zhongshu.payment.server.core.dataConfig.WxV3PayConfig;
|
|
|
import com.zhongshu.payment.server.core.domain.wallet.RechargeRecord;
|
|
import com.zhongshu.payment.server.core.domain.wallet.RechargeRecord;
|
|
|
import com.zhongshu.payment.server.core.domain.wallet.Wallet;
|
|
import com.zhongshu.payment.server.core.domain.wallet.Wallet;
|
|
|
-import com.zhongshu.payment.server.core.domain.wechatPay.WxPayConfig;
|
|
|
|
|
import com.zhongshu.payment.server.core.service.impl.WalletFeignServiceImpl;
|
|
import com.zhongshu.payment.server.core.service.impl.WalletFeignServiceImpl;
|
|
|
import com.zhongshu.payment.server.core.service.wxPaymentV3.WxPaymentService;
|
|
import com.zhongshu.payment.server.core.service.wxPaymentV3.WxPaymentService;
|
|
|
-import com.zhongshu.payment.server.core.utils.BeanUtils;
|
|
|
|
|
import com.zhongshu.payment.server.core.utils.CommonUtil;
|
|
import com.zhongshu.payment.server.core.utils.CommonUtil;
|
|
|
import com.zhongshu.payment.server.core.utils.DateUtils;
|
|
import com.zhongshu.payment.server.core.utils.DateUtils;
|
|
|
import com.zhongshu.payment.server.core.utils.wx.WechatCUtil;
|
|
import com.zhongshu.payment.server.core.utils.wx.WechatCUtil;
|
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -70,8 +74,12 @@ public class RechargeService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
ProjectPaySettingFeignService paySettingFeignService;
|
|
ProjectPaySettingFeignService paySettingFeignService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ OrganizationFeignService organizationFeignService;
|
|
|
|
|
+
|
|
|
/** 创建充值订单 */
|
|
/** 创建充值订单 */
|
|
|
public Object create(RechargeParam param){
|
|
public Object create(RechargeParam param){
|
|
|
|
|
+ String userId = authHelper.getCurrentUser().getUserId();
|
|
|
Wallet userWallet = walletDao.findTop1ById(param.getWalletId());
|
|
Wallet userWallet = walletDao.findTop1ById(param.getWalletId());
|
|
|
//判断钱包是否初始化
|
|
//判断钱包是否初始化
|
|
|
if (userWallet==null){
|
|
if (userWallet==null){
|
|
@@ -79,11 +87,22 @@ public class RechargeService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
RechargeRecord rechargeRecord = new RechargeRecord();
|
|
RechargeRecord rechargeRecord = new RechargeRecord();
|
|
|
- BeanUtils.copyPropertiesWithoutNull(param, rechargeRecord);
|
|
|
|
|
|
|
+ org.springframework.beans.BeanUtils.copyProperties(param, rechargeRecord, "total");
|
|
|
String outTradeNo = CommonUtil.UUID();
|
|
String outTradeNo = CommonUtil.UUID();
|
|
|
rechargeRecord.setOutTradeNo(outTradeNo);
|
|
rechargeRecord.setOutTradeNo(outTradeNo);
|
|
|
rechargeRecord.setTotal(BigDecimal.valueOf(param.getTotal()));
|
|
rechargeRecord.setTotal(BigDecimal.valueOf(param.getTotal()));
|
|
|
|
|
+ rechargeRecord.setOid(userWallet.getOid());
|
|
|
|
|
+ rechargeRecord.setTradeType(TradeType.Charge);
|
|
|
|
|
+ rechargeRecord.setUserId(userId);
|
|
|
|
|
|
|
|
|
|
+ OrgUserDetailParam orgUserDetailParam = new OrgUserDetailParam();
|
|
|
|
|
+ orgUserDetailParam.setOid(userWallet.getOid());
|
|
|
|
|
+ orgUserDetailParam.setUserId(userWallet.getUserId());
|
|
|
|
|
+ com.zhongshu.card.client.ret.ResultContent<OrganizationUserModel> orgUserDetail = organizationFeignService.getOrgUserDetail(orgUserDetailParam);
|
|
|
|
|
+ if (orgUserDetail.isFailed()){
|
|
|
|
|
+ return ResultContent.buildFail("获取用户信息失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ rechargeRecord.setUserInfo(orgUserDetail.getContent());
|
|
|
rechargeRecord.setRechargeState(RechargeState.NOTPAY);
|
|
rechargeRecord.setRechargeState(RechargeState.NOTPAY);
|
|
|
rechargeRecord.setWallet(userWallet);
|
|
rechargeRecord.setWallet(userWallet);
|
|
|
RechargeRecord record = rechargeRecordDao.save(rechargeRecord);
|
|
RechargeRecord record = rechargeRecordDao.save(rechargeRecord);
|
|
@@ -94,13 +113,16 @@ public class RechargeService {
|
|
|
private RechargeRecordModel toModel(RechargeRecord record) {
|
|
private RechargeRecordModel toModel(RechargeRecord record) {
|
|
|
RechargeRecordModel model = new RechargeRecordModel();
|
|
RechargeRecordModel model = new RechargeRecordModel();
|
|
|
if (record!=null){
|
|
if (record!=null){
|
|
|
- BeanUtils.copyPropertiesWithoutNull(record, model);
|
|
|
|
|
|
|
+ BeanUtils.copyProperties(record, model, "total");
|
|
|
model.setTotal(record.getTotal().intValue());
|
|
model.setTotal(record.getTotal().intValue());
|
|
|
|
|
+ model.setPrePayModel(record.getPrePayModel());
|
|
|
|
|
+ model.setUserInfo(record.getUserInfo());
|
|
|
}
|
|
}
|
|
|
return model;
|
|
return model;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 下单 */
|
|
/** 下单 */
|
|
|
|
|
+ @Transactional
|
|
|
public Object order(OrderParam param){
|
|
public Object order(OrderParam param){
|
|
|
RechargeRecord record = rechargeRecordDao.findByOutTradeNo(param.getOutTradeNo());
|
|
RechargeRecord record = rechargeRecordDao.findByOutTradeNo(param.getOutTradeNo());
|
|
|
if (record==null){
|
|
if (record==null){
|
|
@@ -121,19 +143,17 @@ public class RechargeService {
|
|
|
walletDao.save(userWallet);
|
|
walletDao.save(userWallet);
|
|
|
|
|
|
|
|
//判断微信支付配置
|
|
//判断微信支付配置
|
|
|
- WxPayConfig config = wxPayConfigDao.findByOid(record.getOid());
|
|
|
|
|
|
|
+// WxPayConfig config = wxPayConfigDao.findByOid(record.getOid());
|
|
|
//调用微信支付--下单接口
|
|
//调用微信支付--下单接口
|
|
|
PrepayRequest request = new PrepayRequest();
|
|
PrepayRequest request = new PrepayRequest();
|
|
|
- request.setMchid(config.getMchId());
|
|
|
|
|
- request.setAppid(config.getAppid());
|
|
|
|
|
- request.setNotifyUrl(config.getNotifyUrl());
|
|
|
|
|
|
|
+// request.setMchid(config.getMchId());
|
|
|
|
|
+// request.setAppid(config.getAppid());
|
|
|
|
|
+// request.setNotifyUrl(config.getNotifyUrl());
|
|
|
Amount amount = new Amount();
|
|
Amount amount = new Amount();
|
|
|
amount.setTotal(record.getTotal().intValue());
|
|
amount.setTotal(record.getTotal().intValue());
|
|
|
request.setAmount(amount);
|
|
request.setAmount(amount);
|
|
|
request.setDescription(record.getDescription());
|
|
request.setDescription(record.getDescription());
|
|
|
- //生成商户订单号
|
|
|
|
|
- String outTradeNo = CommonUtil.UUID();
|
|
|
|
|
- request.setOutTradeNo(outTradeNo);
|
|
|
|
|
|
|
+ request.setOutTradeNo(param.getOutTradeNo());
|
|
|
//设置交易失效时间,15分钟
|
|
//设置交易失效时间,15分钟
|
|
|
request.setTimeExpire(DateUtils.paresTime(System.currentTimeMillis() + 15*60*1000, DateUtils.patternWx));
|
|
request.setTimeExpire(DateUtils.paresTime(System.currentTimeMillis() + 15*60*1000, DateUtils.patternWx));
|
|
|
Payer payer = new Payer();
|
|
Payer payer = new Payer();
|
|
@@ -141,7 +161,7 @@ public class RechargeService {
|
|
|
request.setPayer(payer);
|
|
request.setPayer(payer);
|
|
|
|
|
|
|
|
ProjectWxPayParam wxPayParam = new ProjectWxPayParam();
|
|
ProjectWxPayParam wxPayParam = new ProjectWxPayParam();
|
|
|
- wxPayParam.setAppId(WxV3PayConfig.APP_ID);
|
|
|
|
|
|
|
+ wxPayParam.setAppId(record.getAppid());
|
|
|
com.zhongshu.card.client.ret.ResultContent<WxPayConfigModel> paySetResult = paySettingFeignService.getProjectWxPayConfig(wxPayParam);
|
|
com.zhongshu.card.client.ret.ResultContent<WxPayConfigModel> paySetResult = paySettingFeignService.getProjectWxPayConfig(wxPayParam);
|
|
|
if (paySetResult.isFailed()){
|
|
if (paySetResult.isFailed()){
|
|
|
return ResultContent.buildFail("获取微信支付配置失败");
|
|
return ResultContent.buildFail("获取微信支付配置失败");
|
|
@@ -151,6 +171,7 @@ public class RechargeService {
|
|
|
return prepayResult;
|
|
return prepayResult;
|
|
|
}
|
|
}
|
|
|
record.setPrePayModel(prepayResult.getContent());
|
|
record.setPrePayModel(prepayResult.getContent());
|
|
|
|
|
+ record.setRechargeState(RechargeState.RECHARGING);
|
|
|
rechargeRecordDao.save(record);
|
|
rechargeRecordDao.save(record);
|
|
|
return prepayResult;
|
|
return prepayResult;
|
|
|
}
|
|
}
|
|
@@ -201,6 +222,11 @@ public class RechargeService {
|
|
|
if (record==null){
|
|
if (record==null){
|
|
|
return ResultContent.buildFail("充值订单:"+outTradeNo+"不存在");
|
|
return ResultContent.buildFail("充值订单:"+outTradeNo+"不存在");
|
|
|
}
|
|
}
|
|
|
|
|
+ if (record.getRechargeState().equals(RechargeState.NOTPAY)){
|
|
|
|
|
+ record.setRechargeState(RechargeState.CLOSED);
|
|
|
|
|
+ rechargeRecordDao.save(record);
|
|
|
|
|
+ return ResultContent.buildSuccess(toModel(record));
|
|
|
|
|
+ }
|
|
|
record.setRechargeState(RechargeState.CLOSED);
|
|
record.setRechargeState(RechargeState.CLOSED);
|
|
|
rechargeRecordDao.save(record);
|
|
rechargeRecordDao.save(record);
|
|
|
return wxPaymentService.closeOrder(outTradeNo, paySetResult.getContent());
|
|
return wxPaymentService.closeOrder(outTradeNo, paySetResult.getContent());
|
|
@@ -223,8 +249,8 @@ public class RechargeService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 查询充值订单详情 */
|
|
/** 查询充值订单详情 */
|
|
|
- public Object queryInfoById(String id){
|
|
|
|
|
- RechargeRecord record = rechargeRecordDao.findByOutTradeNo(id);
|
|
|
|
|
|
|
+ public Object queryInfoById(String outTradeNo){
|
|
|
|
|
+ RechargeRecord record = rechargeRecordDao.findByOutTradeNo(outTradeNo);
|
|
|
return ResultContent.buildSuccess(toModel(record));
|
|
return ResultContent.buildSuccess(toModel(record));
|
|
|
}
|
|
}
|
|
|
|
|
|