| @@ -1,24 +0,0 @@ | |||||
| package com.iformall.config; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @Component | |||||
| @ConfigurationProperties(prefix = "pay") | |||||
| public class PayProperty { | |||||
| /** | |||||
| * 真实支付 | |||||
| */ | |||||
| private boolean real; | |||||
| public boolean isReal() { | |||||
| return real; | |||||
| } | |||||
| public void setReal(boolean real) { | |||||
| this.real = real; | |||||
| } | |||||
| } | |||||
| @@ -3,15 +3,20 @@ package com.iformall.controller; | |||||
| import com.alibaba.fastjson.JSON; | import com.alibaba.fastjson.JSON; | ||||
| import com.alibaba.fastjson.JSONArray; | import com.alibaba.fastjson.JSONArray; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxCampaign; | import com.iformall.domain.po.WxCampaign; | ||||
| import com.iformall.domain.po.WxCoupon; | |||||
| import com.iformall.domain.po.WxCouponChannel; | import com.iformall.domain.po.WxCouponChannel; | ||||
| import com.iformall.domain.vo.WxCouponChannelVo; | import com.iformall.domain.vo.WxCouponChannelVo; | ||||
| import com.iformall.enums.EnumCampaignStatus; | import com.iformall.enums.EnumCampaignStatus; | ||||
| import com.iformall.enums.EnumCampaignType; | |||||
| import com.iformall.enums.EnumCouponChannelType; | import com.iformall.enums.EnumCouponChannelType; | ||||
| import com.iformall.enums.EnumCouponStatus; | |||||
| import com.iformall.service.WxCampaignService; | import com.iformall.service.WxCampaignService; | ||||
| import com.iformall.service.WxCouponChannelService; | import com.iformall.service.WxCouponChannelService; | ||||
| import com.iformall.service.WxCouponService; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| @@ -22,6 +27,7 @@ import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import java.util.Date; | |||||
| import java.util.List; | import java.util.List; | ||||
| @RestController | @RestController | ||||
| @@ -33,6 +39,9 @@ public class WxCampaignController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxCampaignService wxCampaignService; | private WxCampaignService wxCampaignService; | ||||
| @Autowired | |||||
| WxCouponService wxCouponService; | |||||
| @Autowired | @Autowired | ||||
| private WxCouponChannelService wxCouponChannelService; | private WxCouponChannelService wxCouponChannelService; | ||||
| @@ -87,6 +96,26 @@ public class WxCampaignController extends BaseController { | |||||
| @PostMapping("updateStatus") | @PostMapping("updateStatus") | ||||
| public ResultData updateStatus(@RequestBody WxCampaign wxCampaign) { | public ResultData updateStatus(@RequestBody WxCampaign wxCampaign) { | ||||
| logger.debug("[" + getIpAddr() + "] WxCampaignController::updateStatus"); | logger.debug("[" + getIpAddr() + "] WxCampaignController::updateStatus"); | ||||
| // check coupon 状态 | |||||
| if (wxCampaign.getType().equals(EnumCampaignType.STABLE.getCode())) { | |||||
| if (wxCampaign.getStatus().equals(EnumCampaignStatus.STATUS_THROW_IN.getCode())) { | |||||
| List<String> ids = JSONArray.parseArray(wxCampaign.getCouponIds(), String.class); | |||||
| for (String couponIdStr : ids) { | |||||
| Long couponId = Long.parseLong(couponIdStr); | |||||
| WxCoupon wxCoupon = wxCouponService.getById(couponId); | |||||
| if (wxCoupon == null) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||||
| } | |||||
| if (wxCoupon.getStatus() != EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | |||||
| } | |||||
| if (wxCoupon.getValidEndDate() != null && wxCoupon.getValidEndDate().before(new Date())) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| return wxCampaignService.updateStatus(wxCampaign); | return wxCampaignService.updateStatus(wxCampaign); | ||||
| } | } | ||||
| @@ -3,7 +3,6 @@ package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.config.PayProperty; | |||||
| import com.iformall.domain.po.WxAppinfo; | import com.iformall.domain.po.WxAppinfo; | ||||
| import com.iformall.domain.po.WxCouponOrder; | import com.iformall.domain.po.WxCouponOrder; | ||||
| import com.iformall.domain.vo.WxCouponOrderBVo; | import com.iformall.domain.vo.WxCouponOrderBVo; | ||||
| @@ -43,9 +42,6 @@ public class WxCouponOrderController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxAppinfoService wxAppinfoService; | private WxAppinfoService wxAppinfoService; | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @ApiOperation("分页列表接口") | @ApiOperation("分页列表接口") | ||||
| @GetMapping("list") | @GetMapping("list") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @@ -143,7 +139,7 @@ public class WxCouponOrderController extends BaseController { | |||||
| WxAppinfo appinfo = appinfoPageInfo.getList().get(0); | WxAppinfo appinfo = appinfoPageInfo.getList().get(0); | ||||
| if (appinfo != null) { | if (appinfo != null) { | ||||
| try { | try { | ||||
| wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, couponOrderId, EnumPayType.PAY_ADMIN_REFUND, null); | |||||
| wxRefundOrderService.createRefundOrder(appinfo, couponOrderId, EnumPayType.PAY_ADMIN_REFUND, null); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -70,8 +70,4 @@ mapper: | |||||
| mappers: | mappers: | ||||
| - com.iformall.common.CommonMapper | - com.iformall.common.CommonMapper | ||||
| pay: | |||||
| real: true | |||||
| version: @project.version@ | version: @project.version@ | ||||
| @@ -1,24 +0,0 @@ | |||||
| package com.iformall.config; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @Component | |||||
| @ConfigurationProperties(prefix = "pay") | |||||
| public class PayProperty { | |||||
| /** | |||||
| * 真实支付 | |||||
| */ | |||||
| private boolean real; | |||||
| public boolean isReal() { | |||||
| return real; | |||||
| } | |||||
| public void setReal(boolean real) { | |||||
| this.real = real; | |||||
| } | |||||
| } | |||||
| @@ -3,7 +3,6 @@ package com.iformall.controller; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.config.PayProperty; | |||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.EnumOrderType; | import com.iformall.enums.EnumOrderType; | ||||
| import com.iformall.enums.EnumPayType; | import com.iformall.enums.EnumPayType; | ||||
| @@ -33,9 +32,6 @@ import java.util.Map; | |||||
| public class WxMicroPayController extends BaseController { | public class WxMicroPayController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @Autowired | @Autowired | ||||
| WxMerchantBUserService wxMerchantBUserService; | WxMerchantBUserService wxMerchantBUserService; | ||||
| @@ -98,7 +94,7 @@ public class WxMicroPayController extends BaseController { | |||||
| record.setIp(ipStr); | record.setIp(ipStr); | ||||
| try { | try { | ||||
| return wxPayOrderService.createMicroPayOrder(payProperty.isReal(), user, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| return wxPayOrderService.createMicroPayOrder(user, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | ||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | return new ResultData(e.getErrorCode(), e.getMessage()); | ||||
| @@ -253,7 +249,7 @@ public class WxMicroPayController extends BaseController { | |||||
| WxMerchantBUser bUser = getUser(); | WxMerchantBUser bUser = getUser(); | ||||
| WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | ||||
| try { | try { | ||||
| ResultData rd = wxRefundOrderService.createRefundOrderFromMicroPay(payProperty.isReal(), appinfo, orderId, EnumPayType.PAY_B_REFUND, bUser.getId()); | |||||
| ResultData rd = wxRefundOrderService.createRefundOrderFromMicroPay(appinfo, orderId, EnumPayType.PAY_B_REFUND, bUser.getId()); | |||||
| return rd; | return rd; | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("退款 1:" + e.getMessage()); | logger.error("退款 1:" + e.getMessage()); | ||||
| @@ -3,7 +3,6 @@ package com.iformall.controller; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.config.PayProperty; | |||||
| import com.iformall.domain.po.WxAppinfo; | import com.iformall.domain.po.WxAppinfo; | ||||
| import com.iformall.domain.po.WxPayBill; | import com.iformall.domain.po.WxPayBill; | ||||
| import com.iformall.enums.EnumPayStatus; | import com.iformall.enums.EnumPayStatus; | ||||
| @@ -31,9 +30,6 @@ import java.util.Map; | |||||
| public class WxPayBillController extends BaseController { | public class WxPayBillController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @Autowired | @Autowired | ||||
| private WxPayBillService wxPayBillService; | private WxPayBillService wxPayBillService; | ||||
| @@ -83,7 +79,7 @@ public class WxPayBillController extends BaseController { | |||||
| record.setTenantId(appInfo.getTenantId()); | record.setTenantId(appInfo.getTenantId()); | ||||
| try { | try { | ||||
| record.setIp(IPUtil.getIpAddr(request)); | record.setIp(IPUtil.getIpAddr(request)); | ||||
| return wxPayBillService.createPayBill(payProperty.isReal(), appInfo, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| return wxPayBillService.createPayBill(appInfo, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | ||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | return new ResultData(e.getErrorCode(), e.getMessage()); | ||||
| @@ -4,12 +4,9 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.config.PayProperty; | |||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.EnumPayType; | import com.iformall.enums.EnumPayType; | ||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.service.WxCouponOrderService; | |||||
| import com.iformall.service.WxOrderService; | |||||
| import com.iformall.service.WxRefundOrderService; | import com.iformall.service.WxRefundOrderService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| @@ -29,9 +26,6 @@ import java.util.Map; | |||||
| public class WxRefundOrderController extends BaseController { | public class WxRefundOrderController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @Autowired | @Autowired | ||||
| private WxRefundOrderService wxRefundOrderService; | private WxRefundOrderService wxRefundOrderService; | ||||
| @@ -57,7 +51,7 @@ public class WxRefundOrderController extends BaseController { | |||||
| WxMerchantBUser bUser = getUser(); | WxMerchantBUser bUser = getUser(); | ||||
| WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | ||||
| try { | try { | ||||
| ResultData rd = wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, couponOrderId, EnumPayType.PAY_B_REFUND, bUser.getId()); | |||||
| ResultData rd = wxRefundOrderService.createRefundOrder(appinfo, couponOrderId, EnumPayType.PAY_B_REFUND, bUser.getId()); | |||||
| return rd; | return rd; | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -49,8 +49,4 @@ mapper: | |||||
| mappers: | mappers: | ||||
| - com.iformall.common.CommonMapper | - com.iformall.common.CommonMapper | ||||
| pay: | |||||
| real: true | |||||
| version: @project.version@ | version: @project.version@ | ||||
| @@ -1,24 +0,0 @@ | |||||
| package com.iformall.config; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @Component | |||||
| @ConfigurationProperties(prefix = "pay") | |||||
| public class PayProperty { | |||||
| /** | |||||
| * 真实支付 | |||||
| */ | |||||
| private boolean real; | |||||
| public boolean isReal() { | |||||
| return real; | |||||
| } | |||||
| public void setReal(boolean real) { | |||||
| this.real = real; | |||||
| } | |||||
| } | |||||
| @@ -4,7 +4,6 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.config.PayProperty; | |||||
| import com.iformall.domain.po.WxAppinfo; | import com.iformall.domain.po.WxAppinfo; | ||||
| import com.iformall.domain.po.WxCUser; | import com.iformall.domain.po.WxCUser; | ||||
| import com.iformall.domain.po.WxOrder; | import com.iformall.domain.po.WxOrder; | ||||
| @@ -34,9 +33,6 @@ import java.util.Map; | |||||
| public class WxPayOrderController extends BaseController { | public class WxPayOrderController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @Autowired | @Autowired | ||||
| private WxPayOrderService wxPayOrderService; | private WxPayOrderService wxPayOrderService; | ||||
| @@ -70,7 +66,7 @@ public class WxPayOrderController extends BaseController { | |||||
| try { | try { | ||||
| record.setIp(IPUtil.getIpAddr(request)); | record.setIp(IPUtil.getIpAddr(request)); | ||||
| return wxPayOrderService.createPayOrder(payProperty.isReal(), appInfo, user, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| return wxPayOrderService.createPayOrder(appInfo, user, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | ||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | return new ResultData(e.getErrorCode(), e.getMessage()); | ||||
| @@ -365,7 +365,7 @@ public class WxUserGrantController extends BaseController { | |||||
| * 检查用户状态 | * 检查用户状态 | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| @GetMapping("/checkUserStatus") | |||||
| @RequestMapping("/checkUserStatus") | |||||
| @ApiOperation(value = "判断是否是老用户", notes="") | @ApiOperation(value = "判断是否是老用户", notes="") | ||||
| public ResultData checkUserStatus() { | public ResultData checkUserStatus() { | ||||
| Map resultMap = new HashMap(); | Map resultMap = new HashMap(); | ||||
| @@ -384,7 +384,7 @@ public class WxUserGrantController extends BaseController { | |||||
| * 检查用户状态 | * 检查用户状态 | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| @GetMapping("/checkPhoneStatus") | |||||
| @RequestMapping("/checkPhoneStatus") | |||||
| @ApiOperation(value = "判断是否是老用户", notes="") | @ApiOperation(value = "判断是否是老用户", notes="") | ||||
| public ResultData checkPhoneStatus() { | public ResultData checkPhoneStatus() { | ||||
| Map resultMap = new HashMap(); | Map resultMap = new HashMap(); | ||||
| @@ -566,7 +566,7 @@ public class WxUserGrantController extends BaseController { | |||||
| * 获取用户折扣率 | * 获取用户折扣率 | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| @GetMapping("/getDiscountInfo") | |||||
| @RequestMapping("/getDiscountInfo") | |||||
| @ApiOperation(value = "获取用户折扣率", notes="") | @ApiOperation(value = "获取用户折扣率", notes="") | ||||
| public ResultData getDiscountInfo() { | public ResultData getDiscountInfo() { | ||||
| @@ -49,8 +49,4 @@ mapper: | |||||
| mappers: | mappers: | ||||
| - com.iformall.common.CommonMapper | - com.iformall.common.CommonMapper | ||||
| pay: | |||||
| real: true | |||||
| version: @project.version@ | version: @project.version@ | ||||
| @@ -1,24 +0,0 @@ | |||||
| package com.iformall.config; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @Component | |||||
| @ConfigurationProperties(prefix = "pay") | |||||
| public class PayProperty { | |||||
| /** | |||||
| * 真实支付 | |||||
| */ | |||||
| private boolean real; | |||||
| public boolean isReal() { | |||||
| return real; | |||||
| } | |||||
| public void setReal(boolean real) { | |||||
| this.real = real; | |||||
| } | |||||
| } | |||||
| @@ -66,8 +66,4 @@ mapper: | |||||
| mappers: | mappers: | ||||
| - com.iformall.common.CommonMapper | - com.iformall.common.CommonMapper | ||||
| pay: | |||||
| real: true | |||||
| version: @project.version@ | version: @project.version@ | ||||
| @@ -1,24 +0,0 @@ | |||||
| package com.iformall.config; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @Component | |||||
| @ConfigurationProperties(prefix = "pay") | |||||
| public class PayProperty { | |||||
| /** | |||||
| * 真实支付 | |||||
| */ | |||||
| private boolean real; | |||||
| public boolean isReal() { | |||||
| return real; | |||||
| } | |||||
| public void setReal(boolean real) { | |||||
| this.real = real; | |||||
| } | |||||
| } | |||||
| @@ -1,15 +1,11 @@ | |||||
| package com.iformall.schedule; | package com.iformall.schedule; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.config.PayProperty; | |||||
| import com.iformall.domain.dto.WxSharingOrderDto; | import com.iformall.domain.dto.WxSharingOrderDto; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.mapper.*; | import com.iformall.mapper.*; | ||||
| import com.iformall.service.WxOrderService; | import com.iformall.service.WxOrderService; | ||||
| import com.iformall.service.WxPayOrderService; | |||||
| import com.iformall.service.WxProfitSharingOrderService; | import com.iformall.service.WxProfitSharingOrderService; | ||||
| import com.iformall.service.WxRefundOrderService; | import com.iformall.service.WxRefundOrderService; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -27,13 +23,9 @@ import java.util.List; | |||||
| public class CouponOrderExpiringSchedule { | public class CouponOrderExpiringSchedule { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | @Autowired | ||||
| private WxCouponOrderMapper wxCouponOrderMapper; | private WxCouponOrderMapper wxCouponOrderMapper; | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @Autowired | @Autowired | ||||
| private WxRefundOrderService wxRefundOrderService; | private WxRefundOrderService wxRefundOrderService; | ||||
| @@ -127,7 +119,7 @@ public class CouponOrderExpiringSchedule { | |||||
| appinfo = wxAppinfoMapper.findList(appinfo).get(0); | appinfo = wxAppinfoMapper.findList(appinfo).get(0); | ||||
| try { | try { | ||||
| wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, co.getId(), EnumPayType.PAY_AUTO_REFUND, null); | |||||
| wxRefundOrderService.createRefundOrder(appinfo, co.getId(), EnumPayType.PAY_AUTO_REFUND, null); | |||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("退款失败:"+e.getMessage()+"couponOrderId="+co.getId()); | logger.error("退款失败:"+e.getMessage()+"couponOrderId="+co.getId()); | ||||
| throw new MallinkException(e.getErrorCode(), e.getMessage()); | throw new MallinkException(e.getErrorCode(), e.getMessage()); | ||||
| @@ -66,8 +66,4 @@ mapper: | |||||
| mappers: | mappers: | ||||
| - com.iformall.common.CommonMapper | - com.iformall.common.CommonMapper | ||||
| pay: | |||||
| real: true | |||||
| version: @project.version@ | version: @project.version@ | ||||
| @@ -163,6 +163,10 @@ public class WxCoupon implements Serializable { | |||||
| @Transient | @Transient | ||||
| private String merchantParams; | private String merchantParams; | ||||
| /**投放频道参数,用来过滤**/ | |||||
| @Transient | |||||
| private Integer targetAd; | |||||
| //营销分析 | //营销分析 | ||||
| private WxCouponStatisVo wxCouponStatisVo; | private WxCouponStatisVo wxCouponStatisVo; | ||||
| @@ -442,6 +446,14 @@ public class WxCoupon implements Serializable { | |||||
| this.autoRefund = autoRefund; | this.autoRefund = autoRefund; | ||||
| } | } | ||||
| public Integer getTargetAd() { | |||||
| return targetAd; | |||||
| } | |||||
| public void setTargetAd(Integer targetAd) { | |||||
| this.targetAd = targetAd; | |||||
| } | |||||
| public static enum Field | public static enum Field | ||||
| { | { | ||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | ||||
| @@ -19,7 +19,7 @@ public interface WxPayBillService { | |||||
| * @param payWay | * @param payWay | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| ResultData createPayBill(boolean isReal, WxAppinfo appInfo, WxPayBill record, EnumPayWay payWay); | |||||
| ResultData createPayBill(WxAppinfo appInfo, WxPayBill record, EnumPayWay payWay); | |||||
| /** | /** | ||||
| * 微信支付订单查询 | * 微信支付订单查询 | ||||
| @@ -19,7 +19,7 @@ public interface WxPayOrderService { | |||||
| * @param payWay | * @param payWay | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| ResultData createPayOrder(boolean isReal, WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay); | |||||
| ResultData createPayOrder(WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay); | |||||
| /** | /** | ||||
| * 刷卡支付订单 | * 刷卡支付订单 | ||||
| @@ -28,7 +28,7 @@ public interface WxPayOrderService { | |||||
| * @param payWay | * @param payWay | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| ResultData createMicroPayOrder(boolean isReal, WxMerchantBUser user, WxPayOrder record, EnumPayWay payWay); | |||||
| ResultData createMicroPayOrder(WxMerchantBUser user, WxPayOrder record, EnumPayWay payWay); | |||||
| /** | /** | ||||
| * 微信支付订单查询 | * 微信支付订单查询 | ||||
| @@ -14,25 +14,23 @@ public interface WxRefundOrderService { | |||||
| /** | /** | ||||
| * 创建退款订单 | * 创建退款订单 | ||||
| * @param isReal | |||||
| * @param appInfo | * @param appInfo | ||||
| * @param couponOrderId 券包Id | * @param couponOrderId 券包Id | ||||
| * @param payType 退款来源 | * @param payType 退款来源 | ||||
| * @param bUserId b端退款Id,auto,admin,self可为null | * @param bUserId b端退款Id,auto,admin,self可为null | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| ResultData createRefundOrder(boolean isReal, WxAppinfo appInfo, Long couponOrderId, EnumPayType payType, Long bUserId); | |||||
| ResultData createRefundOrder(WxAppinfo appInfo, Long couponOrderId, EnumPayType payType, Long bUserId); | |||||
| /** | /** | ||||
| * 创建退款订单 | * 创建退款订单 | ||||
| * @param isReal | |||||
| * @param appInfo | * @param appInfo | ||||
| * @param orderId 订单Id | * @param orderId 订单Id | ||||
| * @param payType 退款来源 | * @param payType 退款来源 | ||||
| * @param bUserId b端退款Id,auto,admin,self可为null | * @param bUserId b端退款Id,auto,admin,self可为null | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| ResultData createRefundOrderFromMicroPay(boolean isReal, WxAppinfo appInfo, Long orderId, EnumPayType payType, Long bUserId); | |||||
| ResultData createRefundOrderFromMicroPay(WxAppinfo appInfo, Long orderId, EnumPayType payType, Long bUserId); | |||||
| /** | /** | ||||
| * 退款订单查询 | * 退款订单查询 | ||||
| @@ -74,7 +74,7 @@ public class WxCouponServiceImpl implements WxCouponService { | |||||
| List<WxCoupon> wxCouponList = page.getList(); | List<WxCoupon> wxCouponList = page.getList(); | ||||
| if (wxCouponList.isEmpty()) { | |||||
| if (wxCouponList.isEmpty() || wxCoupon.getTargetAd() != null) { | |||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @@ -81,7 +81,7 @@ public class WxPayBillServiceImpl implements WxPayBillService { | |||||
| "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); | "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); | ||||
| @Override | @Override | ||||
| public ResultData createPayBill(boolean isReal, WxAppinfo appInfo, WxPayBill record, EnumPayWay payWay) { | |||||
| public ResultData createPayBill(WxAppinfo appInfo, WxPayBill record, EnumPayWay payWay) { | |||||
| final IdWorker idworker = IdWorker.get(); | final IdWorker idworker = IdWorker.get(); | ||||
| EnumPayShare isShare = EnumPayShare.NO; | EnumPayShare isShare = EnumPayShare.NO; | ||||
| @@ -109,7 +109,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); | "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); | ||||
| @Override | @Override | ||||
| public ResultData createPayOrder(boolean isReal, WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay) { | |||||
| public ResultData createPayOrder(WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay) { | |||||
| final IdWorker idworker = IdWorker.get(); | final IdWorker idworker = IdWorker.get(); | ||||
| EnumPayShare isShare = EnumPayShare.NO; | EnumPayShare isShare = EnumPayShare.NO; | ||||
| @@ -134,7 +134,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| throw new MallinkException(ErrorCode.COUPON_CHANNEL_IS_TAKE_OFF); | throw new MallinkException(ErrorCode.COUPON_CHANNEL_IS_TAKE_OFF); | ||||
| } | } | ||||
| if(order.getPressEndDate() == null) { | |||||
| if (order.getPressEndDate() == null) { | |||||
| // 非砍价券 | // 非砍价券 | ||||
| if (order.getOrderStatus() == EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()) { | if (order.getOrderStatus() == EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()) { | ||||
| logger.error("订单已支付: " + order.toString() + " , payWay: " + payWay.toString()); | logger.error("订单已支付: " + order.toString() + " , payWay: " + payWay.toString()); | ||||
| @@ -143,12 +143,12 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| logger.error("订单已取消: " + order.toString() + " , payWay: " + payWay.toString()); | logger.error("订单已取消: " + order.toString() + " , payWay: " + payWay.toString()); | ||||
| throw new MallinkException(ErrorCode.ORDER_HAD_CANCEL); | throw new MallinkException(ErrorCode.ORDER_HAD_CANCEL); | ||||
| } else { | } else { | ||||
| if(order.getOrderStatus() != EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()) { | |||||
| if (order.getOrderStatus() != EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()) { | |||||
| logger.error("订单已支付: " + order.toString() + " , payWay: " + payWay.toString()); | logger.error("订单已支付: " + order.toString() + " , payWay: " + payWay.toString()); | ||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_PAY); | throw new MallinkException(ErrorCode.ORDER_IS_NOT_PAY); | ||||
| } | } | ||||
| } | } | ||||
| } else if(order.getPressEndDate() != null) { | |||||
| } else if (order.getPressEndDate() != null) { | |||||
| // 砍价券,只有在过期时无法支付 | // 砍价券,只有在过期时无法支付 | ||||
| // 砍价中,原价购买 | // 砍价中,原价购买 | ||||
| // 砍价完成,低价购买 | // 砍价完成,低价购买 | ||||
| @@ -221,184 +221,159 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| } | } | ||||
| } | } | ||||
| if (isReal) { | |||||
| // 微信实际支付 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 统一下单 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxPayOrderP wxPayOrderP = new WxPayOrderP(); | |||||
| wxPayOrderP.setOpenid(user.getOpenId()); | |||||
| wxPayOrderP.setAppid(user.getAppId()); | |||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderP.setNonce_str(noncestr); | |||||
| wxPayOrderP.setBody(order.getDetail()); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderP.setGoods_tag(String.valueOf(order.getProductId())); | |||||
| wxPayOrderP.setNotify_url(payAccount.getPayNotifyUrl()); | |||||
| wxPayOrderP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||||
| wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderP); | |||||
| wxPayOrderP.setSign(WxPayment.createSign(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); | |||||
| logger.info("pay order, wechat pushOrder, " + wxPayOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String prepay_id = returnMap.get("prepay_id"); | |||||
| // update payOrder with prepay_id | |||||
| record.setPrepayId(prepay_id); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | |||||
| Map<String, String> sighMap = MapUtil.getOrderMap(); | |||||
| sighMap.put("appId", returnMap.get("appid")); | |||||
| sighMap.put("timeStamp", timestamp); | |||||
| sighMap.put("nonceStr", noncestr); | |||||
| sighMap.put("package", "prepay_id=" + prepay_id); | |||||
| sighMap.put("signType", "MD5"); | |||||
| String signAgent = WxPayment.createSign(sighMap, payAccount.getApiKey()); | |||||
| returnMap.put("timeStamp", timestamp); | |||||
| returnMap.put("nonceStr", noncestr); | |||||
| returnMap.put("package", "prepay_id=" + prepay_id); | |||||
| returnMap.put("paySign", signAgent); | |||||
| logger.info("back to UI: " + returnMap.toString()); | |||||
| return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); | |||||
| } else { | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 统一下单 // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxPayOrderSP wxPayOrderSP = new WxPayOrderSP(); | |||||
| wxPayOrderSP.setSub_openid(user.getOpenId()); | |||||
| wxPayOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxPayOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderSP.setSub_appid(user.getAppId()); | |||||
| wxPayOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxPayOrderSP.setNonce_str(noncestr); | |||||
| wxPayOrderSP.setBody(order.getDetail()); | |||||
| wxPayOrderSP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderSP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderSP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderSP.setGoods_tag(String.valueOf(order.getProductId())); // 券ID | |||||
| wxPayOrderSP.setNotify_url(payAccount.getPayNotifyUrl()); | |||||
| wxPayOrderSP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||||
| wxPayOrderSP.setProduct_id(String.valueOf(order.getProductId())); // 券ID | |||||
| wxPayOrderSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| wxPayOrderSP.setSign_type("HMAC-SHA256"); | |||||
| wxPayOrderSP.setProfit_sharing(null); | |||||
| if (isShare == EnumPayShare.YES) { | |||||
| wxPayOrderSP.setProfit_sharing("Y"); | |||||
| } | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderSP); | |||||
| wxPayOrderSP.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderSP)); | |||||
| logger.info("pay order, wechat pushOrder, " + wxPayOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String prepay_id = returnMap.get("prepay_id"); | |||||
| // update payOrder with prepay_id | |||||
| record.setPrepayId(prepay_id); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | |||||
| Map<String, String> sighMap = MapUtil.getOrderMap(); | |||||
| sighMap.put("appId", appInfo.getAppId()); | |||||
| sighMap.put("timeStamp", timestamp); | |||||
| sighMap.put("nonceStr", noncestr); | |||||
| sighMap.put("package", "prepay_id=" + prepay_id); | |||||
| sighMap.put("signType", "HMAC-SHA256"); | |||||
| String signAgent = WxPayment.createSignHMAC(sighMap, payAccount.getApiKey()); | |||||
| returnMap.put("timeStamp", timestamp); | |||||
| returnMap.put("nonceStr", noncestr); | |||||
| returnMap.put("package", "prepay_id=" + prepay_id); | |||||
| returnMap.put("paySign", signAgent); | |||||
| returnMap.put("signType", "HMAC-SHA256"); | |||||
| logger.info("back to UI: " + returnMap.toString()); | |||||
| return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); | |||||
| } else { | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } | |||||
| } else { | |||||
| // 虚拟支付 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 统一下单 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxPayOrderP wxPayOrderP = new WxPayOrderP(); | WxPayOrderP wxPayOrderP = new WxPayOrderP(); | ||||
| wxPayOrderP.setOpenid(user.getOpenId()); | wxPayOrderP.setOpenid(user.getOpenId()); | ||||
| wxPayOrderP.setAppid(user.getAppId()); | wxPayOrderP.setAppid(user.getAppId()); | ||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | wxPayOrderP.setMch_id(payAccount.getMchId()); | ||||
| wxPayOrderP.setNonce_str(noncestr); | |||||
| wxPayOrderP.setBody(order.getDetail()); | wxPayOrderP.setBody(order.getDetail()); | ||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | ||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | wxPayOrderP.setTotal_fee(order.getPayment()); | ||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | ||||
| wxPayOrderP.setGoods_tag(String.valueOf(order.getProductId())); // 券ID | |||||
| wxPayOrderP.setGoods_tag(String.valueOf(order.getProductId())); | |||||
| wxPayOrderP.setNotify_url(payAccount.getPayNotifyUrl()); | wxPayOrderP.setNotify_url(payAccount.getPayNotifyUrl()); | ||||
| wxPayOrderP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | wxPayOrderP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | ||||
| wxPayOrderP.setProduct_id(String.valueOf(order.getProductId())); // 券ID | |||||
| wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | ||||
| Date futureDate = new Date(); | Date futureDate = new Date(); | ||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | ||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | ||||
| wxPayOrderP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxPayOrderP), payAccount.getApiKey())); | |||||
| Map<String, String> returnMap = BeanUtils.toStringMap(wxPayOrderP); | |||||
| return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderP); | |||||
| wxPayOrderP.setSign(WxPayment.createSign(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); | |||||
| logger.info("pay order, wechat pushOrder, " + wxPayOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String prepay_id = returnMap.get("prepay_id"); | |||||
| // update payOrder with prepay_id | |||||
| record.setPrepayId(prepay_id); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | |||||
| Map<String, String> sighMap = MapUtil.getOrderMap(); | |||||
| sighMap.put("appId", returnMap.get("appid")); | |||||
| sighMap.put("timeStamp", timestamp); | |||||
| sighMap.put("nonceStr", noncestr); | |||||
| sighMap.put("package", "prepay_id=" + prepay_id); | |||||
| sighMap.put("signType", "MD5"); | |||||
| String signAgent = WxPayment.createSign(sighMap, payAccount.getApiKey()); | |||||
| returnMap.put("timeStamp", timestamp); | |||||
| returnMap.put("nonceStr", noncestr); | |||||
| returnMap.put("package", "prepay_id=" + prepay_id); | |||||
| returnMap.put("paySign", signAgent); | |||||
| logger.info("back to UI: " + returnMap.toString()); | |||||
| return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); | |||||
| } else { | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 统一下单 // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxPayOrderSP wxPayOrderSP = new WxPayOrderSP(); | |||||
| wxPayOrderSP.setSub_openid(user.getOpenId()); | |||||
| wxPayOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxPayOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderSP.setSub_appid(user.getAppId()); | |||||
| wxPayOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxPayOrderSP.setNonce_str(noncestr); | |||||
| wxPayOrderSP.setBody(order.getDetail()); | |||||
| wxPayOrderSP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderSP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderSP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderSP.setGoods_tag(String.valueOf(order.getProductId())); // 券ID | |||||
| wxPayOrderSP.setNotify_url(payAccount.getPayNotifyUrl()); | |||||
| wxPayOrderSP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||||
| wxPayOrderSP.setProduct_id(String.valueOf(order.getProductId())); // 券ID | |||||
| wxPayOrderSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| wxPayOrderSP.setSign_type("HMAC-SHA256"); | |||||
| wxPayOrderSP.setProfit_sharing(null); | |||||
| if (isShare == EnumPayShare.YES) { | |||||
| wxPayOrderSP.setProfit_sharing("Y"); | |||||
| } | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderSP); | |||||
| wxPayOrderSP.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderSP)); | |||||
| logger.info("pay order, wechat pushOrder, " + wxPayOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String prepay_id = returnMap.get("prepay_id"); | |||||
| // update payOrder with prepay_id | |||||
| record.setPrepayId(prepay_id); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | |||||
| Map<String, String> sighMap = MapUtil.getOrderMap(); | |||||
| sighMap.put("appId", appInfo.getAppId()); | |||||
| sighMap.put("timeStamp", timestamp); | |||||
| sighMap.put("nonceStr", noncestr); | |||||
| sighMap.put("package", "prepay_id=" + prepay_id); | |||||
| sighMap.put("signType", "HMAC-SHA256"); | |||||
| String signAgent = WxPayment.createSignHMAC(sighMap, payAccount.getApiKey()); | |||||
| returnMap.put("timeStamp", timestamp); | |||||
| returnMap.put("nonceStr", noncestr); | |||||
| returnMap.put("package", "prepay_id=" + prepay_id); | |||||
| returnMap.put("paySign", signAgent); | |||||
| returnMap.put("signType", "HMAC-SHA256"); | |||||
| logger.info("back to UI: " + returnMap.toString()); | |||||
| return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); | |||||
| } else { | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } | } | ||||
| } catch (RuntimeException e) { | } catch (RuntimeException e) { | ||||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | ||||
| @@ -408,7 +383,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public ResultData createMicroPayOrder(boolean isReal, WxMerchantBUser user, WxPayOrder record, EnumPayWay payWay) { | |||||
| public ResultData createMicroPayOrder(WxMerchantBUser user, WxPayOrder record, EnumPayWay payWay) { | |||||
| final IdWorker idworker = IdWorker.get(); | final IdWorker idworker = IdWorker.get(); | ||||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(user.getTenantId()); | WxAppinfo appInfo = wxAppinfoService.getCAppInfo(user.getTenantId()); | ||||
| @@ -493,62 +468,47 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| payOrderNo = String.valueOf(record.getId()); | payOrderNo = String.valueOf(record.getId()); | ||||
| } | } | ||||
| if (isReal) { | |||||
| // 微信实际支付 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 刷卡支付 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxMicroPayOrderP wxPayOrderP = new WxMicroPayOrderP(); | |||||
| wxPayOrderP.setAppid(user.getAppId()); | |||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderP.setDevice_info(user.getPhone()); | |||||
| wxPayOrderP.setNonce_str(noncestr); | |||||
| wxPayOrderP.setBody(order.getDetail()); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderP.setAuth_code(record.getAuthCode()); | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderP); | |||||
| wxPayOrderP.setSign(WxPayment.createSign(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.micropay(BeanUtils.toStringMap(wxPayOrderP)); | |||||
| logger.info("pay order, wechat micropay, " + wxPayOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| returnMap.put("orderId", orderNo); | |||||
| String return_code = returnMap.get("return_code"); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String openId = returnMap.get("openid"); | |||||
| String isSubscribe = returnMap.get("is_subscribe"); | |||||
| String transactionId = returnMap.get("transaction_id"); | |||||
| record.setTransactionId(transactionId); | |||||
| record.setUpdateTime(new Date()); | |||||
| handleMicroOrderPaySuccess(record, transactionId, openId, isSubscribe); | |||||
| return new ResultData(Result.SUCCESS, "刷卡支付成功", returnMap); | |||||
| } else { | |||||
| String err_code = returnMap.get("err_code"); | |||||
| String errMsg = returnMap.get("err_code_des"); | |||||
| if (errMsg.length() <= 0) { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| } | |||||
| record.setFailReason(errMsg); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 刷卡支付 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxMicroPayOrderP wxPayOrderP = new WxMicroPayOrderP(); | |||||
| wxPayOrderP.setAppid(user.getAppId()); | |||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderP.setDevice_info(user.getPhone()); | |||||
| wxPayOrderP.setNonce_str(noncestr); | |||||
| wxPayOrderP.setBody(order.getDetail()); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderP.setAuth_code(record.getAuthCode()); | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderP); | |||||
| wxPayOrderP.setSign(WxPayment.createSign(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.micropay(BeanUtils.toStringMap(wxPayOrderP)); | |||||
| logger.info("pay order, wechat micropay, " + wxPayOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| returnMap.put("orderId", orderNo); | |||||
| String return_code = returnMap.get("return_code"); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String openId = returnMap.get("openid"); | |||||
| String isSubscribe = returnMap.get("is_subscribe"); | |||||
| String transactionId = returnMap.get("transaction_id"); | |||||
| record.setTransactionId(transactionId); | |||||
| record.setUpdateTime(new Date()); | |||||
| handleMicroOrderPaySuccess(record, transactionId, openId, isSubscribe); | |||||
| return new ResultData(Result.SUCCESS, "刷卡支付成功", returnMap); | |||||
| } else { | } else { | ||||
| String errMsg = returnMap.get("return_msg"); | |||||
| String err_code = returnMap.get("err_code"); | |||||
| String errMsg = returnMap.get("err_code_des"); | |||||
| if (errMsg.length() <= 0) { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| } | |||||
| record.setFailReason(errMsg); | record.setFailReason(errMsg); | ||||
| record.setUpdateTime(new Date()); | record.setUpdateTime(new Date()); | ||||
| try { | try { | ||||
| @@ -560,66 +520,66 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | ||||
| } | } | ||||
| } else { | } else { | ||||
| // 统一下单 // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxMicroPayOrderSP wxPayOrderSP = new WxMicroPayOrderSP(); | |||||
| wxPayOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxPayOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderSP.setSub_appid(appInfo.getAppId()); | |||||
| wxPayOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxPayOrderSP.setDevice_info(user.getPhone()); | |||||
| wxPayOrderSP.setNonce_str(noncestr); | |||||
| wxPayOrderSP.setBody(order.getDetail()); | |||||
| wxPayOrderSP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderSP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderSP.setSpbill_create_ip(record.getIp()); | |||||
| wxPayOrderSP.setAuth_code(record.getAuthCode()); | |||||
| wxPayOrderSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| wxPayOrderSP.setSign_type("HMAC-SHA256"); | |||||
| wxPayOrderSP.setProfit_sharing(null); | |||||
| if (isShare == EnumPayShare.YES) { | |||||
| wxPayOrderSP.setProfit_sharing("Y"); | |||||
| String errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | } | ||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderSP); | |||||
| wxPayOrderSP.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.micropay(BeanUtils.toStringMap(wxPayOrderSP)); | |||||
| logger.info("pay order, wechat micropay, " + wxPayOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| returnMap.put("orderId", orderNo); | |||||
| String return_code = returnMap.get("return_code"); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String openId = returnMap.get("sub_openid"); | |||||
| String isSubscribe = returnMap.get("sub_is_subscribe"); | |||||
| String transactionId = returnMap.get("transaction_id"); | |||||
| record.setTransactionId(transactionId); | |||||
| record.setUpdateTime(new Date()); | |||||
| handleMicroOrderPaySuccess(record, transactionId, openId, isSubscribe); | |||||
| return new ResultData(Result.SUCCESS, "刷卡支付成功", returnMap); | |||||
| } else { | |||||
| String err_code = returnMap.get("err_code"); | |||||
| String errMsg = returnMap.get("err_code_des"); | |||||
| if (errMsg.length() <= 0) { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| } | |||||
| record.setFailReason(errMsg); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 统一下单 // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxMicroPayOrderSP wxPayOrderSP = new WxMicroPayOrderSP(); | |||||
| wxPayOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxPayOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderSP.setSub_appid(appInfo.getAppId()); | |||||
| wxPayOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxPayOrderSP.setDevice_info(user.getPhone()); | |||||
| wxPayOrderSP.setNonce_str(noncestr); | |||||
| wxPayOrderSP.setBody(order.getDetail()); | |||||
| wxPayOrderSP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderSP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderSP.setSpbill_create_ip(record.getIp()); | |||||
| wxPayOrderSP.setAuth_code(record.getAuthCode()); | |||||
| wxPayOrderSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| wxPayOrderSP.setSign_type("HMAC-SHA256"); | |||||
| wxPayOrderSP.setProfit_sharing(null); | |||||
| if (isShare == EnumPayShare.YES) { | |||||
| wxPayOrderSP.setProfit_sharing("Y"); | |||||
| } | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderSP); | |||||
| wxPayOrderSP.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.micropay(BeanUtils.toStringMap(wxPayOrderSP)); | |||||
| logger.info("pay order, wechat micropay, " + wxPayOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| returnMap.put("orderId", orderNo); | |||||
| String return_code = returnMap.get("return_code"); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String openId = returnMap.get("sub_openid"); | |||||
| String isSubscribe = returnMap.get("sub_is_subscribe"); | |||||
| String transactionId = returnMap.get("transaction_id"); | |||||
| record.setTransactionId(transactionId); | |||||
| record.setUpdateTime(new Date()); | |||||
| handleMicroOrderPaySuccess(record, transactionId, openId, isSubscribe); | |||||
| return new ResultData(Result.SUCCESS, "刷卡支付成功", returnMap); | |||||
| } else { | } else { | ||||
| String errMsg = returnMap.get("return_msg"); | |||||
| String err_code = returnMap.get("err_code"); | |||||
| String errMsg = returnMap.get("err_code_des"); | |||||
| if (errMsg.length() <= 0) { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| } | |||||
| record.setFailReason(errMsg); | record.setFailReason(errMsg); | ||||
| record.setUpdateTime(new Date()); | record.setUpdateTime(new Date()); | ||||
| try { | try { | ||||
| @@ -630,25 +590,18 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| } | } | ||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | ||||
| } | } | ||||
| } else { | |||||
| String errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | } | ||||
| } else { | |||||
| // 虚拟支付 | |||||
| WxMicroPayOrderP wxPayOrderP = new WxMicroPayOrderP(); | |||||
| wxPayOrderP.setAppid(user.getAppId()); | |||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderP.setBody(order.getDetail()); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderP.setDevice_info(user.getPhone()); | |||||
| wxPayOrderP.setAuth_code(record.getAuthCode()); | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| wxPayOrderP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxPayOrderP), payAccount.getApiKey())); | |||||
| Map<String, String> returnMap = BeanUtils.toStringMap(wxPayOrderP); | |||||
| return new ResultData(Result.SUCCESS, "创建刷卡支付订单成功", returnMap); | |||||
| } | } | ||||
| } catch (RuntimeException e) { | } catch (RuntimeException e) { | ||||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | ||||
| @@ -1363,7 +1316,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| wxCouponOrderService.sendCouponAfterMicroPay(record.getTenantId(), record.getOrderId(), record.getcUserId()); | wxCouponOrderService.sendCouponAfterMicroPay(record.getTenantId(), record.getOrderId(), record.getcUserId()); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("订单刷卡发券失败: orderId: {}, payOrderId: {}", record.getOrderId(), record.getId()); | logger.error("订单刷卡发券失败: orderId: {}, payOrderId: {}", record.getOrderId(), record.getId()); | ||||
| logger.error("订单刷卡发券失败: " +e.getMessage()); | |||||
| logger.error("订单刷卡发券失败: " + e.getMessage()); | |||||
| } | } | ||||
| logger.info("订单刷卡发券 结束"); | logger.info("订单刷卡发券 结束"); | ||||
| @@ -1384,7 +1337,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| wxOrderService.shareForMicroPay(tenantId, orderId, payOrderId); | wxOrderService.shareForMicroPay(tenantId, orderId, payOrderId); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("订单分账失败: orderId: {}, payOrderId: {}", orderId, payOrderId); | logger.error("订单分账失败: orderId: {}, payOrderId: {}", orderId, payOrderId); | ||||
| logger.error("订单分账失败: " +e.getMessage()); | |||||
| logger.error("订单分账失败: " + e.getMessage()); | |||||
| } | } | ||||
| logger.info("订单分账结束: orderId: {}, payOrderId: {}", orderId, payOrderId); | logger.info("订单分账结束: orderId: {}, payOrderId: {}", orderId, payOrderId); | ||||
| }).start(); | }).start(); | ||||
| @@ -234,26 +234,26 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| private boolean isMerchantOrder(WxOrder wxOrder, Long merchantId) { | private boolean isMerchantOrder(WxOrder wxOrder, Long merchantId) { | ||||
| if (wxOrder.getType().equals(EnumOrderType.COUPON.getCode())){ | |||||
| if (wxOrder.getType().equals(EnumOrderType.COUPON.getCode())) { | |||||
| WxCoupon wxCoupon = wxCouponMapper.selectByPrimaryKey(wxOrder.getProductId()); | WxCoupon wxCoupon = wxCouponMapper.selectByPrimaryKey(wxOrder.getProductId()); | ||||
| if (wxCoupon != null) { | if (wxCoupon != null) { | ||||
| WxCouponMerchant wxCouponMerchant = new WxCouponMerchant(); | WxCouponMerchant wxCouponMerchant = new WxCouponMerchant(); | ||||
| wxCouponMerchant.setProductId(wxCoupon.getId()); | wxCouponMerchant.setProductId(wxCoupon.getId()); | ||||
| wxCouponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | wxCouponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | ||||
| List<WxCouponMerchant> couponMerchantList = wxCouponMerchantMapper.findList(wxCouponMerchant); | |||||
| if (couponMerchantList.stream().anyMatch(cm->cm.getMerchantId().equals(merchantId))){ | |||||
| List<WxCouponMerchant> couponMerchantList = wxCouponMerchantMapper.findList(wxCouponMerchant); | |||||
| if (couponMerchantList.stream().anyMatch(cm -> cm.getMerchantId().equals(merchantId))) { | |||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| }else if(wxOrder.getType().equals(EnumOrderType.MICROPAY.getCode())) { | |||||
| } else if (wxOrder.getType().equals(EnumOrderType.MICROPAY.getCode())) { | |||||
| WxMerchantBUser wxMerchantBUser = wxMerchantBUserMapper.selectByPrimaryKey(wxOrder.getProductId()); | WxMerchantBUser wxMerchantBUser = wxMerchantBUserMapper.selectByPrimaryKey(wxOrder.getProductId()); | ||||
| if (wxMerchantBUser != null && wxMerchantBUser.equals(merchantId)) { | if (wxMerchantBUser != null && wxMerchantBUser.equals(merchantId)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| }else if(wxOrder.getType().equals(EnumOrderType.NATIVEPAY.getCode())) { | |||||
| } else if (wxOrder.getType().equals(EnumOrderType.NATIVEPAY.getCode())) { | |||||
| }else if(wxOrder.getType().equals(EnumOrderType.PREPAIDCARD.getCode())) { | |||||
| } else if (wxOrder.getType().equals(EnumOrderType.PREPAIDCARD.getCode())) { | |||||
| } | } | ||||
| @@ -263,7 +263,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| public ResultData createRefundOrder(boolean isReal, WxAppinfo appInfo, Long couponOrderId, EnumPayType payType, Long bUserId) { | |||||
| public ResultData createRefundOrder(WxAppinfo appInfo, Long couponOrderId, EnumPayType payType, Long bUserId) { | |||||
| WxCouponOrder wxCouponOrder = wxCouponOrderMapper.selectByPrimaryKey(couponOrderId); | WxCouponOrder wxCouponOrder = wxCouponOrderMapper.selectByPrimaryKey(couponOrderId); | ||||
| if (wxCouponOrder == null) { | if (wxCouponOrder == null) { | ||||
| logger.error("券ID不存在:" + couponOrderId); | logger.error("券ID不存在:" + couponOrderId); | ||||
| @@ -342,14 +342,14 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| } | } | ||||
| // 更改 couponOrder 状态 | // 更改 couponOrder 状态 | ||||
| if(wxCouponOrder.getCouponType().equals(EnumCouponType.CARD_MULTIMCH.getCode())) { | |||||
| if (wxCouponOrder.getCouponType().equals(EnumCouponType.CARD_MULTIMCH.getCode())) { | |||||
| wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.CARD_RETURNED.getCode()); // 卡线下退款 | wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.CARD_RETURNED.getCode()); // 卡线下退款 | ||||
| } else { | } else { | ||||
| wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()); //3退款,券作废 | wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()); //3退款,券作废 | ||||
| } | } | ||||
| if (payType == EnumPayType.PAY_B_REFUND) { | if (payType == EnumPayType.PAY_B_REFUND) { | ||||
| wxCouponOrder.setbUserId(bUserId); | wxCouponOrder.setbUserId(bUserId); | ||||
| } else{ | |||||
| } else { | |||||
| wxCouponOrder.setbUserId(payType.getCode().longValue());//其他退款模式将退款方式存入BUSERID | wxCouponOrder.setbUserId(payType.getCode().longValue());//其他退款模式将退款方式存入BUSERID | ||||
| } | } | ||||
| wxCouponOrder.setUpdateDate(currentDate); | wxCouponOrder.setUpdateDate(currentDate); | ||||
| @@ -430,169 +430,10 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| logger.error("退款订单已存在, 无法再提交退款申请"); | logger.error("退款订单已存在, 无法再提交退款申请"); | ||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_EXIST.getCode(), "退款订单已存在, 无法再提交退款申请"); | throw new MallinkException(ErrorCode.REFUND_ORDER_EXIST.getCode(), "退款订单已存在, 无法再提交退款申请"); | ||||
| } | } | ||||
| if (isReal) { | |||||
| // 实际支付 | |||||
| // 向微信提交退款申请 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | |||||
| wxRefundOrderP.setAppid(appInfo.getAppId()); | |||||
| wxRefundOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxRefundOrderP.setNonce_str(noncestr); | |||||
| // 微信内部订单号 | |||||
| if (record.getTransactionId() != null) | |||||
| wxRefundOrderP.setTransaction_id(record.getTransactionId()); | |||||
| // 支付订单号 | |||||
| wxRefundOrderP.setOut_trade_no(payOrder.getPayOrderNo()); | |||||
| // 退款支付订单号 | |||||
| wxRefundOrderP.setOut_refund_no(out_refund_id); | |||||
| wxRefundOrderP.setTotal_fee(record.getTotalFee()); | |||||
| wxRefundOrderP.setRefund_fee(record.getRefundFee()); | |||||
| if (payType == EnumPayType.PAY_B_REFUND) { | |||||
| wxRefundOrderP.setRefund_desc("B端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||||
| wxRefundOrderP.setRefund_desc("管理端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||||
| wxRefundOrderP.setRefund_desc("超期自动退款"); | |||||
| } else { | |||||
| wxRefundOrderP.setRefund_desc("用户自己退款"); | |||||
| } | |||||
| wxRefundOrderP.setNotify_url(payAccount.getRefundNotifyUrl()); | |||||
| Map signMap = null; | |||||
| try { | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSign(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxRefundOrderSP wxRefundOrderSP = new WxRefundOrderSP(); | |||||
| wxRefundOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxRefundOrderSP.setSub_appid(appInfo.getAppId()); | |||||
| wxRefundOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxRefundOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxRefundOrderSP.setNonce_str(noncestr); | |||||
| // 微信内部订单号 | |||||
| if (record.getTransactionId() != null) | |||||
| wxRefundOrderSP.setTransaction_id(record.getTransactionId()); | |||||
| // 支付订单号 | |||||
| wxRefundOrderSP.setOut_trade_no(payOrder.getPayOrderNo()); | |||||
| // 退款支付订单号 | |||||
| wxRefundOrderSP.setOut_refund_no(out_refund_id); | |||||
| wxRefundOrderSP.setTotal_fee(record.getTotalFee()); | |||||
| wxRefundOrderSP.setRefund_fee(record.getRefundFee()); | |||||
| if (payType == EnumPayType.PAY_B_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("B端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("管理端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("超期自动退款"); | |||||
| } else { | |||||
| wxRefundOrderSP.setRefund_desc("用户自己退款"); | |||||
| } | |||||
| wxRefundOrderSP.setNotify_url(payAccount.getRefundNotifyUrl()); | |||||
| wxRefundOrderSP.setSign_type("HMAC-SHA256"); | |||||
| Map signMap = null; | |||||
| try { | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderSP); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSignHMAC(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "订单状态更新失败"); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg); | |||||
| } | |||||
| } | |||||
| } else { | |||||
| // 虚拟支付 | |||||
| // 向微信提交退款申请 | |||||
| // 实际支付 | |||||
| // 向微信提交退款申请 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | String noncestr = Utility.generate32UUID(); | ||||
| WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | ||||
| wxRefundOrderP.setAppid(appInfo.getAppId()); | wxRefundOrderP.setAppid(appInfo.getAppId()); | ||||
| @@ -618,27 +459,140 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| } | } | ||||
| wxRefundOrderP.setNotify_url(payAccount.getRefundNotifyUrl()); | wxRefundOrderP.setNotify_url(payAccount.getRefundNotifyUrl()); | ||||
| Map returnMap = null; | |||||
| Map signMap = null; | |||||
| try { | try { | ||||
| returnMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("退款签名异常"); | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | ||||
| } | } | ||||
| String signAgent = WxPayment.createSign(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | try { | ||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | wxRefundOrderMapper.updateByPrimaryKeySelective(record); | ||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxRefundOrderSP wxRefundOrderSP = new WxRefundOrderSP(); | |||||
| wxRefundOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxRefundOrderSP.setSub_appid(appInfo.getAppId()); | |||||
| wxRefundOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxRefundOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxRefundOrderSP.setNonce_str(noncestr); | |||||
| // 微信内部订单号 | |||||
| if (record.getTransactionId() != null) | |||||
| wxRefundOrderSP.setTransaction_id(record.getTransactionId()); | |||||
| // 支付订单号 | |||||
| wxRefundOrderSP.setOut_trade_no(payOrder.getPayOrderNo()); | |||||
| // 退款支付订单号 | |||||
| wxRefundOrderSP.setOut_refund_no(out_refund_id); | |||||
| wxRefundOrderSP.setTotal_fee(record.getTotalFee()); | |||||
| wxRefundOrderSP.setRefund_fee(record.getRefundFee()); | |||||
| if (payType == EnumPayType.PAY_B_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("B端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("管理端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("超期自动退款"); | |||||
| } else { | |||||
| wxRefundOrderSP.setRefund_desc("用户自己退款"); | |||||
| } | |||||
| wxRefundOrderSP.setNotify_url(payAccount.getRefundNotifyUrl()); | |||||
| wxRefundOrderSP.setSign_type("HMAC-SHA256"); | |||||
| Map signMap = null; | |||||
| try { | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderSP); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSignHMAC(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "订单状态更新失败"); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| public ResultData createRefundOrderFromMicroPay(boolean isReal, WxAppinfo appInfo, Long orderId, EnumPayType payType, Long bUserId) { | |||||
| public ResultData createRefundOrderFromMicroPay(WxAppinfo appInfo, Long orderId, EnumPayType payType, Long bUserId) { | |||||
| WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(orderId); | WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(orderId); | ||||
| if (payType == EnumPayType.PAY_B_REFUND) { | if (payType == EnumPayType.PAY_B_REFUND) { | ||||
| @@ -766,168 +720,9 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_EXIST.getCode(), "退款订单已存在, 无法再提交退款申请"); | throw new MallinkException(ErrorCode.REFUND_ORDER_EXIST.getCode(), "退款订单已存在, 无法再提交退款申请"); | ||||
| } | } | ||||
| if (isReal) { | |||||
| // 实际支付 | |||||
| // 向微信提交退款申请 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | |||||
| wxRefundOrderP.setAppid(appInfo.getAppId()); | |||||
| wxRefundOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxRefundOrderP.setNonce_str(noncestr); | |||||
| // 微信内部订单号 | |||||
| if (record.getTransactionId() != null) | |||||
| wxRefundOrderP.setTransaction_id(record.getTransactionId()); | |||||
| // 支付订单号 | |||||
| wxRefundOrderP.setOut_trade_no(payOrder.getPayOrderNo()); | |||||
| // 退款支付订单号 | |||||
| wxRefundOrderP.setOut_refund_no(out_refund_id); | |||||
| wxRefundOrderP.setTotal_fee(record.getTotalFee()); | |||||
| wxRefundOrderP.setRefund_fee(record.getRefundFee()); | |||||
| if (payType == EnumPayType.PAY_B_REFUND) { | |||||
| wxRefundOrderP.setRefund_desc("B端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||||
| wxRefundOrderP.setRefund_desc("管理端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||||
| wxRefundOrderP.setRefund_desc("超期自动退款"); | |||||
| } else { | |||||
| wxRefundOrderP.setRefund_desc("用户自己退款"); | |||||
| } | |||||
| wxRefundOrderP.setNotify_url(payAccount.getRefundNotifyUrl()); | |||||
| Map signMap = null; | |||||
| try { | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSign(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxRefundOrderSP wxRefundOrderSP = new WxRefundOrderSP(); | |||||
| wxRefundOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxRefundOrderSP.setSub_appid(appInfo.getAppId()); | |||||
| wxRefundOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxRefundOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxRefundOrderSP.setNonce_str(noncestr); | |||||
| // 微信内部订单号 | |||||
| if (record.getTransactionId() != null) | |||||
| wxRefundOrderSP.setTransaction_id(record.getTransactionId()); | |||||
| // 支付订单号 | |||||
| wxRefundOrderSP.setOut_trade_no(payOrder.getPayOrderNo()); | |||||
| // 退款支付订单号 | |||||
| wxRefundOrderSP.setOut_refund_no(out_refund_id); | |||||
| wxRefundOrderSP.setTotal_fee(record.getTotalFee()); | |||||
| wxRefundOrderSP.setRefund_fee(record.getRefundFee()); | |||||
| if (payType == EnumPayType.PAY_B_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("B端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("管理端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("超期自动退款"); | |||||
| } else { | |||||
| wxRefundOrderSP.setRefund_desc("用户自己退款"); | |||||
| } | |||||
| wxRefundOrderSP.setNotify_url(payAccount.getRefundNotifyUrl()); | |||||
| wxRefundOrderSP.setSign_type("HMAC-SHA256"); | |||||
| Map signMap = null; | |||||
| try { | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderSP); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSignHMAC(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "订单状态更新失败"); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg); | |||||
| } | |||||
| } | |||||
| } else { | |||||
| // 虚拟支付 | |||||
| // 向微信提交退款申请 | |||||
| // 向微信提交退款申请 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | String noncestr = Utility.generate32UUID(); | ||||
| WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | ||||
| wxRefundOrderP.setAppid(appInfo.getAppId()); | wxRefundOrderP.setAppid(appInfo.getAppId()); | ||||
| @@ -953,20 +748,133 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| } | } | ||||
| wxRefundOrderP.setNotify_url(payAccount.getRefundNotifyUrl()); | wxRefundOrderP.setNotify_url(payAccount.getRefundNotifyUrl()); | ||||
| Map returnMap = null; | |||||
| Map signMap = null; | |||||
| try { | try { | ||||
| returnMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("退款签名异常"); | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | ||||
| } | } | ||||
| String signAgent = WxPayment.createSign(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | try { | ||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | wxRefundOrderMapper.updateByPrimaryKeySelective(record); | ||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxRefundOrderSP wxRefundOrderSP = new WxRefundOrderSP(); | |||||
| wxRefundOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxRefundOrderSP.setSub_appid(appInfo.getAppId()); | |||||
| wxRefundOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxRefundOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxRefundOrderSP.setNonce_str(noncestr); | |||||
| // 微信内部订单号 | |||||
| if (record.getTransactionId() != null) | |||||
| wxRefundOrderSP.setTransaction_id(record.getTransactionId()); | |||||
| // 支付订单号 | |||||
| wxRefundOrderSP.setOut_trade_no(payOrder.getPayOrderNo()); | |||||
| // 退款支付订单号 | |||||
| wxRefundOrderSP.setOut_refund_no(out_refund_id); | |||||
| wxRefundOrderSP.setTotal_fee(record.getTotalFee()); | |||||
| wxRefundOrderSP.setRefund_fee(record.getRefundFee()); | |||||
| if (payType == EnumPayType.PAY_B_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("B端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("管理端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("超期自动退款"); | |||||
| } else { | |||||
| wxRefundOrderSP.setRefund_desc("用户自己退款"); | |||||
| } | |||||
| wxRefundOrderSP.setNotify_url(payAccount.getRefundNotifyUrl()); | |||||
| wxRefundOrderSP.setSign_type("HMAC-SHA256"); | |||||
| Map signMap = null; | |||||
| try { | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderSP); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSignHMAC(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "订单状态更新失败"); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -235,134 +235,140 @@ | |||||
| <sql id="dynamicWhereConditionsForCoupon"> | <sql id="dynamicWhereConditionsForCoupon"> | ||||
| where 1 = 1 | where 1 = 1 | ||||
| <if test=" null != targetAd "> | |||||
| and 0 = (select count(*) from wx_coupon_channel cc | |||||
| where c.`id` = cc.coupon_id | |||||
| and cc.status = 0 | |||||
| and cc.target_ad = #{targetAd}) | |||||
| </if> | |||||
| <if test=" null != id "> | <if test=" null != id "> | ||||
| and `id` = #{id} | |||||
| and c.`id` = #{id} | |||||
| </if> | </if> | ||||
| <if test=" null != tenantId "> | <if test=" null != tenantId "> | ||||
| and `tenant_id` = #{tenantId} | |||||
| and c.`tenant_id` = #{tenantId} | |||||
| </if> | </if> | ||||
| <if test=" null == type "> | <if test=" null == type "> | ||||
| and `type` < 7 | |||||
| and c.`type` < 7 | |||||
| </if> | </if> | ||||
| <if test=" null != type "> | <if test=" null != type "> | ||||
| and `type` = #{type} | |||||
| and c.`type` = #{type} | |||||
| </if> | </if> | ||||
| <if test=" null != coverImg "> | <if test=" null != coverImg "> | ||||
| and `cover_img` like concat('%', #{coverImg},'%') | |||||
| and c.`cover_img` like concat('%', #{coverImg},'%') | |||||
| </if> | </if> | ||||
| <if test=" null != title and ''!=title"> | <if test=" null != title and ''!=title"> | ||||
| and `title` like concat('%', #{title},'%') | |||||
| and c.`title` like concat('%', #{title},'%') | |||||
| </if> | </if> | ||||
| <if test=" null != subTitle "> | <if test=" null != subTitle "> | ||||
| and `sub_title` like concat('%', #{subTitle},'%') | |||||
| and c.`sub_title` like concat('%', #{subTitle},'%') | |||||
| </if> | </if> | ||||
| <if test=" null != salePrice "> | <if test=" null != salePrice "> | ||||
| and `sale_price` = #{salePrice} | |||||
| and c.`sale_price` = #{salePrice} | |||||
| </if> | </if> | ||||
| <if test=" null != usePrice "> | <if test=" null != usePrice "> | ||||
| and `use_price` = #{usePrice} | |||||
| and c.`use_price` = #{usePrice} | |||||
| </if> | </if> | ||||
| <if test=" null != useLimitQuantity "> | <if test=" null != useLimitQuantity "> | ||||
| and `use_limit_quantity` = #{useLimitQuantity} | |||||
| and c.`use_limit_quantity` = #{useLimitQuantity} | |||||
| </if> | </if> | ||||
| <if test=" null != sendType "> | <if test=" null != sendType "> | ||||
| and `send_type` = #{sendType} | |||||
| and c.`send_type` = #{sendType} | |||||
| </if> | </if> | ||||
| <if test=" null != validType "> | <if test=" null != validType "> | ||||
| and `valid_type` = #{validType} | |||||
| and c.`valid_type` = #{validType} | |||||
| </if> | </if> | ||||
| <if test=" null != validStartDate "> | <if test=" null != validStartDate "> | ||||
| and `valid_start_date` = #{validStartDate} | |||||
| and c.`valid_start_date` = #{validStartDate} | |||||
| </if> | </if> | ||||
| <if test=" null != validEndDate "> | <if test=" null != validEndDate "> | ||||
| and `valid_end_date` = #{validEndDate} | |||||
| and c.`valid_end_date` = #{validEndDate} | |||||
| </if> | </if> | ||||
| <if test=" null != validDays "> | <if test=" null != validDays "> | ||||
| and `valid_days` = #{validDays} | |||||
| and c.`valid_days` = #{validDays} | |||||
| </if> | </if> | ||||
| <if test=" null != detail "> | <if test=" null != detail "> | ||||
| and `detail` like concat('%', #{detail},'%') | |||||
| and c.`detail` like concat('%', #{detail},'%') | |||||
| </if> | </if> | ||||
| <if test=" null != price "> | <if test=" null != price "> | ||||
| and `price` = #{price} | |||||
| and c.`price` = #{price} | |||||
| </if> | </if> | ||||
| <if test=" null != unit "> | <if test=" null != unit "> | ||||
| and `unit` = #{unit} | |||||
| and c.`unit` = #{unit} | |||||
| </if> | </if> | ||||
| <if test=" null != remainInventory "> | <if test=" null != remainInventory "> | ||||
| and `remain_inventory` = #{remainInventory} | |||||
| and c.`remain_inventory` = #{remainInventory} | |||||
| </if> | </if> | ||||
| <if test=" null != inventory "> | <if test=" null != inventory "> | ||||
| and `inventory` = #{inventory} | |||||
| and c.`inventory` = #{inventory} | |||||
| </if> | </if> | ||||
| <if test=" null != remark "> | <if test=" null != remark "> | ||||
| and `remark` like concat('%', #{remark},'%') | |||||
| and c.`remark` like concat('%', #{remark},'%') | |||||
| </if> | </if> | ||||
| <if test=" null != status"> | <if test=" null != status"> | ||||
| and `status` = #{status} | |||||
| and c.`status` = #{status} | |||||
| </if> | </if> | ||||
| <if test=" null != startdate and null!=enddate"> | <if test=" null != startdate and null!=enddate"> | ||||
| and `create_date` between #{startdate} and #{enddate} | |||||
| and c.`create_date` between #{startdate} and #{enddate} | |||||
| </if> | </if> | ||||
| <if test=" null != updateDate "> | <if test=" null != updateDate "> | ||||
| and `update_date` = #{updateDate} | |||||
| and c.`update_date` = #{updateDate} | |||||
| </if> | </if> | ||||
| <if test=" null != business "> | <if test=" null != business "> | ||||
| and `business` = #{business} | |||||
| and c.`business` = #{business} | |||||
| </if> | </if> | ||||
| <if test=" null != supportTransfer "> | <if test=" null != supportTransfer "> | ||||
| and `support_transfer` = #{supportTransfer} | |||||
| and c.`support_transfer` = #{supportTransfer} | |||||
| </if> | </if> | ||||
| <if test=" null != subsidyType "> | <if test=" null != subsidyType "> | ||||
| and `subsidy_type` = #{subsidyType} | |||||
| and c.`subsidy_type` = #{subsidyType} | |||||
| </if> | </if> | ||||
| <if test=" null != subsidyNum "> | <if test=" null != subsidyNum "> | ||||
| and `subsidy_num` = #{subsidyNum} | |||||
| and c.`subsidy_num` = #{subsidyNum} | |||||
| </if> | </if> | ||||
| <if test=" null != pressLimitNum "> | <if test=" null != pressLimitNum "> | ||||
| and `press_limit_num` = #{pressLimitNum} | |||||
| and c.`press_limit_num` = #{pressLimitNum} | |||||
| </if> | </if> | ||||
| <if test=" null != pressLimitHours "> | <if test=" null != pressLimitHours "> | ||||
| and `press_limit_hours` = #{pressLimitHours} | |||||
| and c.`press_limit_hours` = #{pressLimitHours} | |||||
| </if> | </if> | ||||
| <if test=" null != autoRefund "> | <if test=" null != autoRefund "> | ||||
| and `auto_refund` = #{autoRefund} | |||||
| and c.`auto_refund` = #{autoRefund} | |||||
| </if> | </if> | ||||
| <if test=" null != ids "> | <if test=" null != ids "> | ||||
| and id in | |||||
| and c.id in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | ||||
| #{idItem} | #{idItem} | ||||
| </foreach> | </foreach> | ||||
| @@ -373,7 +379,7 @@ | |||||
| <select id="findCouponList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap"> | <select id="findCouponList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap"> | ||||
| select | select | ||||
| <include refid="allColumns"/> | <include refid="allColumns"/> | ||||
| from wx_coupon | |||||
| from wx_coupon c | |||||
| <include refid="dynamicWhereConditionsForCoupon"/> | <include refid="dynamicWhereConditionsForCoupon"/> | ||||
| </select> | </select> | ||||