package com.hx.phip.service.refund.impl;
|
|
import javax.annotation.Resource;
|
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.hx.common.dao.CommonDao;
|
import com.hx.common.service.CommonService;
|
import com.hx.phiappt.common.*;
|
import com.hx.phiappt.constants.enums.ApprovalTypeEnum;
|
import com.hx.phiappt.constants.tool.JbpmTaskComTool;
|
import com.hx.phiappt.constants.tool.RefundToolUtil;
|
import com.hx.phiappt.model.*;
|
import com.hx.phiappt.model.refund.*;
|
import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed;
|
import com.hx.phiappt.vo.workFlow.JbpmParamVo;
|
import com.hx.phip.config.CustomParameter;
|
import com.hx.phip.dao.mapper.*;
|
import com.hx.phip.service.SystemParameterService;
|
import com.hx.phip.util.api.ApiOrderUtil;
|
import com.hx.phip.util.api.RefundUtil;
|
import com.hx.phip.util.api.UserMoneyUtil;
|
import com.hx.util.StringUtils;
|
import com.hz.his.dto.refund.RefundFundsDto;
|
import com.platform.exception.PlatTipsException;
|
import com.platform.resultTool.PlatformCode;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.hx.exception.TipsException;
|
import com.hx.phip.service.refund.RefundRecordService;
|
import com.hx.mybatisTool.SqlSentence;
|
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
@Transactional
|
@Service
|
public class RefundRecordServiceImpl implements RefundRecordService {
|
|
// log4j日志
|
private static final Logger logger = LoggerFactory.getLogger(RefundRecordServiceImpl.class.getName());
|
|
@Resource
|
private CommonDao commonDao;
|
@Resource
|
private CustomParameter customParameter;
|
@Resource
|
private RefundRecordMapper refundRecordMapper;
|
@Resource
|
private SystemParameterService systemParameterService;
|
|
/**查询列表*/
|
@Override
|
public List<RefundRecord> selectList(SqlSentence sqlSentence) {
|
return refundRecordMapper.selectList(sqlSentence);
|
}
|
|
/**查询列表*/
|
@Override
|
public List<Map<String,Object>> selectListMap(SqlSentence sqlSentence) {
|
return refundRecordMapper.selectListMap(sqlSentence);
|
}
|
|
/**查询单个*/
|
@Override
|
public RefundRecord selectOne(SqlSentence sqlSentence) {
|
return refundRecordMapper.selectOne(sqlSentence);
|
}
|
|
/**查询单个*/
|
@Override
|
public Map<String,Object> selectOneMap(SqlSentence sqlSentence) {
|
return refundRecordMapper.selectOneMap(sqlSentence);
|
}
|
|
/**查询单个,大数据不拿取*/
|
@Override
|
public RefundRecord selectOneByKey(Object object) {
|
return refundRecordMapper.selectOneByKey(object);
|
}
|
|
/**查询单个,大数据拿取*/
|
@Override
|
public RefundRecord selectOneByKeyBlob(Object object) {
|
return refundRecordMapper.selectOneByKeyBlob(object);
|
}
|
|
/**新增*/
|
@Override
|
public void insert(RefundRecord refundRecord) {
|
int count = refundRecordMapper.insert(refundRecord);
|
if(count != 1) {
|
throw new TipsException("新增失败!");
|
}
|
}
|
|
/**修改*/
|
@Override
|
public void updateAll(RefundRecord refundRecord) {
|
int count = refundRecordMapper.updateAll(refundRecord);
|
if(count!=1) {
|
throw new TipsException("保存失败!");
|
}
|
}
|
|
/**修改*/
|
@Override
|
public void updateWhere(SqlSentence sqlSentence) {
|
int count = refundRecordMapper.updateWhere(sqlSentence);
|
if(count!=1) {
|
throw new TipsException("保存失败!");
|
}
|
}
|
|
/**删除一个*/
|
@Override
|
public void deleteOne(String delId) {
|
int count = refundRecordMapper.deleteById(delId);
|
if(count!=1) {
|
throw new TipsException("删除失败!");
|
}
|
}
|
|
@Override
|
public RefundRecord selectOrderId(String orderId) {
|
return refundRecordMapper.selectOrderId(orderId);
|
}
|
|
@Override
|
public Map<String, Object> refund(JSONArray refundPayMethodList,String remarks, String operatorId, String shopId, String userId, CommonService commonService) {
|
Map<String, String> operator = ApiOrderUtil.getOperator(commonService, operatorId);//获取操作人信息
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String,Object> map=new HashMap<>();
|
sqlSentence.setM(map);
|
|
String totalCode = systemParameterService.createRecordNo("R", 16, "yyyyMMddHHmmss"); //总订单编号
|
BigDecimal sumMoney=BigDecimal.ZERO;
|
RefundRecord refundRecord =null;
|
RefundRecordItem refundRecordItem=null;
|
RefundRecordMethod refundRecordMethod=null;
|
|
Shop shop =commonService.selectOneByKey(ShopMapper.class,shopId);
|
if(shop==null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到操作人的门店信息");
|
}
|
//退款总记录
|
refundRecord=new RefundRecord(totalCode,shop.getId(),shop.getName(),sumMoney,OrderTotalConstants.STATUS_REFUND_APPLY,1, RefundSoruceConstants.TYPE_SOURCE_ORDER,remarks,null,userId);
|
// refundRecordService.insert(refundRecord);
|
commonService.insert(RefundRecordMapper.class,refundRecord);
|
|
List<PaymentMethod> payMethodList=null;
|
//记录退回客户的支付方式
|
for(int i=0;i<refundPayMethodList.size();i++){
|
|
JSONObject jsonObject = refundPayMethodList.getJSONObject(i);
|
String payMethodNo = jsonObject.getString("payMethodNo");//支付方式编码
|
BigDecimal money = jsonObject.getBigDecimal("money");//实退金额
|
String payee = jsonObject.getString("payee");//收款方
|
String openBank = jsonObject.getString("openBank");//开户行
|
String openBranch = jsonObject.getString("openBranch");//开户支行
|
String account = jsonObject.getString("account");//账号
|
String remark = jsonObject.getString("remarks");//备注
|
map.put("method",payMethodNo);
|
sqlSentence.setSqlSentence("select * from payment_method where numberNo=#{m.method} and isDel=0 and isUp=1");
|
PaymentMethod paymentMethod =commonService.selectOne(PaymentMethodMapper.class,sqlSentence);
|
if(paymentMethod==null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到该支付方式编码"+payMethodNo);
|
}
|
if(money ==null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"实退金额为空");
|
}
|
sumMoney=sumMoney.add(money);
|
refundRecordMethod=new RefundRecordMethod(payMethodNo,paymentMethod.getName(),money, ConsumePayConstants.STATUS_ORDER,null,refundRecord.getId(),paymentMethod.getId());
|
refundRecordMethod.setPayee(payee);
|
refundRecordMethod.setOpenBank(openBank);
|
refundRecordMethod.setOpenBranch(openBranch);
|
refundRecordMethod.setAccount(account);
|
refundRecordMethod.setRemarks(remark);
|
commonService.insert(RefundRecordMethodMapper.class,refundRecordMethod);
|
// if(PayMethodTypeConstants.PAY_STORED.equals(paymentMethod.getNumberNo())){
|
payMethodList=new ArrayList();
|
payMethodList.add(paymentMethod);
|
// }
|
}
|
//保存退款详情订单
|
refundRecordItem = new RefundRecordItem(payMethodList.get(0).getNumberNo(), payMethodList.get(0).getName(), payMethodList.get(0).getId(), 0, sumMoney, "", refundRecord.getId(), "[]", "");
|
refundRecordItem.setType("userMoney");
|
commonService.insert(RefundRecordItemMapper.class,refundRecordItem);
|
//处理提交审核流程
|
JbpmParamVo jbpmParamVo = new JbpmParamVo();
|
jbpmParamVo.setType(ApprovalTypeEnum.CHARGEBACK.getCode());
|
jbpmParamVo.setShopId(refundRecord.getRefundShopId());
|
jbpmParamVo.setTotal(sumMoney);
|
jbpmParamVo.setAmount(sumMoney);
|
jbpmParamVo.setApplyId(refundRecord.getId());
|
jbpmParamVo.setOrderId(refundRecord.getId());
|
Integer integer = JbpmTaskComTool.checkConditions(jbpmParamVo, commonService);
|
if(integer==null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"预约系统的审核流程接口返回为空");
|
}
|
if(integer==0){
|
//没有审批流程走完成退款流程
|
RefundToolUtil.completeRefund(commonService,operator.get("operatorId"),operator.get("operatorName"),refundRecord.getId(),customParameter.getAesFixedKey());
|
}else if(integer==1){
|
Integer data = JbpmTaskComTool.checkConditionsWithInsert(jbpmParamVo, commonService);
|
if(data==0){
|
// logger.info("无退款流程,请添加重试,退款订单:"+refundRecord.getId());
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"审核退款任务生成失败,请重试");
|
}
|
}else if(integer==2){
|
//没有审批流程走完成退款流程
|
RefundToolUtil.completeRefund(commonService,operator.get("operatorId"),operator.get("operatorName"),refundRecord.getId(),customParameter.getAesFixedKey());
|
}
|
//返回数据
|
Map<String,Object> data=new HashMap<>();
|
data.put("refundRecordId",refundRecord.getId());
|
data.put("refundRecordCode",refundRecord.getCode());
|
return data;
|
}
|
|
/**查询条数*/
|
@Override
|
public int selectCount(SqlSentence sqlSentence) {
|
int count = refundRecordMapper.selectCount(sqlSentence);
|
return count;
|
}
|
|
@Override
|
public void refundAduit(CommonService commonService, String operationId,String operationNme, String refundId, CustomParameter customParameter,String appIdCode) {
|
RefundUtil.refundProcess(commonService, operationId, operationNme, refundId, customParameter, appIdCode,1);
|
}
|
|
@Override
|
public void reject(RefundRecord refundRecord,String refundId,CommonService commonService) {
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String,Object> map=new HashMap<>();
|
sqlSentence.setM(map);
|
map.put("isDel", BaseEntity.NO);
|
map.put("refundId", refundId);
|
//拒绝退款
|
map.put("refundStatus", RefundStatus.STATUS_FAIL_REFUND);
|
map.put("oldRefundStatus", RefundStatus.STATUS_APPLY_REFUND);
|
sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus} where id=#{m.refundId} and isDel=#{m.isDel} and refundStatus=#{m.oldRefundStatus}");
|
commonService.updateWhere(RefundRecordMapper.class,sqlSentence);
|
|
//更新总订单状态
|
map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_REFUSED);
|
map.put("status", OrderTotalConstants.STATUS_DONE);
|
map.put("oldRefundStatus", RefundStatus.STATUS_APPLY_REFUND);
|
map.put("orderId", refundRecord.getOrderId());
|
map.put("isDel", BaseEntity.NO);
|
sqlSentence.setSqlSentence(" status=#{m.status},refundStatus=#{m.refundStatus} where id=#{m.orderId} and isDel=#{m.isDel} and refundStatus=#{m.oldRefundStatus}");
|
commonService.updateWhere(OrdersTotalMapper.class,sqlSentence);
|
}
|
|
/**
|
* 获取支付方法
|
* @param code 编号
|
* @return 返回
|
*/
|
private PaymentMethod getPaymentMethodByCode(String code){
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String, Object> sqlValues = new HashMap<>();
|
sqlValues.put("method", code);
|
sqlValues.put("isDel", BaseEntity.NO);
|
String sql = "select * from payment_method where numberNo=#{m.method} and isDel=#{m.isDel}";
|
sqlSentence.sqlSentence(sql, sqlValues);
|
return commonDao.selectOne(PaymentMethodMapper.class, sqlSentence);
|
}
|
|
/**
|
* 获取退款客户的支付方式
|
* @param refundRecordId 退款总记录标识
|
* @return 返回
|
*/
|
private RefundRecordMethod getRefundRecordMethodByRefundRecordId(String refundRecordId){
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String, Object> sqlValues = new HashMap<>();
|
sqlValues.put("refundRecordId", refundRecordId);
|
sqlValues.put("isDel", BaseEntity.NO);
|
String sql = "select * from refund_record_method where refundRecordId=#{m.refundRecordId} and isDel=#{m.isDel}";
|
sqlSentence.sqlSentence(sql, sqlValues);
|
return commonDao.selectOne(RefundRecordMethodMapper.class, sqlSentence);
|
}
|
|
/**
|
* 获取退款客户的审核记录
|
* @param refundRecordId 退款总记录标识
|
* @return 返回
|
*/
|
private RefundApprove getRefundApproveByRefundRecordId(String refundRecordId){
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String, Object> sqlValues = new HashMap<>();
|
sqlValues.put("isDel", BaseEntity.NO);
|
sqlValues.put("refundRecordId", refundRecordId);
|
String sql = "select * from refund_approve where refundRecordId=#{m.refundRecordId} and isDel=#{m.isDel}";
|
sqlSentence.sqlSentence(sql, sqlValues);
|
return commonDao.selectOne(RefundApproveMapper.class, sqlSentence);
|
}
|
|
/**
|
* 操作用户资金
|
* @param refundRecord 资金记录
|
* @param type 是否为提现处理 0 否 1 是 (否就是表示为不通过返回资金)
|
*/
|
private void opUserMoneyUnclaimed(RefundRecord refundRecord, Integer type) {
|
// 构建操作资金对象
|
UserMoneyUnclaimed userMoneyUnclaimed = new UserMoneyUnclaimed();
|
userMoneyUnclaimed.setUserId(refundRecord.getUserId());
|
userMoneyUnclaimed.setFundType(UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND);
|
userMoneyUnclaimed.setOriginChannel(OriginChannelConstants.ORIGIN_CHANNEL_PHIS);
|
userMoneyUnclaimed.setOperationReason(OperationReasonConstants.OP_REASON_WITHDRAW);
|
userMoneyUnclaimed.setCommonId(refundRecord.getId());
|
// 处理操作人信息
|
if (RefundRecord.OPERATOR_TYPE_EMPLOYEE == refundRecord.getOperatorType()) {
|
userMoneyUnclaimed.setOperatorType(UserMoneyUnclaimed.OPERATOR_TYPE_EMPLOYEE);
|
userMoneyUnclaimed.setOperatorId(refundRecord.getOperatorId());
|
userMoneyUnclaimed.setOperatorName(refundRecord.getOperatorName());
|
}
|
if (RefundRecord.OPERATOR_TYPE_USER == refundRecord.getOperatorType()) {
|
userMoneyUnclaimed.setOperatorType(UserMoneyUnclaimed.OPERATOR_TYPE_USER);
|
userMoneyUnclaimed.setOperatorId(refundRecord.getOperatorId());
|
userMoneyUnclaimed.setOperatorName(refundRecord.getOperatorName());
|
}
|
if (RefundRecord.OPERATOR_TYPE_ADMIN == refundRecord.getOperatorType()) {
|
userMoneyUnclaimed.setOperatorType(UserMoneyUnclaimed.OPERATOR_TYPE_ADMIN);
|
userMoneyUnclaimed.setOperatorId(refundRecord.getOperatorId());
|
userMoneyUnclaimed.setOperatorName(refundRecord.getOperatorName());
|
}
|
String info;
|
String title = "客户储值金提现";
|
if (BaseEntity.YES.equals(type)) {
|
title += "-提现冻结金额";
|
info = ", 提现冻结金额等待审核出款";
|
userMoneyUnclaimed.setOpNumber(refundRecord.getRefundTotal().negate());
|
} else {
|
title += "-回退冻结金额";
|
info = ", 回退冻结金额审核不通过";
|
userMoneyUnclaimed.setOpNumber(refundRecord.getRefundTotal());
|
}
|
info = title + info +", 提现金额:" + refundRecord.getRefundTotal();
|
// 标题
|
userMoneyUnclaimed.setOriginSubject(title);
|
// 备注
|
userMoneyUnclaimed.setRemarks(info);
|
// 调用工具类处理
|
UserMoneyUtil.addUserMoneyUnclaimedData(userMoneyUnclaimed);
|
}
|
|
/**
|
* 审核处理
|
* @param refundFundsDto 参数
|
* @param refundRecord 退款对象
|
* @param type 状态 0 审核失败 1 审核成功
|
*/
|
private void handlerApprove(RefundFundsDto refundFundsDto, RefundRecord refundRecord, Integer type) {
|
RefundApprove refundApprove = this.getRefundApproveByRefundRecordId(refundRecord.getId());
|
if (refundApprove != null) {
|
// 营销助手审批标识
|
refundApprove.setApplyId(refundFundsDto.getApplyId());
|
// 审核员
|
Employee employee = commonDao.selectOneByKey(EmployeeMapper.class, refundFundsDto.getExamEmplId());
|
if (employee != null) {
|
refundApprove.setExamManId(employee.getId());
|
refundApprove.setExamManName(employee.getCnName());
|
}
|
// 是否审核 0 审核失败 1 审核成功
|
if (BaseEntity.YES.equals(type)) {
|
refundApprove.setApprovalStatus(RefundApprove.SUCCESS);
|
} else {
|
refundApprove.setApprovalStatus(RefundApprove.FAIL);
|
}
|
// 备注
|
if (!StringUtils.isEmpty(refundFundsDto.getRemarks())) {
|
refundApprove.setRemarks(refundFundsDto.getRemarks());
|
}
|
// 更新时间
|
refundApprove.setEditTime(new Date());
|
// 处理
|
commonDao.updateAll(RefundApproveMapper.class, refundApprove);
|
}
|
}
|
|
/**
|
* 用户资金退款
|
* @param refundFundsDto 参数
|
*/
|
@Override
|
public String refundUserFunds(RefundFundsDto refundFundsDto) {
|
// 用户判断
|
User user = commonDao.selectOneByKey(UserMapper.class, refundFundsDto.getUserId());
|
if (user == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "用户信息不存在!");
|
}
|
// 门店判断
|
Shop shop = commonDao.selectOneByKey(ShopMapper.class, refundFundsDto.getShopId());
|
if (shop == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "门店信息不存在!");
|
}
|
// 退款总记录
|
RefundRecord refundRecord = new RefundRecord();
|
// 操作人为员工
|
if (RefundRecord.OPERATOR_TYPE_EMPLOYEE == refundFundsDto.getOperatorType()) {
|
Employee employee = commonDao.selectOneByKey(EmployeeMapper.class, refundFundsDto.getOperatorId());
|
if (employee == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作人的信息不存在");
|
} else {
|
refundRecord.setOperatorType(RefundRecord.OPERATOR_TYPE_EMPLOYEE);
|
refundRecord.setOperatorId(employee.getId());
|
refundRecord.setOperatorName(employee.getCnName());
|
}
|
}
|
|
// 操作人为后台用户
|
if (RefundRecord.OPERATOR_TYPE_ADMIN == refundFundsDto.getOperatorType()) {
|
SysAdmin sysAdmin = commonDao.selectOneByKey(SysAdminMapper.class, refundFundsDto.getOperatorId());
|
if (sysAdmin == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作人的信息不存在");
|
} else {
|
refundRecord.setOperatorType(RefundRecord.OPERATOR_TYPE_ADMIN);
|
refundRecord.setOperatorId(sysAdmin.getId());
|
refundRecord.setOperatorName(sysAdmin.getName());
|
}
|
}
|
|
// 操作人为用户
|
if (RefundRecord.OPERATOR_TYPE_USER == refundFundsDto.getOperatorType()) {
|
User opUser = commonDao.selectOneByKey(UserMapper.class, refundFundsDto.getOperatorId());
|
if (opUser == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作人的信息不存在");
|
} else {
|
refundRecord.setOperatorType(RefundRecord.OPERATOR_TYPE_USER);
|
refundRecord.setOperatorId(opUser.getId());
|
refundRecord.setOperatorName(opUser.getName());
|
}
|
}
|
// 退款记录单号
|
String totalCode = systemParameterService.createRecordNo("R", 16, "yyyyMMddHHmmss");
|
refundRecord.setRefundType(1);
|
refundRecord.setCode(totalCode);
|
refundRecord.setUserId(user.getId());
|
refundRecord.setRefundStatus(OrderTotalConstants.STATUS_REFUND_APPLY);
|
refundRecord.setRefundShopId(shop.getId());
|
refundRecord.setRefundShopName(shop.getName());
|
refundRecord.setRefundTotal(refundFundsDto.getRefundTotal());
|
refundRecord.setRealRefundTotal(refundFundsDto.getRefundTotal());
|
refundRecord.setSourceType(RefundSoruceConstants.TYPE_SOURCE_USER);
|
refundRecord.setRemarks(refundRecord.getRemarks());
|
// 插入数据
|
int count = refundRecordMapper.insert(refundRecord);
|
if (count != 1) {
|
throw new TipsException("新增失败!");
|
} else {
|
// 获取银行卡退款方式
|
PaymentMethod bank = getPaymentMethodByCode("PM95");
|
if (bank == null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "银行卡支付方式不存在");
|
}
|
// 获取储值金退款方式
|
PaymentMethod storedValueFund = getPaymentMethodByCode("00000");
|
if (storedValueFund == null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "储值金支付方式不存在");
|
}
|
|
// 退款方式转换表
|
RefundMethodTransformation refundMethodTransformation = new RefundMethodTransformation();
|
refundMethodTransformation.setRefundRecordId(refundRecord.getId());
|
refundMethodTransformation.setPayMethodNo(storedValueFund.getNumberNo());
|
refundMethodTransformation.setPayMethodName(storedValueFund.getName());
|
refundMethodTransformation.setPayTotal(refundFundsDto.getRefundTotal());
|
refundMethodTransformation.setRefundNumberNo(bank.getNumberNo());
|
refundMethodTransformation.setRefundNumberName(bank.getName());
|
refundMethodTransformation.setRefundTotal(refundFundsDto.getRefundTotal());
|
commonDao.insert(RefundMethodTransformationMapper.class, refundMethodTransformation);
|
|
// 退款方式处理
|
RefundRecordMethod refundRecordMethod = new RefundRecordMethod();
|
refundRecordMethod.setNumberNo(storedValueFund.getNumberNo());
|
refundRecordMethod.setRefundNumberNo(bank.getNumberNo());
|
refundRecordMethod.setName(storedValueFund.getName());
|
refundRecordMethod.setPaymentMethodId(storedValueFund.getId());
|
refundRecordMethod.setActualTotal(refundFundsDto.getRefundTotal());
|
refundRecordMethod.setRealRefundTotal(refundFundsDto.getRefundTotal());
|
refundRecordMethod.setIsMoneyPay(BaseEntity.NO);
|
refundRecordMethod.setIsExecute(BaseEntity.NO);
|
refundRecordMethod.setIsPay(BaseEntity.NO);
|
refundRecordMethod.setType(ConsumePayConstants.STATUS_WITHDRAW);
|
refundRecordMethod.setRefundRecordId(refundRecord.getId());
|
refundRecordMethod.setPayee(refundFundsDto.getPayee());
|
refundRecordMethod.setOpenBank(refundFundsDto.getOpenBank());
|
refundRecordMethod.setOpenBranch(refundFundsDto.getOpenBranch());
|
refundRecordMethod.setAccount(refundFundsDto.getAccount());
|
refundRecordMethod.setRemarks(refundFundsDto.getRemarks());
|
commonDao.insert(RefundRecordMethodMapper.class, refundRecordMethod);
|
|
// 退款审批处理
|
RefundApprove refundApprove = new RefundApprove();
|
refundApprove.setRefundRecordId(refundRecord.getId());
|
refundApprove.setOperatorType(refundRecord.getOperatorType());
|
refundApprove.setOperatorId(refundApprove.getOperatorId());
|
refundApprove.setOperatorName(refundApprove.getOperatorName());
|
Employee opEmployee = commonDao.selectOneByKey(EmployeeMapper.class, refundFundsDto.getOperatorId());
|
if (opEmployee != null) {
|
refundApprove.setOperatorType(RefundRecord.OPERATOR_TYPE_EMPLOYEE);
|
refundApprove.setOperatorId(opEmployee.getId());
|
refundApprove.setOperatorName(opEmployee.getCnName());
|
refundApprove.setRoleId(opEmployee.getRoleId());
|
refundApprove.setRoleStr(opEmployee.getRoleStr());
|
}
|
refundApprove.setShopId(shop.getId());
|
refundApprove.setShopName(shop.getName());
|
refundApprove.setIsApproval(BaseEntity.YES);
|
refundApprove.setPlatformSource(refundFundsDto.getPlatformSource());
|
commonDao.insert(RefundApproveMapper.class, refundApprove);
|
// 先减扣冻结用户资金处理
|
this.opUserMoneyUnclaimed(refundRecord, BaseEntity.YES);
|
}
|
return refundRecord.getId();
|
}
|
|
/**
|
* 用户资金退款审核
|
* @param refundFundsDto 参数
|
*/
|
@Override
|
public void refundUserFundsApprove(RefundFundsDto refundFundsDto) {
|
RefundRecord refundRecord = refundRecordMapper.selectOneByKey(refundFundsDto.getRefundId());
|
if (refundRecord == null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录不存在");
|
}
|
if(OrderTotalConstants.STATUS_REFUND_APPLY != refundRecord.getRefundStatus()
|
&& OrderTotalConstants.STATUS_REFUND_WAIT != refundRecord.getRefundStatus()) {
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录已被操作请不要重复操作!");
|
}
|
RefundRecordMethod refundRecordMethod = getRefundRecordMethodByRefundRecordId(refundRecord.getId());
|
if (refundRecordMethod == null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录的退款方式不存在");
|
}
|
if (!ConsumePayConstants.STATUS_WITHDRAW.equals(refundRecordMethod.getType())){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录不是提现单!");
|
}
|
// 审核通过处理
|
if (BaseEntity.YES.equals(refundFundsDto.getType())){
|
refundRecord.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH);
|
} else {
|
refundRecord.setRefundStatus(OrderTotalConstants.STATUS_REFUND_REFUSED);
|
}
|
// 备注处理
|
if (!StringUtils.isEmpty(refundFundsDto.getRemarks())) {
|
refundRecord.setRemarks(refundFundsDto.getRemarks());
|
}
|
refundRecord.setEditTime(new Date());
|
int count = refundRecordMapper.updateAll(refundRecord);
|
if(count!=1) {
|
throw new TipsException("保存失败!");
|
} else {
|
// 审核通过处理
|
if (BaseEntity.YES.equals(refundFundsDto.getType())){
|
refundRecordMethod.setIsPay(BaseEntity.YES);
|
refundRecordMethod.setEditTime(new Date());
|
// 更新数据
|
commonDao.updateAll(RefundRecordMethodMapper.class, refundRecordMethod);
|
// 审核成功
|
handlerApprove(refundFundsDto, refundRecord, BaseEntity.YES);
|
} else {
|
// 审核失败
|
handlerApprove(refundFundsDto, refundRecord, BaseEntity.NO);
|
// 审核不通过退回资金
|
this.opUserMoneyUnclaimed(refundRecord, BaseEntity.NO);
|
}
|
}
|
}
|
|
/**
|
* 用户资金退款作废
|
* @param refundFundsDto 参数
|
*/
|
@Override
|
public void refundUserFundsCancel(RefundFundsDto refundFundsDto) {
|
RefundRecord refundRecord = refundRecordMapper.selectOneByKey(refundFundsDto.getRefundId());
|
if (refundRecord == null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录不存在");
|
}
|
if(OrderTotalConstants.STATUS_REFUND_APPLY != refundRecord.getRefundStatus()
|
&& OrderTotalConstants.STATUS_REFUND_WAIT != refundRecord.getRefundStatus()) {
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录已被操作请不要重复操作!");
|
}
|
RefundRecordMethod refundRecordMethod = getRefundRecordMethodByRefundRecordId(refundRecord.getId());
|
if (refundRecordMethod == null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录的退款方式不存在");
|
}
|
if (!ConsumePayConstants.STATUS_WITHDRAW.equals(refundRecordMethod.getType())){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录不是提现单!");
|
}
|
// 作废处理
|
refundRecord.setRefundStatus(OrderTotalConstants.STATUS_REFUND_REVOKE);
|
// 备注处理
|
if (!StringUtils.isEmpty(refundFundsDto.getRemarks())) {
|
refundRecord.setRemarks(refundFundsDto.getRemarks());
|
}
|
refundRecord.setEditTime(new Date());
|
int count = refundRecordMapper.updateAll(refundRecord);
|
if(count!=1) {
|
throw new TipsException("保存失败!");
|
} else {
|
// 审核失败
|
handlerApprove(refundFundsDto, refundRecord, BaseEntity.NO);
|
// 审核不通过退回资金
|
this.opUserMoneyUnclaimed(refundRecord, BaseEntity.NO);
|
}
|
}
|
}
|