Merge remote-tracking branch 'origin/master'

This commit is contained in:
little-cat-sweet 2021-08-02 17:31:44 +08:00
commit 2a0765f62a
20 changed files with 539 additions and 428 deletions

View File

@ -68,11 +68,6 @@ public class StatusConstants {
*/ */
public static final Integer EXPIRE_TIME = 5 * 60 * 1000; public static final Integer EXPIRE_TIME = 5 * 60 * 1000;
/**
* 状态0待支付 1充值成功2充值失败
*/
private Integer status;
/** /**
* 充值订单状态待支付 * 充值订单状态待支付
*/ */
@ -162,4 +157,24 @@ public class StatusConstants {
* 清分状态待审核 * 清分状态待审核
*/ */
public static final Integer SORTING_STATUS_EXAMINE = 4; public static final Integer SORTING_STATUS_EXAMINE = 4;
/**
* 类型1充值 2退款 3充电
*/
private Integer type;
/**
* 用户充值流水
*/
public static final Integer FLOWING_WATER_RECHARGE_TYPE = 1;
/**
* 用户退款流水
*/
public static final Integer FLOWING_WATER_REFUND_TYPE = 2;
/**
* 用户充电流水
*/
public static final Integer FLOWING_WATER_CHARGE_TYPE = 3;
} }

View File

@ -6,6 +6,7 @@ import org.springframework.util.AntPathMatcher;
import java.beans.PropertyDescriptor; import java.beans.PropertyDescriptor;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -15,12 +16,15 @@ import java.util.Map;
* *
* @author ruoyi * @author ruoyi
*/ */
public class StringUtils extends org.apache.commons.lang3.StringUtils public class StringUtils extends org.apache.commons.lang3.StringUtils {
{ /**
/** 空字符串 */ * 空字符串
*/
private static final String NULLSTR = ""; private static final String NULLSTR = "";
/** 下划线 */ /**
* 下划线
*/
private static final char SEPARATOR = '_'; private static final char SEPARATOR = '_';
/** /**
@ -29,8 +33,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param value defaultValue 要判断的value * @param value defaultValue 要判断的value
* @return value 返回值 * @return value 返回值
*/ */
public static <T> T nvl(T value, T defaultValue) public static <T> T nvl(T value, T defaultValue) {
{
return value != null ? value : defaultValue; return value != null ? value : defaultValue;
} }
@ -40,8 +43,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param coll 要判断的Collection * @param coll 要判断的Collection
* @return true为空 false非空 * @return true为空 false非空
*/ */
public static boolean isEmpty(Collection<?> coll) public static boolean isEmpty(Collection<?> coll) {
{
return isNull(coll) || coll.isEmpty(); return isNull(coll) || coll.isEmpty();
} }
@ -51,8 +53,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param coll 要判断的Collection * @param coll 要判断的Collection
* @return true非空 false * @return true非空 false
*/ */
public static boolean isNotEmpty(Collection<?> coll) public static boolean isNotEmpty(Collection<?> coll) {
{
return !isEmpty(coll); return !isEmpty(coll);
} }
@ -60,10 +61,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* * 判断一个对象数组是否为空 * * 判断一个对象数组是否为空
* *
* @param objects 要判断的对象数组 * @param objects 要判断的对象数组
** @return true为空 false非空 * * @return true为空 false非空
*/ */
public static boolean isEmpty(Object[] objects) public static boolean isEmpty(Object[] objects) {
{
return isNull(objects) || (objects.length == 0); return isNull(objects) || (objects.length == 0);
} }
@ -73,8 +73,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param objects 要判断的对象数组 * @param objects 要判断的对象数组
* @return true非空 false * @return true非空 false
*/ */
public static boolean isNotEmpty(Object[] objects) public static boolean isNotEmpty(Object[] objects) {
{
return !isEmpty(objects); return !isEmpty(objects);
} }
@ -84,8 +83,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param map 要判断的Map * @param map 要判断的Map
* @return true为空 false非空 * @return true为空 false非空
*/ */
public static boolean isEmpty(Map<?, ?> map) public static boolean isEmpty(Map<?, ?> map) {
{
return isNull(map) || map.isEmpty(); return isNull(map) || map.isEmpty();
} }
@ -95,8 +93,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param map 要判断的Map * @param map 要判断的Map
* @return true非空 false * @return true非空 false
*/ */
public static boolean isNotEmpty(Map<?, ?> map) public static boolean isNotEmpty(Map<?, ?> map) {
{
return !isEmpty(map); return !isEmpty(map);
} }
@ -106,8 +103,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param str String * @param str String
* @return true为空 false非空 * @return true为空 false非空
*/ */
public static boolean isEmpty(String str) public static boolean isEmpty(String str) {
{
return isNull(str) || NULLSTR.equals(str.trim()); return isNull(str) || NULLSTR.equals(str.trim());
} }
@ -117,8 +113,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param str String * @param str String
* @return true非空串 false空串 * @return true非空串 false空串
*/ */
public static boolean isNotEmpty(String str) public static boolean isNotEmpty(String str) {
{
return !isEmpty(str); return !isEmpty(str);
} }
@ -128,8 +123,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param object Object * @param object Object
* @return true为空 false非空 * @return true为空 false非空
*/ */
public static boolean isNull(Object object) public static boolean isNull(Object object) {
{
return object == null; return object == null;
} }
@ -139,8 +133,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param object Object * @param object Object
* @return true非空 false * @return true非空 false
*/ */
public static boolean isNotNull(Object object) public static boolean isNotNull(Object object) {
{
return !isNull(object); return !isNull(object);
} }
@ -150,44 +143,37 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param object 对象 * @param object 对象
* @return true是数组 false不是数组 * @return true是数组 false不是数组
*/ */
public static boolean isArray(Object object) public static boolean isArray(Object object) {
{
return isNotNull(object) && object.getClass().isArray(); return isNotNull(object) && object.getClass().isArray();
} }
/** /**
* 去空格 * 去空格
*/ */
public static String trim(String str) public static String trim(String str) {
{
return (str == null ? "" : str.trim()); return (str == null ? "" : str.trim());
} }
/** /**
* 截取字符串 * 截取字符串
* *
* @param str 字符串 * @param str 字符串
* @param start 开始 * @param start 开始
* @return 结果 * @return 结果
*/ */
public static String substring(final String str, int start) public static String substring(final String str, int start) {
{ if (str == null) {
if (str == null)
{
return NULLSTR; return NULLSTR;
} }
if (start < 0) if (start < 0) {
{
start = str.length() + start; start = str.length() + start;
} }
if (start < 0) if (start < 0) {
{
start = 0; start = 0;
} }
if (start > str.length()) if (start > str.length()) {
{
return NULLSTR; return NULLSTR;
} }
@ -197,43 +183,35 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 截取字符串 * 截取字符串
* *
* @param str 字符串 * @param str 字符串
* @param start 开始 * @param start 开始
* @param end 结束 * @param end 结束
* @return 结果 * @return 结果
*/ */
public static String substring(final String str, int start, int end) public static String substring(final String str, int start, int end) {
{ if (str == null) {
if (str == null)
{
return NULLSTR; return NULLSTR;
} }
if (end < 0) if (end < 0) {
{
end = str.length() + end; end = str.length() + end;
} }
if (start < 0) if (start < 0) {
{
start = str.length() + start; start = str.length() + start;
} }
if (end > str.length()) if (end > str.length()) {
{
end = str.length(); end = str.length();
} }
if (start > end) if (start > end) {
{
return NULLSTR; return NULLSTR;
} }
if (start < 0) if (start < 0) {
{
start = 0; start = 0;
} }
if (end < 0) if (end < 0) {
{
end = 0; end = 0;
} }
@ -246,18 +224,14 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param str 要判断的value * @param str 要判断的value
* @return 结果 * @return 结果
*/ */
public static boolean hasText(String str) public static boolean hasText(String str) {
{
return (str != null && !str.isEmpty() && containsText(str)); return (str != null && !str.isEmpty() && containsText(str));
} }
private static boolean containsText(CharSequence str) private static boolean containsText(CharSequence str) {
{
int strLen = str.length(); int strLen = str.length();
for (int i = 0; i < strLen; i++) for (int i = 0; i < strLen; i++) {
{ if (!Character.isWhitespace(str.charAt(i))) {
if (!Character.isWhitespace(str.charAt(i)))
{
return true; return true;
} }
} }
@ -274,13 +248,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* 转义\ format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> * 转义\ format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
* *
* @param template 文本模板被替换的部分用 {} 表示 * @param template 文本模板被替换的部分用 {} 表示
* @param params 参数值 * @param params 参数值
* @return 格式化后的文本 * @return 格式化后的文本
*/ */
public static String format(String template, Object... params) public static String format(String template, Object... params) {
{ if (isEmpty(params) || isEmpty(template)) {
if (isEmpty(params) || isEmpty(template))
{
return template; return template;
} }
return StrFormatter.format(template, params); return StrFormatter.format(template, params);
@ -289,10 +261,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 驼峰转下划线命名 * 驼峰转下划线命名
*/ */
public static String toUnderScoreCase(String str) public static String toUnderScoreCase(String str) {
{ if (str == null) {
if (str == null)
{
return null; return null;
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -302,31 +272,23 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
boolean curreCharIsUpperCase = true; boolean curreCharIsUpperCase = true;
// 下一字符是否大写 // 下一字符是否大写
boolean nexteCharIsUpperCase = true; boolean nexteCharIsUpperCase = true;
for (int i = 0; i < str.length(); i++) for (int i = 0; i < str.length(); i++) {
{
char c = str.charAt(i); char c = str.charAt(i);
if (i > 0) if (i > 0) {
{
preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1)); preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1));
} } else {
else
{
preCharIsUpperCase = false; preCharIsUpperCase = false;
} }
curreCharIsUpperCase = Character.isUpperCase(c); curreCharIsUpperCase = Character.isUpperCase(c);
if (i < (str.length() - 1)) if (i < (str.length() - 1)) {
{
nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1)); nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1));
} }
if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) {
{
sb.append(SEPARATOR); sb.append(SEPARATOR);
} } else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) {
else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase)
{
sb.append(SEPARATOR); sb.append(SEPARATOR);
} }
sb.append(Character.toLowerCase(c)); sb.append(Character.toLowerCase(c));
@ -338,18 +300,14 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 是否包含字符串 * 是否包含字符串
* *
* @param str 验证字符串 * @param str 验证字符串
* @param strs 字符串组 * @param strs 字符串组
* @return 包含返回true * @return 包含返回true
*/ */
public static boolean inStringIgnoreCase(String str, String... strs) public static boolean inStringIgnoreCase(String str, String... strs) {
{ if (str != null && strs != null) {
if (str != null && strs != null) for (String s : strs) {
{ if (str.equalsIgnoreCase(trim(s))) {
for (String s : strs)
{
if (str.equalsIgnoreCase(trim(s)))
{
return true; return true;
} }
} }
@ -363,27 +321,21 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param name 转换前的下划线大写方式命名的字符串 * @param name 转换前的下划线大写方式命名的字符串
* @return 转换后的驼峰式命名的字符串 * @return 转换后的驼峰式命名的字符串
*/ */
public static String convertToCamelCase(String name) public static String convertToCamelCase(String name) {
{
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
// 快速检查 // 快速检查
if (name == null || name.isEmpty()) if (name == null || name.isEmpty()) {
{
// 没必要转换 // 没必要转换
return ""; return "";
} } else if (!name.contains("_")) {
else if (!name.contains("_"))
{
// 不含下划线仅将首字母大写 // 不含下划线仅将首字母大写
return name.substring(0, 1).toUpperCase() + name.substring(1); return name.substring(0, 1).toUpperCase() + name.substring(1);
} }
// 用下划线将原始字符串分割 // 用下划线将原始字符串分割
String[] camels = name.split("_"); String[] camels = name.split("_");
for (String camel : camels) for (String camel : camels) {
{
// 跳过原始字符串中开头结尾的下换线或双重下划线 // 跳过原始字符串中开头结尾的下换线或双重下划线
if (camel.isEmpty()) if (camel.isEmpty()) {
{
continue; continue;
} }
// 首字母大写 // 首字母大写
@ -396,30 +348,22 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 驼峰式命名法 例如user_name->userName * 驼峰式命名法 例如user_name->userName
*/ */
public static String toCamelCase(String s) public static String toCamelCase(String s) {
{ if (s == null) {
if (s == null)
{
return null; return null;
} }
s = s.toLowerCase(); s = s.toLowerCase();
StringBuilder sb = new StringBuilder(s.length()); StringBuilder sb = new StringBuilder(s.length());
boolean upperCase = false; boolean upperCase = false;
for (int i = 0; i < s.length(); i++) for (int i = 0; i < s.length(); i++) {
{
char c = s.charAt(i); char c = s.charAt(i);
if (c == SEPARATOR) if (c == SEPARATOR) {
{
upperCase = true; upperCase = true;
} } else if (upperCase) {
else if (upperCase)
{
sb.append(Character.toUpperCase(c)); sb.append(Character.toUpperCase(c));
upperCase = false; upperCase = false;
} } else {
else
{
sb.append(c); sb.append(c);
} }
} }
@ -429,20 +373,16 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 查找指定字符串是否匹配指定字符串列表中的任意一个字符串 * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
* *
* @param str 指定字符串 * @param str 指定字符串
* @param strs 需要检查的字符串数组 * @param strs 需要检查的字符串数组
* @return 是否匹配 * @return 是否匹配
*/ */
public static boolean matches(String str, List<String> strs) public static boolean matches(String str, List<String> strs) {
{ if (isEmpty(str) || isEmpty(strs)) {
if (isEmpty(str) || isEmpty(strs))
{
return false; return false;
} }
for (String pattern : strs) for (String pattern : strs) {
{ if (isMatch(pattern, str)) {
if (isMatch(pattern, str))
{
return true; return true;
} }
} }
@ -459,15 +399,13 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param url 需要匹配的url * @param url 需要匹配的url
* @return * @return
*/ */
public static boolean isMatch(String pattern, String url) public static boolean isMatch(String pattern, String url) {
{
AntPathMatcher matcher = new AntPathMatcher(); AntPathMatcher matcher = new AntPathMatcher();
return matcher.match(pattern, url); return matcher.match(pattern, url);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T cast(Object obj) public static <T> T cast(Object obj) {
{
return (T) obj; return (T) obj;
} }
@ -526,4 +464,18 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
} }
} }
/**
* 获取编号
*
* @param userId
* @param type
* @return
*/
public static String numFormat(Long userId, int channelType, int type) {
StringBuffer num = new StringBuffer();
DecimalFormat decimalFormat = new DecimalFormat("0000000");
int random = (int) (1 + Math.random() * (10 - 1 + 1));
num.append(decimalFormat.format(userId)).append(DateUtils.timePath()).append(channelType).append(type).append(random);
return num.toString();
}
} }

View File

@ -3,12 +3,9 @@ package com.xhpc.payment.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient; import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient; import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.internal.util.AlipaySignature; import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.request.AlipayTradeCreateRequest; import com.alipay.api.request.AlipayTradeCreateRequest;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.alipay.api.response.AlipayTradeCreateResponse; import com.alipay.api.response.AlipayTradeCreateResponse;
import com.xhpc.common.core.utils.DateUtils; import com.xhpc.common.core.utils.DateUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -112,56 +109,4 @@ public class AlipayPaymentController {
System.out.println(AlipaySignature.getSignCheckContentV1(params)); System.out.println(AlipaySignature.getSignCheckContentV1(params));
} }
} }
/**
* 25 * 支付宝转账到用户账号
* 26 * @throws IOException
* 27
*/
@GetMapping(value = "/enterpriseCheckOut")
public void toHtml() throws AlipayApiException {
String orderNumber = "alipay" + DateUtils.timePath();
String filePath = this.getClass().getResource("/").getPath() + "证书名字";
System.out.println(filePath);
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");
certAlipayRequest.setAppId(environment.getProperty("ALIPAYAPPID"));
certAlipayRequest.setPrivateKey(environment.getProperty("ALIPAYPRIVATEKEY"));//密钥
certAlipayRequest.setFormat("json");
certAlipayRequest.setCharset("UTF-8");
certAlipayRequest.setSignType("RSA2");
certAlipayRequest.setCertPath(filePath + "appCertPublicKey.crt");//应用证书
certAlipayRequest.setAlipayPublicCertPath(filePath + "alipayCertPublicKey_RSA2.crt");//支付证书
certAlipayRequest.setRootCertPath(filePath + "alipayRootCert.crt");
DefaultAlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
//价格
Double money = 0.01;
//转账标题
String order_title = "支付宝提现";
//支付宝会员id
String identity = "123";
//实名信息
String name = "";
request.setBizContent("{" +
"\"out_biz_no\":\"201806300001\"," +
"\"trans_amount\":" + money + "," +
"\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +
"\"biz_scene\":\"DIRECT_TRANSFER\"," +
"\"order_title\":\"" + order_title + "\"," +
"\"payee_info\":{" +
"\"identity\":\"" + identity + "\"," +
"\"identity_type\":\"ALIPAY_USER_ID \"," +
" }," +
" }");
AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
if (response.isSuccess()) {
System.out.println("调用成功");
} else {
System.out.println("调用失败");
}
}
} }

View File

@ -2,27 +2,16 @@ package com.xhpc.payment.controller;
import com.xhpc.common.core.constant.HttpStatus; import com.xhpc.common.core.constant.HttpStatus;
import com.xhpc.common.core.constant.StatusConstants; import com.xhpc.common.core.constant.StatusConstants;
import com.xhpc.common.core.listener.ConfigListener;
import com.xhpc.common.core.utils.DateUtils;
import com.xhpc.common.core.utils.StringUtils; import com.xhpc.common.core.utils.StringUtils;
import com.xhpc.common.core.utils.WXPayUtil; import com.xhpc.common.core.utils.WXPayUtil;
import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.payment.domain.XhpcAppUser; import com.xhpc.payment.domain.XhpcAppUser;
import com.xhpc.payment.domain.XhpcRechargeOrder; import com.xhpc.payment.domain.XhpcRechargeOrder;
import com.xhpc.payment.domain.XhpcUserAccountStatement;
import com.xhpc.payment.mapper.XhpcUserAccountStatementMapper; import com.xhpc.payment.mapper.XhpcUserAccountStatementMapper;
import com.xhpc.payment.service.IXhpcRechargeOrderService; import com.xhpc.payment.service.IXhpcRechargeOrderService;
import com.xhpc.payment.service.IXhpcRefundOrderService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -30,15 +19,16 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.net.ssl.SSLContext;
import javax.servlet.ServletInputStream; import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.security.KeyStore;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
@ -61,10 +51,6 @@ public class WxPaymentController {
@Autowired @Autowired
private XhpcUserAccountStatementMapper xhpcUserAccountStatementMapper; private XhpcUserAccountStatementMapper xhpcUserAccountStatementMapper;
@Autowired
private IXhpcRefundOrderService iXhpcRefundOrderService;
@Autowired @Autowired
private Environment environment; private Environment environment;
@ -86,7 +72,7 @@ public class WxPaymentController {
return AjaxResult.error(HttpStatus.NOT_NULL, "用户信息不能为空"); return AjaxResult.error(HttpStatus.NOT_NULL, "用户信息不能为空");
} }
Double amount1 = Double.parseDouble(amount) * 100; Double amount1 = Double.parseDouble(amount) * 100;
String orderNumber = String.format("%07d", userId) + DateUtils.timePath() + 1 + 1 + (int) (1 + Math.random() * (10 - 1 + 1)); String orderNumber = StringUtils.numFormat(Long.parseLong(userId), 1, StatusConstants.FLOWING_WATER_RECHARGE_TYPE);
if (0.0 == amount1) { if (0.0 == amount1) {
return AjaxResult.error(HttpStatus.NOT_NULL, "充值金额不能为0"); return AjaxResult.error(HttpStatus.NOT_NULL, "充值金额不能为0");
} }
@ -353,10 +339,16 @@ public class WxPaymentController {
xhpcAppUser.setAppUserId(xhpcRechargeOrder.getUserId()); xhpcAppUser.setAppUserId(xhpcRechargeOrder.getUserId());
xhpcAppUser.setBalance(BigDecimal.valueOf(Double.valueOf(balance)).add(xhpcRechargeOrder.getAmount())); xhpcAppUser.setBalance(BigDecimal.valueOf(Double.valueOf(balance)).add(xhpcRechargeOrder.getAmount()));
xhpcUserAccountStatementMapper.updateAppUserBalance(xhpcAppUser); xhpcUserAccountStatementMapper.updateAppUserBalance(xhpcAppUser);
XhpcUserAccountStatement xhpcUserAccountStatement = new XhpcUserAccountStatement();
xhpcUserAccountStatement.setType(StatusConstants.FLOWING_WATER_RECHARGE_TYPE);
xhpcUserAccountStatement.setRechargeOrderId(xhpcRechargeOrder.getRechargeOrderId());
xhpcUserAccountStatement.setUserId(xhpcRechargeOrder.getUserId());
xhpcUserAccountStatement.setAmount(xhpcRechargeOrder.getAmount());
xhpcUserAccountStatement.setRemainingSum(xhpcAppUser.getBalance());
xhpcUserAccountStatementMapper.insert(xhpcUserAccountStatement);
} }
} }
/** /**
* 回调Api * 回调Api
*/ */
@ -417,191 +409,4 @@ public class WxPaymentController {
} }
return null; return null;
} }
/**
* 企业退款
*
* @return
*/
@PostMapping("/enterpriseCheckOut")
@ApiOperation(value = "企业退款")
public synchronized Object enterpriseCheckOut(@RequestBody Map<String, Object> map) {
//用户信息id
String refundOrderId = StringUtils.valueOf(map.get("refundOrderId"));
if (StringUtils.isNull(refundOrderId)) {
return AjaxResult.error(HttpStatus.NOT_NULL, "订单信息不能为空");
}
Map<String, Object> xhpcRefundOrder = iXhpcRefundOrderService.info(Long.parseLong(refundOrderId));
if (StringUtils.isNull(xhpcRefundOrder)) {
return AjaxResult.error(HttpStatus.DATA_ERROR, "订单不存在");
}
String examineStatus = StringUtils.valueOf(xhpcRefundOrder.get("examineStatus"));
if ("1".equals(examineStatus)) {
return AjaxResult.error(HttpStatus.ERROR_STATUS, "订单状态不能退款");
}
String status = StringUtils.valueOf(xhpcRefundOrder.get("status"));
if ("0".equals(status)) {
return AjaxResult.error(HttpStatus.ERROR_STATUS, "订单状态不能退款");
}
CloseableHttpClient httpClient = null;
try {
//证书的地址
ConfigListener.getConf().get("certPath");
httpClient = initCert();
} catch (Exception e) {
e.printStackTrace();
}
String orderOutNumber = StringUtils.valueOf(xhpcRefundOrder.get("refundOrderNumber"));
String openId = StringUtils.valueOf(xhpcRefundOrder.get("openId"));
Double amount = Double.parseDouble(StringUtils.valueOf(xhpcRefundOrder.get("amount")));
//退款金额单位为分
Double value = amount * 100;
Integer refund_fee = value.intValue();
if (refund_fee <= 0) {
return AjaxResult.error(HttpStatus.ERROR_STATUS, "订单金额出错");
}
String userId = StringUtils.valueOf(map.get("userId"));
Map<String, Object> appUserInfo = xhpcUserAccountStatementMapper.appUserInfo(Long.parseLong(userId));
String balance = StringUtils.valueOf(appUserInfo.get("balance"));
if (StringUtils.isNotNull(appUserInfo)) {
return AjaxResult.error(HttpStatus.DATA_ERROR, "用户不存在");
}
BigDecimal surplus = BigDecimal.valueOf(Double.valueOf(balance)).subtract(BigDecimal.valueOf(amount));
if (surplus.compareTo(BigDecimal.ZERO) == -1) {
return AjaxResult.error(HttpStatus.ERROR_STATUS, "余额不足");
}
String result = "";
HttpPost httpPost = new HttpPost(environment.getProperty("WXTRANSFERS"));
StringEntity postEntity = new StringEntity(creatXMLParam(orderOutNumber, refund_fee.toString(), "退款申请", openId), "UTF-8");
httpPost.addHeader("Content-Type", "text/xml");
httpPost.setEntity(postEntity);
try {
HttpResponse response = null;
try {
response = httpClient.execute(httpPost);
} catch (IOException e) {
e.printStackTrace();
}
HttpEntity entity = response.getEntity();
try {
result = EntityUtils.toString(entity, "UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
} finally {
httpPost.abort();
}
return parseXml(result, Long.parseLong(refundOrderId), surplus, userId);
}
/**
* 加载证书
*
* @param
* @throws Exception
*/
private CloseableHttpClient initCert() throws Exception {
String path = "apiclient_cert.p12";
File file = new File(this.getClass().getResource("/").getPath() + path);
//线上地址
//File file = new File("/www/wwwroot/msjd.project2.tingsun.net/" + path);
// 证书密码默认为商户ID
String key = environment.getProperty("MCHID");
// 指定读取证书格式为PKCS12
KeyStore keyStore = KeyStore.getInstance("PKCS12");
// 读取本机存放的PKCS12证书文件
FileInputStream instream = new FileInputStream(file);
try {
// 指定PKCS12的密码(商户ID)
keyStore.load(instream, key.toCharArray());
} finally {
instream.close();
}
SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, key.toCharArray()).build();
SSLConnectionSocketFactory sslsf =
new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null,
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
}
/**
* 生成xml格式 添加参数时按照abcd26个字母顺序添加
*
* @param openid 用户openid
* @param partner_trade_no 商户退款单号
* @param amount 退款金额
* @param refund_desc 退款原因
* @return
*/
private String creatXMLParam(String partner_trade_no, String amount, String refund_desc, String openid) {
String param = "";
//随机字符串
String nonceStr = WXPayUtil.generateNonceStr();
//退款金额
param += "amount=" + amount;
//校验用户姓名选项
param += "&check_name=" + "NO_CHECK";
//退款原因
param += "&desc=" + refund_desc;
param += "&mch_appid=" + environment.getProperty("APPID");
//商户id
param += "&mchid=" + environment.getProperty("MCHID");
//随机字符串
param += "&nonce_str=" + nonceStr;
//用户openid
param += "&openid=" + openid;
//商户退款单号 一个订单唯一
param += "&partner_trade_no=" + partner_trade_no;
//生成签名 添加key值
String stringSignTemp = param + "&key=" + environment.getProperty("KEY");
//签名 不参与签名 默认MD5算法
String sign = StringUtils.md5(stringSignTemp);
String xmlString = "<xml>\n" +
" <amount>" + amount + "</amount>\n" +
" <check_name>" + "NO_CHECK" + "</check_name>\n" +
" <desc>" + refund_desc + "</desc>\n" +
" <mch_appid>" + environment.getProperty("APPID") + "</mch_appid>\n" +
" <mchid>" + environment.getProperty("MCHID") + "</mchid>\n" +
" <nonce_str>" + nonceStr + "</nonce_str>\n" +
" <openid>" + openid + "</openid>\n" +
" <partner_trade_no>" + partner_trade_no + "</partner_trade_no>\n" +
" <sign>" + sign + "</sign>\n" +
"</xml> ";
return xmlString;
}
/**
* 解析xml字符串
*
* @param result 请求后的结果
* @return
*/
private AjaxResult parseXml(String result, Long id, BigDecimal amount, String userId) {
try {
Map<String, String> map = WXPayUtil.xmlToMap(result);
String result_code = map.get("result_code");
if ("FAIL".equals(result_code)) {
return AjaxResult.error(map.get("err_code_des"));
} else {
//退款成功修改订单
iXhpcRefundOrderService.updateRefundOrder(id, StatusConstants.OPERATION_WX_TYPE, StatusConstants.REFUND_ORDER_STATUS_SUCCESS);
//减少用户余额
XhpcAppUser xhpcAppUser = new XhpcAppUser();
xhpcAppUser.setAppUserId(Long.parseLong(userId));
xhpcAppUser.setBalance(amount);
xhpcUserAccountStatementMapper.updateAppUserBalance(xhpcAppUser);
return AjaxResult.success("退款成功");
}
} catch (Exception e) {
AjaxResult.error(e.getMessage());
e.printStackTrace();
}
return AjaxResult.error();
}
} }

View File

@ -1,15 +1,46 @@
package com.xhpc.payment.controller; package com.xhpc.payment.controller;
import com.alipay.api.AlipayApiException;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.xhpc.common.core.constant.HttpStatus;
import com.xhpc.common.core.constant.StatusConstants;
import com.xhpc.common.core.listener.ConfigListener;
import com.xhpc.common.core.utils.DateUtils;
import com.xhpc.common.core.utils.StringUtils;
import com.xhpc.common.core.utils.WXPayUtil;
import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo; import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.payment.domain.XhpcAppUser;
import com.xhpc.payment.domain.XhpcRefundAudit; import com.xhpc.payment.domain.XhpcRefundAudit;
import com.xhpc.payment.domain.XhpcUserAccountStatement;
import com.xhpc.payment.mapper.XhpcUserAccountStatementMapper;
import com.xhpc.payment.service.IXhpcRefundAuditService; import com.xhpc.payment.service.IXhpcRefundAuditService;
import com.xhpc.payment.service.IXhpcRefundOrderService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.net.ssl.SSLContext;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.security.KeyStore;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -21,6 +52,15 @@ public class XhpcRefundAuditController extends BaseController {
@Autowired @Autowired
private IXhpcRefundAuditService iXhpcRefundAuditService; private IXhpcRefundAuditService iXhpcRefundAuditService;
@Autowired
private IXhpcRefundOrderService iXhpcRefundOrderService;
@Autowired
private XhpcUserAccountStatementMapper xhpcUserAccountStatementMapper;
@Autowired
private Environment environment;
/** /**
* 退款审核 * 退款审核
* *
@ -30,6 +70,16 @@ public class XhpcRefundAuditController extends BaseController {
@GetMapping("/examine") @GetMapping("/examine")
@ApiOperation(value = "退款审核") @ApiOperation(value = "退款审核")
public AjaxResult info(@RequestBody XhpcRefundAudit xhpcRefundAudit) { public AjaxResult info(@RequestBody XhpcRefundAudit xhpcRefundAudit) {
if (StatusConstants.REFUND_ORDER_STATUS_SUCCESS == xhpcRefundAudit.getStatus()) {
Map<String, Object> map = iXhpcRefundOrderService.info(xhpcRefundAudit.getRefundOrderId());
if (null == map) {
AjaxResult.error(HttpStatus.DATA_ERROR, "退款订单不存在");
}
String refundOrderId = StringUtils.valueOf(map.get("refundOrderId"));
if (StatusConstants.OPERATION_WX_TYPE.equals(refundOrderId)) {
enterpriseCheckOut(xhpcRefundAudit);
}
}
return AjaxResult.success(iXhpcRefundAuditService.insert(xhpcRefundAudit)); return AjaxResult.success(iXhpcRefundAuditService.insert(xhpcRefundAudit));
} }
@ -42,4 +92,248 @@ public class XhpcRefundAuditController extends BaseController {
List<Map<String, Object>> list = iXhpcRefundAuditService.list(refundOrderId); List<Map<String, Object>> list = iXhpcRefundAuditService.list(refundOrderId);
return getDataTable(list); return getDataTable(list);
} }
/**
* 企业退款
*
* @return
*/
public synchronized Object enterpriseCheckOut(@RequestBody XhpcRefundAudit xhpcRefundAudit) {
//只有审核通过才能退款
Map<String, Object> xhpcRefundOrder = iXhpcRefundOrderService.info(xhpcRefundAudit.getRefundOrderId());
if (StringUtils.isNull(xhpcRefundOrder)) {
return AjaxResult.error(HttpStatus.DATA_ERROR, "订单不存在");
}
String examineStatus = StringUtils.valueOf(xhpcRefundOrder.get("examineStatus"));
if (!"1".equals(examineStatus)) {
return AjaxResult.error(HttpStatus.ERROR_STATUS, "订单状态不能退款");
}
String status = StringUtils.valueOf(xhpcRefundOrder.get("status"));
if (!"0".equals(status)) {
return AjaxResult.error(HttpStatus.ERROR_STATUS, "订单状态不能退款");
}
CloseableHttpClient httpClient = null;
try {
//证书的地址
ConfigListener.getConf().get("certPath");
httpClient = initCert();
} catch (Exception e) {
e.printStackTrace();
}
String orderOutNumber = StringUtils.valueOf(xhpcRefundOrder.get("refundOrderNumber"));
String openId = StringUtils.valueOf(xhpcRefundOrder.get("openId"));
Double amount = Double.parseDouble(StringUtils.valueOf(xhpcRefundOrder.get("amount")));
//退款金额单位为分
Double value = amount * 100;
Integer refund_fee = value.intValue();
if (refund_fee <= 0) {
return AjaxResult.error(HttpStatus.ERROR_STATUS, "订单金额出错");
}
String userId = StringUtils.valueOf(xhpcRefundOrder.get("userId"));
Map<String, Object> appUserInfo = xhpcUserAccountStatementMapper.appUserInfo(Long.parseLong(userId));
String balance = StringUtils.valueOf(appUserInfo.get("balance"));
if (StringUtils.isNull(appUserInfo)) {
return AjaxResult.error(HttpStatus.DATA_ERROR, "用户不存在");
}
BigDecimal surplus = BigDecimal.valueOf(Double.valueOf(balance)).subtract(BigDecimal.valueOf(amount));
if (surplus.compareTo(BigDecimal.ZERO) == -1) {
return AjaxResult.error(HttpStatus.ERROR_STATUS, "余额不足");
}
String result = "";
HttpPost httpPost = new HttpPost(environment.getProperty("WXTRANSFERS"));
StringEntity postEntity = new StringEntity(creatXMLParam(orderOutNumber, refund_fee.toString(), "退款申请", openId), "UTF-8");
httpPost.addHeader("Content-Type", "text/xml");
httpPost.setEntity(postEntity);
try {
HttpResponse response = null;
try {
response = httpClient.execute(httpPost);
} catch (IOException e) {
e.printStackTrace();
}
HttpEntity entity = response.getEntity();
try {
result = EntityUtils.toString(entity, "UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
} finally {
httpPost.abort();
}
return parseXml(result, xhpcRefundAudit.getRefundOrderId(), BigDecimal.valueOf(amount), userId);
}
/**
* 加载证书
*
* @param
* @throws Exception
*/
private CloseableHttpClient initCert() throws Exception {
String path = "apiclient_cert.p12";
File file = new File(this.getClass().getResource("/").getPath() + path);
//线上地址
//File file = new File("/www/wwwroot/msjd.project2.tingsun.net/" + path);
// 证书密码默认为商户ID
String key = environment.getProperty("MCHID");
// 指定读取证书格式为PKCS12
KeyStore keyStore = KeyStore.getInstance("PKCS12");
// 读取本机存放的PKCS12证书文件
FileInputStream instream = new FileInputStream(file);
try {
// 指定PKCS12的密码(商户ID)
keyStore.load(instream, key.toCharArray());
} finally {
instream.close();
}
SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, key.toCharArray()).build();
SSLConnectionSocketFactory sslsf =
new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null,
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
}
/**
* 生成xml格式 添加参数时按照abcd26个字母顺序添加
*
* @param openid 用户openid
* @param partner_trade_no 商户退款单号
* @param amount 退款金额
* @param refund_desc 退款原因
* @return
*/
private String creatXMLParam(String partner_trade_no, String amount, String refund_desc, String openid) {
String param = "";
//随机字符串
String nonceStr = WXPayUtil.generateNonceStr();
//退款金额
param += "amount=" + amount;
//校验用户姓名选项
param += "&check_name=" + "NO_CHECK";
//退款原因
param += "&desc=" + refund_desc;
param += "&mch_appid=" + environment.getProperty("APPID");
//商户id
param += "&mchid=" + environment.getProperty("MCHID");
//随机字符串
param += "&nonce_str=" + nonceStr;
//用户openid
param += "&openid=" + openid;
//商户退款单号 一个订单唯一
param += "&partner_trade_no=" + partner_trade_no;
//生成签名 添加key值
String stringSignTemp = param + "&key=" + environment.getProperty("KEY");
//签名 不参与签名 默认MD5算法
String sign = StringUtils.md5(stringSignTemp);
String xmlString = "<xml>\n" +
" <amount>" + amount + "</amount>\n" +
" <check_name>" + "NO_CHECK" + "</check_name>\n" +
" <desc>" + refund_desc + "</desc>\n" +
" <mch_appid>" + environment.getProperty("APPID") + "</mch_appid>\n" +
" <mchid>" + environment.getProperty("MCHID") + "</mchid>\n" +
" <nonce_str>" + nonceStr + "</nonce_str>\n" +
" <openid>" + openid + "</openid>\n" +
" <partner_trade_no>" + partner_trade_no + "</partner_trade_no>\n" +
" <sign>" + sign + "</sign>\n" +
"</xml> ";
return xmlString;
}
/**
* 解析xml字符串
*
* @param result 请求后的结果
* @return
*/
private AjaxResult parseXml(String result, Long id, BigDecimal amount, String userId) {
try {
Map<String, String> map = WXPayUtil.xmlToMap(result);
String result_code = map.get("result_code");
if ("FAIL".equals(result_code)) {
return AjaxResult.error(map.get("err_code_des"));
} else {
//退款成功修改订单
iXhpcRefundOrderService.updateRefundOrder(id, StatusConstants.OPERATION_WX_TYPE, StatusConstants.REFUND_ORDER_STATUS_SUCCESS);
Map<String, Object> appUserInfo = xhpcUserAccountStatementMapper.appUserInfo(Long.parseLong(userId));
if (StringUtils.isNotNull(appUserInfo)) {
String balance = StringUtils.valueOf(appUserInfo.get("balance"));
//减少用户余额
XhpcAppUser xhpcAppUser = new XhpcAppUser();
xhpcAppUser.setAppUserId(Long.parseLong(userId));
BigDecimal surplus = BigDecimal.valueOf(Double.valueOf(balance)).subtract(amount);
xhpcAppUser.setBalance(surplus);
xhpcUserAccountStatementMapper.updateAppUserBalance(xhpcAppUser);
XhpcUserAccountStatement xhpcUserAccountStatement = new XhpcUserAccountStatement();
xhpcUserAccountStatement.setType(StatusConstants.FLOWING_WATER_REFUND_TYPE);
xhpcUserAccountStatement.setRefundOrderId(id);
xhpcUserAccountStatement.setUserId(Long.parseLong(userId));
xhpcUserAccountStatement.setAmount(amount);
xhpcUserAccountStatement.setRemainingSum(xhpcAppUser.getBalance());
xhpcUserAccountStatementMapper.insert(xhpcUserAccountStatement);
}
return AjaxResult.success("退款成功");
}
} catch (Exception e) {
AjaxResult.error(e.getMessage());
e.printStackTrace();
}
return AjaxResult.error();
}
/**
* 25 * 支付宝转账到用户账号
* 26 * @throws IOException
* 27
*/
public void enterpriseCheckOut() throws AlipayApiException {
String orderNumber = "alipay" + DateUtils.timePath();
String filePath = this.getClass().getResource("/").getPath() + "证书名字";
System.out.println(filePath);
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");
certAlipayRequest.setAppId(environment.getProperty("ALIPAYAPPID"));
certAlipayRequest.setPrivateKey(environment.getProperty("ALIPAYPRIVATEKEY"));//密钥
certAlipayRequest.setFormat("json");
certAlipayRequest.setCharset("UTF-8");
certAlipayRequest.setSignType("RSA2");
certAlipayRequest.setCertPath(filePath + "appCertPublicKey.crt");//应用证书
certAlipayRequest.setAlipayPublicCertPath(filePath + "alipayCertPublicKey_RSA2.crt");//支付证书
certAlipayRequest.setRootCertPath(filePath + "alipayRootCert.crt");
DefaultAlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
//价格
Double money = 0.01;
//转账标题
String order_title = "支付宝提现";
//支付宝会员id
String identity = "123";
//实名信息
String name = "";
request.setBizContent("{" +
"\"out_biz_no\":\"201806300001\"," +
"\"trans_amount\":" + money + "," +
"\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +
"\"biz_scene\":\"DIRECT_TRANSFER\"," +
"\"order_title\":\"" + order_title + "\"," +
"\"payee_info\":{" +
"\"identity\":\"" + identity + "\"," +
"\"identity_type\":\"ALIPAY_USER_ID \"," +
" }," +
" }");
AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
if (response.isSuccess()) {
System.out.println("调用成功");
} else {
System.out.println("调用失败");
}
}
} }

View File

@ -1,7 +1,7 @@
package com.xhpc.payment.controller; package com.xhpc.payment.controller;
import com.xhpc.common.core.constant.HttpStatus; import com.xhpc.common.core.constant.HttpStatus;
import com.xhpc.common.core.utils.DateUtils; import com.xhpc.common.core.constant.StatusConstants;
import com.xhpc.common.core.utils.StringUtils; import com.xhpc.common.core.utils.StringUtils;
import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.domain.AjaxResult;
@ -51,9 +51,14 @@ public class XhpcRefundOrderController extends BaseController {
return AjaxResult.error(HttpStatus.NOT_NULL, "退款渠道不能为空"); return AjaxResult.error(HttpStatus.NOT_NULL, "退款渠道不能为空");
} }
//生成退款订单 //生成退款订单
String orderOutNumber = String.format("%07d", userId) + DateUtils.timePath() + type + 2 + (int) (1 + Math.random() * (10 - 1 + 1)); String orderOutNumber = StringUtils.numFormat(Long.parseLong(userId), Integer.parseInt(type), StatusConstants.FLOWING_WATER_REFUND_TYPE);
iXhpcRefundOrderService.addRefundOrder(userId, BigDecimal.valueOf(Double.parseDouble(amount)), type, orderOutNumber, openid);
return AjaxResult.success(); return iXhpcRefundOrderService.addRefundOrder(userId, BigDecimal.valueOf(Double.parseDouble(amount)), type, orderOutNumber, openid);
}
public static void main(String[] args) {
System.out.println(StringUtils.numFormat(Long.parseLong("11"), Integer.parseInt("1"), StatusConstants.FLOWING_WATER_REFUND_TYPE));//打印结果"000006"
} }
/** /**

View File

@ -1,6 +1,7 @@
package com.xhpc.payment.controller; package com.xhpc.payment.controller;
import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo; import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.payment.service.IXhpcUserAccountStatementService; import com.xhpc.payment.service.IXhpcUserAccountStatementService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -29,10 +30,23 @@ public class XhpcUserAccountStatementController extends BaseController {
* @return * @return
*/ */
@ApiOperation(value = "用户流水分页列表") @ApiOperation(value = "用户流水分页列表")
@GetMapping("/list") @GetMapping("/page")
public TableDataInfo page(@RequestParam Long appUserId) { public TableDataInfo page(@RequestParam Long appUserId) {
startPage(); startPage();
List<Map<String, Object>> list = iXhpcUserAccountStatementService.page(appUserId); List<Map<String, Object>> list = iXhpcUserAccountStatementService.page(appUserId);
return getDataTable(list); return getDataTable(list);
} }
/**
* 用户流水列表
*
* @param appUserId C端用户id
* @return
*/
@ApiOperation(value = "用户流水列表")
@GetMapping("/list")
public AjaxResult list(@RequestParam Long appUserId) {
List<Map<String, Object>> list = iXhpcUserAccountStatementService.list(appUserId);
return AjaxResult.success(list);
}
} }

View File

@ -48,4 +48,13 @@ public interface XhpcRefundOrderMapper {
* @return * @return
*/ */
public List<Map<String, Object>> page(@Param("phone") String phone, @Param("refundOrderNumber") String refundOrderNumber, @Param("status") String status, @Param("createTimeStart") String createTimeStart, @Param("createTimeEnd") String createTimeEnd); public List<Map<String, Object>> page(@Param("phone") String phone, @Param("refundOrderNumber") String refundOrderNumber, @Param("status") String status, @Param("createTimeStart") String createTimeStart, @Param("createTimeEnd") String createTimeEnd);
/**
* 通过用户id查询未完成充电订单
*
* @param userId 用户id
* @return 结果
*/
public List<Map<String, Object>> getNotChargeOrder(@Param("userId") Long userId);
} }

View File

@ -46,4 +46,13 @@ public interface XhpcUserAccountStatementMapper {
* @return * @return
*/ */
public int updateAppUserBalance(XhpcAppUser xhpcAppUser); public int updateAppUserBalance(XhpcAppUser xhpcAppUser);
/**
* 用户流水列表
*
* @param appUserId C端用户id
* @return
*/
public List<Map<String, Object>> list(@Param("appUserId") Long appUserId);
} }

View File

@ -1,5 +1,6 @@
package com.xhpc.payment.service; package com.xhpc.payment.service;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.payment.domain.XhpcRefundAudit; import com.xhpc.payment.domain.XhpcRefundAudit;
import java.util.List; import java.util.List;
@ -17,7 +18,7 @@ public interface IXhpcRefundAuditService {
* *
* @param xhpcRefundAudit 退款审核 * @param xhpcRefundAudit 退款审核
*/ */
public int insert(XhpcRefundAudit xhpcRefundAudit); public AjaxResult insert(XhpcRefundAudit xhpcRefundAudit);
/** /**
* 退款审核列表 * 退款审核列表

View File

@ -1,5 +1,6 @@
package com.xhpc.payment.service; package com.xhpc.payment.service;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.payment.domain.XhpcRefundOrder; import com.xhpc.payment.domain.XhpcRefundOrder;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -48,7 +49,7 @@ public interface IXhpcRefundOrderService {
* @param type 退款渠道1微信 2支付宝 * @param type 退款渠道1微信 2支付宝
* @return * @return
*/ */
public XhpcRefundOrder addRefundOrder(String appUserId, BigDecimal amount, String type, String refundOrderNumber, String openid); public AjaxResult addRefundOrder(String appUserId, BigDecimal amount, String type, String refundOrderNumber, String openid);
/** /**
* 修改订单状态 退款订单 * 修改订单状态 退款订单

View File

@ -27,4 +27,11 @@ public interface IXhpcUserAccountStatementService {
*/ */
public List<Map<String, Object>> page(Long appUserId); public List<Map<String, Object>> page(Long appUserId);
/**
* 用户流水列表
*
* @param appUserId C端用户id
* @return
*/
public List<Map<String, Object>> list(Long appUserId);
} }

View File

@ -1,7 +1,9 @@
package com.xhpc.payment.service.impl; package com.xhpc.payment.service.impl;
import com.xhpc.common.core.constant.HttpStatus;
import com.xhpc.common.core.constant.StatusConstants; import com.xhpc.common.core.constant.StatusConstants;
import com.xhpc.common.core.utils.StringUtils; import com.xhpc.common.core.utils.StringUtils;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.payment.domain.XhpcRefundAudit; import com.xhpc.payment.domain.XhpcRefundAudit;
import com.xhpc.payment.domain.XhpcRefundOrder; import com.xhpc.payment.domain.XhpcRefundOrder;
import com.xhpc.payment.mapper.XhpcRefundAuditMapper; import com.xhpc.payment.mapper.XhpcRefundAuditMapper;
@ -36,18 +38,22 @@ public class XhpcRefundAuditServiceImpl implements IXhpcRefundAuditService {
* @param xhpcRefundAudit 退款审核 * @param xhpcRefundAudit 退款审核
*/ */
@Override @Override
public int insert(XhpcRefundAudit xhpcRefundAudit) { public AjaxResult insert(XhpcRefundAudit xhpcRefundAudit) {
XhpcRefundOrder xhpcRefundOrder = new XhpcRefundOrder(); XhpcRefundOrder xhpcRefundOrder = new XhpcRefundOrder();
xhpcRefundOrder.setRefundOrderId(xhpcRefundAudit.getRefundOrderId()); xhpcRefundOrder.setRefundOrderId(xhpcRefundAudit.getRefundOrderId());
xhpcRefundOrder.setExamineStatus(xhpcRefundAudit.getStatus()); xhpcRefundOrder.setExamineStatus(xhpcRefundAudit.getStatus());
xhpcRefundOrderMapper.update(xhpcRefundOrder); xhpcRefundOrderMapper.update(xhpcRefundOrder);
if (StatusConstants.REFUND_ORDER_STATUS_SUCCESS == xhpcRefundOrder.getStatus()) { if (StatusConstants.REFUND_ORDER_STATUS_SUCCESS == xhpcRefundAudit.getStatus()) {
Map<String, Object> map = xhpcRefundOrderMapper.info(xhpcRefundOrder.getRefundOrderId()); Map<String, Object> map = xhpcRefundOrderMapper.info(xhpcRefundOrder.getRefundOrderId());
if (null == map) {
AjaxResult.error(HttpStatus.DATA_ERROR, "退款订单不存在");
}
String amount = "-" + StringUtils.valueOf(map.get("amount")); String amount = "-" + StringUtils.valueOf(map.get("amount"));
String userId = StringUtils.valueOf(map.get("userId")); String userId = StringUtils.valueOf(map.get("userId"));
xhpcUserAccountStatementService.add(xhpcRefundAudit.getRefundOrderId(), amount, userId, StatusConstants.FLOWING_WATER_REFUND); xhpcUserAccountStatementService.add(xhpcRefundAudit.getRefundOrderId(), amount, userId, StatusConstants.FLOWING_WATER_REFUND);
} }
return xhpcRefundAuditMapper.insert(xhpcRefundAudit); xhpcRefundAuditMapper.insert(xhpcRefundAudit);
return AjaxResult.success();
} }
/** /**

View File

@ -1,6 +1,8 @@
package com.xhpc.payment.service.impl; package com.xhpc.payment.service.impl;
import com.xhpc.common.core.constant.HttpStatus;
import com.xhpc.common.core.constant.StatusConstants; import com.xhpc.common.core.constant.StatusConstants;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.payment.domain.XhpcRefundOrder; import com.xhpc.payment.domain.XhpcRefundOrder;
import com.xhpc.payment.mapper.XhpcRefundOrderMapper; import com.xhpc.payment.mapper.XhpcRefundOrderMapper;
import com.xhpc.payment.service.IXhpcRefundOrderService; import com.xhpc.payment.service.IXhpcRefundOrderService;
@ -67,7 +69,12 @@ public class XhpcRefundOrderServiceImpl implements IXhpcRefundOrderService {
* @return * @return
*/ */
@Override @Override
public XhpcRefundOrder addRefundOrder(String appUserId, BigDecimal amount, String type, String refundOrderNumber, String openid) { public AjaxResult addRefundOrder(String appUserId, BigDecimal amount, String type, String refundOrderNumber, String openid) {
List<Map<String, Object>> list = xhpcRefundOrderMapper.getNotChargeOrder(Long.parseLong(appUserId));
if (null != list && list.size() > 0) {
return AjaxResult.error(HttpStatus.ERROR_STATUS, "还有未完成的订单,不能退款");
}
XhpcRefundOrder xhpcRefundOrder = new XhpcRefundOrder(); XhpcRefundOrder xhpcRefundOrder = new XhpcRefundOrder();
xhpcRefundOrder.setUserId(Long.parseLong(appUserId)); xhpcRefundOrder.setUserId(Long.parseLong(appUserId));
xhpcRefundOrder.setAmount(amount); xhpcRefundOrder.setAmount(amount);
@ -79,7 +86,7 @@ public class XhpcRefundOrderServiceImpl implements IXhpcRefundOrderService {
xhpcRefundOrder.setAlipayId(openid); xhpcRefundOrder.setAlipayId(openid);
} }
xhpcRefundOrderMapper.insert(xhpcRefundOrder); xhpcRefundOrderMapper.insert(xhpcRefundOrder);
return xhpcRefundOrder; return AjaxResult.success();
} }
/** /**

View File

@ -71,4 +71,15 @@ public class XhpcUserAccountStatementServiceImpl implements IXhpcUserAccountStat
} }
xhpcUserAccountStatementMapper.insert(xhpcUserAccountStatement); xhpcUserAccountStatementMapper.insert(xhpcUserAccountStatement);
} }
/**
* 用户流水列表
*
* @param appUserId C端用户id
* @return
*/
@Override
public List<Map<String, Object>> list(Long appUserId) {
return xhpcUserAccountStatementMapper.list(appUserId);
}
} }

