多个代理商入驻逻辑 新增
This commit is contained in:
parent
54b0cae1c1
commit
7fc99bb3ca
@ -27,12 +27,12 @@ public interface EsignPlatformInfoService {
|
||||
EsignPlatformInfo getDistributorInfoById(Long id);
|
||||
|
||||
/**
|
||||
* 根据ID获取代理商信息
|
||||
* 根据入驻编号获取平台和代理商信息
|
||||
*
|
||||
* @param ids
|
||||
* @param mchId
|
||||
* @return
|
||||
*/
|
||||
List<EsignPlatformInfo> getDistributorAndPlatformByIds(Long... ids);
|
||||
List<EsignPlatformInfo> getDistributorAndPlatformByIds(Long mchId);
|
||||
|
||||
/**
|
||||
* 根据分类和营业执照号获取平台方信息
|
||||
@ -57,4 +57,20 @@ public interface EsignPlatformInfoService {
|
||||
* @return
|
||||
*/
|
||||
Pair<String, String> getEsignPlatformMobileAndLicenseNumber();
|
||||
|
||||
/**
|
||||
* 根据入驻编号获取商户的二级代理
|
||||
*
|
||||
* @param mchId
|
||||
* @return
|
||||
*/
|
||||
EsignPlatformInfo getMch2ndAgent(Long mchId);
|
||||
|
||||
/**
|
||||
* 根据入驻编号获取商户的二级代理(收运费的代理商)
|
||||
*
|
||||
* @param mchId
|
||||
* @return
|
||||
*/
|
||||
EsignPlatformInfo getMch2ndAgentWithShippingFee(Long mchId);
|
||||
}
|
||||
|
||||
@ -13,18 +13,30 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.suisung.mall.common.constant.CommonConstant;
|
||||
import com.suisung.mall.common.modules.esign.EsignPlatformInfo;
|
||||
import com.suisung.mall.common.modules.store.ShopMchEntry;
|
||||
import com.suisung.mall.common.utils.CheckUtil;
|
||||
import com.suisung.mall.common.utils.phone.PhoneNumberUtils;
|
||||
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
||||
import com.suisung.mall.shop.esign.mapper.EsignPlatformInfoMapper;
|
||||
import com.suisung.mall.shop.esign.service.EsignPlatformInfoService;
|
||||
import com.suisung.mall.shop.store.service.ShopMchEntryService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.util.Pair;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformInfoMapper, EsignPlatformInfo> implements EsignPlatformInfoService {
|
||||
|
||||
@Lazy
|
||||
@Resource
|
||||
private ShopMchEntryService shopMchEntryService;
|
||||
|
||||
/**
|
||||
* 根据ID获取代理商信息
|
||||
*
|
||||
@ -51,34 +63,52 @@ public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformI
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据一个或多个代理商自增ID获取代理商和平台记录,无论怎么都要获取一条平台方的记录
|
||||
* 根据入驻编号获取平台和代理商信息
|
||||
* 无论是否找到代理商,都会返回平台方记录
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
* @param mchId 商户ID
|
||||
* @return List<EsignPlatformInfo> 平台方和代理商信息列表
|
||||
*/
|
||||
@Override
|
||||
public List<EsignPlatformInfo> getDistributorAndPlatformByIds(Long... ids) {
|
||||
public List<EsignPlatformInfo> getDistributorAndPlatformByIds(Long mchId) {
|
||||
// 获取平台方记录
|
||||
QueryWrapper<EsignPlatformInfo> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("status", CommonConstant.Enable).orderByAsc("level");
|
||||
if (ids != null && ids.length > 0) {
|
||||
queryWrapper.and(wrapper -> {
|
||||
wrapper.in("id", ids).gt("level", 0);
|
||||
wrapper.or(wrapperOr -> {
|
||||
wrapperOr.eq("level", 0);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
queryWrapper.eq("level", 0);
|
||||
}
|
||||
queryWrapper.eq("level", 0)
|
||||
.eq("status", CommonConstant.Enable)
|
||||
.orderByAsc("level");
|
||||
|
||||
List<EsignPlatformInfo> esignPlatformInfos = list(queryWrapper);
|
||||
if (CollectionUtil.isEmpty(esignPlatformInfos)) {
|
||||
log.error("[获取平台和代理商信息] 未找到平台方记录");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取商户的二级代理
|
||||
EsignPlatformInfo agent2nd = getMch2ndAgent(mchId);
|
||||
if (agent2nd == null) {
|
||||
return esignPlatformInfos;
|
||||
}
|
||||
|
||||
esignPlatformInfos.add(agent2nd);
|
||||
|
||||
// 获取一级代理(如果存在)
|
||||
if (CheckUtil.isEmpty(agent2nd.getParent_id())) {
|
||||
return esignPlatformInfos;
|
||||
}
|
||||
|
||||
try {
|
||||
EsignPlatformInfo agent1st = get(agent2nd.getParent_id());
|
||||
if (agent1st != null) {
|
||||
esignPlatformInfos.add(agent1st);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[获取平台和代理商信息] 获取一级代理商时发生异常,parent_id: {}", agent2nd.getParent_id(), e);
|
||||
}
|
||||
|
||||
return esignPlatformInfos;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据分类和营业执照号获取平台方信息
|
||||
*
|
||||
@ -148,4 +178,98 @@ public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformI
|
||||
|
||||
return Pair.of(mobile, esignPlatformInfo.getLicense_number());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据入驻编号获取商户的二级代理
|
||||
*
|
||||
* @param mchId 商户入驻编号
|
||||
* @return EsignPlatformInfo 二级代理信息,未找到时返回null
|
||||
*/
|
||||
@Override
|
||||
public EsignPlatformInfo getMch2ndAgent(Long mchId) {
|
||||
// 参数校验
|
||||
if (CheckUtil.isEmpty(mchId)) {
|
||||
log.warn("[获取二级代理] 参数校验失败:商户入驻编号为空");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取商户入驻信息
|
||||
ShopMchEntry shopMchEntry = shopMchEntryService.shopMerchEntryById(mchId);
|
||||
if (shopMchEntry == null) {
|
||||
log.warn("[获取二级代理] 未找到商户入驻信息,mchId={}", mchId);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 检查是否有指定的分销商ID或区域信息
|
||||
if (CheckUtil.isEmpty(shopMchEntry.getDistributor_id()) && StrUtil.isBlank(shopMchEntry.getStore_district())) {
|
||||
log.debug("[获取二级代理] 商户未指定分销商且无区域信息,mchId={}", mchId);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 构建查询条件
|
||||
QueryWrapper<EsignPlatformInfo> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("level", CommonConstant.Agent_Level_2nd)
|
||||
.eq("status", CommonConstant.Enable)
|
||||
.orderByAsc("id");
|
||||
|
||||
// 优先使用指定的分销商ID查询,否则使用区域信息查询
|
||||
if (CheckUtil.isNotEmpty(shopMchEntry.getDistributor_id())) {
|
||||
queryWrapper.eq("id", shopMchEntry.getDistributor_id());
|
||||
log.debug("[获取二级代理] 使用指定分销商ID查询,distributorId={}", shopMchEntry.getDistributor_id());
|
||||
}
|
||||
|
||||
EsignPlatformInfo result = findOne(queryWrapper);
|
||||
if (result == null) {
|
||||
if (StrUtil.isNotBlank(shopMchEntry.getStore_district())) {
|
||||
// 运费代理商
|
||||
queryWrapper.clear();
|
||||
queryWrapper.eq("level", CommonConstant.Agent_Level_2nd)
|
||||
.eq("status", CommonConstant.Enable)
|
||||
.eq("license_district_id", shopMchEntry.getStore_district())
|
||||
.gt("shipping_fee", 0).ne("supplier_id", "")
|
||||
.orderByAsc("id");
|
||||
log.debug("[获取二级代理] 使用区域信息查询,districtId={}", shopMchEntry.getStore_district());
|
||||
|
||||
result = findOne(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
log.info("[获取二级代理] 未找到匹配的二级代理信息,mchId={}", mchId);
|
||||
} else {
|
||||
log.debug("[获取二级代理] 成功获取二级代理信息,mchId={}, agentId={}", mchId, result.getId());
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("[获取二级代理] 查询过程中发生异常,mchId={}", mchId, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据入驻编号获取商户的二级代理(收运费的代理商)
|
||||
*
|
||||
* @param mchId 商户入驻编号
|
||||
* @return EsignPlatformInfo 收运费的二级代理信息,未找到或不满足条件时返回null
|
||||
*/
|
||||
@Override
|
||||
public EsignPlatformInfo getMch2ndAgentWithShippingFee(Long mchId) {
|
||||
// 获取商户的二级代理信息
|
||||
EsignPlatformInfo esignPlatformInfo = getMch2ndAgent(mchId);
|
||||
if (esignPlatformInfo == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 检查该代理是否具备收取运费的条件:设置了运费且有供应商ID
|
||||
if (CheckUtil.isNotEmpty(esignPlatformInfo.getShipping_fee()) &&
|
||||
StrUtil.isNotBlank(esignPlatformInfo.getSupplier_id())) {
|
||||
return esignPlatformInfo;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -43,20 +43,19 @@ public interface LklLedgerReceiverService extends IBaseService<LklLedgerReceiver
|
||||
/**
|
||||
* 通过平台方(代理商)记录信息构建申请分账接收方的请求参数
|
||||
*
|
||||
* @param platformId
|
||||
* @param mchId
|
||||
* @return
|
||||
*/
|
||||
JSONArray buildApplyLedgerReceiverReqParams(Long platformId);
|
||||
JSONArray buildApplyLedgerReceiverReqParams(Long mchId);
|
||||
|
||||
/**
|
||||
* 内部调用:申请分账接收方
|
||||
*
|
||||
* @param mchId
|
||||
* @param merCupNo
|
||||
* @param platformId
|
||||
* @return
|
||||
*/
|
||||
Boolean innerApplyLedgerReceiver(Long mchId, String merCupNo, Long platformId);
|
||||
Boolean innerApplyLedgerReceiver(Long mchId, String merCupNo);
|
||||
|
||||
/**
|
||||
* 是否存在平台方的相关记录信息?
|
||||
|
||||
@ -34,12 +34,12 @@ import com.suisung.mall.common.pojo.dto.LklSeparateWithTotalAmountDTO;
|
||||
import com.suisung.mall.common.service.impl.CommonService;
|
||||
import com.suisung.mall.common.utils.*;
|
||||
import com.suisung.mall.core.web.service.RedisService;
|
||||
import com.suisung.mall.shop.esign.service.EsignPlatformInfoService;
|
||||
import com.suisung.mall.shop.lakala.service.*;
|
||||
import com.suisung.mall.shop.lakala.utils.LakalaUtil;
|
||||
import com.suisung.mall.shop.message.service.PushMessageService;
|
||||
import com.suisung.mall.shop.message.service.ShopMessageTemplateService;
|
||||
import com.suisung.mall.shop.order.service.ShopOrderBaseService;
|
||||
import com.suisung.mall.shop.order.service.ShopOrderInfoService;
|
||||
import com.suisung.mall.shop.order.service.ShopOrderLklService;
|
||||
import com.suisung.mall.shop.page.service.OssService;
|
||||
import com.suisung.mall.shop.store.service.ShopMchEntryService;
|
||||
@ -153,10 +153,14 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
@Lazy
|
||||
@Resource
|
||||
private ShopOrderBaseService shopOrderBaseService;
|
||||
//
|
||||
// @Lazy
|
||||
// @Resource
|
||||
// private ShopOrderInfoService shopOrderInfoService;
|
||||
|
||||
@Lazy
|
||||
@Resource
|
||||
private ShopOrderInfoService shopOrderInfoService;
|
||||
private EsignPlatformInfoService esignPlatformInfoService;
|
||||
|
||||
@Lazy
|
||||
@Resource
|
||||
@ -506,8 +510,8 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
ecParams.put("D11", signDate);
|
||||
ecParams.put("D12", signDate);
|
||||
|
||||
Boolean hasAgent = false; // 有无分账代理商?
|
||||
if (hasAgent) {
|
||||
// 如果入驻有代理商推荐码,代理商Id-distributor_id 会大于0(shop_mch_entry->distributor_id)
|
||||
if (esignPlatformInfoService.getMch2ndAgent(shopMchEntry.getId()) != null) {
|
||||
ecParams.put("E1", platformName + "和代理商");
|
||||
ecParams.put("E2", "《平台商户入驻服务框架协议》和《小发同城服务费结算》");
|
||||
} else {
|
||||
@ -1189,7 +1193,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
Long receiverCnt = lklLedgerReceiverService.countByCondition("", "", shopMchEntry.getDistributor_id());
|
||||
if (receiverCnt <= 0) {
|
||||
// 1:新增一个接收方记录,起码要一个平台方,代理商根据入驻信息新增
|
||||
Boolean success = lklLedgerReceiverService.innerApplyLedgerReceiver(shopMchEntry.getId(), merCupNo, shopMchEntry.getDistributor_id());
|
||||
Boolean success = lklLedgerReceiverService.innerApplyLedgerReceiver(shopMchEntry.getId(), merCupNo);
|
||||
if (!success) {
|
||||
return CommonResult.failed("申请分账接收方失败");
|
||||
}
|
||||
@ -2564,7 +2568,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
}
|
||||
return Pair.of(false, "订单可分账金额低于1分钱");
|
||||
}
|
||||
|
||||
|
||||
Integer merchantAmount = lklSeparateDTO.getMchAmount();
|
||||
Integer platformAmount = lklSeparateDTO.getPlatAmount();
|
||||
Integer agent1stAmount = lklSeparateDTO.getAgent1stAmount();
|
||||
|
||||
@ -32,7 +32,6 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@ -137,21 +136,19 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
|
||||
* 通过平台方(代理商) ID 记录信息转成 Lakala 接收方记录
|
||||
* 平台方一定要获取,如果有代理商也要获取
|
||||
*
|
||||
* @param distributorId 代理商id(非平台Id)
|
||||
* @param mchId 商户id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public JSONArray buildApplyLedgerReceiverReqParams(Long distributorId) {
|
||||
List<Long> ids = new ArrayList<>();
|
||||
if (distributorId != null && distributorId > 0) {
|
||||
ids.add(distributorId);
|
||||
}
|
||||
public JSONArray buildApplyLedgerReceiverReqParams(Long mchId) {
|
||||
|
||||
// 获取平台记录和代理商记录
|
||||
List<EsignPlatformInfo> esignPlatformInfoList = esignPlatformInfoService.getDistributorAndPlatformByIds(ids.toArray(new Long[0]));
|
||||
List<EsignPlatformInfo> esignPlatformInfoList = esignPlatformInfoService.getDistributorAndPlatformByIds(mchId);
|
||||
if (CollectionUtil.isEmpty(esignPlatformInfoList)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
JSONArray reqParams = new JSONArray();
|
||||
for (EsignPlatformInfo esignPlatformInfo : esignPlatformInfoList) {
|
||||
JSONObject reqParam = new JSONObject();
|
||||
@ -216,14 +213,14 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
|
||||
* 内部调用:申请一个或多个分账接收方(平台方和代理商)
|
||||
*
|
||||
* @param mchId
|
||||
* @param merCupNo 用于标记接收方绑定merCupNo商家
|
||||
* @param distributorId 代理商id(非平台id)
|
||||
* @param merCupNo 用于标记接收方绑定merCupNo商家
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean innerApplyLedgerReceiver(Long mchId, String merCupNo, Long distributorId) {
|
||||
public Boolean innerApplyLedgerReceiver(Long mchId, String merCupNo) {
|
||||
// 接收方至少有一个平台方
|
||||
JSONArray buildApplyLedgerReceiverReqParams = buildApplyLedgerReceiverReqParams(distributorId);
|
||||
JSONArray buildApplyLedgerReceiverReqParams = buildApplyLedgerReceiverReqParams(mchId);
|
||||
|
||||
if (buildApplyLedgerReceiverReqParams == null || buildApplyLedgerReceiverReqParams.isEmpty()) {
|
||||
log.error("先新增平台或代理商信息");
|
||||
return false;
|
||||
|
||||
@ -741,7 +741,7 @@ public class LklTkServiceImpl {
|
||||
}
|
||||
|
||||
// 2:新增一个接收方记录,起码要一个平台方,代理商根据入驻信息新增
|
||||
Boolean genSuccess = lklLedgerReceiverService.innerApplyLedgerReceiver(mchId, merCupNo, distributorId);
|
||||
Boolean genSuccess = lklLedgerReceiverService.innerApplyLedgerReceiver(mchId, merCupNo);
|
||||
if (!genSuccess) {
|
||||
logger.error("进件、申请分账业务成功已成功,等待拉卡拉审核分账业务请求,但创建分账接收方失败了,请管理员补偿流程");
|
||||
shopMchEntryService.updateMerchEntryApprovalByMchId(mchId, null,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user