代理商入驻

This commit is contained in:
Jack 2026-01-22 14:11:38 +08:00
parent 4e6927d2b9
commit 822b9a1aec
9 changed files with 640 additions and 193 deletions

View File

@ -26,10 +26,10 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@Api(tags = "E签宝电子签控制器") @Api(tags = "E签宝电子签后台控制器")
@RestController @RestController
@RequestMapping("/admin/shop/esign") @RequestMapping("/admin/shop/esign")
public class EsignController extends BaseControllerImpl { public class EsignAdminController extends BaseControllerImpl {
@Resource @Resource
private EsignContractFillingFileService esignContractFillingFileService; private EsignContractFillingFileService esignContractFillingFileService;

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2025. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
* Vestibulum commodo. Ut rhoncus gravida arcu.
*/
package com.suisung.mall.shop.esign.controller.mobile;
import cn.hutool.json.JSONObject;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.service.impl.BaseControllerImpl;
import com.suisung.mall.shop.esign.service.EsignContractFillingFileService;
import com.suisung.mall.shop.esign.service.EsignContractService;
import com.suisung.mall.shop.esign.service.EsignPlatformInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Api(tags = "E签宝电子签前台控制器")
@RestController
@RequestMapping("/mobile/shop/esign")
public class EsignController extends BaseControllerImpl {
@Resource
private EsignContractFillingFileService esignContractFillingFileService;
@Resource
private EsignContractService esignContractService;
@Resource
private EsignPlatformInfoService esignPlatformInfoService;
@ApiOperation(value = "区域(二级)代理商申请", notes = "区域(二级)代理商申请")
@RequestMapping(value = "/apply/agent", method = RequestMethod.POST)
public CommonResult signFlowCreateByFile(@RequestBody JSONObject paramsJSON) {
return esignContractService.signFlowCreateByFile(paramsJSON.getInt("store_id"));
}
@ApiOperation(value = "区域(三级)代理商详细信息", notes = "区域(三级)代理商详细信息")
@RequestMapping(value = "/agent/info", method = RequestMethod.POST)
public ResponseEntity<String> signAsyncNotify(HttpServletRequest request, HttpServletResponse response, @RequestBody String requestBody) {
return esignContractService.signAsyncNotify(request, response, requestBody);
}
}

View File

@ -8,6 +8,8 @@
package com.suisung.mall.shop.esign.service; package com.suisung.mall.shop.esign.service;
import cn.hutool.json.JSONObject;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.modules.esign.EsignPlatformInfo; import com.suisung.mall.common.modules.esign.EsignPlatformInfo;
import org.springframework.data.util.Pair; import org.springframework.data.util.Pair;
@ -18,6 +20,15 @@ import java.util.List;
*/ */
public interface EsignPlatformInfoService { public interface EsignPlatformInfoService {
/**
* 添加或更新平台方信息
*
* @param esignPlatformInfo
* @return
*/
Boolean addOrUpdateEsignPlatformInfo(EsignPlatformInfo esignPlatformInfo);
/** /**
* 根据ID获取代理商信息 * 根据ID获取代理商信息
* *
@ -43,6 +54,16 @@ public interface EsignPlatformInfoService {
*/ */
EsignPlatformInfo getEsignPlatformInfo(Integer level, String licenseNumber); EsignPlatformInfo getEsignPlatformInfo(Integer level, String licenseNumber);
/**
* 根据分类和营业执照号和法人身份证号获取平台方信息
*
* @param level 分类必选类型:0-平台方(只能一条记录)1-一级代理2-二级代理3-三级代理4-四级代理
* @param licenseNumber 营业执照号码必选
* @param legalPersonIdCard 法人身份证号必选
* @return
*/
EsignPlatformInfo getEsignPlatformInfo(Integer level, String licenseNumber, String legalPersonIdCard);
/** /**
* 是否存在平台方的相关记录信息 * 是否存在平台方的相关记录信息
* *
@ -81,4 +102,12 @@ public interface EsignPlatformInfoService {
* @return * @return
*/ */
String getSupplierIdByAgentId(Long agentId); String getSupplierIdByAgentId(Long agentId);
/**
* 申请二级代理商
*
* @param paramsJSON
* @return
*/
CommonResult apply2ndAgent(JSONObject paramsJSON);
} }

View File

@ -8,11 +8,14 @@
package com.suisung.mall.shop.esign.service.impl; package com.suisung.mall.shop.esign.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.constant.CommonConstant; import com.suisung.mall.common.constant.CommonConstant;
import com.suisung.mall.common.exception.ApiException;
import com.suisung.mall.common.modules.esign.EsignPlatformInfo; import com.suisung.mall.common.modules.esign.EsignPlatformInfo;
import com.suisung.mall.common.modules.store.ShopMchEntry; import com.suisung.mall.common.modules.store.ShopMchEntry;
import com.suisung.mall.common.utils.CheckUtil; import com.suisung.mall.common.utils.CheckUtil;
@ -20,6 +23,7 @@ import com.suisung.mall.common.utils.phone.PhoneNumberUtils;
import com.suisung.mall.core.web.service.impl.BaseServiceImpl; import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
import com.suisung.mall.shop.esign.mapper.EsignPlatformInfoMapper; import com.suisung.mall.shop.esign.mapper.EsignPlatformInfoMapper;
import com.suisung.mall.shop.esign.service.EsignPlatformInfoService; import com.suisung.mall.shop.esign.service.EsignPlatformInfoService;
import com.suisung.mall.shop.lakala.service.LklLedgerReceiverService;
import com.suisung.mall.shop.store.service.ShopMchEntryService; import com.suisung.mall.shop.store.service.ShopMchEntryService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
@ -28,6 +32,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -40,6 +45,71 @@ public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformI
@Resource @Resource
private ShopMchEntryService shopMchEntryService; private ShopMchEntryService shopMchEntryService;
@Lazy
@Resource
private LklLedgerReceiverService lklLedgerReceiverService;
/**
* 添加或更新平台方信息
*
* @param esignPlatformInfo 电子签章平台信息实体
* @return 操作结果成功返回true失败返回false
*/
@Override
public Boolean addOrUpdateEsignPlatformInfo(EsignPlatformInfo esignPlatformInfo) {
// 参数校验
if (esignPlatformInfo == null) {
log.warn("[添加或更新平台方信息] 缺少参数错误");
return false;
}
// 营业执照号+法人身份证号+代理商等级确定一条记录不能重复
if (StrUtil.isBlank(esignPlatformInfo.getLicense_number())
|| StrUtil.isBlank(esignPlatformInfo.getLegal_person_id_card())
|| CheckUtil.isEmpty(esignPlatformInfo.getLevel())) {
log.warn("[添加或更新平台方信息] 缺少必要参数:营业执照号或等级");
return false;
}
if (StrUtil.hasBlank(
esignPlatformInfo.getLicense_company(),
esignPlatformInfo.getLicense_number(),
esignPlatformInfo.getLicense_image(),
esignPlatformInfo.getLicense_area(),
esignPlatformInfo.getLicense_district_id(),
esignPlatformInfo.getLegal_person_name(),
esignPlatformInfo.getLegal_person_mobile(),
esignPlatformInfo.getLegal_person_id_card(),
esignPlatformInfo.getLegal_person_id_card_image1(),
esignPlatformInfo.getLegal_person_id_card_image2(),
esignPlatformInfo.getRec_acc_card_no(),
esignPlatformInfo.getRec_acc_name(),
esignPlatformInfo.getRec_acc_cert_no(),
esignPlatformInfo.getRec_acc_bank_name(),
esignPlatformInfo.getRec_acc_bank_no())) {
log.warn("[添加或更新平台方信息] 缺少关键参数:手机号或营业执照公司或法人身份证或收款账户卡号或收款账户开户行号");
return false;
}
// 根据等级和营业执照号查询现有记录
EsignPlatformInfo existingRecord = getEsignPlatformInfo(esignPlatformInfo.getLevel(), esignPlatformInfo.getLicense_number());
if (existingRecord == null) {
// 记录不存在执行新增操作
log.debug("[添加平台方信息] 新增平台方信息,等级: {}, 营业执照号: {}",
esignPlatformInfo.getLevel(), esignPlatformInfo.getLicense_number());
return save(esignPlatformInfo);
} else {
// 记录存在更新现有记录ID并执行更新操作
esignPlatformInfo.setId(existingRecord.getId());
log.debug("[更新平台方信息] 更新平台方信息ID: {}, 等级: {}, 营业执照号: {}",
existingRecord.getId(), esignPlatformInfo.getLevel(), esignPlatformInfo.getLicense_number());
return updateById(esignPlatformInfo);
}
}
/** /**
* 根据ID获取代理商信息 * 根据ID获取代理商信息
* *
@ -52,17 +122,14 @@ public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformI
return null; return null;
} }
QueryWrapper<EsignPlatformInfo> queryWrapper = new QueryWrapper<>(); return getOne(
queryWrapper.eq("id", id) new LambdaQueryWrapper<EsignPlatformInfo>()
.gt("level", 0) .eq(EsignPlatformInfo::getId, id)
.eq("status", CommonConstant.Enable).orderByAsc("level"); .gt(EsignPlatformInfo::getLevel, 0)
.eq(EsignPlatformInfo::getStatus, CommonConstant.Enable)
List<EsignPlatformInfo> esignPlatformInfos = list(queryWrapper); .orderByAsc(EsignPlatformInfo::getLevel),
if (CollectionUtil.isEmpty(esignPlatformInfos)) { false
return null; );
}
return esignPlatformInfos.get(0);
} }
/** /**
@ -79,12 +146,14 @@ public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformI
log.debug("[获取平台和代理商信息] 开始查询平台方和代理商信息商户ID: {}", mchId); log.debug("[获取平台和代理商信息] 开始查询平台方和代理商信息商户ID: {}", mchId);
// 获取平台方记录 // 获取平台方记录
QueryWrapper<EsignPlatformInfo> queryWrapper = new QueryWrapper<>(); EsignPlatformInfo esignPlatformInfo = getOne(
queryWrapper.eq("level", 0) new LambdaQueryWrapper<EsignPlatformInfo>()
.eq("status", CommonConstant.Enable) .eq(EsignPlatformInfo::getLevel, 0)
.orderByAsc("id"); .eq(EsignPlatformInfo::getStatus, CommonConstant.Enable)
.orderByAsc(EsignPlatformInfo::getId),
false
);
EsignPlatformInfo esignPlatformInfo = getOne(queryWrapper, false);
if (ObjectUtil.isEmpty(esignPlatformInfo)) { if (ObjectUtil.isEmpty(esignPlatformInfo)) {
log.error("[获取平台和代理商信息] 未找到有效的平台方记录"); log.error("[获取平台和代理商信息] 未找到有效的平台方记录");
return Collections.emptyList(); return Collections.emptyList();
@ -110,12 +179,15 @@ public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformI
} }
// 获取县级代理商的省级代理商 // 获取县级代理商的省级代理商
queryWrapper.clear(); EsignPlatformInfo agent1st = getOne(
queryWrapper.eq("id", agent2nd.getParent_id()) new LambdaQueryWrapper<EsignPlatformInfo>()
.eq("level", CommonConstant.Agent_Level_1st) .eq(EsignPlatformInfo::getId, agent2nd.getParent_id())
.gt("split_ratio", 0) .eq(EsignPlatformInfo::getLevel, CommonConstant.Agent_Level_1st)
.eq("status", CommonConstant.Enable); .gt(EsignPlatformInfo::getSplit_ratio, 0)
EsignPlatformInfo agent1st = getOne(queryWrapper, false); .eq(EsignPlatformInfo::getStatus, CommonConstant.Enable),
false
);
if (agent1st != null) { if (agent1st != null) {
esignPlatformInfos.add(agent1st); esignPlatformInfos.add(agent1st);
log.debug("[获取平台和代理商信息] 成功获取一级代理信息ID: {}", agent1st.getId()); log.debug("[获取平台和代理商信息] 成功获取一级代理信息ID: {}", agent1st.getId());
@ -137,21 +209,34 @@ public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformI
*/ */
@Override @Override
public EsignPlatformInfo getEsignPlatformInfo(Integer level, String licenseNumber) { public EsignPlatformInfo getEsignPlatformInfo(Integer level, String licenseNumber) {
QueryWrapper<EsignPlatformInfo> queryWrapper = new QueryWrapper<>(); LambdaQueryWrapper<EsignPlatformInfo> queryWrapper =
queryWrapper.eq("status", CommonConstant.Enable); new LambdaQueryWrapper<>();
queryWrapper.eq(EsignPlatformInfo::getStatus, CommonConstant.Enable);
if (!ObjectUtils.isEmpty(level)) { if (!ObjectUtils.isEmpty(level)) {
queryWrapper.eq("level", level); queryWrapper.eq(EsignPlatformInfo::getLevel, level);
} else { } else {
queryWrapper.eq("level", 0); queryWrapper.eq(EsignPlatformInfo::getLevel, 0);
} }
if (StrUtil.isNotBlank(licenseNumber)) { if (StrUtil.isNotBlank(licenseNumber)) {
queryWrapper.eq("license_number", licenseNumber); queryWrapper.eq(EsignPlatformInfo::getLicense_number, licenseNumber);
} }
return getOne(queryWrapper, false); return getOne(queryWrapper, false);
} }
@Override
public EsignPlatformInfo getEsignPlatformInfo(Integer level, String licenseNumber, String legalPersonIdCard) {
LambdaQueryWrapper<EsignPlatformInfo> queryWrapper =
new LambdaQueryWrapper<>();
queryWrapper
.eq(EsignPlatformInfo::getLevel, level)
.eq(EsignPlatformInfo::getLicense_number, licenseNumber)
.eq(EsignPlatformInfo::getLegal_person_id_card, legalPersonIdCard);
return getOne(queryWrapper, false);
}
/** /**
* 是否存在平台方的相关记录信息 * 是否存在平台方的相关记录信息
* *
@ -159,15 +244,12 @@ public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformI
*/ */
@Override @Override
public EsignPlatformInfo hasPlatformMch() { public EsignPlatformInfo hasPlatformMch() {
QueryWrapper<EsignPlatformInfo> queryWrapper = new QueryWrapper<>(); return getOne(
queryWrapper.eq("level", 0).eq("status", CommonConstant.Enable); new LambdaQueryWrapper<EsignPlatformInfo>()
.eq(EsignPlatformInfo::getLevel, 0)
EsignPlatformInfo esignPlatformInfo = getOne(queryWrapper); .eq(EsignPlatformInfo::getStatus, CommonConstant.Enable),
if (ObjectUtils.isEmpty(esignPlatformInfo)) { false
return null; );
}
return esignPlatformInfo;
} }
/** /**
@ -180,12 +262,18 @@ public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformI
log.debug("[获取平台方信息] 开始获取平台方手机号和营业执照号"); log.debug("[获取平台方信息] 开始获取平台方手机号和营业执照号");
try { try {
QueryWrapper<EsignPlatformInfo> queryWrapper = new QueryWrapper<>(); EsignPlatformInfo esignPlatformInfo = getOne(
queryWrapper.eq("level", 0) new LambdaQueryWrapper<EsignPlatformInfo>()
.eq("status", CommonConstant.Enable) .eq(EsignPlatformInfo::getLevel, 0)
.select("telephone", "license_number", "legal_person_mobile"); .eq(EsignPlatformInfo::getStatus, CommonConstant.Enable)
.select(
EsignPlatformInfo::getTelephone,
EsignPlatformInfo::getLicense_number,
EsignPlatformInfo::getLegal_person_mobile
),
false
);
EsignPlatformInfo esignPlatformInfo = getOne(queryWrapper, false);
if (esignPlatformInfo == null) { if (esignPlatformInfo == null) {
log.warn("[获取平台方信息] 未找到有效的平台方记录"); log.warn("[获取平台方信息] 未找到有效的平台方记录");
return null; return null;
@ -243,31 +331,38 @@ public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformI
} }
// 构建查询条件 // 构建查询条件
QueryWrapper<EsignPlatformInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("level", CommonConstant.Agent_Level_2nd)
.eq("status", CommonConstant.Enable)
.orderByAsc("id");
EsignPlatformInfo result = null; EsignPlatformInfo result = null;
// 优先使用指定的分销商ID查询否则使用区域信息查询 // 优先使用指定的分销商ID查询
if (shopMchEntry.getDistributor_id() != null && shopMchEntry.getDistributor_id() > 0) { if (shopMchEntry.getDistributor_id() != null && shopMchEntry.getDistributor_id() > 0) {
queryWrapper.eq("id", shopMchEntry.getDistributor_id()); result = getOne(
result = getOne(queryWrapper, false); new LambdaQueryWrapper<EsignPlatformInfo>()
.eq(EsignPlatformInfo::getId, shopMchEntry.getDistributor_id())
.eq(EsignPlatformInfo::getLevel, CommonConstant.Agent_Level_2nd)
.eq(EsignPlatformInfo::getStatus, CommonConstant.Enable)
.orderByAsc(EsignPlatformInfo::getId),
false
);
log.debug("[获取二级代理] 使用指定分销商ID查询distributorId={}", shopMchEntry.getDistributor_id()); log.debug("[获取二级代理] 使用指定分销商ID查询distributorId={}", shopMchEntry.getDistributor_id());
} }
// 如果通过分销商ID未找到使用区域信息查询
if (result == null && StrUtil.isNotBlank(shopMchEntry.getStore_district())) { if (result == null && StrUtil.isNotBlank(shopMchEntry.getStore_district())) {
// 和商户同地区并且二级代理商有配送相关资质 // 和商户同地区并且二级代理商有配送相关资质
queryWrapper.eq("license_district_id", shopMchEntry.getStore_district()) result = getOne(
.gt("shipping_fee", 0).ne("supplier_id", "") new LambdaQueryWrapper<EsignPlatformInfo>()
.orderByAsc("id"); .eq(EsignPlatformInfo::getLevel, CommonConstant.Agent_Level_2nd)
result = getOne(queryWrapper, false); .eq(EsignPlatformInfo::getStatus, CommonConstant.Enable)
.eq(EsignPlatformInfo::getLicense_district_id, shopMchEntry.getStore_district())
.gt(EsignPlatformInfo::getShipping_fee, 0)
.isNotNull(EsignPlatformInfo::getSupplier_id)
.ne(EsignPlatformInfo::getSupplier_id, "")
.orderByAsc(EsignPlatformInfo::getId),
false
);
log.debug("[获取二级代理] 使用区域信息查询districtId={}", shopMchEntry.getStore_district()); log.debug("[获取二级代理] 使用区域信息查询districtId={}", shopMchEntry.getStore_district());
} }
if (result == null) { if (result == null) {
@ -284,6 +379,7 @@ public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformI
} }
} }
/** /**
* 根据入驻编号获取商户的二级代理(收运费的代理商) * 根据入驻编号获取商户的二级代理(收运费的代理商)
* *
@ -324,15 +420,15 @@ public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformI
try { try {
log.debug("[获取供应商ID] 开始查询供应商信息agentId={}", agentId); log.debug("[获取供应商ID] 开始查询供应商信息agentId={}", agentId);
// 构建查询条件
QueryWrapper<EsignPlatformInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", agentId)
.eq("level", CommonConstant.Agent_Level_2nd)
.eq("status", CommonConstant.Enable)
.select("supplier_id");
// 查询记录 // 查询记录
EsignPlatformInfo result = getOne(queryWrapper); EsignPlatformInfo result = getOne(
new LambdaQueryWrapper<EsignPlatformInfo>()
.eq(EsignPlatformInfo::getId, agentId)
.eq(EsignPlatformInfo::getLevel, CommonConstant.Agent_Level_2nd)
.eq(EsignPlatformInfo::getStatus, CommonConstant.Enable)
.select(EsignPlatformInfo::getSupplier_id),
false
);
// 检查结果并返回 // 检查结果并返回
if (result != null && StrUtil.isNotBlank(result.getSupplier_id())) { if (result != null && StrUtil.isNotBlank(result.getSupplier_id())) {
@ -349,4 +445,160 @@ public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformI
} }
public CommonResult apply2ndAgent(JSONObject paramsJSON) {
log.debug("[申请二级代理商] 开始处理申请params={}", paramsJSON);
if (paramsJSON == null) {
return CommonResult.failed("缺少必要参数错误");
}
EsignPlatformInfo record = JSONUtil.toBean(paramsJSON, EsignPlatformInfo.class);
if (record == null) {
return CommonResult.failed("参数格式有误");
}
// 校验 EsignPlatformInfo 必要关键参数
if (StrUtil.hasBlank(
record.getLicense_company(),
record.getLicense_number(),
record.getLicense_image(),
record.getLicense_area(),
record.getLicense_district_id(),
record.getLegal_person_name(),
record.getLegal_person_mobile(),
record.getLegal_person_id_card(),
record.getLegal_person_id_card_image1(),
record.getLegal_person_id_card_image2(),
record.getRec_acc_card_no(),
record.getRec_acc_name(),
record.getRec_acc_cert_no(),
record.getRec_acc_bank_name(),
record.getRec_acc_bank_no())) {
return CommonResult.failed("缺少必要参数");
}
// 清算行号和银行账号一致
record.setRec_acc_clear_bank_no(record.getRec_acc_bank_no());
record.setRec_acc_type(2); // 款账户账户类型:1-个人对私2-企业对公
// 邀请码要自动生成
record.setInvite_code("6543");
// 接口只接收二级代理商
record.setLevel(CommonConstant.Agent_Level_2nd);
if (StrUtil.isBlank(record.getEmail())) {
record.setEmail(record.getTelephone() + "@qq.com");
}
// 默认一级代理商ID为0
if (CheckUtil.isEmpty(record.getParent_id())) {
record.setParent_id(0L);
}
// 内部配送费
if (CheckUtil.isEmpty(record.getShipping_fee())) {
record.setShipping_fee(400);
}
// 默认分账比例1%
if (CheckUtil.isEmpty(record.getSplit_ratio())) {
record.setSplit_ratio(BigDecimal.valueOf(0.01));
}
// 如果 esign_platform_info 记录不存在新增esign_platform_info 记录
Boolean result = addOrUpdateEsignPlatformInfo(record);
if (!result) {
throw new ApiException("保存代理商信息失败");
}
log.info("[申请二级代理商] 申请成功代理商ID: {}, 公司名: {}", record.getId(), record.getLicense_company());
return CommonResult.success();
}
/**
* 审批二级代理商
*
* @param paramsJSON 申请参数JSON
* @return CommonResult 操作结果
*/
public CommonResult approval2ndAgent(JSONObject paramsJSON) {
log.debug("[申请二级代理商] 开始处理申请params={}", paramsJSON);
if (paramsJSON == null) {
return CommonResult.failed("缺少必要参数错误");
}
EsignPlatformInfo record = JSONUtil.toBean(paramsJSON, EsignPlatformInfo.class);
if (record == null) {
return CommonResult.failed("参数格式有误");
}
// 校验 EsignPlatformInfo 必要关键参数
if (StrUtil.hasBlank(
record.getLicense_company(),
record.getLicense_number(),
record.getLicense_image(),
record.getLicense_area(),
record.getLicense_district_id(),
record.getLegal_person_name(),
record.getLegal_person_mobile(),
record.getLegal_person_id_card(),
record.getLegal_person_id_card_image1(),
record.getLegal_person_id_card_image2(),
record.getRec_acc_card_no(),
record.getRec_acc_name(),
record.getRec_acc_cert_no(),
record.getRec_acc_bank_name(),
record.getRec_acc_bank_no())) {
return CommonResult.failed("缺少必要参数");
}
// 清算行号和银行账号一致
record.setRec_acc_clear_bank_no(record.getRec_acc_bank_no());
record.setRec_acc_type(2); // 款账户账户类型:1-个人对私2-企业对公
// 邀请码要自动生成
record.setInvite_code("6543");
// 接口只接收二级代理商
record.setLevel(CommonConstant.Agent_Level_2nd);
if (StrUtil.isBlank(record.getEmail())) {
record.setEmail(record.getTelephone() + "@qq.com");
}
// 默认一级代理商ID为0
if (CheckUtil.isEmpty(record.getParent_id())) {
record.setParent_id(0L);
}
// 内部配送费
if (CheckUtil.isEmpty(record.getShipping_fee())) {
record.setShipping_fee(400);
}
// 默认分账比例1%
if (CheckUtil.isEmpty(record.getSplit_ratio())) {
record.setSplit_ratio(BigDecimal.valueOf(0.01));
}
// 先向拉卡拉申请分账接收方
// 这里需要调用拉卡拉相关的服务
// 向拉卡拉提交分账接收方申请成功后添加接收方记录
Pair<Boolean, String> applyResult = lklLedgerReceiverService.innerApplyLedgerReceiver(record);
if (!applyResult.getFirst()) {
throw new ApiException("代理商提交第三方失败:" + applyResult.getSecond());
}
// 如果 esign_platform_info 记录不存在新增esign_platform_info 记录
Boolean result = addOrUpdateEsignPlatformInfo(record);
if (!result) {
throw new ApiException("保存代理商信息失败");
}
log.info("[申请二级代理商] 申请成功代理商ID: {}, 公司名: {}", record.getId(), record.getLicense_company());
return CommonResult.success();
}
} }

