Commit fa1f9fbe by zhiwj

Merge branch '1202' into 'developer'

1202

See merge request !55
parents ffb1a08d 16990677
...@@ -10,18 +10,20 @@ public enum BuyTypeEnum { ...@@ -10,18 +10,20 @@ public enum BuyTypeEnum {
/** /**
* 短信套餐包购买 * 短信套餐包购买
*/ */
BUY_SHORT_MESSAGE_PACKAGE(2, "短信套餐包购买"), BUY_SHORT_MESSAGE_PACKAGE(2, "短信套餐包购买", "BUY_SHORT_MESSAGE_PACKAGE"),
/** /**
* 商户余额充值 * 商户余额充值
*/ */
BALANCE_RECHARGE(1, "商户余额充值"); BALANCE_RECHARGE(1, "商户余额充值", "BALANCE_RECHARGE");
private int code; private int code;
private String message; private String message;
private String type;
private BuyTypeEnum(int code, String message) { private BuyTypeEnum(int code, String message, String type) {
this.code = code; this.code = code;
this.message = message; this.message = message;
this.type = type;
} }
public static String getMessageByCode(Integer code) { public static String getMessageByCode(Integer code) {
...@@ -36,19 +38,27 @@ public enum BuyTypeEnum { ...@@ -36,19 +38,27 @@ public enum BuyTypeEnum {
return "未知"; return "未知";
} }
public int getCode() { public static String getTypeByCode(Integer code) {
return code; if (code == null) {
return "未知";
}
for (BuyTypeEnum typeEnum : values()) {
if (code.intValue() == typeEnum.getCode()) {
return typeEnum.getType();
}
}
return "未知";
} }
public void setCode(int code) { public int getCode() {
this.code = code; return code;
} }
public String getMessage() { public String getMessage() {
return message; return message;
} }
public void setMessage(String message) { public String getType() {
this.message = message; return type;
} }
} }
...@@ -93,4 +93,23 @@ public interface Constants { ...@@ -93,4 +93,23 @@ public interface Constants {
String NATIONCODESIGN = "+86"; String NATIONCODESIGN = "+86";
String ERP = "erp"; String ERP = "erp";
/**
* 支付锁
*/
String PAY_LOCK = "enterprise:biilingcenterpay";
/**
* 余额支付锁
*/
String PAY_BALANCE_LOCK = "enterprise:biilingcenterbalancepay";
/**
* 退款锁
*/
String REFUND_LOCK = "enterprise:refund";
/**
* 支付回调
*/
String PAY_BACK_LOCK = "enterprise:biilingcentercallback";
} }
...@@ -31,6 +31,10 @@ public class ApprovalCallBackDTO implements Serializable { ...@@ -31,6 +31,10 @@ public class ApprovalCallBackDTO implements Serializable {
@NotNull(message = "审批时间不能为空, 格式为yyyyMMdd", groups = ApprovalValid.class) @NotNull(message = "审批时间不能为空, 格式为yyyyMMdd", groups = ApprovalValid.class)
private String timeEnd; private String timeEnd;
private String prepayId; private String prepayId;
/**
* 支付类型
*/
private Integer payType;
private String onlineSerialNumber; private String onlineSerialNumber;
...@@ -138,6 +142,14 @@ public class ApprovalCallBackDTO implements Serializable { ...@@ -138,6 +142,14 @@ public class ApprovalCallBackDTO implements Serializable {
this.totalFee = totalFee; this.totalFee = totalFee;
} }
public Integer getPayType() {
return payType;
}
public void setPayType(Integer payType) {
this.payType = payType;
}
@Override @Override
public String toString() { public String toString() {
return "ApprovalCallBackDTO{" + return "ApprovalCallBackDTO{" +
......
...@@ -17,7 +17,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -17,7 +17,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -51,6 +50,7 @@ public class BillingAccountServiceImpl implements BillingAccountService{ ...@@ -51,6 +50,7 @@ public class BillingAccountServiceImpl implements BillingAccountService{
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public int updateAccountAfterRechargeOrRefund(double totalFee, Integer enterpriseId) { public int updateAccountAfterRechargeOrRefund(double totalFee, Integer enterpriseId) {
RedissonClient redisClient = RedisUtil.getRedisClient(); RedissonClient redisClient = RedisUtil.getRedisClient();
...@@ -58,7 +58,8 @@ public class BillingAccountServiceImpl implements BillingAccountService{ ...@@ -58,7 +58,8 @@ public class BillingAccountServiceImpl implements BillingAccountService{
account.addAndGet(totalFee); account.addAndGet(totalFee);
TabBillingAccount tabBillingAccount = tabBillingAccountMapper.selectByEnterpriseId(enterpriseId); TabBillingAccount tabBillingAccount = tabBillingAccountMapper.selectByEnterpriseId(enterpriseId);
double newTotal = new BigDecimal(tabBillingAccount.getAccountBalance().toString()).add(new BigDecimal(totalFee + "")).doubleValue(); // double newTotal = new BigDecimal(tabBillingAccount.getAccountBalance().toString()).add(new BigDecimal(totalFee + "")).doubleValue();
double newTotal = tabBillingAccount.getAccountBalance() + totalFee;
logger.info("商户:{}, 充值/退款前余额:{}, 充值/退款金额:{}, 充值/退款后余额:{}", enterpriseId, tabBillingAccount.getAccountBalance(), totalFee, newTotal); logger.info("商户:{}, 充值/退款前余额:{}, 充值/退款金额:{}, 充值/退款后余额:{}", enterpriseId, tabBillingAccount.getAccountBalance(), totalFee, newTotal);
UserDTO user = userApiService.getUserByEnterpriseId(enterpriseId).getResult(); UserDTO user = userApiService.getUserByEnterpriseId(enterpriseId).getResult();
todoItemService.finishTodoItem(enterpriseId, user.getUserId(), Constants.PRODUCT, config.getHost() + Constants.TODO_ITEM_ACCOUNT_BALANCE_URL); todoItemService.finishTodoItem(enterpriseId, user.getUserId(), Constants.PRODUCT, config.getHost() + Constants.TODO_ITEM_ACCOUNT_BALANCE_URL);
......
...@@ -329,7 +329,7 @@ public class AuditLogApiServiceImpl implements AuditLogApiService { ...@@ -329,7 +329,7 @@ public class AuditLogApiServiceImpl implements AuditLogApiService {
if (AuditTypeEnum.HAOBAN.getCode().equals(auditLogDTO.getAuditType())) { if (AuditTypeEnum.HAOBAN.getCode().equals(auditLogDTO.getAuditType())) {
position = StringUtils.isBlank(auditLogDTO.getPosition()) ? "" : auditLogDTO.getPosition(); position = StringUtils.isBlank(auditLogDTO.getPosition()) ? "" : auditLogDTO.getPosition();
} else { } else {
UserDTO userDTO = userApiService.getUserById(auditLogDTO.getApplyUserId()).getResult(); UserDTO userDTO = userApiService.getUserInfoById(auditLogDTO.getApplyUserId()).getResult();
LoginUserTypeEnum userTypeEnum = LoginUserTypeEnum.getByCode(userDTO.getLoginType()); LoginUserTypeEnum userTypeEnum = LoginUserTypeEnum.getByCode(userDTO.getLoginType());
position = userTypeEnum != null ? userTypeEnum.getMessage() : ""; position = userTypeEnum != null ? userTypeEnum.getMessage() : "";
} }
......
...@@ -238,44 +238,21 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService { ...@@ -238,44 +238,21 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService {
@Override @Override
public ServiceResponse<Integer> deductAccount(double totalFee, Integer enterpriseId) { public ServiceResponse<Integer> deductAccount(double totalFee, Integer enterpriseId) {
if (isNotInWhiteList(enterpriseId)) { // 在白名单中
TabBillingAccount billingAccount = billingAccountService.getByEnterpriseId(enterpriseId); if (isInWhiteList(enterpriseId)) {
Double accountBalance = billingAccount.getAccountBalance();
if (accountBalance >= 0) {
int i = billingAccountService.deductAccount(totalFee, enterpriseId); int i = billingAccountService.deductAccount(totalFee, enterpriseId);
LOGGER.info("扣费是否成功:{}", i > 0);
if (i > 0) {
TabBillingAccount account = this.billingAccountService.getByEnterpriseId(enterpriseId);
if (account.getAccountBalance() < 0) {
Object cache = RedisUtil.getCache("message:" + enterpriseId);
if (cache == null) {
String content = "您的达摩账户已欠费, 为避免您的业务受到影响,请及时<a href='" + config.getHost() + "cost-center/billing-center/recharge'>充值</a>";
this.pushMessageApiService.pushMessage(enterpriseId, "系统消息", "商户欠费", content);
sendSms(enterpriseId, "GICJFZX012");
// 待办事项
sendTotoItem(enterpriseId, "您的达摩账户已欠费");
RedisUtil.setCache("message:" + enterpriseId, 1, 1L, TimeUnit.DAYS);
}
} else if (account.getAccountBalance() < ACCOUNT_NOTICE_LINE) {
Object cache = RedisUtil.getCache("insufficientAccountBalanceMessage:" + enterpriseId);
if (cache == null) {
String content = "您的达摩账户余额已不足1000元,若账户欠费将中断部分正常业务,请及时<a href='" + config.getHost() + "cost-center/billing-center/recharge'>充值</a>";
this.pushMessageApiService.pushMessage(enterpriseId, "系统消息", "商户欠费", content);
sendSms(enterpriseId, "GICJFZX001");
// 待办事项
sendTotoItem(enterpriseId, "您的达摩账户余额已不足1000元");
RedisUtil.setCache("insufficientAccountBalanceMessage:" + enterpriseId, 1, 7L, TimeUnit.DAYS);
}
}
}
return ServiceResponse.success(i); return ServiceResponse.success(i);
} else { }
// 不在白名单中
TabBillingAccount billingAccount = billingAccountService.getByEnterpriseId(enterpriseId);
Double accountBalance = billingAccount.getAccountBalance();
if (accountBalance < 0) {
return ServiceResponse.failure(ErrorCode.OPERATION_FAILED.getCode(), "余额不足"); return ServiceResponse.failure(ErrorCode.OPERATION_FAILED.getCode(), "余额不足");
} }
} else {
int i = billingAccountService.deductAccount(totalFee, enterpriseId); int i = billingAccountService.deductAccount(totalFee, enterpriseId);
LOGGER.info("扣费是否成功:{}", i > 0);
return ServiceResponse.success(i); return ServiceResponse.success(i);
}
} }
private void sendSms(Integer enterpriseId, String sceneId) { private void sendSms(Integer enterpriseId, String sceneId) {
...@@ -300,14 +277,21 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService { ...@@ -300,14 +277,21 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService {
Integer enterpriseId = enterpriseDTO.getEnterpriseId(); Integer enterpriseId = enterpriseDTO.getEnterpriseId();
if (isNotInWhiteList(enterpriseId)) { if (isNotInWhiteList(enterpriseId)) {
TabBillingAccount account = this.billingAccountService.getByEnterpriseId(enterpriseId); TabBillingAccount account = this.billingAccountService.getByEnterpriseId(enterpriseId);
if (account.getAccountBalance() < ACCOUNT_NOTICE_LINE) { if (account.getAccountBalance() < 0) {
String[] smsArr = new String[]{enterpriseDTO.getEnterpriseName(), String.valueOf(-account.getAccountBalance())}; String content = "您的达摩账户已欠费, 为避免您的业务受到影响,请及时<a href='" + config.getHost() + "cost-center/billing-center/recharge'>充值</a>";
ServiceResponse<UserDTO> userResult = userApiService.getUserByEnterpriseId(enterpriseId); this.pushMessageApiService.pushMessage(enterpriseId, "系统消息", "商户欠费", content);
UserDTO userDTO = userResult.getResult(); sendSms(enterpriseId, "GICJFZX012");
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms(account.getAccountBalance() < 0 ? "GICJFZX012" :"GICJFZX001", // 待办事项
enterpriseId, userDTO.getPhoneAreaCode(), userDTO.getPhoneNumber(), smsArr); sendTotoItem(enterpriseId, "您的达摩账户已欠费");
if (!smsSendResult.isSuccess()) { } else if (account.getAccountBalance() < ACCOUNT_NOTICE_LINE) {
LOGGER.warn(smsSendResult.getMessage()); Object cache = RedisUtil.getCache("insufficientAccountBalanceMessage:" + enterpriseId);
if (cache == null) {
String content = "您的达摩账户余额已不足1000元,若账户欠费将中断部分正常业务,请及时<a href='" + config.getHost() + "cost-center/billing-center/recharge'>充值</a>";
this.pushMessageApiService.pushMessage(enterpriseId, "系统消息", "商户欠费", content);
sendSms(enterpriseId, "GICJFZX001");
// 待办事项
sendTotoItem(enterpriseId, "您的达摩账户余额已不足1000元");
RedisUtil.setCache("insufficientAccountBalanceMessage:" + enterpriseId, 1, 7L, TimeUnit.DAYS);
} }
} }
} }
...@@ -320,6 +304,11 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService { ...@@ -320,6 +304,11 @@ public class BillingAccountApiServiceImpl implements BillingAccountApiService {
return this.enterpriseWhiteListService.getEnterpriseWhiteList(enterpriseId) == null; return this.enterpriseWhiteListService.getEnterpriseWhiteList(enterpriseId) == null;
} }
private boolean isInWhiteList(Integer enterpriseId) {
// 判断商户在不在白名单中
return this.enterpriseWhiteListService.getEnterpriseWhiteList(enterpriseId) != null;
}
private void sendTotoItem(Integer enterpriseId, String content) { private void sendTotoItem(Integer enterpriseId, String content) {
TodoItemDTO todoItemDTO = new TodoItemDTO(); TodoItemDTO todoItemDTO = new TodoItemDTO();
UserDTO userDTO = userApiService.getUserByEnterpriseId(enterpriseId).getResult(); UserDTO userDTO = userApiService.getUserByEnterpriseId(enterpriseId).getResult();
......
package com.gic.enterprise.service.outer.impl; package com.gic.enterprise.service.outer.impl;
import java.math.BigDecimal;
import java.util.Date;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse; import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil; import com.gic.commons.util.EntityUtil;
import com.gic.enterprise.constant.BillingPayResultEnum; import com.gic.enterprise.constant.BillingPayResultEnum;
import com.gic.enterprise.constant.Constants;
import com.gic.enterprise.constant.PayTypeEnum; import com.gic.enterprise.constant.PayTypeEnum;
import com.gic.enterprise.dto.*; import com.gic.enterprise.dto.*;
import com.gic.enterprise.entity.TabBillingAccount; import com.gic.enterprise.entity.TabBillingAccount;
...@@ -20,7 +12,16 @@ import com.gic.enterprise.entity.TabBillingRefund; ...@@ -20,7 +12,16 @@ import com.gic.enterprise.entity.TabBillingRefund;
import com.gic.enterprise.error.ErrorCode; import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.service.*; import com.gic.enterprise.service.*;
import com.gic.enterprise.utils.CreateRandomUtils; import com.gic.enterprise.utils.CreateRandomUtils;
import com.gic.redis.data.util.RedisUtil;
import com.gic.store.utils.valid.ValidUtil; import com.gic.store.utils.valid.ValidUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.math.BigDecimal;
import java.util.Date;
/** /**
* *
...@@ -96,6 +97,8 @@ public class BillingBalancePayApiServiceImpl implements BillingBalancePayApiServ ...@@ -96,6 +97,8 @@ public class BillingBalancePayApiServiceImpl implements BillingBalancePayApiServ
@Override @Override
public ServiceResponse<BalancePayReturnDTO> savePayAndConfirmPay(OutPayDTO outPayDTO) { public ServiceResponse<BalancePayReturnDTO> savePayAndConfirmPay(OutPayDTO outPayDTO) {
try {
RedisUtil.lock(Constants.PAY_BALANCE_LOCK + outPayDTO.getEnterpriseId(), 5L);
ServiceResponse paramResult = ValidUtil.allCheckValidate(outPayDTO, OutPayDTO.ConfirmPay.class, OutPayDTO.SavePrePay.class); ServiceResponse paramResult = ValidUtil.allCheckValidate(outPayDTO, OutPayDTO.ConfirmPay.class, OutPayDTO.SavePrePay.class);
if (!paramResult.isSuccess()) { if (!paramResult.isSuccess()) {
return paramResult; return paramResult;
...@@ -118,6 +121,12 @@ public class BillingBalancePayApiServiceImpl implements BillingBalancePayApiServ ...@@ -118,6 +121,12 @@ public class BillingBalancePayApiServiceImpl implements BillingBalancePayApiServ
} else { } else {
return ServiceResponse.failure(confirmPayResponse.getCode(), confirmPayResponse.getMessage()); return ServiceResponse.failure(confirmPayResponse.getCode(), confirmPayResponse.getMessage());
} }
} catch (Exception e) {
logger.info("余额支付回调错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.PAY_BALANCE_LOCK);
}
} }
@Override @Override
...@@ -150,11 +159,15 @@ public class BillingBalancePayApiServiceImpl implements BillingBalancePayApiServ ...@@ -150,11 +159,15 @@ public class BillingBalancePayApiServiceImpl implements BillingBalancePayApiServ
@Override @Override
public ServiceResponse<RefundReturnDTO> refund(RefundDTO refundDTO) { public ServiceResponse<RefundReturnDTO> refund(RefundDTO refundDTO) {
try {
RedisUtil.lock(Constants.REFUND_LOCK + refundDTO.getEnterpriseId(), 5L);
ServiceResponse paramResult = ValidUtil.allCheckValidate(refundDTO, RefundDTO.RefundValid.class); ServiceResponse paramResult = ValidUtil.allCheckValidate(refundDTO, RefundDTO.RefundValid.class);
if (!paramResult.isSuccess()) { if (!paramResult.isSuccess()) {
return paramResult; return paramResult;
} }
ServiceResponse<BillingPayInfoDTO> payService = this.billingPayInfoApiService.getPayInfo(refundDTO.getEnterpriseId(), refundDTO.getOrderSerialNumber(), refundDTO.getRequestCode()); ServiceResponse<BillingPayInfoDTO> payService =
this.billingPayInfoApiService.getPayInfo(refundDTO.getEnterpriseId(), refundDTO.getOrderSerialNumber(), refundDTO.getRequestCode());
if (!payService.isSuccess()) { if (!payService.isSuccess()) {
return ServiceResponse.failure(payService.getCode(), payService.getMessage()); return ServiceResponse.failure(payService.getCode(), payService.getMessage());
} }
...@@ -204,6 +217,12 @@ public class BillingBalancePayApiServiceImpl implements BillingBalancePayApiServ ...@@ -204,6 +217,12 @@ public class BillingBalancePayApiServiceImpl implements BillingBalancePayApiServ
refundReturnDTO.setRefundPaySerialNumber(serialNumber); refundReturnDTO.setRefundPaySerialNumber(serialNumber);
refundReturnDTO.setDeductionTime(date); refundReturnDTO.setDeductionTime(date);
return ServiceResponse.success(refundReturnDTO); return ServiceResponse.success(refundReturnDTO);
} catch (Exception e) {
logger.info("银行转账回调错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.REFUND_LOCK);
}
} }
@Override @Override
......
...@@ -59,7 +59,6 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService { ...@@ -59,7 +59,6 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService {
@Autowired @Autowired
public BillingPayInfoApiServiceImpl(Map<String, PayStrategy> strategyMap) { public BillingPayInfoApiServiceImpl(Map<String, PayStrategy> strategyMap) {
this.strategyMap.clear();
this.strategyMap.putAll(strategyMap); this.strategyMap.putAll(strategyMap);
} }
...@@ -126,7 +125,10 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService { ...@@ -126,7 +125,10 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService {
approvalCallBackDTO.setPrepayId(resData.getPrepay_id()); approvalCallBackDTO.setPrepayId(resData.getPrepay_id());
approvalCallBackDTO.setResultCode(StringUtils.equalsIgnoreCase(resData.getResult_code(), "SUCCESS") ? 1 : 0); approvalCallBackDTO.setResultCode(StringUtils.equalsIgnoreCase(resData.getResult_code(), "SUCCESS") ? 1 : 0);
approvalCallBackDTO.setTotalFeePaid(new BigDecimal(resData.getTotal_fee()).divide(new BigDecimal("100"), 5, RoundingMode.HALF_UP).doubleValue()); approvalCallBackDTO.setTotalFeePaid(new BigDecimal(resData.getTotal_fee()).divide(new BigDecimal("100"), 5, RoundingMode.HALF_UP).doubleValue());
approvalCallBackDTO.setTotalFee(approvalCallBackDTO.getTotalFeePaid());
approvalCallBackDTO.setOnlineSerialNumber(resData.getTransaction_id()); approvalCallBackDTO.setOnlineSerialNumber(resData.getTransaction_id());
approvalCallBackDTO.setAuditStatus(BillingAuditStatusEnum.PASS.getCode());
approvalCallBackDTO.setPayType(PayTypeEnum.WE_CHAT_PAY.getCode());
return strategyMap.get(PayTypeEnum.WE_CHAT_PAY.getCode() + "").callBack(approvalCallBackDTO); return strategyMap.get(PayTypeEnum.WE_CHAT_PAY.getCode() + "").callBack(approvalCallBackDTO);
} }
...@@ -145,6 +147,7 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService { ...@@ -145,6 +147,7 @@ public class BillingPayInfoApiServiceImpl implements BillingPayInfoApiService {
// 银行回调取计划金额 // 银行回调取计划金额
approvalCallBackDTO.setTotalFee(jsonObject.getDouble("plannedAmount")); approvalCallBackDTO.setTotalFee(jsonObject.getDouble("plannedAmount"));
approvalCallBackDTO.setTotalFeePaid(jsonObject.getDouble("accountAmount")); approvalCallBackDTO.setTotalFeePaid(jsonObject.getDouble("accountAmount"));
approvalCallBackDTO.setPayType(PayTypeEnum.OFFLINE_PAY.getCode());
ServiceResponse<Void> validParam = ValidParamsUtils.allCheckValidate(approvalCallBackDTO, ApprovalCallBackDTO.ApprovalValid.class); ServiceResponse<Void> validParam = ValidParamsUtils.allCheckValidate(approvalCallBackDTO, ApprovalCallBackDTO.ApprovalValid.class);
if (!validParam.isSuccess()) { if (!validParam.isSuccess()) {
return validParam; return validParam;
......
...@@ -147,11 +147,11 @@ public class InternationalSmsRecordApiServiceImpl implements InternationalSmsRec ...@@ -147,11 +147,11 @@ public class InternationalSmsRecordApiServiceImpl implements InternationalSmsRec
*/ */
private void setUserName(InternationalSmsRecordDTO smsRecordDTO) { private void setUserName(InternationalSmsRecordDTO smsRecordDTO) {
if (smsRecordDTO.getUserId() != null) { if (smsRecordDTO.getUserId() != null) {
ServiceResponse<UserDTO> userResp = userApiService.getUserById(smsRecordDTO.getUserId()); ServiceResponse<UserDTO> userResp = userApiService.getUserInfoById(smsRecordDTO.getUserId());
if (userResp.isSuccess()) { if (userResp.isSuccess()) {
UserDTO userDTO = userResp.getResult(); UserDTO userDTO = userResp.getResult();
if (userDTO != null) { if (userDTO != null) {
smsRecordDTO.setUserName(smsRecordDTO.getUserName()); smsRecordDTO.setUserName(userDTO.getUserName());
} }
} else { } else {
logger.info("userId:{}, UserApiService.getUserById 调用失败:{}", smsRecordDTO.getUserId(), userResp.getMessage()); logger.info("userId:{}, UserApiService.getUserById 调用失败:{}", smsRecordDTO.getUserId(), userResp.getMessage());
......
...@@ -111,10 +111,28 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService { ...@@ -111,10 +111,28 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService {
logger.info("短信验证不通过:{}", paramResult.getMessage()); logger.info("短信验证不通过:{}", paramResult.getMessage());
return paramResult; return paramResult;
} }
// 判断是扣套餐包还是扣余额
RAtomicLong smsCount = billingEnterpriseSmsPackageService.getTotalSmsInPackageByEnterpriseId(smsRecordDTO.getEnterpriseId());
smsRecordDTO.setCacheStatus(0);
smsRecordDTO.setDatabaseStatus(0);
// 缓存扣费 0套餐包 4余额
Integer fee = accountStandardService.queryUnitFee(smsRecordDTO.getEnterpriseId(), AccountStandardEnum.SMS.getCode());
int deductType = deduct(smsCount, smsRecordDTO.getEnterpriseId(), fee);
smsRecordDTO.setPayType(deductType);
smsRecordDTO.setFee((double)fee/1000);
Long smsRecordId = billingSmsRecordService.saveSmsRecord(smsRecordDTO);
smsRecordDTO.setSmsRecordId(smsRecordId);
billingSmsRecordService.updateCacheStatus(smsRecordDTO.getSmsRecordId());
smsRecordDTO.setCacheStatus(1);
// 队列
GicMQClient client = GICMQClientUtil.getClientInstance(); GicMQClient client = GICMQClientUtil.getClientInstance();
try { try {
String json = JSON.toJSONString(smsRecordDTO); client.sendMessage("smsDbMq", JSON.toJSONString(smsRecordDTO));
client.sendMessage("smsMq", json);
} catch (Exception e) { } catch (Exception e) {
logger.warn("调用mq失败", e); logger.warn("调用mq失败", e);
} }
...@@ -126,7 +144,7 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService { ...@@ -126,7 +144,7 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService {
@Override @Override
public ServiceResponse<Void> run(String arg) { public ServiceResponse<Void> run(String arg) {
// 缓存中计费 /*// 缓存中计费
GicMQClient client = GICMQClientUtil.getClientInstance(); GicMQClient client = GICMQClientUtil.getClientInstance();
try { try {
logger.info("国内短信缓存扣费:{}", arg); logger.info("国内短信缓存扣费:{}", arg);
...@@ -154,17 +172,21 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService { ...@@ -154,17 +172,21 @@ public class SmsRecordApiServiceImpl implements SmsRecordApiService {
} catch (Exception e) { } catch (Exception e) {
logger.warn("调用mq失败", e); logger.warn("调用mq失败", e);
} }
*/
return ServiceResponse.success(); return ServiceResponse.success();
} }
private int deduct(RAtomicLong rSmsCount, Integer enterpriseId, Integer fee) { private int deduct(RAtomicLong rSmsCount, Integer enterpriseId, Integer fee) {
long smsCount = rSmsCount.get(); long smsCount = rSmsCount.get();
if (smsCount > 0) { if (smsCount > 0) {
// 套餐包计费 /*
套餐包计费
这里不能改成 decrementAndGet自减, 否则会出现减到0的情况
*/
boolean smsCountDeduct = rSmsCount.compareAndSet(smsCount, smsCount - 1); boolean smsCountDeduct = rSmsCount.compareAndSet(smsCount, smsCount - 1);
// rSmsCount.decrementAndGet();
if (!smsCountDeduct) { if (!smsCountDeduct) {
// 设置失败 重新计算 // 设置失败 重新计算
// todo 这里不知道要不要加个延时之类的
return deduct(rSmsCount, enterpriseId, fee); return deduct(rSmsCount, enterpriseId, fee);
} else { } else {
return 0; return 0;
......
...@@ -36,6 +36,7 @@ public class AliPayStrategy implements PayStrategy { ...@@ -36,6 +36,7 @@ public class AliPayStrategy implements PayStrategy {
@Override @Override
public ServiceResponse<Void> callBack(ApprovalCallBackDTO resData) { public ServiceResponse<Void> callBack(ApprovalCallBackDTO resData) {
return ServiceResponse.failure(ErrorCode.UNKNOWN_ERROR.getCode(), ErrorCode.UNKNOWN_ERROR.getMsg()); return ServiceResponse.failure(ErrorCode.UNKNOWN_ERROR.getCode(), ErrorCode.UNKNOWN_ERROR.getMsg());
} }
} }
...@@ -10,18 +10,17 @@ import com.gic.commons.util.GlobalInfo; ...@@ -10,18 +10,17 @@ import com.gic.commons.util.GlobalInfo;
import com.gic.enterprise.constant.*; import com.gic.enterprise.constant.*;
import com.gic.enterprise.dto.ApprovalCallBackDTO; import com.gic.enterprise.dto.ApprovalCallBackDTO;
import com.gic.enterprise.dto.BillingPayInfoDTO; import com.gic.enterprise.dto.BillingPayInfoDTO;
import com.gic.enterprise.dto.EnterpriseDTO;
import com.gic.enterprise.dto.OutPayDTO; import com.gic.enterprise.dto.OutPayDTO;
import com.gic.enterprise.entity.TabBillingOrder;
import com.gic.enterprise.entity.TabBillingPayInfo; import com.gic.enterprise.entity.TabBillingPayInfo;
import com.gic.enterprise.entity.TabBillingRechargeRecord;
import com.gic.enterprise.entity.TabEnterprise; import com.gic.enterprise.entity.TabEnterprise;
import com.gic.enterprise.error.ErrorCode; import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.service.*; import com.gic.enterprise.service.*;
import com.gic.enterprise.service.outer.impl.payComplete.PayCompleteHandler;
import com.gic.enterprise.utils.CreateRandomUtils; import com.gic.enterprise.utils.CreateRandomUtils;
import com.gic.finance.dto.TransferAccountsApprovalDTO; import com.gic.finance.dto.TransferAccountsApprovalDTO;
import com.gic.finance.service.TransferAccountsApprovalApiService; import com.gic.finance.service.TransferAccountsApprovalApiService;
import com.gic.marketing.process.api.service.sms.SmsSendApiService; import com.gic.marketing.process.api.service.sms.SmsSendApiService;
import com.gic.redis.data.util.RedisUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -31,6 +30,8 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -31,6 +30,8 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.Date; import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* *
...@@ -58,9 +59,17 @@ public class OfflineStrategy implements PayStrategy { ...@@ -58,9 +59,17 @@ public class OfflineStrategy implements PayStrategy {
@Autowired @Autowired
private EnterpriseApiService enterpriseApiService; private EnterpriseApiService enterpriseApiService;
private Map<String, PayCompleteHandler> payCompleteHandlerMap = new ConcurrentHashMap<>();
@Autowired
public OfflineStrategy(Map<String, PayCompleteHandler> payCompleteHandlerMap) {
this.payCompleteHandlerMap.putAll(payCompleteHandlerMap);
}
@Override @Override
@Transactional(rollbackFor = Exception.class)
public ServiceResponse<BillingPayInfoDTO> savePrePayInfo(OutPayDTO outPayDTO) { public ServiceResponse<BillingPayInfoDTO> savePrePayInfo(OutPayDTO outPayDTO) {
try {
RedisUtil.lock(Constants.PAY_LOCK + outPayDTO.getEnterpriseId(), 5L);
// 判断该商户下是否有相同的订单号 // 判断该商户下是否有相同的订单号
TabBillingPayInfo payInfo = billingPayInfoService.getByOrderSerialNumber(outPayDTO.getOrderSerialNumber(), PayTypeEnum.OFFLINE_PAY.getCode()); TabBillingPayInfo payInfo = billingPayInfoService.getByOrderSerialNumber(outPayDTO.getOrderSerialNumber(), PayTypeEnum.OFFLINE_PAY.getCode());
if (payInfo != null) { if (payInfo != null) {
...@@ -88,12 +97,19 @@ public class OfflineStrategy implements PayStrategy { ...@@ -88,12 +97,19 @@ public class OfflineStrategy implements PayStrategy {
return ServiceResponse.failure(ErrorCode.OPERATION_FAILED.getCode(), "线下支付交易保存失败"); return ServiceResponse.failure(ErrorCode.OPERATION_FAILED.getCode(), "线下支付交易保存失败");
} }
return ServiceResponse.success(payInfoDTO); return ServiceResponse.success(payInfoDTO);
} catch (Exception e) {
logger.info("预支付错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.PAY_LOCK);
}
} }
@Override @Override
public ServiceResponse<BillingPayInfoDTO> confirmPay(OutPayDTO outPayDTO) { public ServiceResponse<BillingPayInfoDTO> confirmPay(OutPayDTO outPayDTO) {
try {
TabBillingPayInfo payInfo = billingPayInfoService.getByOrderSerialNumber(outPayDTO.getEnterpriseId(), outPayDTO.getRequestCode() ,outPayDTO.getOrderSerialNumber()); RedisUtil.lock(Constants.PAY_LOCK + outPayDTO.getEnterpriseId(), 5L);
TabBillingPayInfo payInfo = billingPayInfoService.getByOrderSerialNumber(outPayDTO.getEnterpriseId(), outPayDTO.getRequestCode(), outPayDTO.getOrderSerialNumber());
BillingPayInfoDTO billingPayInfoDTO = new BillingPayInfoDTO(); BillingPayInfoDTO billingPayInfoDTO = new BillingPayInfoDTO();
if (payInfo == null) { if (payInfo == null) {
...@@ -129,7 +145,12 @@ public class OfflineStrategy implements PayStrategy { ...@@ -129,7 +145,12 @@ public class OfflineStrategy implements PayStrategy {
// 发起审批 // 发起审批
initiateApproval(outPayDTO); initiateApproval(outPayDTO);
return ServiceResponse.success(billingPayInfoDTO); return ServiceResponse.success(billingPayInfoDTO);
} catch (Exception e) {
logger.info("确认支付错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.PAY_LOCK);
}
} }
@Override @Override
...@@ -141,76 +162,30 @@ public class OfflineStrategy implements PayStrategy { ...@@ -141,76 +162,30 @@ public class OfflineStrategy implements PayStrategy {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ServiceResponse<Void> callBack(ApprovalCallBackDTO resData) { public ServiceResponse<Void> callBack(ApprovalCallBackDTO resData) {
try {
RedisUtil.lock(Constants.PAY_BACK_LOCK + resData.getEnterpriseId(), 5L);
logger.info("银行线下支付回调结果:{}", JSON.toJSONString(resData)); logger.info("银行线下支付回调结果:{}", JSON.toJSONString(resData));
String orderSerialNumber = resData.getOrderSerialNumber(); String orderSerialNumber = resData.getOrderSerialNumber();
TabBillingPayInfo billingPayInfo = billingPayInfoService.getByOrderSerialNumber(orderSerialNumber, PayTypeEnum.OFFLINE_PAY.getCode()); TabBillingPayInfo billingPayInfo = billingPayInfoService.getByOrderSerialNumber(orderSerialNumber, PayTypeEnum.OFFLINE_PAY.getCode());
resData.setPaySerialNumber(billingPayInfo.getSerialNumber()); resData.setPaySerialNumber(billingPayInfo.getSerialNumber());
if (StringUtils.isBlank(billingPayInfo.getTimeEnd())) { // 防止重复推信息
// 写入支付结果 if (StringUtils.isNotBlank(billingPayInfo.getTimeEnd())) {
Integer i = billingPayInfoService.updatePayInfoBySerialNumber(resData);
switch (resData.getBuyType()) {
case 1:
// 商户余额充值
billingRechargeRecordService.updateBySerialNumber(billingPayInfo.getEnterpriseId(), resData.getOrderSerialNumber(), resData.getTotalFee(), resData.getTotalFeePaid(), resData.getAuditStatus(), resData.getTimeEnd(), null);
sendRechargeSuccessSms(resData, billingPayInfo.getEnterpriseId());
sendApprovalSms(resData, "GICJFZX007");
break;
case 2:
// 短信套餐包购买
this.billingOrderService.updateBySerialNumber(resData.getOrderSerialNumber(), resData.getTotalFeePaid(), resData.getAuditStatus(), resData.getTimeEnd());
sendOrderApprovalSms(resData, "GICJFZX008");
break;
default:
break;
}
}else {
logger.info("银行转账重复回调 orderSerialNumber:{}", resData.getOrderSerialNumber()); logger.info("银行转账重复回调 orderSerialNumber:{}", resData.getOrderSerialNumber());
}
return ServiceResponse.success(); return ServiceResponse.success();
} }
// 写入支付结果
private void sendRechargeSuccessSms(ApprovalCallBackDTO resData, Integer enterpriseId) { Integer i = billingPayInfoService.updatePayInfoBySerialNumber(resData);
UserDTO userDTO = userApiService.getUserByEnterpriseId(enterpriseId).getResult(); payCompleteHandlerMap.get(BuyTypeEnum.getTypeByCode(resData.getBuyType())).payComplete(resData, billingPayInfo);
sendSms(resData, userDTO, "GICJFZX005"); return ServiceResponse.success();
}
private void sendApprovalSms(ApprovalCallBackDTO resData, String code) {
TabBillingRechargeRecord rechargeRecord = billingRechargeRecordService.getRechargeRecordBySerialNumber(resData.getOrderSerialNumber());
Integer initiator = rechargeRecord.getInitiator();
UserDTO userDTO = userApiService.getUserById(initiator).getResult();
sendSms(resData, userDTO, code);
}
private void sendOrderApprovalSms(ApprovalCallBackDTO resData, String code) {
TabBillingOrder order = billingOrderService.getOrderBySerialNumber(resData.getOrderSerialNumber());
Integer initiator = order.getInitiatorUser();
if (initiator != null) {
UserDTO userDTO = userApiService.getUserById(initiator).getResult();
sendSms(resData, userDTO, code);
}
}
private void sendSms(ApprovalCallBackDTO resData, UserDTO userDTO, String code) {
try {
if (StringUtils.isBlank(userDTO.getPhoneAreaCode())) {
userDTO.setPhoneAreaCode("+86");
}
EnterpriseDTO enterpriseDTO = enterpriseApiService.getEnterpriseById(userDTO.getEnterpriseId()).getResult();
String[] smsArr = new String[]{enterpriseDTO.getEnterpriseName(), resData.getOrderSerialNumber(), BillingAuditStatusEnum.PASS.getCode().equals(resData.getAuditStatus()) ? "成功" : "失败"};
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms(code,
userDTO.getEnterpriseId(), userDTO.getPhoneAreaCode(), userDTO.getPhoneNumber(), smsArr);
if (!smsSendResult.isSuccess()) {
logger.warn(smsSendResult.getMessage());
}
} catch (Exception e) { } catch (Exception e) {
logger.info("发送短信失败", e); logger.info("银行转账回调错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.PAY_BACK_LOCK);
} }
} }
private void initiateApproval(OutPayDTO outPayDTO) { private void initiateApproval(OutPayDTO outPayDTO) {
TransferAccountsApprovalDTO approvalDTO = new TransferAccountsApprovalDTO(); TransferAccountsApprovalDTO approvalDTO = new TransferAccountsApprovalDTO();
approvalDTO.setOrderNumber(outPayDTO.getOrderSerialNumber()); approvalDTO.setOrderNumber(outPayDTO.getOrderSerialNumber());
......
...@@ -3,24 +3,26 @@ package com.gic.enterprise.service.outer.impl.pay; ...@@ -3,24 +3,26 @@ package com.gic.enterprise.service.outer.impl.pay;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse; import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.UserDTO; import com.gic.auth.dto.UserDTO;
import com.gic.auth.service.UserApiService;
import com.gic.commons.util.DateUtil; import com.gic.commons.util.DateUtil;
import com.gic.commons.util.EntityUtil; import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.GlobalInfo; import com.gic.commons.util.GlobalInfo;
import com.gic.enterprise.constant.BillingAuditStatusEnum; import com.gic.enterprise.constant.BuyTypeEnum;
import com.gic.enterprise.constant.Constants;
import com.gic.enterprise.constant.PayTypeEnum; import com.gic.enterprise.constant.PayTypeEnum;
import com.gic.enterprise.dto.ApprovalCallBackDTO; import com.gic.enterprise.dto.ApprovalCallBackDTO;
import com.gic.enterprise.dto.BillingPayInfoDTO; import com.gic.enterprise.dto.BillingPayInfoDTO;
import com.gic.enterprise.dto.EnterpriseDTO; import com.gic.enterprise.dto.EnterpriseDTO;
import com.gic.enterprise.dto.OutPayDTO; import com.gic.enterprise.dto.OutPayDTO;
import com.gic.enterprise.entity.TabBillingPayInfo; import com.gic.enterprise.entity.TabBillingPayInfo;
import com.gic.enterprise.entity.TabBillingRechargeRecord;
import com.gic.enterprise.error.ErrorCode; import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.service.*; import com.gic.enterprise.service.BillingPayInfoService;
import com.gic.enterprise.service.EnterpriseApiService;
import com.gic.enterprise.service.outer.impl.payComplete.PayCompleteHandler;
import com.gic.enterprise.utils.CreateRandomUtils; import com.gic.enterprise.utils.CreateRandomUtils;
import com.gic.log.api.dto.SystemSetLogDTO; import com.gic.log.api.dto.SystemSetLogDTO;
import com.gic.log.api.service.LogApiService; import com.gic.log.api.service.LogApiService;
import com.gic.marketing.process.api.service.sms.SmsSendApiService; import com.gic.marketing.process.api.service.sms.SmsSendApiService;
import com.gic.redis.data.util.RedisUtil;
import com.gic.thirdparty.api.dto.ScanPayReqDataDTO; import com.gic.thirdparty.api.dto.ScanPayReqDataDTO;
import com.gic.thirdparty.api.service.Pay4WXService; import com.gic.thirdparty.api.service.Pay4WXService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -31,6 +33,8 @@ import org.springframework.stereotype.Component; ...@@ -31,6 +33,8 @@ import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* *
...@@ -47,23 +51,23 @@ public class WxPayStrategy implements PayStrategy { ...@@ -47,23 +51,23 @@ public class WxPayStrategy implements PayStrategy {
@Autowired @Autowired
private BillingPayInfoService billingPayInfoService; private BillingPayInfoService billingPayInfoService;
@Autowired @Autowired
private BillingRechargeRecordService billingRechargeRecordService;
@Autowired
private BillingOrderService billingOrderService;
@Autowired
private PushMessageApiService pushMessageApiService;
@Autowired
private UserApiService userApiService;
@Autowired
private EnterpriseApiService enterpriseApiService; private EnterpriseApiService enterpriseApiService;
@Autowired @Autowired
SmsSendApiService smsSendApiService; SmsSendApiService smsSendApiService;
@Autowired @Autowired
private LogApiService logApiService; private LogApiService logApiService;
private Map<String, PayCompleteHandler> payCompleteHandlerMap = new ConcurrentHashMap<>();
@Autowired
public WxPayStrategy(Map<String, PayCompleteHandler> payCompleteHandlerMap) {
this.payCompleteHandlerMap.putAll(payCompleteHandlerMap);
}
@Override @Override
public ServiceResponse<BillingPayInfoDTO> savePrePayInfo(OutPayDTO outPayDTO) { public ServiceResponse<BillingPayInfoDTO> savePrePayInfo(OutPayDTO outPayDTO) {
try {
RedisUtil.lock(Constants.PAY_BACK_LOCK + outPayDTO.getEnterpriseId(), 5L);
if (StringUtils.isNotBlank(outPayDTO.getOrderSerialNumber())) { if (StringUtils.isNotBlank(outPayDTO.getOrderSerialNumber())) {
TabBillingPayInfo payInfo = billingPayInfoService.getByOrderSerialNumber(outPayDTO.getOrderSerialNumber(), outPayDTO.getPayType()); TabBillingPayInfo payInfo = billingPayInfoService.getByOrderSerialNumber(outPayDTO.getOrderSerialNumber(), outPayDTO.getPayType());
if (payInfo != null) { if (payInfo != null) {
...@@ -80,11 +84,17 @@ public class WxPayStrategy implements PayStrategy { ...@@ -80,11 +84,17 @@ public class WxPayStrategy implements PayStrategy {
} else { } else {
return ServiceResponse.failure(ErrorCode.SYSTEM_ERROR.getCode(), "调用微信支付失败"); return ServiceResponse.failure(ErrorCode.SYSTEM_ERROR.getCode(), "调用微信支付失败");
} }
} catch (Exception e) {
logger.info("预支付错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.PAY_BACK_LOCK);
}
} }
@Override @Override
public ServiceResponse<BillingPayInfoDTO> confirmPay(OutPayDTO outPayDTO) { public ServiceResponse<BillingPayInfoDTO> confirmPay(OutPayDTO outPayDTO) {
logger.info("线下转账没有该方法 confirmPay"); logger.info("微信没有该方法 confirmPay");
return ServiceResponse.success(); return ServiceResponse.success();
} }
...@@ -115,40 +125,29 @@ public class WxPayStrategy implements PayStrategy { ...@@ -115,40 +125,29 @@ public class WxPayStrategy implements PayStrategy {
@Override @Override
public ServiceResponse<Void> callBack(ApprovalCallBackDTO resData) { public ServiceResponse<Void> callBack(ApprovalCallBackDTO resData) {
try {
RedisUtil.lock(Constants.PAY_BACK_LOCK + resData.getEnterpriseId(), 5L);
logger.info("微信支付回调结果:{}", JSON.toJSONString(resData)); logger.info("微信支付回调结果:{}", JSON.toJSONString(resData));
// 写入支付结果 // 写入支付结果
TabBillingPayInfo billingPayInfo = billingPayInfoService.getBySerialNumber(resData.getPaySerialNumber()); TabBillingPayInfo billingPayInfo = billingPayInfoService.getBySerialNumber(resData.getPaySerialNumber());
if (StringUtils.isBlank(billingPayInfo.getTimeEnd())) { // 防止微信重复推信息
Integer i = billingPayInfoService.updatePayInfoBySerialNumber(resData); if (StringUtils.isNotBlank(billingPayInfo.getTimeEnd())) {
switch (billingPayInfo.getBuyType()) { logger.info("微信重复回调 paySerialNumber:{}", resData.getPaySerialNumber());
case 1: return ServiceResponse.success();
// 商户余额充值
billingRechargeRecordService.updateBySerialNumber(resData.getEnterpriseId(), billingPayInfo.getOrderSerialNumber(), resData.getTotalFeePaid(), resData.getTotalFeePaid(), BillingAuditStatusEnum.PASS.getCode(), resData.getTimeEnd(), resData.getOnlineSerialNumber());
this.pushMessageApiService.pushMessage(resData.getEnterpriseId(), "系统通知", "余额充值", "您的商户成功充值"+resData.getTotalFeePaid()+"元!感谢您的支持和使用!");
sendRechargeSuccessSms(resData, billingPayInfo.getEnterpriseId());
TabBillingRechargeRecord rechargeRecord = billingRechargeRecordService.getRechargeRecordBySerialNumber(billingPayInfo.getOrderSerialNumber());
UserDTO userDTO = userApiService.getUserById(rechargeRecord.getInitiatorUser()).getResult();
createLog("充值", "账户余额", userDTO);
break;
case 2:
// 短信套餐包购买
this.billingOrderService.updateBySerialNumber(billingPayInfo.getOrderSerialNumber(), resData.getTotalFeePaid(), BillingAuditStatusEnum.PASS.getCode(), resData.getTimeEnd());
TabBillingRechargeRecord tabBillingRechargeRecord = billingRechargeRecordService.getRechargeRecordBySerialNumber(billingPayInfo.getOrderSerialNumber());
UserDTO user = userApiService.getUserById(tabBillingRechargeRecord.getInitiatorUser()).getResult();
createLog("支付", "订单内容", user);
break;
default:
break;
} }
Integer i = billingPayInfoService.updatePayInfoBySerialNumber(resData);
resData.setOrderSerialNumber(billingPayInfo.getOrderSerialNumber());
payCompleteHandlerMap.get(BuyTypeEnum.getTypeByCode(resData.getBuyType())).payComplete(resData, billingPayInfo);
// 删除其他的支付方式 // 删除其他的支付方式
billingPayInfoService.delOtherPayInfoExceptId(billingPayInfo.getPayInfoId(), billingPayInfo.getEnterpriseId(), billingPayInfo.getOrderSerialNumber()); billingPayInfoService.delOtherPayInfoExceptId(billingPayInfo.getPayInfoId(), billingPayInfo.getEnterpriseId(), billingPayInfo.getOrderSerialNumber());
} else {
logger.info("微信重复回调 paySerialNumber:{}", resData.getPaySerialNumber());
}
return ServiceResponse.success(); return ServiceResponse.success();
} catch (Exception e) {
logger.info("微信回调错误", e);
throw new RuntimeException(e);
} finally {
RedisUtil.unlock(Constants.PAY_BACK_LOCK);
}
} }
private BillingPayInfoDTO saveWxPrePay(Integer enterpriseId, String serialNumber, Double totalFee, Integer buyType, String orderSerialNumber) { private BillingPayInfoDTO saveWxPrePay(Integer enterpriseId, String serialNumber, Double totalFee, Integer buyType, String orderSerialNumber) {
...@@ -187,33 +186,6 @@ public class WxPayStrategy implements PayStrategy { ...@@ -187,33 +186,6 @@ public class WxPayStrategy implements PayStrategy {
} }
} }
private void sendRechargeSuccessSms(ApprovalCallBackDTO resData, Integer enterpriseId) {
UserDTO userDTO = userApiService.getUserByEnterpriseId(enterpriseId).getResult();
sendSms(resData, userDTO, "GICJFZX005");
}
private void sendSms(ApprovalCallBackDTO resData, UserDTO userDTO, String code) {
try {
if (StringUtils.isBlank(userDTO.getPhoneAreaCode())) {
userDTO.setPhoneAreaCode("+86");
}
EnterpriseDTO enterpriseDTO = enterpriseApiService.getEnterpriseById(userDTO.getEnterpriseId()).getResult();
String[] smsArr = new String[]{enterpriseDTO.getEnterpriseName(), resData.getOrderSerialNumber(), BillingAuditStatusEnum.PASS.getCode().equals(resData.getAuditStatus()) ? "成功" : "失败"};
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms(code,
userDTO.getEnterpriseId(), userDTO.getPhoneAreaCode(), userDTO.getPhoneNumber(), smsArr);
if (!smsSendResult.isSuccess()) {
logger.warn(smsSendResult.getMessage());
}
} catch (Exception e) {
logger.info("发送短信失败", e);
}
}
public void createLog(String content, String operationObject, UserDTO userDTO) {
doLog(content, operationObject, userDTO);
}
private void doLog(String content, String operationObject, UserDTO userDTO) { private void doLog(String content, String operationObject, UserDTO userDTO) {
final SystemSetLogDTO logDTO = new SystemSetLogDTO(); final SystemSetLogDTO logDTO = new SystemSetLogDTO();
//操作时间 //操作时间
......
package com.gic.enterprise.service.outer.impl.payComplete;
import com.gic.enterprise.dto.ApprovalCallBackDTO;
import com.gic.enterprise.entity.TabBillingPayInfo;
/**
*
* @Description:
* @author zhiwj
* @date 2020-11-24 15:39
*/
public interface PayCompleteHandler {
/**
* 购买套餐包或余额充值以后的统一处理
* @Title: payComplete
* @Description:
* @author zhiwj
* @param callBackDTO
* @param billingPayInfo
* @return void
* @throws
*/
void payComplete(ApprovalCallBackDTO callBackDTO, TabBillingPayInfo billingPayInfo);
}
package com.gic.enterprise.service.outer.impl.payComplete;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.UserDTO;
import com.gic.auth.service.UserApiService;
import com.gic.enterprise.constant.BillingAuditStatusEnum;
import com.gic.enterprise.constant.PayTypeEnum;
import com.gic.enterprise.dto.ApprovalCallBackDTO;
import com.gic.enterprise.dto.EnterpriseDTO;
import com.gic.enterprise.entity.TabBillingPayInfo;
import com.gic.enterprise.entity.TabBillingRechargeRecord;
import com.gic.enterprise.service.BillingRechargeRecordService;
import com.gic.enterprise.service.EnterpriseApiService;
import com.gic.enterprise.service.PushMessageApiService;
import com.gic.log.api.dto.SystemSetLogDTO;
import com.gic.log.api.service.LogApiService;
import com.gic.marketing.process.api.service.sms.SmsSendApiService;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* 余额充值支付完成
* @Description:
* @author zhiwj
* @date 2020-11-24 15:57
*/
@Component("BALANCE_RECHARGE")
public class RechargeHandler implements PayCompleteHandler {
private Logger logger = LogManager.getLogger(RechargeHandler.class);
@Autowired
private BillingRechargeRecordService billingRechargeRecordService;
@Autowired
private UserApiService userApiService;
@Autowired
private PushMessageApiService pushMessageApiService;
@Autowired
private EnterpriseApiService enterpriseApiService;
@Autowired
private SmsSendApiService smsSendApiService;
@Autowired
private LogApiService logApiService;
@Override
public void payComplete(ApprovalCallBackDTO resData, TabBillingPayInfo billingPayInfo) {
// 通知
pushMessageApiService.pushMessage(resData.getEnterpriseId(), "系统通知", "余额充值", "您的商户成功充值"+resData.getTotalFeePaid()+"元!感谢您的支持和使用!");
// 充值成功短信
sendRechargeSuccessSms(resData, billingPayInfo.getEnterpriseId());
// 日志
TabBillingRechargeRecord rechargeRecord = billingRechargeRecordService.getRechargeRecordBySerialNumber(billingPayInfo.getOrderSerialNumber());
UserDTO userDTO = userApiService.getUserInfoById(rechargeRecord.getInitiatorUser()).getResult();
doLog("充值", "账户余额", userDTO);
// 审核成功短信
if (PayTypeEnum.OFFLINE_PAY.getCode() == resData.getPayType()) {
sendApprovalSms(resData, "GICJFZX008");
}
billingRechargeRecordService.updateBySerialNumber(resData.getEnterpriseId(), resData.getOrderSerialNumber(),
resData.getTotalFee(), resData.getTotalFeePaid(), resData.getAuditStatus(), resData.getTimeEnd(), resData.getOnlineSerialNumber());
}
private void sendApprovalSms(ApprovalCallBackDTO resData, String code) {
TabBillingRechargeRecord rechargeRecord = billingRechargeRecordService.getRechargeRecordBySerialNumber(resData.getOrderSerialNumber());
Integer initiator = rechargeRecord.getInitiator();
UserDTO userDTO = userApiService.getUserInfoById(initiator).getResult();
sendSms(resData, userDTO, code);
}
private void sendRechargeSuccessSms(ApprovalCallBackDTO resData, Integer enterpriseId) {
UserDTO userDTO = userApiService.getUserByEnterpriseId(enterpriseId).getResult();
sendSms(resData, userDTO, "GICJFZX005");
}
private void sendSms(ApprovalCallBackDTO resData, UserDTO userDTO, String code) {
try {
if (StringUtils.isBlank(userDTO.getPhoneAreaCode())) {
userDTO.setPhoneAreaCode("+86");
}
EnterpriseDTO enterpriseDTO = enterpriseApiService.getEnterpriseById(userDTO.getEnterpriseId()).getResult();
String[] smsArr = new String[]{enterpriseDTO.getEnterpriseName(), resData.getOrderSerialNumber(), BillingAuditStatusEnum.PASS.getCode().equals(resData.getAuditStatus()) ? "成功" : "失败"};
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms(code,
userDTO.getEnterpriseId(), userDTO.getPhoneAreaCode(), userDTO.getPhoneNumber(), smsArr);
if (!smsSendResult.isSuccess()) {
logger.warn(smsSendResult.getMessage());
}
} catch (Exception e) {
logger.info("发送短信失败", e);
}
}
private void doLog(String content, String operationObject, UserDTO userDTO) {
final SystemSetLogDTO logDTO = new SystemSetLogDTO();
//操作时间
logDTO.setLogTime(new Date());
logDTO.setCreateTime(new Date());
//操作人
logDTO.setUserId(Long.valueOf(userDTO.getUserId()));
logDTO.setUserName(userDTO.getUserName());
//操作内容
logDTO.setContent(content);
//为了search查询,暂时用这个字段存
logDTO.setInterfaceName(content);
////操作对象
logDTO.setBusinessName(operationObject);
//操作模块
logDTO.setRelationId(45000L);
logDTO.setProject("企业-计费中心");
// }
//账号(手机号)
logDTO.setRemark1(userDTO.getPhoneAreaCode());
logDTO.setRemark2(userDTO.getPhoneNumber());
logDTO.setEnterpriseId(userDTO.getEnterpriseId().longValue());
EnterpriseDTO enterpriseDTO = enterpriseApiService.getEnterpriseById(userDTO.getEnterpriseId()).getResult();
logDTO.setEnterpriseName(enterpriseDTO.getEnterpriseName());
logApiService.saveSystemSetLog(logDTO);
}
}
package com.gic.enterprise.service.outer.impl.payComplete;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.UserDTO;
import com.gic.auth.service.UserApiService;
import com.gic.enterprise.constant.BillingAuditStatusEnum;
import com.gic.enterprise.dto.ApprovalCallBackDTO;
import com.gic.enterprise.dto.EnterpriseDTO;
import com.gic.enterprise.entity.TabBillingOrder;
import com.gic.enterprise.entity.TabBillingPayInfo;
import com.gic.enterprise.service.BillingOrderService;
import com.gic.enterprise.service.EnterpriseApiService;
import com.gic.log.api.dto.SystemSetLogDTO;
import com.gic.log.api.service.LogApiService;
import com.gic.marketing.process.api.service.sms.SmsSendApiService;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
*
* @Description:
* @author zhiwj
* @date 2020-11-24 16:01
*/
@Component("BUY_SHORT_MESSAGE_PACKAGE")
public class SmsPackageHandler implements PayCompleteHandler {
private Logger logger = LogManager.getLogger(SmsPackageHandler.class);
@Autowired
private BillingOrderService billingOrderService;
@Autowired
private UserApiService userApiService;
@Autowired
private EnterpriseApiService enterpriseApiService;
@Autowired
private SmsSendApiService smsSendApiService;
@Autowired
private LogApiService logApiService;
@Override
public void payComplete(ApprovalCallBackDTO resData, TabBillingPayInfo billingPayInfo) {
billingOrderService.updateBySerialNumber(resData.getOrderSerialNumber(), resData.getTotalFeePaid(), resData.getAuditStatus(), resData.getTimeEnd());
TabBillingOrder order = this.billingOrderService.getOrderBySerialNumber(resData.getOrderSerialNumber());
UserDTO user = userApiService.getUserInfoById(order.getInitiatorUser()).getResult();
doLog("支付", "订单内容", user);
sendOrderApprovalSms(resData, "GICJFZX006");
}
private void sendOrderApprovalSms(ApprovalCallBackDTO resData, String code) {
TabBillingOrder order = billingOrderService.getOrderBySerialNumber(resData.getOrderSerialNumber());
Integer initiator = order.getInitiatorUser();
if (initiator != null) {
UserDTO userDTO = userApiService.getUserInfoById(initiator).getResult();
sendSms(resData, userDTO, code);
}
}
private void sendSms(ApprovalCallBackDTO resData, UserDTO userDTO, String code) {
try {
if (StringUtils.isBlank(userDTO.getPhoneAreaCode())) {
userDTO.setPhoneAreaCode("+86");
}
EnterpriseDTO enterpriseDTO = enterpriseApiService.getEnterpriseById(userDTO.getEnterpriseId()).getResult();
String[] smsArr = new String[]{enterpriseDTO.getEnterpriseName(), resData.getOrderSerialNumber(), BillingAuditStatusEnum.PASS.getCode().equals(resData.getAuditStatus()) ? "成功" : "失败"};
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms(code,
userDTO.getEnterpriseId(), userDTO.getPhoneAreaCode(), userDTO.getPhoneNumber(), smsArr);
if (!smsSendResult.isSuccess()) {
logger.warn(smsSendResult.getMessage());
}
} catch (Exception e) {
logger.info("发送短信失败", e);
}
}
private void doLog(String content, String operationObject, UserDTO userDTO) {
final SystemSetLogDTO logDTO = new SystemSetLogDTO();
//操作时间
logDTO.setLogTime(new Date());
logDTO.setCreateTime(new Date());
//操作人
logDTO.setUserId(Long.valueOf(userDTO.getUserId()));
logDTO.setUserName(userDTO.getUserName());
//操作内容
logDTO.setContent(content);
//为了search查询,暂时用这个字段存
logDTO.setInterfaceName(content);
////操作对象
logDTO.setBusinessName(operationObject);
//操作模块
logDTO.setRelationId(45000L);
logDTO.setProject("企业-计费中心");
// }
//账号(手机号)
logDTO.setRemark1(userDTO.getPhoneAreaCode());
logDTO.setRemark2(userDTO.getPhoneNumber());
logDTO.setEnterpriseId(userDTO.getEnterpriseId().longValue());
EnterpriseDTO enterpriseDTO = enterpriseApiService.getEnterpriseById(userDTO.getEnterpriseId()).getResult();
logDTO.setEnterpriseName(enterpriseDTO.getEnterpriseName());
logApiService.saveSystemSetLog(logDTO);
}
}
...@@ -149,4 +149,5 @@ ...@@ -149,4 +149,5 @@
<dubbo:reference interface="com.gic.widget.screening.api.service.EsScreeningEnterpriseInitService" id="esScreeningEnterpriseInitService" timeout="6000" /> <dubbo:reference interface="com.gic.widget.screening.api.service.EsScreeningEnterpriseInitService" id="esScreeningEnterpriseInitService" timeout="6000" />
<dubbo:reference interface="com.gic.cloud.service.IndexDescApiService" id="indexDescApiService" timeout="6000" /> <dubbo:reference interface="com.gic.cloud.service.IndexDescApiService" id="indexDescApiService" timeout="6000" />
<dubbo:reference interface="com.gic.member.tag.api.service.SceneCrowdGroupApiService" id="sceneCrowdGroupApiService" timeout="6000" /> <dubbo:reference interface="com.gic.member.tag.api.service.SceneCrowdGroupApiService" id="sceneCrowdGroupApiService" timeout="6000" />
<dubbo:reference interface="com.gic.store.service.StoreWidgetApiService" id="storeWidgetApiService" timeout="6000" />
</beans> </beans>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment