|
|
@@ -4,6 +4,7 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
import com.github.microservice.models.hxz.*;
|
|
|
import com.github.microservice.models.type.PaymentDeviceType;
|
|
|
+import com.github.microservice.models.type.PaymentType;
|
|
|
import com.zhongshu.card.client.model.payment.ExpenseFlowCount;
|
|
|
import com.zhongshu.card.client.model.payment.ExpenseFlowModel;
|
|
|
import com.zhongshu.card.client.model.payment.ExpenseFlowSearch;
|
|
|
@@ -19,6 +20,7 @@ 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.DeviceBindDao;
|
|
|
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;
|
|
|
@@ -26,15 +28,14 @@ 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.CardInfo;
|
|
|
import com.zhongshu.card.server.core.domain.org.DeviceInfo;
|
|
|
+import com.zhongshu.card.server.core.domain.school.DeviceBind;
|
|
|
import com.zhongshu.card.server.core.httpRequest.ApiRequestService;
|
|
|
import com.zhongshu.card.server.core.httpRequest.apiConf.APIResponseModel;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
-import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
-import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
-import com.zhongshu.card.server.core.util.DateUtils;
|
|
|
-import com.zhongshu.card.server.core.util.NextNoUtil;
|
|
|
+import com.zhongshu.card.server.core.util.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
@@ -70,9 +71,13 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
|
|
|
@Autowired
|
|
|
CardInfoDao cardInfoDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ApiRequestService apiRequestService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ DeviceBindDao deviceBindDao;
|
|
|
+
|
|
|
/**
|
|
|
* 创建订单
|
|
|
*
|
|
|
@@ -89,21 +94,28 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
|
|
|
// 消费订单号
|
|
|
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.setPaymentType(param.getPaymentType());
|
|
|
expenseFlow.setParam(iotParam);
|
|
|
expenseFlow.setPaymentDeviceType(PaymentDeviceType.HxzConsumTransactions);
|
|
|
- expenseFlowDao.save(expenseFlow);
|
|
|
+
|
|
|
+ // 验证参数、填充数据
|
|
|
+ commonVerifyExpenseFlow(expenseFlow);
|
|
|
+// expenseFlowDao.save(expenseFlow);
|
|
|
return ResultContent.buildSuccess(expenseFlow);
|
|
|
}
|
|
|
|
|
|
@@ -115,89 +127,10 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
*/
|
|
|
@Transactional
|
|
|
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);
|
|
|
- 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) {
|
|
|
+ if (entity.getVerifyParamIsSuccess() == null || !entity.getVerifyParamIsSuccess()) {
|
|
|
+ // 参数失败
|
|
|
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) {
|
|
|
- entity.setIsPaySuccess(Boolean.FALSE);
|
|
|
- entity.setPayRemark(String.format("支付失败钱包%s", wallet.getDataState().getRemark()));
|
|
|
- entity.setPaymentStatus("支付失败");
|
|
|
- expenseFlowDao.save(entity);
|
|
|
- return ResultContent.buildSuccess(entity);
|
|
|
- }
|
|
|
-
|
|
|
- // 检查
|
|
|
- if (wallet.getAmount().compareTo(amount) < 0) {
|
|
|
- entity.setIsPaySuccess(Boolean.FALSE);
|
|
|
- entity.setPayRemark("余额不足");
|
|
|
+ entity.setPayRemark(entity.getVerifyParamMsg());
|
|
|
entity.setPaymentStatus("支付失败");
|
|
|
expenseFlowDao.save(entity);
|
|
|
return ResultContent.buildSuccess(entity);
|
|
|
@@ -207,8 +140,10 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
entity.setPaymentStatus("支付成功");
|
|
|
entity.setIsPaySuccess(Boolean.TRUE);
|
|
|
entity.setPayRemark("支付成功");
|
|
|
- expenseFlowDao.save(entity);
|
|
|
|
|
|
+ Wallet wallet = walletDao.findByUserId(entity.getUserId());
|
|
|
+ BigDecimal amount = entity.getPayAmount();
|
|
|
+ UserAccount userAccount = entity.getUserAccount();
|
|
|
// 扣款
|
|
|
// 消费金额
|
|
|
try {
|
|
|
@@ -223,7 +158,7 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
walletRecharge.setAmount(amount);
|
|
|
walletRecharge.setRechargeType(RechargeType.Expend);
|
|
|
walletRecharge.setAfterAmount(afterAmount);
|
|
|
- walletRecharge.setUserId(userId);
|
|
|
+ walletRecharge.setUserId(userAccount.getUserId());
|
|
|
walletRecharge.setUserAccount(userAccount);
|
|
|
walletRecharge.setWallet(wallet);
|
|
|
walletRecharge.setUserName(userAccount.getName());
|
|
|
@@ -237,6 +172,8 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ expenseFlowDao.save(entity);
|
|
|
+
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
@@ -277,6 +214,9 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
public ResultContent<ExpenseFlow> createExpenseFlowByHxz(QRCodeTransactionModel iotParam) {
|
|
|
ExpenseFlow expenseFlow = new ExpenseFlow();
|
|
|
|
|
|
+ String userId = "665fc0389083d203896d3541";
|
|
|
+ expenseFlow.setUserId(userId);
|
|
|
+
|
|
|
expenseFlow.setYear(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyy));
|
|
|
expenseFlow.setMonth(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternMM));
|
|
|
expenseFlow.setPaymentTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
|
|
|
@@ -293,69 +233,171 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
expenseFlow.setPayAmount(amount);
|
|
|
|
|
|
String deviceId = iotParam.getDeviceId();
|
|
|
- // 设备信息
|
|
|
expenseFlow.setDeviceId(deviceId);
|
|
|
- // 支付方式 钱包 二维码
|
|
|
- expenseFlow.setPaymentWay(iotParam.getPaymentType().getRemark());
|
|
|
+
|
|
|
+ // 支付方式 付款码
|
|
|
+ String QR = iotParam.getQR();
|
|
|
+ // 判断 是 微信、支付宝的付款码
|
|
|
+ PaymentType paymentType = PaymentUtil.getPaymentTypeByQr(QR);
|
|
|
+ expenseFlow.setQr(QR);
|
|
|
+ if (paymentType != null) {
|
|
|
+ expenseFlow.setPaymentWay(paymentType.getRemark());
|
|
|
+ }
|
|
|
+ expenseFlow.setPaymentType(paymentType);
|
|
|
expenseFlow.setParam(iotParam);
|
|
|
expenseFlow.setPaymentDeviceType(PaymentDeviceType.HxzConsumTransactions);
|
|
|
- expenseFlowDao.save(expenseFlow);
|
|
|
+
|
|
|
+ commonVerifyExpenseFlow(expenseFlow);
|
|
|
+
|
|
|
+// expenseFlowDao.save(expenseFlow);
|
|
|
return ResultContent.buildSuccess(expenseFlow);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 消费机 B扫C的支付
|
|
|
+ * 同意验证 支付订单的数据是否符合要求
|
|
|
*
|
|
|
* @param entity
|
|
|
- * @return
|
|
|
*/
|
|
|
- @Transactional
|
|
|
- public ResultContent<ExpenseFlow> expendPayQrCode(ExpenseFlow entity) {
|
|
|
- // 验证QR 关联的用户信息
|
|
|
- String userId = "665fc0389083d203896d3541";
|
|
|
+ private void commonVerifyExpenseFlow(ExpenseFlow entity) {
|
|
|
+ String deviceId = entity.getDeviceId();
|
|
|
+ // 查询设备绑定德 商户 学校
|
|
|
+ if (StringUtils.isNotEmpty(deviceId)) {
|
|
|
+ DeviceBind deviceBind = deviceBindDao.findTopByDeviceId(deviceId);
|
|
|
+ if (ObjectUtils.isNotEmpty(deviceBind)) {
|
|
|
+ entity.setSchoolOid(deviceBind.getSchoolInfoOid());
|
|
|
+ entity.setShopOid(deviceBind.getShopInfoOid());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- 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 (StringUtils.isNotEmpty(entity.getSchoolOid())) {
|
|
|
+ entity.setVerifyParamIsSuccess(Boolean.FALSE);
|
|
|
+ entity.setVerifyParamMsg("设备未绑定学校");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(entity.getShopOid())) {
|
|
|
+ entity.setVerifyParamIsSuccess(Boolean.FALSE);
|
|
|
+ entity.setVerifyParamMsg("设备未绑定商户");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ PaymentType paymentType = entity.getPaymentType();
|
|
|
+ // 刷卡支付
|
|
|
+ if (paymentType == PaymentType.UserWallet) {
|
|
|
+
|
|
|
+ CardInfo cardInfo = cardInfoDao.findByCode(entity.getCardNo());
|
|
|
+ if (ObjectUtils.isNotEmpty(cardInfo)) {
|
|
|
+ entity.setCardInfo(cardInfo);
|
|
|
+ entity.setUserId(cardInfo.getUserId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证卡片
|
|
|
+ if (ObjectUtils.isEmpty(cardInfo)) {
|
|
|
+ entity.setVerifyParamIsSuccess(Boolean.FALSE);
|
|
|
+ entity.setVerifyParamMsg("卡片未注册");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 判断卡片是否可用
|
|
|
+ if (cardInfo.getCardState() != CardState.Enable) {
|
|
|
+ entity.setVerifyParamIsSuccess(Boolean.FALSE);
|
|
|
+ entity.setVerifyParamMsg(String.format("卡片", cardInfo.getCardState().getRemark()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ ConsumTransactionsModel iotParam = (ConsumTransactionsModel) entity.getParam();
|
|
|
+ if (iotParam.getMode() != 0 && iotParam.getPayType() != 0) {
|
|
|
+ entity.setVerifyParamIsSuccess(Boolean.FALSE);
|
|
|
+ entity.setVerifyParamMsg("消费模式不支持");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(entity.getUserId())) {
|
|
|
+ entity.setVerifyParamIsSuccess(Boolean.FALSE);
|
|
|
+ entity.setVerifyParamMsg("订单未找到用户");
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
+ UserAccount userAccount = userCountDao.findTopByUserId(entity.getUserId());
|
|
|
+ if (ObjectUtils.isEmpty(userAccount)) {
|
|
|
+ entity.setVerifyParamIsSuccess(Boolean.FALSE);
|
|
|
+ entity.setVerifyParamMsg("用户未注册");
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (userAccount.getState() == UserState.Locked) {
|
|
|
- entity.setIsPaySuccess(Boolean.FALSE);
|
|
|
- entity.setPayRemark("账号已锁定");
|
|
|
- entity.setPaymentStatus("支付失败");
|
|
|
- expenseFlowDao.save(entity);
|
|
|
- return ResultContent.buildSuccess(entity);
|
|
|
+ entity.setVerifyParamIsSuccess(Boolean.FALSE);
|
|
|
+ entity.setVerifyParamMsg("用户已锁定");
|
|
|
+ return;
|
|
|
}
|
|
|
entity.setUserName(userAccount.getName());
|
|
|
- entity.setUserId(userId);
|
|
|
+ entity.setUserAccount(userAccount);
|
|
|
+
|
|
|
+ // 个人钱包
|
|
|
+ if (paymentType == PaymentType.UserWallet) {
|
|
|
+ // 得到钱包的金额
|
|
|
+ BigDecimal amount = entity.getPayAmount();
|
|
|
+ // 钱包信息
|
|
|
+ Wallet wallet = walletService.getUserWalletByUserId(entity.getUserId());
|
|
|
+ if (wallet.getDataState() != DataState.Enable) {
|
|
|
+ entity.setVerifyParamIsSuccess(Boolean.FALSE);
|
|
|
+ entity.setVerifyParamMsg(String.format("支付失败钱包%s", wallet.getDataState().getRemark()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- String deviceId = entity.getDeviceId();
|
|
|
- if (deviceId == null) {
|
|
|
- deviceId = "";
|
|
|
+ // 检查
|
|
|
+ if (wallet.getAmount().compareTo(amount) < 0) {
|
|
|
+ entity.setVerifyParamIsSuccess(Boolean.FALSE);
|
|
|
+ entity.setVerifyParamMsg("余额不足");
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ // 验证设备
|
|
|
DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
|
|
|
if (ObjectUtils.isEmpty(deviceInfo)) {
|
|
|
- entity.setIsPaySuccess(Boolean.FALSE);
|
|
|
- entity.setPayRemark("业务设备未注册");
|
|
|
- entity.setPaymentStatus("支付失败");
|
|
|
- expenseFlowDao.save(entity);
|
|
|
- return ResultContent.buildSuccess(entity);
|
|
|
+ entity.setVerifyParamIsSuccess(Boolean.FALSE);
|
|
|
+ entity.setVerifyParamMsg("业务设备未注册");
|
|
|
+ return;
|
|
|
}
|
|
|
-
|
|
|
// 消费设备信息
|
|
|
if (deviceInfo.getDeviceType() != null) {
|
|
|
entity.setPayType(deviceInfo.getDeviceType().getRemark());
|
|
|
} else {
|
|
|
entity.setPayType("消费");
|
|
|
}
|
|
|
+ if (entity.getPaymentType() == null) {
|
|
|
+ entity.setVerifyParamIsSuccess(Boolean.FALSE);
|
|
|
+ entity.setVerifyParamMsg("支付方式不支持");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 消费机 B扫C的支付
|
|
|
+ *
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public ResultContent<ExpenseFlow> expendPayQrCode(ExpenseFlow entity) {
|
|
|
+ if (entity.getVerifyParamIsSuccess() == null || !entity.getVerifyParamIsSuccess()) {
|
|
|
+ // 参数失败
|
|
|
+ entity.setIsPaySuccess(Boolean.FALSE);
|
|
|
+ entity.setPayRemark(entity.getVerifyParamMsg());
|
|
|
+ entity.setPaymentStatus("支付失败");
|
|
|
+ expenseFlowDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ PaymentType paymentType = entity.getPaymentType();
|
|
|
// 调用微信支付
|
|
|
QRCodeTransactionModel payParam = (QRCodeTransactionModel) entity.getParam();
|
|
|
+ // 微信支付
|
|
|
String url = "https://jupan.5xryd.com//wxapi/pay/createQrCodeOrder";
|
|
|
-
|
|
|
+ if (paymentType == PaymentType.ZfbQrCode) {
|
|
|
+ // 支付宝支付
|
|
|
+ url = "https://jupan.5xryd.com//wxapi/pay/createAliQrCodeOrder";
|
|
|
+ }
|
|
|
APIResponseModel apiResponseModel = apiRequestService.sendWxRequest(url, payParam);
|
|
|
entity.setPayResult(apiResponseModel);
|
|
|
log.info("支付结果:{}", apiResponseModel);
|