退款成功

This commit is contained in:
clunt 2022-10-12 14:40:14 +08:00
parent ff2c4e92be
commit 6640c56dc6
2 changed files with 23 additions and 14 deletions

View File

@ -7,6 +7,8 @@ import com.alibaba.fastjson.JSONObject;
import com.ghy.common.adapay.model.AdapayStatusEnum;
import com.ghy.common.adapay.model.PaymentDTO;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.enums.PayStatus;
import com.ghy.common.enums.PayTypeEnum;
import com.ghy.common.exception.base.BaseException;
import com.ghy.common.utils.DateUtils;
import com.ghy.common.utils.ObjectUtils;
@ -122,7 +124,7 @@ public class AfterServiceRecordServiceImpl implements IAfterServiceRecordService
AfterServiceRecord afterServiceRecord = this.selectAfterServiceRecordById(param.getId());
Assert.notNull(afterServiceRecord, "售后记录不存在!");
// 实际同意,需要发起退款减少原单分账金额-调用退款接口
if(param.getCustomerFinalCheck() == 1){
if(param.getCustomerFinalCheck() != null && param.getCustomerFinalCheck() == 1){
OrderDetail orderDetail = orderDetailService.selectById(afterServiceRecord.getOrderDetailId());
Assert.notNull(orderDetail, "子单不存在!");
FinancialDetail financialDetail = financialDetailService.selectByOrderDetailId(afterServiceRecord.getOrderDetailId());
@ -144,23 +146,27 @@ public class AfterServiceRecordServiceImpl implements IAfterServiceRecordService
Assert.notNull(orderMaster, "找不到对应的订单");
FinancialMaster financialMaster = financialMasterService.selectByOrderMasterId(orderDetail.getOrderMasterId());
Assert.notNull(financialMaster, "找不到订单");
Assert.isTrue(financialMaster.getPayStatus() == 1, "订单未支付");
Assert.hasText(financialMaster.getPaymentId(), "找不到订单的支付记录,请联系管理员");
JSONObject response = null;
try {
response = adapayService.payReverse(orderMaster.getDeptId(), financialMaster.getPaymentId(), String.valueOf(refundMoney));
if (AdapayStatusEnum.succeeded.code.equals(response.getString("status"))) {
if(PayTypeEnum.ALIPAY_QR.getCode().equals(orderMaster.getPayType()) && ! PayStatus.PAID.getCode().equals(financialMaster.getPayStatus())){
financialMaster.setPayMoney(financialMaster.getPayMoney().subtract(refundMoney));
financialMasterService.updateFinancialMaster(financialMaster);
financialDetailService.updateFinancialDetail(financialDetail);
}else {
Assert.hasText(financialMaster.getPaymentId(), "找不到订单的支付记录,请联系管理员");
JSONObject response = null;
try {
response = adapayService.payReverse(orderMaster.getDeptId(), financialMaster.getPaymentId(), String.valueOf(refundMoney));
if (AdapayStatusEnum.succeeded.code.equals(response.getString("status"))) {
afterServiceRecord.setCustomerFinalCheck(1L);
financialDetailService.updateFinancialDetail(financialDetail);
if (AdapayStatusEnum.succeeded.code.equals(response.getString("status"))) {
financialDetailService.updateFinancialDetail(financialDetail);
}
}
} catch (BaseAdaPayException e) {
throw new BaseException("发起退款异常!");
}
} catch (BaseAdaPayException e) {
throw new BaseException("发起退款异常!");
}
}
afterServiceRecord.setUpdateTime(DateUtils.getNowDate());
return afterServiceRecordMapper.updateAfterServiceRecord(afterServiceRecord);
param.setUpdateTime(DateUtils.getNowDate());
return afterServiceRecordMapper.updateAfterServiceRecord(param);
}
/**

View File

@ -40,6 +40,9 @@
<if test="refund != null "> and refund = #{refund}</if>
<if test="agreedRefund != null "> and agreed_refund = #{agreedRefund}</if>
<if test="customerFinalCheck != null "> and customer_final_check = #{customerFinalCheck}</if>
<if test="customerFinalCheck == null">
and ( customer_final_check = '0' or customer_final_check is null )
</if>
</where>
</select>
@ -113,7 +116,7 @@
</delete>
<delete id="deleteAfterServiceRecordByIds" parameterType="String">
delete from after_service_record where customer_final_check != 1 and id in
delete from after_service_record where (customer_final_check is NULL or customer_final_check = 0) and id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>