View File

@ -9,8 +9,11 @@
package com.suisung.mall.shop.lakala.service; package com.suisung.mall.shop.lakala.service;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.suisung.mall.common.modules.esign.EsignPlatformInfo;
import com.suisung.mall.common.modules.lakala.LklLedgerReceiver; import com.suisung.mall.common.modules.lakala.LklLedgerReceiver;
import com.suisung.mall.core.web.service.IBaseService; import com.suisung.mall.core.web.service.IBaseService;
import org.springframework.data.util.Pair;
import java.util.List; import java.util.List;
@ -48,14 +51,29 @@ public interface LklLedgerReceiverService extends IBaseService<LklLedgerReceiver
*/ */
JSONArray buildApplyLedgerReceiverReqParams(Long mchId); JSONArray buildApplyLedgerReceiverReqParams(Long mchId);
/**
* 通过平台方代理商记录信息构建申请分账接收方的请求参数
*
* @param esignPlatformInfo
* @return
*/
JSONObject buildApplyLedgerReceiverReqParams(EsignPlatformInfo esignPlatformInfo);
/** /**
* 内部调用申请分账接收方 * 内部调用申请分账接收方
* *
* @param mchId * @param mchId
* @param merCupNo
* @return * @return
*/ */
Boolean innerApplyLedgerReceiver(Long mchId, String merCupNo); Boolean innerApplyLedgerReceiver(Long mchId);
/**
* 内部调用申请一个或多个分账接收方平台方和代理商
*
* @param esignPlatformInfo
* @return
*/
Pair<Boolean, String> innerApplyLedgerReceiver(EsignPlatformInfo esignPlatformInfo);
/** /**
* 是否存在平台方的相关记录信息 * 是否存在平台方的相关记录信息

View File

@ -1270,7 +1270,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
Long receiverCnt = lklLedgerReceiverService.countByCondition("", "", shopMchEntry.getDistributor_id()); Long receiverCnt = lklLedgerReceiverService.countByCondition("", "", shopMchEntry.getDistributor_id());
if (receiverCnt <= 0) { if (receiverCnt <= 0) {
// 1新增一个接收方记录起码要一个平台方代理商根据入驻信息新增 // 1新增一个接收方记录起码要一个平台方代理商根据入驻信息新增
Boolean success = lklLedgerReceiverService.innerApplyLedgerReceiver(shopMchEntry.getId(), merCupNo); Boolean success = lklLedgerReceiverService.innerApplyLedgerReceiver(shopMchEntry.getId());
if (!success) { if (!success) {
return CommonResult.failed("申请分账接收方失败"); return CommonResult.failed("申请分账接收方失败");
} }
@ -1518,6 +1518,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
String errorMsg = lakalaRespJSON != null String errorMsg = lakalaRespJSON != null
? lakalaRespJSON.getStr("retMsg", "未知错误") ? lakalaRespJSON.getStr("retMsg", "未知错误")
: "响应解析失败"; : "响应解析失败";
shopMchEntryService.updateMerchEntryApprovalByMchId( shopMchEntryService.updateMerchEntryApprovalByMchId(
mchId, CommonConstant.MCH_APPR_STA_NOPASS, "创建分账接收方失败:" + lakalaRespJSON.getStr("retMsg") mchId, CommonConstant.MCH_APPR_STA_NOPASS, "创建分账接收方失败:" + lakalaRespJSON.getStr("retMsg")
); );
@ -1543,6 +1544,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
// 更新商户分账状态 // 更新商户分账状态
shopMchEntryService.updateMulStatus(mchId, "", 0, 0, 0, 0, 1, 0, CommonConstant.MCH_APPR_STA_LKL_PADDING); shopMchEntryService.updateMulStatus(mchId, "", 0, 0, 0, 0, 1, 0, CommonConstant.MCH_APPR_STA_LKL_PADDING);
return CommonResult.success(receiver, "创建接收方成功!"); return CommonResult.success(receiver, "创建接收方成功!");
} catch (Exception e) { } catch (Exception e) {

View File

@ -13,7 +13,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.suisung.mall.common.api.CommonResult; import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.api.ResultCode; import com.suisung.mall.common.api.ResultCode;
import com.suisung.mall.common.constant.CommonConstant; import com.suisung.mall.common.constant.CommonConstant;
@ -30,6 +30,7 @@ import com.suisung.mall.shop.store.service.ShopMchEntryService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -48,6 +49,7 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
@Resource @Resource
private LakalaApiService lakalaApiService; private LakalaApiService lakalaApiService;
@Lazy
@Autowired @Autowired
private ShopMchEntryService shopMchEntryService; private ShopMchEntryService shopMchEntryService;
@ -63,18 +65,19 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
return false; return false;
} }
QueryWrapper<LklLedgerReceiver> queryWrapper = new QueryWrapper<>(); LambdaQueryWrapper<LklLedgerReceiver> queryWrapper =
new LambdaQueryWrapper<>();
if (StrUtil.isNotBlank(record.getLicense_no())) { if (StrUtil.isNotBlank(record.getLicense_no())) {
queryWrapper.eq("license_no", record.getLicense_no()); queryWrapper.eq(LklLedgerReceiver::getLicense_no, record.getLicense_no());
} }
if (StrUtil.isNotBlank(record.getContact_mobile())) { if (StrUtil.isNotBlank(record.getContact_mobile())) {
queryWrapper.eq("contact_mobile", record.getContact_mobile()); queryWrapper.eq(LklLedgerReceiver::getContact_mobile, record.getContact_mobile());
} }
Long platformId = record.getPlatform_id(); Long platformId = record.getPlatform_id();
if (ObjectUtil.isEmpty(platformId)) { if (ObjectUtil.isEmpty(platformId)) {
platformId = 0L; platformId = 0L;
} }
queryWrapper.eq("platform_id", platformId).eq("status", CommonConstant.Enable); queryWrapper.eq(LklLedgerReceiver::getPlatform_id, platformId).eq(LklLedgerReceiver::getStatus, CommonConstant.Enable);
LklLedgerReceiver existsRecord = getOne(queryWrapper, false); LklLedgerReceiver existsRecord = getOne(queryWrapper, false);
if (ObjectUtil.isNotEmpty(existsRecord)) { if (ObjectUtil.isNotEmpty(existsRecord)) {
@ -99,11 +102,13 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
return null; return null;
} }
QueryWrapper<LklLedgerReceiver> queryWrapper = new QueryWrapper<>(); return getOne(
queryWrapper.eq("receiver_no", receiverNo).eq("status", CommonConstant.Enable); new LambdaQueryWrapper<LklLedgerReceiver>()
queryWrapper.orderByAsc("id"); .eq(LklLedgerReceiver::getReceiver_no, receiverNo)
.eq(LklLedgerReceiver::getStatus, CommonConstant.Enable)
return getOne(queryWrapper); .orderByAsc(LklLedgerReceiver::getId),
false
);
} }
/** /**
@ -118,10 +123,13 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
return null; return null;
} }
QueryWrapper<LklLedgerReceiver> queryWrapper = new QueryWrapper<>(); List<LklLedgerReceiver> lklLedgerReceivers = list(
queryWrapper.eq("platform_id", platformId).eq("status", CommonConstant.Enable).orderByAsc("id"); new LambdaQueryWrapper<LklLedgerReceiver>()
.eq(LklLedgerReceiver::getPlatform_id, platformId)
.eq(LklLedgerReceiver::getStatus, CommonConstant.Enable)
.orderByAsc(LklLedgerReceiver::getId)
);
List<LklLedgerReceiver> lklLedgerReceivers = list(queryWrapper);
if (CollectionUtil.isEmpty(lklLedgerReceivers)) { if (CollectionUtil.isEmpty(lklLedgerReceivers)) {
return null; return null;
} }
@ -138,7 +146,6 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
*/ */
@Override @Override
public JSONArray buildApplyLedgerReceiverReqParams(Long mchId) { public JSONArray buildApplyLedgerReceiverReqParams(Long mchId) {
// 获取平台记录和代理商记录 // 获取平台记录和代理商记录
List<EsignPlatformInfo> esignPlatformInfoList = esignPlatformInfoService.selectAgentAndPlatformByMchId(mchId); List<EsignPlatformInfo> esignPlatformInfoList = esignPlatformInfoService.selectAgentAndPlatformByMchId(mchId);
if (CollectionUtil.isEmpty(esignPlatformInfoList)) { if (CollectionUtil.isEmpty(esignPlatformInfoList)) {
@ -147,78 +154,116 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
JSONArray reqParams = new JSONArray(); JSONArray reqParams = new JSONArray();
for (EsignPlatformInfo esignPlatformInfo : esignPlatformInfoList) { for (EsignPlatformInfo esignPlatformInfo : esignPlatformInfoList) {
JSONObject reqParam = new JSONObject(); JSONObject reqParam = buildApplyLedgerReceiverReqParams(esignPlatformInfo);
if (reqParam != null) {
reqParam.put("receiverName", esignPlatformInfo.getLicense_company()); reqParams.add(reqParam);
reqParam.put("contactMobile", esignPlatformInfo.getLegal_person_mobile());
Long tempPlatformId = esignPlatformInfo.getId();
if (esignPlatformInfo.getLevel().equals(0)) {// 是平台的记录id 设置为0
tempPlatformId = 0L;
} }
reqParam.put("platformId", tempPlatformId);
reqParam.put("licenseNo", esignPlatformInfo.getLicense_number());
reqParam.put("licenseName", esignPlatformInfo.getLicense_company());
reqParam.put("legalPersonName", esignPlatformInfo.getLegal_person_name());
reqParam.put("legalPersonCertificateType", "17");
reqParam.put("legalPersonCertificateNo", esignPlatformInfo.getLegal_person_id_card());
reqParam.put("level", esignPlatformInfo.getLevel());
reqParam.put("splitRatio", esignPlatformInfo.getSplit_ratio());
reqParam.put("shippingFee", esignPlatformInfo.getShipping_fee());
reqParam.put("parentId", CheckUtil.isEmpty(esignPlatformInfo.getParent_id()) ? 0L : esignPlatformInfo.getParent_id());
reqParam.put("acctNo", esignPlatformInfo.getRec_acc_card_no());
reqParam.put("acctName", esignPlatformInfo.getRec_acc_bank_name());
reqParam.put("acctTypeCode", "57");
reqParam.put("acctCertificateType", "17");
reqParam.put("acctCertificateNo", esignPlatformInfo.getLegal_person_id_card());
reqParam.put("acctOpenBankCode", esignPlatformInfo.getRec_acc_bank_no());
reqParam.put("acctOpenBankName", esignPlatformInfo.getRec_acc_bank_name());
reqParam.put("acctClearBankCode", esignPlatformInfo.getRec_acc_clear_bank_no());
//文件类型参考https://o.lakala.com/#/home/document/detail?id=90
JSONArray attachList = new JSONArray();
if (StrUtil.isNotBlank(esignPlatformInfo.getLicense_image())) {
JSONObject BUSINESS_LICENCE = new JSONObject();
BUSINESS_LICENCE.put("attachType", "BUSINESS_LICENCE").put("attachName", "营业执照")
.put("attachStoreFile", esignPlatformInfo.getLicense_image());
attachList.add(BUSINESS_LICENCE);
}
if (StrUtil.isNotBlank(esignPlatformInfo.getLegal_person_id_card_image1())) {
JSONObject FR_ID_CARD_FRONT = new JSONObject();
FR_ID_CARD_FRONT.put("attachType", "FR_ID_CARD_FRONT").put("attachName", "法人身份证正面")
.put("attachStoreFile", esignPlatformInfo.getLegal_person_id_card_image1());
attachList.add(FR_ID_CARD_FRONT);
}
if (StrUtil.isNotBlank(esignPlatformInfo.getLegal_person_id_card_image2())) {
JSONObject FR_ID_CARD_BEHIND = new JSONObject();
FR_ID_CARD_BEHIND.put("attachType", "FR_ID_CARD_BEHIND").put("attachName", "法人身份证反面")
.put("attachStoreFile", esignPlatformInfo.getLegal_person_id_card_image2());
attachList.add(FR_ID_CARD_BEHIND);
}
if (CollectionUtil.isNotEmpty(attachList)) {
reqParam.put("attachList", attachList);
}
reqParams.add(reqParam);
} }
return reqParams; return reqParams;
} }
/** /**
* 内部调用申请一个或多个分账接收方平台方和代理商 * 通过平台方代理商 ID 记录信息转成 Lakala 接收方记录
* 平台方一定要获取如果有代理商也要获取
* *
* @param mchId * @param esignPlatformInfo 平台代理商实例
* @param merCupNo 用于标记接收方绑定merCupNo商家
* @return * @return
*/ */
@Override @Override
public Boolean innerApplyLedgerReceiver(Long mchId, String merCupNo) { public JSONObject buildApplyLedgerReceiverReqParams(EsignPlatformInfo esignPlatformInfo) {
if (ObjectUtil.isEmpty(esignPlatformInfo)) {
return null;
}
JSONObject reqParam = new JSONObject();
// 平台的记录platformId 设置为0代理商使用其ID
Long tempPlatformId = (CheckUtil.isEmpty(esignPlatformInfo.getLevel()) || esignPlatformInfo.getLevel().equals(0))
? 0L : esignPlatformInfo.getId();
reqParam.set("platformId", tempPlatformId);
reqParam.set("licenseNo", esignPlatformInfo.getLicense_number());
reqParam.set("licenseName", esignPlatformInfo.getLicense_company());
reqParam.set("receiverName", esignPlatformInfo.getLicense_company());
reqParam.set("legalPersonName", esignPlatformInfo.getLegal_person_name());
// legalPersonCertificateType 法人证件类型: 17 身份证18 护照19 港澳居民来往内地通行证 20 台湾居民来往内地通行证
reqParam.set("legalPersonCertificateType", "17");
reqParam.set("legalPersonCertificateNo", esignPlatformInfo.getLegal_person_id_card()); // 法人身份证号
reqParam.set("contactMobile", esignPlatformInfo.getLegal_person_mobile());
reqParam.set("level", esignPlatformInfo.getLevel());
reqParam.set("splitRatio", esignPlatformInfo.getSplit_ratio());
reqParam.set("shippingFee", esignPlatformInfo.getShipping_fee());
reqParam.set("parentId", CheckUtil.isEmpty(esignPlatformInfo.getParent_id()) ? 0L : esignPlatformInfo.getParent_id());
// 银行账户信息
reqParam.set("acctNo", esignPlatformInfo.getRec_acc_card_no());
reqParam.set("acctName", esignPlatformInfo.getRec_acc_bank_name());
reqParam.set("acctTypeCode", "57"); // 收款账户账户类型: 57对公 58对私
// acctCertificateType 收款账户证件类型 17 身份证18 护照19 港澳居民来往内地通行证 20 台湾居民来往内地通行证
reqParam.set("acctCertificateType", "17");
reqParam.set("acctCertificateNo", esignPlatformInfo.getLegal_person_id_card());
reqParam.set("acctOpenBankCode", esignPlatformInfo.getRec_acc_bank_no());
reqParam.set("acctOpenBankName", esignPlatformInfo.getRec_acc_bank_name());
// 清算行号处理如果没有单独设置清算行号或与开户行号不同则使用开户行号
String acctClearBankCode = esignPlatformInfo.getRec_acc_clear_bank_no();
if (StrUtil.isBlank(acctClearBankCode) || !esignPlatformInfo.getRec_acc_bank_no().equals(acctClearBankCode)) {
acctClearBankCode = esignPlatformInfo.getRec_acc_bank_no();
}
reqParam.set("acctClearBankCode", acctClearBankCode);
reqParam.set("settleType", "03"); // 提款类型01主动提款 03交易自动结算 不填默认01
// 文件类型参考https://o.lakala.com/#/home/document/detail?id=90
JSONArray attachList = new JSONArray();
// 添加营业执照附件
if (StrUtil.isNotBlank(esignPlatformInfo.getLicense_image())) {
JSONObject businessLicense = new JSONObject();
businessLicense.set("attachType", "BUSINESS_LICENCE")
.set("attachName", "营业执照")
.set("attachStoreFile", esignPlatformInfo.getLicense_image());
attachList.add(businessLicense);
}
// 添加法人身份证正面附件
if (StrUtil.isNotBlank(esignPlatformInfo.getLegal_person_id_card_image1())) {
JSONObject idCardFront = new JSONObject();
idCardFront.set("attachType", "FR_ID_CARD_FRONT")
.set("attachName", "法人身份证正面")
.set("attachStoreFile", esignPlatformInfo.getLegal_person_id_card_image1());
attachList.add(idCardFront);
}
// 添加法人身份证反面附件
if (StrUtil.isNotBlank(esignPlatformInfo.getLegal_person_id_card_image2())) {
JSONObject idCardBehind = new JSONObject();
idCardBehind.set("attachType", "FR_ID_CARD_BEHIND")
.set("attachName", "法人身份证反面")
.set("attachStoreFile", esignPlatformInfo.getLegal_person_id_card_image2());
attachList.add(idCardBehind);
}
if (CollectionUtil.isNotEmpty(attachList)) {
reqParam.set("attachList", attachList);
}
return reqParam;
}
/**
* 内部调用申请一个或多个分账接收方平台方和代理商
*
* @param mchId
* @return
*/
@Override
public Boolean innerApplyLedgerReceiver(Long mchId) {
// 商户的分账接收方平台+代理商 // 商户的分账接收方平台+代理商
JSONArray platformAndAgentReceiver = buildApplyLedgerReceiverReqParams(mchId); JSONArray platformAndAgentReceiver = buildApplyLedgerReceiverReqParams(mchId);
@ -230,7 +275,7 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
int successCnt = 0; int successCnt = 0;
for (JSONObject reqParam : platformAndAgentReceiver.jsonIter()) { for (JSONObject reqParam : platformAndAgentReceiver.jsonIter()) {
log.debug("申请分账接收方参数:{}", reqParam); log.debug("申请分账接收方参数:{}", reqParam);
reqParam.put("mchId", mchId); // 附加入驻商户编号 reqParam.set("mchId", mchId); // 附加入驻商户编号
// 向拉卡拉申请分账接收方 // 向拉卡拉申请分账接收方
CommonResult result = lakalaApiService.applyLedgerReceiver(reqParam); CommonResult result = lakalaApiService.applyLedgerReceiver(reqParam);
@ -245,12 +290,39 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
boolean success = successCnt > 0; boolean success = successCnt > 0;
if (success) { if (success) {
// 更新多个状态 // 更新多个状态
shopMchEntryService.updateMulStatus(mchId, merCupNo, 0, 0, 0, 0, 1, 0, CommonConstant.MCH_APPR_STA_LKL_PADDING); shopMchEntryService.updateMulStatus(mchId, "", 0, 0, 0, 0, 1, 0, CommonConstant.MCH_APPR_STA_LKL_PADDING);
} }
return success; return success;
} }
/**
* 内部调用申请一个或多个分账接收方平台方和代理商
*
* @param esignPlatformInfo
* @return
*/
@Override
public Pair<Boolean, String> innerApplyLedgerReceiver(EsignPlatformInfo esignPlatformInfo) {
// 商户的分账接收方平台+代理商
JSONObject reqParam = buildApplyLedgerReceiverReqParams(esignPlatformInfo);
if (reqParam == null || reqParam.isEmpty()) {
log.error("平台或代理商信息有误");
return Pair.of(false, "平台或代理商信息有误");
}
// 向拉卡拉申请分账接收方
CommonResult result = lakalaApiService.applyLedgerReceiver(reqParam);
if (result == null || result.getStatus() != ResultCode.SUCCESS.getStatus()) {
log.error("申请分账接收方失败:{}", result.getMsg());
return Pair.of(false, result.getMsg());
}
return Pair.of(true, "");
}
/** /**
* 是否存在平台方的相关记录信息 * 是否存在平台方的相关记录信息
* *
@ -258,10 +330,13 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
*/ */
@Override @Override
public LklLedgerReceiver hasPlatformMch() { public LklLedgerReceiver hasPlatformMch() {
QueryWrapper<LklLedgerReceiver> queryWrapper = new QueryWrapper<>(); List<LklLedgerReceiver> lklLedgerReceivers = list(
queryWrapper.eq("platform_id", 0).eq("status", CommonConstant.Enable).orderByAsc("id"); new LambdaQueryWrapper<LklLedgerReceiver>()
.eq(LklLedgerReceiver::getPlatform_id, 0L)
.eq(LklLedgerReceiver::getStatus, CommonConstant.Enable)
.orderByAsc(LklLedgerReceiver::getId)
);
List<LklLedgerReceiver> lklLedgerReceivers = list(queryWrapper);
if (CollectionUtil.isEmpty(lklLedgerReceivers)) { if (CollectionUtil.isEmpty(lklLedgerReceivers)) {
return null; return null;
} }
@ -276,9 +351,12 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
*/ */
@Override @Override
public List<LklLedgerReceiver> selectPlatformAnDistributorList() { public List<LklLedgerReceiver> selectPlatformAnDistributorList() {
QueryWrapper<LklLedgerReceiver> queryWrapper = new QueryWrapper<>(); return list(
queryWrapper.ge("platform_id", 0).eq("status", CommonConstant.Enable).orderByAsc("platform_id"); new LambdaQueryWrapper<LklLedgerReceiver>()
return list(queryWrapper); .ge(LklLedgerReceiver::getPlatform_id, 0L)
.eq(LklLedgerReceiver::getStatus, CommonConstant.Enable)
.orderByAsc(LklLedgerReceiver::getPlatform_id)
);
} }
/** /**
@ -298,16 +376,18 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
return null; return null;
} }
QueryWrapper<LklLedgerReceiver> queryWrapper = new QueryWrapper<>(); LambdaQueryWrapper<LklLedgerReceiver> queryWrapper =
new LambdaQueryWrapper<>();
if (StrUtil.isNotBlank(LicenseNo)) { if (StrUtil.isNotBlank(LicenseNo)) {
queryWrapper.eq("license_no", LicenseNo); queryWrapper.eq(LklLedgerReceiver::getLicense_no, LicenseNo);
} }
if (StrUtil.isNotBlank(ContactMobile)) { if (StrUtil.isNotBlank(ContactMobile)) {
queryWrapper.eq("contact_mobile", ContactMobile); queryWrapper.eq(LklLedgerReceiver::getContact_mobile, ContactMobile);
} }
queryWrapper.eq("platform_id", platformId) queryWrapper.eq(LklLedgerReceiver::getPlatform_id, platformId)
.eq("status", CommonConstant.Enable); .eq(LklLedgerReceiver::getStatus, CommonConstant.Enable);
return getOne(queryWrapper); return getOne(queryWrapper);
} }
@ -319,15 +399,17 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
return null; return null;
} }
QueryWrapper<LklLedgerReceiver> queryWrapper = new QueryWrapper<>(); LambdaQueryWrapper<LklLedgerReceiver> queryWrapper =
new LambdaQueryWrapper<>();
if (StrUtil.isNotBlank(LicenseNo)) { if (StrUtil.isNotBlank(LicenseNo)) {
queryWrapper.eq("license_no", LicenseNo); queryWrapper.eq(LklLedgerReceiver::getLicense_no, LicenseNo);
} }
if (StrUtil.isNotBlank(ContactMobile)) { if (StrUtil.isNotBlank(ContactMobile)) {
queryWrapper.eq("contact_mobile", ContactMobile); queryWrapper.eq(LklLedgerReceiver::getContact_mobile, ContactMobile);
} }
queryWrapper.eq("status", CommonConstant.Enable); queryWrapper.eq(LklLedgerReceiver::getStatus, CommonConstant.Enable);
return list(queryWrapper); return list(queryWrapper);
} }
@ -342,19 +424,21 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
*/ */
@Override @Override
public Long countByCondition(String LicenseNo, String ContactMobile, Long platformId) { public Long countByCondition(String LicenseNo, String ContactMobile, Long platformId) {
QueryWrapper<LklLedgerReceiver> queryWrapper = new QueryWrapper<>(); LambdaQueryWrapper<LklLedgerReceiver> queryWrapper =
new LambdaQueryWrapper<>();
if (StrUtil.isNotBlank(LicenseNo)) { if (StrUtil.isNotBlank(LicenseNo)) {
queryWrapper.eq("license_no", LicenseNo); queryWrapper.eq(LklLedgerReceiver::getLicense_no, LicenseNo);
} }
if (StrUtil.isNotBlank(ContactMobile)) { if (StrUtil.isNotBlank(ContactMobile)) {
queryWrapper.eq("contact_mobile", ContactMobile); queryWrapper.eq(LklLedgerReceiver::getContact_mobile, ContactMobile);
} }
if (ObjectUtil.isNotEmpty(platformId) && platformId > 0) { if (ObjectUtil.isNotEmpty(platformId) && platformId > 0) {
queryWrapper.eq("platform_id", platformId); queryWrapper.eq(LklLedgerReceiver::getPlatform_id, platformId);
} }
queryWrapper.eq("status", CommonConstant.Enable); queryWrapper.eq(LklLedgerReceiver::getStatus, CommonConstant.Enable);
return count(queryWrapper); return count(queryWrapper);
} }
@ -372,11 +456,13 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
log.debug("[获取平台和代理商信息] 开始查询平台方和代理商接收方信息商户ID: {}", mchId); log.debug("[获取平台和代理商信息] 开始查询平台方和代理商接收方信息商户ID: {}", mchId);
// 获取平台方记录 // 获取平台方记录
QueryWrapper<LklLedgerReceiver> queryWrapper = new QueryWrapper<>(); LklLedgerReceiver platformInfo = findOne(
queryWrapper.eq("level", 0) new LambdaQueryWrapper<LklLedgerReceiver>()
.eq("status", CommonConstant.Enable).orderByAsc("id"); .eq(LklLedgerReceiver::getLevel, 0)
.eq(LklLedgerReceiver::getStatus, CommonConstant.Enable)
.orderByAsc(LklLedgerReceiver::getId)
);
LklLedgerReceiver platformInfo = findOne(queryWrapper);
if (platformInfo == null || platformInfo.getId() == null || platformInfo.getId() <= 0) { if (platformInfo == null || platformInfo.getId() == null || platformInfo.getId() <= 0) {
log.error("[获取平台和代理商信息] 未找到有效的平台方记录, mchId={}", mchId); log.error("[获取平台和代理商信息] 未找到有效的平台方记录, mchId={}", mchId);
return Collections.emptyList(); return Collections.emptyList();
@ -402,13 +488,15 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
} }
// 获取县级代理商的省级代理商 // 获取县级代理商的省级代理商
queryWrapper.clear(); LklLedgerReceiver agent1st = findOne(
queryWrapper.eq("platform_id", agent2nd.getParent_id()) new LambdaQueryWrapper<LklLedgerReceiver>()
.eq("level", CommonConstant.Agent_Level_1st) .eq(LklLedgerReceiver::getPlatform_id, agent2nd.getParent_id())
.gt("split_ratio", 0) .eq(LklLedgerReceiver::getLevel, CommonConstant.Agent_Level_1st)
.eq("status", CommonConstant.Enable) .gt(LklLedgerReceiver::getSplit_ratio, 0)
.orderByAsc("id"); .eq(LklLedgerReceiver::getStatus, CommonConstant.Enable)
LklLedgerReceiver agent1st = findOne(queryWrapper); .orderByAsc(LklLedgerReceiver::getId)
);
if (agent1st != null) { if (agent1st != null) {
list.add(agent1st); list.add(agent1st);
log.debug("[获取平台和代理商信息] 成功获取一级代理信息ID: {}", agent1st.getId()); log.debug("[获取平台和代理商信息] 成功获取一级代理信息ID: {}", agent1st.getId());
@ -451,26 +539,29 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
return null; return null;
} }
// 构建查询条件
QueryWrapper<LklLedgerReceiver> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("level", CommonConstant.Agent_Level_2nd)
.eq("status", CommonConstant.Enable)
.orderByAsc("id");
LklLedgerReceiver result = null; LklLedgerReceiver result = null;
// 优先使用指定的分销商ID查询否则使用区域信息查询 // 优先使用指定的分销商ID查询否则使用区域信息查询
if (shopMchEntry.getDistributor_id() != null && shopMchEntry.getDistributor_id() > 0) { if (shopMchEntry.getDistributor_id() != null && shopMchEntry.getDistributor_id() > 0) {
queryWrapper.eq("platform_id", shopMchEntry.getDistributor_id()); LambdaQueryWrapper<LklLedgerReceiver> queryWrapper = new LambdaQueryWrapper<LklLedgerReceiver>()
result = findOne(queryWrapper); .eq(LklLedgerReceiver::getLevel, CommonConstant.Agent_Level_2nd)
.eq(LklLedgerReceiver::getStatus, CommonConstant.Enable)
.eq(LklLedgerReceiver::getPlatform_id, shopMchEntry.getDistributor_id())
.orderByAsc(LklLedgerReceiver::getId);
result = getOne(queryWrapper, false);
log.debug("[获取二级代理] 使用指定分销商ID查询distributorId={}", shopMchEntry.getDistributor_id()); log.debug("[获取二级代理] 使用指定分销商ID查询distributorId={}", shopMchEntry.getDistributor_id());
} }
if (result == null && StrUtil.isNotBlank(shopMchEntry.getStore_district())) { if (result == null && StrUtil.isNotBlank(shopMchEntry.getStore_district())) {
// 运费代理商 // 运费代理商
queryWrapper.eq("license_district_id", shopMchEntry.getStore_district()) LambdaQueryWrapper<LklLedgerReceiver> queryWrapper = new LambdaQueryWrapper<LklLedgerReceiver>()
.gt("shipping_fee", 0).ne("supplier_id", "") .eq(LklLedgerReceiver::getLevel, CommonConstant.Agent_Level_2nd)
.orderByAsc("id"); .eq(LklLedgerReceiver::getStatus, CommonConstant.Enable)
result = findOne(queryWrapper); .eq(LklLedgerReceiver::getLicense_district_id, shopMchEntry.getStore_district())
.gt(LklLedgerReceiver::getShipping_fee, 0)
.isNotNull(LklLedgerReceiver::getSupplier_id)
.ne(LklLedgerReceiver::getSupplier_id, "")
.orderByAsc(LklLedgerReceiver::getId);
result = getOne(queryWrapper, false);
log.debug("[获取二级代理] 使用区域信息查询districtId={}", shopMchEntry.getStore_district()); log.debug("[获取二级代理] 使用区域信息查询districtId={}", shopMchEntry.getStore_district());
} }

View File

@ -1139,7 +1139,7 @@ public class LklTkServiceImpl {
} }
// 2新增一个接收方记录起码要一个平台方代理商根据入驻商家由哪个代理商邀请而确定是否新增 // 2新增一个接收方记录起码要一个平台方代理商根据入驻商家由哪个代理商邀请而确定是否新增
Boolean genSuccess = lklLedgerReceiverService.innerApplyLedgerReceiver(mchId, merCupNo); Boolean genSuccess = lklLedgerReceiverService.innerApplyLedgerReceiver(mchId);
if (!genSuccess) { if (!genSuccess) {
logger.error("进件、申请分账业务成功已成功,等待拉卡拉审核分账业务请求,但创建分账接收方失败了,请管理员补偿流程"); logger.error("进件、申请分账业务成功已成功,等待拉卡拉审核分账业务请求,但创建分账接收方失败了,请管理员补偿流程");
shopMchEntryService.updateMerchEntryApprovalByMchId(mchId, null, shopMchEntryService.updateMerchEntryApprovalByMchId(mchId, null,

View File

@ -1715,7 +1715,7 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
@Override @Override
public Boolean updateMerchEntryApprovalByMchId(Long mchId, Integer approvalStatus, String approvalRemark) { public Boolean updateMerchEntryApprovalByMchId(Long mchId, Integer approvalStatus, String approvalRemark) {
// 1. 参数校验mchId // 1. 参数校验mchId
if (ObjectUtil.isEmpty(mchId)) { if (CheckUtil.isEmpty(mchId)) {
log.error("更新入驻审批状态和备注失败:缺少 mchId "); log.error("更新入驻审批状态和备注失败:缺少 mchId ");
return false; return false;
} }