|
@@ -1,12 +1,26 @@
|
|
|
package com.cyksj.service.goods.impl;
|
|
package com.cyksj.service.goods.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+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.exception.BusinessRuntimeException;
|
|
|
|
|
+import com.cyksj.common.util.Codec;
|
|
|
|
|
+import com.cyksj.common.util.Xmls;
|
|
|
import com.cyksj.mapper.GoodsWholesaleMapper;
|
|
import com.cyksj.mapper.GoodsWholesaleMapper;
|
|
|
|
|
+import com.cyksj.mapper.GoodsWholesaleUserDepositMapper;
|
|
|
|
|
+import com.cyksj.mapper.channel.ShopConfigMapper;
|
|
|
|
|
+import com.cyksj.mapper.manage.cms.CmsUserMapper;
|
|
|
import com.cyksj.model.entity.GoodsWholesale;
|
|
import com.cyksj.model.entity.GoodsWholesale;
|
|
|
|
|
+import com.cyksj.model.entity.GoodsWholesaleUserDeposit;
|
|
|
import com.cyksj.service.goods.GoodsWholesaleService;
|
|
import com.cyksj.service.goods.GoodsWholesaleService;
|
|
|
|
|
+import com.cyksj.service.order.OrderRefundService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 项目名: yhlxj
|
|
* 项目名: yhlxj
|
|
|
* 文件名: GoodsWholesaleServiceImpl
|
|
* 文件名: GoodsWholesaleServiceImpl
|
|
@@ -15,6 +29,65 @@ import org.springframework.stereotype.Service;
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
|
|
|
+@Slf4j
|
|
|
public class GoodsWholesaleServiceImpl extends ServiceImpl<GoodsWholesaleMapper, GoodsWholesale> implements GoodsWholesaleService {
|
|
public class GoodsWholesaleServiceImpl extends ServiceImpl<GoodsWholesaleMapper, GoodsWholesale> implements GoodsWholesaleService {
|
|
|
|
|
+ private final GoodsWholesaleUserDepositMapper goodsWholesaleUserDepositMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final OrderRefundService orderRefundService;
|
|
|
|
|
+
|
|
|
|
|
+ private final ShopConfigMapper shopConfigMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final CmsUserMapper cmsUserMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void depositRefund(Long id, Long adminId) throws Exception {
|
|
|
|
|
+ GoodsWholesaleUserDeposit goodsWholesaleUserDeposit = goodsWholesaleUserDepositMapper.selectById(id);
|
|
|
|
|
+ if (goodsWholesaleUserDeposit == null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("记录不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!goodsWholesaleUserDeposit.getStatus()) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("押金已退");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int update = goodsWholesaleUserDepositMapper.update(null, Wrappers.lambdaUpdate(GoodsWholesaleUserDeposit.class)
|
|
|
|
|
+ .set(GoodsWholesaleUserDeposit::getStatus, 0)
|
|
|
|
|
+ .eq(GoodsWholesaleUserDeposit::getId, id)
|
|
|
|
|
+ .eq(GoodsWholesaleUserDeposit::getStatus, 1));
|
|
|
|
|
+ if (update == 0) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("押金已退");
|
|
|
|
|
+ }
|
|
|
|
|
+ String outRefundNo = orderRefundService.refundWholesaleUserDeposit(goodsWholesaleUserDeposit);
|
|
|
|
|
+ goodsWholesaleUserDeposit.setRefundOutNo(outRefundNo);
|
|
|
|
|
+ Optional.ofNullable(cmsUserMapper.selectById(adminId)).ifPresent(cu -> goodsWholesaleUserDeposit.setOperator(cu.getNickname()));
|
|
|
|
|
+ goodsWholesaleUserDepositMapper.updateById(goodsWholesaleUserDeposit);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void wxRefundNotify(Map<String, String> map) throws Exception {
|
|
|
|
|
+ // 对退款数据 解密
|
|
|
|
|
+ String md5Key = Codec.DoDigest.custom().setAlgorithm(Codec.DoDigest.Algorithm.MD5).setStringData(shopConfigMapper.getByAppId(map.get("mch_id")).getSecret()).toHexString();
|
|
|
|
|
+ String reqInfoXml = Codec.DoCipher.custom().setAlgorithm(Codec.DoCipher.Trans.AES_ECB_PKCS7Padding).setBase64Data(map.get("req_info")).setStringKey(md5Key).ofDecrypt().toText();
|
|
|
|
|
+ log.info("=== 退款数据解密: \n {}", reqInfoXml);
|
|
|
|
|
+ Map<String, String> reqInfoMap = Xmls.toMap(reqInfoXml);
|
|
|
|
|
+ // 退款失败
|
|
|
|
|
+ if (StrUtil.equals("CHANGE", reqInfoMap.get("refund_status"))) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("退款异常.");
|
|
|
|
|
+ } else if (StrUtil.equals("REFUNDCLOSE", reqInfoMap.get("refund_status"))) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("退款关闭.");
|
|
|
|
|
+ }
|
|
|
|
|
+ /* 此处处理业务逻辑 */
|
|
|
|
|
+ String outRefundNo = reqInfoMap.get("out_refund_no");
|
|
|
|
|
+ String transactionId = reqInfoMap.get("transaction_id");
|
|
|
|
|
+ String refundFee = reqInfoMap.get("refund_fee");
|
|
|
|
|
+ GoodsWholesaleUserDeposit userDeposit = goodsWholesaleUserDepositMapper.selectOne(Wrappers.lambdaQuery(GoodsWholesaleUserDeposit.class).eq(GoodsWholesaleUserDeposit::getTransactionId, transactionId).last("limit 1"));
|
|
|
|
|
+ if (userDeposit == null) {
|
|
|
|
|
+ log.error("退款回调,transactionId:{}订单不存在", transactionId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("微信退款: 退款单号[{}] 退款成功.", outRefundNo);
|
|
|
|
|
+ if (userDeposit.getStatus()) {
|
|
|
|
|
+ userDeposit.setStatus(false);
|
|
|
|
|
+ goodsWholesaleUserDepositMapper.updateById(userDeposit);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|