修改充值退款接口

This commit is contained in:
yuyang 2021-08-20 16:46:46 +08:00
parent 73d0e67213
commit aeacac3ea6
5 changed files with 23 additions and 8 deletions

View File

@ -435,7 +435,6 @@ public class HxpcPileOrderController extends BaseController {
} }
} }
xhpcHistoryOrder.setChargeOrderId(hxpcChargeOrder.getChargeOrderId()); xhpcHistoryOrder.setChargeOrderId(hxpcChargeOrder.getChargeOrderId());
xhpcHistoryOrder.setChargingStationId(hxpcChargeOrder.getChargingStationId()); xhpcHistoryOrder.setChargingStationId(hxpcChargeOrder.getChargingStationId());
xhpcHistoryOrder.setUserId(userId); xhpcHistoryOrder.setUserId(userId);

View File

@ -13,6 +13,8 @@ import com.xhpc.payment.service.IXhpcRechargeOrderService;
import com.xhpc.payment.service.IXhpcRefundOrderService; 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.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
@ -58,6 +60,7 @@ public class WxPaymentController {
@Autowired @Autowired
private Environment environment; private Environment environment;
@PostMapping("/payment") @PostMapping("/payment")
@ApiOperation(value = "微信支付") @ApiOperation(value = "微信支付")
public AjaxResult payment(HttpServletRequest servletRequest, @RequestBody Map<String, Object> map) throws Exception { public AjaxResult payment(HttpServletRequest servletRequest, @RequestBody Map<String, Object> map) throws Exception {
@ -69,6 +72,10 @@ public class WxPaymentController {
String amount = StringUtils.valueOf(map.get("amount")); String amount = StringUtils.valueOf(map.get("amount"));
if (StringUtils.isEmpty(amount)) { if (StringUtils.isEmpty(amount)) {
return AjaxResult.error(HttpStatus.NOT_NULL, "充值金额不能为空"); return AjaxResult.error(HttpStatus.NOT_NULL, "充值金额不能为空");
}else{
if(new BigDecimal(5).compareTo(new BigDecimal(amount))==1){
return AjaxResult.error(HttpStatus.NOT_NULL, "充值金额不能少于5元");
}
} }
//用户信息id //用户信息id
String userId = StringUtils.valueOf(map.get("userId")); String userId = StringUtils.valueOf(map.get("userId"));
@ -321,7 +328,7 @@ public class WxPaymentController {
*/ */
@RequestMapping("/test") @RequestMapping("/test")
public void test() { public void test() {
paymentCallback("wx20210728172854", "4200001199202107286896883790"); paymentCallback("000002020210820142215119", "4200001189202108202038629329");
} }
/** /**
@ -353,6 +360,7 @@ public class WxPaymentController {
xhpcUserAccountStatement.setUserId(xhpcRechargeOrder.getUserId()); xhpcUserAccountStatement.setUserId(xhpcRechargeOrder.getUserId());
xhpcUserAccountStatement.setAmount(xhpcRechargeOrder.getAmount()); xhpcUserAccountStatement.setAmount(xhpcRechargeOrder.getAmount());
xhpcUserAccountStatement.setRemainingSum(xhpcAppUser.getBalance()); xhpcUserAccountStatement.setRemainingSum(xhpcAppUser.getBalance());
xhpcUserAccountStatement.setCreateTime(new Date());
xhpcUserAccountStatementMapper.insert(xhpcUserAccountStatement); xhpcUserAccountStatementMapper.insert(xhpcUserAccountStatement);
} }
} }

View File

@ -78,6 +78,7 @@ public class XhpcRefundAuditController extends BaseController {
@Transactional @Transactional
public AjaxResult info(@RequestBody XhpcRefundAudit xhpcRefundAudit) { public AjaxResult info(@RequestBody XhpcRefundAudit xhpcRefundAudit) {
Map<String, Object> map = iXhpcRefundOrderService.info(xhpcRefundAudit.getRefundOrderId()); Map<String, Object> map = iXhpcRefundOrderService.info(xhpcRefundAudit.getRefundOrderId());
if (null == map) { if (null == map) {
AjaxResult.error(HttpStatus.DATA_ERROR, "退款订单不存在"); AjaxResult.error(HttpStatus.DATA_ERROR, "退款订单不存在");
} }
@ -167,6 +168,7 @@ public class XhpcRefundAuditController extends BaseController {
public Object enterpriseCheckOut(@RequestBody XhpcRefundAudit xhpcRefundAudit) { public Object enterpriseCheckOut(@RequestBody XhpcRefundAudit xhpcRefundAudit) {
//只有审核通过才能退款 //只有审核通过才能退款
Map<String, Object> xhpcRefundOrder = iXhpcRefundOrderService.info(xhpcRefundAudit.getRefundOrderId()); Map<String, Object> xhpcRefundOrder = iXhpcRefundOrderService.info(xhpcRefundAudit.getRefundOrderId());
if (StringUtils.isNull(xhpcRefundOrder)) { if (StringUtils.isNull(xhpcRefundOrder)) {
return AjaxResult.error(HttpStatus.DATA_ERROR, "订单不存在"); return AjaxResult.error(HttpStatus.DATA_ERROR, "订单不存在");
} }
@ -183,7 +185,8 @@ public class XhpcRefundAuditController extends BaseController {
CloseableHttpClient httpClient = null; CloseableHttpClient httpClient = null;
try { try {
//证书的地址 //证书的地址
ConfigListener.getConf().get("certPath"); String certPath = ConfigListener.getConf().get("certPath");
System.out.println("certPath:"+certPath);
httpClient = initCert(); httpClient = initCert();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -242,9 +245,9 @@ public class XhpcRefundAuditController extends BaseController {
*/ */
private CloseableHttpClient initCert() throws Exception { private CloseableHttpClient initCert() throws Exception {
String path = "apiclient_cert.p12"; String path = "apiclient_cert.p12";
File file = new File(this.getClass().getResource("/").getPath() + path); //File file = new File(this.getClass().getResource("/").getPath() + path);
//线上地址 //线上地址
//File file = new File("/www/wwwroot/msjd.project2.tingsun.net/" + path); File file = new File("/www/wwwroot/xhpc.scxhua.com/xhpc-payment/" + path);
// 证书密码默认为商户ID // 证书密码默认为商户ID
String key = environment.getProperty("MCHID"); String key = environment.getProperty("MCHID");
// 指定读取证书格式为PKCS12 // 指定读取证书格式为PKCS12
@ -317,6 +320,7 @@ public class XhpcRefundAuditController extends BaseController {
* @return * @return
*/ */
private AjaxResult parseXml(String result, Long id, BigDecimal amount, String userId) { private AjaxResult parseXml(String result, Long id, BigDecimal amount, String userId) {
try { try {
Map<String, String> map = WXPayUtil.xmlToMap(result); Map<String, String> map = WXPayUtil.xmlToMap(result);
String result_code = map.get("result_code"); String result_code = map.get("result_code");
@ -330,7 +334,7 @@ public class XhpcRefundAuditController extends BaseController {
//减少用户余额 //减少用户余额
XhpcAppUser xhpcAppUser = new XhpcAppUser(); XhpcAppUser xhpcAppUser = new XhpcAppUser();
xhpcAppUser.setAppUserId(Long.parseLong(userId)); xhpcAppUser.setAppUserId(Long.parseLong(userId));
BigDecimal surplus = BigDecimal.valueOf(Double.valueOf(balance)).subtract(amount); BigDecimal surplus =new BigDecimal(balance).subtract(amount);
xhpcAppUser.setBalance(surplus); xhpcAppUser.setBalance(surplus);
xhpcUserAccountStatementMapper.updateAppUserBalance(xhpcAppUser); xhpcUserAccountStatementMapper.updateAppUserBalance(xhpcAppUser);
} }

View File

@ -34,7 +34,11 @@ public class XhpcRefundOrderController extends BaseController {
public AjaxResult enterpriseCheckOut(@RequestBody Map<String, Object> map) { public AjaxResult enterpriseCheckOut(@RequestBody Map<String, Object> map) {
String amount = StringUtils.valueOf(map.get("amount")); String amount = StringUtils.valueOf(map.get("amount"));
if (StringUtils.isEmpty(amount)) { if (StringUtils.isEmpty(amount)) {
return AjaxResult.error(HttpStatus.NOT_NULL, "充值金额不能为空"); return AjaxResult.error(HttpStatus.NOT_NULL, "退款金额不能为空");
}else{
if(new BigDecimal(1).compareTo(new BigDecimal(amount))==1){
return AjaxResult.error(HttpStatus.NOT_NULL, "退款金额不能少于1元");
}
} }
//用户信息id //用户信息id
String userId = StringUtils.valueOf(map.get("userId")); String userId = StringUtils.valueOf(map.get("userId"));

View File

@ -144,7 +144,7 @@
<update id="updateAppUserBalance" parameterType="com.xhpc.payment.domain.XhpcAppUser"> <update id="updateAppUserBalance" parameterType="com.xhpc.payment.domain.XhpcAppUser">
UPDATE xhpc_app_user UPDATE xhpc_app_user
<set> <set>
<if test="null != balance">balance = #{balance},</if> <if test="null != balance">balance = #{balance}</if>
</set> </set>
WHERE app_user_id = #{appUserId} WHERE app_user_id = #{appUserId}
</update> </update>