|
@@ -1,31 +1,47 @@
|
|
|
package com.cyksj.service.order.impl;
|
|
package com.cyksj.service.order.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import com.alipay.api.internal.util.AlipaySignature;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.snowflake.Sequence;
|
|
import com.cyksj.common.snowflake.Sequence;
|
|
|
|
|
+import com.cyksj.common.util.Codec;
|
|
|
|
|
+import com.cyksj.common.util.Jsons;
|
|
|
|
|
+import com.cyksj.config.zfb.BaseZfbConfig;
|
|
|
|
|
+import com.cyksj.config.zfb.ZfbProductCode;
|
|
|
import com.cyksj.enums.GatewayApiCode;
|
|
import com.cyksj.enums.GatewayApiCode;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
|
|
+import com.cyksj.mapper.channel.ShopConfigMapper;
|
|
|
import com.cyksj.mapper.sys.SysConfigMapper;
|
|
import com.cyksj.mapper.sys.SysConfigMapper;
|
|
|
import com.cyksj.mapper.vip.VipGoodsSkuMapper;
|
|
import com.cyksj.mapper.vip.VipGoodsSkuMapper;
|
|
|
import com.cyksj.mapper.vip.VipOrderDonMapper;
|
|
import com.cyksj.mapper.vip.VipOrderDonMapper;
|
|
|
|
|
+import com.cyksj.model.dto.AliPayParams;
|
|
|
import com.cyksj.model.entity.*;
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
|
|
+import com.cyksj.model.request.AlipayOrderDonReq;
|
|
|
|
|
+import com.cyksj.model.request.OrderAttach;
|
|
|
import com.cyksj.model.request.VipOrderDonPayReq;
|
|
import com.cyksj.model.request.VipOrderDonPayReq;
|
|
|
import com.cyksj.service.order.VipOrderDonService;
|
|
import com.cyksj.service.order.VipOrderDonService;
|
|
|
|
|
+import com.cyksj.service.pay.AliPayCommonService;
|
|
|
import com.cyksj.service.user.UserBenefitsService;
|
|
import com.cyksj.service.user.UserBenefitsService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
import com.ejlchina.searcher.param.Operator;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 项目名: yhlxj2
|
|
* 项目名: yhlxj2
|
|
@@ -35,6 +51,7 @@ import java.util.List;
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
|
|
|
+@Slf4j
|
|
|
public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOrderDon> implements VipOrderDonService {
|
|
public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOrderDon> implements VipOrderDonService {
|
|
|
private static final Sequence SEQUENCE = new Sequence(0);
|
|
private static final Sequence SEQUENCE = new Sequence(0);
|
|
|
|
|
|
|
@@ -50,6 +67,10 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
|
|
|
|
|
private final SysConfigMapper sysConfigMapper;
|
|
private final SysConfigMapper sysConfigMapper;
|
|
|
|
|
|
|
|
|
|
+ private final AliPayCommonService aliPayCommonService;
|
|
|
|
|
+
|
|
|
|
|
+ private final ShopConfigMapper shopConfigMapper;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public VipOrderDon submit(VipOrderDonPayReq payRequest) {
|
|
public VipOrderDon submit(VipOrderDonPayReq payRequest) {
|
|
|
Long userId = payRequest.getUserId();
|
|
Long userId = payRequest.getUserId();
|
|
@@ -75,7 +96,7 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
//扣除使用优惠券、余额的订单金额
|
|
//扣除使用优惠券、余额的订单金额
|
|
|
deductOrderMoney(orderDon, user, payRequest);
|
|
deductOrderMoney(orderDon, user, payRequest);
|
|
|
//设置订单支付商品信息
|
|
//设置订单支付商品信息
|
|
|
- orderDon.setPayTitle("银河超级AI会员");
|
|
|
|
|
|
|
+ orderDon.setPayTitle(Constant.VIP_TITLE);
|
|
|
this.saveOrUpdate(orderDon);
|
|
this.saveOrUpdate(orderDon);
|
|
|
|
|
|
|
|
Long orderId = orderDon.getId();
|
|
Long orderId = orderDon.getId();
|
|
@@ -87,6 +108,60 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
return orderDon;
|
|
return orderDon;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public AliPayParams aliPay(AlipayOrderDonReq re) throws Exception {
|
|
|
|
|
+ String productCode = StrUtil.EMPTY;
|
|
|
|
|
+ if (re.getType() == 1) {
|
|
|
|
|
+ productCode = ZfbProductCode.MOBILE_WEB.getProductCode();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (re.getType() == 2) {
|
|
|
|
|
+ productCode = ZfbProductCode.PC_WEB.getProductCode();
|
|
|
|
|
+ }
|
|
|
|
|
+ return aliPayCommonService.unifiedPayVip(re.getOrderId(), productCode, re.getPayMode(), re.getReturnUrl());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void aliPayNotify(Map<String, String> params) throws Exception {
|
|
|
|
|
+ //调用SDK验证签名
|
|
|
|
|
+ String body = Codec.DoBase64.custom().setData(params.get("body")).decodeAsText();
|
|
|
|
|
+ OrderAttach orderAttach = Jsons.parseObject(body, OrderAttach.class);
|
|
|
|
|
+ Long oderId = orderAttach.getO();
|
|
|
|
|
+ VipOrderDon orderDon = this.getById(oderId);
|
|
|
|
|
+ if (null == orderDon) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("订单不存在.");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (orderDon.getPopularizeId() == null) {
|
|
|
|
|
+ orderDon.setShopId(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ String appId = params.get("app_id");
|
|
|
|
|
+ boolean signVerified = AlipaySignature.rsaCheckV1(params, shopConfigMapper.getByAppId(appId).getPublicKey(), BaseZfbConfig.charset, BaseZfbConfig.signType);
|
|
|
|
|
+ if (!signVerified) {
|
|
|
|
|
+ log.error("支付宝回调校验签名错误,自定义入参:{}", params.get("body"));
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("支付宝回调校验签名错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ String transactionId = params.get("trade_no");
|
|
|
|
|
+ String payTimeStr = params.get("gmt_payment");
|
|
|
|
|
+ //买家支付宝账号
|
|
|
|
|
+ String buyerId = Optional.ofNullable(params.get("buyer_id")).orElse(params.get("buyer_open_id"));
|
|
|
|
|
+ log.info("支付宝回调信息:{}", Jsons.toJson(params));
|
|
|
|
|
+ if (!orderDon.getStatus().equals(OrderDon.Status.noPayment) && !orderDon.getStatus().equals(OrderDon.Status.close)) {
|
|
|
|
|
+ log.info("支付宝已回调,重复修改状态 id:{}", orderDon.getId());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Date payTime = DateTime.now();
|
|
|
|
|
+ if (StringUtils.isNotBlank(payTimeStr)) {
|
|
|
|
|
+ payTime = DateUtil.parse(payTimeStr, "yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 更改订单状态
|
|
|
|
|
+ orderDon.setTransactionId(transactionId);
|
|
|
|
|
+ orderDon.setPayTime(payTime);
|
|
|
|
|
+ orderDon.setShopId(appId);
|
|
|
|
|
+ orderDon.setType(VipOrderDon.Type.ALI_PAY);
|
|
|
|
|
+ orderDon.setBuyerId(buyerId);
|
|
|
|
|
+ //回调
|
|
|
|
|
+ unifiedHandlerOrderNotify(orderDon);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void unifiedHandlerOrderNotify(VipOrderDon orderDon) {
|
|
private void unifiedHandlerOrderNotify(VipOrderDon orderDon) {
|
|
|
orderDon.setStatus(VipOrderDon.Status.complete);
|
|
orderDon.setStatus(VipOrderDon.Status.complete);
|
|
|
this.updateById(orderDon);
|
|
this.updateById(orderDon);
|