refactor: 调整支付宝支付流程和会员相关功能
parent
f4e4ef40c1
commit
13d4e21691
|
@ -21,9 +21,7 @@ import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("member")
|
@RequestMapping("member")
|
||||||
|
@ -181,11 +179,17 @@ public class MemberController {
|
||||||
@ApiOperation(value = "是否是会员")
|
@ApiOperation(value = "是否是会员")
|
||||||
public AjaxResult isMember() {
|
public AjaxResult isMember() {
|
||||||
Long userId = SecurityUtils.getUserId();
|
Long userId = SecurityUtils.getUserId();
|
||||||
|
Map<String, Long> map = new HashMap<>();
|
||||||
Member member = memberService.getUseUserMemberByUserId(userId);
|
Member member = memberService.getUseUserMemberByUserId(userId);
|
||||||
if (Optional.ofNullable(member).isPresent()) {
|
if (Optional.ofNullable(member).isPresent()) {
|
||||||
return AjaxResult.success(true);
|
map.put("result", 1L);
|
||||||
|
return AjaxResult.success(map);
|
||||||
}
|
}
|
||||||
return AjaxResult.success(false);
|
map.put("result", 0L);
|
||||||
|
map.put("startDate", member.getStartDate().getTime());
|
||||||
|
map.put("endDate", member.getEndDate().getTime());
|
||||||
|
|
||||||
|
return AjaxResult.success(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import javax.validation.constraints.NotNull;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:ChenYan
|
* @Author:ChenYan
|
||||||
|
@ -68,7 +69,7 @@ public class AliPayController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@ApiOperation(value = "支付宝绑定")
|
@ApiOperation(value = "支付宝绑定")
|
||||||
@GetMapping("/generateQrCode")
|
@GetMapping("/generateQrCode")
|
||||||
public void generateQrCode(HttpServletResponse response) throws Exception {
|
public AjaxResult generateQrCode(HttpServletResponse response) throws Exception {
|
||||||
String scope = "auth_user"; // 需要获取用户信息
|
String scope = "auth_user"; // 需要获取用户信息
|
||||||
String appId = "2021005114616085";
|
String appId = "2021005114616085";
|
||||||
String state = ShareCodeUtils.idToCode(SecurityUtils.getUserId()); // 防止CSRF攻击
|
String state = ShareCodeUtils.idToCode(SecurityUtils.getUserId()); // 防止CSRF攻击
|
||||||
|
@ -80,6 +81,7 @@ public class AliPayController extends BaseController {
|
||||||
);
|
);
|
||||||
|
|
||||||
QrCodeUtil.generate(authUrl, 300, 300, "png", response.getOutputStream());
|
QrCodeUtil.generate(authUrl, 300, 300, "png", response.getOutputStream());
|
||||||
|
return AjaxResult.success("成功", authUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,6 +132,9 @@ public class AliPayController extends BaseController {
|
||||||
String type = orderTradeDto.getType();
|
String type = orderTradeDto.getType();
|
||||||
|
|
||||||
if ("member".equalsIgnoreCase(type)) {
|
if ("member".equalsIgnoreCase(type)) {
|
||||||
|
if (!Optional.ofNullable(orderTradeDto.getProductId()).isPresent()) {
|
||||||
|
return AjaxResult.error("商品id不能为空");
|
||||||
|
}
|
||||||
payVo = aliPayService.memberPay(orderTradeDto);
|
payVo = aliPayService.memberPay(orderTradeDto);
|
||||||
} else if ("points".equalsIgnoreCase(type)) {
|
} else if ("points".equalsIgnoreCase(type)) {
|
||||||
payVo = aliPayService.pointsPay(orderTradeDto.getPaymentAmount());
|
payVo = aliPayService.pointsPay(orderTradeDto.getPaymentAmount());
|
||||||
|
|
|
@ -121,7 +121,7 @@ public class OrderTradeController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@GetMapping("/queryTradeStatus")
|
@GetMapping("/queryTradeStatus")
|
||||||
@ApiOperation(value = "查询交易状态")
|
@ApiOperation(value = "查询交易状态")
|
||||||
public Object queryTradeStatus(@Valid @NotBlank(message = "订单号不能为空") @RequestParam String outTradeNo) throws Exception {
|
public Object queryTradeStatus(@Valid @NotBlank(message = "订单号不能为空") String outTradeNo) throws Exception {
|
||||||
Factory.setOptions(config);
|
Factory.setOptions(config);
|
||||||
AlipayTradeQueryResponse query = Factory.Payment.Common().query(outTradeNo);
|
AlipayTradeQueryResponse query = Factory.Payment.Common().query(outTradeNo);
|
||||||
Map<String, Object> map = JSONUtils.jsonToMap(query.getHttpBody());
|
Map<String, Object> map = JSONUtils.jsonToMap(query.getHttpBody());
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class OrderTrade extends BaseEntity {
|
||||||
@NotNull(message = "总金额不能为空")
|
@NotNull(message = "总金额不能为空")
|
||||||
@MinMoney(value = 0, message = "总金额不能小于0")
|
@MinMoney(value = 0, message = "总金额不能小于0")
|
||||||
@MaxMoney(value = 100000, message = "总金额必须小于100000")
|
@MaxMoney(value = 100000, message = "总金额必须小于100000")
|
||||||
private Integer totalAmount;
|
private Double totalAmount;
|
||||||
/**
|
/**
|
||||||
* 付款金额
|
* 付款金额
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -13,8 +14,7 @@ public class OrderTradeDto {
|
||||||
/**
|
/**
|
||||||
* 商品ID
|
* 商品ID
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "商品ID", required = true)
|
@ApiModelProperty(value = "商品ID 如果订单类型是points,可以不传")
|
||||||
@NotNull(message = "商品ID不能为空")
|
|
||||||
private Integer productId;
|
private Integer productId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,7 +28,7 @@ public class OrderTradeDto {
|
||||||
* 订单类型 会员member 积分points
|
* 订单类型 会员member 积分points
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "订单类型 会员member 积分points", required = true)
|
@ApiModelProperty(value = "订单类型 会员member 积分points", required = true)
|
||||||
@NotNull(message = "订单类型不能为空")
|
@NotBlank(message = "订单类型不能为空")
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -48,6 +48,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -158,8 +159,11 @@ public class AliPayServiceImpl implements AliPayService {
|
||||||
tradeEntity.setCode(UUID.randomUUID().toString(true).substring(0, 30));
|
tradeEntity.setCode(UUID.randomUUID().toString(true).substring(0, 30));
|
||||||
tradeEntity.setUserId(SecurityUtils.getUserId());
|
tradeEntity.setUserId(SecurityUtils.getUserId());
|
||||||
tradeEntity.setUserName(SecurityUtils.getUsername());
|
tradeEntity.setUserName(SecurityUtils.getUsername());
|
||||||
|
tradeEntity.setProductId(productId);
|
||||||
tradeEntity.setProductName(memberLevel.getMemberName());
|
tradeEntity.setProductName(memberLevel.getMemberName());
|
||||||
|
tradeEntity.setTotalAmount(orderTradeDto.getPaymentAmount());
|
||||||
|
tradeEntity.setOrderStatus(3);
|
||||||
|
tradeEntity.setPayStatus(2);
|
||||||
orderTradeService.save(tradeEntity);
|
orderTradeService.save(tradeEntity);
|
||||||
|
|
||||||
//调用支付宝的接口
|
//调用支付宝的接口
|
||||||
|
@ -199,7 +203,9 @@ public class AliPayServiceImpl implements AliPayService {
|
||||||
tradeEntity.setProductId(-1);
|
tradeEntity.setProductId(-1);
|
||||||
tradeEntity.setProductName("积分充值");
|
tradeEntity.setProductName("积分充值");
|
||||||
tradeEntity.setUserName(SecurityUtils.getUsername());
|
tradeEntity.setUserName(SecurityUtils.getUsername());
|
||||||
tradeEntity.setPaymentAmount(paymentAmount.intValue());
|
tradeEntity.setTotalAmount(paymentAmount);
|
||||||
|
tradeEntity.setOrderStatus(1);
|
||||||
|
tradeEntity.setPayStatus(1);
|
||||||
|
|
||||||
//调用支付宝的接口
|
//调用支付宝的接口
|
||||||
AlipayTradePrecreateResponse payResponse = Factory.Payment.FaceToFace()
|
AlipayTradePrecreateResponse payResponse = Factory.Payment.FaceToFace()
|
||||||
|
|
|
@ -218,14 +218,14 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
|
||||||
String totalAmountStr = params.get("total_amount");
|
String totalAmountStr = params.get("total_amount");
|
||||||
if (totalAmountStr != null && !totalAmountStr.isEmpty()) {
|
if (totalAmountStr != null && !totalAmountStr.isEmpty()) {
|
||||||
BigDecimal totalAmount = new BigDecimal(totalAmountStr);
|
BigDecimal totalAmount = new BigDecimal(totalAmountStr);
|
||||||
orderTrade.setTotalAmount(totalAmount.intValue());
|
orderTrade.setTotalAmount(totalAmount.doubleValue());
|
||||||
}
|
}
|
||||||
String buyerPayAmountStr = params.get("buyer_pay_amount");
|
String buyerPayAmountStr = params.get("buyer_pay_amount");
|
||||||
if (buyerPayAmountStr != null && !buyerPayAmountStr.isEmpty()) {
|
if (buyerPayAmountStr != null && !buyerPayAmountStr.isEmpty()) {
|
||||||
BigDecimal buyerPayAmount = new BigDecimal(buyerPayAmountStr);
|
BigDecimal buyerPayAmount = new BigDecimal(buyerPayAmountStr);
|
||||||
orderTrade.setPaymentAmount(buyerPayAmount.intValue());
|
orderTrade.setPaymentAmount(buyerPayAmount.intValue());
|
||||||
}
|
}
|
||||||
orderTrade.setCreateTime(new Date());
|
orderTrade.setUpdateTime(new Date());
|
||||||
orderTradeService.save(orderTrade);
|
orderTradeService.updateById(orderTrade);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue