diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantController.java b/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantController.java index 64ff73d99..876332856 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantController.java @@ -8,11 +8,8 @@ import com.iformall.common.ErrorCode; import com.iformall.common.Result; import com.iformall.common.ResultData; import com.iformall.controller.base.BaseController; -import com.iformall.domain.po.WxAppinfo; -import com.iformall.domain.po.WxPayAccount; +import com.iformall.domain.po.*; import com.iformall.domain.po.base.BaseEntity; -import com.iformall.domain.po.WxMerchant; -import com.iformall.domain.po.WxProfitSharingReceiver; import com.iformall.domain.vo.WxMerchantTradeDetailVo; import com.iformall.domain.vo.WxMerchantTradeVo; import com.iformall.domain.vo.WxMerchantVo; @@ -55,6 +52,10 @@ public class WxMerchantController extends BaseController { @Autowired private WxProfitSharingReceiverService wxProfitSharingReceiverService; + @Autowired + private WxProfitPaymentReceiverService wxProfitPaymentReceiverService; + + @UserDataRuleAnnotation("merchant_list") @ApiOperation("分页列表接口") @GetMapping("listVo") @@ -392,7 +393,7 @@ public class WxMerchantController extends BaseController { if(merchant == null){ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); } - return wxProfitSharingReceiverService.updateTtReceiver(merchant); + return wxProfitPaymentReceiverService.updateTtReceiver(merchant); } @@ -414,9 +415,9 @@ public class WxMerchantController extends BaseController { return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); } if(anEnum.equals(AppAddSubMerchantUrlType.improt_URL)){ - return wxProfitSharingReceiverService.getTtReceiverImprotURL(merchant); + return wxProfitPaymentReceiverService.getTtReceiverImprotURL(merchant); }else if(anEnum.equals(AppAddSubMerchantUrlType.Balance_URL)){ - return wxProfitSharingReceiverService.getTtReceiverBalanceURL(merchant); + return wxProfitPaymentReceiverService.getTtReceiverBalanceURL(merchant); }else{ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); } @@ -440,7 +441,7 @@ public class WxMerchantController extends BaseController { if(payAcount == null){ return new ResultData(ErrorCode.APP_ID_NOT_FOUND); } - return wxProfitSharingReceiverService.updateTtReceiverIsUse(merchant); + return wxProfitPaymentReceiverService.updateTtReceiverImportStatus(merchant); } @ApiOperation("更新收款账户信息:必填项 id(商户ID) name(商户名称) accountId(账号ID) accountTypeValue(账号类型) accountName(账号名称)") @@ -466,7 +467,7 @@ public class WxMerchantController extends BaseController { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "账号名称不能为空"); } wxMerchant.updateTenantInfo(getTenantInfo()); - return wxMerchantService.updateMerchantAccount(wxMerchant,false); + return wxMerchantService.updateMerchantAccount(wxMerchant); } @ApiOperation("删除分账账户") @@ -479,7 +480,7 @@ public class WxMerchantController extends BaseController { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "商户分账账户ID不能为空"); } receiver.updateTenantInfo(getTenantInfo()); - return wxProfitSharingReceiverService.delReceiver(receiver, EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode(),false); + return wxProfitSharingReceiverService.delReceiver(receiver, EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode()); } } diff --git a/mallinkAdmin/src/main/resources/db/migration/V2023021300001__add_分账类型.sql b/mallinkAdmin/src/main/resources/db/migration/V2023021300001__add_分账类型.sql new file mode 100644 index 000000000..bb22402ac --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V2023021300001__add_分账类型.sql @@ -0,0 +1,6 @@ +--创建收款帐号表 + +--备份分账帐号表 +--将微信进件的数据转移到收款帐号表里--并将原数据删除 + +--将抖音进件的数据转移到收款帐号表里--原数据修改ReceiverType =10 diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantController.java index c9bf8f8c7..dde903619 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantController.java @@ -27,6 +27,9 @@ public class WxMerchantController extends BaseController { @Autowired private WxMerchantService wxMerchantService; + @Autowired + private WxProfitPaymentReceiverService wxProfitPaymentReceiverService; + @Autowired private WxProfitSharingReceiverService wxProfitSharingReceiverService; @@ -45,7 +48,7 @@ public class WxMerchantController extends BaseController { return new ResultData(wxMerchantService.findList(getTenantInfo())); } - @ApiOperation("查询账户信息") + @ApiOperation("微信查询分账信息") @GetMapping("/findAccountById") @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) public ResultData findAccountById(@ModelAttribute WxMerchant wxMerchant) { @@ -60,18 +63,11 @@ public class WxMerchantController extends BaseController { if(payAccount == null){ return new ResultData(ErrorCode.API_KEY_NOT_FOUND); } - EnumProfitSharingType enumSharingType = EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT; - if(EnumPayMchType.TOTAL.getCode().equals(payAccount.getMchType())){ - enumSharingType = EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT; - }else if(EnumPayMchType.DIRECT.getCode().equals(payAccount.getMchType())){ - enumSharingType = EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT_v2; - }else{ - return new ResultData(ErrorCode.APP_PLAT_ERROR); - } - return new ResultData(wxProfitSharingReceiverService.findReceiver(tenantInfo,wxMerchant.getId(), EnumAppPlat.WX,enumSharingType)); + + return new ResultData(wxProfitSharingReceiverService.findReceiver(tenantInfo,wxMerchant.getId(), EnumAppPlat.WX)); } - @ApiOperation("查询账户信息") + @ApiOperation("抖音查询收款账户信息") @GetMapping("/findTtAccountById") @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) public ResultData findTtAccountById(@ModelAttribute WxMerchant wxMerchant) { @@ -80,7 +76,7 @@ public class WxMerchantController extends BaseController { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "商户ID不能为空"); } wxMerchant.updateTenantInfo(getTenantInfo()); - return new ResultData(wxProfitSharingReceiverService.findReceiver(getTenantInfo(),wxMerchant.getId(), EnumAppPlat.TOUTIAO,EnumProfitSharingType.PROFIT_SHARING_TYPE_DOUYIN)); + return new ResultData(wxProfitPaymentReceiverService.findReceiver(getTenantInfo(),wxMerchant.getId(), EnumAppPlat.TOUTIAO,EnumProfitPaymentReceiverType.tt_merchant_number)); } @ApiOperation("更新收款账户信息:必填项 id(商户ID) name(商户名称) accountId(账号ID) accountTypeValue(账号类型) accountName(账号名称)") @@ -106,7 +102,7 @@ public class WxMerchantController extends BaseController { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "账号名称不能为空"); } wxMerchant.updateTenantInfo(getTenantInfo()); - return wxMerchantService.updateMerchantAccount(wxMerchant,true); + return wxMerchantService.updateMerchantAccount(wxMerchant); } @ApiOperation("删除分账账户") @@ -121,7 +117,7 @@ public class WxMerchantController extends BaseController { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "商户分账账户ID不能为空"); } receiver.updateTenantInfo(getTenantInfo()); - return wxProfitSharingReceiverService.delReceiver(receiver, EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode(),true); + return wxProfitSharingReceiverService.delReceiver(receiver, EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode()); } @ApiOperation("查询是否有权限修改账户") @@ -187,9 +183,9 @@ public class WxMerchantController extends BaseController { } if(anEnum.equals(AppAddSubMerchantUrlType.improt_URL)){ - return wxProfitSharingReceiverService.getTtReceiverImprotURL(merchant); + return wxProfitPaymentReceiverService.getTtReceiverImprotURL(merchant); }else if(anEnum.equals(AppAddSubMerchantUrlType.Balance_URL)){ - return wxProfitSharingReceiverService.getTtReceiverBalanceURL(merchant); + return wxProfitPaymentReceiverService.getTtReceiverBalanceURL(merchant); }else{ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); } diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxProfitSharingReceiverApplyController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxProfitSharingReceiverApplyController.java index b616dc6fc..114137576 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxProfitSharingReceiverApplyController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxProfitSharingReceiverApplyController.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.WxMerchant; +import com.iformall.domain.po.WxProfitPaymentReceiver; import com.iformall.domain.po.WxProfitSharingReceiver; import com.iformall.domain.po.WxProfitSharingReceiverApply; import com.iformall.domain.po.base.TenantEntity; @@ -12,6 +13,7 @@ import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.file.aliyun.AliyunOSS; import com.iformall.service.WxMerchantService; +import com.iformall.service.WxProfitPaymentReceiverService; import com.iformall.service.WxProfitSharingReceiverApplyService; import com.iformall.service.WxProfitSharingReceiverService; import com.iformall.utils.ImgYwsqhUtil; @@ -44,7 +46,7 @@ public class WxProfitSharingReceiverApplyController extends BaseController { private WxProfitSharingReceiverApplyService wxProfitSharingReceiverApplyService; @Autowired - private WxProfitSharingReceiverService wxProfitSharingReceiverService; + private WxProfitPaymentReceiverService wxProfitPaymentReceiverService; @Autowired private WxMerchantService wxMerchantService; @@ -85,7 +87,7 @@ public class WxProfitSharingReceiverApplyController extends BaseController { if(merchant == null || EnumMerchantStatus.NOT_VALID.getCode().equals(merchant.getStatus())){ return new ResultData(ErrorCode.MERCHANT_INFO_NOT_VALID.getCode(),"商户不存在或已停用"); } - WxProfitSharingReceiver receiver = wxProfitSharingReceiverService.findReceiver(merchant, merchant.getId(), EnumAppPlat.WX, EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT_v2); + WxProfitPaymentReceiver receiver = wxProfitPaymentReceiverService.findReceiver(merchant, merchant.getId(), EnumAppPlat.WX, EnumProfitPaymentReceiverType.wx_special_merchant_number); if(receiver != null && MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus())){ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "该商户已进件成功"); } diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxCarController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxCarController.java index a897f4f1d..636a9c4cc 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxCarController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxCarController.java @@ -90,9 +90,9 @@ public class WxCarController extends BaseController { @Autowired WxPayAccountService wxPayAccountService; - + @Autowired - WxProfitSharingReceiverService wxProfitSharingReceiverService; + WxProfitPaymentReceiverService wxProfitPaymentReceiverService; @Autowired @Qualifier("objectCommonRedisTemplate") @@ -470,14 +470,14 @@ public class WxCarController extends BaseController { return new ResultData(Result.ERROR,"未设置停车商户."); } - WxProfitSharingReceiver receiver = wxProfitSharingReceiverService.findReceiver(park, parkMerchant.getId(), EnumAppPlat.WX, EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT_v2); + WxProfitPaymentReceiver receiver = wxProfitPaymentReceiverService.findReceiver(park, parkMerchant.getId(), EnumAppPlat.WX, EnumProfitPaymentReceiverType.wx_special_merchant_number); if (null == receiver || StringUtils.isBlank(receiver.getReceiverAccount())) { //查询商官商户 WxMerchant adminMerchant = wxMerchantService.findAdmin(park); if (null == adminMerchant) { return new ResultData(Result.ERROR,"未找到商管商户."); } - receiver = wxProfitSharingReceiverService.findReceiver(park, adminMerchant.getId(), EnumAppPlat.WX, EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT_v2); + receiver = wxProfitPaymentReceiverService.findReceiver(park, adminMerchant.getId(), EnumAppPlat.WX, EnumProfitPaymentReceiverType.wx_special_merchant_number); if (null == receiver || StringUtils.isBlank(receiver.getReceiverAccount())) { return new ResultData(Result.ERROR,"商管商户未设置收款账号."); } diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantReciverSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantReciverSchedule.java index e69d31c83..06c056bf6 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantReciverSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantReciverSchedule.java @@ -37,7 +37,7 @@ public class TtMerchantReciverSchedule { private WxPayAccountService payAccountService; @Autowired - private WxProfitSharingReceiverService wxProfitSharingReceiverService; + private WxProfitPaymentReceiverService wxProfitPaymentReceiverService; /** @@ -64,7 +64,7 @@ public class TtMerchantReciverSchedule { // logger.error("TtMerchantReciverSchedule error.updateTtReceiver:"+m.getId(),e); // } try { - wxProfitSharingReceiverService.updateTtReceiverIsUse(m); + wxProfitPaymentReceiverService.updateTtReceiverImportStatus(m); } catch (Exception e) { e.printStackTrace(); logger.error("TtMerchantReciverSchedule error.updateTtReceiver:"+m.getId(),e); diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxMerchant.java b/mallinkService/src/main/java/com/iformall/domain/po/WxMerchant.java index 79b095fe3..bf9a33813 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxMerchant.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxMerchant.java @@ -196,20 +196,14 @@ public class WxMerchant extends TenantEntity { return String.join("\n", wxProfitSharingReceiver.stream().map(r->{ StringBuffer str = new StringBuffer(); - if(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT_v2.getCode().equals(r.getSharingType())){ - str.append("微信特约商户号:"); - }else if(EnumProfitSharingType.PROFIT_SHARING_TYPE_DOUYIN.getCode().equals(r.getSharingType())){ - str.append("抖音商户号:"); - }else if(EnumProfitSharingType.PROFIT_SHARING_TYPE_BANK.getCode().equals(r.getSharingType())){ - str.append("银行卡号:"); - }else if(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode().equals(r.getSharingType())){ - if(EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_MERCHANT_ID.getCode().equals(r.getReceiverType())){ + if(EnumProfitSharingType.PROFIT_SHARING_TYPE_SYS.getCode().equals(r.getSharingType())){ + if(EnumProfitPaymentReceiverType.wx_special_merchant_number.getCode().equals(r.getReceiverType())){ str.append("微信商户号:"); - }else if(EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_PERSONAL_WECHATID.getCode().equals(r.getReceiverType())){ + }else if(EnumProfitPaymentReceiverType.wx_personal_wechatid.getCode().equals(r.getReceiverType())){ str.append("个人微信号(微信已停用):"); - }else if(EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_PERSONAL_OPENID.getCode().equals(r.getReceiverType())){ + }else if(EnumProfitPaymentReceiverType.wx_personal_openid.getCode().equals(r.getReceiverType())){ str.append("OPENID:"); - } else if(EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_PERSONAL_SUB_OPENID.getCode().equals(r.getReceiverType())){ + } else if(EnumProfitPaymentReceiverType.wx_personal_sub_openid.getCode().equals(r.getReceiverType())){ str.append("OPENID:"); } } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxProfitPaymentReceiver.java b/mallinkService/src/main/java/com/iformall/domain/po/WxProfitPaymentReceiver.java new file mode 100644 index 000000000..d274ec12b --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxProfitPaymentReceiver.java @@ -0,0 +1,94 @@ +package com.iformall.domain.po; + +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.iformall.domain.po.base.TenantEntity; +import com.iformall.douyin.pay.orderQuery.QueryMerchantResult; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.apache.commons.lang3.StringUtils; + +import java.util.Date; + +@TableName(value = "wx_profit_payment_receiver") +@Data +@EqualsAndHashCode(callSuper = true) +public class WxProfitPaymentReceiver extends TenantEntity { + + protected Long id; + + @io.swagger.annotations.ApiModelProperty(value="商户ID",name="merchantId") + private Long merchantId; + @io.swagger.annotations.ApiModelProperty(value="收款帐号类型 EnumProfitPaymentReceiverType",name="receiverType") + private Integer receiverType; + @io.swagger.annotations.ApiModelProperty(value="收款商户号",name="receiverAccount") + private String receiverAccount; + @io.swagger.annotations.ApiModelProperty(value="说明",name="receiverComments") + private String receiverComments; + @io.swagger.annotations.ApiModelProperty(value="",name="createTime") + private Date createTime; + @io.swagger.annotations.ApiModelProperty(value="",name="updateTime") + private Date updateTime; + + @io.swagger.annotations.ApiModelProperty(value="分账接收方状态 0,正常 1,停用",name="status") + private Integer status; + @io.swagger.annotations.ApiModelProperty(value="平台 EnumAppPlat",name="plat") + private Integer plat; + + @io.swagger.annotations.ApiModelProperty(value = "进件状态", name = "ttImportStatus") + private String ttImportStatus; + + @TableField(exist = false) + private Integer wxImportStatus; + @TableField(exist = false) + private Integer alipayImportStatus; + @TableField(exist = false) + private Integer hzImportStatus; + + private QueryMerchantResult getMerchantResult(){ + QueryMerchantResult queryMerchantResult = null; + try{ + if(StringUtils.isNotBlank(this.ttImportStatus)) { + queryMerchantResult = JSON.parseObject(this.ttImportStatus, QueryMerchantResult.class); + } + }catch(Exception e){} + if(queryMerchantResult == null){ + queryMerchantResult = new QueryMerchantResult(); + } + return queryMerchantResult; + } + + public Integer getWxImportStatus(){ + return getMerchantResult().getWx(); + } + public Integer getAlipayImportStatus(){ + return getMerchantResult().getAlipay(); + } + public Integer getHzImportStatus(){ + return getMerchantResult().getHz(); + } + + @io.swagger.annotations.ApiModelProperty(value = "进件页面", name = "ttImportUrl") + private String ttImportUrl; + + @io.swagger.annotations.ApiModelProperty(value = "余额页面", name = "ttBalanceUrl") + private String ttBalanceUrl; + + + + + + @TableField(exist = false) + @io.swagger.annotations.ApiModelProperty(value="分账金额(分)",name="sharingAmount") + private Integer sharingAmount; + @TableField(exist = false) + @io.swagger.annotations.ApiModelProperty(value="真实费率",name="rateAmount") + private Integer rateAmount; + @TableField(exist = false) + private Integer realRateAmount;//平台手续费 + @TableField(exist = false) + private Integer commissionAmount;//平台佣金 + + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingReceiver.java b/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingReceiver.java index bb197b311..52b96241c 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingReceiver.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingReceiver.java @@ -30,7 +30,7 @@ public class WxProfitSharingReceiver extends TenantEntity { private Date createTime; @io.swagger.annotations.ApiModelProperty(value="",name="updateTime") private Date updateTime; - @io.swagger.annotations.ApiModelProperty(value="分账类型:1-服务商户分账,2-商户转入银行卡",name="sharingType") + @io.swagger.annotations.ApiModelProperty(value="EnumProfitSharingType 分账类型:1-服务商户分账,2-商户转入银行卡",name="sharingType") private Integer sharingType; @io.swagger.annotations.ApiModelProperty(value="",name="bankNo") private String bankNo; diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumProfitPaymentReceiverType.java b/mallinkService/src/main/java/com/iformall/enums/EnumProfitPaymentReceiverType.java new file mode 100644 index 000000000..76215f157 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumProfitPaymentReceiverType.java @@ -0,0 +1,39 @@ +package com.iformall.enums; + +/** + * Created by Stormeye on 2018/08/09. + */ +public enum EnumProfitPaymentReceiverType { + wx_special_merchant_number(0, "MERCHANT_ID"),//微信特约商户号 + wx_personal_wechatid(1, "PERSONAL_WECHATID"),//微信号 已不支持 + wx_personal_openid(2, "PERSONAL_OPENID"),//v2,v3 + wx_personal_sub_openid(3, "PERSONAL_SUB_OPENID"), + + tt_merchant_number(10,"")//抖音商户号 + ; + + public static EnumProfitPaymentReceiverType getEnum(Integer code) { + for (EnumProfitPaymentReceiverType value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumProfitPaymentReceiverType(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingType.java b/mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingType.java index 43d1e3b5e..4f43ed40a 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingType.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingType.java @@ -4,11 +4,8 @@ package com.iformall.enums; * Created by Stormeye on 2018/08/09. */ public enum EnumProfitSharingType { - PROFIT_SHARING_TYPE_WECHAT(1, "微信分账"), - PROFIT_SHARING_TYPE_BANK(2, "银行卡分账"), - - PROFIT_SHARING_TYPE_DOUYIN(3, "抖音进件"), - PROFIT_SHARING_TYPE_WECHAT_v2(4, "微信特约商户进件"), + PROFIT_SHARING_TYPE_SYS(1, "系统分账"), + PROFIT_SHARING_TYPE_BANK(2, "银行卡打款"), ; public static EnumProfitSharingType getEnum(Integer code) { diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxProfitPaymentReceiverMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxProfitPaymentReceiverMapper.java new file mode 100644 index 000000000..c36e7b2e4 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/WxProfitPaymentReceiverMapper.java @@ -0,0 +1,15 @@ +package com.iformall.mapper; + +import com.iformall.common.CommonMapper; +import com.iformall.domain.po.WxProfitPaymentReceiver; +import com.iformall.domain.po.WxProfitSharingReceiver; + +import java.util.List; + +public interface WxProfitPaymentReceiverMapper extends CommonMapper { + + List findList(WxProfitPaymentReceiver record); + + WxProfitPaymentReceiver findOne(WxProfitPaymentReceiver record); + +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxProfitSharingReceiverMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxProfitSharingReceiverMapper.java index c4c92e5ad..6d238fcfc 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxProfitSharingReceiverMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxProfitSharingReceiverMapper.java @@ -10,5 +10,4 @@ public interface WxProfitSharingReceiverMapper extends CommonMapper findMerchantIdList(WxProfitSharingReceiver wxProfitSharingReceiver); } diff --git a/mallinkService/src/main/java/com/iformall/service/WxMerchantService.java b/mallinkService/src/main/java/com/iformall/service/WxMerchantService.java index 9ec2ba45b..13227d1b2 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxMerchantService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxMerchantService.java @@ -142,10 +142,9 @@ public interface WxMerchantService { /** * * @param wxMerchant - * @param isSync 是否需要同步第三方(微信总分模式需要) * @return */ - ResultData updateMerchantAccount(WxMerchant wxMerchant,boolean isSync); + ResultData updateMerchantAccount(WxMerchant wxMerchant); ResultData updateMerchantAdmin(WxMerchant wxMerchant); diff --git a/mallinkService/src/main/java/com/iformall/service/WxProfitPaymentReceiverService.java b/mallinkService/src/main/java/com/iformall/service/WxProfitPaymentReceiverService.java new file mode 100644 index 000000000..04e5f0ab6 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/WxProfitPaymentReceiverService.java @@ -0,0 +1,70 @@ +package com.iformall.service; + +import com.github.pagehelper.PageInfo; +import com.iformall.common.ResultData; +import com.iformall.domain.po.WxMerchant; +import com.iformall.domain.po.WxProfitPaymentReceiver; +import com.iformall.domain.po.WxProfitSharingReceiver; +import com.iformall.domain.po.base.TenantEntity; +import com.iformall.enums.EnumAppPlat; +import com.iformall.enums.EnumProfitPaymentReceiverType; +import com.iformall.enums.EnumProfitSharingType; + +import java.util.List; + +public interface WxProfitPaymentReceiverService { + + /** + * 根据实体查询分页列表 + * + * @param record + * @return + */ + PageInfo listAsPage(WxProfitPaymentReceiver record, Integer pageIndex, Integer pageSize); + + /** + * 根据Id获得实体 + * + * @param id + * @return + */ + WxProfitPaymentReceiver getById(Long id); + + /** + * 保存或更新实体 + * + * @param record + */ + void saveOrUpdate(WxProfitPaymentReceiver record); + +// /** +// * 根据Id删除实体 +// * +// * @param id +// */ +// void deleteById(Long id); + + /** + * 获取门店的收款帐号 + * @param tenantEntity + * @param merchantId + * @param plat + * @param receiverType + * @return + */ + WxProfitPaymentReceiver findReceiver(TenantEntity tenantEntity, Long merchantId, EnumAppPlat plat, EnumProfitPaymentReceiverType receiverType); + + + ResultData updateReceiver(WxProfitPaymentReceiver receiver); + + + + ResultData updateTtReceiver(WxMerchant merchant); + + ResultData getTtReceiverImprotURL(WxMerchant merchant); + + ResultData getTtReceiverBalanceURL(WxMerchant merchant); + + ResultData updateTtReceiverImportStatus(WxMerchant merchant); + +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java b/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java index 3a2fbbc07..a70448736 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java @@ -43,30 +43,22 @@ public interface WxProfitSharingReceiverService { */ void deleteById(Long id); - WxProfitSharingReceiver findReceiver(TenantEntity tenantEntity,Long merchantId, EnumAppPlat plat,EnumProfitSharingType sharingType); + WxProfitSharingReceiver findReceiver(TenantEntity tenantEntity,Long merchantId, EnumAppPlat plat); List findReceivers(TenantEntity tenantEntity,Long merchantId); - ResultData addReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver, List delList, boolean isSync); + ResultData addReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver, List delList); - ResultData delReceiver(WxProfitSharingReceiver receiver, Integer send, boolean isSync); + ResultData delReceiver(WxProfitSharingReceiver receiver, Integer send); /** * * @param merchant * @param receiver - * @param isSync 是否需要同步第三方(微信总分模式需要) * @return */ - ResultData updateReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver, boolean isSync); + ResultData updateReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver); void sendMsg(String phone, String account, String merchant, String time, Integer modelType, TenantEntity tenantEntity); - ResultData updateTtReceiver(WxMerchant merchant); - - ResultData getTtReceiverImprotURL(WxMerchant merchant); - - ResultData getTtReceiverBalanceURL(WxMerchant merchant); - - ResultData updateTtReceiverIsUse(WxMerchant merchant); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java index 5054390b9..0ad378c6b 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java @@ -1471,9 +1471,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { if(wxPayOrder != null && EnumPayMchType.TOTAL.getCode().equals(wxPayOrder.getMchType()) && EnumPayShare.YES.getCode().equals(wxPayOrder.getShare())){ WxProfitSharingReceiver receiver = payServiceFactory.getPayShareAdapterService(wxPayOrder.getPayVendor(),couponOrder.getPayVersion()) - .getReceiver(mallTenantEntity, merchantId, wxPayOrder.getTtPayWay(),wxPayOrder.getMchType()); + .getSharingReceiver(mallTenantEntity, merchantId, wxPayOrder.getTtPayWay(),wxPayOrder.getMchType()); if (null == receiver) { - throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL.getCode(),"当前商户没有配置收款账号。"); + throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL.getCode(),"当前商户没有配置分账账号。"); } } // else if(wxPayOrder != null && EnumPayMchType.DIRECT.getCode().equals(wxPayOrder.getMchType())){ @@ -2890,7 +2890,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { String merchant_uid = ""; if(EnumPayMchType.DIRECT.getCode().equals(payOrder.getMchType())){//直连模式记录收款商户 merchant_id = bUser.getMerchantId(); - WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchant_id, null, payOrder.getMchType()); + WxProfitPaymentReceiver receiver = payShareServie.getPaymantReceiver(payAccount, merchant_id); if(receiver == null){ throw new MallinkException(ErrorCode.PAY_ORDER_MERCHANT_UID_ERROR); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java index 5bfc8a1a7..963fbcc50 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -890,7 +890,7 @@ public class WxCouponServiceImpl implements WxCouponService { //多商户券,抖音 直连 门店只有进件支付宝才能参加活动 todo if(EnumAppPlat.TOUTIAO.equals(plat) && EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode().equals(record.getMerchantType())){ for (WxMerchant merchant:merchantList) { - WxProfitSharingReceiver receiver = payShareServie.getReceiver(mallTenantEntity, merchant.getId(), null, payMchType.getCode()); + WxProfitPaymentReceiver receiver = payShareServie.getPaymantReceiver(mallTenantEntity, merchant.getId()); if (receiver == null) { badNames.add(merchant.getName()); } @@ -975,7 +975,7 @@ public class WxCouponServiceImpl implements WxCouponService { //总分模式下不能分账的商户 private boolean toTalPayMchTypeMerchantIsBad(PayShareAdapterService payShareServie,WxPayAccount payAccount, String merchantName,Long merchantId,EnumPayMchType payMchType,EnumAppPlat plat) throws Exception { - WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchType.getCode()); + WxProfitSharingReceiver receiver = payShareServie.getSharingReceiver(payAccount, merchantId, null, payMchType.getCode()); if (receiver == null) { return true; } @@ -1615,7 +1615,7 @@ public class WxCouponServiceImpl implements WxCouponService { if(wxCoupon.getSalePrice() != null && wxCoupon.getSalePrice() > 0) { PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); - WxProfitSharingReceiver receiver = payShareServie.getReceiver(makeMerchant, makeMerchant.getId(), null, payMchType.getCode()); + WxProfitPaymentReceiver receiver = payShareServie.getPaymantReceiver(makeMerchant, makeMerchant.getId()); if (receiver == null) { throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "所属商户[\""+makeMerchant.getName()+"\"]未配置收款账户"); } @@ -1873,7 +1873,7 @@ public class WxCouponServiceImpl implements WxCouponService { Map merchantAutoShareMap = new HashMap(); for (Long mid:wxCoupon.getMerchantIds()) { //开通了支付宝就可以 - WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, mid, null, payMchType.getCode()); + WxProfitSharingReceiver receiver = payShareServie.getSharingReceiver(payAccount, mid, null, payMchType.getCode()); if (null == receiver) { merchantAutoShareMap.put(mid, false); }else { diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java index e802c5731..827adc5be 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java @@ -744,7 +744,7 @@ public class WxMerchantServiceImpl implements WxMerchantService { @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) @Override - public ResultData updateMerchantAccount(WxMerchant wxMerchant,boolean isSync) { + public ResultData updateMerchantAccount(WxMerchant wxMerchant) { try { if (wxMerchant.getId() == null) { return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND); @@ -760,7 +760,7 @@ public class WxMerchantServiceImpl implements WxMerchantService { receiver.setReceiverType(wxMerchant.getAccountTypeValue()); receiver.setTrueName(wxMerchant.getAccountName()); receiver.setParameter(wxMerchant.getAccountParameter()); - return wxProfitSharingReceiverService.updateReceiver(wxMerchant, receiver, isSync); + return wxProfitSharingReceiverService.updateReceiver(wxMerchant, receiver); } } catch (Exception e) { logger.error("db failed: 账户操作失败, e:" + e.getMessage(),e); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java index 079959a49..e3aa29271 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java @@ -427,7 +427,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { throw new MallinkException(ErrorCode.PAY_ORDER_MERCHANT_UID_ERROR); } PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); - WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchant_id, null, payMchTypeEnum.getCode()); + WxProfitPaymentReceiver receiver = payShareServie.getPaymantReceiver(payAccount, merchant_id); if(receiver == null){ throw new MallinkException(ErrorCode.PAY_ORDER_MERCHANT_UID_ERROR); } @@ -558,7 +558,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { String merchant_uid = ""; if(EnumPayMchType.DIRECT.getCode().equals(record.getMchType())){//直连模式记录收款商户 merchant_id = user.getMerchantId(); - WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchant_id, null, record.getMchType()); + WxProfitPaymentReceiver receiver = payShareServie.getPaymantReceiver(payAccount, merchant_id); if(receiver == null){ throw new MallinkException(ErrorCode.PAY_ORDER_MERCHANT_UID_ERROR); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitPaymentReceiverServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitPaymentReceiverServiceImpl.java new file mode 100644 index 000000000..3ee548dcc --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitPaymentReceiverServiceImpl.java @@ -0,0 +1,325 @@ +package com.iformall.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.iformall.common.ErrorCode; +import com.iformall.common.IdWorker; +import com.iformall.common.ResultData; +import com.iformall.domain.dto.WxMerchantDto; +import com.iformall.domain.po.*; +import com.iformall.domain.po.base.TenantEntity; +import com.iformall.domain.po.msg.WxMsgRecord; +import com.iformall.domain.vo.WxMerchantVo; +import com.iformall.douyin.pay.DouYinPayHelper; +import com.iformall.douyin.pay.enums.AppAddSubMerchantUrlType; +import com.iformall.douyin.pay.orderQuery.QueryMerchantResult; +import com.iformall.douyin.pay.preOrder.AppAddSubMerchant; +import com.iformall.douyin.pay.preOrder.AppAddSubMerchantResult; +import com.iformall.enums.*; +import com.iformall.exception.MallinkException; +import com.iformall.mapper.WxProfitPaymentReceiverMapper; +import com.iformall.mq.MqBaseProducer; +import com.iformall.service.*; +import com.iformall.service.pay.PayServiceFactory; +import com.iformall.service.pay.service.share.entity.ShareAccountResult; +import com.iformall.utils.Constant; +import com.iformall.utils.DateUtils; +import com.iformall.utils.RedisCacheUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Lazy; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +@Service +public class WxProfitPaymentReceiverServiceImpl implements WxProfitPaymentReceiverService { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + WxProfitPaymentReceiverMapper wxProfitPaymentReceiverMapper; + @Autowired + WxAppinfoService wxAppinfoService; + @Autowired + WxPayAccountService wxPayAccountService; + + @Lazy + @Autowired + WxMerchantService wxMerchantService; + + @Autowired + private MqBaseProducer mqBaseProducer; + + @Autowired + PayServiceFactory payServiceFactory; + + @Autowired + @Qualifier("objectCommonRedisTemplate") + RedisTemplate paymentReceicerRedisTemplate; + + @Override + public PageInfo listAsPage(WxProfitPaymentReceiver record, Integer pageIndex, Integer pageSize) { + return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxProfitPaymentReceiverMapper.findList(record)); + } + + @Override + public WxProfitPaymentReceiver getById(Long id) { + return wxProfitPaymentReceiverMapper.selectById(id); + } + + @Override + public void saveOrUpdate(WxProfitPaymentReceiver record) { + Date date = new Date(); + if (record.getId() == null) { + //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); + final IdWorker idWorker = IdWorker.get(); + record.setId(idWorker.nextId()); + record.setCreateTime(date); + record.setUpdateTime(date); + wxProfitPaymentReceiverMapper.insert(record); + } else { + record.setUpdateTime(date); + wxProfitPaymentReceiverMapper.updateById(record); + this.deleteRedis(record.getId()); + } + } + +// @Override +// public void deleteById(Long id) { +// wxProfitPaymentReceiverMapper.deleteById(id); +// } + + + @Override + public WxProfitPaymentReceiver findReceiver(TenantEntity tenantEntity,Long merchantId, EnumAppPlat plat,EnumProfitPaymentReceiverType receiverType) { + WxProfitPaymentReceiver record = null; + String key = Constant.paymentReceicerPrev + tenantEntity.getTenantId() + + ":" + plat.getCode() + + ":" + merchantId + + ":" + receiverType.getCode(); + record = RedisCacheUtils.getCacheObject(paymentReceicerRedisTemplate, key, WxProfitPaymentReceiver.class); + if(record == null){ + WxProfitPaymentReceiver receiver = new WxProfitPaymentReceiver(); + receiver.updateTenantInfo(tenantEntity); + receiver.setMerchantId(merchantId); + receiver.setPlat(plat.getCode()); + receiver.setReceiverType(receiverType.getCode()); + receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); + record = wxProfitPaymentReceiverMapper.findOne(receiver); + if(record != null){ + RedisCacheUtils.cache(paymentReceicerRedisTemplate, key, record, 3600*24*7); + } + } + return record; + + } + + + @Override + public ResultData updateTtReceiver(WxMerchant merchant) { + if(merchant == null) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); + } + WxProfitPaymentReceiver wxProfitPaymentReceiver = getTtPaymentReceiver(merchant); + + //进件页面 + AppAddSubMerchantResult improt_URLResult = appAddSubMerchant(merchant,merchant.getId().toString(),AppAddSubMerchantUrlType.improt_URL); + if(improt_URLResult.isSuccess()){ + wxProfitPaymentReceiver.setReceiverAccount(improt_URLResult.getMerchantId()); + wxProfitPaymentReceiver.setTtImportUrl(improt_URLResult.getUrl()); + }else{ + logger.error("获取进件页面 error{}"+improt_URLResult.getMsg()); + } + //余额页面 + AppAddSubMerchantResult balance_URLResult = appAddSubMerchant(merchant,merchant.getId().toString(),AppAddSubMerchantUrlType.Balance_URL); + if(balance_URLResult.isSuccess()){ + wxProfitPaymentReceiver.setReceiverAccount(balance_URLResult.getMerchantId()); + wxProfitPaymentReceiver.setTtBalanceUrl(balance_URLResult.getUrl()); + }else{ + logger.error("获取余额页面 error{}"+balance_URLResult.getMsg()); + } + this.saveOrUpdate(wxProfitPaymentReceiver); + return new ResultData(); + } + + @Override + public ResultData getTtReceiverImprotURL(WxMerchant merchant) { + if(merchant == null) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); + } + WxProfitPaymentReceiver wxProfitPaymentReceiver = getTtPaymentReceiver(merchant); + //进件页面 + AppAddSubMerchantResult improt_URLResult = appAddSubMerchant(merchant,merchant.getId().toString(),AppAddSubMerchantUrlType.improt_URL); + if(improt_URLResult.isSuccess()){ + wxProfitPaymentReceiver.setReceiverAccount(improt_URLResult.getMerchantId()); + wxProfitPaymentReceiver.setTtImportUrl(improt_URLResult.getUrl()); + this.saveOrUpdate(wxProfitPaymentReceiver); + return new ResultData(wxProfitPaymentReceiver.getTtImportUrl()); + }else{ + logger.error("获取进件页面 error{}"+improt_URLResult.getMsg()); + return new ResultData(ErrorCode.SYS_SERVER_ERROR); + } + } + + @Override + public ResultData getTtReceiverBalanceURL(WxMerchant merchant) { + if(merchant == null) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); + } + WxProfitPaymentReceiver wxProfitPaymentReceiver = getTtPaymentReceiver(merchant); + //余额页面 + AppAddSubMerchantResult balance_URLResult = appAddSubMerchant(merchant,merchant.getId().toString(),AppAddSubMerchantUrlType.Balance_URL); + if(balance_URLResult.isSuccess()){ + wxProfitPaymentReceiver.setReceiverAccount(balance_URLResult.getMerchantId()); + wxProfitPaymentReceiver.setTtBalanceUrl(balance_URLResult.getUrl()); + this.saveOrUpdate(wxProfitPaymentReceiver); + return new ResultData(wxProfitPaymentReceiver.getTtBalanceUrl()); + }else{ + logger.error("获取余额页面 error{}"+balance_URLResult.getMsg()); + return new ResultData(ErrorCode.SYS_SERVER_ERROR); + } + } + + private WxProfitPaymentReceiver getTtPaymentReceiver(WxMerchant merchant){ + WxProfitPaymentReceiver receiver = new WxProfitPaymentReceiver(); + receiver.updateTenantInfo(merchant); + receiver.setMerchantId(merchant.getId()); + receiver.setReceiverType(EnumProfitPaymentReceiverType.tt_merchant_number.getCode()); + receiver.setPlat(EnumAppPlat.TOUTIAO.getCode()); + receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); + WxProfitPaymentReceiver wxProfitPaymentReceiver = wxProfitPaymentReceiverMapper.selectOne(new QueryWrapper(receiver)); + if(wxProfitPaymentReceiver == null){ + receiver.setReceiverAccount("0"); + this.saveOrUpdate(receiver); + return receiver; + } + return wxProfitPaymentReceiver; + } + + @Override + public ResultData updateTtReceiverImportStatus(WxMerchant merchant) { + if(merchant == null) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); + } + WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(merchant.getTenantId(), EnumAppPlat.TOUTIAO); + if(appInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAcount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); + if(payAcount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); + } + + WxProfitPaymentReceiver receiver = new WxProfitPaymentReceiver(); + receiver.updateTenantInfo(merchant); + receiver.setMerchantId(merchant.getId()); + receiver.setReceiverType(EnumProfitPaymentReceiverType.tt_merchant_number.getCode()); + receiver.setPlat(EnumAppPlat.TOUTIAO.getCode()); + receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); + WxProfitPaymentReceiver wxProfitPaymentReceiver = wxProfitPaymentReceiverMapper.selectOne(new QueryWrapper(receiver)); + if(wxProfitPaymentReceiver == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未找到收款信息"); + } + + QueryMerchantResult queryMerchantResult = DouYinPayHelper.queryMerchantStatus(appInfo.getAppId(), payAcount.getMerchantApiKey(), wxProfitPaymentReceiver.getReceiverAccount(), wxProfitPaymentReceiver.getMerchantId().toString(), null); + if(queryMerchantResult != null){ + wxProfitPaymentReceiver.setTtImportStatus(JSON.toJSONString(queryMerchantResult)); + this.saveOrUpdate(wxProfitPaymentReceiver); + return new ResultData(); + }else{ + return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"查询进件状态出错!"); + } + } + + private AppAddSubMerchantResult appAddSubMerchant(TenantEntity tenantEntity, String merchantId, AppAddSubMerchantUrlType appAddSubMerchantUrlType){ + WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(tenantEntity.getTenantId(), EnumAppPlat.TOUTIAO); + if(appInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAcount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); + if(payAcount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); + } + AppAddSubMerchant appAddSubMerchant = new AppAddSubMerchant(); + appAddSubMerchant.setAppId(appInfo.getAppId()); + appAddSubMerchant.setSalt(payAcount.getMerchantApiKey()); + appAddSubMerchant.setSubMerchantId(merchantId); + appAddSubMerchant.setUrlType(appAddSubMerchantUrlType.getCode()); + return DouYinPayHelper.appAddSubMerchant(appAddSubMerchant); + } + + @Override + @Transactional(rollbackFor = {Exception.class}) + public ResultData updateReceiver(WxProfitPaymentReceiver receiver) { + + if(receiver.getMerchantId() == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"缺少商户信息"); + } + if(receiver.getPlat() == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"缺少平台信息"); + } + if(receiver.getReceiverType() == null){ + receiver.setReceiverType(EnumProfitPaymentReceiverType.wx_special_merchant_number.getCode()); + } + + WxProfitPaymentReceiver receiverQ = new WxProfitPaymentReceiver(); + receiverQ.updateTenantInfo(receiver); + receiverQ.setMerchantId(receiver.getMerchantId()); + receiverQ.setReceiverAccount(receiver.getReceiverAccount()); + // + WxProfitPaymentReceiver paymentReceiver = wxProfitPaymentReceiverMapper.selectOne(new QueryWrapper(receiverQ)); + if(paymentReceiver != null){ + receiver.setId(paymentReceiver.getId()); + receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); + this.saveOrUpdate(receiver); + }else{ + WxProfitPaymentReceiver oldReceiver = new WxProfitPaymentReceiver(); + oldReceiver.updateTenantInfo(receiver); + oldReceiver.setMerchantId(receiver.getMerchantId()); + oldReceiver.setReceiverType(receiver.getReceiverType()); + oldReceiver.setPlat(receiver.getPlat()); + oldReceiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); + List oldList = wxProfitPaymentReceiverMapper.selectList(new QueryWrapper(oldReceiver)); + + receiver.setId(null); + receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); + this.saveOrUpdate(receiver); + + if(oldList != null && oldList.size() > 0){ + for (WxProfitPaymentReceiver delReceiver:oldList) { + WxProfitPaymentReceiver del = new WxProfitPaymentReceiver(); + del.setId(delReceiver.getId()); + del.updateTenantInfo(delReceiver); + del.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode()); + this.saveOrUpdate(del); + } + } + } + + return new ResultData(); + } + + private void deleteRedis(Long id){ + WxProfitPaymentReceiver receiver = wxProfitPaymentReceiverMapper.selectById(id); + if(receiver != null){ + String key = Constant.paymentReceicerPrev + receiver.getTenantId() + + ":" + receiver.getPlat() + + ":" + receiver.getMerchantId() + + ":" + receiver.getReceiverType(); + RedisCacheUtils.removeCache(paymentReceicerRedisTemplate, key); + } + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java index c39ef6c5d..519020417 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java @@ -161,7 +161,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ merchantQ.setStatus(EnumMerchantStatus.VALID.getCode()); WxMerchant merchant = wxMerchantService.findListOne(merchantQ); if(merchant != null && !merchant.getId().equals(payMerchantId)){ - return payShareAdapterService.getReceiver(tenantEntity, merchant.getId(), ttPayWay, mchType); + return payShareAdapterService.getSharingReceiver(tenantEntity, merchant.getId(), ttPayWay, mchType); } return null; } @@ -332,7 +332,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ isSharingResult = true; }else{ isCallSharing = true; - WxProfitSharingReceiver receiver = payShareAdapterService.getReceiver(merchant,sharingOrder.getMerchantId(),payOrder.getTtPayWay(),payOrder.getMchType()); + WxProfitSharingReceiver receiver = payShareAdapterService.getSharingReceiver(merchant,sharingOrder.getMerchantId(),payOrder.getTtPayWay(),payOrder.getMchType()); if(EnumPayMchType.TOTAL.getCode().equals(payOrder.getMchType()) && EnumPayShare.YES.getCode().equals(payOrder.getShare())){ //总分 分账 抖音不支持 不支持开通 JSONObject jo = new JSONObject(); @@ -427,7 +427,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ if(EnumPayMchType.TOTAL.getCode().equals(payOrder.getMchType())){ //解冻给收款方(广场) JSONObject jo = new JSONObject(); - jo.put("type",EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_MERCHANT_ID.getMessage()); + jo.put("type",EnumProfitPaymentReceiverType.wx_special_merchant_number.getMessage()); jo.put("account",payAccount.getSubMchId()); jo.put("amount", shareAmount); jo.put("merchantId",0); @@ -435,7 +435,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ jo.put("description",0); receivers.add(jo); }else if(EnumPayMchType.DIRECT.getCode().equals(payOrder.getMchType())){ - WxProfitSharingReceiver receiver = payShareAdapterService.getReceiver(sharingOrder,wxComposeChildOrderShare.getMerchantId(),payOrder.getTtPayWay(),payOrder.getMchType()); + WxProfitPaymentReceiver receiver = payShareAdapterService.getPaymantReceiver(sharingOrder,wxComposeChildOrderShare.getMerchantId()); //解冻给收款方(门店) JSONObject jo = new JSONObject(); jo.put("type",payShareAdapterService.getShareAccount(receiver.getReceiverType()).getMessage()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverApplyServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverApplyServiceImpl.java index 27052f358..2daf0a469 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverApplyServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverApplyServiceImpl.java @@ -39,7 +39,7 @@ public class WxProfitSharingReceiverApplyServiceImpl implements WxProfitSharingR WxProfitSharingReceiverApplyMapper wxProfitSharingReceiverApplyMapper; @Autowired - WxProfitSharingReceiverService wxProfitSharingReceiverService; + WxProfitPaymentReceiverService wxProfitPaymentReceiverService; @Autowired WxAppinfoService wxAppinfoService; @@ -189,21 +189,13 @@ public class WxProfitSharingReceiverApplyServiceImpl implements WxProfitSharingR receiverApplyUpd.setUpdateTime(new Date()); wxProfitSharingReceiverApplyMapper.updateById(receiverApplyUpd); if(enumApplymentState.equals(EnumSharingReceiverApplymentState.APPLYMENT_STATE_FINISHED)){ - WxProfitSharingReceiver receiver = wxProfitSharingReceiverService.findReceiver(receiverApply, receiverApply.getMerchantId(), EnumAppPlat.WX, EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT_v2); - WxProfitSharingReceiver receiverUpd = new WxProfitSharingReceiver(); - receiverUpd.updateTenantInfo(receiverApply); - if(receiver != null){ - receiverUpd.setId(receiver.getId()); - receiverUpd.setReceiverAccount(receiverApplyUpd.getSubMchid()); - }else{ - receiverUpd.setPlat(EnumAppPlat.WX.getCode()); - receiverUpd.setMerchantId(receiverApply.getMerchantId()); - receiverUpd.setReceiverType(EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_MERCHANT_ID.getCode()); - receiverUpd.setReceiverAccount(receiverApplyUpd.getSubMchid()); - receiverUpd.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT_v2.getCode()); - receiverUpd.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); - } - wxProfitSharingReceiverService.saveOrUpdate(receiverUpd); + WxProfitPaymentReceiver receiver = new WxProfitPaymentReceiver(); + receiver.updateTenantInfo(receiverApply); + receiver.setMerchantId(receiverApply.getMerchantId()); + receiver.setPlat(EnumAppPlat.WX.getCode()); + receiver.setReceiverType(EnumProfitPaymentReceiverType.tt_merchant_number.getCode()); + receiver.setReceiverAccount(receiverApplyUpd.getSubMchid()); + wxProfitPaymentReceiverService.updateReceiver(receiver); } receiverApply.setSubMchid(receiverApplyUpd.getSubMchid()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java index 864a8e0e2..44ca366fb 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java @@ -124,20 +124,23 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv @Override - public WxProfitSharingReceiver findReceiver(TenantEntity tenantEntity,Long merchantId, EnumAppPlat plat,EnumProfitSharingType sharingType) { + public WxProfitSharingReceiver findReceiver(TenantEntity tenantEntity,Long merchantId, EnumAppPlat plat) { WxProfitSharingReceiver record = null; String key = Constant.sharingReceicerPrev + tenantEntity.getTenantId() - + ":" + merchantId - + ":" + plat.getCode() + "a" + sharingType.getCode(); + + ":" + plat.getCode() + + ":" + merchantId; record = RedisCacheUtils.getCacheObject(sharingReceicerRedisTemplate, key, WxProfitSharingReceiver.class); if(record == null){ WxProfitSharingReceiver receiver = new WxProfitSharingReceiver(); receiver.updateTenantInfo(tenantEntity); receiver.setMerchantId(merchantId); receiver.setPlat(plat.getCode()); - receiver.setSharingType(sharingType.getCode()); + receiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_SYS.getCode()); receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); - record = wxProfitSharingReceiverMapper.findOne(receiver); + List receivers = wxProfitSharingReceiverMapper.findList(receiver); + if(receivers != null && receivers.size() > 0){ + record = receivers.get(0); + } if(record != null){ RedisCacheUtils.cache(sharingReceicerRedisTemplate, key, record, 3600*24*7); } @@ -156,14 +159,14 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv } @Override - public ResultData addReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver, List delList, boolean isSync) { + public ResultData addReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver, List delList) { WxAppinfo appInfo = wxAppinfoService.getCAppInfo(merchant,EnumAppPlat.WX); WxPayAccount payAccount = wxPayAccountService.getById(appInfo.getPayId()); receiver.updateTenantInfo(merchant); receiver.setMerchantId(merchant.getId()); - receiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); + receiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_SYS.getCode()); receiver.setId(IdWorker.get().nextId()); Date date = new Date(); receiver.setCreateTime(date); @@ -177,20 +180,18 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv //receiver.setReceiverType(receiverParam.getReceiverType()); //receiver.setTrueName(receiverParam.getTrueName()); - if(isSync){ - //添加分账账户 - ShareAccountResult createResult = payServiceFactory.getPayShareAdapterService(EnumPayWay.PAY_WAY_WECHAT.getCode(),payAccount.getPayVersion()) - .createShareAccount(appInfo, payAccount, receiver); - if (!createResult.isSuccess()) { - return new ResultData(createResult.getCode(), createResult.getMsg()); - } + //添加分账账户 + ShareAccountResult createResult = payServiceFactory.getPayShareAdapterService(EnumPayWay.PAY_WAY_WECHAT.getCode(),payAccount.getPayVersion()) + .createShareAccount(appInfo, payAccount, receiver); + if (!createResult.isSuccess()) { + return new ResultData(createResult.getCode(), createResult.getMsg()); } wxProfitSharingReceiverMapper.insert(receiver); //添加成功才删除账户 for (WxProfitSharingReceiver delReceiver : delList) { - delReceiver(delReceiver, EnumMsgSend.MSG_SEND_NOT_IMMEDIATELY.getCode(),isSync); + delReceiver(delReceiver, EnumMsgSend.MSG_SEND_NOT_IMMEDIATELY.getCode()); } WxProfitSharingReceiver wxProfitSharingReceiver = new WxProfitSharingReceiver(); @@ -269,148 +270,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv } @Override - public ResultData updateTtReceiver(WxMerchant merchant) { - if(merchant == null) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); - } - WxProfitSharingReceiver wxProfitSharingReceiver = getTtSharingReceiver(merchant); - - //进件页面 - AppAddSubMerchantResult improt_URLResult = appAddSubMerchant(merchant,merchant.getId().toString(),AppAddSubMerchantUrlType.improt_URL); - if(improt_URLResult.isSuccess()){ - wxProfitSharingReceiver.setReceiverAccount(improt_URLResult.getMerchantId()); - wxProfitSharingReceiver.setTtImportUrl(improt_URLResult.getUrl()); - }else{ - logger.error("获取进件页面 error{}"+improt_URLResult.getMsg()); - } - //余额页面 - AppAddSubMerchantResult balance_URLResult = appAddSubMerchant(merchant,merchant.getId().toString(),AppAddSubMerchantUrlType.Balance_URL); - if(balance_URLResult.isSuccess()){ - wxProfitSharingReceiver.setReceiverAccount(balance_URLResult.getMerchantId()); - wxProfitSharingReceiver.setTtBalanceUrl(balance_URLResult.getUrl()); - }else{ - logger.error("获取余额页面 error{}"+balance_URLResult.getMsg()); - } - this.saveOrUpdate(wxProfitSharingReceiver); - return new ResultData(); - } - - @Override - public ResultData getTtReceiverImprotURL(WxMerchant merchant) { - if(merchant == null) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); - } - WxProfitSharingReceiver wxProfitSharingReceiver = getTtSharingReceiver(merchant); - //进件页面 - AppAddSubMerchantResult improt_URLResult = appAddSubMerchant(merchant,merchant.getId().toString(),AppAddSubMerchantUrlType.improt_URL); - if(improt_URLResult.isSuccess()){ - wxProfitSharingReceiver.setReceiverAccount(improt_URLResult.getMerchantId()); - wxProfitSharingReceiver.setTtImportUrl(improt_URLResult.getUrl()); - this.saveOrUpdate(wxProfitSharingReceiver); - return new ResultData(wxProfitSharingReceiver.getTtImportUrl()); - }else{ - logger.error("获取进件页面 error{}"+improt_URLResult.getMsg()); - return new ResultData(ErrorCode.SYS_SERVER_ERROR); - } - } - - @Override - public ResultData getTtReceiverBalanceURL(WxMerchant merchant) { - if(merchant == null) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); - } - WxProfitSharingReceiver wxProfitSharingReceiver = getTtSharingReceiver(merchant); - //余额页面 - AppAddSubMerchantResult balance_URLResult = appAddSubMerchant(merchant,merchant.getId().toString(),AppAddSubMerchantUrlType.Balance_URL); - if(balance_URLResult.isSuccess()){ - wxProfitSharingReceiver.setReceiverAccount(balance_URLResult.getMerchantId()); - wxProfitSharingReceiver.setTtBalanceUrl(balance_URLResult.getUrl()); - this.saveOrUpdate(wxProfitSharingReceiver); - return new ResultData(wxProfitSharingReceiver.getTtBalanceUrl()); - }else{ - logger.error("获取余额页面 error{}"+balance_URLResult.getMsg()); - return new ResultData(ErrorCode.SYS_SERVER_ERROR); - } - } - - private WxProfitSharingReceiver getTtSharingReceiver(WxMerchant merchant){ - WxProfitSharingReceiver oldReceiver = new WxProfitSharingReceiver(); - oldReceiver.updateTenantInfo(merchant); - oldReceiver.setMerchantId(merchant.getId()); - oldReceiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_DOUYIN.getCode()); - oldReceiver.setPlat(EnumAppPlat.TOUTIAO.getCode()); - WxProfitSharingReceiver wxProfitSharingReceiver = wxProfitSharingReceiverMapper.selectOne(new QueryWrapper(oldReceiver)); - if(wxProfitSharingReceiver == null){ - wxProfitSharingReceiver = oldReceiver; - wxProfitSharingReceiver.setReceiverType(EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_MERCHANT_ID.getCode()); - wxProfitSharingReceiver.setReceiverAccount("0"); -// wxProfitSharingReceiver.setIsUse(EnumProfitSharingUse.APPLY.getCode()); - wxProfitSharingReceiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); - this.saveOrUpdate(wxProfitSharingReceiver); - } - return wxProfitSharingReceiver; - } - - @Override - public ResultData updateTtReceiverIsUse(WxMerchant merchant) { - if(merchant == null) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); - } - WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(merchant.getTenantId(), EnumAppPlat.TOUTIAO); - if(appInfo == null){ - throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); - } - WxPayAccount payAcount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); - if(payAcount == null){ - throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); - } - - WxProfitSharingReceiver oldReceiver = new WxProfitSharingReceiver(); - oldReceiver.updateTenantInfo(merchant); - oldReceiver.setMerchantId(merchant.getId()); - oldReceiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_DOUYIN.getCode()); - oldReceiver.setPlat(EnumAppPlat.TOUTIAO.getCode()); - WxProfitSharingReceiver wxProfitSharingReceiver = wxProfitSharingReceiverMapper.selectOne(new QueryWrapper(oldReceiver)); - if(wxProfitSharingReceiver == null){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未找到分账信息"); - } - - QueryMerchantResult queryMerchantResult = DouYinPayHelper.queryMerchantStatus(appInfo.getAppId(), payAcount.getMerchantApiKey(), wxProfitSharingReceiver.getReceiverAccount(), wxProfitSharingReceiver.getMerchantId().toString(), null); - if(queryMerchantResult != null){ -// if(queryMerchantResult.getWx().intValue() != 1){ -// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"微信渠道未进件成功!"); -// } -// if(queryMerchantResult.getAlipay().intValue() != 1){ -// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"支付宝渠道未进件成功!"); -// } -// wxProfitSharingReceiver.setIsUse(EnumProfitSharingUse.YES.getCode()); - wxProfitSharingReceiver.setTtImportStatus(JSON.toJSONString(queryMerchantResult)); - this.saveOrUpdate(wxProfitSharingReceiver); - return new ResultData(); - }else{ - return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"查询进件状态出错!"); - } - } - - private AppAddSubMerchantResult appAddSubMerchant(TenantEntity tenantEntity, String merchantId, AppAddSubMerchantUrlType appAddSubMerchantUrlType){ - WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(tenantEntity.getTenantId(), EnumAppPlat.TOUTIAO); - if(appInfo == null){ - throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); - } - WxPayAccount payAcount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); - if(payAcount == null){ - throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); - } - AppAddSubMerchant appAddSubMerchant = new AppAddSubMerchant(); - appAddSubMerchant.setAppId(appInfo.getAppId()); - appAddSubMerchant.setSalt(payAcount.getMerchantApiKey()); - appAddSubMerchant.setSubMerchantId(merchantId); - appAddSubMerchant.setUrlType(appAddSubMerchantUrlType.getCode()); - return DouYinPayHelper.appAddSubMerchant(appAddSubMerchant); - } - - @Override - public ResultData delReceiver(WxProfitSharingReceiver receiver, Integer send, boolean isSync) { + public ResultData delReceiver(WxProfitSharingReceiver receiver, Integer send) { // WxAppinfo appInfo = wxAppinfoService.getCAppInfo(receiver,EnumAppPlat.WX); // WxPayAccount payAccount = wxPayAccountService.getById(appInfo.getPayId()); @@ -434,13 +294,11 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv ))) { //还有别的商户使用这个账号,不从微信服务器申请删除 } else { - if(isSync){ - WxAppinfo appInfo = wxAppinfoService.getCAppInfo(receiver,EnumAppPlat.WX); - WxPayAccount payAccount = wxPayAccountService.getById(appInfo.getPayId()); - ShareAccountResult shareResult = payServiceFactory.getPayShareAdapterService(receiver.getPlat(),payAccount.getPayVersion()).deleteShareAccount(appInfo, payAccount, receiver); - if (!shareResult.isSuccess()) { - return new ResultData(shareResult.getCode(), shareResult.getMsg()); - } + WxAppinfo appInfo = wxAppinfoService.getCAppInfo(receiver,EnumAppPlat.WX); + WxPayAccount payAccount = wxPayAccountService.getById(appInfo.getPayId()); + ShareAccountResult shareResult = payServiceFactory.getPayShareAdapterService(receiver.getPlat(),payAccount.getPayVersion()).deleteShareAccount(appInfo, payAccount, receiver); + if (!shareResult.isSuccess()) { + return new ResultData(shareResult.getCode(), shareResult.getMsg()); } } @@ -457,12 +315,12 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv } @Override - public ResultData updateReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver,boolean isSync) { + public ResultData updateReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver) { WxProfitSharingReceiver oldReceiver = new WxProfitSharingReceiver(); oldReceiver.updateTenantInfo(merchant); oldReceiver.setMerchantId(merchant.getId()); - oldReceiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); + oldReceiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_SYS.getCode()); oldReceiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); oldReceiver.setPlat(EnumAppPlat.WX.getCode()); List delList = wxProfitSharingReceiverMapper.selectList(new QueryWrapper(oldReceiver)); @@ -472,7 +330,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv oldReceiver = wxProfitSharingReceiverMapper.selectOne(new QueryWrapper(oldReceiver)); if (oldReceiver == null) { - return addReceiver(merchant, receiver, delList, isSync); + return addReceiver(merchant, receiver, delList); } else { oldReceiver.setParameter(receiver.getParameter()); oldReceiver.setUpdateTime(new Date()); @@ -486,8 +344,8 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv WxProfitSharingReceiver receiver = wxProfitSharingReceiverMapper.selectById(id); if(receiver != null){ String key = Constant.sharingReceicerPrev + receiver.getTenantId() - + ":" + receiver.getMerchantId() - + ":" + receiver.getPlat() + "a" + receiver.getSharingType(); + + ":" + receiver.getPlat() + + ":" + receiver.getMerchantId(); RedisCacheUtils.removeCache(sharingReceicerRedisTemplate, key); } } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java index 86447e366..951156cb5 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java @@ -39,6 +39,14 @@ public interface PayShareAdapterService { */ // public PayShareCalculateAmount calculateAmount(Integer payAmount,Integer officialCommissionRate,Integer systemAmount,WxPayAccount payAccount); + /** + * 查询商户的收款账号信息 + * @param tenantEntity + * @param merchantId + * @return + */ + WxProfitPaymentReceiver getPaymantReceiver(TenantEntity tenantEntity, Long merchantId); + /** * 查询商户的收款账号信息 * @param tenantEntity @@ -46,7 +54,7 @@ public interface PayShareAdapterService { * @param ttPayWay * @return */ - WxProfitSharingReceiver getReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType); + WxProfitSharingReceiver getSharingReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType); /** * 无分账接收方分账 ,钱直接分给小程序方 调用API分账 diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java index 15d0f912e..b0a02eff1 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java @@ -22,6 +22,7 @@ import com.iformall.douyin.payv2.result.ProfitSharingResult; import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.mapper.*; +import com.iformall.service.WxProfitPaymentReceiverService; import com.iformall.service.WxProfitSharingReceiverService; import com.iformall.service.order.entity.WxComposeChildOrderShare; import com.iformall.service.order.util.OrderHelper; @@ -78,6 +79,10 @@ public class TtPayShareService extends PayShareBaseAdapterService{ @Autowired WxProfitSharingReceiverService wxProfitSharingReceiverService; + @Lazy + @Autowired + WxProfitPaymentReceiverService wxProfitPaymentReceiverService; + /** * 做为分账的扩展数据 * @param payOrder @@ -94,6 +99,7 @@ public class TtPayShareService extends PayShareBaseAdapterService{ return EnumMerchantSubsidyType.DOUYIN.getCode(); } + // @Override // public Integer getSharingOrderInitialStatus() { // return EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode(); @@ -308,12 +314,12 @@ public class TtPayShareService extends PayShareBaseAdapterService{ } @Override - public WxProfitSharingReceiver getReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { + public WxProfitSharingReceiver getSharingReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { if(merchantId == null || merchantId.equals(0L)){ return null; } - WxProfitSharingReceiver record = wxProfitSharingReceiverService.findReceiver(tenantEntity, merchantId,EnumAppPlat.TOUTIAO,EnumProfitSharingType.PROFIT_SHARING_TYPE_DOUYIN); + WxProfitSharingReceiver record = wxProfitSharingReceiverService.findReceiver(tenantEntity, merchantId,EnumAppPlat.TOUTIAO); if(ttPayWay != null){ if(EnumTtPayChannel.WX_PAY.getCode().equals(ttPayWay) @@ -334,4 +340,20 @@ public class TtPayShareService extends PayShareBaseAdapterService{ } + @Override + public WxProfitPaymentReceiver getPaymantReceiver(TenantEntity tenantEntity, Long merchantId) { + if(merchantId == null || merchantId.equals(0L)){ + return null; + } + + WxProfitPaymentReceiver record = wxProfitPaymentReceiverService.findReceiver(tenantEntity, merchantId,EnumAppPlat.TOUTIAO,EnumProfitPaymentReceiverType.tt_merchant_number); + if(record != null && !MerchantImportStatus.improt_success.getCode().equals(record.getWxImportStatus()) + && !MerchantImportStatus.improt_success.getCode().equals(record.getAlipayImportStatus()) + && !MerchantImportStatus.improt_success.getCode().equals(record.getHzImportStatus())){ + log.error("该商户未开通支付"); + return null; + } + return record; + } + } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java index 8e8d5e63d..33b754a00 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java @@ -156,9 +156,14 @@ public class WxPayShareSFTService extends PayShareBaseAdapterService{ } @Override - public WxProfitSharingReceiver getReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { + public WxProfitSharingReceiver getSharingReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { return null; } + @Override + public WxProfitPaymentReceiver getPaymantReceiver(TenantEntity tenantEntity, Long merchantId) { + return null; + } + } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java index 40bc71932..5954bc8b3 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java @@ -12,6 +12,7 @@ import com.iformall.douyin.pay.enums.MerchantImportStatus; import com.iformall.enums.*; import com.iformall.mapper.*; +import com.iformall.service.WxProfitPaymentReceiverService; import com.iformall.service.WxProfitSharingReceiverService; import com.iformall.utils.*; import net.sf.saxon.trans.Err; @@ -52,6 +53,10 @@ public class WxPayShareService extends PayShareBaseAdapterService{ @Autowired WxProfitSharingReceiverService wxProfitSharingReceiverService; + @Autowired + WxProfitPaymentReceiverService wxProfitPaymentReceiverService; + + final JSONObject statusMap = JSON.parseObject( "{\"ACCEPTED\":3," + "\"PROCESSING\": 4," + @@ -356,17 +361,26 @@ public class WxPayShareService extends PayShareBaseAdapterService{ } @Override - public WxProfitSharingReceiver getReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { + public WxProfitSharingReceiver getSharingReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { if(merchantId == null || merchantId.equals(0L)){ return null; } - WxProfitSharingReceiver record = wxProfitSharingReceiverService.findReceiver(tenantEntity, merchantId,EnumAppPlat.WX,EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT); - if(record != null && EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_PERSONAL_WECHATID.getCode().equals(record.getReceiverType())){ + WxProfitSharingReceiver record = wxProfitSharingReceiverService.findReceiver(tenantEntity, merchantId,EnumAppPlat.WX); + if(record != null && EnumProfitPaymentReceiverType.wx_personal_wechatid.getCode().equals(record.getReceiverType())){ throw new MallinkException(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID.getCode(),"该商户收款账号存在个人微信号方式,微信已停止支持,请重新设置."); } return record; } + @Override + public WxProfitPaymentReceiver getPaymantReceiver(TenantEntity tenantEntity, Long merchantId) { + if(merchantId == null || merchantId.equals(0L)){ + return null; + } + WxProfitPaymentReceiver record = wxProfitPaymentReceiverService.findReceiver(tenantEntity, merchantId,EnumAppPlat.WX,EnumProfitPaymentReceiverType.wx_special_merchant_number); + return record; + } + private static String queryOrderShareAmount(String mchId,String transcationId,String apiKey) { WxProfitSharingP psCmd = new WxProfitSharingP(); psCmd.setMch_id(mchId);//服务商商户id diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java index 0422b27a7..77d0ce286 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java @@ -14,6 +14,7 @@ import com.iformall.domain.po.*; import com.iformall.domain.po.base.TenantEntity; import com.iformall.enums.*; import com.iformall.mapper.*; +import com.iformall.service.WxProfitPaymentReceiverService; import com.iformall.utils.Constant; import com.iformall.utils.RedisCacheUtils; import org.apache.commons.lang3.StringUtils; @@ -52,6 +53,10 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ @Lazy @Autowired WxProfitSharingReceiverService wxProfitSharingReceiverService; + + @Lazy + @Autowired + WxProfitPaymentReceiverService wxProfitPaymentReceiverService; @Autowired MaUtil maUtil; @@ -79,25 +84,27 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ @Override - public WxProfitSharingReceiver getReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { + public WxProfitSharingReceiver getSharingReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { if(merchantId == null || merchantId.equals(0L)){ return null; } - //直连,必须是特约商户号 - if (EnumPayMchType.DIRECT.getCode() == mchType) { - return wxProfitSharingReceiverService.findReceiver(tenantEntity, merchantId,EnumAppPlat.WX,EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT_v2); -// 总分 - }else if (EnumPayMchType.TOTAL.getCode() == mchType) { - return wxProfitSharingReceiverService.findReceiver(tenantEntity, merchantId,EnumAppPlat.WX,EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT); - } + return wxProfitSharingReceiverService.findReceiver(tenantEntity, merchantId,EnumAppPlat.WX); // if (null == receiver) { // throw new MallinkException(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID.getCode(),"该商户未设置分账账号."); // } - return null; } + @Override + public WxProfitPaymentReceiver getPaymantReceiver(TenantEntity tenantEntity, Long merchantId) { + if(merchantId == null || merchantId.equals(0L)){ + return null; + } + WxProfitPaymentReceiver record = wxProfitPaymentReceiverService.findReceiver(tenantEntity, merchantId,EnumAppPlat.WX,EnumProfitPaymentReceiverType.wx_special_merchant_number); + return record; + } + //无需分账,直接解冻 @Override public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record) { diff --git a/mallinkService/src/main/java/com/iformall/utils/Constant.java b/mallinkService/src/main/java/com/iformall/utils/Constant.java index 2dec1945d..17bb72bd4 100644 --- a/mallinkService/src/main/java/com/iformall/utils/Constant.java +++ b/mallinkService/src/main/java/com/iformall/utils/Constant.java @@ -101,6 +101,7 @@ public class Constant { //获取mall信息 public static final String appinfoPrev = "appinfo:"; public static final String payaccountPrev = "payAccount:"; + public static final String paymentReceicerPrev = "paymentReceicer:"; public static final String sharingReceicerPrev = "sharingReceicer:"; public static final String mallinfoPrev = "mallinfo:"; public static final String subMallinfoPrev = "mallinfo:subMallinfo:"; diff --git a/mallinkService/src/main/resources/mapper/WxProfitPaymentReceiverMapper.xml b/mallinkService/src/main/resources/mapper/WxProfitPaymentReceiverMapper.xml new file mode 100644 index 000000000..c9dd5fc3f --- /dev/null +++ b/mallinkService/src/main/resources/mapper/WxProfitPaymentReceiverMapper.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`, + `receiver_type`,`receiver_account`,`receiver_comments`, + `create_time`,`update_time`,`status`,`plat`, + `tt_import_status`,`tt_import_url`,`tt_balance_url` + + + + where 1 = 1 + + + and `id` = #{id} + + + + and `tenant_id` = #{tenantId} + + + and `parent_tenant_id` = #{parentTenantId} + + + + and `merchant_id` = #{merchantId} + + + + and `receiver_type` = #{receiverType} + + + + and `receiver_account` like concat('%', #{receiverAccount},'%') + + + + and `receiver_comments` like concat('%', #{receiverComments},'%') + + + + and `status` = #{status} + + + + and `plat` = #{plat} + + + + and `tt_import_status` -> '$.wx' = #{wxImportStatus} + + + and `tt_import_status` -> '$.alipay' = #{alipayImportStatus} + + + and `tt_import_status` -> '$.hz' = #{hzImportStatus} + + + + and id in + + #{idItem} + + + order by ${sortColumns} + + + + + + + + diff --git a/mallinkService/src/main/resources/mapper/WxProfitSharingReceiverMapper.xml b/mallinkService/src/main/resources/mapper/WxProfitSharingReceiverMapper.xml index b66a2ab38..73c07f69a 100644 --- a/mallinkService/src/main/resources/mapper/WxProfitSharingReceiverMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxProfitSharingReceiverMapper.xml @@ -17,6 +17,7 @@ + @@ -24,7 +25,7 @@ - `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`receiver_type`,`receiver_account`,`receiver_comments`,`create_time`,`update_time`,`sharing_type`,`bank_no`,`true_name`,`bank_code`,`status`,`parameter`,`is_use` + `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`receiver_type`,`receiver_account`,`receiver_comments`,`create_time`,`update_time`,`sharing_type`,`bank_no`,`true_name`,`bank_code`,`status`,`parameter`,`plat`,`is_use` ,`tt_import_status`,`tt_import_url`,`tt_balance_url` @@ -98,6 +99,10 @@ + + and `plat` = #{plat} + + and `is_use` = #{isUse}