分账逻辑接口设计
This commit is contained in:
parent
8e6da147a1
commit
dd80552720
@ -40,6 +40,7 @@ public class LklLedgerMerReceiverBind implements Serializable {
|
||||
private String entrust_file_path;
|
||||
private String ret_url;
|
||||
private String apply_id;
|
||||
private Long platform_id;
|
||||
private String audit_status;
|
||||
private String audit_status_text;
|
||||
private String remark;
|
||||
|
||||
@ -46,6 +46,9 @@ public class LklOrderSeparate {
|
||||
@ApiModelProperty(value = "分账指令流水号,分账系统生成唯一流水")
|
||||
private String separate_no;
|
||||
|
||||
@ApiModelProperty(value = "平台订单Id")
|
||||
private String order_id;
|
||||
|
||||
@ApiModelProperty(value = "分账总金额,单位:分")
|
||||
private String total_amt;
|
||||
|
||||
|
||||
@ -0,0 +1,70 @@
|
||||
package com.suisung.mall.common.modules.order;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 关联拉卡拉的店铺订单信息
|
||||
* </p>
|
||||
*
|
||||
* @author Xinze
|
||||
* @since 2021-04-30
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("shop_order_lkl")
|
||||
@ApiModel(value = "ShopOrderLkl对象", description = "关联拉卡拉的店铺订单信息")
|
||||
public class ShopOrderLkl implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "自增Id")
|
||||
@TableId(value = "id", type = IdType.INPUT)
|
||||
private Long id;
|
||||
|
||||
private String store_id;
|
||||
|
||||
private String order_id;
|
||||
|
||||
private String log_no;
|
||||
|
||||
private String log_date;
|
||||
|
||||
private String merchant_no;
|
||||
|
||||
private Integer total_amt;
|
||||
|
||||
private Integer shopping_fee;
|
||||
|
||||
private BigDecimal split_ratio;
|
||||
|
||||
private String payment_time;
|
||||
|
||||
private String account_type;
|
||||
|
||||
private String trans_type;
|
||||
|
||||
private String lkl_trade_no;
|
||||
|
||||
private String lkl_term_no;
|
||||
|
||||
private String lkl_resp;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private Date created_at;
|
||||
|
||||
private Date updated_at;
|
||||
}
|
||||
@ -9,7 +9,6 @@
|
||||
package com.suisung.mall.shop.lakala.service;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.lkl.laop.sdk.request.V3SacsSeparateRequest;
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
import org.springframework.data.util.Pair;
|
||||
|
||||
@ -190,7 +189,8 @@ public interface LakalaApiService {
|
||||
* @param merchantNo 拉卡拉外部商户号
|
||||
* @param logNo 拉卡拉对账单流水号
|
||||
* @param logDate 拉卡拉对账单交易日期 yyyyMMdd
|
||||
* @return 响应结果 {
|
||||
* @return 响应结果 分账总金额,可分账金额 键值对
|
||||
* {
|
||||
* "merchant_no": "82229005943096D",
|
||||
* "total_separate_amt": "9900",
|
||||
* "can_separate_amt": "0",
|
||||
@ -198,15 +198,15 @@ public interface LakalaApiService {
|
||||
* "log_no": "66210306990190"
|
||||
* }
|
||||
*/
|
||||
JSONObject queryMchCanSplitAmt(String merchantNo, String logNo, String logDate);
|
||||
Pair<String, String> queryMchCanSplitAmt(String merchantNo, String logNo, String logDate);
|
||||
|
||||
/**
|
||||
* 拉卡拉订单分账,用户下单成功之后,进行分账
|
||||
* 说明:分账指令是异步处理模式,响应报文成功时,指令状态是”status”: “PROCESSING”,需要等待分账结果通知,或者主动发起查询,建议主动发起查询与分账指令动作之间间隔15秒以上。
|
||||
* 参考:https://o.lakala.com/#/home/document/detail?id=389
|
||||
*
|
||||
* @param v3SacsSeparateRequest
|
||||
* @param orderId 平台订单号
|
||||
* @return
|
||||
*/
|
||||
Pair<Boolean, String> innerDoOrderSeparate(V3SacsSeparateRequest v3SacsSeparateRequest);
|
||||
Pair<Boolean, String> innerDoOrderSeparate(String orderId);
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ public interface LklLedgerEcService extends IBaseService<LklLedgerEc> {
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
Boolean saveOrUpdateByMchId(LklLedgerEc record);
|
||||
Boolean addOrUpdateByMchId(LklLedgerEc record);
|
||||
|
||||
/**
|
||||
* 根据applyId更新记录
|
||||
|
||||
@ -36,7 +36,7 @@ public interface LklLedgerMemberService extends IBaseService<LklLedgerMember> {
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
Boolean saveOrUpdateByMerCupNo(LklLedgerMember record);
|
||||
Boolean addOrUpdateByMerCupNo(LklLedgerMember record);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -11,6 +11,8 @@ package com.suisung.mall.shop.lakala.service;
|
||||
import com.suisung.mall.common.modules.lakala.LklLedgerMerReceiverBind;
|
||||
import com.suisung.mall.core.web.service.IBaseService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface LklLedgerMerReceiverBindService extends IBaseService<LklLedgerMerReceiverBind> {
|
||||
|
||||
/**
|
||||
@ -19,10 +21,10 @@ public interface LklLedgerMerReceiverBindService extends IBaseService<LklLedgerM
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
Boolean saveOrUpdateByMerCupNoReceiverNo(LklLedgerMerReceiverBind record);
|
||||
Boolean addOrUpdateByMerCupNoReceiverNo(LklLedgerMerReceiverBind record);
|
||||
|
||||
/**
|
||||
* 根据接收方编号查询记录
|
||||
* 根据商户编号和接收方编号查询一条记录
|
||||
*
|
||||
* @param merCupNo
|
||||
* @param receiverNo
|
||||
@ -30,6 +32,16 @@ public interface LklLedgerMerReceiverBindService extends IBaseService<LklLedgerM
|
||||
*/
|
||||
LklLedgerMerReceiverBind getByCondition(String merCupNo, String receiverNo);
|
||||
|
||||
|
||||
/**
|
||||
* 根据商户编号查询多条记录
|
||||
*
|
||||
* @param merCupNo
|
||||
* @param isPlatform
|
||||
* @return
|
||||
*/
|
||||
List<LklLedgerMerReceiverBind> selectByMerCupNo(String merCupNo, Boolean isPlatform);
|
||||
|
||||
/**
|
||||
* 更新审核结果
|
||||
*
|
||||
|
||||
@ -22,7 +22,7 @@ public interface LklLedgerReceiverService extends IBaseService<LklLedgerReceiver
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
Boolean saveOrUpdateByReceiverNo(LklLedgerReceiver record);
|
||||
Boolean addOrUpdateByReceiverNo(LklLedgerReceiver record);
|
||||
|
||||
/**
|
||||
* 根据接收方编号查询记录
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
package com.suisung.mall.shop.lakala.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
@ -20,6 +21,7 @@ import com.lkl.laop.sdk.exception.SDKException;
|
||||
import com.lkl.laop.sdk.request.*;
|
||||
import com.lkl.laop.sdk.request.model.V3LabsTradeLocationInfo;
|
||||
import com.lkl.laop.sdk.request.model.V3LabsTradePreorderWechatBus;
|
||||
import com.lkl.laop.sdk.request.model.V3SacsSeparateRecvDatas;
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
import com.suisung.mall.common.constant.CommonConstant;
|
||||
import com.suisung.mall.common.exception.ApiException;
|
||||
@ -28,11 +30,13 @@ import com.suisung.mall.common.modules.lakala.LklLedgerEc;
|
||||
import com.suisung.mall.common.modules.lakala.LklLedgerMember;
|
||||
import com.suisung.mall.common.modules.lakala.LklLedgerMerReceiverBind;
|
||||
import com.suisung.mall.common.modules.lakala.LklLedgerReceiver;
|
||||
import com.suisung.mall.common.modules.order.ShopOrderLkl;
|
||||
import com.suisung.mall.common.modules.store.ShopMchEntry;
|
||||
import com.suisung.mall.common.modules.store.ShopStoreBase;
|
||||
import com.suisung.mall.common.utils.*;
|
||||
import com.suisung.mall.shop.lakala.service.*;
|
||||
import com.suisung.mall.shop.lakala.utils.LakalaUtil;
|
||||
import com.suisung.mall.shop.order.service.ShopOrderLklService;
|
||||
import com.suisung.mall.shop.page.service.OssService;
|
||||
import com.suisung.mall.shop.store.service.ShopMchEntryService;
|
||||
import com.suisung.mall.shop.store.service.ShopStoreBaseService;
|
||||
@ -114,6 +118,10 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
@Resource
|
||||
private ShopMchEntryService shopMchEntryService;
|
||||
|
||||
@Lazy
|
||||
@Resource
|
||||
private ShopOrderLklService shopOrderLklService;
|
||||
|
||||
// @Lazy
|
||||
// @Resource
|
||||
// private
|
||||
@ -558,7 +566,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
ecParams.put("A109", today.getDayOfMonth());
|
||||
ecParams.put("B1", today.getYear());
|
||||
ecParams.put("B3", "是");
|
||||
ecParams.put("B4", "是");
|
||||
// ecParams.put("B4", "是");
|
||||
ecParams.put("B2", today.getMonthValue());
|
||||
ecParams.put("B8", isQy ? shopMchEntry.getBiz_license_company() : shopMchEntry.getAccount_holder_name());
|
||||
ecParams.put("B9", StrUtil.sub(shopMchEntry.getSales_info(), 0, 22));
|
||||
@ -649,7 +657,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
record.setEc_apply_id(respData.getLong("ec_apply_id"));
|
||||
record.setResult_url(respData.getStr("result_url"));
|
||||
record.setResp_body(respBody.toString());
|
||||
Boolean success = lklLedgerEcService.saveOrUpdateByMchId(record);
|
||||
Boolean success = lklLedgerEcService.addOrUpdateByMchId(record);
|
||||
if (!success) {
|
||||
errMsg = "申请入网电子合同失败,数据保存失败";
|
||||
shopMchEntryService.updateMerchEntryApprovalByMchId(shopMchEntry.getId(), "", CommonConstant.MCH_APPR_STA_NOPASS, errMsg);
|
||||
@ -769,7 +777,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
// 新增数据
|
||||
// 将 JSON 对象的键名转换为下划线命名
|
||||
LklLedgerMember lklLedgerMemberNew = JSONUtil.toBean(StringUtils.convertCamelToSnake(paramsJSON.toString()), LklLedgerMember.class);
|
||||
if (!lklLedgerMemberService.saveOrUpdateByMerCupNo(lklLedgerMemberNew)) {
|
||||
if (!lklLedgerMemberService.addOrUpdateByMerCupNo(lklLedgerMemberNew)) {
|
||||
return Pair.of(false, I18nUtil._("商户分账业务材料新增失败,待审核中!"));
|
||||
}
|
||||
|
||||
@ -1346,7 +1354,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
LklLedgerReceiver.class
|
||||
);
|
||||
|
||||
if (!lklLedgerReceiverService.saveOrUpdateByReceiverNo(receiver)) {
|
||||
if (!lklLedgerReceiverService.addOrUpdateByReceiverNo(receiver)) {
|
||||
log.error("接收方创建成功,但更新本地数据失败!");
|
||||
return CommonResult.failed(I18nUtil._("接收方创建成功,但更新本地数据失败!"));
|
||||
}
|
||||
@ -1460,7 +1468,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
LklLedgerReceiver lklLedgerReceiver = JSONUtil.toBean(StringUtils.convertCamelToSnake(paramsJSON.toString()), LklLedgerReceiver.class);
|
||||
|
||||
// 新增或修改本地数据
|
||||
Boolean success = lklLedgerReceiverService.saveOrUpdateByReceiverNo(lklLedgerReceiver);
|
||||
Boolean success = lklLedgerReceiverService.addOrUpdateByReceiverNo(lklLedgerReceiver);
|
||||
if (!success) {
|
||||
log.error("接收方创建成功,但更新本地数据失败!");
|
||||
return CommonResult.failed(I18nUtil._("接收方创建成功,但更新本地数据失败!"));
|
||||
@ -1610,7 +1618,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
// 新增数据
|
||||
// 将 JSON 对象的键名转换为下划线命名
|
||||
LklLedgerMerReceiverBind lklLedgerMerReceiverBind = JSONUtil.toBean(StringUtils.convertCamelToSnake(paramsJSON.toString()), LklLedgerMerReceiverBind.class);
|
||||
if (lklLedgerMerReceiverBindService.saveOrUpdateByMerCupNoReceiverNo(lklLedgerMerReceiverBind)) {
|
||||
if (lklLedgerMerReceiverBindService.addOrUpdateByMerCupNoReceiverNo(lklLedgerMerReceiverBind)) {
|
||||
successCnt += 1;
|
||||
}
|
||||
// return Pair.of(true, "提交成功,待审核中!");
|
||||
@ -1717,12 +1725,13 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
paramsJSON.set("apply_id", respJson.getByPath("respData.applyId"));
|
||||
paramsJSON.set("receiver_no", receiver.getReceiver_no());
|
||||
paramsJSON.set("remark", respJson.getStr("retMsg"));
|
||||
paramsJSON.set("platform_id", receiver.getPlatform_id());
|
||||
|
||||
// 转换JSON键名格式并保存
|
||||
String snakeJson = StringUtils.convertCamelToSnake(paramsJSON.toString());
|
||||
LklLedgerMerReceiverBind bindRecord = JSONUtil.toBean(snakeJson, LklLedgerMerReceiverBind.class);
|
||||
|
||||
if (lklLedgerMerReceiverBindService.saveOrUpdateByMerCupNoReceiverNo(bindRecord)) {
|
||||
if (lklLedgerMerReceiverBindService.addOrUpdateByMerCupNoReceiverNo(bindRecord)) {
|
||||
successCount++;
|
||||
} else {
|
||||
log.warn("绑定记录保存失败:merCupNo={}, receiverNo={}", merCupNo, receiver.getReceiver_no());
|
||||
@ -1759,7 +1768,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
// 1. 验签处理(提前失败返回)
|
||||
String authorization = request.getHeader("Authorization");
|
||||
String requestBody = LakalaUtil.getBody(request);
|
||||
log.debug("回调参数:requestBody={}\nauthorization={}", requestBody, authorization);
|
||||
log.debug("回调参数:requestBody={}\n authorization={}", requestBody, authorization);
|
||||
|
||||
if (!LakalaUtil.verify(authorization, requestBody, lklNotifyCerPath)) {
|
||||
log.error("验签失败,拒绝处理回调");
|
||||
@ -1898,7 +1907,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
* }
|
||||
*/
|
||||
@Override
|
||||
public JSONObject queryMchCanSplitAmt(String merchantNo, String logNo, String logDate) {
|
||||
public Pair<String, String> queryMchCanSplitAmt(String merchantNo, String logNo, String logDate) {
|
||||
if (StringUtils.isAnyBlank(merchantNo, logNo, logDate)) {
|
||||
return null;
|
||||
}
|
||||
@ -1926,7 +1935,14 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (JSONObject) lklRespJSON.get("resp_data");
|
||||
JSONObject respData = (JSONObject) lklRespJSON.get("resp_data");
|
||||
if (respData == null
|
||||
|| StringUtils.isAnyBlank(respData.getStr("total_separate_amt"), respData.getStr("can_separate_amt"))) {
|
||||
log.error(I18nUtil._("返回值有误!"));
|
||||
return null;
|
||||
}
|
||||
|
||||
return Pair.of(respData.getStr("total_separate_amt"), respData.getStr("can_separate_amt"));
|
||||
} catch (SDKException e) {
|
||||
log.error("账户余额查询失败:", e);
|
||||
return null;
|
||||
@ -1938,38 +1954,123 @@ public class LakalaApiServiceImpl implements LakalaApiService {
|
||||
* 说明:分账指令是异步处理模式,响应报文成功时,指令状态是”status”: “PROCESSING”,需要等待分账结果通知,或者主动发起查询,建议主动发起查询与分账指令动作之间间隔15秒以上。
|
||||
* 参考:https://o.lakala.com/#/home/document/detail?id=389
|
||||
*
|
||||
* @param v3SacsSeparateRequest
|
||||
* @param orderId 平台订单Id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Pair<Boolean, String> innerDoOrderSeparate(V3SacsSeparateRequest v3SacsSeparateRequest) {
|
||||
if (v3SacsSeparateRequest == null) {
|
||||
return Pair.of(false, "分账参数不能为空");
|
||||
public Pair<Boolean, String> innerDoOrderSeparate(String orderId) {
|
||||
if (StrUtil.isBlank(orderId)) {
|
||||
return Pair.of(false, "订单号不能为空");
|
||||
}
|
||||
|
||||
// 1. 配置初始化
|
||||
initLKLSDK();
|
||||
|
||||
try {
|
||||
log.debug("分账执行请求参数:{}", JSONUtil.toJsonStr(v3SacsSeparateRequest));
|
||||
|
||||
//3. 发送请求
|
||||
String responseStr = LKLSDK.httpPost(v3SacsSeparateRequest);
|
||||
if (StrUtil.isBlank(responseStr)) {
|
||||
return Pair.of(false, "服务器无返回值!");
|
||||
// 1. 配置初始化
|
||||
initLKLSDK();
|
||||
|
||||
// 获取订单信息、店铺信息,商户信息、分账信息
|
||||
List<ShopOrderLkl> orderList = shopOrderLklService.selectByOrderId(orderId, "");
|
||||
if (CollectionUtil.isEmpty(orderList)) {
|
||||
return Pair.of(false, "订单不存在");
|
||||
}
|
||||
|
||||
JSONObject lklRespJSON = JSONUtil.parseObj(responseStr);
|
||||
if (lklRespJSON == null || !lklSacsSuccessCode.equals(lklRespJSON.getStr("code")) || lklRespJSON.get("resp_data") == null) {
|
||||
log.error("返回值有误!");
|
||||
return Pair.of(false, "返回值有误!");
|
||||
}
|
||||
|
||||
return Pair.of(true, "分账成功执行,处理中");
|
||||
for (ShopOrderLkl order : orderList) {
|
||||
String merchantNo = order.getMerchant_no();
|
||||
|
||||
// 分账总金额
|
||||
Integer paymentAmount = order.getTotal_amt();
|
||||
Integer shoppingFee = order.getShopping_fee();
|
||||
BigDecimal splitRatio = order.getSplit_ratio();
|
||||
if (paymentAmount <= 0 || (shoppingFee != null && paymentAmount - shoppingFee <= 0)) {
|
||||
return Pair.of(false, "订单金额有误");
|
||||
}
|
||||
|
||||
V3SacsSeparateRequest req = new V3SacsSeparateRequest();
|
||||
req.setMerchantNo(merchantNo);
|
||||
req.setLogNo(orderId);
|
||||
req.setLogDate(order.getLog_date());
|
||||
req.setOutSeparateNo(StringUtils.genLklOrderNo(18)); // 14+18=32位商户分账指令流水号,每个商户号下唯一,否则会校验失败
|
||||
req.setTotalAmt(order.getTotal_amt().toString());
|
||||
req.setLklOrgNo(orgCode);
|
||||
req.setCalType("0"); // 0- 按照指定金额,1- 按照指定比例。默认 0
|
||||
req.setNotifyUrl(projectDomain + "/api/v1/lkl/order/separate/notify");
|
||||
|
||||
|
||||
List<LklLedgerMerReceiverBind> platformList = lklLedgerMerReceiverBindService.selectByMerCupNo(merchantNo, true);
|
||||
List<LklLedgerMerReceiverBind> distributorList = lklLedgerMerReceiverBindService.selectByMerCupNo(merchantNo, false);
|
||||
if (CollectionUtil.isEmpty(platformList)) {
|
||||
return Pair.of(false, "商户未绑定分账平台方");
|
||||
}
|
||||
|
||||
|
||||
List<V3SacsSeparateRecvDatas> recvDatas = new ArrayList<>();
|
||||
|
||||
|
||||
// 是否有运费
|
||||
if (shoppingFee != null && shoppingFee > 0) {
|
||||
V3SacsSeparateRecvDatas recvData = new V3SacsSeparateRecvDatas();
|
||||
recvData.setRecvNo(platformList.get(0).getReceiver_no());
|
||||
recvData.setSeparateValue(shoppingFee.toString()); // 分账金额,单位分,分账金额不能大于订单金额,分账金额不能小于0
|
||||
recvDatas.add(recvData);
|
||||
}
|
||||
|
||||
Integer splitAmount = paymentAmount - shoppingFee;
|
||||
if (!CollectionUtils.isEmpty(distributorList)
|
||||
&& (splitRatio != null && splitRatio.compareTo(BigDecimal.ONE) > 0)) {
|
||||
// 平台方分账
|
||||
BigDecimal separateValue = new BigDecimal(splitAmount).multiply(new BigDecimal("0.01")); // 平台收取1%手续费
|
||||
if (separateValue.compareTo(BigDecimal.ZERO) > 0) {
|
||||
V3SacsSeparateRecvDatas recvData = new V3SacsSeparateRecvDatas();
|
||||
recvData.setRecvNo(platformList.get(0).getReceiver_no());
|
||||
recvData.setSeparateValue(separateValue.toString()); // 分账金额,单位分,分账金额不能大于订单金额,分账金额不能小于0
|
||||
recvDatas.add(recvData);
|
||||
}
|
||||
|
||||
// 代理方分账, 100-1-splitRatio 1%是平台方的,其余都是代理商的
|
||||
BigDecimal separateValue2 = new BigDecimal(splitAmount).multiply(new BigDecimal(99).subtract(splitRatio).divide(new BigDecimal(100)));
|
||||
if (separateValue.compareTo(BigDecimal.ZERO) > 0) {
|
||||
V3SacsSeparateRecvDatas recvData2 = new V3SacsSeparateRecvDatas();
|
||||
recvData2.setRecvNo(distributorList.get(0).getReceiver_no());
|
||||
recvData2.setSeparateValue(separateValue2.toString()); // 分账金额,单位分,分账金额不能大于订单金额,分账金额不能小于0
|
||||
recvDatas.add(recvData2);
|
||||
}
|
||||
} else {
|
||||
// 仅平台方一方分账
|
||||
BigDecimal separateValue = new BigDecimal(splitAmount).multiply(new BigDecimal(100).subtract(splitRatio).divide(new BigDecimal(100)));
|
||||
if (separateValue.compareTo(BigDecimal.ZERO) > 0) {
|
||||
V3SacsSeparateRecvDatas recvData = new V3SacsSeparateRecvDatas();
|
||||
recvData.setRecvNo(platformList.get(0).getReceiver_no());
|
||||
recvData.setSeparateValue(separateValue.toString()); // 分账金额,单位分,分账金额不能大于订单金额,分账金额不能小于0
|
||||
recvDatas.add(recvData);
|
||||
}
|
||||
}
|
||||
|
||||
req.setRecvDatas(recvDatas);
|
||||
|
||||
|
||||
log.debug("分账执行请求参数:{}", JSONUtil.toJsonStr(req));
|
||||
|
||||
//3. 发送请求
|
||||
String responseStr = LKLSDK.httpPost(req);
|
||||
if (StrUtil.isBlank(responseStr)) {
|
||||
return Pair.of(false, "服务器无返回值!");
|
||||
}
|
||||
|
||||
JSONObject lklRespJSON = JSONUtil.parseObj(responseStr);
|
||||
if (lklRespJSON == null || !lklSacsSuccessCode.equals(lklRespJSON.getStr("code")) || lklRespJSON.get("resp_data") == null) {
|
||||
log.error("分账返回值有误!");
|
||||
return Pair.of(false, "返回值有误!");
|
||||
}
|
||||
|
||||
return Pair.of(true, "分账成功执行,处理中");
|
||||
}
|
||||
} catch (SDKException e) {
|
||||
log.error("分账发生错误:", e);
|
||||
return Pair.of(false, "分账发生错误");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ public class LklLedgerEcServiceImpl extends BaseServiceImpl<LklLedgerEcMapper, L
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean saveOrUpdateByMchId(LklLedgerEc record) {
|
||||
public Boolean addOrUpdateByMchId(LklLedgerEc record) {
|
||||
if (record == null || (ObjectUtil.isEmpty(record.getMch_id()) && StrUtil.isBlank(record.getMch_mobile()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ public class LklLedgerMemberServiceImpl extends BaseServiceImpl<LklLedgerMemberM
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean saveOrUpdateByMerCupNo(LklLedgerMember record) {
|
||||
public Boolean addOrUpdateByMerCupNo(LklLedgerMember record) {
|
||||
if (record == null || StrUtil.isBlank(record.getMer_cup_no())) {
|
||||
return false;
|
||||
}
|
||||
@ -123,5 +123,5 @@ public class LklLedgerMemberServiceImpl extends BaseServiceImpl<LklLedgerMemberM
|
||||
|
||||
return update(updateWrapper);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ public class LklLedgerMerReceiverBindServiceImpl extends BaseServiceImpl<LklLedg
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean saveOrUpdateByMerCupNoReceiverNo(LklLedgerMerReceiverBind record) {
|
||||
public Boolean addOrUpdateByMerCupNoReceiverNo(LklLedgerMerReceiverBind record) {
|
||||
if (record == null || StrUtil.isBlank(record.getMer_cup_no()) || StrUtil.isBlank(record.getReceiver_no())) {
|
||||
return false;
|
||||
}
|
||||
@ -51,6 +51,14 @@ public class LklLedgerMerReceiverBindServiceImpl extends BaseServiceImpl<LklLedg
|
||||
return add(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商户编号和接收方编号查询一条记录
|
||||
*
|
||||
* @param merCupNo
|
||||
* @param receiverNo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public LklLedgerMerReceiverBind getByCondition(String merCupNo, String receiverNo) {
|
||||
if (StrUtil.isBlank(merCupNo) || StrUtil.isBlank(receiverNo)) {
|
||||
return null;
|
||||
@ -61,10 +69,36 @@ public class LklLedgerMerReceiverBindServiceImpl extends BaseServiceImpl<LklLedg
|
||||
.eq("receiver_no", receiverNo)
|
||||
.eq("audit_status", CommonConstant.Enable);
|
||||
|
||||
|
||||
return getOne(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商户编号查询多条记录
|
||||
*
|
||||
* @param merCupNo
|
||||
* @param isPlatform 是否平台
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<LklLedgerMerReceiverBind> selectByMerCupNo(String merCupNo, Boolean isPlatform) {
|
||||
if (StrUtil.isBlank(merCupNo)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
QueryWrapper<LklLedgerMerReceiverBind> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("mer_cup_no", merCupNo)
|
||||
.eq("audit_status", CommonConstant.Enable);
|
||||
if (isPlatform != null && isPlatform) {
|
||||
queryWrapper.eq("platform_id", 0);
|
||||
} else if (isPlatform != null && !isPlatform) {
|
||||
queryWrapper.gt("platform_id", 0);
|
||||
}
|
||||
|
||||
queryWrapper.orderByAsc("id");
|
||||
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新审核结果
|
||||
*
|
||||
@ -111,7 +145,7 @@ public class LklLedgerMerReceiverBindServiceImpl extends BaseServiceImpl<LklLedg
|
||||
if (StrUtil.isNotBlank(remark)) {
|
||||
updateWrapper.set("remark", remark);
|
||||
}
|
||||
|
||||
|
||||
return update(updateWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ public class LklLedgerReceiverServiceImpl extends BaseServiceImpl<LklLedgerRecei
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean saveOrUpdateByReceiverNo(LklLedgerReceiver record) {
|
||||
public Boolean addOrUpdateByReceiverNo(LklLedgerReceiver record) {
|
||||
if (record == null || (StrUtil.isBlank(record.getLicense_no()) && StrUtil.isBlank(record.getContact_mobile()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -627,24 +627,25 @@ public class LklTkServiceImpl {
|
||||
// TODO 新建一个正式的已审核通过的店铺, 新建之前判断是否已经新建过了?
|
||||
// 新建一个正式的已审核通过的店铺,不要抛异常,使用补偿机制,可以独立初始化店铺
|
||||
ShopMchEntry shopEntry = shopMchEntryService.getShopMerchEntryByMerCupNo(merCupNo);
|
||||
if (shopEntry != null && !CommonConstant.Enable.equals(shopEntry.getStore_status())) {
|
||||
String mchMobile = shopEntry.getLogin_mobile();
|
||||
Pair<Integer, String> retPair = shopStoreBaseService.merchEntryInfo2StoreInfo(mchMobile);
|
||||
|
||||
if (retPair.getFirst() > 0) {
|
||||
// 2025-05-17暂停e签宝电子合同生成流程
|
||||
// 更改合同记录表的店铺id
|
||||
// esignContractService.updateContractStoreId(mchMobile, retPair.getFirst());
|
||||
// 填充合同模版表的店铺Id
|
||||
// esignContractFillingFileService.updateContractFillingStoreId(mchMobile, retPair.getFirst());
|
||||
// 店铺创建状态已完成
|
||||
shopMchEntryService.updateMerchEntryStoreStatus(mchMobile, CommonConstant.Enable);
|
||||
logger.info("商家进件:初始化店铺成功!");
|
||||
} else {
|
||||
logger.error("商家进件:初始化店铺失败!");
|
||||
// throw new ApiException("商家进件:初始化店铺失败!");
|
||||
}
|
||||
}
|
||||
// if (shopEntry != null && !CommonConstant.Enable.equals(shopEntry.getStore_status())) {
|
||||
// String mchMobile = shopEntry.getLogin_mobile();
|
||||
// // 禁止往外抛异常,如果失败使用补偿机制,创建新店
|
||||
// Pair<Integer, String> retPair = shopStoreBaseService.merchEntryInfo2StoreInfo(mchMobile, false);
|
||||
//
|
||||
// if (retPair.getFirst() > 0) {
|
||||
// // 2025-05-17暂停e签宝电子合同生成流程
|
||||
// // 更改合同记录表的店铺id
|
||||
// // esignContractService.updateContractStoreId(mchMobile, retPair.getFirst());
|
||||
// // 填充合同模版表的店铺Id
|
||||
// // esignContractFillingFileService.updateContractFillingStoreId(mchMobile, retPair.getFirst());
|
||||
// // 店铺创建状态已完成
|
||||
// shopMchEntryService.updateMerchEntryStoreStatus(mchMobile, CommonConstant.Enable);
|
||||
// logger.info("商家进件:初始化店铺成功!");
|
||||
// } else {
|
||||
// logger.error("商家进件:初始化店铺失败!");
|
||||
// // throw new ApiException("商家进件:初始化店铺失败!");
|
||||
// }
|
||||
// }
|
||||
|
||||
// 1、(电子合同)给商家申请分账功能使用;务必检查是否申请过?申请过忽略
|
||||
// 下一步等待拉卡拉审核通过,再绑定接收方和商家的关系
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* 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.order.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.suisung.mall.common.modules.order.ShopOrderLkl;
|
||||
|
||||
public interface ShopOrderLklMapper extends BaseMapper<ShopOrderLkl> {
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.order.service;
|
||||
|
||||
import com.suisung.mall.common.modules.order.ShopOrderLkl;
|
||||
import com.suisung.mall.core.web.service.IBaseService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ShopOrderLklService extends IBaseService<ShopOrderLkl> {
|
||||
|
||||
/**
|
||||
* 添加或更新记录
|
||||
*
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
Boolean addOrUpdateByStoreOrder(ShopOrderLkl record);
|
||||
|
||||
/**
|
||||
* 根据订单编号查询多条记录(因为一个订单里可能有多个店铺的商品)
|
||||
*
|
||||
* @param orderId
|
||||
* @param storeId
|
||||
* @return
|
||||
*/
|
||||
List<ShopOrderLkl> selectByOrderId(String orderId, String storeId);
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.order.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.suisung.mall.common.modules.order.ShopOrderLkl;
|
||||
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
||||
import com.suisung.mall.shop.order.mapper.ShopOrderLklMapper;
|
||||
import com.suisung.mall.shop.order.service.ShopOrderLklService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ShopOrderLklServiceImpl extends BaseServiceImpl<ShopOrderLklMapper, ShopOrderLkl> implements ShopOrderLklService {
|
||||
|
||||
@Override
|
||||
public Boolean addOrUpdateByStoreOrder(ShopOrderLkl record) {
|
||||
if (record == null
|
||||
|| StringUtils.isAnyBlank(record.getOrder_id(), record.getStore_id(), record.getLog_no())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<ShopOrderLkl> existsRecordList = selectByOrderId(record.getOrder_id(), record.getStore_id());
|
||||
if (CollectionUtil.isNotEmpty(existsRecordList)
|
||||
&& existsRecordList.get(0) != null
|
||||
&& existsRecordList.get(0).getId() > 0) {
|
||||
// 更新记录
|
||||
record.setId(existsRecordList.get(0).getId());
|
||||
return updateById(record);
|
||||
}
|
||||
|
||||
return add(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据订单编号查询多条记录(因为一个订单里可能有多个店铺的商品)
|
||||
*
|
||||
* @param orderId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<ShopOrderLkl> selectByOrderId(String orderId, String storeId) {
|
||||
if (StringUtils.isBlank(orderId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
QueryWrapper<ShopOrderLkl> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("order_id", orderId);
|
||||
if (StrUtil.isNotBlank(storeId)) {
|
||||
queryWrapper.eq("store_id", storeId);
|
||||
}
|
||||
|
||||
return list(queryWrapper);
|
||||
}
|
||||
}
|
||||
@ -254,7 +254,7 @@ public class ShopStoreBaseController extends BaseControllerImpl {
|
||||
@ApiOperation(value = "商家入驻资料转成店铺", notes = "商家入驻资料转成店铺")
|
||||
@RequestMapping(value = "/mchinfo/to/storeinfo", method = RequestMethod.POST)
|
||||
public CommonResult merchEntryInfo2StoreInfo(@RequestBody JSONObject jsonParam) {
|
||||
Pair<Integer, String> result = shopStoreBaseService.merchEntryInfo2StoreInfo(jsonParam.getStr("mchMobile"));
|
||||
Pair<Integer, String> result = shopStoreBaseService.merchEntryInfo2StoreInfo(jsonParam.getStr("mchMobile"), true);
|
||||
if (result.getFirst().equals(0)) {
|
||||
return CommonResult.failed(result.getSecond());
|
||||
}
|
||||
|
||||
@ -141,9 +141,10 @@ public interface ShopStoreBaseService extends IBaseService<ShopStoreBase> {
|
||||
* (重要)入驻审批通过并且合同盖章完结之后,把商家入驻信息转换成店铺信息,正式生成店铺所需的数据
|
||||
*
|
||||
* @param mchMobile
|
||||
* @param allowThrown 是否允许抛出异常
|
||||
* @return 店铺Id
|
||||
*/
|
||||
Pair<Integer, String> merchEntryInfo2StoreInfo(String mchMobile);
|
||||
Pair<Integer, String> merchEntryInfo2StoreInfo(String mchMobile, Boolean allowThrown);
|
||||
|
||||
/**
|
||||
* 根据店铺名称判断店铺是否存在
|
||||
|
||||
@ -2991,11 +2991,12 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
|
||||
* (重要)入驻审批通过并且合同盖章完结之后,把商家入驻信息转换成店铺信息,正式生成店铺所需的数据
|
||||
*
|
||||
* @param mchMobile
|
||||
* @param allowThrown 是否允许抛出异常?
|
||||
* @return 店铺Id
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public Pair<Integer, String> merchEntryInfo2StoreInfo(String mchMobile) {
|
||||
public Pair<Integer, String> merchEntryInfo2StoreInfo(String mchMobile, Boolean allowThrown) {
|
||||
if (StrUtil.isBlank(mchMobile)) {
|
||||
logger.error("生成店铺:商家手机号不能为空");
|
||||
return Pair.of(0, "商家手机不能为空");
|
||||
@ -3071,7 +3072,10 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
|
||||
shopStoreBase.setStore_end_time(System.currentTimeMillis() + 1000L * 60 * 60 * 24 * 365 * 5); // 5年
|
||||
if (!save(shopStoreBase)) {
|
||||
logger.error("生成店铺:新增店铺基本信息失败");
|
||||
throw new ApiException(I18nUtil._("新增店铺基础信息失败"));
|
||||
if (allowThrown) {
|
||||
throw new ApiException(I18nUtil._("新增店铺基础信息失败"));
|
||||
}
|
||||
return Pair.of(0, "新增店铺基础信息失败");
|
||||
}
|
||||
|
||||
// 保存后店铺Id
|
||||
@ -3110,7 +3114,10 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
|
||||
shopStoreInfo.setStore_state_id(StateCode.STORE_STATE_YES);
|
||||
if (!shopStoreInfoService.save(shopStoreInfo)) {
|
||||
logger.error("生成店铺:新增店铺info失败");
|
||||
throw new ApiException(I18nUtil._("新增店铺信息失败"));
|
||||
if (allowThrown) {
|
||||
throw new ApiException(I18nUtil._("新增店铺信息失败"));
|
||||
}
|
||||
return Pair.of(0, "新增店铺信息失败");
|
||||
}
|
||||
|
||||
// 初始化默认公司信息,避免商家编辑不了,申请入驻即使是个人类型的,也需要保存相关应有信息,公司信息不能空着
|
||||
@ -3157,7 +3164,11 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
|
||||
|
||||
if (!shopStoreCompanyService.save(shopStoreCompany)) {
|
||||
logger.error("生成店铺:新增店铺公司失败");
|
||||
throw new ApiException(I18nUtil._("新增店铺公司失败"));
|
||||
if (allowThrown) {
|
||||
throw new ApiException(I18nUtil._("新增店铺公司失败"));
|
||||
}
|
||||
|
||||
return Pair.of(0, "新增店铺公司失败");
|
||||
}
|
||||
|
||||
// shop_store_employee 店铺员工,添加管理员
|
||||
@ -3170,7 +3181,11 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
|
||||
shopStoreEmployeeService.save(shopStoreEmployee);
|
||||
if (!shopStoreEmployeeService.save(shopStoreEmployee)) {
|
||||
logger.error("生成店铺:新增店铺员工失败");
|
||||
throw new ApiException(I18nUtil._("新增店铺员工失败"));
|
||||
if (allowThrown) {
|
||||
throw new ApiException(I18nUtil._("新增店铺员工失败"));
|
||||
}
|
||||
|
||||
return Pair.of(0, "新增店铺员工失败");
|
||||
}
|
||||
|
||||
// 生成店铺的太阳码 2025-03-31
|
||||
@ -3190,6 +3205,9 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
|
||||
return Pair.of(storeId, "新增成功");
|
||||
} catch (Exception e) {
|
||||
logger.error("店铺生成失败", e);
|
||||
if (allowThrown) {
|
||||
throw new ApiException(I18nUtil._("新增店铺失败"));
|
||||
}
|
||||
return Pair.of(0, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.suisung.mall.shop.order.mapper.ShopOrderLklMapper">
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
*
|
||||
</sql>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user