TRX hai 1 ano
pai
achega
bede1c6860

+ 7 - 4
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/payment/HxzController.java

@@ -1,10 +1,7 @@
 package com.zhongshu.card.server.core.controller.payment;
 
 
-import com.github.microservice.models.hxz.ConsumTransactionsFullParam;
-import com.github.microservice.models.hxz.ConsumTransactionsFullResult;
-import com.github.microservice.models.hxz.ServerTimeModel;
-import com.github.microservice.models.hxz.ServerTimeResult;
+import com.github.microservice.models.hxz.*;
 import com.github.microservice.models.hxz.base.BaseResultModel;
 import com.zhongshu.card.client.ret.ResultContent;
 import com.zhongshu.card.server.core.service.payment.HxzService;
@@ -43,4 +40,10 @@ public class HxzController {
         return hxzService.consumTransactions(param);
     }
 
+    @Operation(summary = "用户刷卡消费结果查询接口")
+    @PostMapping(value = "orderQuery", consumes = MediaType.APPLICATION_JSON_VALUE)
+    public ResultContent orderQuery(@RequestBody OrderQueryModel param) {
+        return hxzService.orderQuery(param);
+    }
+
 }

+ 2 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/payment/ExpenseFlowDao.java

@@ -17,4 +17,6 @@ public interface ExpenseFlowDao extends MongoDao<ExpenseFlow>, ExpenseFlowDaoExt
 
     ExpenseFlow findTopById(String id);
 
+    ExpenseFlow findTopByOrderNoAndCardNoOrderByCreateTimeDesc(String orderNo, String cardNo);
+
 }

+ 11 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/payment/ExpenseFlow.java

@@ -1,6 +1,7 @@
 package com.zhongshu.card.server.core.domain.payment;
 
 import cn.hutool.json.JSONObject;
+import com.github.microservice.models.type.PaymentDeviceType;
 import com.zhongshu.card.client.utils.type.RefundState;
 import com.zhongshu.card.server.core.domain.base.SuperMain;
 import com.zhongshu.card.server.core.domain.school.CardInfo;
