|
|
@@ -34,10 +34,8 @@ import com.fs.course.config.RedPacketConfig;
|
|
|
import com.fs.course.service.IFsCourseRedPacketLogService;
|
|
|
import com.fs.course.service.IFsUserCourseOrderService;
|
|
|
import com.fs.course.service.IFsUserVipOrderService;
|
|
|
-import com.fs.his.domain.FsPayConfig;
|
|
|
-import com.fs.his.domain.FsStorePayment;
|
|
|
-import com.fs.his.domain.FsUser;
|
|
|
-import com.fs.his.domain.FsUserWx;
|
|
|
+import com.fs.course.service.impl.FsCoursePlaySourceConfigServiceImpl;
|
|
|
+import com.fs.his.domain.*;
|
|
|
import com.fs.his.dto.PayConfigDTO;
|
|
|
import com.fs.his.enums.PaymentMethodEnum;
|
|
|
import com.fs.his.mapper.*;
|
|
|
@@ -91,6 +89,7 @@ import com.google.gson.Gson;
|
|
|
import com.hc.openapi.tool.fastjson.JSON;
|
|
|
import io.netty.util.internal.StringUtil;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -107,6 +106,8 @@ import java.lang.reflect.Field;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 支付明细Service业务层处理
|
|
|
@@ -196,6 +197,12 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
*/
|
|
|
private static final String REDPACKET_COMPANY_MONEY = "redpacket_money";
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 微信商户号对应的配置key
|
|
|
+ * */
|
|
|
+ private static final String WX_MCH_CONFIG_KEY = "sys_config:redPacket.wx_mchConfig:";
|
|
|
+
|
|
|
/**
|
|
|
* 用户领取红包限制
|
|
|
*/
|
|
|
@@ -204,6 +211,12 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysRedpacketConfigMoreMapper sysRedpacketConfigMoreMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsCoursePlaySourceConfigServiceImpl coursePlaySourceConfigService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 查询支付明细
|
|
|
@@ -554,7 +567,16 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
if (StringUtil.isNullOrEmpty(json) || json.isEmpty()) {
|
|
|
json = configService.selectConfigByKey("redPacket.config");
|
|
|
}
|
|
|
- config = JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
+ //这里开始优先取多小程序配置的所属微信商户号
|
|
|
+ String mchId = coursePlaySourceConfigService.getMchIdByAppId(param.getAppId());
|
|
|
+ if (mchId != null) {
|
|
|
+ //读取指定的定商户号配置
|
|
|
+ config=getMchConfig(mchId);
|
|
|
+ logger.info("发放红包的小程序appId:{},商户号:{}",param.getAppId(),mchId);
|
|
|
+ }else {
|
|
|
+ //读取默认商户号配置
|
|
|
+ config = JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
+ }
|
|
|
break;
|
|
|
case 2:
|
|
|
json = companyConfigService.selectRedPacketConfigByKey(param.getCompanyId());
|
|
|
@@ -591,6 +613,35 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据商户号获取商户号配置(单 Key 缓存版)
|
|
|
+ * 缓存 Key 格式:sys_config:redPacket.wx_mchConfig: + mchId
|
|
|
+ * 缓存 Value:RedPacketConfig 对应的 JSON 字符串
|
|
|
+ */
|
|
|
+ public RedPacketConfig getMchConfig(String mchId) {
|
|
|
+ String cacheKey = WX_MCH_CONFIG_KEY + mchId;
|
|
|
+
|
|
|
+ // 1. 从缓存读取 JSON 字符串
|
|
|
+ String json = redisCache.getCacheObject(cacheKey);
|
|
|
+ if (StringUtils.isNotBlank(json)) {
|
|
|
+ return JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 缓存未命中,查数据库
|
|
|
+ SysRedpacketConfigMore configMore = sysRedpacketConfigMoreMapper.getSysRedpacketConfigByMchId(mchId);
|
|
|
+ if (configMore == null) {
|
|
|
+ logger.error("商户号配置不存在, mchId: {}", mchId);
|
|
|
+ throw new CustomException("您刚刚发起提现,请稍后再试!!!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 序列化为 JSON 字符串并存入缓存
|
|
|
+ String configJson = JSONUtil.toJsonStr(configMore);
|
|
|
+ redisCache.setCacheObject(cacheKey, configJson);
|
|
|
+
|
|
|
+ // 4. 返回 RedPacketConfig 对象(利用字段名一致的特性自动映射)
|
|
|
+ return JSONUtil.toBean(configJson, RedPacketConfig.class);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
|
|
|
public R sendRedPacketAppReward(WxSendRedPacketParam param) {
|