Commit 88319d66 by 程裕兵

feat:callback

parent 5834916f
......@@ -340,35 +340,56 @@ public class StudioMerchantServiceImpl implements StudioMerchantService {
StudioMerchantApply toModify = MerchantConvert.convertApply(apply, event,
configService.getDefaultBrandSubChannelInfo().getSubChannels());
studioMerchantApplyRpService.updateById(toModify);
if (!OpenStateEnums.SUCCESS.getCode().equals(toModify.getOpenState())) {
if (OpenStateEnums.SUCCESS != OpenStateEnums.getByCode(toModify.getOpenState())) {
return;
}
if (OpenStateEnums.SUCCESS == OpenStateEnums.getByCode(apply.getOpenState())) {
// 绑定逻辑幂等处理
return;
}
// 所有子通道全部开通成功
PartyToMerchant old = getRelation(apply.getStudioId());
// 1. 如果当前场馆绑定的是自己的商户号(old),则需要将绑定了该商户号的所有其他场馆进行解绑
if (null != old && !old.getMerchantId().equals(event.getMerchantId())) {
StudioMerchantApply oldApply = studioMerchantApplyRpService.getLatestOneSuccessByMerchantId(
old.getMerchantId());
if (!oldApply.getStudioId().equals(apply.getStudioId())) {
// 1.1 如果当前场馆绑定的是自己的商户号(old),则需要将绑定了该商户号的所有其他场馆进行解绑
this.unbindAll(old.getMerchantId());
// 1.2 场馆商户发生了变更,解绑掉绑定了老商户号的品牌
brandMerchantService.unbind(apply.getBrandId(), old.getMerchantId());
// 绑定商户
this.bindWhenOpenSuccess(event, apply);
}
private Long unbindWhenOpenSuccess(StudioMerchantApply apply) {
PartyToMerchant old = this.getRelation(apply.getStudioId());
if (null == old) {
return null;
}
Long oldMerchantId = old.getMerchantId();
StudioMerchantApply exist = studioMerchantApplyRpService.getLatestOneSuccessByMerchantId(oldMerchantId);
if (!exist.getStudioId().equals(apply.getStudioId())) {
// 之前绑定的商户不是自己的商户,不需要解绑
return oldMerchantId;
}
// 1. 如果当前场馆绑定的是自己的商户号(old),则需要将绑定了该商户号的所有其他场馆进行解绑
this.unbindAll(oldMerchantId);
// 2. 场馆商户发生了变更,解绑掉绑定了老商户号的品牌
brandMerchantService.unbind(apply.getBrandId(), oldMerchantId);
return oldMerchantId;
}
private void bindWhenOpenSuccess(MerchantEvent event, StudioMerchantApply apply) {
// 1. 解绑历史商户
Long oldMerchantId = this.unbindWhenOpenSuccess(apply);
// 2. 绑定场馆
this.bind(apply.getStudioId(), event.getMerchantId(), false);
// 3. 绑定品牌
brandMerchantService.bind(apply.getBrandId(), event.getMerchantId());
// 4. 其他操作
executor.execute(() -> this.doAfterMerchantSuccess(event,
Optional.ofNullable(old).map(PartyToMerchant::getMerchantId).orElse(null)));
executor.execute(() -> this.doAfterMerchantSuccess(event, oldMerchantId));
}
private void doAfterMerchantSuccess(MerchantEvent event, Long oldMerchantId) {
// 1. 配置场馆小程序appId
this.rebindMiniAppId(oldMerchantId, event.getMerchantId());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment