package com.hx.phip.controller.refund;
|
|
import com.alibaba.fastjson.JSON;
|
import com.hx.common.service.CommonService;
|
import com.hx.exception.TipsException;
|
import com.hx.mybatisTool.SqlSentence;
|
import com.hx.phiappt.common.OrderTotalConstants;
|
import com.hx.phiappt.dao.mapper.OrdersTotalMapper;
|
import com.hx.phiappt.model.BaseEntity;
|
import com.hx.phiappt.model.Employee;
|
import com.hx.phiappt.model.EmployeeRole;
|
import com.hx.phiappt.model.consume.ConsumeNotify;
|
import com.hx.phiappt.model.order.OrdersTotal;
|
import com.hx.phiappt.model.refund.RefundRecord;
|
import com.hx.phip.service.EmployeeRoleService;
|
import com.hx.phip.service.EmployeeService;
|
import com.hx.phip.service.OrdersTotalService;
|
import com.hx.phip.service.consume.ConsumeNotifyService;
|
import com.hx.phip.service.order.OrderRefundService;
|
import com.hx.phip.service.refund.RefundRecordService;
|
import com.hx.phip.tool.payment.ConsumeTool;
|
import com.hx.resultTool.Result;
|
import com.hx.util.StringUtils;
|
import com.hz.his.dto.order.OrderRefundDto;
|
import com.hz.his.vo.order.refund.RefundCancelVo;
|
import com.hz.his.vo.order.refund.qr.RefundQrVo;
|
import com.platform.constants.LoginConstant;
|
import com.platform.entity.ThirtApplication;
|
import com.platform.exception.PlatTipsException;
|
import com.platform.resultTool.PlatformCode;
|
import com.platform.resultTool.PlatformResult;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import java.math.BigDecimal;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @Author 部分退款工具类
|
*/
|
@RestController
|
@RequestMapping("/order")
|
public class OrderRefundController {
|
|
private static final Logger logger = LoggerFactory.getLogger(OrderRefundController.class);
|
|
@Resource
|
private OrderRefundService orderRefundService;
|
@Resource
|
private CommonService commonService;
|
@Resource
|
private OrdersTotalService ordersTotalService;
|
@Resource
|
private RefundRecordService refundRecordService;
|
@Resource
|
private EmployeeService employeeService;
|
@Resource
|
private EmployeeRoleService employeeRoleService;
|
@Resource
|
private ConsumeNotifyService consumeNotifyService;
|
|
|
/** 部分退款显示数据接口-获取可退款数量*/
|
@RequestMapping("/refund/details")
|
public Result refundDetails(@RequestBody OrderRefundDto orderRefundDto){
|
if (StringUtils.isEmpty(orderRefundDto.getOrderId())) {
|
throw new TipsException("订单标识为空!");
|
}
|
OrdersTotal ordersTotal = ordersTotalService.selectOneByKey(orderRefundDto.getOrderId());
|
if (ordersTotal == null) {
|
throw new TipsException("订单标识错误!");
|
}
|
if(ordersTotal.getIsDel().equals(OrdersTotal.YES)){
|
throw new TipsException("订单处于删除状态!");
|
}
|
|
if (OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())) {
|
throw new TipsException("充值订单不支持部分退款!");
|
}
|
|
if(OrderTotalConstants.PAY_STATUS_SUC != ordersTotal.getPayStatus()){
|
throw new TipsException("订单未支付!");
|
}
|
|
if(OrderTotalConstants.STATUS_PAY != ordersTotal.getStatus()
|
&& OrderTotalConstants.STATUS_WAIT_RECEIVE != ordersTotal.getStatus()
|
&& OrderTotalConstants.STATUS_DONE != ordersTotal.getStatus()){
|
throw new TipsException("当前订单状态不能退款!");
|
}
|
|
if(OrderTotalConstants.STATUS_REFUND_NONE != ordersTotal.getRefundStatus()
|
&& OrderTotalConstants.STATUS_REFUND_PART != ordersTotal.getRefundStatus()){
|
throw new TipsException("订单退款状态不正确!");
|
}
|
|
//返回集合
|
Map<String, Object> returnMap = new HashMap<>();
|
returnMap.put("details",ordersTotal);
|
List<Map<String, Object>> refundDetails=orderRefundService.refundDetails(ordersTotal);
|
returnMap.put("refundDetails",refundDetails);
|
|
return Result.success(returnMap);
|
}
|
|
/** 选完数量点击下一步显示数据接口 */
|
@RequestMapping("/refund/nextStep")
|
public Result nextStep(@RequestBody OrderRefundDto orderRefundDto){
|
if (StringUtils.isEmpty(orderRefundDto.getOrderId())) {
|
throw new TipsException("订单标识为空!");
|
}
|
if (orderRefundDto.getRefundList()==null) {
|
throw new TipsException("退款信息集合为空!");
|
}
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String, Object> sqlMap = new HashMap<>();
|
sqlSentence.setM(sqlMap);
|
sqlMap.put("isDel", BaseEntity.NO);
|
sqlMap.put("orderId", orderRefundDto.getOrderId());
|
|
sqlSentence.setSqlSentence("SELECT * FROM orders_total WHERE id = #{m.orderId} and isDel = #{m.isDel} ");
|
OrdersTotal ordersTotal = ordersTotalService.selectOne(sqlSentence);
|
if (ordersTotal == null) {
|
throw new TipsException("订单标识错误!");
|
}
|
if (OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())) {
|
throw new TipsException("充值订单不支持部分退款!");
|
}
|
if(OrderTotalConstants.PAY_STATUS_SUC != ordersTotal.getPayStatus()){
|
throw new TipsException("订单未支付!");
|
}
|
|
if(OrderTotalConstants.STATUS_PAY != ordersTotal.getStatus()
|
&& OrderTotalConstants.STATUS_WAIT_RECEIVE != ordersTotal.getStatus()
|
&& OrderTotalConstants.STATUS_DONE != ordersTotal.getStatus()){
|
throw new TipsException("当前订单状态不能退款!");
|
}
|
|
if(OrderTotalConstants.STATUS_REFUND_NONE != ordersTotal.getRefundStatus()
|
&& OrderTotalConstants.STATUS_REFUND_PART != ordersTotal.getRefundStatus()){
|
throw new TipsException("订单退款状态不正确!");
|
}
|
|
//返回集合
|
OrderRefundDto returnMap = orderRefundService.nextStep(ordersTotal,orderRefundDto);
|
returnMap.setRefundPayMethod(returnMap.getPayMethodList());
|
returnMap.setCouponList(returnMap.getPayCouponList());
|
return Result.success(returnMap);
|
}
|
|
/**
|
* 部分退款
|
*/
|
@RequestMapping(value = "/partial/refund",method = RequestMethod.POST)
|
public PlatformResult partRefund(HttpServletRequest request, @RequestBody OrderRefundDto orderRefundDto) {
|
//操作平台
|
ThirtApplication thirtApplication = (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY);
|
if(thirtApplication==null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"签名失败,请检查签名!");
|
}
|
|
if(StringUtils.isEmpty(orderRefundDto.getOrderId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单标识不能为空");
|
}
|
|
if(StringUtils.isEmpty(orderRefundDto.getRoleId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作角色标识不能为空");
|
}
|
if(StringUtils.isEmpty(orderRefundDto.getOperatorId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作员工标识不能为空");
|
}
|
|
if(orderRefundDto.getIsApproval()==null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"是否需要审批不能为空");
|
}
|
|
if(orderRefundDto.getIsRefund() == null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"是否自动生成退款单不能为空");
|
}
|
if(orderRefundDto.getRefundStatistics() == null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"退款统计类型不能为空!");
|
}
|
|
OrdersTotal ordersTotal = ordersTotalService.selectOneByKey(orderRefundDto.getOrderId());
|
if (ordersTotal == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"订单标识错误!");
|
}
|
if(ordersTotal.getIsDel().equals(OrdersTotal.YES)){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"订单已删除!");
|
}
|
if (OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())) {
|
throw new TipsException("充值订单不支持部分退款!");
|
}
|
|
orderRefundDto.setRefundOperationType(BaseEntity.YES);
|
return orderRefundService.partRefund(ordersTotal,orderRefundDto,thirtApplication);
|
}
|
|
/**
|
* 全部退款
|
*/
|
@RequestMapping(value = "/whole/refund",method = RequestMethod.POST)
|
public PlatformResult wholeRefund(HttpServletRequest request,@RequestBody OrderRefundDto orderRefundDto) {
|
//操作平台
|
ThirtApplication thirtApplication= (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY);
|
if(thirtApplication==null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"签名失败,请检查签名!");
|
}
|
|
if(StringUtils.isEmpty(orderRefundDto.getOrderId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单id不能为空");
|
}
|
if(StringUtils.isEmpty(orderRefundDto.getOperatorId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作人不能为空");
|
}
|
if(orderRefundDto.getIsApproval()==null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"是否需要审批不能为空");
|
}
|
if(orderRefundDto.getIsRefund()==null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"是否自动生成退款单不能为空");
|
}
|
if(orderRefundDto.getRefundStatistics() == null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"退款统计类型不能为空!");
|
}
|
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String, Object> sqlMap = new HashMap<>();
|
sqlSentence.setM(sqlMap);
|
sqlMap.put("isDel", BaseEntity.NO);
|
sqlMap.put("id", orderRefundDto.getOrderId());
|
sqlSentence.setSqlSentence("SELECT * FROM orders_total WHERE id = #{m.id} and isDel = #{m.isDel} ");
|
OrdersTotal ordersTotal = commonService.selectOne(OrdersTotalMapper.class, sqlSentence);
|
if (ordersTotal == null) {
|
throw new TipsException("订单标识错误!");
|
}
|
if(!(OrderTotalConstants.PAY_STATUS_SUC==ordersTotal.getPayStatus())){
|
throw new TipsException("订单未支付!");
|
}
|
if(!(OrderTotalConstants.STATUS_PAY==ordersTotal.getStatus()) && !(OrderTotalConstants.STATUS_WAIT_RECEIVE==ordersTotal.getStatus()) && !(OrderTotalConstants.STATUS_DONE==ordersTotal.getStatus())){
|
throw new TipsException("订单不是已支付状态!");
|
}
|
|
if(OrderTotalConstants.STATUS_REFUND_NONE!=ordersTotal.getRefundStatus()){
|
throw new TipsException("订单退款状态不正确!");
|
}
|
|
return orderRefundService.wholeRefund(orderRefundDto,thirtApplication);
|
}
|
|
/**
|
* 伪造部分退款处理退款逻辑
|
*
|
*/
|
/*@RequestMapping(value = "/forge/partial/refund",method = RequestMethod.POST)*/
|
public PlatformResult forgePartRefund(@RequestBody OrderRefundDto orderRefundDto) {
|
if(StringUtils.isEmpty(orderRefundDto.getOrderId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单id不能为空");
|
}
|
if(StringUtils.isEmpty(orderRefundDto.getOperatorId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作人不能为空");
|
}
|
if(orderRefundDto.getIsApproval()==null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"是否需要审批不能为空");
|
}
|
if(orderRefundDto.getIsRefund()==null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"是否自动生成退款单不能为空");
|
}
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String, Object> sqlMap = new HashMap<>();
|
sqlSentence.setM(sqlMap);
|
sqlMap.put("isDel", BaseEntity.NO);
|
sqlMap.put("id", orderRefundDto.getOrderId());
|
sqlSentence.setSqlSentence("SELECT * FROM orders_total WHERE id = #{m.id} and isDel = #{m.isDel} ");
|
OrdersTotal ordersTotal = commonService.selectOne(OrdersTotalMapper.class, sqlSentence);
|
if (ordersTotal == null) {
|
throw new TipsException("订单标识错误!");
|
}
|
if(!(OrderTotalConstants.PAY_STATUS_SUC==ordersTotal.getPayStatus())){
|
throw new TipsException("订单未支付!");
|
}
|
if(!(OrderTotalConstants.STATUS_PAY==ordersTotal.getStatus()) && !(OrderTotalConstants.STATUS_WAIT_RECEIVE==ordersTotal.getStatus()) && !(OrderTotalConstants.STATUS_DONE==ordersTotal.getStatus())){
|
throw new TipsException("订单不是已支付状态!");
|
}
|
|
if(!(OrderTotalConstants.STATUS_REFUND_NONE==ordersTotal.getRefundStatus()) &&
|
!(OrderTotalConstants.STATUS_REFUND_PART==ordersTotal.getRefundStatus())){
|
throw new TipsException("订单退款状态不正确!");
|
}
|
/* if (OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())) {
|
throw new TipsException("充值订单不支持部分退款!");
|
}*/
|
orderRefundDto.setRefundOperationType(BaseEntity.YES);
|
return orderRefundService.forgePartRefund(orderRefundDto);
|
}
|
/**
|
* 根据订单 重新绑定订单退款状态
|
*
|
*/
|
@RequestMapping(value = "/verify/order/refundStatus",method = RequestMethod.POST)
|
public PlatformResult verifyOrderRefundStatus(@RequestBody OrdersTotal ordersTotalDto) {
|
if(ordersTotalDto==null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"参数不能为空!");
|
}
|
if(StringUtils.isEmpty(ordersTotalDto.getId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单id不能为空");
|
}
|
orderRefundService.verifyOrderRefundStatus(ordersTotalDto);
|
return PlatformResult.success();
|
}
|
|
/**
|
* 作废订单退款单
|
*
|
*/
|
@RequestMapping(value = "/refund/cancel",method = RequestMethod.POST)
|
public PlatformResult refundCancel(HttpServletRequest request,@RequestBody RefundCancelVo refundCancelVo) {
|
//操作平台
|
ThirtApplication thirtApplication= (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY);
|
if(thirtApplication==null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未获取到操作平台!");
|
}
|
|
if(StringUtils.isEmpty(refundCancelVo.getId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"退款单标识必传!");
|
}
|
RefundRecord refundRecord = refundRecordService.selectOneByKey(refundCancelVo.getId());
|
if(refundRecord == null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款单标识错误!");
|
}
|
if(StringUtils.isEmpty(refundCancelVo.getRemarks())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"作废备注必填!");
|
}
|
if(StringUtils.isEmpty(refundCancelVo.getStaffId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作员工必填!");
|
}
|
Employee employee = employeeService.selectOneByKey(refundCancelVo.getStaffId());
|
if(employee == null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作员工标识错误!");
|
}
|
if(StringUtils.isEmpty(refundCancelVo.getStaffRoleId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作员工角色必填!");
|
}
|
EmployeeRole employeeRole = employeeRoleService.getEmployeeRole(refundCancelVo.getStaffRoleId());
|
if(employeeRole == null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作员工角色标识错误!");
|
}
|
|
orderRefundService.refundCancel(refundCancelVo,refundRecord,employee,employeeRole,thirtApplication);
|
return PlatformResult.success();
|
}
|
|
/**
|
* 订单二维码调起退款
|
* 针对未支付的订单,但是已经使用了订单二维码支付
|
* 只能全部退款,不能部分退款,逻辑删除支付回调记录
|
*/
|
@RequestMapping(value = "/qr/refund",method = RequestMethod.POST)
|
public PlatformResult orderQrRefund(HttpServletRequest request,@RequestBody RefundQrVo refundQrVo) {
|
logger.info("订单二维码调起退款数据:{}", JSON.toJSONString(refundQrVo));
|
|
//操作平台
|
ThirtApplication thirtApplication= (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY);
|
if(thirtApplication==null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未获取到操作平台!");
|
}
|
logger.info("订单二维码调起退款操作平台:{},{},{}", thirtApplication.getAppId(),thirtApplication.getName(),thirtApplication.getAppIdCode());
|
|
if(StringUtils.isEmpty(refundQrVo.getOrderId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单标识必传!");
|
}
|
if(refundQrVo.getRefundTotal() == null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"退款金額!");
|
}
|
if(refundQrVo.getRefundTotal().compareTo(BigDecimal.ZERO) < 1){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"退款金額错误!");
|
}
|
if(StringUtils.isEmpty(refundQrVo.getPayNo())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"支付订单编号必传!");
|
}
|
if(StringUtils.isEmpty(refundQrVo.getEmployeeId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作员工必传!");
|
}
|
Employee employee = employeeService.selectOneByKey(refundQrVo.getEmployeeId());
|
if(employee == null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作员工标识错误!");
|
}
|
|
//找到回调信息
|
ConsumeNotify consumeNotify = ConsumeTool.selectConsumeNotifyByOrderNo(refundQrVo.getOrderId(),refundQrVo.getPayNo(),refundQrVo.getPayNo(),commonService);
|
if(consumeNotify == null){
|
throw new TipsException("未找到支付记录!");
|
}
|
|
return PlatformResult.success( consumeNotifyService.consumeNotifyRefund(consumeNotify,employee,refundQrVo));
|
}
|
|
|
}
|