|
|
@@ -10,6 +10,8 @@ import com.github.microservice.models.hxz.ConsumTransactionsResult;
|
|
|
import com.github.microservice.models.hxz.QRCodeTransactionModel;
|
|
|
import com.github.microservice.models.hxz.WxPayResult;
|
|
|
import com.github.microservice.models.type.OrderFromType;
|
|
|
+import com.github.microservice.pay.client.model.ledger.TransactionLogModel;
|
|
|
+import com.github.microservice.pay.client.ret.ResultState;
|
|
|
import com.github.microservice.types.payment.PaymentDeviceType;
|
|
|
import com.github.microservice.types.payment.PaymentType;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
@@ -28,6 +30,8 @@ import com.zhongshu.card.client.service.payment.ExpenseFlowService;
|
|
|
import com.zhongshu.card.client.type.*;
|
|
|
import com.zhongshu.card.client.type.school.CardState;
|
|
|
import com.zhongshu.card.client.utils.DateUtils;
|
|
|
+import com.zhongshu.card.server.core.dao.devices.DevicePermissDao;
|
|
|
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
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.projectAbout.ProjectPaySettingDao;
|
|
|
@@ -35,6 +39,7 @@ import com.zhongshu.card.server.core.dao.school.CardInfoDao;
|
|
|
import com.zhongshu.card.server.core.dao.devices.DeviceBindDao;
|
|
|
import com.zhongshu.card.server.core.dao.devices.DeviceInfoDao;
|
|
|
import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
|
|
|
+import com.zhongshu.card.server.core.domain.devices.DevicePermiss;
|
|
|
import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
import com.zhongshu.card.server.core.domain.org.OrganizationRelation;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
@@ -45,6 +50,8 @@ import com.zhongshu.card.server.core.domain.devices.DeviceBind;
|
|
|
import com.zhongshu.card.server.core.httpRequest.ApiRequestService;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.service.org.OrganizationServiceImpl;
|
|
|
+import com.zhongshu.card.server.core.service.pay.BalancePayService;
|
|
|
+import com.zhongshu.card.server.core.service.paySetting.ProjectPaySettingServiceImpl;
|
|
|
import com.zhongshu.card.server.core.service.user.OperationLogsService;
|
|
|
import com.zhongshu.card.server.core.util.*;
|
|
|
import com.zhongshu.payment.client.model.param.AmountUpdateParam;
|
|
|
@@ -109,6 +116,18 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
@Autowired
|
|
|
ProjectPaySettingDao projectPaySettingDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OrganizationDao organizationDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProjectPaySettingServiceImpl projectPaySettingService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DevicePermissDao devicePermissDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BalancePayService balancePayService;
|
|
|
+
|
|
|
/**
|
|
|
* 创建流水
|
|
|
*
|
|
|
@@ -145,8 +164,11 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
expenseFlow.setDeviceId(deviceId);
|
|
|
// 支付来源 刷卡 二维码 刷脸
|
|
|
expenseFlow.setOrderFromType(iotParam.getOrderFromType());
|
|
|
+ // 传过来的参数
|
|
|
expenseFlow.setParam(iotParam);
|
|
|
+ // 支付来源设备产品类型
|
|
|
expenseFlow.setPaymentDeviceType(PaymentDeviceType.HxzConsumTransactions);
|
|
|
+
|
|
|
expenseFlow.setOrderType(OrderState.WAIT_PAYMENT);
|
|
|
|
|
|
// 验证参数、填充数据
|
|
|
@@ -173,28 +195,22 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
if (entity.getMode() != null) {
|
|
|
if (entity.getMode() == 0) {
|
|
|
entity.setOrderModeType(OrderModeType.Consume);
|
|
|
- // 消费模式
|
|
|
- PaymentType paymentType = entity.getPaymentType();
|
|
|
- // 调用支付中心
|
|
|
- CreateOrderParam param = new CreateOrderParam();
|
|
|
- param.setProjectOid(entity.getProjectOid());
|
|
|
- param.setUserId(entity.getUserId());
|
|
|
- param.setShopId(entity.getShopOid());
|
|
|
- param.setSchoolId(entity.getSchoolOid());
|
|
|
- param.setTotal(entity.getPayAmount());
|
|
|
- param.setOutTradeNo(entity.getPaymentNo());
|
|
|
- param.setPaymentType(paymentType);
|
|
|
- String desc = "消费";
|
|
|
- param.setDescription(desc);
|
|
|
|
|
|
+ String desc = "消费";
|
|
|
OperationLogsAddParam logsAddParam = initLog(entity.getUserId());
|
|
|
logsAddParam.setTitle(desc);
|
|
|
logsAddParam.setDataId(entity.getPaymentNo());
|
|
|
entity.setPayStartTime(System.currentTimeMillis());
|
|
|
- ResultContent content = orderPayFeignService.createAndPay(param);
|
|
|
- if (content.isSuccess()) {
|
|
|
+
|
|
|
+ com.github.microservice.pay.client.ret.ResultContent<List<TransactionLogModel>> resultContent = balancePayService.balancePay(
|
|
|
+ entity.getProjectOid(), entity.getShopOid(), entity.getUserId(),
|
|
|
+ entity.getPayAmount(), entity.getPaymentNo(), entity.getRemark()
|
|
|
+ );
|
|
|
+ if (resultContent.getState() == ResultState.Success) {
|
|
|
// 关联参数
|
|
|
String msg = "支付成功";
|
|
|
+ List<TransactionLogModel> list = resultContent.getContent();
|
|
|
+ entity.setTransactionIds(list.stream().map(it -> it.getId()).collect(Collectors.toUnmodifiableList()));
|
|
|
entity.setPaymentStatus(msg);
|
|
|
entity.setIsPaySuccess(Boolean.TRUE);
|
|
|
entity.setPayRemark(msg);
|
|
|
@@ -203,7 +219,7 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
logsAddParam.setLevel(LogsLevel.Low);
|
|
|
logsAddParam.setContent(msg);
|
|
|
} else {
|
|
|
- String msg = content.getMsg();
|
|
|
+ String msg = resultContent.getMsg();
|
|
|
if (StringUtils.isNotEmpty(msg) && msg.contains("Connection reset")) {
|
|
|
msg = "调用支付中心失败";
|
|
|
}
|
|
|
@@ -301,35 +317,20 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 查询设备绑定德 商户 学校
|
|
|
- if (StringUtils.isNotEmpty(deviceId)) {
|
|
|
- DeviceBind deviceBind = deviceBindDao.findTopByDeviceId(deviceId);
|
|
|
- if (ObjectUtils.isNotEmpty(deviceBind)) {
|
|
|
- entity.setSchoolOid(deviceBind.getSchoolInfoOid());
|
|
|
- entity.setShopOid(deviceBind.getShopInfoOid());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(entity.getSchoolOid())) {
|
|
|
- entity.setVerifyError("设备未绑定学校");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(entity.getShopOid())) {
|
|
|
- entity.setVerifyError("设备未绑定商户");
|
|
|
+ // 检查设备是否绑定机构
|
|
|
+ if (StringUtils.isEmpty(deviceInfo.getBeLongOid())) {
|
|
|
+ entity.setVerifyError(String.format("设备未绑定机构"));
|
|
|
return;
|
|
|
}
|
|
|
+ entity.setShopOid(deviceInfo.getBeLongOid());
|
|
|
|
|
|
- // 查询学校绑定的项目信息
|
|
|
- OrganizationRelation relation = organizationService.getSchoolRelationProject(entity.getSchoolOid());
|
|
|
- if (ObjectUtils.isNotEmpty(relation)) {
|
|
|
- Organization projectOrg = relation.getRelOrganization();
|
|
|
- if (ObjectUtils.isNotEmpty(projectOrg)) {
|
|
|
- entity.setProjectCode(projectOrg.getCode());
|
|
|
- entity.setProjectOid(projectOrg.getOid());
|
|
|
- }
|
|
|
+ // 填充项目信息
|
|
|
+ String projectOid = deviceInfo.getProjectOid();
|
|
|
+ Organization projectInfo = organizationDao.findTopByOid(projectOid);
|
|
|
+ if (ObjectUtils.isNotEmpty(projectInfo)) {
|
|
|
+ entity.setProjectCode(projectInfo.getCode());
|
|
|
+ entity.setProjectOid(projectInfo.getOid());
|
|
|
}
|
|
|
-
|
|
|
// 验证项目信息
|
|
|
if (StringUtils.isEmpty(entity.getProjectCode())) {
|
|
|
entity.setVerifyError("未绑定项目信息");
|
|
|
@@ -337,13 +338,13 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
}
|
|
|
|
|
|
// 确定项目的付款方式
|
|
|
- ProjectPaySetting projectPaySetting = projectPaySettingDao.findTopByProjectOid(entity.getProjectOid());
|
|
|
- if (ObjectUtils.isEmpty(projectPaySetting) || projectPaySetting.getChannelType() == null) {
|
|
|
- entity.setVerifyError("项目为配置支付渠道");
|
|
|
+ ResultContent<PaymentType> resultContent = projectPaySettingService.getProjectPayment(entity.getProjectOid());
|
|
|
+ if (resultContent.isFailed()) {
|
|
|
+ entity.setVerifyError(resultContent.getMsg());
|
|
|
return;
|
|
|
}
|
|
|
// 支付方式来自项目配置
|
|
|
- PaymentType paymentType = projectPaySetting.getChannelType();
|
|
|
+ PaymentType paymentType = resultContent.getContent();
|
|
|
entity.setPaymentType(paymentType);
|
|
|
entity.setPaymentWay(paymentType.getRemark());
|
|
|
|
|
|
@@ -396,6 +397,19 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // 判断设备和用户是否绑定
|
|
|
+ DevicePermiss devicePermiss = devicePermissDao.findTopByUserIdAndDeviceIdAndProjectOid(
|
|
|
+ entity.getUserId(), entity.getDeviceId(), entity.getProjectOid());
|
|
|
+ if (ObjectUtils.isEmpty(devicePermiss)) {
|
|
|
+ entity.setVerifyError("用户没有使用设备权限");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (devicePermiss.getDataState() == null ||
|
|
|
+ devicePermiss.getDataState() != DataState.Enable) {
|
|
|
+ entity.setVerifyError("用户设备权限未启用");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// 消费设备信息
|
|
|
if (deviceInfo.getDeviceType() != null) {
|
|
|
entity.setPayType(deviceInfo.getDeviceType().getRemark());
|