|
@@ -1,9 +1,11 @@
|
|
|
package com.rongwei.wechat.system.wechat.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.rongwe.wechat.system.domain.SwBillManagementUnpaidDo;
|
|
|
import com.rongwe.wechat.system.domain.SwEnterpriseConfigInfoDo;
|
|
|
+import com.rongwe.wechat.system.domain.SwPaymentInitRecordDo;
|
|
|
import com.rongwe.wechat.system.vo.CreatePaymentRecordVo;
|
|
|
import com.rongwe.wechat.system.vo.PrepayNoticeVo;
|
|
|
import com.rongwe.wechat.system.vo.WeChatPayTransactionVo;
|
|
@@ -12,6 +14,7 @@ import com.rongwei.commonservice.service.impl.RedisServiceImpl;
|
|
|
import com.rongwei.rwcommon.base.BaseDo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
+import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommonentity.commonservers.domain.TenantDo;
|
|
|
import com.rongwei.wechat.system.config.ContextHolder;
|
|
|
import com.rongwei.wechat.system.config.WeChatAboutApiPara;
|
|
@@ -19,6 +22,7 @@ import com.rongwei.wechat.system.dao.CommonBusinessDao;
|
|
|
import com.rongwei.wechat.system.service.impl.SwBillManagementUnpaidServiceImpl;
|
|
|
import com.rongwei.wechat.system.service.impl.SwBillingRecordServiceImpl;
|
|
|
import com.rongwei.wechat.system.service.impl.SwEnterpriseConfigInfoServiceImpl;
|
|
|
+import com.rongwei.wechat.system.service.impl.SwPaymentInitRecordServiceImpl;
|
|
|
import com.rongwei.wechat.system.utils.WxPayApi;
|
|
|
import com.rongwei.wechat.system.wechat.PayMentService;
|
|
|
import com.rongwei.wechat.system.wechat.PaymentRecordService;
|
|
@@ -37,9 +41,13 @@ import javax.crypto.spec.SecretKeySpec;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.rongwei.wechat.system.utils.SaveConstans.PayType.SUCCESS;
|
|
|
+import static com.rongwei.wechat.system.utils.SaveConstans.PayType.WE_CHAT;
|
|
|
+
|
|
|
/**
|
|
|
* PayMentServiceImpl class
|
|
|
*
|
|
@@ -61,14 +69,12 @@ public class PayMentServiceImpl implements PayMentService {
|
|
|
private CommonBusinessDao commonBusinessDao;
|
|
|
@Autowired
|
|
|
private SwBillingRecordServiceImpl swBillingRecordService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private SwBillManagementUnpaidServiceImpl swBillManagementUnpaidService;
|
|
|
-
|
|
|
-
|
|
|
@Autowired
|
|
|
private PaymentRecordService paymentRecordService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private SwPaymentInitRecordServiceImpl swPaymentInitRecordService;
|
|
|
static final int TAG_LENGTH_BIT = 128;
|
|
|
|
|
|
@Override
|
|
@@ -129,13 +135,13 @@ public class PayMentServiceImpl implements PayMentService {
|
|
|
String nonceStr = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
vo.setOutTradeNo(nonceStr);
|
|
|
// 商户名称+
|
|
|
- vo.setDescription(merchantname + "-水费");
|
|
|
+ vo.setDescription(merchantname + ": 户号:" + vo.getUserNumber() + "-水费");
|
|
|
PrepayWithRequestPaymentResponse prepayWithRequestPaymentResponse = wxPayApi.prepayWithRequestPayment(vo);
|
|
|
Map<String, Object> paymentReturnMap = new HashMap<>();
|
|
|
paymentReturnMap.put("paymentSign", prepayWithRequestPaymentResponse);
|
|
|
paymentReturnMap.put("orderNo", nonceStr);
|
|
|
String zdId = vo.getZdId();
|
|
|
-
|
|
|
+ createAdvancePayRecordData(WE_CHAT, zdId, vo.getUserNumber(), nonceStr, vo.toString(), paymentReturnMap.toString(), vo.getOpenId());
|
|
|
if (StringUtils.isNotBlank(zdId)) {
|
|
|
// 预缴款项对应的账单信息 更新订单号
|
|
|
List<SwBillManagementUnpaidDo> unpaidDoList = new ArrayList<>();
|
|
@@ -151,6 +157,31 @@ public class PayMentServiceImpl implements PayMentService {
|
|
|
return R.ok(paymentReturnMap);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建预下单记录
|
|
|
+ */
|
|
|
+ public void createAdvancePayRecordData(String payType, String zdId, String userNum,
|
|
|
+ String orderNo, String paraStr, String returnStr, String openId) {
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ //创建微信下单记录
|
|
|
+ SwPaymentInitRecordDo swPaymentInitRecordDo = new SwPaymentInitRecordDo();
|
|
|
+ swPaymentInitRecordDo.setId(SecurityUtil.getUUID());
|
|
|
+ swPaymentInitRecordDo.setCreatedate(new Date());
|
|
|
+ swPaymentInitRecordDo.setModifydate(new Date());
|
|
|
+ swPaymentInitRecordDo.setPaytype(payType);
|
|
|
+ swPaymentInitRecordDo.setBillid(zdId);
|
|
|
+ swPaymentInitRecordDo.setOrderpara(paraStr);
|
|
|
+ swPaymentInitRecordDo.setOrderno(orderNo);
|
|
|
+ swPaymentInitRecordDo.setPaydate(now);
|
|
|
+ swPaymentInitRecordDo.setYearnum(now.getYear());
|
|
|
+ swPaymentInitRecordDo.setMonthnnum(now.getMonthValue());
|
|
|
+ swPaymentInitRecordDo.setDaynum(now.getDayOfMonth());
|
|
|
+ swPaymentInitRecordDo.setReturendata(returnStr);
|
|
|
+ swPaymentInitRecordDo.setUsernum(userNum);
|
|
|
+ swPaymentInitRecordDo.setWechatsign(openId);
|
|
|
+ swPaymentInitRecordService.save(swPaymentInitRecordDo);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 微信支付成功回调函数
|
|
|
*
|
|
@@ -224,9 +255,20 @@ public class PayMentServiceImpl implements PayMentService {
|
|
|
CreatePaymentRecordVo createPaymentRecordVo = new CreatePaymentRecordVo();
|
|
|
createPaymentRecordVo.setOrderNo(outTradeNo);
|
|
|
createPaymentRecordVo.setPaymentAmount(amount);
|
|
|
- List<SwBillManagementUnpaidDo> list = swBillManagementUnpaidService.list(new LambdaQueryWrapper<SwBillManagementUnpaidDo>()
|
|
|
- .eq(BaseDo::getDeleted, "0").eq(SwBillManagementUnpaidDo::getMerchantpaymentnumber, outTradeNo));
|
|
|
- String zdIds = list.stream().map(SwBillManagementUnpaidDo::getId).collect(Collectors.joining(","));
|
|
|
+ SwPaymentInitRecordDo paymentInitRecordDo = swPaymentInitRecordService.getOne(new LambdaQueryWrapper<SwPaymentInitRecordDo>()
|
|
|
+ .eq(BaseDo::getDeleted, "0")
|
|
|
+ .eq(SwPaymentInitRecordDo::getOrderno, outTradeNo), false);
|
|
|
+ String zdIds = null;
|
|
|
+ if (paymentInitRecordDo != null) {
|
|
|
+ zdIds =StringUtils.isBlank(paymentInitRecordDo.getBillid()) ? null : paymentInitRecordDo.getBillid();
|
|
|
+ swPaymentInitRecordService.update(new LambdaUpdateWrapper<SwPaymentInitRecordDo>()
|
|
|
+ .eq(SwPaymentInitRecordDo::getId,paymentInitRecordDo.getId())
|
|
|
+ .set(SwPaymentInitRecordDo::getState,SUCCESS)
|
|
|
+ .set(SwPaymentInitRecordDo::getCallbackcontent,transaction.toString())
|
|
|
+ .set(BaseDo::getModifydate,new Date())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
createPaymentRecordVo.setZdId(zdIds);
|
|
|
createPaymentRecordVo.setUserNumber(userNum);
|
|
|
createPaymentRecordVo.setOpenId(transaction.getPayer().getOpenid());
|
|
@@ -235,9 +277,9 @@ public class PayMentServiceImpl implements PayMentService {
|
|
|
createPaymentRecordVo.setSuccessTime(successTime);
|
|
|
log.error("开始创建缴费记录:{}", createPaymentRecordVo);
|
|
|
paymentRecordService.createRecord(createPaymentRecordVo);
|
|
|
- }catch (Exception e) {
|
|
|
+ } catch (Exception e) {
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error.toString());
|
|
|
- }finally {
|
|
|
+ } finally {
|
|
|
ContextHolder.clear();
|
|
|
}
|
|
|
return ResponseEntity.status(HttpStatus.OK).body("");
|