package com.hx.phip.controller.order; 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.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.order.OrderRefundService; import com.hx.phip.service.refund.RefundRecordService; 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.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.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.util.HashMap; import java.util.List; import java.util.Map; /** * @Author 部分退款工具类 */ @RestController @RequestMapping("/order") public class OrderRefundController { @Resource private OrderRefundService orderRefundService; @Resource private CommonService commonService; @Resource private OrdersTotalService ordersTotalService; @Resource private RefundRecordService refundRecordService; @Resource private EmployeeService employeeService; @Resource private EmployeeRoleService employeeRoleService; /** 部分退款显示数据接口-获取可退款数量*/ @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 returnMap = new HashMap<>(); returnMap.put("details",ordersTotal); List> 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 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); /* //TODO 测试 thirtApplication = new ThirtApplication(); thirtApplication.setAppId("54654asdf56sd1e1gv567as1"); thirtApplication.setName("PHI"); thirtApplication.setAppIdCode("his");*/ 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,"是否自动生成退款单不能为空"); } 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,"是否自动生成退款单不能为空"); } SqlSentence sqlSentence = new SqlSentence(); Map 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 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 = "/verify/order/refundStatus",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(); } }