View File

@ -179,4 +179,13 @@
ORDER BY xro.create_time DESC ORDER BY xro.create_time DESC
</select> </select>
<select id="getNotChargeOrder" parameterType="java.lang.Long" resultType="java.util.Map">
select xco.*
from xhpc_charge_order xco
where xco.del_flag = 0 and xco.status IN (0,2)
<if test="userId != null and userId != ''">
and xco.user_id = #{userId}
</if>
ORDER BY xco.create_time DESC
</select>
</mapper> </mapper>

View File

@ -148,4 +148,18 @@
</set> </set>
WHERE app_user_id = #{appUserId} WHERE app_user_id = #{appUserId}
</update> </update>
<select id="list" parameterType="java.lang.Long" resultType="java.util.Map">
select xuas.user_account_statement_id userAccountStatementId,xuas.user_id appUserId,xau.phone ,
xuas.amount amount,xuas.remaining_sum remainingSum,xuas.create_time createTime,
xuas.type, sdd.dict_label typeName
from xhpc_user_account_statement xuas
LEFT JOIN xhpc_app_user xau on xau.app_user_id = xuas.user_id
LEFT JOIN sys_dict_data sdd on sdd.`dict_type` = 'account_statement_type' and sdd.dict_value = xuas.type
WHERE xuas.del_flag = 0
<if test="appUserId != null and appUserId != ''">
and xau.app_user_id = #{appUserId}
</if>
ORDER BY xuas.create_time DESC
</select>
</mapper> </mapper>

