From 6910f32c722b1144917df6c0dbae878a6ac3e2a5 Mon Sep 17 00:00:00 2001 From: xhxu Date: Thu, 17 Mar 2022 17:50:13 +0800 Subject: [PATCH] //TTreciver --- .../basic/WxMerchantController.java | 55 ++++++++++- .../V2022031700001__sharingReceiver.sql | 3 + .../schedule/TtMerchantReciverSchedule.java | 89 +++++++++++++++++ .../domain/po/WxProfitSharingReceiver.java | 6 ++ .../com/iformall/mapper/WxMerchantMapper.java | 1 + .../WxProfitSharingReceiverService.java | 3 + .../impl/WxProfitSharingOrderServiceImpl.java | 4 + .../WxProfitSharingReceiverServiceImpl.java | 97 ++++++++++++++++++- .../resources/mapper/WxMerchantMapper.xml | 14 +++ .../mapper/WxProfitSharingReceiverMapper.xml | 7 +- 10 files changed, 274 insertions(+), 5 deletions(-) create mode 100644 mallinkAdmin/src/main/resources/db/migration/V2022031700001__sharingReceiver.sql create mode 100644 mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantReciverSchedule.java 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 4c3955b6e..80e255e8c 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantController.java @@ -4,9 +4,12 @@ import com.github.pagehelper.PageInfo; import com.iformall.annotation.SystemControllerLog; import com.iformall.annotation.TenantIgnore; import com.iformall.annotation.UserDataRuleAnnotation; +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.base.BaseEntity; import com.iformall.domain.po.WxMerchant; import com.iformall.domain.po.WxProfitSharingReceiver; @@ -16,8 +19,7 @@ import com.iformall.domain.vo.WxMerchantVo; import com.iformall.enums.EnumAppPlat; import com.iformall.enums.EnumMerchantStatus; import com.iformall.enums.EnumPayWay; -import com.iformall.service.QrCodeService; -import com.iformall.service.WxMerchantService; +import com.iformall.service.*; import com.iformall.utils.Constant; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -45,6 +47,14 @@ public class WxMerchantController extends BaseController { @Autowired private QrCodeService qrCodeService; + @Autowired + private WxAppinfoService wxAppinfoService; + @Autowired + private WxPayAccountService payAccountService; + + @Autowired + private WxProfitSharingReceiverService wxProfitSharingReceiverService; + @UserDataRuleAnnotation("merchant_list") @ApiOperation("分页列表接口") @GetMapping("listVo") @@ -331,4 +341,45 @@ public class WxMerchantController extends BaseController { wxMerchantService.exportUserTradeList(wxMerchant, request,response); } + @ApiOperation("刷新进件页面") + @GetMapping("/updateTtReceiver") + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) + @SystemControllerLog(description = "商户-删除") + public ResultData updateTtReceiver(Long id) { + logger.debug("[" + getIpAddr() + "] WxMerchantController::updateTtReceiver"); + WxMerchant merchant = wxMerchantService.selectById(id); + if(merchant == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); + } + WxAppinfo appInfo = wxAppinfoService.getCAppInfo(getTenantInfo(), EnumAppPlat.TOUTIAO); + if(appInfo == null) { + return new ResultData(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAcount = payAccountService.getById(appInfo.getPayId()); + if(payAcount == null){ + return new ResultData(ErrorCode.APP_ID_NOT_FOUND); + } + return wxProfitSharingReceiverService.updateTtReceiver(merchant,appInfo.getAppId(),payAcount.getMerchantApiKey()); + } + + @ApiOperation("修改可用状态") + @GetMapping("/updateTtReceiverIsUse") + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) + @SystemControllerLog(description = "商户-删除") + public ResultData updateTtReceiverIsUse(Long id) { + WxMerchant merchant = wxMerchantService.selectById(id); + if(merchant == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); + } + WxAppinfo appInfo = wxAppinfoService.getCAppInfo(getTenantInfo(), EnumAppPlat.TOUTIAO); + if(appInfo == null) { + return new ResultData(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAcount = payAccountService.getById(appInfo.getPayId()); + if(payAcount == null){ + return new ResultData(ErrorCode.APP_ID_NOT_FOUND); + } + return wxProfitSharingReceiverService.updateTtReceiverIsUse(merchant,appInfo.getAppId(),payAcount.getMerchantApiKey()); + } + } diff --git a/mallinkAdmin/src/main/resources/db/migration/V2022031700001__sharingReceiver.sql b/mallinkAdmin/src/main/resources/db/migration/V2022031700001__sharingReceiver.sql new file mode 100644 index 000000000..d5be0b0bf --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V2022031700001__sharingReceiver.sql @@ -0,0 +1,3 @@ +ALTER TABLE `mallink`.`wx_profit_sharing_receiver` +ADD COLUMN `tt_import_url` varchar(500) COMMENT '进件页面' AFTER `plat`, +ADD COLUMN `tt_balance_url` varchar(500) COMMENT '余额页面' AFTER `tt_import_url`; \ No newline at end of file diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantReciverSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantReciverSchedule.java new file mode 100644 index 000000000..8c0eab800 --- /dev/null +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantReciverSchedule.java @@ -0,0 +1,89 @@ +package com.iformall.schedule; + +import com.iformall.domain.po.*; +import com.iformall.enums.*; +import com.iformall.mapper.WxMerchantMapper; +import com.iformall.service.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author gongbiao + */ +@Component +public class TtMerchantReciverSchedule { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private WxMallService wxMallService; + + @Autowired + private WxMerchantMapper wxMerchantMapper; + + @Autowired + private WxAppinfoService wxAppinfoService; + + @Autowired + private WxPayAccountService payAccountService; + + @Autowired + private WxProfitSharingReceiverService wxProfitSharingReceiverService; + + + /** + * 每天0点执行 + */ + @Scheduled(cron = "0 0 0 * * ?") +// @Scheduled(cron = "0 */5 * * * *?") //测试五分钟执行 + public void updateMerchantReciverSchedule() { + WxMall mallQ = new WxMall(); + mallQ.setSaleType(EnumSaleType.TT_ALL_ROUND.getCode()); + List mallList = wxMallService.findList(mallQ); + if(mallList == null || mallList.isEmpty()){ + return; + } + List tenantIds = mallList.stream().map(m -> m.getTenantId()).collect(Collectors.toList()); + + List merchants = wxMerchantMapper.findByTenantIds(tenantIds); + if(merchants == null || merchants.isEmpty()){ + return; + } + + Map appIdMap = new HashMap<>(); + Map payAccountKeyMap = new HashMap<>(); + WxAppinfo appQ = new WxAppinfo(); + appQ.setType(EnumAppType.C.getCode()); + appQ.setPlat(EnumPayWay.PAY_WAY_TT.getPlat().getCode()); + List wxAppinfoList = wxAppinfoService.getList(appQ); + for (WxAppinfo wxAppinfo:wxAppinfoList) { + appIdMap.put(wxAppinfo.getTenantId(),wxAppinfo.getAppId()); + WxPayAccount wxPayAccount = payAccountService.getById(wxAppinfo.getId()); + payAccountKeyMap.put(wxAppinfo.getTenantId(),wxPayAccount.getApiKey()); + } + + for (WxMerchant m:merchants) { + try { + wxProfitSharingReceiverService.updateTtReceiver(m,appIdMap.get(m.getTenantId()),payAccountKeyMap.get(m.getTenantId())); + } catch (Exception e) { + e.printStackTrace(); + logger.error("TtMerchantReciverSchedule error.updateTtReceiver:"+m.getId(),e); + } + try { + wxProfitSharingReceiverService.updateTtReceiverIsUse(m,appIdMap.get(m.getTenantId()),payAccountKeyMap.get(m.getTenantId())); + } catch (Exception e) { + e.printStackTrace(); + logger.error("TtMerchantReciverSchedule error.updateTtReceiver:"+m.getId(),e); + } + } + } + +} \ No newline at end of file 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 1edad606e..d29a2fe48 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingReceiver.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingReceiver.java @@ -49,4 +49,10 @@ public class WxProfitSharingReceiver extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value = "是否使用 0,不使用 1,使用", name = "isUse") private Integer isUse; + @io.swagger.annotations.ApiModelProperty(value = "进件页面", name = "ttImportUrl") + private String ttImportUrl; + + @io.swagger.annotations.ApiModelProperty(value = "余额页面", name = "ttBalanceUrl") + private String ttBalanceUrl; + } diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxMerchantMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxMerchantMapper.java index 53b1283d9..56b270830 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxMerchantMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxMerchantMapper.java @@ -17,6 +17,7 @@ public interface WxMerchantMapper extends CommonMapper { List findList(WxMerchant wxMerchant); List findIdList(WxMerchant wxMerchant); + List findByTenantIds(@Param("tenantIds")List tenantIds); List findIdNameList(WxMerchant wxMerchant); diff --git a/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java b/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java index 81bad6ccc..3b4336773 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java @@ -53,4 +53,7 @@ public interface WxProfitSharingReceiverService { void sendMsg(String phone, String account, String merchant, String time, Integer modelType, TenantEntity tenantEntity); + ResultData updateTtReceiver(WxMerchant merchant, String appId, String payAccountKey); + + ResultData updateTtReceiverIsUse(WxMerchant merchant, String appId, String payAccountKey); } 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 c14628a47..d9ebe6e5f 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java @@ -251,6 +251,10 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ psReceiverQ.setMerchantId(sharingOrderDto.getMerchantId()); psReceiverQ.setSharingType(payServiceFactory.getPayShareAdapterService(payWay).getProfitSharingType()); psReceiverQ.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); + psReceiverQ.setPlat(EnumPayWay.getEnum(payWay).getPlat().getCode()); + if(EnumAppPlat.TOUTIAO.getCode().equals(psReceiverQ.getPlat())){ + psReceiverQ.setIsUse(EnumProfitSharingUse.YES.getCode()); + } List psReceiverList = wxProfitSharingReceiverMapper.findList(psReceiverQ); if (psReceiverList.size() < 0 || psReceiverList.size() > 50) { return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); 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 1471663cd..73fd5ae81 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java @@ -16,6 +16,11 @@ import com.iformall.domain.po.WxProfitSharingReceiver; 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.mapper.WxAppinfoMapper; import com.iformall.mapper.WxMerchantMapper; @@ -88,12 +93,16 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv @Override public void saveOrUpdate(WxProfitSharingReceiver 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); wxProfitSharingReceiverMapper.insert(record); } else { + record.setUpdateTime(date); wxProfitSharingReceiverMapper.updateById(record); } } @@ -104,14 +113,19 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv } + //todo 微信和抖音分账可能存在两个分账信息 @Override public WxProfitSharingReceiver findReceiver(WxMerchant merchant) { WxProfitSharingReceiver receiver = new WxProfitSharingReceiver(); receiver.updateTenantInfo(merchant); receiver.setMerchantId(merchant.getId()); - receiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); +// receiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); - return wxProfitSharingReceiverMapper.selectOne(new QueryWrapper(receiver)); + List list = wxProfitSharingReceiverMapper.findList(receiver); + if(list != null && list.size() > 0){ + return list.get(0); + } + return null; } @@ -230,6 +244,84 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv logger.info("》》》》》》》》》》》"); } + @Override + public ResultData updateTtReceiver(WxMerchant merchant, String appId, String payAccountKey) { + if(merchant == null || StringUtils.isBlank(appId) || StringUtils.isBlank(payAccountKey)) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); + } + 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); + } + //进件页面 + AppAddSubMerchantResult improt_URLResult = appAddSubMerchant(appId,payAccountKey,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(appId,payAccountKey,merchant.getId().toString(),AppAddSubMerchantUrlType.Balance_URL); + if(balance_URLResult.isSuccess()){ + wxProfitSharingReceiver.setReceiverAccount(improt_URLResult.getMerchantId()); + wxProfitSharingReceiver.setTtBalanceUrl(balance_URLResult.getMerchantId()); + }else{ + logger.error("获取余额页面 error{}"+improt_URLResult.getMsg()); + } + this.saveOrUpdate(wxProfitSharingReceiver); + return new ResultData(); + } + + @Override + public ResultData updateTtReceiverIsUse(WxMerchant merchant, String appId, String payAccountKey) { + if(merchant == null || StringUtils.isBlank(appId) || StringUtils.isBlank(payAccountKey)) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); + } + 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(appId, payAccountKey, 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()); + this.saveOrUpdate(wxProfitSharingReceiver); + return new ResultData(); + }else{ + return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"查询进件状态出错!"); + } + } + + private AppAddSubMerchantResult appAddSubMerchant(String appId, String payAccountKey, String merchantId, AppAddSubMerchantUrlType appAddSubMerchantUrlType){ + AppAddSubMerchant appAddSubMerchant = new AppAddSubMerchant(); + appAddSubMerchant.setAppId(appId); + appAddSubMerchant.setSalt(payAccountKey); + appAddSubMerchant.setSubMerchantId(merchantId); + appAddSubMerchant.setUrlType(appAddSubMerchantUrlType.getCode()); + return DouYinPayHelper.appAddSubMerchant(appAddSubMerchant); + } + @Override public ResultData delReceiver(WxProfitSharingReceiver receiver, Integer send) { WxAppinfo appInfo = new WxAppinfo(); @@ -284,6 +376,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv oldReceiver.setMerchantId(merchant.getId()); oldReceiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); oldReceiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); + oldReceiver.setPlat(payWay.getPlat().getCode()); List delList = wxProfitSharingReceiverMapper.selectList(new QueryWrapper(oldReceiver)); oldReceiver.setReceiverAccount(receiver.getReceiverAccount()); oldReceiver.setReceiverType(receiver.getReceiverType()); diff --git a/mallinkService/src/main/resources/mapper/WxMerchantMapper.xml b/mallinkService/src/main/resources/mapper/WxMerchantMapper.xml index ef4026d39..ff12c4a59 100644 --- a/mallinkService/src/main/resources/mapper/WxMerchantMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxMerchantMapper.xml @@ -182,6 +182,20 @@ from wx_merchant m + +