mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-30 11:11:55 +08:00
!979 MEMBER: 根据【代码评审】完善微信小程序码。 修复获得个人分销统计 NPE 异常
Merge pull request !979 from puhui999/develop
This commit is contained in:
commit
2d44b3a245
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.trade.controller.app.brokerage;
|
package cn.iocoder.yudao.module.trade.controller.app.brokerage;
|
||||||
|
|
||||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
|
import cn.hutool.core.util.ObjUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
||||||
@ -10,6 +11,8 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*;
|
|||||||
import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert;
|
import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert;
|
||||||
import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageUserConvert;
|
import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageUserConvert;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
|
||||||
|
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
|
||||||
|
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageEnabledConditionEnum;
|
||||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
|
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
|
||||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
|
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
|
||||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
|
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
|
||||||
@ -17,16 +20,17 @@ import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
|
|||||||
import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService;
|
import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService;
|
||||||
import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService;
|
import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService;
|
||||||
import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSummaryRespBO;
|
import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSummaryRespBO;
|
||||||
|
import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -50,7 +54,8 @@ public class AppBrokerageUserController {
|
|||||||
private BrokerageRecordService brokerageRecordService;
|
private BrokerageRecordService brokerageRecordService;
|
||||||
@Resource
|
@Resource
|
||||||
private BrokerageWithdrawService brokerageWithdrawService;
|
private BrokerageWithdrawService brokerageWithdrawService;
|
||||||
|
@Resource
|
||||||
|
private TradeConfigService tradeConfigService;
|
||||||
@Resource
|
@Resource
|
||||||
private MemberUserApi memberUserApi;
|
private MemberUserApi memberUserApi;
|
||||||
|
|
||||||
@ -59,9 +64,13 @@ public class AppBrokerageUserController {
|
|||||||
@PreAuthenticated
|
@PreAuthenticated
|
||||||
public CommonResult<AppBrokerageUserRespVO> getBrokerageUser() {
|
public CommonResult<AppBrokerageUserRespVO> getBrokerageUser() {
|
||||||
Optional<BrokerageUserDO> user = Optional.ofNullable(brokerageUserService.getBrokerageUser(getLoginUserId()));
|
Optional<BrokerageUserDO> user = Optional.ofNullable(brokerageUserService.getBrokerageUser(getLoginUserId()));
|
||||||
|
// 获得交易中心配置
|
||||||
|
TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig();
|
||||||
|
// 如果是人人分佣 BrokerageUserDO 为 null 时,也有分销资格
|
||||||
|
boolean brokerageEnabled = ObjUtil.equal(BrokerageEnabledConditionEnum.ALL.getCondition(), tradeConfig.getBrokerageEnabledCondition());
|
||||||
// 返回数据
|
// 返回数据
|
||||||
AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO()
|
AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO()
|
||||||
.setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(false))
|
.setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(brokerageEnabled))
|
||||||
.setBrokeragePrice(user.map(BrokerageUserDO::getBrokeragePrice).orElse(0))
|
.setBrokeragePrice(user.map(BrokerageUserDO::getBrokeragePrice).orElse(0))
|
||||||
.setFrozenPrice(user.map(BrokerageUserDO::getFrozenPrice).orElse(0));
|
.setFrozenPrice(user.map(BrokerageUserDO::getFrozenPrice).orElse(0));
|
||||||
return success(respVO);
|
return success(respVO);
|
||||||
@ -79,21 +88,22 @@ public class AppBrokerageUserController {
|
|||||||
@PreAuthenticated
|
@PreAuthenticated
|
||||||
public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() {
|
public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() {
|
||||||
// 查询当前登录用户信息
|
// 查询当前登录用户信息
|
||||||
BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(getLoginUserId());
|
Long userId = getLoginUserId();
|
||||||
|
BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(userId);
|
||||||
// 统计用户昨日的佣金
|
// 统计用户昨日的佣金
|
||||||
LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
|
LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
|
||||||
LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday);
|
LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday);
|
||||||
LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
|
LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
|
||||||
Integer yesterdayPrice = brokerageRecordService.getSummaryPriceByUserId(brokerageUser.getId(),
|
Integer yesterdayPrice = brokerageRecordService.getSummaryPriceByUserId(userId,
|
||||||
BrokerageRecordBizTypeEnum.ORDER, BrokerageRecordStatusEnum.SETTLEMENT, beginTime, endTime);
|
BrokerageRecordBizTypeEnum.ORDER, BrokerageRecordStatusEnum.SETTLEMENT, beginTime, endTime);
|
||||||
// 统计用户提现的佣金
|
// 统计用户提现的佣金
|
||||||
Integer withdrawPrice = brokerageWithdrawService.getWithdrawSummaryListByUserId(Collections.singleton(brokerageUser.getId()),
|
Integer withdrawPrice = brokerageWithdrawService.getWithdrawSummaryListByUserId(Collections.singleton(userId),
|
||||||
BrokerageWithdrawStatusEnum.AUDIT_SUCCESS).stream()
|
BrokerageWithdrawStatusEnum.AUDIT_SUCCESS).stream()
|
||||||
.findFirst().map(BrokerageWithdrawSummaryRespBO::getPrice).orElse(0);
|
.findFirst().map(BrokerageWithdrawSummaryRespBO::getPrice).orElse(0);
|
||||||
// 统计分销用户数量(一级)
|
// 统计分销用户数量(一级)
|
||||||
Long firstBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(brokerageUser.getId(), 1);
|
Long firstBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1);
|
||||||
// 统计分销用户数量(二级)
|
// 统计分销用户数量(二级)
|
||||||
Long secondBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(brokerageUser.getId(), 2);
|
Long secondBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2);
|
||||||
|
|
||||||
// 拼接返回
|
// 拼接返回
|
||||||
return success(BrokerageUserConvert.INSTANCE.convert(yesterdayPrice, withdrawPrice, firstBrokerageUserCount, secondBrokerageUserCount, brokerageUser));
|
return success(BrokerageUserConvert.INSTANCE.convert(yesterdayPrice, withdrawPrice, firstBrokerageUserCount, secondBrokerageUserCount, brokerageUser));
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.member.controller.app.social;
|
package cn.iocoder.yudao.module.member.controller.app.social;
|
||||||
|
|
||||||
|
import cn.hutool.core.codec.Base64;
|
||||||
|
import cn.hutool.core.util.ObjUtil;
|
||||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
@ -22,8 +24,6 @@ import jakarta.validation.Valid;
|
|||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
|
|
||||||
@ -33,6 +33,13 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
|
|||||||
@Validated
|
@Validated
|
||||||
public class AppSocialUserController {
|
public class AppSocialUserController {
|
||||||
|
|
||||||
|
public static final String ENV_VERSION = "release"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
|
||||||
|
private static final String SCENE = ""; // 页面路径不能携带参数(参数请放在scene字段里)
|
||||||
|
private static final Integer WIDTH = 430; // 二维码宽度
|
||||||
|
private static final Boolean AUTO_COLOR = true; // 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
|
||||||
|
private static final Boolean CHECK_PATH = true; // 默认true 检查 page 是否存在
|
||||||
|
private static final Boolean HYALINE = true; // 是否需要透明底色, hyaline 为true时,生成透明底色的小程序码
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SocialUserApi socialUserApi;
|
private SocialUserApi socialUserApi;
|
||||||
@Resource
|
@Resource
|
||||||
@ -69,10 +76,13 @@ public class AppSocialUserController {
|
|||||||
@PostMapping("/wxa-qrcode")
|
@PostMapping("/wxa-qrcode")
|
||||||
@Operation(summary = "获得微信小程序码(base64 image)")
|
@Operation(summary = "获得微信小程序码(base64 image)")
|
||||||
public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) {
|
public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) {
|
||||||
byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class)
|
byte[] wxQrcode = socialClientApi.getWxaQrcode(new SocialWxQrcodeReqDTO().setPath(reqVO.getPath())
|
||||||
.setEnvVersion(AppSocialWxQrcodeReqVO.ENV_VERSION));
|
.setEnvVersion(ENV_VERSION).setWidth(ObjUtil.defaultIfNull(reqVO.getWidth(), WIDTH))
|
||||||
// TODO @puhui999:1)是不是 base64 返回,不拼接哈 data:image/png;base64;2)cn.hutool.core.codec.Base64.encode()
|
.setScene(ObjUtil.defaultIfNull(reqVO.getScene(), SCENE))
|
||||||
return success("data:image/png;base64," + Base64.getEncoder().encodeToString(wxQrcode));
|
.setAutoColor(ObjUtil.defaultIfNull(reqVO.getAutoColor(), AUTO_COLOR))
|
||||||
|
.setHyaline(ObjUtil.defaultIfNull(reqVO.getHyaline(), HYALINE))
|
||||||
|
.setCheckPath(ObjUtil.defaultIfNull(reqVO.getCheckPath(), CHECK_PATH)));
|
||||||
|
return success(Base64.encode(wxQrcode));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,20 +9,11 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class AppSocialWxQrcodeReqVO {
|
public class AppSocialWxQrcodeReqVO {
|
||||||
|
|
||||||
// TODO @puhui999: 没有默认值 getQrcodeService().createWxaCodeUnlimitBytes() 转类型会报错 🤣
|
|
||||||
// TODO @puhui999:懂了哈;default 最好在 controller 搞;对于 VO 来说,不给默认值;
|
|
||||||
public static String ENV_VERSION = "release"; // 小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
|
|
||||||
private static String SCENE = ""; // 页面路径不能携带参数(参数请放在scene字段里)
|
|
||||||
private static Integer WIDTH = 430; // 二维码宽度
|
|
||||||
private static Boolean AUTO_COLOR = true; // 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
|
|
||||||
private static Boolean CHECK_PATH = true; // 默认true 检查 page 是否存在
|
|
||||||
private static Boolean HYALINE = true; // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 页面路径不能携带参数(参数请放在scene字段里)
|
* 页面路径不能携带参数(参数请放在scene字段里)
|
||||||
*/
|
*/
|
||||||
@Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
|
@Schema(description = "场景值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
|
||||||
private String scene = SCENE;
|
private String scene;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,不能携带参数(参数请放在scene字段里),
|
* 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,不能携带参数(参数请放在scene字段里),
|
||||||
@ -33,15 +24,15 @@ public class AppSocialWxQrcodeReqVO {
|
|||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
@Schema(description = "二维码宽度", requiredMode = Schema.RequiredMode.REQUIRED, example = "430")
|
@Schema(description = "二维码宽度", requiredMode = Schema.RequiredMode.REQUIRED, example = "430")
|
||||||
private Integer width = WIDTH;
|
private Integer width;
|
||||||
|
|
||||||
@Schema(description = "是/否自动配置线条颜色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
@Schema(description = "是/否自动配置线条颜色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
||||||
private Boolean autoColor = AUTO_COLOR;
|
private Boolean autoColor;
|
||||||
|
|
||||||
@Schema(description = "是/否检查 page 是否存在", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
@Schema(description = "是/否检查 page 是否存在", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
||||||
private Boolean checkPath = CHECK_PATH;
|
private Boolean checkPath;
|
||||||
|
|
||||||
@Schema(description = "是/否需要透明底色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
@Schema(description = "是/否需要透明底色", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
||||||
private Boolean hyaline = HYALINE;
|
private Boolean hyaline;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user