优化进件流程, 补偿机制

This commit is contained in:
Jack 2025-09-03 17:34:16 +08:00
parent 0cde19efd7
commit 4247e5f6cf
12 changed files with 168 additions and 166 deletions

View File

@ -143,7 +143,7 @@ public class LoginController extends BaseControllerImpl {
user_account = CommonConstant.IDD_ZH_CN + user_account;
if (PhoneNumberUtils.isValidNumber(user_account)) {
//尝试手机号绑定登录
result = accountUserBaseService.doMobileBindLogin(user_account, user_password);
result = accountUserBaseService.doMobileBindLoginByPwd(user_account, user_password);
}
}
@ -174,7 +174,7 @@ public class LoginController extends BaseControllerImpl {
user_account = CommonConstant.IDD_ZH_CN + user_account;
if (PhoneNumberUtils.isValidNumber(user_account)) {
//尝试手机号绑定登录
result = accountUserBaseService.doMobileBindLogin(user_account, user_password);
result = accountUserBaseService.doMobileBindLoginByPwd(user_account, user_password);
}
}

View File

@ -163,14 +163,14 @@ public class AccountUserBaseController extends BaseControllerImpl {
//验证码错误
throw new ApiException(ResultCode.VERIFYCODE_FAILED);
}
// ccountUserBaseService.login 里重复代码,为了兼容商家版登录
// accountUserBaseService.login 里重复代码,为了兼容商家版登录
Map<String, String> params = new HashMap<>();
// 商家手机账号登录
String userMobile = PhoneNumberUtils.convZhPhoneNumber(user_account);
Boolean isMobileAccount = Validator.isNumber(user_account) && PhoneNumberUtils.isValidNumber(userMobile);
if (isMobileAccount) {
if (isMobileAccount) {// 商家手机账号登录
AccountUserBindConnect bind_row = accountUserBindConnectService.getBindByBindId(user_account, BindCode.MOBILE, CommonConstant.USER_TYPE_MCH);
if (bind_row != null) {
AccountUserBase accountUserBase = accountUserBaseService.get(bind_row.getUser_id());
@ -184,12 +184,6 @@ public class AccountUserBaseController extends BaseControllerImpl {
return CommonResult.failed("账号或密码错误!");
}
// log.info("bind:{}", bind_row);
// log.info("pwd:{}", "b3d1339eb3948463522cd115094856a5");
// log.info("salt:{}", accountUserBase.getUser_salt());
// log.info("npwd:{}, eq?:{}", user_password_entry, user_password_entry.equals("b3d1339eb3948463522cd115094856a5"));
// 手机注册的商家账号
params.put("client_id", AuthConstant.MCH_CLIENT_ID);
params.put("client_secret", AuthConstant.AUTHORITY_MOBILE_SECRET);
@ -220,13 +214,12 @@ public class AccountUserBaseController extends BaseControllerImpl {
// 随机数图形验证码有效期一分钟
params.put("verify_code", verifyCode);
CommonResult result = accountUserBaseService.login(params);
//user_account判断是否手机号
if (result.getStatus() != 200 && isMobileAccount) {
//尝试手机号绑定登录
result = accountUserBaseService.doMobileBindLogin(userMobile, user_password);
result = accountUserBaseService.doMobileBindLoginByPwd(userMobile, user_password);
}
return result;

View File

@ -157,7 +157,7 @@ public interface AccountUserBaseService extends IBaseService<AccountUserBase> {
Map<String, Object> doAppConnectLogin(String bind_name, String code);
CommonResult doMobileBindLogin(String user_mobile, String verify_code);
CommonResult doMobileBindLoginByPwd(String user_mobile, String verify_code);
/**
* 用户来源

View File

@ -220,13 +220,14 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
if (StrUtil.isNotBlank(params.get("user_mobile"))
&& CommonConstant.USER_TYPE_MCH.equals(params.get("user_is_admin"))) {
// 商家版app显示申请入驻的状态
data.put("is_merch", CommonConstant.Enable);
data.put("user_mobile", params.get("user_mobile"));
//入驻商家的审批状态1-已通过2-未通过3-待审核4-未申请
// Map<String, Object> params2 = new HashMap<>();
// params2.put("user_mobile", params.get("user_mobile"));
// data.put("merch_approval_status", shopService.shopMerchEntryApprovalStatus(params2));
String userMobile = params.get("user_mobile");
// 登录成功之后异步检查并修复商户店铺信息
asyncTaskService.checkAndFixMchStoreInfo(PhoneNumberUtils.cleanPhoneNumber(userMobile));
data.put("is_merch", CommonConstant.Enable);
data.put("user_mobile", userMobile);
}
// 个推消息推送设备与用户绑定
@ -2943,7 +2944,7 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
// 找出手机对应的用户
// 是否为手机号注册
if (StrUtil.isNotBlank(user_mobile)) {
return doMobileBindLogin(user_mobile, "");
return doMobileBindLoginByPwd(user_mobile, "");
}
return CommonResult.success();
@ -3186,18 +3187,15 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
* @param password
* @return
*/
public CommonResult doMobileBindLogin(String user_mobile, String password) {
public CommonResult doMobileBindLoginByPwd(String user_mobile, String password) {
AccountUserBindConnect bind_row = bindConnectService.get(user_mobile);
// 检查输入字符是不是包含 sql 注入特征如果包含不给以通过
if (!CommonService.isValidInput(user_mobile, password)) {
// new ApiException(ResultCode.VALIDATE_INPUTS);
return CommonResult.failed(ResultCode.VALIDATE_INPUTS);
}
if (bind_row != null && ObjectUtil.equal(BindCode.MOBILE, bind_row.getBind_type())) {
// AccountUserBindConnect accountUserBindConnect = accountUserBindConnectService.getBindByBindId(user_mobile, BindCode.MOBILE, CommonConstant.USER_TYPE_NORMAL);
// if (accountUserBindConnect != null) {
// 绑定了手机的情况
Integer user_id = bind_row.getUser_id();
AccountUserBase user_base_row = get(user_id);

View File

@ -262,11 +262,11 @@ public class EsignContractServiceImpl extends BaseServiceImpl<EsignContractMappe
String timestamp = request.getHeader("X-Tsign-Open-TIMESTAMP");
if (StrUtil.isBlank(reqAppId) || StrUtil.isBlank(signture) || StrUtil.isBlank(timestamp)) {
return new ResponseEntity<>(new JSONObject().put("code", 400).put("msg", "缺少必要参数").toString(), HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new JSONObject().put("code", 400).put("msg", "缺少必要参数").toString());
}
if (!reqAppId.equals(appId)) {
return new ResponseEntity<>(new JSONObject().put("code", 400).put("msg", "appId 有误").toString(), HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new JSONObject().put("code", 400).put("msg", "appId 有误").toString());
}
//按照规则进行加密
@ -275,7 +275,7 @@ public class EsignContractServiceImpl extends BaseServiceImpl<EsignContractMappe
log.debug("加密出来的签名值:----------->>>>>>" + mySignature);
log.debug("header里面的签名值---------->>>>>>" + signture);
if (!mySignature.equals(signture)) {
return new ResponseEntity<>(new JSONObject().put("code", 400).put("msg", "签名校验失败").toString(), HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new JSONObject().put("code", 400).put("msg", "签名校验失败").toString());
}
// 处理业务逻辑
@ -284,19 +284,19 @@ public class EsignContractServiceImpl extends BaseServiceImpl<EsignContractMappe
String signFlowId = reqBodyJSON.getStr("signFlowId");
Integer signResult = reqBodyJSON.getInt("signResult");
if (StrUtil.isBlank(action) || StrUtil.isBlank(signFlowId)) {
return new ResponseEntity<>(new JSONObject().put("code", 400).put("msg", "返回数据有误").toString(), HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new JSONObject().put("code", 400).put("msg", "返回数据有误").toString());
}
// 获取合同签署记录
EsignContract esignContract = baseMapper.selectOne(new QueryWrapper<EsignContract>().eq("sign_flow_id", signFlowId));
if (esignContract == null) {
return new ResponseEntity<>(new JSONObject().put("code", 400).put("msg", "获取不到合同记录").toString(), HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new JSONObject().put("code", 400).put("msg", "获取不到合同记录").toString());
}
log.debug("签署流程结束通知:action >>> {}", action);
if (CommonConstant.CONTRACT_SIGN_STA_FINISH.equals(esignContract.getSign_flow_status()) && StrUtil.isNotEmpty(esignContract.getLocal_contract_url())) {
// 已经签署完毕不用在更改状态
return new ResponseEntity<>(new JSONObject().put("code", 200).put("msg", "success").toString(), HttpStatus.OK);
return ResponseEntity.ok(new JSONObject().put("code", 200).put("msg", "success").toString());
}
// 获取正式盖章合同文件上传到 oss 服务器更状态,保存数据
@ -315,10 +315,10 @@ public class EsignContractServiceImpl extends BaseServiceImpl<EsignContractMappe
log.error("商家申请分账业务异常:{}", retPair.getSecond());
}
// 更新商家的hasEsigned状态=1
shopMchEntryService.updateMulStatus(0L, esignContract.getMch_mobile(), "", 1, 0, 0, 0, 0, 0, CommonConstant.MCH_APPR_STA_LKL_PADDING);
// TODO mchId 必填字段更新商家的hasEsigned状态=1
shopMchEntryService.updateMulStatus(0L, "", 1, 0, 0, 0, 0, 0, CommonConstant.MCH_APPR_STA_LKL_PADDING);
return new ResponseEntity<>(new JSONObject().put("code", 200).put("msg", "success").toString(), HttpStatus.OK);
return ResponseEntity.ok(new JSONObject().put("code", 200).put("msg", "success").toString());
}
} else if (action.equals("SIGN_MISSON_COMPLETE") && ObjectUtil.isNotEmpty(signResult)) {// 签署方-签署结果含拒签通知
Integer signFlowStatus = null;
@ -330,13 +330,13 @@ public class EsignContractServiceImpl extends BaseServiceImpl<EsignContractMappe
// 更新合同流程状态和文件地址
boolean success = updateContractFlowStatusAndFileUrlBySignFlowId(signFlowId, signFlowStatus, "");
if (success) {
return new ResponseEntity<>(new JSONObject().put("code", 200).put("msg", "success").toString(), HttpStatus.OK);
return ResponseEntity.ok(new JSONObject().put("code", 200).put("msg", "success").toString());
}
} else {
log.debug("签署流程未完成,不做处理");
}
return new ResponseEntity<>(new JSONObject().put("code", 400).put("msg", "未更新数据!").toString(), HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new JSONObject().put("code", 400).put("msg", "未更新数据!").toString());
}
/**

View File

@ -136,10 +136,10 @@ public class LakalaController extends BaseControllerImpl {
public ResponseEntity<JSONObject> ecApplyNotify(HttpServletRequest request) {
JSONObject resp = lakalaPayService.applyLedgerMerEcNotify(request);
if (resp != null && "SUCCESS".equals(resp.get("code"))) {
return new ResponseEntity<>(resp, HttpStatus.OK);
return ResponseEntity.ok(resp);
}
return new ResponseEntity<>(resp, HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resp);
}
@ApiOperation(value = "商户分账业务开通申请", notes = "商户分账业务开通申请")
@ -153,10 +153,10 @@ public class LakalaController extends BaseControllerImpl {
public ResponseEntity<JSONObject> ledgerApplyLedgerMerNotify(HttpServletRequest request) {
JSONObject resp = lakalaPayService.applyLedgerMerNotify(request);
if (resp != null && "SUCCESS".equals(resp.get("code"))) {
return new ResponseEntity<>(resp, HttpStatus.OK);
return ResponseEntity.ok(resp);
}
return new ResponseEntity<>(resp, HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resp);
}
@ApiOperation(value = "分账接收方创建申请", notes = "分账接收方创建申请")
@ -177,9 +177,9 @@ public class LakalaController extends BaseControllerImpl {
public ResponseEntity<JSONObject> applyBindNotify(HttpServletRequest request) {
JSONObject resp = lakalaPayService.applyLedgerMerReceiverBindNotify(request);
if (resp != null && "SUCCESS".equals(resp.get("code"))) {
return new ResponseEntity<>(resp, HttpStatus.OK);
return ResponseEntity.ok(resp);
}
return new ResponseEntity<>(resp, HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resp);
}
}

View File

@ -72,10 +72,10 @@ public class LklTkController extends BaseControllerImpl {
public ResponseEntity<JSONObject> registrationMerchantNotify(HttpServletRequest request) {
JSONObject resp = lklTkService.registrationMerchantNotify(request);
if (resp != null && resp.get("code").equals("200")) {
return new ResponseEntity<>(resp, HttpStatus.OK);
return ResponseEntity.ok(resp);
}
return new ResponseEntity<>(resp, HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resp);
}
@ApiOperation(value = "上传文件", notes = "上传文件")

View File

@ -1030,7 +1030,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
}
// 更新商家分账申请状态为已申请hasApplySplit=1
shopMchEntryService.updateMulStatus(lklLedgerMember.getMch_id(), "", merCupNo, 0, 0, 0, 1, 0, 0, CommonConstant.MCH_APPR_STA_LKL_PADDING);
shopMchEntryService.updateMulStatus(lklLedgerMember.getMch_id(), merCupNo, 0, 0, 0, 1, 0, 0, CommonConstant.MCH_APPR_STA_LKL_PADDING);
shopMchEntryService.updateMerchEntryApprovalByMchId(lklLedgerMember.getMch_id(), null, "商户分账业务申请已审核通过");
log.debug("商户分账业务申请异步回调处理成功applyId={}", applyId);
@ -1180,7 +1180,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, "创建接收方成功!");
} catch (Exception e) {
@ -1339,7 +1339,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
if (successCount == 0) {
if (lklLedgerMember != null) {
shopMchEntryService.updateMerchEntryApprovalByMchId(
lklLedgerMember.getMch_id(), CommonConstant.MCH_APPR_STA_NOPASS, "商家绑定分账接收方失败"
lklLedgerMember.getMch_id(), CommonConstant.MCH_APPR_STA_NOPASS, "商家绑定分账接收方失败"
);
}
return Pair.of(false, "商家绑定分账接收方失败");
@ -1359,7 +1359,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
* @param request HTTP请求对象
* @return 返回处理结果JSON包含code和message字段
*/
@Transactional
// @Transactional
@Override
public JSONObject applyLedgerMerReceiverBindNotify(HttpServletRequest request) {
log.debug("商家绑定分账接收方异步通知回调开始");
@ -1387,6 +1387,11 @@ public class LakalaApiServiceImpl implements LakalaApiService {
String applyId = paramsJSON.getStr("applyId");
String auditStatus = paramsJSON.getStr("auditStatus");
LklLedgerMerReceiverBind lklLedgerMerReceiverBind = lklLedgerMerReceiverBindService.getPlatformByApplyId(applyId);
if (lklLedgerMerReceiverBind == null || CheckUtil.isEmpty(lklLedgerMerReceiverBind.getMch_id())) {
return JSONUtil.createObj().put("code", "FAIL").put("message", "无法获取到绑定记录!");
}
// 4. 参数校验防止空值
if (org.apache.commons.lang3.StringUtils.isAnyBlank(merCupNo, applyId, auditStatus)) {
String errorMsg = String.format("关键参数缺失merCupNo=%s, applyId=%s, auditStatus=%s", merCupNo, applyId, auditStatus);
@ -1421,17 +1426,28 @@ public class LakalaApiServiceImpl implements LakalaApiService {
return JSONUtil.createObj().put("code", "FAIL").put("message", "更新状态失败");
}
LklLedgerMerReceiverBind lklLedgerMerReceiverBind = lklLedgerMerReceiverBindService.getPlatformByApplyId(applyId);
if (lklLedgerMerReceiverBind != null) {
// 7. 成功后更新商户绑定状态为已绑定
shopMchEntryService.updateMulStatus(lklLedgerMerReceiverBind.getMch_id(), "", merCupNo, 0, 0, 0, 0, 0, 1, CommonConstant.MCH_APPR_STA_PASS);
Long mchId = lklLedgerMerReceiverBind.getMch_id();
// 7. 成功后更新商户绑定状态为已绑定
shopMchEntryService.updateMulStatus(mchId, merCupNo, 0, 0, 0, 0, 0, 1, CommonConstant.MCH_APPR_STA_PASS);
// 创建店铺并初始化
// 新建一个正式的已审核通过的店铺不要抛异常使用补偿机制可以独立初始化店铺
// 重要包含了更改 merchEntryInfo 的状态 使用法人小微个人的手机号注册商家账号作为店铺的管理员
Pair<Integer, String> retPair = shopStoreBaseService.covMerchEntryInfo2StoreInfo(mchId, false);
if (retPair.getFirst() <= 0) {
shopMchEntryService.updateMerchEntryApprovalByMchId(mchId, null, "创建并初始化店铺失败:" + retPair.getSecond());
log.error("进件成功,但初始化店铺失败: mchId={}, reason={}", mchId, retPair.getSecond());
} else {
log.debug("进件成功创建并初始化店铺成功mchId={}", mchId);
}
// 8. 检查商户绑定状态是否完成 更改总的审核状态
shopMchEntryService.checkMerchEntryFinished("", merCupNo);
shopMchEntryService.checkMerchEntryFinished(mchId);
// 9. 日志记录并返回成功响应
log.debug("商家绑定分账接收方异步通知处理完成merCupNo{}", merCupNo);
log.debug("商家绑定分账接收方异步通知处理完成mchId:{} merCupNo{}", mchId, merCupNo);
return JSONUtil.createObj().put("code", "SUCCESS").put("message", "分账接收方绑定成功");
} catch (Exception e) {

View File

@ -245,7 +245,7 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
boolean success = successCnt > 0;
if (success) {
// 更新多个状态
shopMchEntryService.updateMulStatus(mchId, "", merCupNo, 0, 0, 0, 0, 1, 0, CommonConstant.MCH_APPR_STA_LKL_PADDING);
shopMchEntryService.updateMulStatus(mchId, merCupNo, 0, 0, 0, 0, 1, 0, CommonConstant.MCH_APPR_STA_LKL_PADDING);
}
return success;

View File

@ -22,6 +22,7 @@ import com.suisung.mall.common.modules.store.ShopMchEntry;
import com.suisung.mall.common.pojo.to.AddressParseResultTO;
import com.suisung.mall.common.service.impl.CommonService;
import com.suisung.mall.common.utils.AddressUtil;
import com.suisung.mall.common.utils.CheckUtil;
import com.suisung.mall.common.utils.RestTemplateHttpUtil;
import com.suisung.mall.common.utils.UploadUtil;
import com.suisung.mall.core.web.service.RedisService;
@ -40,7 +41,6 @@ import org.springframework.data.util.Pair;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@ -350,6 +350,16 @@ public class LklTkServiceImpl {
return Pair.of(false, "商家先签署合同,再来进件!");
}
// 判断是否已经进件过进件过执行下一步操作进件异步通知的相关操作
//密集操作进件审核通过之后要下一步流程操作申请分账业务创建分账接收方
if (CommonConstant.Enable.equals(shopMchEntry.getHas_apply_mer()) && CheckUtil.isNotEmpty(shopMchEntry.getDistributor_id())
&& StrUtil.isAllNotBlank(shopMchEntry.getLkl_mer_cup_no(), shopMchEntry.getLkl_term_no())) {
// 已经进件过了执行下一步操作
registrationMerchantAfterHook(mchId, shopMchEntry.getLkl_mer_cup_no(), shopMchEntry.getDistributor_id());
return Pair.of(true, "请勿重复提交,拉卡拉已进件成功了,准备提交分账业务申请!");
}
JSONObject reqJsonBody = new JSONObject();
reqJsonBody.put("userNo", userNo);
reqJsonBody.put("busiCode", "WECHAT_PAY");// WECHAT_PAY:专业化扫码;B2B_SYT:B2B收银台;
@ -559,7 +569,7 @@ public class LklTkServiceImpl {
* @param request
* @return
*/
@Transactional
// @Transactional
public JSONObject registrationMerchantNotify(HttpServletRequest request) {
logger.debug("拉卡拉进件异步通知开始");
@ -633,57 +643,48 @@ public class LklTkServiceImpl {
return new JSONObject().set("code", "500").set("message", "更新商户号失败");
}
shopMchEntryService.updateMerchEntryApprovalByMchId(shopMchEntry.getId(), CommonConstant.MCH_APPR_STA_LKL_PADDING,
"进件、申请分账业务、创建分账接收方均已成功,等待拉卡拉审核分账业务请求!");
//密集操作进件审核通过之后要下一步流程操作申请分账业务创建分账接收方
registrationMerchantAfterHook(mchId, merCupNo, shopMchEntry.getDistributor_id());
return new JSONObject().set("code", "200").set("message", "处理成功");
}
/**
* 进件审核通过之后要下一步流程操作申请分账业务创建分账接收方
*
* @param mchId
* @param merCupNo
* @param distributorId
*/
private void registrationMerchantAfterHook(Long mchId, String merCupNo, Long distributorId) {
logger.info("商家进件已成功,下一步申请拉卡拉分账业务,再创建分账接收方!");
// 备注RMK 采用拉卡拉的入网电子合同签署流程暂停e签宝的电子合同生成流程
// logger.debug("###开始异步执行生成电子合同模版和填充模版数据,并生该商家和平台方签署的未盖章合同文件###");
// // 生成电子合同模版和填充模版数据并生该商家和平台方签署的未盖章合同文件
// Boolean genSuccess = esignContractFillingFileService.fillDocTemplate(shopMchEntry.getLogin_mobile(), "");
// if (!genSuccess) {
// logger.error("###商家入驻电子合同生成失败###");
// }
//
// // 1发起E签宝合同签署签署完成之后生成分账盖章协议书下一步才能申请分账功能权限
// Pair<Boolean, String> resPair = esignContractService.innerSignFlowCreateByFile(shopMchEntry.getLogin_mobile());
// if (!resPair.getFirst()) {
// logger.error("###商家发起电子签名失败:{}###", resPair.getSecond());
// }
// 新建一个正式的已审核通过的店铺不要抛异常使用补偿机制可以独立初始化店铺
// 重要包含了更改 merchEntryInfo 的状态 使用法人小微个人的手机号注册商家账号作为店铺的管理员
Pair<Integer, String> retPair = shopStoreBaseService.covMerchEntryInfo2StoreInfo(mchId, false);
if (retPair.getFirst() <= 0) {
shopMchEntryService.updateMerchEntryApprovalByMchId(shopMchEntry.getId(), null, "创建并初始化店铺失败");
logger.error("初始化店铺失败: mchId={}, reason={}", mchId, retPair.getSecond());
} else {
logger.debug("初始化店铺成功mchId={}", mchId);
}
// 重要给商家申请分账业务务必检查是否申请过申请过忽略
Pair<Boolean, String> applyRetPair = lakalaApiService.innerApplyLedgerMer(merCupNo);
if (!applyRetPair.getFirst()) {
String message = "商家申请分账业务异常:" + applyRetPair.getSecond();
shopMchEntryService.updateMerchEntryApprovalByMchId(shopMchEntry.getId(), null, message);
String message = "提交分账业务申请异常:" + applyRetPair.getSecond();
shopMchEntryService.updateMerchEntryApprovalByMchId(mchId, null, message);
logger.error(message);
return new JSONObject().set("code", "500").set("message", message);
} else {
logger.info("申请分账业务已成功,等待拉卡拉审核,准备创建分账接收方!");
}
logger.info("申请分账业务已成功,等待拉卡拉审核,准备创建分账接收方!");
// 2新增一个接收方记录起码要一个平台方代理商根据入驻信息新增
Boolean genSuccess = lklLedgerReceiverService.innerApplyLedgerReceiver(shopMchEntry.getId(), merCupNo, shopMchEntry.getDistributor_id());
Boolean genSuccess = lklLedgerReceiverService.innerApplyLedgerReceiver(mchId, merCupNo, distributorId);
if (!genSuccess) {
logger.error("申请分账业务已成功,等待拉卡拉审核,但创建分账接收方失败了");
shopMchEntryService.updateMerchEntryApprovalByMchId(shopMchEntry.getId(), null, "申请分账业务已成功,等待拉卡拉审核,但创建分账接收方失败了");
return new JSONObject().set("code", "500").set("message", "创建分账接收方失败");
logger.error("进件、申请分账业务成功已成功,等待拉卡拉审核分账业务请求,但创建分账接收方失败了,请管理员补偿流程");
shopMchEntryService.updateMerchEntryApprovalByMchId(mchId, null,
"进件、申请分账业务成功已成功,等待拉卡拉审核分账业务请求,但创建分账接收方失败了,请管理员补偿流程");
} else {
logger.info("创建分账接收方成功!");
}
shopMchEntryService.updateMerchEntryApprovalByMchId(shopMchEntry.getId(), CommonConstant.MCH_APPR_STA_LKL_PADDING, "申请分账业务、创建分账接收方均已成功,等待拉卡拉审核开通分账业务");
return new JSONObject().put("code", "200").put("message", "处理成功");
}
/**
* 获取拉卡拉店铺的(或银行的)省市区编码
*

View File

@ -253,7 +253,6 @@ public interface ShopMchEntryService {
* 根据商户号或商家手机号修改商户入驻信息多个状态
*
* @param mchId 商户入驻自增Id
* @param merchantMobile 商家手机号
* @param merchantCupNo 商户号
* @param hasEcSigned 是否已签署电子合同
* @param hasApplyMerchant 是否已申请商户进件
@ -264,7 +263,7 @@ public interface ShopMchEntryService {
* @param approvalStatus 审批状态
* @return 更新结果true为成功false为失败
*/
Boolean updateMulStatus(Long mchId, String merchantMobile, String merchantCupNo, Integer hasEcSigned, Integer hasApplyMerchant, Integer storeStatus,
Boolean updateMulStatus(Long mchId, String merchantCupNo, Integer hasEcSigned, Integer hasApplyMerchant, Integer storeStatus,
Integer hasApplySplit, Integer hasApplyReceiver, Integer hasBindReceiver, Integer approvalStatus);
/**
@ -286,13 +285,12 @@ public interface ShopMchEntryService {
Boolean updateMerchEntryEcResultUrlByMchId(Long mchId, String lklEcResultUrl);
/**
* 根据商户手机号和商户号检查商家入驻整个流程是否全部完成
* 根据商家入驻Id 检查商家入驻整个流程是否全部完成
*
* @param merchantMobile 商家手机号
* @param merchantCupNo 商户号
* @param mchId 商家入驻Id
* @return
*/
Boolean checkMerchEntryFinished(String merchantMobile, String merchantCupNo);
Boolean checkMerchEntryFinished(Long mchId);
/**
* 检查更新商户入驻店铺初始化状态

View File

@ -73,13 +73,6 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
@Resource
private EsignPlatformInfoService esignPlatformInfoService;
// @Resource
// private EsignContractFillingFileService esignContractFillingFileService;
//
// @Lazy
// @Resource
// private EsignContractService esignContractService;
@Lazy
@Resource
private ShopStoreBaseService shopStoreBaseService;
@ -91,9 +84,6 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
@Resource
private LklLedgerEcService lklLedgerEcService;
// @Autowired
// private TaskService taskService;
@Lazy
@Resource
private LakalaApiServiceImpl lakalaApiService;
@ -104,7 +94,6 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
@Resource
private AccountService accountService;
/**
* 获取店铺的经营类目列表
*
@ -582,7 +571,6 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
queryWrapper.eq("id", recordId);
}
if (StrUtil.isNotBlank(mobile)) {
queryWrapper.eq("login_mobile", mobile);
}
@ -648,6 +636,8 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
// === 拉卡拉签约逻辑 ===
Long mchId = record.getId();
if (CommonConstant.Enable.equals(record.getHas_ec_signed())) {
LklLedgerEc ec = lklLedgerEcService.getByMchId(
record.getId(),
@ -666,6 +656,23 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
}
}
}
// RMK 补偿机制入驻总状态店铺创建和初始化
// 创建店铺并初始化
// 新建一个正式的已审核通过的店铺不要抛异常使用补偿机制可以独立初始化店铺
// 重要包含了更改 merchEntryInfo 的状态 使用法人小微个人的手机号注册商家账号作为店铺的管理员
Pair<Integer, String> retPair = shopStoreBaseService.covMerchEntryInfo2StoreInfo(mchId, false);
if (retPair.getFirst() <= 0) {
updateMerchEntryApprovalByMchId(mchId, null, "创建并初始化店铺失败:" + retPair.getSecond());
log.error("进件成功,但初始化店铺失败: mchId={}, reason={}", mchId, retPair.getSecond());
} else {
log.debug("进件成功创建并初始化店铺成功mchId={}", mchId);
}
// 8. 检查商户绑定状态是否完成 更改总的审核状态
checkMerchEntryFinished(mchId);
} catch (Exception e) {
log.error("更新商户签约状态异常, recordId:{}, error:{}",
record != null ? record.getId() : "null",
@ -755,10 +762,11 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
}
// 4.2 检查入驻状态
boolean isValidStatus =
CommonConstant.MCH_APPR_STA_PASS.equals(entry.getApproval_status()) &&
CommonConstant.Enable.equals(entry.getHas_ec_signed()) &&
CommonConstant.Enable.equals(entry.getHas_apply_mer());
boolean isValidStatus = CommonConstant.Enable.equals(entry.getHas_ec_signed())
&& CommonConstant.Enable.equals(entry.getHas_apply_mer())
&& CommonConstant.Enable.equals(entry.getHas_apply_split())
&& CommonConstant.Enable.equals(entry.getHas_apply_receiver())
&& CommonConstant.Enable.equals(entry.getHas_bind_receiver());
if (!isValidStatus) {
log.debug("入驻记录状态不满足修复条件入驻ID: {}", entry.getId());
@ -1643,54 +1651,54 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
}
/**
* 检查商户入驻流程是否全部完成并更新审批状态
* 根据商家入驻Id 检查商家入驻整个流程是否全部完成
*
* @param merchantMobile 商家手机号
* @param merchantCupNo 商户号
* @return 如果全部完成返回 true否则返回 false
* @param mchId 商家入驻Id
* @return
*/
@Override
public Boolean checkMerchEntryFinished(String merchantMobile, String merchantCupNo) {
// 1. 参数校验商户号和商家手机号不能同时为空
if (StrUtil.isAllBlank(merchantCupNo, merchantMobile)) {
log.error("检查商户入驻流程完成状态失败:商户号和商家手机号不能同时为空");
public Boolean checkMerchEntryFinished(Long mchId) {
if (ObjectUtil.isEmpty(mchId)) {
log.error("检查商户入驻流程状态失败商户入驻ID为空");
return false;
}
try {
// 2. 根据手机号或商户号获取商户入驻信息
ShopMchEntry merchantEntry = getShopMerchEntryByMobileOrMerCupNo(merchantMobile, merchantCupNo);
ShopMchEntry merchantEntry = shopMerchEntryById(mchId);
if (merchantEntry == null) {
log.error("检查商户入驻流程完成状态失败:商户不存在, merchantMobile={}, merchantCupNo={}", merchantMobile, merchantCupNo);
log.error("检查商户入驻流程状态失败:商户不存在, mchId={}", mchId);
return false;
}
// 3. 检查各项状态是否已完成
boolean isFinished = CommonConstant.Enable.equals(merchantEntry.getHas_ec_signed())
&& CommonConstant.Enable.equals(merchantEntry.getHas_apply_mer())
&& CommonConstant.Enable.equals(merchantEntry.getStore_status())
&& CommonConstant.Enable.equals(merchantEntry.getHas_apply_split())
&& CommonConstant.Enable.equals(merchantEntry.getHas_apply_receiver())
&& CommonConstant.Enable.equals(merchantEntry.getHas_bind_receiver());
&& CommonConstant.Enable.equals(merchantEntry.getHas_bind_receiver())
&& CommonConstant.Enable.equals(merchantEntry.getStore_status());
// 4. 如果所有状态都已完成则更新商户入驻信息简化if嵌套
if (!isFinished) {
return false; // 返回 false表示入驻流程未全部完成
}
ShopMchEntry merchantEntryUpd = new ShopMchEntry();
merchantEntryUpd.setId(merchantEntry.getId());
merchantEntryUpd.setApproval_status(CommonConstant.MCH_APPR_STA_PASS); // 设置审批状态为已通过
merchantEntryUpd.setApproval_remark("已全部完成入驻流程!"); // 设置审批备注
boolean updateResult = updateById(merchantEntry); // 更新商户入驻信息
UpdateWrapper<ShopMchEntry> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", mchId).eq("status", CommonConstant.Enable)
.ne("approval_status", CommonConstant.MCH_APPR_STA_PASS);
updateWrapper.set("approval_status", CommonConstant.MCH_APPR_STA_PASS);
updateWrapper.set("approval_remark", "恭喜您,入驻流程已全部完成!");
boolean updateResult = update(updateWrapper); // 更新商户入驻信息
if (!updateResult) {
log.error("更新商户入驻信息状态失败, merchantId={}", merchantEntry.getId());
log.error("更新商户入驻信息状态失败, mchId={}", mchId);
return false;
}
return true; // 返回 true表示入驻流程已全部完成
} catch (Exception e) {
// 5. 捕获异常并记录错误日志
log.error("检查商户入驻流程完成状态时发生异常, merchantMobile={}, merchantCupNo={}", merchantMobile, merchantCupNo, e);
log.error("检查商户入驻流程状态异常, mchId={}", mchId, e);
return false; // 发生异常时返回 false
}
}
@ -1700,7 +1708,6 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
* 根据商户号或商家手机号修改商户入驻信息多个状态
*
* @param mchId 商户自增ID
* @param merchantMobile 商家手机号
* @param merchantCupNo 商户号
* @param hasEcSigned 是否已签署电子合同
* @param hasApplyMerchant 是否已申请商户进件
@ -1712,11 +1719,11 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
* @return 更新结果true为成功false为失败
*/
@Override
public Boolean updateMulStatus(Long mchId, String merchantMobile, String merchantCupNo, Integer hasEcSigned, Integer hasApplyMerchant, Integer storeStatus,
public Boolean updateMulStatus(Long mchId, String merchantCupNo, Integer hasEcSigned, Integer hasApplyMerchant, Integer storeStatus,
Integer hasApplySplit, Integer hasApplyReceiver, Integer hasBindReceiver, Integer approvalStatus) {
// 1. 参数校验商户号和商家手机号不能同时为空
if (StrUtil.isAllBlank(merchantCupNo, merchantMobile) && CheckUtil.isEmpty(mchId)) {
log.error("更新商户多个状态失败:缺少必要参数");
if (StrUtil.isBlank(merchantCupNo) && CheckUtil.isEmpty(mchId)) {
log.error("更新商户多个状态失败:缺少必要参数 mchId:{} merchantCupNo:{}", mchId, merchantCupNo);
return false;
}
@ -1725,40 +1732,32 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
UpdateWrapper<ShopMchEntry> updateWrapper = new UpdateWrapper<>();
// 3. 设置查询条件优先 mchId
// if (CheckUtil.isEmpty(mchId)) {
// updateWrapper.eq("id", mchId);
// }
Optional.ofNullable(mchId)
.filter(CheckUtil::isNotEmpty)
.ifPresent(id -> updateWrapper.eq("id", id));
Optional.ofNullable(merchantMobile)
.filter(StrUtil::isNotBlank)
.ifPresent(mobile -> updateWrapper.eq("login_mobile", mobile));
Optional.ofNullable(merchantCupNo)
.filter(StrUtil::isNotBlank)
.ifPresent(cupNo -> updateWrapper.eq("lkl_mer_cup_no", cupNo));
String approvalRemark = "";
if (hasEcSigned.equals(CommonConstant.Enable)) {
if (CommonConstant.Enable.equals(hasEcSigned)) {
approvalRemark = "合同签署完成,商家信息正在提交审核,请耐心等待";
} else if (hasApplyMerchant.equals(CommonConstant.Enable)) {
approvalRemark = "商家资质审核通过,系统正在初始化店铺,请稍后操作";
} else if (storeStatus.equals(CommonConstant.Enable)) {
approvalRemark = "店铺创建成功,系统正在处理分账业务申请";
} else if (hasApplySplit.equals(CommonConstant.Enable)) {
approvalRemark = "分账业务申请已通过,系统正在处理接收方申请";
} else if (hasApplyReceiver.equals(CommonConstant.Enable)) {
} else if (CommonConstant.Enable.equals(hasApplyMerchant)) {
approvalRemark = "商家资质审核通过,系统正在提交分账业务申请,请耐心等待";
} else if (CommonConstant.Enable.equals(hasApplySplit)) {
approvalRemark = "提交分账业务申请已通过,系统正在申请分账接收方事宜";
} else if (CommonConstant.Enable.equals(hasApplyReceiver)) {
approvalRemark = "分账接收方申请成功,系统正在处理接收方绑定";
} else if (hasBindReceiver.equals(CommonConstant.Enable)) {
approvalRemark = "分账接收方绑定成功,入驻流程即将完成";
} else if (CommonConstant.Enable.equals(hasBindReceiver)) {
approvalRemark = "分账接收方绑定成功,系统准备创建初始化店铺";
} else if (CommonConstant.Enable.equals(storeStatus)) {
approvalRemark = "店铺创建并初始化成功,入驻流程即将全部完成";
} else {
approvalRemark = "入驻资料正在审核中,请耐心等待";
}
if (StrUtil.isNotBlank(approvalRemark)) {
updateWrapper.set("approval_remark", approvalRemark);
}
updateWrapper.set("approval_remark", approvalRemark);
// 4. 构建需要更新的字段和值的映射关系
Map<String, Integer> updateFieldMap = new LinkedHashMap<>();
@ -1770,21 +1769,17 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
updateFieldMap.put("has_apply_receiver", hasApplyReceiver); // 是否已申请收款方
updateFieldMap.put("has_bind_receiver", hasBindReceiver); // 是否已绑定收款方
// 5. 过滤掉值为 null 或小于等于 0 的字段避免更新无效字段
updateFieldMap.entrySet().stream()
.filter(entry -> entry.getValue() != null && entry.getValue() > 0)
.forEach(entry -> updateWrapper.set(entry.getKey(), entry.getValue()));
// 6. 执行更新操作并返回结果
return update(updateWrapper);
} catch (Exception e) {
// 7. 异常处理记录异常信息避免程序中断
log.error("更新商户入驻信息多个状态失败", e);
// 可以选择抛出异常 Spring 事务管理器进行回滚
// throw new RuntimeException("更新商户多个状态失败", e);
return false; // 发生异常时返回 false
}
}
@ -1810,7 +1805,8 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
shopMchEntry = getById(shopMchEntryId);
}
if (shopMchEntry != null && StrUtil.isNotBlank(shopMchEntry.getStore_id()) && !CommonConstant.Enable.equals(shopMchEntry.getStore_status())) {
if (shopMchEntry != null && StrUtil.isNotBlank(shopMchEntry.getStore_id())
&& !CommonConstant.Enable.equals(shopMchEntry.getStore_status())) {
UpdateWrapper<ShopMchEntry> updateWrapper = new UpdateWrapper<>();
updateWrapper.set("store_status", CommonConstant.Enable);
updateWrapper.eq("id", shopMchEntryId);