|
|
@@ -34,6 +34,9 @@ import com.fs.erp.domain.ErpOrderItem;
|
|
|
import com.fs.erp.domain.ErpOrderPayment;
|
|
|
import com.fs.erp.dto.ErpOrderResponse;
|
|
|
import com.fs.erp.service.IErpOrderService;
|
|
|
+import com.fs.event.TemplateBean;
|
|
|
+import com.fs.event.TemplateEvent;
|
|
|
+import com.fs.event.TemplateListenEnum;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
import com.fs.his.domain.*;
|
|
|
import com.fs.his.dto.ErpRemarkDTO;
|
|
|
@@ -45,6 +48,9 @@ import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.his.utils.PhoneUtil;
|
|
|
import com.fs.his.utils.RedisCacheUtil;
|
|
|
import com.fs.his.vo.*;
|
|
|
+import com.fs.huifuPay.domain.HuiFuRefundResult;
|
|
|
+import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayRefundRequest;
|
|
|
+import com.fs.huifuPay.service.HuiFuService;
|
|
|
import com.fs.qw.domain.QwUser;
|
|
|
import com.fs.qw.mapper.QwUserMapper;
|
|
|
import com.fs.tzBankPay.doman.PayType;
|
|
|
@@ -57,6 +63,7 @@ import org.redisson.api.RObjectAsync;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.context.ApplicationEventPublisher;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
@@ -95,12 +102,22 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService
|
|
|
|
|
|
@Autowired
|
|
|
private FsIntegralGoodsMapper fsIntegralGoodsMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsStorePaymentMapper storePaymentMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private FsUserIntegralLogsMapper fsUserIntegralLogsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private QwUserMapper qwUserMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ HuiFuService huiFuService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApplicationEventPublisher publisher;
|
|
|
+
|
|
|
@Autowired
|
|
|
private CompanyUserMapper companyUserMapper;
|
|
|
@Autowired
|
|
|
@@ -870,6 +887,46 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService
|
|
|
fsUserIntegralLogs.setStatus(0);
|
|
|
fsUserIntegralLogs.setCreateTime(new Date());
|
|
|
i = fsUserIntegralLogsMapper.insertFsUserIntegralLogs(fsUserIntegralLogs);
|
|
|
+
|
|
|
+ //还原库存
|
|
|
+ if (fsIntegralOrder.getItemJson().startsWith("[") && fsIntegralOrder.getItemJson().endsWith("]")){
|
|
|
+ List<FsIntegralGoods> goodsItem = JSONUtil.toBean(fsIntegralOrder.getItemJson(), new TypeReference<List<FsIntegralGoods>>(){}, true);
|
|
|
+ goodsItem.forEach(goods -> fsIntegralGoodsMapper.addStock(goods.getGoodsId(), Objects.isNull(goods.getNum()) ? 1 : goods.getNum()));
|
|
|
+ } else {
|
|
|
+ FsIntegralGoods integralGoods = JSONUtil.toBean(fsIntegralOrder.getItemJson(), FsIntegralGoods.class);
|
|
|
+ fsIntegralGoodsMapper.addStock(integralGoods.getGoodsId(), Objects.isNull(integralGoods.getNum()) ? 1 : integralGoods.getNum());
|
|
|
+ }
|
|
|
+
|
|
|
+ //还原金额
|
|
|
+ List<FsStorePayment> payments = storePaymentMapper.selectFsStorePaymentByPay(6,fsIntegralOrder.getOrderId());
|
|
|
+ if(payments!=null&&payments.size()==1){
|
|
|
+ FsStorePayment payment=payments.get(0);
|
|
|
+ V2TradePaymentScanpayRefundRequest request = new V2TradePaymentScanpayRefundRequest();
|
|
|
+ request.setOrdAmt(payment.getPayMoney().toString());
|
|
|
+ request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
|
|
|
+ request.setReqSeqId("refund-"+payment.getPayCode());
|
|
|
+ Map<String, Object> extendInfoMap = new HashMap<>();
|
|
|
+ extendInfoMap.put("org_req_seq_id", "integral-"+payment.getPayCode());
|
|
|
+ request.setExtendInfo(extendInfoMap);
|
|
|
+ HuiFuRefundResult refund = huiFuService.refund(request);
|
|
|
+ log.info("积分退款返回结果:积分订单id:"+fsIntegralOrder.getOrderId()+refund);
|
|
|
+ if((refund.getResp_code().equals("00000000")||refund.getResp_code().equals("00000100"))&&(refund.getTrans_stat().equals("S")||refund.getTrans_stat().equals("P"))){
|
|
|
+ FsStorePayment paymentMap=new FsStorePayment();
|
|
|
+ paymentMap.setPaymentId(payment.getPaymentId());
|
|
|
+ paymentMap.setStatus(-1);
|
|
|
+ paymentMap.setRefundTime(DateUtils.getNowDate());
|
|
|
+ paymentMap.setRefundMoney(payment.getPayMoney());
|
|
|
+ storePaymentMapper.updateFsStorePayment(paymentMap);
|
|
|
+ TemplateBean templateBean = TemplateBean.builder()
|
|
|
+ .orderId(fsIntegralOrder.getOrderId().toString())
|
|
|
+ .title("订单已取消")
|
|
|
+ .remark("您的订单已取消")
|
|
|
+ .uid(fsIntegralOrder.getUserId())
|
|
|
+ .templateType(TemplateListenEnum.TYPE_1.getValue())
|
|
|
+ .build();
|
|
|
+ publisher.publishEvent(new TemplateEvent(this, templateBean));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return i;
|
|
|
}
|