| @@ -1084,78 +1084,78 @@ public class WxOrderController extends BaseController { | |||
| logger.info("抖音支付2.0退款回调---body{}"+body); | |||
| Map<String, Object> map = new HashMap(); | |||
| map.put("err_no",ErrorCode.SYS_SERVER_ERROR.getCode()); | |||
| map.put("err_tips","暂不支持"); | |||
| // map.put("err_no",ErrorCode.SYS_SERVER_ERROR.getCode()); | |||
| // map.put("err_tips","暂不支持"); | |||
| return map; | |||
| // try { | |||
| // JSONObject jsonObject = JSONObject.parseObject(body); | |||
| // String msg = jsonObject.getString("msg"); | |||
| // | |||
| // JSONObject msgObject = JSONObject.parseObject(msg); | |||
| // String app_id = msgObject.getString("app_id"); | |||
| // String open_id = msgObject.getString("open_id"); | |||
| // | |||
| // //验证app | |||
| // WxAppinfo appinfo = wxAppinfoService.getByAppId(app_id); | |||
| // if(appinfo == null || !EnumAppPlat.TOUTIAO.getCode().equals(appinfo.getPlat()) | |||
| // || !EnumAppType.C.getCode().equals(appinfo.getType())){ | |||
| // map.put("err_no",ErrorCode.APP_ID_NOT_FOUND.getCode()); | |||
| // map.put("err_tips",ErrorCode.APP_ID_NOT_FOUND.getMessage()); | |||
| // return map; | |||
| // } | |||
| // WxPayAccount payAccount = wxPayAccountService.getById(appinfo.getPayId()); | |||
| // if(payAccount == null){ | |||
| // map.put("err_no",ErrorCode.API_KEY_NOT_FOUND.getCode()); | |||
| // map.put("err_tips","未找到支付配置"); | |||
| // return map; | |||
| // } | |||
| // TenantEntity tenantEntity = new TenantEntity(); | |||
| // tenantEntity.updateTenantInfo(appinfo); | |||
| // //验证用户 | |||
| // Long memberId = null; | |||
| // TtCUser cuser = (TtCUser) cuserFactory.getCUserService(EnumAppPlat.TOUTIAO).getByOpenId(open_id, tenantEntity.getTenantId()); | |||
| // if(cuser != null && cuser.getUserId() != null){ | |||
| // memberId = cuser.getUserId(); | |||
| // } | |||
| // if(memberId == null){ | |||
| // map.put("err_no",ErrorCode.USER_NOT_MEMBER.getCode()); | |||
| // map.put("err_tips",ErrorCode.USER_NOT_MEMBER.getMessage()); | |||
| // return map; | |||
| // } | |||
| // | |||
| // TtPayService ttPayService = maUtil.getTtPayService(appinfo, payAccount); | |||
| // RefundOrderCallback refundOrderCallback = ttPayService.refundOrderNotifyV2Result(body, header); | |||
| // | |||
| // ResultData resultData = wxRefundOrderService.ttCallBackCreateRefundOrder(tenantEntity,memberId,refundOrderCallback); | |||
| // | |||
| // if(resultData.code == 200){ | |||
| // WxRefundOrder refundOrder = (WxRefundOrder) resultData.data; | |||
| // Map<String, Object> data = new HashMap<>(); | |||
| // data.put("out_refund_no",refundOrder.getId().toString()); | |||
| // data.put("order_entry_schema",wxOrderService.getOrderEntrySchema(Long.parseLong(refundOrder.getPayOrderNo()))); | |||
| // map.put("data",data); | |||
| // map.put("err_no",0); | |||
| // map.put("err_tips",resultData.message); | |||
| // logger.info("resultData{}"+JSON.toJSONString(map)); | |||
| // return map; | |||
| // }else{ | |||
| // map.put("err_no",resultData.code); | |||
| // map.put("err_tips",resultData.message); | |||
| // return map; | |||
| // } | |||
| // | |||
| // } catch (TtPayException e) { | |||
| // logger.error(e.getMessage()); | |||
| // map.put("err_no",ErrorCode.SYS_BEAN_EMPTY_PROPERTY_ERROR.getCode()); | |||
| // map.put("err_tips",e.getMessage()); | |||
| // return map; | |||
| // } catch (Exception e){ | |||
| // logger.error(e.getMessage()); | |||
| // map.put("err_no",ErrorCode.SYS_SERVER_ERROR.getCode()); | |||
| // map.put("err_tips",e.getMessage()); | |||
| // return map; | |||
| // } | |||
| // return map; | |||
| try { | |||
| JSONObject jsonObject = JSONObject.parseObject(body); | |||
| String msg = jsonObject.getString("msg"); | |||
| JSONObject msgObject = JSONObject.parseObject(msg); | |||
| String app_id = msgObject.getString("app_id"); | |||
| String open_id = msgObject.getString("open_id"); | |||
| //验证app | |||
| WxAppinfo appinfo = wxAppinfoService.getByAppId(app_id); | |||
| if(appinfo == null || !EnumAppPlat.TOUTIAO.getCode().equals(appinfo.getPlat()) | |||
| || !EnumAppType.C.getCode().equals(appinfo.getType())){ | |||
| map.put("err_no",ErrorCode.APP_ID_NOT_FOUND.getCode()); | |||
| map.put("err_tips",ErrorCode.APP_ID_NOT_FOUND.getMessage()); | |||
| return map; | |||
| } | |||
| WxPayAccount payAccount = wxPayAccountService.getById(appinfo.getPayId()); | |||
| if(payAccount == null){ | |||
| map.put("err_no",ErrorCode.API_KEY_NOT_FOUND.getCode()); | |||
| map.put("err_tips","未找到支付配置"); | |||
| return map; | |||
| } | |||
| TenantEntity tenantEntity = new TenantEntity(); | |||
| tenantEntity.updateTenantInfo(appinfo); | |||
| //验证用户 | |||
| Long memberId = null; | |||
| TtCUser cuser = (TtCUser) cuserFactory.getCUserService(EnumAppPlat.TOUTIAO).getByOpenId(open_id, tenantEntity.getTenantId()); | |||
| if(cuser != null && cuser.getUserId() != null){ | |||
| memberId = cuser.getUserId(); | |||
| } | |||
| if(memberId == null){ | |||
| map.put("err_no",ErrorCode.USER_NOT_MEMBER.getCode()); | |||
| map.put("err_tips",ErrorCode.USER_NOT_MEMBER.getMessage()); | |||
| return map; | |||
| } | |||
| TtPayService ttPayService = maUtil.getTtPayService(appinfo, payAccount); | |||
| RefundOrderCallback refundOrderCallback = ttPayService.refundOrderNotifyV2Result(body, header); | |||
| ResultData resultData = wxRefundOrderService.ttCallBackCreateRefundOrder(tenantEntity,memberId,refundOrderCallback); | |||
| if(resultData.code == 200){ | |||
| WxRefundOrder refundOrder = (WxRefundOrder) resultData.data; | |||
| Map<String, Object> data = new HashMap<>(); | |||
| data.put("out_refund_no",refundOrder.getId().toString()); | |||
| data.put("order_entry_schema",wxOrderService.getOrderEntrySchema(Long.parseLong(refundOrder.getPayOrderNo()))); | |||
| map.put("data",data); | |||
| map.put("err_no",0); | |||
| map.put("err_tips",resultData.message); | |||
| logger.info("resultData{}"+JSON.toJSONString(map)); | |||
| return map; | |||
| }else{ | |||
| map.put("err_no",resultData.code); | |||
| map.put("err_tips",resultData.message); | |||
| return map; | |||
| } | |||
| } catch (TtPayException e) { | |||
| logger.error(e.getMessage()); | |||
| map.put("err_no",ErrorCode.SYS_BEAN_EMPTY_PROPERTY_ERROR.getCode()); | |||
| map.put("err_tips",e.getMessage()); | |||
| return map; | |||
| } catch (Exception e){ | |||
| logger.error(e.getMessage()); | |||
| map.put("err_no",ErrorCode.SYS_SERVER_ERROR.getCode()); | |||
| map.put("err_tips",e.getMessage()); | |||
| return map; | |||
| } | |||
| } | |||
| @@ -2,11 +2,13 @@ package com.iformall.schedule; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.douyin.pay.TtPayService; | |||
| import com.iformall.douyin.pay.exception.TtPayException; | |||
| import com.iformall.douyin.payv2.request.TtRefundAuditMsgRequest; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.WxRefundOrderService; | |||
| import com.iformall.utils.MaUtil; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -14,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.scheduling.annotation.Scheduled; | |||
| import org.springframework.stereotype.Component; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Component | |||
| @@ -28,6 +31,9 @@ public class OrderRefundAuditSchedule { | |||
| @Autowired | |||
| WxRefundOrderMapper wxRefundOrderMapper; | |||
| @Autowired | |||
| WxRefundOrderService wxRefundOrderService; | |||
| @Autowired | |||
| WxPayAccountMapper wxPayAccountMapper; | |||
| @@ -35,22 +41,111 @@ public class OrderRefundAuditSchedule { | |||
| @Autowired | |||
| MaUtil maUtil; | |||
| private List<WxAppinfo> getAppInfos() { | |||
| @Scheduled(cron = "0 */5 * * * ?")// | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void orderQueryRefund() { | |||
| logger.info("抖音同步申请退款状态"); | |||
| try{ | |||
| List<WxAppinfo> appInfos = getTTAppInfos(); | |||
| for (WxAppinfo appinfo : appInfos) { | |||
| WxRefundOrder refundOrder = new WxRefundOrder(); | |||
| refundOrder.updateTenantInfo(appinfo); | |||
| refundOrder.setRefundVendor(EnumPayWay.PAY_WAY_TT.getCode()); | |||
| refundOrder.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||
| List<WxRefundOrder> list = wxRefundOrderMapper.findList(refundOrder); | |||
| if(list != null && list.size() > 0){ | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appinfo.getPayId()); | |||
| for (WxRefundOrder order:list) { | |||
| try { | |||
| wxRefundOrderService.syncRefundOrder(appinfo,payAccount,order); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| }catch(Exception e){} | |||
| logger.info("抖音同步退款状态"); | |||
| try{ | |||
| List<WxAppinfo> appInfos = getTTAppInfos(); | |||
| for (WxAppinfo appinfo : appInfos) { | |||
| WxRefundOrder refundOrder = new WxRefundOrder(); | |||
| refundOrder.updateTenantInfo(appinfo); | |||
| refundOrder.setRefundVendor(EnumPayWay.PAY_WAY_TT.getCode()); | |||
| refundOrder.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_AGREE.getCode()); | |||
| List<WxRefundOrder> list = wxRefundOrderMapper.findList(refundOrder); | |||
| if(list != null && list.size() > 0){ | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appinfo.getPayId()); | |||
| for (WxRefundOrder order:list) { | |||
| try { | |||
| wxRefundOrderService.syncRefundOrder(appinfo,payAccount,order); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| }catch(Exception e){} | |||
| logger.info("微信同步退款状态"); | |||
| try{ | |||
| List<WxAppinfo> appInfos = getWXAppInfos(); | |||
| for (WxAppinfo appinfo : appInfos) { | |||
| WxRefundOrder refundOrder = new WxRefundOrder(); | |||
| refundOrder.updateTenantInfo(appinfo); | |||
| refundOrder.setRefundVendor(EnumPayWay.PAY_WAY_WECHAT.getCode()); | |||
| refundOrder.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||
| List<WxRefundOrder> list = wxRefundOrderMapper.findList(refundOrder); | |||
| if(list != null && list.size() > 0){ | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appinfo.getPayId()); | |||
| for (WxRefundOrder order:list) { | |||
| try { | |||
| wxRefundOrderService.syncRefundOrder(appinfo,payAccount,order); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| }catch(Exception e){} | |||
| } | |||
| @Scheduled(cron = "0 */5 * * * ?")// | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void orderQueryRefundWX() { | |||
| } | |||
| private List<WxAppinfo> getWXAppInfos() { | |||
| WxAppinfo appinfo =new WxAppinfo(); | |||
| appinfo.setPlat(EnumAppPlat.WX.getCode()); | |||
| appinfo.setType(EnumAppType.C.getCode()); | |||
| appinfo.setEnable(EnumEnableType.Enable.getCode()); | |||
| return wxAppinfoMapper.findList(appinfo); | |||
| } | |||
| private List<WxAppinfo> getTTAppInfos() { | |||
| WxAppinfo appinfo =new WxAppinfo(); | |||
| appinfo.setPlat(EnumAppPlat.TOUTIAO.getCode()); | |||
| appinfo.setType(EnumAppType.C.getCode()); | |||
| return wxAppinfoMapper.findList(appinfo); | |||
| appinfo.setEnable(EnumEnableType.Enable.getCode()); | |||
| return wxAppinfoMapper.findList(appinfo); | |||
| } | |||
| @Scheduled(cron = "0 */10 * * * *?") // 每10分钟检查一次 | |||
| @Scheduled(cron = "0 30 */1 * * ?")// 每个小时的30分钟 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void merchantAuditCallback() { | |||
| logger.info("退款自动审核start"); | |||
| List<WxAppinfo> appInfos = getAppInfos(); | |||
| List<WxAppinfo> appInfos = getTTAppInfos(); | |||
| for (WxAppinfo appinfo : appInfos) { | |||
| WxRefundOrder refundOrder = new WxRefundOrder(); | |||
| refundOrder.updateTenantInfo(appinfo); | |||
| refundOrder.setRefundVendor(EnumPayWay.PAY_WAY_TT.getCode()); | |||
| refundOrder.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||
| List<WxRefundOrder> list = wxRefundOrderMapper.findList(refundOrder); | |||
| if(list != null && list.size() > 0){ | |||
| @@ -61,7 +156,15 @@ public class OrderRefundAuditSchedule { | |||
| TtRefundAuditMsgRequest request = new TtRefundAuditMsgRequest(); | |||
| request.setOutRefundNo(order.getId().toString()); | |||
| request.setRefundAuditStatus(1); | |||
| ttPayService.merchantAuditCallback(request); | |||
| boolean b = ttPayService.merchantAuditCallback(request); | |||
| if(b){ | |||
| WxRefundOrder updRefundOrder = new WxRefundOrder(); | |||
| updRefundOrder.updateTenantInfo(appinfo); | |||
| updRefundOrder.setId(order.getId()); | |||
| updRefundOrder.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_AGREE.getCode()); | |||
| updRefundOrder.setUpdateTime(new Date()); | |||
| wxRefundOrderMapper.updateById(updRefundOrder); | |||
| } | |||
| } catch (TtPayException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall.domain.po; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import lombok.Data; | |||
| @@ -42,6 +43,9 @@ public class WxRefundOrder extends TenantEntity { | |||
| private Integer ttPayWay; | |||
| @io.swagger.annotations.ApiModelProperty(value="支付状态: 0-退款中;1-退款成功;2-退款失败",name="refundOrderStatus") | |||
| private Integer refundOrderStatus; | |||
| @TableField(exist = false) | |||
| private Integer notStatus; | |||
| @io.swagger.annotations.ApiModelProperty(value="微信退款单号",name="refundId") | |||
| private String refundId; | |||
| @io.swagger.annotations.ApiModelProperty(value="退款原因",name="refundReason") | |||
| @@ -17,7 +17,7 @@ public enum EnumMsgRecordType { | |||
| INSIDE_COUPON_VERIFY(101, "券核销"), | |||
| INSIDE_C_LOGIN(102, "C端用户登录"),//内部消息,加积分等 | |||
| //INSIDE_NOTIFY_PAY_SUCCESS(103, "微信支付回调"), | |||
| INSIDE_NOTIFY_REFUND_SUCCESS(104, "微信退款回调"), | |||
| INSIDE_NOTIFY_REFUND_SUCCESS(104, "退款回调"), | |||
| COUPON_STOCK(105, "券库存更新"), | |||
| CASH_OUT(106,"商户提现"), | |||
| INSIDE_ORDER_REFUND(107, "退款提交成功"), | |||
| @@ -8,6 +8,7 @@ public enum EnumRefundStatus { | |||
| REFUND_WAIT(0, "退款中"), | |||
| REFUND_REQ_SUCCESS(1, "退款申请成功"), | |||
| REFUND_REQ_FAIL(2, "退款申请失败"), | |||
| REFUND_REQ_AGREE(11, "同意退款"), | |||
| REFUND_SUCCESS(3, "退款成功"), | |||
| REFUND_FAIL(4, "退款失败"), | |||
| ; | |||
| @@ -3,14 +3,9 @@ package com.iformall.mapper; | |||
| import java.util.*; | |||
| import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.WxRefundOrder; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| public interface WxRefundOrderMapper extends CommonMapper<WxRefundOrder, Long> { | |||
| List<WxRefundOrder> findList(WxRefundOrder wxRefundOrder); | |||
| } | |||
| @@ -51,10 +51,8 @@ public interface WxRefundOrderService { | |||
| /** | |||
| * 处理退款成功 | |||
| * @param record | |||
| * @param transactionId | |||
| * @param refundId | |||
| */ | |||
| void handleRefundSuccess(WxRefundOrder record, String transactionId, String refundId); | |||
| void handleRefundSuccess(WxRefundOrder record); | |||
| /** | |||
| * 页面回调 | |||
| @@ -112,4 +110,6 @@ public interface WxRefundOrderService { | |||
| * @return | |||
| */ | |||
| ResultData ttCallBackCreateRefundOrder(TenantEntity tenantEntity, Long memberId, RefundOrderCallback refundOrderCallback); | |||
| ResultData syncRefundOrder(WxAppinfo appinfo, WxPayAccount payAccount, WxRefundOrder order); | |||
| } | |||
| @@ -10,6 +10,7 @@ import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.msg.FmInsideOrderRefundMsg; | |||
| import com.iformall.domain.po.msg.WxMsgRecord; | |||
| @@ -310,6 +311,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||
| record.updateTenantInfo(tenantEntity); | |||
| record.setPayOrderNo(String.valueOf(payOrder.getId())); | |||
| record.setOrderId(wxOrder.getId()); | |||
| record.setNotStatus(EnumRefundStatus.REFUND_FAIL.getCode()); | |||
| // check 是否有退款订单 | |||
| List<WxRefundOrder> refundList = wxRefundOrderMapper.findList(record); | |||
| @@ -595,7 +597,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||
| return notifyResult.getReturnJson(); | |||
| }else { | |||
| if (null != notifyResult.getRefundOrder()) { | |||
| handleRefundSuccess(notifyResult.getRefundOrder(), notifyResult.getTranscationId(), notifyResult.getRefundId()); | |||
| handleRefundSuccess(notifyResult.getRefundOrder()); | |||
| } | |||
| return notifyResult.getReturnJson(); | |||
| } | |||
| @@ -608,7 +610,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void handleRefundSuccess(WxRefundOrder refundOrder, String transactionId, String refundId) { | |||
| public void handleRefundSuccess(WxRefundOrder refundOrder) { | |||
| EnumRefundStatus refundStatus = EnumRefundStatus.getEnum(refundOrder.getRefundOrderStatus()); | |||
| // 判断退款状态 | |||
| if (refundStatus != EnumRefundStatus.REFUND_REQ_SUCCESS) { | |||
| @@ -629,8 +631,8 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||
| updateOrder.setOrderId(refundOrder.getOrderId()); | |||
| updateOrder.setUpdateTime(currentDate); | |||
| updateOrder.setRefundOrderStatus(EnumRefundStatus.REFUND_SUCCESS.getCode()); | |||
| updateOrder.setTransactionId(transactionId); | |||
| updateOrder.setRefundId(refundId); | |||
| // updateOrder.setTransactionId(transactionId); | |||
| // updateOrder.setRefundId(refundId); | |||
| // 修改退款订单状态 | |||
| try { | |||
| wxRefundOrderMapper.updateById(updateOrder); | |||
| @@ -823,7 +825,9 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||
| WxRefundOrder refundOrderQ = new WxRefundOrder(); | |||
| refundOrderQ.updateTenantInfo(tenantInfo); | |||
| refundOrderQ.setOrderId(orderId); | |||
| return wxRefundOrderMapper.selectOne(new QueryWrapper<>(refundOrderQ)); | |||
| refundOrderQ.setSortColumns(BaseEntity.SortField.CreateTime_DESC); | |||
| List<WxRefundOrder> list = wxRefundOrderMapper.findList(refundOrderQ); | |||
| return list.get(0); | |||
| } | |||
| @Override | |||
| @@ -961,7 +965,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||
| record.updateTenantInfo(tenantEntity); | |||
| record.setPayOrderNo(wxOrder.getComposeOrderId().toString()); | |||
| record.setOrderId(wxOrder.getId()); | |||
| record.setNotStatus(EnumRefundStatus.REFUND_FAIL.getCode()); | |||
| // check 是否有退款订单 | |||
| List<WxRefundOrder> refundList = wxRefundOrderMapper.findList(record); | |||
| if (refundList.size() > 0) { | |||
| @@ -1009,10 +1013,72 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", record); | |||
| }else{ | |||
| //目前只支持单订单单券 | |||
| logger.error("订单数据异常:compseOrderId " + compseOrderId); | |||
| throw new MallinkException(ErrorCode.ORDER_PAY_REFUND_FAIL); | |||
| } | |||
| } | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public ResultData syncRefundOrder(WxAppinfo appinfo, WxPayAccount payAccount, WxRefundOrder order) { | |||
| RefundAdapterResult refundAdapterResult = payServiceFactory.getRefundPayAdapterService(order.getRefundVendor()).queryRefund(appinfo, payAccount, order); | |||
| if(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode().equals(refundAdapterResult.getCode())){//退款中 退款申请成功 | |||
| if(EnumRefundStatus.REFUND_WAIT.getCode().equals(order.getRefundOrderStatus())){ | |||
| WxRefundOrder updRefundStatus = new WxRefundOrder(); | |||
| updRefundStatus.updateTenantInfo(order); | |||
| updRefundStatus.setId(order.getId()); | |||
| updRefundStatus.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||
| updRefundStatus.setUpdateTime(new Date()); | |||
| wxRefundOrderMapper.updateById(updRefundStatus); | |||
| } | |||
| }else if(EnumRefundStatus.REFUND_SUCCESS.getCode().equals(refundAdapterResult.getCode())){//退款成功 | |||
| handleRefundSuccess(order); | |||
| }else if(EnumRefundStatus.REFUND_REQ_FAIL.getCode().equals(refundAdapterResult.getCode()) //退款申请失败 | |||
| || EnumRefundStatus.REFUND_FAIL.getCode().equals(refundAdapterResult.getCode())){//退款失败 | |||
| if(EnumRefundStatus.REFUND_WAIT.getCode().equals(order.getRefundOrderStatus()) | |||
| || EnumRefundStatus.REFUND_REQ_SUCCESS.getCode().equals(order.getRefundOrderStatus()) | |||
| || EnumRefundStatus.REFUND_REQ_AGREE.getCode().equals(order.getRefundOrderStatus())){ | |||
| Date now = new Date(); | |||
| // WxOrder wxOrder = wxOrderMapper.selectById(order.getOrderId(), order.getTenantId()); | |||
| // WxOrder updOrderStatus = new WxOrder(); | |||
| // updOrderStatus.updateTenantInfo(wxOrder); | |||
| // updOrderStatus.setId(wxOrder.getId()); | |||
| // updOrderStatus.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||
| // updOrderStatus.setUpdateDate(now); | |||
| // wxOrderMapper.updateById(updOrderStatus); | |||
| // | |||
| // WxCouponOrder couponOrderQ = new WxCouponOrder(); | |||
| // couponOrderQ.updateTenantInfo(wxOrder); | |||
| // couponOrderQ.setOrderId(wxOrder.getId()); | |||
| // List<WxCouponOrder> couponOrderList = wxCouponOrderMapper.findList(couponOrderQ); | |||
| // for (WxCouponOrder couponOrder:couponOrderList) { | |||
| // if(!EnumCouponType.CARD_MULTIMCH.getCode().equals(couponOrder.getCouponType())){ | |||
| // WxCouponOrder updCouponOrderStatus = new WxCouponOrder(); | |||
| // updCouponOrderStatus.updateTenantInfo(couponOrder); | |||
| // updCouponOrderStatus.setId(couponOrder.getId()); | |||
| // updCouponOrderStatus.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||
| // updCouponOrderStatus.setUpdateDate(now); | |||
| // wxCouponOrderMapper.updateById(updCouponOrderStatus); | |||
| // } | |||
| // } | |||
| WxRefundOrder updRefundStatus = new WxRefundOrder(); | |||
| updRefundStatus.updateTenantInfo(order); | |||
| updRefundStatus.setId(order.getId()); | |||
| updRefundStatus.setRefundOrderStatus(EnumRefundStatus.REFUND_FAIL.getCode()); | |||
| updRefundStatus.setFailReason(refundAdapterResult.getMsg()); | |||
| updRefundStatus.setUpdateTime(now); | |||
| wxRefundOrderMapper.updateById(updRefundStatus); | |||
| } | |||
| }else{ | |||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR); | |||
| } | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -10,7 +10,9 @@ import com.iformall.douyin.pay.exception.TtPayException; | |||
| import com.iformall.douyin.pay.orderQuery.QueryRefundResult; | |||
| import com.iformall.douyin.pay.preOrder.CreateRefund; | |||
| import com.iformall.douyin.pay.preOrder.CreateRefundResult; | |||
| import com.iformall.douyin.payv2.request.TtPayRefundQueryV2Request; | |||
| import com.iformall.douyin.payv2.request.TtPayRefundV2Request; | |||
| import com.iformall.douyin.payv2.result.TtPayRefundQueryV2Result; | |||
| import com.iformall.douyin.payv2.result.TtPayRefundV2Result; | |||
| import com.iformall.enums.EnumPayType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| @@ -107,16 +109,39 @@ public class TtRefundAdapterService implements RefundPayAdapterService{ | |||
| @Override | |||
| public RefundAdapterResult queryRefund(WxAppinfo appInfo,WxPayAccount payAccount, WxRefundOrder record) { | |||
| QueryRefundResult queryRefundResult = DouYinPayHelper.refundQuery(appInfo.getAppId(), payAccount.getApiKey(), String.valueOf(record.getId()), null); | |||
| if(queryRefundResult != null){ | |||
| if("SUCCESS".equals(queryRefundResult.getRefundStatus())){ | |||
| return new RefundAdapterResult(true,0,"退款",queryRefundResult); | |||
| try { | |||
| TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | |||
| TtPayRefundQueryV2Request request = new TtPayRefundQueryV2Request(); | |||
| TtPayRefundQueryV2Result ttPayRefundQueryV2Result = ttPayService.refundQueryV2(request); | |||
| if(ttPayRefundQueryV2Result != null){ | |||
| if("PROCESSING".equals(ttPayRefundQueryV2Result.getRefundStatus())){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_REQ_SUCCESS.getCode(),"退款订单申请成功",ttPayRefundQueryV2Result); | |||
| }else if("SUCCESS".equals(ttPayRefundQueryV2Result.getRefundStatus())){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_SUCCESS.getCode(),"退款成功",ttPayRefundQueryV2Result); | |||
| }else if("FAIL".equals(ttPayRefundQueryV2Result.getRefundStatus())){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_FAIL.getCode(),ttPayRefundQueryV2Result.getMessage(),ttPayRefundQueryV2Result); | |||
| }else{ | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(),"查询状态异常"); | |||
| } | |||
| }else{ | |||
| return new RefundAdapterResult(false,ErrorCode.REFUND_ORDER_ERROR.getCode(),"退款失败",queryRefundResult); | |||
| return new RefundAdapterResult(false,EnumRefundStatus.REFUND_REQ_FAIL.getCode(),"退款订单申请失败",null); | |||
| } | |||
| }else{ | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||
| } catch (TtPayException e) { | |||
| e.printStackTrace(); | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(),"查询状态异常"); | |||
| } | |||
| // QueryRefundResult queryRefundResult = DouYinPayHelper.refundQuery(appInfo.getAppId(), payAccount.getApiKey(), String.valueOf(record.getId()), null); | |||
| // if(queryRefundResult != null){ | |||
| // if("SUCCESS".equals(queryRefundResult.getRefundStatus())){ | |||
| // return new RefundAdapterResult(true,0,"退款",queryRefundResult); | |||
| // }else{ | |||
| // return new RefundAdapterResult(false,ErrorCode.REFUND_ORDER_ERROR.getCode(),"退款失败",queryRefundResult); | |||
| // } | |||
| // }else{ | |||
| // throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||
| // } | |||
| } | |||
| @Autowired | |||
| @@ -417,40 +417,87 @@ public class WxRefundAdapterService implements RefundPayAdapterService{ | |||
| record.getRefundId(), payAccount.getApiKey()); | |||
| String response = WxPay.orderRefundQuery(paramMap); | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| String result_no = returnMap.get("result_code"); | |||
| if ("SUCCESS".equals(result_no)) { | |||
| String refund_id = returnMap.get("refund_id"); | |||
| return new RefundAdapterResult(true,0,"退款",returnMap); | |||
| } else { | |||
| String errMsg = ""; | |||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||
| if (errObj != null) { | |||
| errMsg = errObj.toJSONString(); | |||
| } else { | |||
| errMsg = returnMap.get("return_msg"); | |||
| String return_code = returnMap.get("return_code"); | |||
| if("SUCCESS".equals(return_code)){ | |||
| String result_code = returnMap.get("result_code"); | |||
| if("SUCCESS".equals(result_code)){ | |||
| String refund_status_0 = returnMap.get("refund_status_0"); | |||
| if("SUCCESS".equals(refund_status_0)){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_SUCCESS.getCode(),"退款成功",returnMap); | |||
| }else if("REFUNDCLOSE".equals(refund_status_0)){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_FAIL.getCode(),"退款关闭,指商户发起退款失败的情况",returnMap); | |||
| }else if("PROCESSING".equals(refund_status_0)){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_REQ_SUCCESS.getCode(),"退款中",returnMap); | |||
| }else if("CHANGE".equals(refund_status_0)){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_FAIL.getCode(), | |||
| "退款异常,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败。",returnMap); | |||
| }else{ | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(),"查询状态异常 非法状态"); | |||
| } | |||
| }else{ | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(),"查询状态异常 "+returnMap.get("err_code_des")); | |||
| } | |||
| return new RefundAdapterResult(false,ErrorCode.REFUND_ORDER_ERROR.getCode(),errMsg,returnMap); | |||
| }else{ | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(),"查询状态异常 "+returnMap.get("return_msg")); | |||
| } | |||
| // String result_no = returnMap.get("result_code"); | |||
| // if ("SUCCESS".equals(result_no)) { | |||
| // String refund_id = returnMap.get("refund_id"); | |||
| // return new RefundAdapterResult(true,0,"退款",returnMap); | |||
| // } else { | |||
| // String errMsg = ""; | |||
| // JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||
| // if (errObj != null) { | |||
| // errMsg = errObj.toJSONString(); | |||
| // } else { | |||
| // errMsg = returnMap.get("return_msg"); | |||
| // } | |||
| // return new RefundAdapterResult(false,ErrorCode.REFUND_ORDER_ERROR.getCode(),errMsg,returnMap); | |||
| // } | |||
| } else { | |||
| Map<String, String> paramMap = WxPayment.buildSWeappRefundQueryMap( | |||
| appInfo.getParentAppId(), appInfo.getAppId(), payAccount.getMchId(), payAccount.getSubMchId(), | |||
| record.getTransactionId(), record.getPayOrderNo(), String.valueOf(record.getId()), record.getRefundId(), payAccount.getApiKey()); | |||
| String response = WxPay.orderRefundQuery(paramMap); | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| String result_no = returnMap.get("result_code"); | |||
| if ("SUCCESS".equals(result_no)) { | |||
| String refund_id = returnMap.get("refund_id"); | |||
| return new RefundAdapterResult(true,0,"退款",returnMap); | |||
| } else { | |||
| String errMsg = ""; | |||
| JSONObject errObj = errorRefundQueryMap.getJSONObject(result_no); | |||
| if (errObj != null) { | |||
| errMsg = errObj.toJSONString(); | |||
| } else { | |||
| errMsg = returnMap.get("return_msg"); | |||
| String return_code = returnMap.get("return_code"); | |||
| if("SUCCESS".equals(return_code)){ | |||
| String result_code = returnMap.get("result_code"); | |||
| if("SUCCESS".equals(result_code)){ | |||
| String refund_status_0 = returnMap.get("refund_status_0"); | |||
| if("SUCCESS".equals(refund_status_0)){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_SUCCESS.getCode(),"退款成功",returnMap); | |||
| }else if("REFUNDCLOSE".equals(refund_status_0)){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_FAIL.getCode(),"退款关闭,指商户发起退款失败的情况",returnMap); | |||
| }else if("PROCESSING".equals(refund_status_0)){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_REQ_SUCCESS.getCode(),"退款中",returnMap); | |||
| }else if("CHANGE".equals(refund_status_0)){ | |||
| return new RefundAdapterResult(true,EnumRefundStatus.REFUND_FAIL.getCode(),"退款异常",returnMap); | |||
| }else{ | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(),"查询状态异常 非法状态"); | |||
| } | |||
| }else{ | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(),"查询状态异常 "+returnMap.get("err_code_des")); | |||
| } | |||
| return new RefundAdapterResult(false,ErrorCode.REFUND_ORDER_ERROR.getCode(),errMsg,returnMap); | |||
| }else{ | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(),"查询状态异常 "+returnMap.get("return_msg")); | |||
| } | |||
| // String result_no = returnMap.get("result_code"); | |||
| // if ("SUCCESS".equals(result_no)) { | |||
| // String refund_id = returnMap.get("refund_id"); | |||
| // return new RefundAdapterResult(true,0,"退款",returnMap); | |||
| // } else { | |||
| // String errMsg = ""; | |||
| // JSONObject errObj = errorRefundQueryMap.getJSONObject(result_no); | |||
| // if (errObj != null) { | |||
| // errMsg = errObj.toJSONString(); | |||
| // } else { | |||
| // errMsg = returnMap.get("return_msg"); | |||
| // } | |||
| // return new RefundAdapterResult(false,ErrorCode.REFUND_ORDER_ERROR.getCode(),errMsg,returnMap); | |||
| // } | |||
| } | |||
| } | |||
| @@ -109,7 +109,12 @@ | |||
| <if test=" null != failReason "> | |||
| and `fail_reason` like concat('%', #{failReason},'%') | |||
| </if> | |||
| </if> | |||
| <if test=" null != notStatus "> | |||
| and `refund_order_status` != #{notStatus} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| @@ -127,4 +132,5 @@ | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| </mapper> | |||