Browse Source

修改提现功能

master
xh-pan1 1 year ago
parent
commit
e174243526
  1. 2
      cereshop-admin/src/main/java/com/shop/cereshop/admin/dao/order/CereOrderProductDAO.java
  2. 9
      cereshop-admin/src/main/java/com/shop/cereshop/admin/dao/order/CereShopOrderDAO.java
  3. 2
      cereshop-admin/src/main/java/com/shop/cereshop/admin/dao/shop/CerePlatformShopDAO.java
  4. 2
      cereshop-admin/src/main/java/com/shop/cereshop/admin/pay/PayService.java
  5. 2
      cereshop-admin/src/main/java/com/shop/cereshop/admin/pay/alipay/service/impl/AliPayServiceImpl.java
  6. 2
      cereshop-admin/src/main/java/com/shop/cereshop/admin/pay/weixin/service/impl/WxPayServiceImpl.java
  7. 226
      cereshop-admin/src/main/java/com/shop/cereshop/admin/pay/xs/impl/XsPayServiceImpl.java
  8. 2
      cereshop-admin/src/main/java/com/shop/cereshop/admin/service/after/impl/CereOrderAfterServiceImpl.java
  9. 2
      cereshop-admin/src/main/java/com/shop/cereshop/admin/service/shop/CerePlatformShopService.java
  10. 5
      cereshop-admin/src/main/java/com/shop/cereshop/admin/service/shop/impl/CerePlatformShopServiceImpl.java
  11. 31
      cereshop-admin/src/main/resources/mybatis/mapper/order/CereOrderProductDAO.xml
  12. 18
      cereshop-admin/src/main/resources/mybatis/mapper/order/CereShopOrderDAO.xml
  13. 11
      cereshop-admin/src/main/resources/mybatis/mapper/shop/CerePlatformShopDAO.xml

2
cereshop-admin/src/main/java/com/shop/cereshop/admin/dao/order/CereOrderProductDAO.java

@ -19,4 +19,6 @@ public interface CereOrderProductDAO extends BaseMapper<CereOrderProduct> {
int insertSelective(CereOrderProduct record);
void insertBatchAttibutes(@Param("list") List<CereOrderProductAttribute> list);
List<CereOrderProduct> findByOrderIds(List<Long> orderIdList);
}

9
cereshop-admin/src/main/java/com/shop/cereshop/admin/dao/order/CereShopOrderDAO.java

@ -10,9 +10,11 @@ import com.shop.cereshop.admin.page.order.ShopOrderAfter;
import com.shop.cereshop.admin.page.product.Product;
import com.shop.cereshop.admin.page.product.SkuDetail;
import com.shop.cereshop.admin.param.order.OrderGetAllParam;
import com.shop.cereshop.commons.domain.order.CereOrderParent;
import com.shop.cereshop.commons.domain.order.CereShopOrder;
import com.shop.cereshop.commons.domain.product.CereProductSku;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -56,5 +58,12 @@ public interface CereShopOrderDAO extends BaseMapper<CereShopOrder> {
BigDecimal selectChannelOrderAmount(String channelCode);
@MapKey("sku_id")
List<Map<String, Object>> selectSalesVolumeBySkuIdList(List<Long> skuIdList);
CereOrderParent findByParentFormid(@Param("orderFormId") String orderFormId);
List<CereShopOrder> findByParentId(@Param("parentId") Long parentId);
List<CereShopOrder> findByFormid(@Param("orderFormId") String orderFormId);
}

2
cereshop-admin/src/main/java/com/shop/cereshop/admin/dao/shop/CerePlatformShopDAO.java

@ -66,4 +66,6 @@ public interface CerePlatformShopDAO extends BaseMapper<CerePlatformShop> {
BigDecimal findWithdrawing(Long shopId);
Boolean cleanShop(Long shopId);
List<CerePlatformShop> getByIdList(@Param("shopIdList") List<Long> shopIdList);
}

2
cereshop-admin/src/main/java/com/shop/cereshop/admin/pay/PayService.java

