refactor(payment): 调整支付宝支付和订单状态
parent
63f14ce3d1
commit
103a6e7db7
|
@ -85,9 +85,14 @@ public class MemberController {
|
|||
public AjaxResult getPoints() {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
|
||||
SysUser sysUser = sysUserService.selectUserById(userId);
|
||||
|
||||
Member member = memberService.getUseUserMemberByUserId(userId);
|
||||
if (!Optional.ofNullable(member).isPresent()) {
|
||||
return AjaxResult.warn("用户未开通会员");
|
||||
|
||||
double points = sysUser.getFreePoints();
|
||||
|
||||
if (Objects.nonNull(member)) {
|
||||
points = points + member.getPoints();
|
||||
}
|
||||
|
||||
PointsVO pointsVO = new PointsVO();
|
||||
|
@ -98,7 +103,7 @@ public class MemberController {
|
|||
.eq(MemberConsume::getUserId, userId)
|
||||
.list();
|
||||
|
||||
pointsVO.setPoints(member.getPoints());
|
||||
pointsVO.setPoints(points);
|
||||
pointsVO.setMemberConsumeList(memberConsumeList);
|
||||
|
||||
return AjaxResult.success(pointsVO);
|
||||
|
|
|
@ -152,7 +152,7 @@ public class AliPayController extends BaseController {
|
|||
@NotNull(message = "提现金额不能为空")
|
||||
Double amount) throws Exception {
|
||||
if (amount < 0.1) {
|
||||
return AjaxResult.error("提现金额最小为0.01");
|
||||
return AjaxResult.error("提现金额最小为0.1");
|
||||
}
|
||||
String outBizNo = UUID.fastUUID().toString(true);
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ import com.mcwl.system.service.ISysUserPayAccountService;
|
|||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -86,6 +87,9 @@ public class AliPayServiceImpl implements AliPayService {
|
|||
@Autowired
|
||||
private OrderTradeService orderTradeService;
|
||||
|
||||
@Autowired
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
private final int MAX_RETRY = 3; // 最大重试次数
|
||||
|
||||
|
||||
|
@ -359,27 +363,13 @@ public class AliPayServiceImpl implements AliPayService {
|
|||
long time = (System.currentTimeMillis() - orderTrade.getCreateTime().getTime()) / 1000 / 60;
|
||||
// time 超过15分钟,则删除redis中订单信息
|
||||
if (time >= 1) {
|
||||
for (int i = 0; i < MAX_RETRY; i++) {
|
||||
// 撤销交易
|
||||
AlipayTradeCancelResponse cancel = Factory.Payment.Common().cancel(outTradeNo);
|
||||
if (cancel.getMsg().equals("Success")) {
|
||||
orderTrade.setOrderStatus(4);
|
||||
orderTradeService.updateById(orderTrade);
|
||||
redisCache.deleteObject(outTradeNo + "promotionId");
|
||||
break;
|
||||
} else {
|
||||
// 检查是否需要继续重试
|
||||
if (!"Y".equals(cancel.getRetryFlag())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Thread.sleep(2000); // 间隔2秒重试
|
||||
}
|
||||
|
||||
this.cancelTrade(orderTrade);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
redisCache.setCacheObject(outTradeNo, JSONUtil.toJsonStr(orderTrade), 10, TimeUnit.SECONDS);
|
||||
redisCache.setCacheObject(outTradeNo, JSONUtil.toJsonStr(orderTrade), 4, TimeUnit.SECONDS);
|
||||
return AjaxResult.success("查询成功", orderTrade.getOrderStatus());
|
||||
}
|
||||
|
||||
|
@ -454,6 +444,34 @@ public class AliPayServiceImpl implements AliPayService {
|
|||
|
||||
}
|
||||
|
||||
|
||||
private void cancelTrade(OrderTrade orderTrade) throws Exception {
|
||||
|
||||
threadPoolTaskExecutor.execute(() -> {
|
||||
try {
|
||||
for (int i = 0; i < MAX_RETRY; i++) {
|
||||
// 撤销交易
|
||||
AlipayTradeCancelResponse cancel = Factory.Payment.Common().cancel(orderTrade.getCode());
|
||||
if (cancel.getMsg().equals("Success")) {
|
||||
orderTrade.setOrderStatus(4);
|
||||
orderTradeService.updateById(orderTrade);
|
||||
redisCache.deleteObject(orderTrade.getCode() + "promotionId");
|
||||
break;
|
||||
} else {
|
||||
// 检查是否需要继续重试
|
||||
if (!"Y".equals(cancel.getRetryFlag())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Thread.sleep(2000); // 间隔2秒重试
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private Object getTradStatus(String outTradeNo) throws Exception {
|
||||
Factory.setOptions(config);
|
||||
AlipayTradeQueryResponse query = Factory.Payment.Common().query(outTradeNo);
|
||||
|
|
|
@ -217,7 +217,7 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
|
|||
orderTrade.setPaymentMethod(params.get("trade_no"));
|
||||
orderTrade.setTransactionId(1);
|
||||
orderTrade.setOrderTime(DateUtils.parseDate(params.get("gmt_payment")));
|
||||
orderTrade.setOrderStatus(3);
|
||||
orderTrade.setOrderStatus(2);
|
||||
orderTrade.setPayStatus(2);
|
||||
String totalAmountStr = params.get("total_amount");
|
||||
if (totalAmountStr != null && !totalAmountStr.isEmpty()) {
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -235,10 +236,7 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
|
|||
List<String> tagList = new ArrayList<>();
|
||||
if (StringUtils.isNotEmpty(modelImage.getTags())) {
|
||||
String[] tagValueList = modelImage.getTags().split(",");
|
||||
for (String tagValue : tagValueList) {
|
||||
String dictLabel = DictInit.getDictValue(DictConstants.IMAGE_LABEL, tagValue);
|
||||
tagList.add(dictLabel);
|
||||
}
|
||||
tagList.addAll(Arrays.asList(tagValueList));
|
||||
}
|
||||
modelImageVo.setTags(tagList);
|
||||
|
||||
|
|
Loading…
Reference in New Issue