|
|
@@ -2,10 +2,7 @@ package com.zhongshu.card.server.core.service.payment;
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
-import com.github.microservice.models.hxz.ConsumTransactionsFullParam;
|
|
|
-import com.github.microservice.models.hxz.ConsumTransactionsModel;
|
|
|
-import com.github.microservice.models.hxz.ConsumTransactionsResult;
|
|
|
-import com.github.microservice.models.hxz.QRCodeTransactionModel;
|
|
|
+import com.github.microservice.models.hxz.*;
|
|
|
import com.github.microservice.models.type.PaymentDeviceType;
|
|
|
import com.zhongshu.card.client.model.payment.ExpenseFlowCount;
|
|
|
import com.zhongshu.card.client.model.payment.ExpenseFlowModel;
|
|
|
@@ -32,6 +29,8 @@ import com.zhongshu.card.server.core.domain.payment.WalletRecharge;
|
|
|
import com.zhongshu.card.server.core.domain.school.BookInfo;
|
|
|
import com.zhongshu.card.server.core.domain.school.CardInfo;
|
|
|
import com.zhongshu.card.server.core.domain.school.DeviceInfo;
|
|
|
+import com.zhongshu.card.server.core.httpRequest.ApiRequestService;
|
|
|
+import com.zhongshu.card.server.core.httpRequest.apiConf.APIResponseModel;
|
|
|
import com.zhongshu.card.server.core.model.payment.ExpendParam;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
@@ -75,6 +74,8 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
|
|
|
@Autowired
|
|
|
CardInfoDao cardInfoDao;
|
|
|
+ @Autowired
|
|
|
+ private ApiRequestService apiRequestService;
|
|
|
|
|
|
/**
|
|
|
* 创建订单
|
|
|
@@ -243,8 +244,37 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询构建支付返回结果
|
|
|
+ *
|
|
|
+ * @param orderNo
|
|
|
+ * @param cardNo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ConsumTransactionsResult buildConsumTransactionsResult(String orderNo, String cardNo) {
|
|
|
+ ConsumTransactionsResult result = new ConsumTransactionsResult();
|
|
|
+ ExpenseFlow expenseFlow = expenseFlowDao.findTopByOrderNoAndCardNoOrderByCreateTimeDesc(orderNo, cardNo);
|
|
|
+ if (ObjectUtils.isNotEmpty(expenseFlow)) {
|
|
|
+ Boolean isPaySuccess = expenseFlow.getIsPaySuccess();
|
|
|
+ if (isPaySuccess != null && isPaySuccess) {
|
|
|
+ result.setSuccess();
|
|
|
+ result.setText("支付成功");
|
|
|
+ result.setCardNo(expenseFlow.getCardNo());
|
|
|
+ result.setName(expenseFlow.getUserName());
|
|
|
+ // 金额 转为 元 单位
|
|
|
+ result.setAmount(CommonUtil.turnMoney2Show(expenseFlow.getPayAmount()));
|
|
|
+ } else {
|
|
|
+ result.setFailed(expenseFlow.getPayRemark());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result.setFailed("未查询到订单");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通过 付款码(二维码)支付接口 创建订单
|
|
|
+ *
|
|
|
* @param iotParam
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -256,18 +286,20 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
expenseFlow.setPaymentTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
|
|
|
|
|
|
// 消费订单号
|
|
|
-// expenseFlow.setOrderNo(iotParam.getOrder());
|
|
|
-// expenseFlow.setCardNo(iotParam.getCardNo());
|
|
|
+ String orderNo = NextNoUtil.getNextPaymentNo("o");
|
|
|
+ expenseFlow.setOrderNo(orderNo);
|
|
|
+ expenseFlow.setCardNo("");
|
|
|
String paymentNo = NextNoUtil.getNextPaymentNo(null);
|
|
|
// 支付订单号
|
|
|
expenseFlow.setPaymentNo(paymentNo);
|
|
|
+ // 消费金额
|
|
|
BigDecimal amount = CommonUtil.turnMoney2BigDecimal(iotParam.getAmount());
|
|
|
expenseFlow.setPayAmount(amount);
|
|
|
|
|
|
String deviceId = iotParam.getDeviceId();
|
|
|
// 设备信息
|
|
|
expenseFlow.setDeviceId(deviceId);
|
|
|
- // 支付方式
|
|
|
+ // 支付方式 钱包 二维码
|
|
|
expenseFlow.setPaymentWay(iotParam.getPaymentType().getRemark());
|
|
|
expenseFlow.setParam(iotParam);
|
|
|
expenseFlow.setPaymentDeviceType(PaymentDeviceType.HxzConsumTransactions);
|
|
|
@@ -275,21 +307,91 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
return ResultContent.buildSuccess(expenseFlow);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 消费机 B扫C的支付
|
|
|
+ *
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public ResultContent<ExpenseFlow> expendPayQrCode(ExpenseFlow entity) {
|
|
|
+ // 验证QR 关联的用户信息
|
|
|
+ String userId = "665fc0389083d203896d3541";
|
|
|
+
|
|
|
+ UserAccount userAccount = userCountDao.findTopByUserId(userId);
|
|
|
+ if (ObjectUtils.isEmpty(userAccount)) {
|
|
|
+ entity.setIsPaySuccess(Boolean.FALSE);
|
|
|
+ entity.setPayRemark("账号未注册");
|
|
|
+ entity.setPaymentStatus("支付失败");
|
|
|
+ expenseFlowDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (userAccount.getState() == UserState.Locked) {
|
|
|
+ entity.setIsPaySuccess(Boolean.FALSE);
|
|
|
+ entity.setPayRemark("账号已锁定");
|
|
|
+ entity.setPaymentStatus("支付失败");
|
|
|
+ expenseFlowDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess(entity);
|
|
|
+ }
|
|
|
+ entity.setUserName(userAccount.getName());
|
|
|
+ entity.setUserId(userId);
|
|
|
+
|
|
|
+ String deviceId = entity.getDeviceId();
|
|
|
+ if (deviceId == null) {
|
|
|
+ deviceId = "";
|
|
|
+ }
|
|
|
+ DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
|
|
|
+ if (ObjectUtils.isEmpty(deviceInfo)) {
|
|
|
+ entity.setIsPaySuccess(Boolean.FALSE);
|
|
|
+ entity.setPayRemark("业务设备未注册");
|
|
|
+ entity.setPaymentStatus("支付失败");
|
|
|
+ expenseFlowDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 消费设备信息
|
|
|
+ if (deviceInfo.getDeviceType() != null) {
|
|
|
+ entity.setPayType(deviceInfo.getDeviceType().getRemark());
|
|
|
+ } else {
|
|
|
+ entity.setPayType("消费");
|
|
|
+ }
|
|
|
+ // 调用微信支付
|
|
|
+ QRCodeTransactionModel payParam = (QRCodeTransactionModel) entity.getParam();
|
|
|
+ String url = "https://jupan.5xryd.com//wxapi/pay/createQrCodeOrder";
|
|
|
+ APIResponseModel apiResponseModel = apiRequestService.sendWxRequest(url, payParam);
|
|
|
+ log.info("支付结果:{}", apiResponseModel);
|
|
|
+ if (apiResponseModel.isSuccess()) {
|
|
|
+ // 关联参数
|
|
|
+ TransactionInquiryResult result = JSONUtil.toBean(apiResponseModel.getContent(), TransactionInquiryResult.class);
|
|
|
+ entity.setOrderNo(result.getQrorder());
|
|
|
+ entity.setPaymentStatus("支付成功");
|
|
|
+ entity.setIsPaySuccess(Boolean.TRUE);
|
|
|
+ entity.setPayRemark("支付成功");
|
|
|
+ } else {
|
|
|
+ // 关联参数
|
|
|
+ entity.setPaymentStatus("支付失败");
|
|
|
+ entity.setIsPaySuccess(Boolean.FALSE);
|
|
|
+ entity.setPayRemark(apiResponseModel.getMsg());
|
|
|
+ }
|
|
|
+ expenseFlowDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询构建支付返回结果
|
|
|
*
|
|
|
* @param orderNo
|
|
|
- * @param cardNo
|
|
|
* @return
|
|
|
*/
|
|
|
- public ConsumTransactionsResult buildConsumTransactionsResult(String orderNo, String cardNo) {
|
|
|
+ public ConsumTransactionsResult buildConsumTransactionsResult(String orderNo) {
|
|
|
ConsumTransactionsResult result = new ConsumTransactionsResult();
|
|
|
- ExpenseFlow expenseFlow = expenseFlowDao.findTopByOrderNoAndCardNoOrderByCreateTimeDesc(orderNo, cardNo);
|
|
|
+ ExpenseFlow expenseFlow = expenseFlowDao.findTopByOrderNoOrderByCreateTimeDesc(orderNo);
|
|
|
if (ObjectUtils.isNotEmpty(expenseFlow)) {
|
|
|
Boolean isPaySuccess = expenseFlow.getIsPaySuccess();
|
|
|
if (isPaySuccess != null && isPaySuccess) {
|
|
|
result.setSuccess();
|
|
|
- result.setText("支付成功");
|
|
|
+ result.setText(expenseFlow.getPayRemark());
|
|
|
result.setCardNo(expenseFlow.getCardNo());
|
|
|
result.setName(expenseFlow.getUserName());
|
|
|
// 金额 转为 元 单位
|