View File

@ -74,8 +74,12 @@ public class XhpcAppUserController extends BaseController {
@ApiOperation("禁用/启用C端用户") @ApiOperation("禁用/启用C端用户")
//@PreAuthorize(hasPermi = "app:user:status") //@PreAuthorize(hasPermi = "app:user:status")
@PostMapping("/status") @PostMapping("/status")
public AjaxResult status(@RequestParam Long appUserId) { public AjaxResult status(@RequestBody Map<String, Object> map) {
iXhpcAppUserUserService.status(appUserId); String appUserId = StringUtils.valueOf(map.get("appUserId"));
if (StringUtils.isEmpty(appUserId)) {
return AjaxResult.error(HttpStatus.NOT_NULL, "C端用户信息不能为空");
}
iXhpcAppUserUserService.status(Long.parseLong(appUserId));
return AjaxResult.success(); return AjaxResult.success();
} }

View File

@ -96,7 +96,7 @@ public class XhpcUserController extends BaseController {
@ApiOperation("平台用户详情") @ApiOperation("平台用户详情")
//@PreAuthorize(hasPermi = "user:pc:info") //@PreAuthorize(hasPermi = "user:pc:info")
@GetMapping("/pc/info") @GetMapping("/pc/info")
public AjaxResult pcInfo(@RequestBody Long userId) { public AjaxResult pcInfo(@RequestParam Long userId) {
return AjaxResult.success(iXhpcUserService.pcInfo(userId)); return AjaxResult.success(iXhpcUserService.pcInfo(userId));
} }

View File

@ -167,15 +167,18 @@
</select> </select>
<select id="selectAppUserList" parameterType="java.lang.Long" resultType="java.util.Map"> <select id="selectAppUserList" parameterType="java.lang.Long" resultType="java.util.Map">
select app_user_id appUserId, phone, balance, select xau.app_user_id appUserId, xau.phone, xau.balance,
`status`,create_time createTime, xau.`status`,xau.create_time createTime,
CASE WHEN `status` = 0 THEN '正常' else '禁用' end statusName CASE WHEN xau.`status` = 0 THEN '正常' else '禁用' end statusName,
from xhpc_app_user CASE WHEN a.count > 0 THEN '老用户' else '新用户' end newUser
WHERE del_flag = 0 from xhpc_app_user xau
LEFT JOIN (select count(1) count ,user_id from xhpc_charge_order where del_flag = 0 ) a on a.user_id =
xau.app_user_id
WHERE xau.del_flag = 0
<if test="phone != null and phone != ''"> <if test="phone != null and phone != ''">
and phone like concat(concat('%', #{phone}), '%') and xau.phone like concat(concat('%', #{phone}), '%')
</if> </if>
ORDER BY create_time DESC ORDER BY xau.create_time DESC
</select> </select>
<select id="getAppUserByPhone" parameterType="java.lang.String" resultMap="XhpcAppUserResult"> <select id="getAppUserByPhone" parameterType="java.lang.String" resultMap="XhpcAppUserResult">