小程序首页数据接口
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.czg.controller.user;
|
||||
|
||||
import com.czg.market.service.UserHomeService;
|
||||
import com.czg.market.vo.UserHomeDataVo;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 用户端/首页数据
|
||||
*
|
||||
* @author yjjie
|
||||
* @date 2025/12/11 13:27
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user/home")
|
||||
public class UHomeDataController {
|
||||
|
||||
@Resource
|
||||
private UserHomeService userHomeService;
|
||||
|
||||
/**
|
||||
* 获取用户端首页数据
|
||||
*/
|
||||
@GetMapping("/data")
|
||||
public CzgResult<UserHomeDataVo> getUserHomeData() {
|
||||
return CzgResult.success(userHomeService.getUserHomeData(StpKit.USER.getLoginIdAsLong(), StpKit.USER.getShopId()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.market.service;
|
||||
|
||||
import com.czg.market.vo.UserHomeDataVo;
|
||||
|
||||
/**
|
||||
* @author yjjie
|
||||
* @date 2025/12/11 11:22
|
||||
*/
|
||||
public interface UserHomeService {
|
||||
/**
|
||||
* 获取用户首页数据
|
||||
*/
|
||||
UserHomeDataVo getUserHomeData(Long userId, Long shopId);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.czg.market.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author yjjie
|
||||
* @date 2025/12/11 11:23
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UserHomeDataVo {
|
||||
/**
|
||||
* 店铺Id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 用户Id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
private String userNickname;
|
||||
|
||||
/**
|
||||
* 用户头像
|
||||
*/
|
||||
private String userAvatar;
|
||||
|
||||
/**
|
||||
* 优惠券数量
|
||||
*/
|
||||
private Long couponNum;
|
||||
|
||||
/**
|
||||
* 积分数量
|
||||
*/
|
||||
private Long pointNum;
|
||||
|
||||
/**
|
||||
* 是否开启外卖
|
||||
*/
|
||||
private Integer takeout;
|
||||
|
||||
/**
|
||||
* 是否开启拼团
|
||||
*/
|
||||
private Integer group;
|
||||
|
||||
/**
|
||||
* 是否开启积分商城
|
||||
*/
|
||||
private Integer pointsMall;
|
||||
|
||||
/**
|
||||
* 是否开启分销
|
||||
*/
|
||||
private Integer distribution;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import com.czg.account.dto.user.userinfo.UserInfoDTO;
|
||||
import com.czg.account.service.UserInfoService;
|
||||
import com.czg.market.entity.MkPointsConfig;
|
||||
import com.czg.market.entity.MkPointsUser;
|
||||
import com.czg.market.service.*;
|
||||
import com.czg.market.vo.MkDistributionConfigVO;
|
||||
import com.czg.market.vo.UserCouponVO;
|
||||
import com.czg.market.vo.UserHomeDataVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author yjjie
|
||||
* @date 2025/12/11 11:33
|
||||
*/
|
||||
@Service
|
||||
public class UserHomeServiceImpl implements UserHomeService {
|
||||
|
||||
@Resource
|
||||
private MkPointsConfigService mkPointsConfigService;
|
||||
|
||||
@Resource
|
||||
private MkDistributionConfigService mkDistributionConfigService;
|
||||
|
||||
@Resource
|
||||
private MkPointsUserService mkPointsUserService;
|
||||
|
||||
@Resource
|
||||
private ShopCouponService couponService;
|
||||
|
||||
@DubboReference
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Override
|
||||
public UserHomeDataVo getUserHomeData(Long userId, Long shopId) {
|
||||
UserHomeDataVo userHomeDataVo = new UserHomeDataVo()
|
||||
.setShopId(shopId)
|
||||
.setUserId(userId)
|
||||
.setGroup(0)
|
||||
.setTakeout(0);
|
||||
|
||||
// 用户信息
|
||||
UserInfoDTO info = userInfoService.getInfo(userId);
|
||||
if (info != null) {
|
||||
userHomeDataVo
|
||||
.setUserNickname(info.getNickName())
|
||||
.setUserAvatar(info.getHeadImg());
|
||||
}
|
||||
|
||||
// 积分商城
|
||||
MkPointsConfig pointsConfig = mkPointsConfigService.getById(shopId);
|
||||
if (pointsConfig != null) {
|
||||
userHomeDataVo.setPointsMall(pointsConfig.getEnablePointsMall());
|
||||
}
|
||||
|
||||
// 分销
|
||||
MkDistributionConfigVO distributionConfig = mkDistributionConfigService.detail(shopId);
|
||||
if (distributionConfig != null) {
|
||||
userHomeDataVo.setDistribution(distributionConfig.getIsEnable());
|
||||
}
|
||||
|
||||
// 积分
|
||||
MkPointsUser pointsUser = mkPointsUserService.getPointsUser(shopId, null, userId);
|
||||
if (pointsUser != null) {
|
||||
userHomeDataVo.setPointNum(pointsUser.getPointBalance());
|
||||
}
|
||||
|
||||
// 优惠券
|
||||
Page<UserCouponVO> coupon = couponService.find(userId, "", shopId, 0);
|
||||
userHomeDataVo.setCouponNum(coupon.getTotalRow());
|
||||
|
||||
return userHomeDataVo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user