chenjiahe
2023-05-10 7559759bcf2319c0e2f1b036121eebf93fa78021
提交 | 用户 | age
4dc6e5 1 package com.hx.phip.controller.order;
4918c4 2
a2fbbf 3 import com.hx.common.service.CommonService;
Z 4 import com.hx.exception.TipsException;
5 import com.hx.mybatisTool.SqlSentence;
6 import com.hx.phiappt.common.OrderTotalConstants;
7 import com.hx.phiappt.dao.mapper.OrdersTotalMapper;
8 import com.hx.phiappt.model.BaseEntity;
fd7281 9 import com.hx.phiappt.model.Employee;
C 10 import com.hx.phiappt.model.EmployeeRole;
a2fbbf 11 import com.hx.phiappt.model.order.OrdersTotal;
fd7281 12 import com.hx.phiappt.model.refund.RefundRecord;
C 13 import com.hx.phip.service.EmployeeRoleService;
14 import com.hx.phip.service.EmployeeService;
c9e2be 15 import com.hx.phip.service.OrdersTotalService;
4dc6e5 16 import com.hx.phip.service.order.OrderRefundService;
fd7281 17 import com.hx.phip.service.refund.RefundRecordService;
a2fbbf 18 import com.hx.resultTool.Result;
4dc6e5 19 import com.hx.util.StringUtils;
Z 20 import com.hz.his.dto.order.OrderRefundDto;
fd7281 21 import com.hz.his.vo.order.refund.RefundCancelVo;
4df03d 22 import com.platform.constants.LoginConstant;
C 23 import com.platform.entity.ThirtApplication;
4dc6e5 24 import com.platform.exception.PlatTipsException;
Z 25 import com.platform.resultTool.PlatformCode;
26 import com.platform.resultTool.PlatformResult;
27 import org.springframework.web.bind.annotation.RequestBody;
28 import org.springframework.web.bind.annotation.RequestMapping;
29 import org.springframework.web.bind.annotation.RequestMethod;
30 import org.springframework.web.bind.annotation.RestController;
31
32 import javax.annotation.Resource;
4df03d 33 import javax.servlet.http.HttpServletRequest;
a2fbbf 34 import java.util.HashMap;
Z 35 import java.util.List;
36 import java.util.Map;
4dc6e5 37
Z 38 /**
4918c4 39  * @Author  部分退款工具类
4dc6e5 40  */
Z 41 @RestController
42 @RequestMapping("/order")
43 public class OrderRefundController {
44
45     @Resource
46     private OrderRefundService orderRefundService;
a2fbbf 47     @Resource
Z 48     private CommonService commonService;
c9e2be 49     @Resource
Z 50     private OrdersTotalService ordersTotalService;
fd7281 51     @Resource
C 52     private RefundRecordService refundRecordService;
53     @Resource
54     private EmployeeService employeeService;
55     @Resource
56     private EmployeeRoleService employeeRoleService;
118d96 57
4df03d 58     /** 部分退款显示数据接口-获取可退款数量*/
a2fbbf 59     @RequestMapping("/refund/details")
4df03d 60     public Result refundDetails(@RequestBody OrderRefundDto orderRefundDto){
a2fbbf 61         if (StringUtils.isEmpty(orderRefundDto.getOrderId())) {
Z 62             throw new TipsException("订单标识为空!");
63         }
118d96 64         OrdersTotal ordersTotal = ordersTotalService.selectOneByKey(orderRefundDto.getOrderId());
a2fbbf 65         if (ordersTotal == null) {
a026ab 66             throw new TipsException("订单标识错误!");
a2fbbf 67         }
118d96 68         if(ordersTotal.getIsDel().equals(OrdersTotal.YES)){
C 69             throw new TipsException("订单处于删除状态!");
a2fbbf 70         }
542dc1 71
a2fbbf 72         if (OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())) {
Z 73             throw new TipsException("充值订单不支持部分退款!");
74         }
118d96 75
C 76         if(OrderTotalConstants.PAY_STATUS_SUC != ordersTotal.getPayStatus()){
77             throw new TipsException("订单未支付!");
78         }
79
80         if(OrderTotalConstants.STATUS_PAY != ordersTotal.getStatus()
81                 && OrderTotalConstants.STATUS_WAIT_RECEIVE != ordersTotal.getStatus()
82                 && OrderTotalConstants.STATUS_DONE != ordersTotal.getStatus()){
83             throw new TipsException("当前订单状态不能退款!");
84         }
85
86         if(OrderTotalConstants.STATUS_REFUND_NONE != ordersTotal.getRefundStatus()
87                 && OrderTotalConstants.STATUS_REFUND_PART != ordersTotal.getRefundStatus()){
88             throw new TipsException("订单退款状态不正确!");
89         }
90
a2fbbf 91         //返回集合
Z 92         Map<String, Object> returnMap = new HashMap<>();
93         returnMap.put("details",ordersTotal);
118d96 94         List<Map<String, Object>> refundDetails=orderRefundService.refundDetails(ordersTotal);
a2fbbf 95         returnMap.put("refundDetails",refundDetails);
4dc6e5 96
a2fbbf 97         return Result.success(returnMap);
Z 98     }
118d96 99
a2fbbf 100     /** 选完数量点击下一步显示数据接口 */
Z 101     @RequestMapping("/refund/nextStep")
4df03d 102     public Result nextStep(@RequestBody OrderRefundDto orderRefundDto){
a2fbbf 103         if (StringUtils.isEmpty(orderRefundDto.getOrderId())) {
Z 104             throw new TipsException("订单标识为空!");
105         }
106         if (orderRefundDto.getRefundList()==null) {
107             throw new TipsException("退款信息集合为空!");
108         }
c9e2be 109         SqlSentence sqlSentence = new SqlSentence();
Z 110         Map<String, Object> sqlMap = new HashMap<>();
111         sqlSentence.setM(sqlMap);
112         sqlMap.put("isDel", BaseEntity.NO);
113         sqlMap.put("orderId", orderRefundDto.getOrderId());
114
4df03d 115         sqlSentence.setSqlSentence("SELECT * FROM  orders_total WHERE id = #{m.orderId} and isDel = #{m.isDel} ");
c9e2be 116         OrdersTotal ordersTotal = ordersTotalService.selectOne(sqlSentence);
Z 117         if (ordersTotal == null) {
a026ab 118             throw new TipsException("订单标识错误!");
c9e2be 119         }
Z 120         if (OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())) {
121             throw new TipsException("充值订单不支持部分退款!");
122         }
118d96 123         if(OrderTotalConstants.PAY_STATUS_SUC != ordersTotal.getPayStatus()){
C 124             throw new TipsException("订单未支付!");
125         }
126
127         if(OrderTotalConstants.STATUS_PAY != ordersTotal.getStatus()
128                 && OrderTotalConstants.STATUS_WAIT_RECEIVE != ordersTotal.getStatus()
129                 && OrderTotalConstants.STATUS_DONE != ordersTotal.getStatus()){
130             throw new TipsException("当前订单状态不能退款!");
131         }
132
133         if(OrderTotalConstants.STATUS_REFUND_NONE != ordersTotal.getRefundStatus()
134                 && OrderTotalConstants.STATUS_REFUND_PART != ordersTotal.getRefundStatus()){
135             throw new TipsException("订单退款状态不正确!");
136         }
137
a2fbbf 138         //返回集合
118d96 139         OrderRefundDto returnMap = orderRefundService.nextStep(ordersTotal,orderRefundDto);
ae6ff7 140         returnMap.setRefundPayMethod(returnMap.getPayMethodList());
4df03d 141         returnMap.setCouponList(returnMap.getPayCouponList());
a2fbbf 142         return Result.success(returnMap);
Z 143     }
118d96 144
4dc6e5 145     /**
4918c4 146      * 部分退款
4dc6e5 147      */
Z 148     @RequestMapping(value = "/partial/refund",method = RequestMethod.POST)
4df03d 149     public PlatformResult partRefund(HttpServletRequest request, @RequestBody OrderRefundDto orderRefundDto)  {
C 150         //操作平台
151         ThirtApplication thirtApplication = (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY);
2e8393 152        /* //TODO 测试
ae6ff7 153         thirtApplication = new ThirtApplication();
C 154         thirtApplication.setAppId("54654asdf56sd1e1gv567as1");
155         thirtApplication.setName("PHI");
2e8393 156         thirtApplication.setAppIdCode("his");*/
4df03d 157         if(thirtApplication==null){
C 158             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"签名失败,请检查签名!");
159         }
c04e8a 160
4dc6e5 161         if(StringUtils.isEmpty(orderRefundDto.getOrderId())){
c04e8a 162             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单标识不能为空");
4dc6e5 163         }
c04e8a 164
4df03d 165         if(StringUtils.isEmpty(orderRefundDto.getRoleId())){
c04e8a 166             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作角色标识不能为空");
4dc6e5 167         }
ae6ff7 168         if(StringUtils.isEmpty(orderRefundDto.getOperatorId())){
C 169             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作员工标识不能为空");
170         }
c04e8a 171
4dc6e5 172         if(orderRefundDto.getIsApproval()==null){
Z 173             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"是否需要审批不能为空");
174         }
c04e8a 175
C 176         if(orderRefundDto.getIsRefund() == null){
4dc6e5 177             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"是否自动生成退款单不能为空");
Z 178         }
c04e8a 179
C 180         OrdersTotal ordersTotal = ordersTotalService.selectOneByKey(orderRefundDto.getOrderId());
da4ad2 181         if (ordersTotal == null) {
c3fd3d 182             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"订单标识错误!");
da4ad2 183         }
c04e8a 184         if(ordersTotal.getIsDel().equals(OrdersTotal.YES)){
C 185             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"订单已删除!");
da4ad2 186         }
8b5222 187         if (OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())) {
C 188             throw new TipsException("充值订单不支持部分退款!");
189         }
4dc6e5 190
04ce22 191         orderRefundDto.setRefundOperationType(BaseEntity.YES);
4df03d 192         return orderRefundService.partRefund(ordersTotal,orderRefundDto,thirtApplication);
4dc6e5 193     }
c04e8a 194
97a5fc 195     /**
Z 196      * 全部退款
197      */
198     @RequestMapping(value = "/whole/refund",method = RequestMethod.POST)
4df03d 199     public PlatformResult wholeRefund(HttpServletRequest request,@RequestBody OrderRefundDto orderRefundDto)  {
C 200         //操作平台
201         ThirtApplication thirtApplication= (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY);
202         if(thirtApplication==null){
203             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"签名失败,请检查签名!");
204         }
205
97a5fc 206         if(StringUtils.isEmpty(orderRefundDto.getOrderId())){
Z 207             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单id不能为空");
208         }
209         if(StringUtils.isEmpty(orderRefundDto.getOperatorId())){
210             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作人不能为空");
211         }
212         if(orderRefundDto.getIsApproval()==null){
213             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"是否需要审批不能为空");
214         }
215         if(orderRefundDto.getIsRefund()==null){
216             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"是否自动生成退款单不能为空");
217         }
218         SqlSentence sqlSentence = new SqlSentence();
219         Map<String, Object> sqlMap = new HashMap<>();
220         sqlSentence.setM(sqlMap);
221         sqlMap.put("isDel", BaseEntity.NO);
222         sqlMap.put("id", orderRefundDto.getOrderId());
223         sqlSentence.setSqlSentence("SELECT * FROM orders_total  WHERE id = #{m.id}  and  isDel = #{m.isDel} ");
224         OrdersTotal ordersTotal = commonService.selectOne(OrdersTotalMapper.class, sqlSentence);
225         if (ordersTotal == null) {
a026ab 226             throw new TipsException("订单标识错误!");
97a5fc 227         }
Z 228         if(!(OrderTotalConstants.PAY_STATUS_SUC==ordersTotal.getPayStatus())){
a026ab 229             throw new TipsException("订单未支付!");
97a5fc 230         }
edf5ea 231         if(!(OrderTotalConstants.STATUS_PAY==ordersTotal.getStatus())  && !(OrderTotalConstants.STATUS_WAIT_RECEIVE==ordersTotal.getStatus()) && !(OrderTotalConstants.STATUS_DONE==ordersTotal.getStatus())){
a026ab 232             throw new TipsException("订单不是已支付状态!");
97a5fc 233         }
Z 234
235         if(OrderTotalConstants.STATUS_REFUND_NONE!=ordersTotal.getRefundStatus()){
a026ab 236             throw new TipsException("订单退款状态不正确!");
97a5fc 237         }
Z 238
4df03d 239         return orderRefundService.wholeRefund(orderRefundDto,thirtApplication);
97a5fc 240     }
250fca 241
Z 242     /**
25d452 243      * 伪造部分退款处理退款逻辑
250fca 244      *
Z 245      */
246     @RequestMapping(value = "/forge/partial/refund",method = RequestMethod.POST)
247     public PlatformResult forgePartRefund(@RequestBody OrderRefundDto orderRefundDto)  {
248         if(StringUtils.isEmpty(orderRefundDto.getOrderId())){
249             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单id不能为空");
250         }
251         if(StringUtils.isEmpty(orderRefundDto.getOperatorId())){
252             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作人不能为空");
253         }
254         if(orderRefundDto.getIsApproval()==null){
255             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"是否需要审批不能为空");
256         }
257         if(orderRefundDto.getIsRefund()==null){
258             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"是否自动生成退款单不能为空");
259         }
260         SqlSentence sqlSentence = new SqlSentence();
261         Map<String, Object> sqlMap = new HashMap<>();
262         sqlSentence.setM(sqlMap);
263         sqlMap.put("isDel", BaseEntity.NO);
264         sqlMap.put("id", orderRefundDto.getOrderId());
265         sqlSentence.setSqlSentence("SELECT * FROM orders_total  WHERE id = #{m.id}  and  isDel = #{m.isDel} ");
266         OrdersTotal ordersTotal = commonService.selectOne(OrdersTotalMapper.class, sqlSentence);
267         if (ordersTotal == null) {
a026ab 268             throw new TipsException("订单标识错误!");
250fca 269         }
Z 270         if(!(OrderTotalConstants.PAY_STATUS_SUC==ordersTotal.getPayStatus())){
a026ab 271             throw new TipsException("订单未支付!");
250fca 272         }
edf5ea 273         if(!(OrderTotalConstants.STATUS_PAY==ordersTotal.getStatus())  && !(OrderTotalConstants.STATUS_WAIT_RECEIVE==ordersTotal.getStatus()) && !(OrderTotalConstants.STATUS_DONE==ordersTotal.getStatus())){
a026ab 274             throw new TipsException("订单不是已支付状态!");
250fca 275         }
Z 276
277         if(!(OrderTotalConstants.STATUS_REFUND_NONE==ordersTotal.getRefundStatus()) &&
278                 !(OrderTotalConstants.STATUS_REFUND_PART==ordersTotal.getRefundStatus())){
a026ab 279             throw new TipsException("订单退款状态不正确!");
250fca 280         }
Z 281      /*   if (OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())) {
282             throw new TipsException("充值订单不支持部分退款!");
283         }*/
284         orderRefundDto.setRefundOperationType(BaseEntity.YES);
285         return orderRefundService.forgePartRefund(orderRefundDto);
286     }
892b96 287     /**
Z 288      * 根据订单 重新绑定订单退款状态
289      *
290      */
291     @RequestMapping(value = "/verify/order/refundStatus",method = RequestMethod.POST)
292     public PlatformResult verifyOrderRefundStatus(@RequestBody OrdersTotal ordersTotalDto)  {
293         if(ordersTotalDto==null){
294             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"参数不能为空!");
295         }
296         if(StringUtils.isEmpty(ordersTotalDto.getId())){
297             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单id不能为空");
298         }
299         orderRefundService.verifyOrderRefundStatus(ordersTotalDto);
300         return PlatformResult.success();
301     }
302
fd7281 303     /**
755975 304      * 作废订单退款单
fd7281 305      *
C 306      */
307     @RequestMapping(value = "/verify/order/refundStatus",method = RequestMethod.POST)
308     public PlatformResult refundCancel(HttpServletRequest request,@RequestBody RefundCancelVo refundCancelVo)  {
309         //操作平台
310         ThirtApplication thirtApplication= (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY);
311         if(thirtApplication==null){
312             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未获取到操作平台!");
313         }
314
315         if(StringUtils.isEmpty(refundCancelVo.getId())){
316             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"退款单标识必传!");
317         }
318         RefundRecord refundRecord = refundRecordService.selectOneByKey(refundCancelVo.getId());
319         if(refundRecord == null){
320             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款单标识错误!");
321         }
322         if(StringUtils.isEmpty(refundCancelVo.getRemarks())){
323             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"作废备注必填!");
324         }
325         if(StringUtils.isEmpty(refundCancelVo.getStaffId())){
326             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作员工必填!");
327         }
328         Employee employee = employeeService.selectOneByKey(refundCancelVo.getStaffId());
329         if(employee == null){
330             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作员工标识错误!");
331         }
332         if(StringUtils.isEmpty(refundCancelVo.getStaffRoleId())){
333             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作员工角色必填!");
334         }
335         EmployeeRole employeeRole = employeeRoleService.getEmployeeRole(refundCancelVo.getStaffRoleId());
336         if(employeeRole == null){
337             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"操作员工角色标识错误!");
338         }
339
340         orderRefundService.refundCancel(refundCancelVo,refundRecord,employee,employeeRole,thirtApplication);
341         return PlatformResult.success();
342     }
343
4dc6e5 344 }