@@ -32,6 +33,9 @@ public class ExpenseFlow extends SuperMain {
     @Schema(description = "用户userId")
     private String userId;
 
+    @Schema(description = "用户名称")
+    private String userName;
+
     @Schema(description = "消费机设备ID")
     private String deviceId;
 
@@ -60,7 +64,7 @@ public class ExpenseFlow extends SuperMain {
     @Schema(description = "支付订单号")
     private String paymentNo;
 
-    @Schema(description = "消费时间")
+    @Schema(description = "消费创建时间")
     private String paymentTime;
 
     @Schema(description = "支付方式")
@@ -75,6 +79,12 @@ public class ExpenseFlow extends SuperMain {
     @Indexed
     private Object param;
 
+    @Schema(description = "订单是否创建成功")
+    private Boolean isCreateSuccess = Boolean.TRUE;
+
+    @Schema(description = "编辑支付设备和方式")
+    PaymentDeviceType paymentDeviceType;
+
     //------------------支付结果 start-------------------------
 
     @Schema(description = "支付订单状态")

+ 160 - 42
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/payment/ExpenseFlowServiceImpl.java

@@ -1,6 +1,11 @@
 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.type.PaymentDeviceType;
 import com.zhongshu.card.client.model.payment.ExpenseFlowCount;
 import com.zhongshu.card.client.model.payment.ExpenseFlowModel;
 import com.zhongshu.card.client.model.payment.ExpenseFlowSearch;
@@ -11,16 +16,21 @@ import com.zhongshu.card.client.ret.ResultMessage;
 import com.zhongshu.card.client.service.payment.ExpenseFlowService;
 import com.zhongshu.card.client.utils.type.DataState;
 import com.zhongshu.card.client.utils.type.RechargeType;
+import com.zhongshu.card.client.utils.type.UserState;
+import com.zhongshu.card.client.utils.type.school.CardState;
+import com.zhongshu.card.server.core.dao.CardInfoDao;
 import com.zhongshu.card.server.core.dao.org.UserCountDao;
 import com.zhongshu.card.server.core.dao.payment.ExpenseFlowDao;
 import com.zhongshu.card.server.core.dao.payment.WalletDao;
 import com.zhongshu.card.server.core.dao.payment.WalletRechargeDao;
+import com.zhongshu.card.server.core.dao.school.DeviceInfoDao;
 import com.zhongshu.card.server.core.domain.org.UserAccount;
 import com.zhongshu.card.server.core.domain.payment.ExpenseFlow;
 import com.zhongshu.card.server.core.domain.payment.Wallet;
 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.model.payment.ExpendParam;
 import com.zhongshu.card.server.core.service.base.SuperService;
 import com.zhongshu.card.server.core.util.BeanUtils;
@@ -59,66 +69,147 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
     @Autowired
     WalletRechargeDao walletRechargeDao;
 
+    @Autowired
+    DeviceInfoDao deviceInfoDao;
+
+    @Autowired
+    CardInfoDao cardInfoDao;
+
     /**
-     * 消费付款
+     * 创建订单
      *
      * @param param
      * @return
      */
+    public ResultContent<ExpenseFlow> createExpenseFlowByHxz(ConsumTransactionsFullParam param) {
+        ExpenseFlow expenseFlow = new ExpenseFlow();
+        ConsumTransactionsModel iotParam = param.getParam();
+
+        expenseFlow.setYear(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyy));
+        expenseFlow.setMonth(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternMM));
+        expenseFlow.setPaymentTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
+
+        // 消费订单号
+        expenseFlow.setOrderNo(iotParam.getOrder());
+        expenseFlow.setCardNo(iotParam.getCardNo());
+        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(param.getPaymentType().getRemark());
+        expenseFlow.setParam(iotParam);
+        expenseFlow.setPaymentDeviceType(PaymentDeviceType.HxzConsumTransactions);
+        expenseFlowDao.save(expenseFlow);
+        return ResultContent.buildSuccess(expenseFlow);
+    }
+
+    /**
+     * 消费付款
+     *
+     * @param entity
+     * @return
+     */
     @Transactional
-    public ResultContent expendPay(ExpendParam param) {
-        CardInfo cardInfo = param.getCardInfo();
+    public ResultContent<ExpenseFlow> expendPay(ExpenseFlow entity) {
+        String deviceId = entity.getDeviceId();
+
+        // 验证卡片
+        CardInfo cardInfo = cardInfoDao.findByCode(entity.getCardNo());
+        if (ObjectUtils.isEmpty(cardInfo)) {
+            entity.setIsPaySuccess(Boolean.FALSE);
+            entity.setPayRemark("卡片未注册");
+            entity.setPaymentStatus("支付失败");
+            expenseFlowDao.save(entity);
+            return ResultContent.buildSuccess(entity);
+        }
+        entity.setCardInfo(cardInfo);
+        entity.setUserId(cardInfo.getUserId());
 
         String userId = cardInfo.getUserId();
         UserAccount userAccount = userCountDao.findTopByUserId(userId);
-        // 得到钱包的金额
-        BigDecimal amount = param.getAmount();
-        ResultContent result = walletService.checkUserWallet(cardInfo.getUserId(), amount);
-        if (result.isFailed()) {
-            return result;
+        if (ObjectUtils.isEmpty(userAccount)) {
+            entity.setIsPaySuccess(Boolean.FALSE);
+            entity.setPayRemark("持卡人为空");
+            entity.setPaymentStatus("支付失败");
+            expenseFlowDao.save(entity);
+            return ResultContent.buildSuccess(entity);
+        }
+        entity.setUserName(userAccount.getName());
+
+        if (userAccount.getState() == UserState.Locked) {
+            entity.setIsPaySuccess(Boolean.FALSE);
+            entity.setPayRemark("持卡人已锁定");
+            entity.setPaymentStatus("支付失败");
+            expenseFlowDao.save(entity);
+            return ResultContent.buildSuccess(entity);
+        }
+
+        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("消费");
+        }
+
+        // 判断卡片是否可用
+        if (cardInfo.getCardState() != CardState.Enable) {
+            entity.setIsPaySuccess(Boolean.FALSE);
+            entity.setPayRemark(String.format("卡片", cardInfo.getCardState().getRemark()));
+            entity.setPaymentStatus("支付失败");
+            expenseFlowDao.save(entity);
+            return ResultContent.buildSuccess(entity);
+        }
+
+        ConsumTransactionsModel iotParam = (ConsumTransactionsModel) entity.getParam();
+        if (iotParam.getMode() != 0 && iotParam.getPayType() != 0) {
+            entity.setIsPaySuccess(Boolean.FALSE);
+            entity.setPayRemark("消费模式不支持");
+            entity.setPaymentStatus("支付失败");
+            expenseFlowDao.save(entity);
+            return ResultContent.buildSuccess(entity);
+        }
+
+        // 得到钱包的金额
+        BigDecimal amount = entity.getPayAmount();
         // 钱包信息
         Wallet wallet = walletService.getUserWalletByUserId(userId);
         if (wallet.getDataState() != DataState.Enable) {
-            return ResultContent.buildFail(String.format("支付失败钱包", wallet.getDataState().getRemark()));
-        }
-        if (wallet.getAmount().compareTo(amount) < 0) {
-            return ResultContent.buildFail("余额不足");
+            entity.setIsPaySuccess(Boolean.FALSE);
+            entity.setPayRemark(String.format("支付失败钱包%s", wallet.getDataState().getRemark()));
+            entity.setPaymentStatus("支付失败");
+            expenseFlowDao.save(entity);
+            return ResultContent.buildSuccess(entity);
         }
 
-        // 记录流水
-        ExpenseFlow expenseFlow = new ExpenseFlow();
-        // 设备信息
-        expenseFlow.setDeviceId(param.getDeviceId());
-        // 用户信息
-        expenseFlow.setUserId(cardInfo.getUserId());
-        // 卡片信息
-        expenseFlow.setCardNo(cardInfo.getCode());
-        expenseFlow.setCardInfo(cardInfo);
-        // 消费时间
-        if (param.getDeviceInfo() != null && param.getDeviceInfo().getDeviceType() != null) {
-            expenseFlow.setPayType(param.getDeviceInfo().getDeviceType().getRemark());
-        } else {
-            expenseFlow.setPayType("消费");
+        // 检查
+        if (wallet.getAmount().compareTo(amount) < 0) {
+            entity.setIsPaySuccess(Boolean.FALSE);
+            entity.setPayRemark("余额不足");
+            entity.setPaymentStatus("支付失败");
+            expenseFlowDao.save(entity);
+            return ResultContent.buildSuccess(entity);
         }
 
-        expenseFlow.setYear(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyy));
-        expenseFlow.setMonth(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternMM));
-        expenseFlow.setPaymentTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
-        // 消费订单号
-        expenseFlow.setOrderNo(param.getOrder());
-        String paymentNo = NextNoUtil.getNextPaymentNo(null);
-        expenseFlow.setPaymentNo(paymentNo);
-        // 消费金额
-        expenseFlow.setPayAmount(amount);
-        expenseFlow.setPaymentWay(param.getPaymentType().getRemark());
         // 关联参数
-        expenseFlow.setParam(param.getIotParam());
-        expenseFlow.setPaymentStatus("支付成功");
-        expenseFlow.setIsPaySuccess(Boolean.TRUE);
-        expenseFlow.setPayRemark("支付成功");
-        expenseFlowDao.save(expenseFlow);
+        entity.setPaymentStatus("支付成功");
+        entity.setIsPaySuccess(Boolean.TRUE);
+        entity.setPayRemark("支付成功");
+        expenseFlowDao.save(entity);
 
         // 扣款
         // 消费金额
@@ -147,10 +238,37 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
         } catch (Exception e) {
             e.printStackTrace();
         }
-
         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;
+    }
+
     /**
      * 查询分页数据
      *

+ 27 - 66
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/payment/HxzService.java

@@ -10,6 +10,7 @@ import com.zhongshu.card.server.core.dao.CardInfoDao;
 import com.zhongshu.card.server.core.dao.org.UserCountDao;
 import com.zhongshu.card.server.core.dao.school.DeviceInfoDao;
 import com.zhongshu.card.server.core.domain.org.UserAccount;
+import com.zhongshu.card.server.core.domain.payment.ExpenseFlow;
 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;
@@ -82,85 +83,45 @@ public class HxzService extends SuperService {
         result.setPaymentType(param.getPaymentType());
 
         ConsumTransactionsResult resultModel = new ConsumTransactionsResult();
-        // 参数
-        ConsumTransactionsModel iotParam = param.getParam();
-
-        // 检查设备
-        String deviceId = iotParam.getDeviceId();
-        DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
-        if (ObjectUtils.isEmpty(deviceInfo)) {
-            resultModel.setFailed("业务设备未注册");
-            requestInfoService.addRequestInfo(param, resultModel);
-            result.setModel(resultModel);
-            return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
-        }
-        // 验证卡片
-        CardInfo cardInfo = cardInfoDao.findByCode(iotParam.getCardNo());
-        if (ObjectUtils.isEmpty(cardInfo)) {
-            resultModel.setFailed("卡片未注册");
-            requestInfoService.addRequestInfo(param, resultModel);
-            result.setModel(resultModel);
-            return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
-        }
-
-        if (cardInfo.getCardState() != CardState.Enable) {
-            resultModel.setFailed(String.format("卡片", cardInfo.getCardState().getRemark()));
-            requestInfoService.addRequestInfo(param, resultModel);
-            result.setModel(resultModel);
-            return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
-        }
-
-        // 验证持卡人的钱包
-        String userId = cardInfo.getUserId();
-        UserAccount userAccount = userCountDao.findTopByUserId(userId);
-        if (ObjectUtils.isEmpty(userAccount)) {
-            resultModel.setFailed("持卡人为空");
+        // 创建订单
+        ResultContent<ExpenseFlow> createResult = expenseFlowService.createExpenseFlowByHxz(param);
+        if (createResult.isFailed()) {
+            resultModel.setFailed(createResult.getMsg());
             requestInfoService.addRequestInfo(param, resultModel);
             result.setModel(resultModel);
             return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
         }
+        ExpenseFlow expenseFlow = createResult.getContent();
 
-        if (userAccount.getState() == UserState.Locked) {
-            resultModel.setFailed("持卡人已锁定");
+        // 支付
+        ResultContent<ExpenseFlow> resultContent = expenseFlowService.expendPay(expenseFlow);
+        if (resultContent.isFailed()) {
+            resultModel.setFailed(resultContent.getMsg());
             requestInfoService.addRequestInfo(param, resultModel);
             result.setModel(resultModel);
             return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
         }
+        // 构建返回结果
+        resultModel = expenseFlowService.buildConsumTransactionsResult(expenseFlow.getOrderNo(), expenseFlow.getCardNo());
+        result.setModel(resultModel);
+        requestInfoService.addRequestInfo(param, resultModel);
+        return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
+    }
 
-        if (iotParam.getMode() == 0 && iotParam.getPayType() == 0) {
-            // 手动 刷卡扣费
-            String Amount = iotParam.getAmount();
-            ExpendParam expendParam = new ExpendParam();
-            expendParam.setCardInfo(cardInfo);
-            expendParam.setOrder(iotParam.getOrder());
-            expendParam.setAmount(CommonUtil.turnMoney2BigDecimal(Amount));
-            expendParam.setIotParam(iotParam);
-            expendParam.setDeviceId(iotParam.getDeviceId());
-            expendParam.setDeviceInfo(deviceInfo);
-            expendParam.setPaymentType(param.getPaymentType());
-            ResultContent resultContent = expenseFlowService.expendPay(expendParam);
-
-            if (resultContent.isSuccess()) {
-                // 消费成功 设置返回参数
-                resultModel.setSuccess();
-                resultModel.setText("支付成功");
-                resultModel.setCardNo(iotParam.getCardNo());
-                resultModel.setAmount(iotParam.getAmount());
-            } else {
-                resultModel.setFailed(resultContent.getMsg());
-                requestInfoService.addRequestInfo(param, resultModel);
-                result.setModel(resultModel);
-                return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
-            }
-        } else {
-            resultModel.setFailed("消费模式不支持");
-            requestInfoService.addRequestInfo(param, resultModel);
-            result.setModel(resultModel);
-            return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
-        }
+    /**
+     * 用户刷卡消费结果查询接口
+     *
+     * @param param
+     * @return
+     */
+    public ResultContent orderQuery(OrderQueryModel param) {
+        ConsumTransactionsFullResult result = new ConsumTransactionsFullResult();
+        // 构建返回结果
+        ConsumTransactionsResult resultModel = expenseFlowService.buildConsumTransactionsResult(param.getOrder(), param.getCardNo());
         result.setModel(resultModel);
         requestInfoService.addRequestInfo(param, resultModel);
         return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
     }
 
+
 }

+ 10 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/util/CommonUtil.java

@@ -166,6 +166,16 @@ public class CommonUtil {
         return money;
     }
 
+    public static String turnMoney2Show(BigDecimal amount) {
+        String str = "0.00";
+        try {
+            str = amount.divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return str;
+    }
+
     /**
      * 2个Long是否相等
      *