feat(pay): 金币充值
parent
be124c92fa
commit
c78b731816
|
@ -136,6 +136,15 @@ public class AliPayController extends BaseController {
|
||||||
} else if ("points".equalsIgnoreCase(type)) {
|
} else if ("points".equalsIgnoreCase(type)) {
|
||||||
payVo = aliPayService.pointsPay(orderTradeDto.getAmount());
|
payVo = aliPayService.pointsPay(orderTradeDto.getAmount());
|
||||||
// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
|
// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
|
||||||
|
} else if ("wallet".equalsIgnoreCase(type)) {
|
||||||
|
// 充值金额只能是整数
|
||||||
|
if (orderTradeDto.getAmount() % 1 != 0) {
|
||||||
|
return AjaxResult.error("充值金额只能是整数");
|
||||||
|
}
|
||||||
|
payVo = aliPayService.walletPay(orderTradeDto.getAmount());
|
||||||
|
// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
|
||||||
|
} else {
|
||||||
|
return AjaxResult.error("订单类型错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
return AjaxResult.success(payVo);
|
return AjaxResult.success(payVo);
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class OrderTradeDto {
|
||||||
/**
|
/**
|
||||||
* 商品ID
|
* 商品ID
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "商品ID 如果订单类型是points,可以不传")
|
@ApiModelProperty(value = "商品ID 如果订单类型是points 或者 wallet,可以不传")
|
||||||
private Integer productId;
|
private Integer productId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,7 +27,7 @@ public class OrderTradeDto {
|
||||||
/**
|
/**
|
||||||
* 订单类型 会员member 积分points
|
* 订单类型 会员member 积分points
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "订单类型 会员member 积分points", required = true)
|
@ApiModelProperty(value = "订单类型 会员member 积分points 金币 wallet", required = true)
|
||||||
@NotBlank(message = "订单类型不能为空")
|
@NotBlank(message = "订单类型不能为空")
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ import com.mcwl.common.core.domain.AjaxResult;
|
||||||
import com.mcwl.pay.domain.OrderTradeDto;
|
import com.mcwl.pay.domain.OrderTradeDto;
|
||||||
import com.mcwl.pay.domain.vo.PayVo;
|
import com.mcwl.pay.domain.vo.PayVo;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
public interface AliPayService {
|
public interface AliPayService {
|
||||||
String bindingCallback(String authCode, String state);
|
String bindingCallback(String authCode, String state);
|
||||||
|
|
||||||
|
@ -18,4 +20,6 @@ public interface AliPayService {
|
||||||
AjaxResult queryTradeStatus(String outTradeNo) throws Exception;
|
AjaxResult queryTradeStatus(String outTradeNo) throws Exception;
|
||||||
|
|
||||||
String balance() throws AlipayApiException;
|
String balance() throws AlipayApiException;
|
||||||
|
|
||||||
|
PayVo walletPay(Double amount) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ public class AliPayServiceImpl implements AliPayService {
|
||||||
/**
|
/**
|
||||||
* 调用支付宝预下订单接口
|
* 调用支付宝预下订单接口
|
||||||
*
|
*
|
||||||
* @param paymentAmount 充值金额
|
* @param paymentAmount 充值积分
|
||||||
* @return 二维码url
|
* @return 二维码url
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
@ -232,6 +232,44 @@ public class AliPayServiceImpl implements AliPayService {
|
||||||
return payVo;
|
return payVo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用支付宝预下订单接口
|
||||||
|
*
|
||||||
|
* @param paymentAmount 充值金币
|
||||||
|
* @return 二维码url
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PayVo walletPay(Double paymentAmount) throws Exception {
|
||||||
|
// 设置orderTrade信息
|
||||||
|
OrderTrade tradeEntity = new OrderTrade();
|
||||||
|
tradeEntity.setCode(UUID.randomUUID().toString(true).substring(0, 30) + "_wallet");
|
||||||
|
tradeEntity.setUserId(SecurityUtils.getUserId());
|
||||||
|
tradeEntity.setProductId(-1);
|
||||||
|
tradeEntity.setProductName("金币充值");
|
||||||
|
tradeEntity.setUserName(SecurityUtils.getUsername());
|
||||||
|
tradeEntity.setTotalAmount(paymentAmount);
|
||||||
|
tradeEntity.setOrderStatus(1);
|
||||||
|
tradeEntity.setPayStatus(1);
|
||||||
|
orderTradeService.save(tradeEntity);
|
||||||
|
//调用支付宝的接口
|
||||||
|
AlipayTradePrecreateResponse payResponse = Factory.Payment.FaceToFace()
|
||||||
|
.preCreate(tradeEntity.getProductName(),
|
||||||
|
tradeEntity.getCode(),
|
||||||
|
paymentAmount.toString());
|
||||||
|
//参照官方文档响应示例,解析返回结果
|
||||||
|
String httpBodyStr = payResponse.getHttpBody();
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(httpBodyStr);
|
||||||
|
|
||||||
|
String url = jsonObject.getJSONObject("alipay_trade_precreate_response").get("qr_code").toString();
|
||||||
|
PayVo payVo = new PayVo();
|
||||||
|
payVo.setOrderNo(tradeEntity.getCode());
|
||||||
|
payVo.setUrl(url);
|
||||||
|
|
||||||
|
return payVo;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付宝转账方法
|
* 支付宝转账方法
|
||||||
*
|
*
|
||||||
|
|
|
@ -125,14 +125,20 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void orderHandler(OrderTrade orderTrade, String suffix, Map<String, String> params) {
|
public void orderHandler(OrderTrade orderTrade, String suffix, Map<String, String> params) {
|
||||||
this.orderHandler(orderTrade, params);
|
|
||||||
|
// 根据订单类型进行处理
|
||||||
if (OrderTypeEnum.POINTS.getName().equals(suffix)) {
|
if (OrderTypeEnum.POINTS.getName().equals(suffix)) {
|
||||||
pointsHandler(orderTrade, params);
|
pointsHandler(orderTrade, params);
|
||||||
} else if (OrderTypeEnum.MEMBER.getName().equals(suffix)) {
|
} else if (OrderTypeEnum.MEMBER.getName().equals(suffix)) {
|
||||||
Long promotionId = redisCache.getCacheObject(params.get("out_trade_no") + "promotionId");
|
Long promotionId = redisCache.getCacheObject(params.get("out_trade_no") + "promotionId");
|
||||||
memberHandler(orderTrade, promotionId);
|
memberHandler(orderTrade, promotionId);
|
||||||
|
} else if (OrderTypeEnum.WALLET.getName().equals(suffix)) {
|
||||||
|
walletHandler(orderTrade, params);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("订单类型错误");
|
||||||
}
|
}
|
||||||
|
// 处理订单
|
||||||
|
this.orderHandler(orderTrade, params);
|
||||||
// 删除redis缓存
|
// 删除redis缓存
|
||||||
redisCache.deleteObject(orderTrade.getCode());
|
redisCache.deleteObject(orderTrade.getCode());
|
||||||
redisCache.deleteObject(params.get("out_trade_no") + "promotionId");
|
redisCache.deleteObject(params.get("out_trade_no") + "promotionId");
|
||||||
|
@ -161,6 +167,37 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
|
||||||
rechargeRecordService.save(rechargeRecord);
|
rechargeRecordService.save(rechargeRecord);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void walletHandler(OrderTrade orderTrade, Map<String, String> params) {
|
||||||
|
|
||||||
|
// 获取支付金额
|
||||||
|
String amount = params.get("buyer_pay_amount");
|
||||||
|
|
||||||
|
BigDecimal amountBigDecimal = new BigDecimal(amount);
|
||||||
|
|
||||||
|
Long userId = orderTrade.getUserId();
|
||||||
|
SysUser user = sysUserService.selectUserById(userId);
|
||||||
|
|
||||||
|
BigDecimal wallet = new BigDecimal(user.getWallet().toString());
|
||||||
|
|
||||||
|
BigDecimal walletDecimal = wallet.add(amountBigDecimal);
|
||||||
|
|
||||||
|
user.setFreePoints(walletDecimal.doubleValue());
|
||||||
|
sysUserService.updateUser(user);
|
||||||
|
|
||||||
|
// 添加充值记录
|
||||||
|
// RechargeRecord rechargeRecord = new RechargeRecord();
|
||||||
|
// rechargeRecord.setUserId(userId);
|
||||||
|
// rechargeRecord.setCode(orderTrade.getCode());
|
||||||
|
// rechargeRecord.setAmount(Double.parseDouble(amount));
|
||||||
|
// rechargeRecord.setPoints(points);
|
||||||
|
// rechargeRecord.setCreateBy(user.getUserName());
|
||||||
|
// rechargeRecord.setUpdateBy(user.getUserName());
|
||||||
|
// rechargeRecord.setUpdateTime(new Date());
|
||||||
|
// rechargeRecordService.save(rechargeRecord);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void memberHandler(OrderTrade orderTrade, Long promotionId) {
|
private void memberHandler(OrderTrade orderTrade, Long promotionId) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ public enum OrderTypeEnum {
|
||||||
TIME("time"),
|
TIME("time"),
|
||||||
NUM("num"),
|
NUM("num"),
|
||||||
POINTS("points"),
|
POINTS("points"),
|
||||||
|
WALLET("wallet"),
|
||||||
MEMBER("member");
|
MEMBER("member");
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
Loading…
Reference in New Issue