@ -21,7 +21,7 @@ public interface PayService {
* @throws CoBusinessException
* @throws Exception
*/
Map<String,String> refund(String transactionId,String outRefundNo,BigDecimal total,BigDecimal refund) throws CoBusinessException,Exception;
Map<String,String> refund(String orderFormId, String outTradeNo, String transactionId,String outRefundNo,BigDecimal total,BigDecimal refund) throws CoBusinessException,Exception;
/**
* 保证金退款

2
cereshop-admin/src/main/java/com/shop/cereshop/admin/pay/alipay/service/impl/AliPayServiceImpl.java

@ -27,7 +27,7 @@ import java.util.Map;
public class AliPayServiceImpl implements AliPayService {
@Override
public Map<String, String> refund(String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
public Map<String, String> refund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
Map<String, String> result = new HashMap<>();
AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE);

2
cereshop-admin/src/main/java/com/shop/cereshop/admin/pay/weixin/service/impl/WxPayServiceImpl.java

@ -93,7 +93,7 @@ public class WxPayServiceImpl implements WxPayService {
private WXPayV3Util wxPayV3Util;
@Override
public Map<String, String> refund(String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
public Map<String, String> refund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
//APPV3版本的退款以APPV3开头
if (outRefundNo.startsWith("APPV3")) {
return refundWithV3(transactionId, outRefundNo, total, refund);

226
cereshop-admin/src/main/java/com/shop/cereshop/admin/pay/xs/impl/XsPayServiceImpl.java

@ -5,77 +5,199 @@
*/
package com.shop.cereshop.admin.pay.xs.impl;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeRefundApplyModel;
import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.api.response.AlipayTradeRefundResponse;
import com.shop.cereshop.admin.pay.alipay.service.AliPayService;
import com.shop.cereshop.commons.config.AlipayConfig;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
import com.google.gson.Gson;
import com.shop.cereshop.admin.dao.order.CereOrderProductDAO;
import com.shop.cereshop.admin.dao.order.CereShopOrderDAO;
import com.shop.cereshop.admin.dao.shop.CereShopBankDAO;
import com.shop.cereshop.admin.pay.xs.XsPayService;
import com.shop.cereshop.admin.service.shop.CerePlatformShopService;
import com.shop.cereshop.commons.config.XspayConfig;
import com.shop.cereshop.commons.constant.CoReturnFormat;
import com.shop.cereshop.commons.constant.WxPayEnum;
import com.shop.cereshop.commons.domain.order.CereOrderParent;
import com.shop.cereshop.commons.domain.order.CereOrderProduct;
import com.shop.cereshop.commons.domain.order.CereShopOrder;
import com.shop.cereshop.commons.domain.shop.CerePlatformShop;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.utils.EmptyUtils;
import com.shop.cereshop.commons.utils.StringUtils;
import com.shop.cereshop.commons.utils.xspay.CommonUtils;
import com.shop.cereshop.commons.utils.xspay.XsPayUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Service
@Slf4j(topic = "XsPayServiceImpl")
public class XsPayServiceImpl implements AliPayService {
public class XsPayServiceImpl implements XsPayService {
private static final String SHARE_REFUND_SER_CODE = "101022";
@Autowired
private CereShopOrderDAO cereShopOrderDAO;
@Autowired
private CereOrderProductDAO cereOrderProductDAO;
@Autowired
private CerePlatformShopService cerePlatformShopservice;
@Autowired
private CereShopBankDAO cereShopBankDAO;
//售后退款中需要仲裁的售后退款
@Override
public Map<String, String> refund(String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
Map<String, String> result = new HashMap<>();
AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE);
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
//request.setNotifyUrl(AlipayConfig.REFUND_NOTIFY_URL);
AlipayTradeRefundApplyModel model = new AlipayTradeRefundApplyModel();
//model.setOutTradeNo(outTradeNo);
model.setTradeNo(transactionId);
model.setRefundAmount(refund.toString());
request.setBizModel(model);
AlipayTradeRefundResponse response = client.execute(request);
if (response.isSuccess()) {
//这里只是申请退款兼容微信的返回
result.put("return_msg", WxPayEnum.REFUND_SUCCESS.getCode());
result.put("return_code", WxPayEnum.REFUND_OK.getCode());
} else {
log.error("alipay refund failed: subCode = {}, subMsg = {}", response.getSubCode(), response.getSubMsg());
throw new CoBusinessException(CoReturnFormat.APPLY_REFUND_FAILED);
public Map<String, String> refund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
Map<String, Object> contentMap = build22ContentMap(orderFormId, outRefundNo, outTradeNo, transactionId, refund, XspayConfig.BUSINESS_RETURN_NOTICE_URL);
String respMsg = XsPayUtils.requestByXs(SHARE_REFUND_SER_CODE, contentMap);
if(StrUtil.isNotBlank(respMsg)){
try {
//解析响应报文并验签
CommonUtils.verifySignRespMsg(SHARE_REFUND_SER_CODE,respMsg);
LinkedHashMap<String,String> responseMap = JSONObject.parseObject(respMsg,new TypeReference<LinkedHashMap<String,String>>(){}, Feature.OrderedField );
String resMsg = responseMap.get("msg");
String responeMsg = new String(Base64.getDecoder().decode(resMsg));
JSONObject jsonObject = JSONObject.parseObject(responeMsg);
JSONObject content = jsonObject.getJSONObject("content");
String status = content.getString("status");
//2成功 3失败
if(StringUtils.equals(status, "1")) {
Map<String, String> result = new HashMap<>();
result.put("return_msg", WxPayEnum.REFUND_SUCCESS.getCode());
result.put("return_code", WxPayEnum.REFUND_OK.getCode());
return result;
}
} catch (CoBusinessException e) {
if(StringUtils.equals(e.getCode(), "0005")){
throw new CoBusinessException(CoReturnFormat.APPLY_REFUND_FAILED_LATER,"支付系统正在处理,请支付5分钟后再申请退款", "");
}else {
throw e;
}
} catch (Exception e) {
//支付方式为B2CB2BH5成功响应时respMsg为html页面代码
if(respMsg.contains("toNativePayIndexForm")){
log.info("【" + SHARE_REFUND_SER_CODE + "】接口-响应报文-HTML代码无需验签");
}else{
e.printStackTrace();
}
throw new CoBusinessException("10000","退款出错", "");
}
}
return result;
return null;
}
//保证金退款
//TODO 待开发
@Override
public Map<String, String> refundBond(String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
Map<String, String> result = new HashMap<>();
AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE);
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
//request.setNotifyUrl(AlipayConfig.REFUND_NOTIFY_URL);
AlipayTradeRefundApplyModel model = new AlipayTradeRefundApplyModel();
//model.setOutTradeNo(outTradeNo);
model.setTradeNo(transactionId);
model.setRefundAmount(refund.toString());
request.setBizModel(model);
AlipayTradeRefundResponse response = client.execute(request);
if (response.isSuccess()) {
//这里只是申请退款兼容微信的返回
result.put("return_msg", WxPayEnum.REFUND_SUCCESS.getCode());
result.put("return_code", WxPayEnum.REFUND_OK.getCode());
result.put("out_trade_no", response.getOutTradeNo());
result.put("transaction_id", response.getTradeNo());
throw new CoBusinessException("10000","新生通道保证金退款功能待开发", "");
}
private Map<String,Object> build22ContentMap(String orderFormId, String merOrderId, String oldMerOrderId, String dealId, BigDecimal money, String noticeUrl) throws CoBusinessException {
List<CereShopOrder> orderList = null;
String cereOrderFormId = orderFormId;
String[] split = orderFormId.split("-");
if(!EmptyUtils.isEmpty(split)) {
cereOrderFormId = split[0];
}
//查询是否为父订单编号
CereOrderParent parent = cereShopOrderDAO.findByParentFormid(cereOrderFormId);
if (parent != null) {
//查询所有子订单数据
orderList = cereShopOrderDAO.findByParentId(parent.getParentId());
} else {
log.error("alipay refundBond failed: subCode = {}, subMsg = {}", response.getSubCode(), response.getSubMsg());
throw new CoBusinessException(CoReturnFormat.APPLY_REFUND_FAILED);
//子订单支付回调
orderList = cereShopOrderDAO.findByFormid(cereOrderFormId);
}
//这里理论上只会有一个子订单如果出现多个说明出错了
if(orderList.size() != 1){
throw new CoBusinessException("10000","订单查找出错", "");
}
List<CereOrderProduct> cereOrderProductList = cereOrderProductDAO.findByOrderIds(orderList.stream().map(CereShopOrder::getOrderId).collect(Collectors.toList()));
log.info("cereOrderProductList:" + new Gson().toJson(cereOrderProductList));
List<Long> shopIdList = orderList.stream().map(CereShopOrder::getShopId).distinct().collect(Collectors.toList());
List<CerePlatformShop> cerePlatformShopList = cerePlatformShopservice.getByIdList(shopIdList);
Map<String, Object> contentMap = new LinkedHashMap<>();
log.info("orderFormid:" + orderFormId);
contentMap.put("merOrderId", merOrderId);
//oldMerOrderId 对应 101004101005接口中merOrderId
contentMap.put("oldMerOrderId", oldMerOrderId);
//oldDealId 对应 101004101005接口响应参数中dealId
// contentMap.put("oldDealId", dealId);
contentMap.put("oldSubOrderId", orderList.get(0).getOrderFormid());
JSONArray jsonArray = build22SubMerchantOrderDetails(orderList, cereOrderProductList, cerePlatformShopList);
if(jsonArray != null) {
contentMap.put("shareRefundDetail", JSONArray.toJSONString(jsonArray));
}
return result;
contentMap.put("currency", "CNY");
contentMap.put("noticeUrl", noticeUrl);
return contentMap;
}
/**
* 构建分账明细
* @return
*/
private static JSONArray build22SubMerchantOrderDetails(List<CereShopOrder> orderList,
List<CereOrderProduct> cereOrderProductList,
List<CerePlatformShop> cerePlatformShopList){
if(cereOrderProductList.isEmpty()){
return null;
}
JSONArray detailArray1 = new JSONArray();
for (CereShopOrder cereShopOrder : orderList) {
CerePlatformShop cerePlatformShop = cerePlatformShopList.stream().filter(item ->
item.getShopId().equals(cereShopOrder.getShopId())).findFirst().orElse(null);
List<CereOrderProduct> orderProductList = cereOrderProductList.stream().filter(item -> item.getOrderId().equals(cereShopOrder.getOrderId())).collect(Collectors.toList());
for (CereOrderProduct cereOrderProduct : orderProductList) {
//子订单1 明细1
JSONObject detail1 = new JSONObject();
detail1.put("shareDetailId", "" + cereOrderProduct.getOrderId() + cereOrderProduct.getOrderProductId());
detail1.put("shareParId", cerePlatformShop.getXsPayId());
//这里是否需要减去用积分抵扣金额
detail1.put("shareRefundAmount",
cereOrderProduct.getActualPrice().add(cereOrderProduct.getLogisticsPrice())
.subtract(cereOrderProduct.getUseCreditAmount())
.subtract(cereOrderProduct.getPlatformCommission())
.multiply(BigDecimal.valueOf(100)).intValue()
);
// detail1.put("settleCurCode","CNY");
detailArray1.add(detail1);
}
JSONObject detail2 = new JSONObject();
detail2.put("shareDetailId", "platformCommission-" + cereShopOrder.getOrderId());
detail2.put("shareParId", XspayConfig.MER_CODE);
detail2.put("shareRefundAmount", cereShopOrder.getPlatformCommission().multiply(BigDecimal.valueOf(100)).intValue());
// detail2.put("settleCurCode","CNY");
detailArray1.add(detail2);
}
return detailArray1;
}
}

2
cereshop-admin/src/main/java/com/shop/cereshop/admin/service/after/impl/CereOrderAfterServiceImpl.java

@ -247,7 +247,7 @@ public class CereOrderAfterServiceImpl implements CereOrderAfterService {
//第一次售后退款
payLog.setAfter(String.valueOf(param.getAfterId()));
}
Map<String, String> resultMap = PayFactory.getPayService(payLog.getPaymentMode()).refund(refund.getTransactionId(),
Map<String, String> resultMap = PayFactory.getPayService(payLog.getPaymentMode()).refund(refund.getOrderFormid(), refund.getOutTradeNo(), refund.getTransactionId(),
refund.getOutRefundNo(), refund.getOrderPrice(), refund.getPrice());
if(!EmptyUtils.isEmpty(resultMap)){
if(resultMap.get("return_msg").equals(WxPayEnum.REFUND_SUCCESS.getCode())&&

2
cereshop-admin/src/main/java/com/shop/cereshop/admin/service/shop/CerePlatformShopService.java

@ -52,4 +52,6 @@ public interface CerePlatformShopService {
void updateShopStop(CerePlatformShop shop) throws CoBusinessException;
Boolean cleanShop(Long shopId);
List<CerePlatformShop> getByIdList(List<Long> shopIdList);
}

5
cereshop-admin/src/main/java/com/shop/cereshop/admin/service/shop/impl/CerePlatformShopServiceImpl.java

@ -268,4 +268,9 @@ public class CerePlatformShopServiceImpl implements CerePlatformShopService {
public Boolean cleanShop(Long shopId) {
return cerePlatformShopDAO.cleanShop(shopId);
}
@Override
public List<CerePlatformShop> getByIdList(List<Long> shopIdList){
return cerePlatformShopDAO.getByIdList(shopIdList);
}
}

31
cereshop-admin/src/main/resources/mybatis/mapper/order/CereOrderProductDAO.xml

@ -87,4 +87,35 @@
)
</foreach>
</insert>
<select id="findByOrderIds" resultMap="BaseResultMap">
select
cop.order_product_id,
cop.order_id,
cop.product_id,
cso.shop_id,
cop.sku_id,
cop.product_name,
cop.`number`,
cop.actual_price,
cop.product_price,
cop.image,
cop.SKU,
cop.weight,
cop.activity_type,
cop.activity_id,
cop.use_credit,
cop.use_credit_amount,
cop.logistics_price,
cps.rate,
cop.platform_commission
from cere_order_product cop
LEFT JOIN cere_shop_order cso ON cso.order_id = cop.order_id
LEFT JOIN cere_product_sku cps ON cps.sku_id = cop.sku_id
where cop.order_id in
<foreach collection="list" item="orderId" open="(" separator="," close=")">
#{orderId}
</foreach>
</select>
</mapper>

18
cereshop-admin/src/main/resources/mybatis/mapper/order/CereShopOrderDAO.xml

@ -627,4 +627,22 @@
</foreach>
group by b.sku_id
</select>
<select id="findByParentFormid" parameterType="java.lang.Object" resultType="com.shop.cereshop.commons.domain.order.CereOrderParent">
SELECT parent_id FROM cere_order_parent where parent_formid=#{orderFormId}
</select>
<select id="findByParentId" parameterType="java.lang.Object" resultType="com.shop.cereshop.commons.domain.order.CereShopOrder">
SELECT order_id, buyer_user_id, customer_phone, shop_id, price, order_formid, customer_name, shop_group_work_id,
shop_seckill_id, shop_discount_id, payment_mode, coupon_id, is_cross, platform_commission
FROM cere_shop_order where parent_id=#{parentId}
</select>
<select id="findByFormid" parameterType="java.lang.Object" resultType="com.shop.cereshop.commons.domain.order.CereShopOrder">
SELECT order_id, buyer_user_id, customer_phone, shop_id, price, logistics_price ,discount_price, order_formid, customer_name, shop_group_work_id,
shop_seckill_id, shop_discount_id, payment_mode, coupon_id, receive_name, receive_phone, address, remark,
receive_adress, platform_commission
FROM cere_shop_order where order_formid=#{orderFormId}
</select>
</mapper>

11
cereshop-admin/src/main/resources/mybatis/mapper/shop/CerePlatformShopDAO.xml

@ -454,4 +454,15 @@
SELECT IF(SUM(withdrawal_money) IS NULL,0,SUM(withdrawal_money)) FROM cere_shop_withdrawal
where shop_id = #{shopId} and state = 0
</select>
<select id="getByIdList" parameterType="java.util.List" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from cere_platform_shop
where shop_id in (
<foreach collection="shopIdList" item="shopId" index="index" separator=",">
#{shopId}
</foreach>
)
</select>
</mapper>
Loading…
Cancel
Save