|
|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询分页数据
|
|
|
*
|