|
@@ -3,19 +3,23 @@ package com.yonge.cooleshow.biz.dal.service.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
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.yonge.cooleshow.biz.dal.config.HuifuConfiguration;
|
|
|
|
import com.yonge.cooleshow.biz.dal.dto.req.OrderPayReq;
|
|
import com.yonge.cooleshow.biz.dal.dto.req.OrderPayReq;
|
|
import com.yonge.cooleshow.biz.dal.enums.OrderStatusEnum;
|
|
import com.yonge.cooleshow.biz.dal.enums.OrderStatusEnum;
|
|
-import com.yonge.cooleshow.biz.dal.enums.PayChannelEnum;
|
|
|
|
import com.yonge.cooleshow.biz.dal.enums.TradeStatusEnum;
|
|
import com.yonge.cooleshow.biz.dal.enums.TradeStatusEnum;
|
|
-import com.yonge.cooleshow.biz.dal.sdk.PaymentSdk;
|
|
|
|
-import com.yonge.cooleshow.biz.dal.sdk.req.DeviceInfo;
|
|
|
|
-import com.yonge.cooleshow.biz.dal.sdk.req.PaymentReq;
|
|
|
|
|
|
+import com.yonge.cooleshow.biz.dal.props.PaymentProperties;
|
|
import com.yonge.cooleshow.biz.dal.service.UserOrderService;
|
|
import com.yonge.cooleshow.biz.dal.service.UserOrderService;
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.res.OrderPayRes;
|
|
import com.yonge.cooleshow.biz.dal.vo.res.OrderPayRes;
|
|
import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
import com.yonge.cooleshow.common.service.IdGeneratorService;
|
|
import com.yonge.cooleshow.common.service.IdGeneratorService;
|
|
|
|
+import com.yonge.toolset.base.result.BaseResult;
|
|
|
|
+import com.yonge.toolset.payment.base.enums.OpenEnum;
|
|
|
|
+import com.yonge.toolset.payment.base.enums.PayChannelEnum;
|
|
|
|
+import com.yonge.toolset.payment.base.model.ClosePayment;
|
|
|
|
+import com.yonge.toolset.payment.base.model.DeviceInfo;
|
|
|
|
+import com.yonge.toolset.payment.base.model.DivMember;
|
|
|
|
+import com.yonge.toolset.payment.base.model.Payment;
|
|
|
|
+import com.yonge.toolset.payment.core.service.PaymentClient;
|
|
import com.yonge.toolset.utils.string.StringUtil;
|
|
import com.yonge.toolset.utils.string.StringUtil;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -25,10 +29,7 @@ import com.yonge.cooleshow.biz.dal.service.UserOrderPaymentService;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
-import java.util.Date;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -38,7 +39,9 @@ public class UserOrderPaymentServiceImpl extends ServiceImpl<UserOrderPaymentDao
|
|
@Autowired
|
|
@Autowired
|
|
private IdGeneratorService idGeneratorService;
|
|
private IdGeneratorService idGeneratorService;
|
|
@Autowired
|
|
@Autowired
|
|
- private PaymentSdk paymentSdk;
|
|
|
|
|
|
+ private PaymentProperties paymentProperties;
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaymentClient paymentClient;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public UserOrderPayment detailByOrderNo(String orderNo, PayChannelEnum payChannel, TradeStatusEnum status) {
|
|
public UserOrderPayment detailByOrderNo(String orderNo, PayChannelEnum payChannel, TradeStatusEnum status) {
|
|
@@ -63,33 +66,26 @@ public class UserOrderPaymentServiceImpl extends ServiceImpl<UserOrderPaymentDao
|
|
/***
|
|
/***
|
|
* 入订单付款表
|
|
* 入订单付款表
|
|
* @author liweifan
|
|
* @author liweifan
|
|
- * @param: responseResult
|
|
|
|
|
|
+ * @param: paymentRes
|
|
* @param: payReq
|
|
* @param: payReq
|
|
- * @param: paymentNo
|
|
|
|
- * @updateTime 2022/5/7 14:19
|
|
|
|
|
|
+ * @updateTime 2022/5/11 18:47
|
|
* @return: com.yonge.cooleshow.biz.dal.entity.UserOrderPayment
|
|
* @return: com.yonge.cooleshow.biz.dal.entity.UserOrderPayment
|
|
*/
|
|
*/
|
|
- private UserOrderPayment insertOrderPayment(HttpResponseResult<Map<String, Object>> responseResult, OrderPayReq payReq, Long paymentNo) {
|
|
|
|
|
|
+ private UserOrderPayment insertOrderPayment(Payment payment, OrderPayReq payReq) {
|
|
UserOrderPayment orderPayment = new UserOrderPayment();
|
|
UserOrderPayment orderPayment = new UserOrderPayment();
|
|
orderPayment.setOrderNo(payReq.getOrderNo());
|
|
orderPayment.setOrderNo(payReq.getOrderNo());
|
|
- orderPayment.setPaymentNo(paymentNo.toString());
|
|
|
|
|
|
+ orderPayment.setPaymentNo(payment.getPaymentNo());
|
|
orderPayment.setPayChannel(payReq.getPayChannel());
|
|
orderPayment.setPayChannel(payReq.getPayChannel());
|
|
- if (responseResult.getStatus()) {
|
|
|
|
- Map<String, Object> res = responseResult.getData();
|
|
|
|
- orderPayment.setTransNo(res.get("id").toString());
|
|
|
|
- orderPayment.setPayAmt(
|
|
|
|
- new BigDecimal(res.get("pay_amt").toString()).setScale(2, RoundingMode.HALF_UP)
|
|
|
|
- );
|
|
|
|
- String pay_info = ((JSONObject) res.get("expend")).getString("pay_info");
|
|
|
|
- orderPayment.setPayInfo(pay_info);
|
|
|
|
- orderPayment.setStatus(TradeStatusEnum.pending);
|
|
|
|
-
|
|
|
|
- //查询订单下支付中的付款单,取消支付
|
|
|
|
- closePayment(payReq.getOrderNo(),"用户发起了新的付款请求");
|
|
|
|
- } else {
|
|
|
|
- orderPayment.setPayFailMsg(responseResult.getMsg());
|
|
|
|
- orderPayment.setStatus(TradeStatusEnum.failed);
|
|
|
|
- }
|
|
|
|
|
|
+ orderPayment.setTransNo(payment.getId());
|
|
|
|
+ orderPayment.setPayAmt(
|
|
|
|
+ new BigDecimal(payment.getPayAmt()).setScale(2, RoundingMode.HALF_UP)
|
|
|
|
+ );
|
|
|
|
+ orderPayment.setPayInfo(payment.getPayInfo());
|
|
|
|
+ orderPayment.setStatus(TradeStatusEnum.pending);
|
|
|
|
+
|
|
|
|
+ //查询订单下支付中的付款单,取消支付
|
|
|
|
+ closePayment(payReq.getOrderNo(), "用户发起了新的付款请求");
|
|
|
|
+ //保存新的付款单
|
|
save(orderPayment);
|
|
save(orderPayment);
|
|
return orderPayment;
|
|
return orderPayment;
|
|
}
|
|
}
|
|
@@ -99,7 +95,7 @@ public class UserOrderPaymentServiceImpl extends ServiceImpl<UserOrderPaymentDao
|
|
UserOrderPayment orderPayment = baseMapper.selectOne(Wrappers.<UserOrderPayment>lambdaQuery()
|
|
UserOrderPayment orderPayment = baseMapper.selectOne(Wrappers.<UserOrderPayment>lambdaQuery()
|
|
.eq(UserOrderPayment::getOrderNo, orderNo)
|
|
.eq(UserOrderPayment::getOrderNo, orderNo)
|
|
.eq(UserOrderPayment::getStatus, TradeStatusEnum.pending));
|
|
.eq(UserOrderPayment::getStatus, TradeStatusEnum.pending));
|
|
- if(null == orderPayment){
|
|
|
|
|
|
+ if (null == orderPayment) {
|
|
return orderPayment;
|
|
return orderPayment;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -110,12 +106,20 @@ public class UserOrderPaymentServiceImpl extends ServiceImpl<UserOrderPaymentDao
|
|
|
|
|
|
//发送支付关单请求
|
|
//发送支付关单请求
|
|
if (!StringUtil.isEmpty(orderPayment.getTransNo())) {
|
|
if (!StringUtil.isEmpty(orderPayment.getTransNo())) {
|
|
- HttpResponseResult<Map<String, Object>> responseResult = paymentSdk.closePayment(orderPayment.getTransNo(), reason, "");
|
|
|
|
- if (!responseResult.getStatus()) {
|
|
|
|
- orderPayment.setCloseStatus(TradeStatusEnum.failed);
|
|
|
|
- orderPayment.setCloseFailMsg(responseResult.getMsg());
|
|
|
|
- } else {
|
|
|
|
- orderPayment.setCloseStatus(TradeStatusEnum.pending);
|
|
|
|
|
|
+ ClosePayment param = new ClosePayment(orderPayment.getOpenType(), orderPayment.getPayChannel());
|
|
|
|
+ param.setId(orderPayment.getTransNo());
|
|
|
|
+ param.setReason(reason);
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ BaseResult<ClosePayment> responseResult = paymentClient.closePayment(param);
|
|
|
|
+ if (!responseResult.getStatus()) {
|
|
|
|
+ orderPayment.setCloseStatus(TradeStatusEnum.failed);
|
|
|
|
+ orderPayment.setCloseFailMsg(responseResult.getMsg());
|
|
|
|
+ } else {
|
|
|
|
+ orderPayment.setCloseStatus(TradeStatusEnum.pending);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
updateById(orderPayment);
|
|
updateById(orderPayment);
|
|
@@ -147,54 +151,59 @@ public class UserOrderPaymentServiceImpl extends ServiceImpl<UserOrderPaymentDao
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public HttpResponseResult<OrderPayRes> createOrderPayment(OrderPayReq payReq, UserOrderVo detail) {
|
|
|
|
|
|
+ public HttpResponseResult<OrderPayRes> createOrderPayment(OrderPayReq payReq, UserOrderVo detail) throws Exception {
|
|
OrderPayRes orderPayRes = new OrderPayRes();
|
|
OrderPayRes orderPayRes = new OrderPayRes();
|
|
- //汇付订单号生成
|
|
|
|
- Long adapayNo = idGeneratorService.generatorId("adapayNo");
|
|
|
|
|
|
+ //支付订单号生成
|
|
|
|
+ Long paymentNo = idGeneratorService.generatorId("paymentNo");
|
|
|
|
|
|
//构建汇付统一下单请求
|
|
//构建汇付统一下单请求
|
|
- PaymentReq paymentReq = new PaymentReq();
|
|
|
|
- paymentReq.setOrder_no(adapayNo.toString());
|
|
|
|
- paymentReq.setPay_channel(payReq.getPayChannel().getCode());
|
|
|
|
- paymentReq.setPay_amt(detail.getActualPrice().setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
|
- paymentReq.setGoods_title(detail.getOrderName());
|
|
|
|
- paymentReq.setGoods_desc(detail.getOrderDesc());
|
|
|
|
-
|
|
|
|
- DeviceInfo deviceInfo = new DeviceInfo();
|
|
|
|
- deviceInfo.setDevice_ip(payReq.getIpAddress());
|
|
|
|
-
|
|
|
|
- paymentReq.setDevice_info(deviceInfo);
|
|
|
|
- //异步通知地址
|
|
|
|
- paymentReq.setNotify_url(HuifuConfiguration.getHuifuProperties().getNotifyUrl());
|
|
|
|
-
|
|
|
|
- if (PayChannelEnum.alipay_lite.equals(payReq.getPayChannel())) {
|
|
|
|
- Map<String, Object> expend = new HashMap<>();
|
|
|
|
- expend.put("buyer_id", payReq.getBuyerId());
|
|
|
|
- paymentReq.setExpend(expend);
|
|
|
|
- }
|
|
|
|
- if (PayChannelEnum.wx_lite.equals(payReq.getPayChannel())) {
|
|
|
|
- Map<String, Object> expend = new HashMap<>();
|
|
|
|
- expend.put("open_id", payReq.getOpenId());
|
|
|
|
- paymentReq.setExpend(expend);
|
|
|
|
|
|
+ OpenEnum openType = OpenEnum.valueOf(paymentProperties.getOpenType());
|
|
|
|
+ Payment payment = new Payment(openType, payReq.getPayChannel());
|
|
|
|
+ payment.setPaymentNo(paymentNo.toString());
|
|
|
|
+ payment.setOrderTitle(detail.getOrderName());
|
|
|
|
+ payment.setOrderDesc(detail.getOrderDesc());
|
|
|
|
+ payment.setPayAmt(detail.getActualPrice().setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
|
+
|
|
|
|
+ payment.setDescription(payReq.getReason());
|
|
|
|
+
|
|
|
|
+ if (OpenEnum.ADAPAY.equals(openType)) {
|
|
|
|
+ //创建分账对象
|
|
|
|
+ DivMember div_member = new DivMember();
|
|
|
|
+ div_member.setMember_id("0");
|
|
|
|
+ div_member.setAmount(detail.getActualPrice().setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
|
+ div_member.setFee_flag("Y");
|
|
|
|
+ List<DivMember> div_members = Arrays.asList(div_member);
|
|
|
|
+ payment.setDivMembers(div_members);
|
|
|
|
+
|
|
|
|
+ //前端设备信息
|
|
|
|
+ DeviceInfo deviceInfo = new DeviceInfo();
|
|
|
|
+ deviceInfo.setDevice_ip(payReq.getIpAddress());
|
|
|
|
+ payment.setDeviceInfo(deviceInfo);
|
|
|
|
+
|
|
|
|
+ if (PayChannelEnum.wx_lite.equals(payReq.getPayChannel())) {
|
|
|
|
+ Map<String, Object> expend = new HashMap<>();
|
|
|
|
+ expend.put("open_id", payReq.getOpenId());
|
|
|
|
+ payment.setExpend(expend);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
//付款请求
|
|
//付款请求
|
|
- HttpResponseResult<Map<String, Object>> responseResult = paymentSdk.executePayment(paymentReq);
|
|
|
|
- if (responseResult.getStatus()) {
|
|
|
|
|
|
+ BaseResult<Payment> paymentResBaseResult = paymentClient.executePayment(payment);
|
|
|
|
+ if (paymentResBaseResult.getStatus()) {
|
|
orderPayRes.setPay_amt(detail.getActualPrice().setScale(2, RoundingMode.HALF_UP).toString());
|
|
orderPayRes.setPay_amt(detail.getActualPrice().setScale(2, RoundingMode.HALF_UP).toString());
|
|
- String pay_info = ((JSONObject) responseResult.getData().get("expend")).getString("pay_info");
|
|
|
|
|
|
+ String pay_info = paymentResBaseResult.getData().getPayInfo();
|
|
orderPayRes.setPay_info(pay_info);
|
|
orderPayRes.setPay_info(pay_info);
|
|
orderPayRes.setPayChannel(payReq.getPayChannel());
|
|
orderPayRes.setPayChannel(payReq.getPayChannel());
|
|
|
|
|
|
//入订单付款表
|
|
//入订单付款表
|
|
- insertOrderPayment(responseResult, payReq, adapayNo);
|
|
|
|
|
|
+ insertOrderPayment(paymentResBaseResult.getData(), payReq);
|
|
//修改订单状态
|
|
//修改订单状态
|
|
userOrderService.updateStatusByOrderNo(payReq.getOrderNo(), OrderStatusEnum.PAYING.getCode());
|
|
userOrderService.updateStatusByOrderNo(payReq.getOrderNo(), OrderStatusEnum.PAYING.getCode());
|
|
return HttpResponseResult.succeed(orderPayRes);
|
|
return HttpResponseResult.succeed(orderPayRes);
|
|
} else {
|
|
} else {
|
|
//入订单付款表,同时修改订单状态
|
|
//入订单付款表,同时修改订单状态
|
|
- userOrderService.doOrderCancel(detail, OrderStatusEnum.FAIL, responseResult.getMsg());
|
|
|
|
- return HttpResponseResult.failed(responseResult.getMsg());
|
|
|
|
|
|
+ userOrderService.doOrderCancel(detail, OrderStatusEnum.FAIL, paymentResBaseResult.getMsg());
|
|
|
|
+ return HttpResponseResult.failed(paymentResBaseResult.getMsg());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|